2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.bin.Cache;
24 import jalview.datamodel.Alignment;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.ColumnSelection;
27 import jalview.datamodel.PDBEntry;
28 import jalview.datamodel.SequenceI;
29 import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
30 import jalview.gui.StructureViewer.ViewerType;
31 import jalview.io.AppletFormatAdapter;
32 import jalview.io.JalviewFileChooser;
33 import jalview.io.JalviewFileView;
34 import jalview.schemes.BuriedColourScheme;
35 import jalview.schemes.ColourSchemeI;
36 import jalview.schemes.HelixColourScheme;
37 import jalview.schemes.HydrophobicColourScheme;
38 import jalview.schemes.PurinePyrimidineColourScheme;
39 import jalview.schemes.StrandColourScheme;
40 import jalview.schemes.TaylorColourScheme;
41 import jalview.schemes.TurnColourScheme;
42 import jalview.schemes.ZappoColourScheme;
43 import jalview.structures.models.AAStructureBindingModel;
44 import jalview.util.MessageManager;
45 import jalview.util.Platform;
46 import jalview.ws.dbsources.Pdb;
48 import java.awt.event.ActionEvent;
49 import java.awt.event.ActionListener;
50 import java.awt.event.ItemEvent;
51 import java.awt.event.ItemListener;
52 import java.io.BufferedReader;
54 import java.io.FileInputStream;
55 import java.io.FileOutputStream;
56 import java.io.FileReader;
57 import java.io.IOException;
58 import java.io.InputStream;
59 import java.io.PrintWriter;
60 import java.util.ArrayList;
61 import java.util.List;
62 import java.util.Random;
63 import java.util.Vector;
65 import javax.swing.JCheckBoxMenuItem;
66 import javax.swing.JColorChooser;
67 import javax.swing.JInternalFrame;
68 import javax.swing.JMenu;
69 import javax.swing.JMenuItem;
70 import javax.swing.JOptionPane;
71 import javax.swing.event.InternalFrameAdapter;
72 import javax.swing.event.InternalFrameEvent;
73 import javax.swing.event.MenuEvent;
74 import javax.swing.event.MenuListener;
77 * GUI elements for handling an external chimera display
82 public class ChimeraViewFrame extends StructureViewerBase
84 private JalviewChimeraBinding jmb;
86 private boolean allChainsSelected = false;
88 private IProgressIndicator progressBar = null;
91 * Path to Chimera session file. This is set when an open Jalview/Chimera
92 * session is saved, or on restore from a Jalview project (if it holds the
93 * filename of any saved Chimera sessions).
95 private String chimeraSessionFile = null;
97 private Random random = new Random();
100 * Initialise menu options.
102 private void initMenus()
104 viewerActionMenu.setText(MessageManager.getString("label.chimera"));
105 viewerColour.setText(MessageManager
106 .getString("label.colour_with_chimera"));
107 viewerColour.setToolTipText(MessageManager
108 .getString("label.let_chimera_manage_structure_colours"));
109 helpItem.setText(MessageManager.getString("label.chimera_help"));
110 seqColour.setSelected(jmb.isColourBySequence());
111 viewerColour.setSelected(!jmb.isColourBySequence());
112 if (_colourwith == null)
114 _colourwith = new Vector<AlignmentPanel>();
116 if (_alignwith == null)
118 _alignwith = new Vector<AlignmentPanel>();
121 // save As not yet implemented
122 savemenu.setVisible(false);
124 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
125 MessageManager.getString("label.colour_by"), this, _colourwith,
129 public void itemStateChanged(ItemEvent e)
131 if (!seqColour.isSelected())
137 // update the Chimera display now.
138 seqColour_actionPerformed(null);
142 viewMenu.add(seqColourBy);
143 viewMenu.add(fitToWindow);
145 final ItemListener handler;
146 JMenu alpanels = new ViewSelectionMenu(
147 MessageManager.getString("label.superpose_with"), this,
148 _alignwith, handler = new ItemListener()
151 public void itemStateChanged(ItemEvent e)
153 alignStructs.setEnabled(_alignwith.size() > 0);
154 alignStructs.setToolTipText(MessageManager
156 "label.align_structures_using_linked_alignment_views",
157 new Object[] { new Integer(_alignwith
158 .size()).toString() }));
161 handler.itemStateChanged(null);
162 viewerActionMenu.add(alpanels);
163 viewerActionMenu.addMenuListener(new MenuListener()
167 public void menuSelected(MenuEvent e)
169 handler.itemStateChanged(null);
173 public void menuDeselected(MenuEvent e)
175 // TODO Auto-generated method stub
179 public void menuCanceled(MenuEvent e)
181 // TODO Auto-generated method stub
187 * add a single PDB structure to a new or existing Chimera view
194 public ChimeraViewFrame(PDBEntry pdbentry, SequenceI[] seq,
195 String[] chains, final AlignmentPanel ap)
198 String pdbId = pdbentry.getId();
201 * If the PDB file is already loaded, the user may just choose to add to an
202 * existing viewer (or cancel)
204 if (addAlreadyLoadedFile(seq, chains, ap, pdbId))
210 * Check if there are other Chimera views involving this alignment and give
211 * user the option to add and align this molecule to one of them (or cancel)
213 if (addToExistingViewer(pdbentry, seq, chains, ap, pdbId))
219 * If the options above are declined or do not apply, show the structure in
222 openNewChimera(ap, new PDBEntry[] { pdbentry },
223 new SequenceI[][] { seq });
227 * Create a helper to manage progress bar display
229 protected void createProgressBar()
231 if (progressBar == null)
233 progressBar = new ProgressBar(statusPanel, statusBar);
238 * Answers true if this viewer already involves the given PDB ID
241 protected boolean hasPdbId(String pdbId)
243 return jmb.hasPdbId(pdbId);
246 private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
250 // FIXME extractChains needs pdbentries to match IDs to PDBEntry(s) on seqs
251 String[][] chains = extractChains(seqs);
252 jmb = new JalviewChimeraBindingModel(this,
253 ap.getStructureSelectionManager(), pdbentrys, seqs, chains,
255 addAlignmentPanel(ap);
256 useAlignmentPanelForColourbyseq(ap);
257 if (pdbentrys.length > 1)
259 alignAddedStructures = true;
260 useAlignmentPanelForSuperposition(ap);
262 jmb.setColourBySequence(true);
263 setSize(400, 400); // probably should be a configurable/dynamic default here
266 addingStructures = false;
267 worker = new Thread(this);
270 this.addInternalFrameListener(new InternalFrameAdapter()
273 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
282 * Retrieve chains for sequences by inspecting their PDB refs. The hope is
283 * that the first will be to the sequence's own chain. Really need a more
284 * managed way of doing this.
289 protected String[][] extractChains(SequenceI[][] seqs)
291 String[][] chains = new String[seqs.length][];
292 for (int i = 0; i < seqs.length; i++)
294 chains[i] = new String[seqs[i].length];
296 for (SequenceI seq : seqs[i])
299 if (seq.getDatasetSequence() != null)
301 Vector<PDBEntry> pdbrefs = seq.getDatasetSequence()
303 if (pdbrefs != null && pdbrefs.size() > 0)
305 // FIXME: SequenceI.PDBEntry[0] chain mapping used for
306 // ChimeraViewFrame. Is this even used ???
308 chain = pdbrefs.get(0).getChainCode();
311 chains[i][seqno++] = chain;
318 * Create a new viewer from saved session state data including Chimera session
321 * @param chimeraSessionFile
325 * @param colourByChimera
326 * @param colourBySequence
329 public ChimeraViewFrame(String chimeraSessionFile,
330 AlignmentPanel alignPanel, PDBEntry[] pdbArray,
331 SequenceI[][] seqsArray, boolean colourByChimera,
332 boolean colourBySequence, String newViewId)
335 setViewId(newViewId);
336 this.chimeraSessionFile = chimeraSessionFile;
337 openNewChimera(alignPanel, pdbArray, seqsArray);
340 jmb.setColourBySequence(false);
341 seqColour.setSelected(false);
342 viewerColour.setSelected(true);
344 else if (colourBySequence)
346 jmb.setColourBySequence(true);
347 seqColour.setSelected(true);
348 viewerColour.setSelected(false);
353 * create a new viewer containing several structures superimposed using the
360 public ChimeraViewFrame(PDBEntry[] pe, SequenceI[][] seqs,
364 openNewChimera(ap, pe, seqs);
368 * Default constructor
370 public ChimeraViewFrame()
375 * closeViewer will decide whether or not to close this frame
376 * depending on whether user chooses to Cancel or not
378 setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
382 * Returns a list of any Chimera viewers in the desktop. The list is
383 * restricted to those linked to the given alignment panel if it is not null.
386 protected List<StructureViewerBase> getViewersFor(AlignmentPanel ap)
388 List<StructureViewerBase> result = new ArrayList<StructureViewerBase>();
389 JInternalFrame[] frames = Desktop.instance.getAllFrames();
391 for (JInternalFrame frame : frames)
393 if (frame instanceof ChimeraViewFrame)
395 if (ap == null || ((StructureViewerBase) frame).isLinkedWith(ap))
397 result.add((StructureViewerBase) frame);
405 * Launch Chimera. If we have a chimera session file name, send Chimera the
406 * command to open its saved session file.
410 jmb.setFinishedInit(false);
411 jalview.gui.Desktop.addInternalFrame(this,
412 jmb.getViewerTitle("Chimera", true), getBounds().width,
415 if (!jmb.launchChimera())
417 JOptionPane.showMessageDialog(Desktop.desktop,
418 MessageManager.getString("label.chimera_failed"),
419 MessageManager.getString("label.error_loading_file"),
420 JOptionPane.ERROR_MESSAGE);
425 if (this.chimeraSessionFile != null)
427 boolean opened = jmb.openSession(chimeraSessionFile);
431 .println("An error occurred opening Chimera session file "
432 + chimeraSessionFile);
435 jmb.setFinishedInit(true);
437 jmb.startChimeraListener();
441 * If the list is not empty, add menu items for 'All' and each individual
442 * chain to the "View | Show Chain" sub-menu. Multiple selections are allowed.
446 void setChainMenuItems(List<String> chainNames)
448 chainMenu.removeAll();
449 if (chainNames == null || chainNames.isEmpty())
453 JMenuItem menuItem = new JMenuItem(
454 MessageManager.getString("label.all"));
455 menuItem.addActionListener(new ActionListener()
458 public void actionPerformed(ActionEvent evt)
460 allChainsSelected = true;
461 for (int i = 0; i < chainMenu.getItemCount(); i++)
463 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
465 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
468 showSelectedChains();
469 allChainsSelected = false;
473 chainMenu.add(menuItem);
475 for (String chainName : chainNames)
477 menuItem = new JCheckBoxMenuItem(chainName, true);
478 menuItem.addItemListener(new ItemListener()
481 public void itemStateChanged(ItemEvent evt)
483 if (!allChainsSelected)
485 showSelectedChains();
490 chainMenu.add(menuItem);
495 * Show only the selected chain(s) in the viewer
497 void showSelectedChains()
499 List<String> toshow = new ArrayList<String>();
500 for (int i = 0; i < chainMenu.getItemCount(); i++)
502 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
504 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
505 if (item.isSelected())
507 toshow.add(item.getText());
511 jmb.showChains(toshow);
515 * Close down this instance of Jalview's Chimera viewer, giving the user the
516 * option to close the associated Chimera window (process). They may wish to
517 * keep it open until they have had an opportunity to save any work.
519 * @param closeChimera
520 * if true, close any linked Chimera process; if false, prompt first
523 public void closeViewer(boolean closeChimera)
525 if (jmb != null && jmb.isChimeraRunning())
529 String prompt = MessageManager.formatMessage(
530 "label.confirm_close_chimera",
531 new Object[] { jmb.getViewerTitle("Chimera", false) });
532 prompt = JvSwingUtils.wrapTooltip(true, prompt);
533 int confirm = JOptionPane.showConfirmDialog(this, prompt,
534 MessageManager.getString("label.close_viewer"),
535 JOptionPane.YES_NO_CANCEL_OPTION);
537 * abort closure if user hits escape or Cancel
539 if (confirm == JOptionPane.CANCEL_OPTION
540 || confirm == JOptionPane.CLOSED_OPTION)
544 closeChimera = confirm == JOptionPane.YES_OPTION;
546 jmb.closeViewer(closeChimera);
548 setAlignmentPanel(null);
552 // TODO: check for memory leaks where instance isn't finalised because jmb
553 // holds a reference to the window
559 * Open any newly added PDB structures in Chimera, having first fetched data
560 * from PDB (if not already saved).
566 // todo - record which pdbids were successfully imported.
567 StringBuilder errormsgs = new StringBuilder(128);
568 StringBuilder files = new StringBuilder(128);
569 List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
570 List<Integer> filePDBpos = new ArrayList<Integer>();
571 PDBEntry thePdbEntry = null;
574 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
575 // TODO: replace with reference fetching/transfer code (validate PDBentry
577 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
580 thePdbEntry = jmb.getPdbEntry(pi);
581 if (thePdbEntry.getFile() == null)
584 * Retrieve PDB data, save to file, attach to PDBEntry
586 file = fetchPdbFile(thePdbEntry);
589 errormsgs.append("'" + thePdbEntry.getId() + "' ");
595 * Got file already - ignore if already loaded in Chimera.
597 file = new File(thePdbEntry.getFile()).getAbsoluteFile()
599 if (curfiles != null && curfiles.length > 0)
601 addingStructures = true; // already files loaded.
602 for (int c = 0; c < curfiles.length; c++)
604 if (curfiles[c].equals(file))
614 filePDB.add(thePdbEntry);
615 filePDBpos.add(Integer.valueOf(pi));
616 files.append(" \"" + Platform.escapeString(file) + "\"");
619 } catch (OutOfMemoryError oomerror)
621 new OOMWarning("Retrieving PDB files: " + thePdbEntry.getId(),
623 } catch (Exception ex)
625 ex.printStackTrace();
626 errormsgs.append("When retrieving pdbfiles for '"
627 + thePdbEntry.getId() + "'");
629 if (errormsgs.length() > 0)
632 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
633 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
634 new Object[] { errormsgs.toString() }),
635 MessageManager.getString("label.couldnt_load_file"),
636 JOptionPane.ERROR_MESSAGE);
639 if (files.length() > 0)
641 if (!addingStructures)
646 } catch (Exception ex)
648 Cache.log.error("Couldn't open Chimera viewer!", ex);
652 for (PDBEntry pe : filePDB)
655 if (pe.getFile() != null)
659 int pos = filePDBpos.get(num).intValue();
660 long startTime = startProgressBar("Chimera "
661 + MessageManager.getString("status.opening_file_for")
664 jmb.addSequence(pos, jmb.getSequence()[pos]);
665 File fl = new File(pe.getFile());
666 String protocol = AppletFormatAdapter.URL;
671 protocol = AppletFormatAdapter.FILE;
673 } catch (Throwable e)
677 stopProgressBar("", startTime);
679 // Explicitly map to the filename used by Chimera ;
680 jmb.getSsm().setMapping(jmb.getSequence()[pos],
681 jmb.getChains()[pos], pe.getFile(), protocol);
682 } catch (OutOfMemoryError oomerror)
685 "When trying to open and map structures from Chimera!",
687 } catch (Exception ex)
689 Cache.log.error("Couldn't open " + pe.getFile()
690 + " in Chimera viewer!", ex);
693 Cache.log.debug("File locations are " + files);
697 jmb.setFinishedInit(true);
698 jmb.setLoadingFromArchive(false);
700 // refresh the sequence colours for the new structure(s)
701 for (AlignmentPanel ap : _colourwith)
703 jmb.updateColours(ap);
705 // do superposition if asked to
706 if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures)
708 new Thread(new Runnable()
713 alignStructs_withAllAlignPanels();
716 alignAddedStructures = false;
718 addingStructures = false;
725 * Fetch PDB data and save to a local file. Returns the full path to the file,
726 * or null if fetch fails.
728 * @param processingEntry
732 private String fetchPdbFile(PDBEntry processingEntry) throws Exception
734 // FIXME: this is duplicated code with Jmol frame ?
735 String filePath = null;
736 Pdb pdbclient = new Pdb();
737 AlignmentI pdbseq = null;
738 String pdbid = processingEntry.getId();
739 long handle = System.currentTimeMillis()
740 + Thread.currentThread().hashCode();
743 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
745 String msg = MessageManager.formatMessage("status.fetching_pdb",
746 new Object[] { pdbid });
747 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
748 // long hdl = startProgressBar(MessageManager.formatMessage(
749 // "status.fetching_pdb", new Object[]
753 pdbseq = pdbclient.getSequenceRecords(pdbid);
754 } catch (OutOfMemoryError oomerror)
756 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
759 msg = pdbid + " " + MessageManager.getString("label.state_completed");
760 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
761 // stopProgressBar(msg, hdl);
764 * If PDB data were saved and are not invalid (empty alignment), return the
767 if (pdbseq != null && pdbseq.getHeight() > 0)
769 // just use the file name from the first sequence's first PDBEntry
770 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
771 .elementAt(0).getFile()).getAbsolutePath();
772 processingEntry.setFile(filePath);
778 * Convenience method to update the progress bar if there is one. Be sure to
779 * call stopProgressBar with the returned handle to remove the message.
784 public long startProgressBar(String msg)
786 // TODO would rather have startProgress/stopProgress as the
787 // IProgressIndicator interface
788 long tm = random.nextLong();
789 if (progressBar != null)
791 progressBar.setProgressBar(msg, tm);
797 * End the progress bar with the specified handle, leaving a message (if not
798 * null) on the status bar
803 public void stopProgressBar(String msg, long handle)
805 if (progressBar != null)
807 progressBar.setProgressBar(msg, handle);
812 public void pdbFile_actionPerformed(ActionEvent actionEvent)
814 JalviewFileChooser chooser = new JalviewFileChooser(
815 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
817 chooser.setFileView(new JalviewFileView());
818 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
819 chooser.setToolTipText(MessageManager.getString("action.save"));
821 int value = chooser.showSaveDialog(this);
823 if (value == JalviewFileChooser.APPROVE_OPTION)
825 BufferedReader in = null;
828 // TODO: cope with multiple PDB files in view
829 in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
830 File outFile = chooser.getSelectedFile();
832 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
834 while ((data = in.readLine()) != null)
836 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
842 } catch (Exception ex)
844 ex.printStackTrace();
852 } catch (IOException e)
862 public void viewMapping_actionPerformed(ActionEvent actionEvent)
864 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
867 cap.appendText(jmb.printMappings());
868 } catch (OutOfMemoryError e)
871 "composing sequence-structure alignments for display in text box.",
876 jalview.gui.Desktop.addInternalFrame(cap,
877 MessageManager.getString("label.pdb_sequence_mapping"), 550,
882 public void eps_actionPerformed(ActionEvent e)
886 .getString("error.eps_generation_not_implemented"));
890 public void png_actionPerformed(ActionEvent e)
894 .getString("error.png_generation_not_implemented"));
898 public void viewerColour_actionPerformed(ActionEvent actionEvent)
900 if (viewerColour.isSelected())
902 // disable automatic sequence colouring.
903 jmb.setColourBySequence(false);
908 public void seqColour_actionPerformed(ActionEvent actionEvent)
910 jmb.setColourBySequence(seqColour.isSelected());
911 if (_colourwith == null)
913 _colourwith = new Vector<AlignmentPanel>();
915 if (jmb.isColourBySequence())
917 if (!jmb.isLoadingFromArchive())
919 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
921 // Make the currently displayed alignment panel the associated view
922 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
925 // Set the colour using the current view for the associated alignframe
926 for (AlignmentPanel ap : _colourwith)
928 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
934 public void chainColour_actionPerformed(ActionEvent actionEvent)
936 chainColour.setSelected(true);
941 public void chargeColour_actionPerformed(ActionEvent actionEvent)
943 chargeColour.setSelected(true);
944 jmb.colourByCharge();
948 public void zappoColour_actionPerformed(ActionEvent actionEvent)
950 zappoColour.setSelected(true);
951 jmb.setJalviewColourScheme(new ZappoColourScheme());
955 public void taylorColour_actionPerformed(ActionEvent actionEvent)
957 taylorColour.setSelected(true);
958 jmb.setJalviewColourScheme(new TaylorColourScheme());
962 public void hydroColour_actionPerformed(ActionEvent actionEvent)
964 hydroColour.setSelected(true);
965 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
969 public void helixColour_actionPerformed(ActionEvent actionEvent)
971 helixColour.setSelected(true);
972 jmb.setJalviewColourScheme(new HelixColourScheme());
976 public void strandColour_actionPerformed(ActionEvent actionEvent)
978 strandColour.setSelected(true);
979 jmb.setJalviewColourScheme(new StrandColourScheme());
983 public void turnColour_actionPerformed(ActionEvent actionEvent)
985 turnColour.setSelected(true);
986 jmb.setJalviewColourScheme(new TurnColourScheme());
990 public void buriedColour_actionPerformed(ActionEvent actionEvent)
992 buriedColour.setSelected(true);
993 jmb.setJalviewColourScheme(new BuriedColourScheme());
997 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
999 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1003 public void userColour_actionPerformed(ActionEvent actionEvent)
1005 userColour.setSelected(true);
1006 new UserDefinedColours(this, null);
1010 public void backGround_actionPerformed(ActionEvent actionEvent)
1012 java.awt.Color col = JColorChooser
1013 .showDialog(this, MessageManager
1014 .getString("label.select_backgroud_colour"), null);
1017 jmb.setBackgroundColour(col);
1022 public void showHelp_actionPerformed(ActionEvent actionEvent)
1026 jalview.util.BrowserLauncher
1027 .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
1028 } catch (Exception ex)
1033 public void updateTitleAndMenus()
1035 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1040 setChainMenuItems(jmb.getChainNames());
1042 this.setTitle(jmb.getViewerTitle("Chimera", true));
1043 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1045 viewerActionMenu.setVisible(true);
1047 if (!jmb.isLoadingFromArchive())
1049 seqColour_actionPerformed(null);
1057 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1061 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1063 alignStructs_withAllAlignPanels();
1066 private void alignStructs_withAllAlignPanels()
1068 if (getAlignmentPanel() == null)
1073 if (_alignwith.size() == 0)
1075 _alignwith.add(getAlignmentPanel());
1080 AlignmentI[] als = new Alignment[_alignwith.size()];
1081 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1082 int[] alm = new int[_alignwith.size()];
1085 for (AlignmentPanel ap : _alignwith)
1087 als[a] = ap.av.getAlignment();
1089 alc[a++] = ap.av.getColumnSelection();
1091 jmb.superposeStructures(als, alm, alc);
1092 } catch (Exception e)
1094 StringBuffer sp = new StringBuffer();
1095 for (AlignmentPanel ap : _alignwith)
1097 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1099 Cache.log.info("Couldn't align structures with the " + sp.toString()
1100 + "associated alignment panels.", e);
1105 public void setJalviewColourScheme(ColourSchemeI ucs)
1107 jmb.setJalviewColourScheme(ucs);
1114 * @return first alignment panel displaying given alignment, or the default
1117 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1119 for (AlignmentPanel ap : getAllAlignmentPanels())
1121 if (ap.av.getAlignment() == alignment)
1126 return getAlignmentPanel();
1130 public AAStructureBindingModel getBinding()
1136 * Ask Chimera to save its session to the designated file path, or to a
1137 * temporary file if the path is null. Returns the file path if successful,
1143 protected String saveSession(String filepath)
1145 String pathUsed = filepath;
1148 if (pathUsed == null)
1150 File tempFile = File.createTempFile("chimera", ".py");
1151 tempFile.deleteOnExit();
1152 pathUsed = tempFile.getPath();
1154 boolean result = jmb.saveSession(pathUsed);
1157 this.chimeraSessionFile = pathUsed;
1160 } catch (IOException e)
1167 * Returns a string representing the state of the Chimera session. This is
1168 * done by requesting Chimera to save its session to a temporary file, then
1169 * reading the file contents. Returns an empty string on any error.
1172 public String getStateInfo()
1174 String sessionFile = saveSession(null);
1175 if (sessionFile == null)
1179 InputStream is = null;
1182 File f = new File(sessionFile);
1183 byte[] bytes = new byte[(int) f.length()];
1184 is = new FileInputStream(sessionFile);
1186 return new String(bytes);
1187 } catch (IOException e)
1197 } catch (IOException e)
1206 protected void fitToWindow_actionPerformed()
1212 public ViewerType getViewerType()
1214 return ViewerType.CHIMERA;
1218 protected AAStructureBindingModel getBindingModel()