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.DataSourceType;
32 import jalview.io.JalviewFileChooser;
33 import jalview.io.JalviewFileView;
34 import jalview.io.StructureFile;
35 import jalview.schemes.BuriedColourScheme;
36 import jalview.schemes.ColourSchemeI;
37 import jalview.schemes.HelixColourScheme;
38 import jalview.schemes.HydrophobicColourScheme;
39 import jalview.schemes.PurinePyrimidineColourScheme;
40 import jalview.schemes.StrandColourScheme;
41 import jalview.schemes.TaylorColourScheme;
42 import jalview.schemes.TurnColourScheme;
43 import jalview.schemes.ZappoColourScheme;
44 import jalview.structures.models.AAStructureBindingModel;
45 import jalview.util.MessageManager;
46 import jalview.util.Platform;
47 import jalview.ws.dbsources.Pdb;
49 import java.awt.event.ActionEvent;
50 import java.awt.event.ActionListener;
51 import java.awt.event.ItemEvent;
52 import java.awt.event.ItemListener;
53 import java.awt.event.MouseAdapter;
54 import java.awt.event.MouseEvent;
55 import java.io.BufferedReader;
57 import java.io.FileInputStream;
58 import java.io.FileOutputStream;
59 import java.io.FileReader;
60 import java.io.IOException;
61 import java.io.InputStream;
62 import java.io.PrintWriter;
63 import java.util.ArrayList;
64 import java.util.List;
65 import java.util.Random;
66 import java.util.Vector;
68 import javax.swing.JCheckBoxMenuItem;
69 import javax.swing.JColorChooser;
70 import javax.swing.JInternalFrame;
71 import javax.swing.JMenu;
72 import javax.swing.JMenuItem;
73 import javax.swing.event.InternalFrameAdapter;
74 import javax.swing.event.InternalFrameEvent;
75 import javax.swing.event.MenuEvent;
76 import javax.swing.event.MenuListener;
79 * GUI elements for handling an external chimera display
84 public class ChimeraViewFrame extends StructureViewerBase
86 JalviewChimeraBinding jmb;
88 private boolean allChainsSelected = false;
90 private IProgressIndicator progressBar = null;
93 * Path to Chimera session file. This is set when an open Jalview/Chimera
94 * session is saved, or on restore from a Jalview project (if it holds the
95 * filename of any saved Chimera sessions).
97 private String chimeraSessionFile = null;
99 private Random random = new Random();
102 * Initialise menu options.
104 private void initMenus()
106 String chimera = MessageManager.getString("label.chimera");
107 viewerActionMenu.setText(chimera);
108 viewerColour.setText(MessageManager
109 .getString("label.colour_with_chimera"));
110 viewerColour.setToolTipText(MessageManager
111 .getString("label.let_chimera_manage_structure_colours"));
112 helpItem.setText(MessageManager.getString("label.chimera_help"));
113 seqColour.setSelected(jmb.isColourBySequence());
114 viewerColour.setSelected(!jmb.isColourBySequence());
115 if (_colourwith == null)
117 _colourwith = new Vector<AlignmentPanel>();
119 if (_alignwith == null)
121 _alignwith = new Vector<AlignmentPanel>();
124 // save As not yet implemented
125 savemenu.setVisible(false);
127 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
128 MessageManager.getString("label.colour_by"), this, _colourwith,
132 public void itemStateChanged(ItemEvent e)
134 if (!seqColour.isSelected())
140 // update the Chimera display now.
141 seqColour_actionPerformed(null);
145 viewMenu.add(seqColourBy);
146 viewMenu.add(fitToWindow);
148 final ItemListener handler;
149 JMenu alpanels = new ViewSelectionMenu(
150 MessageManager.getString("label.superpose_with"), this,
151 _alignwith, handler = new ItemListener()
154 public void itemStateChanged(ItemEvent e)
156 alignStructs.setEnabled(_alignwith.size() > 0);
157 alignStructs.setToolTipText(MessageManager
159 "label.align_structures_using_linked_alignment_views",
160 new Object[] { new Integer(_alignwith
161 .size()).toString() }));
164 handler.itemStateChanged(null);
165 viewerActionMenu.add(alpanels);
166 viewerActionMenu.addMenuListener(new MenuListener()
169 public void menuSelected(MenuEvent e)
171 handler.itemStateChanged(null);
174 public void menuDeselected(MenuEvent e)
178 public void menuCanceled(MenuEvent e)
183 JMenuItem writeFeatures = new JMenuItem(
184 MessageManager.getString("label.create_viewer_attributes"));
185 writeFeatures.setToolTipText(MessageManager.formatMessage(
186 "label.create_viewer_attributes_tip", chimera));
187 writeFeatures.addActionListener(new ActionListener()
190 public void actionPerformed(ActionEvent e)
192 sendFeaturesToViewer();
195 viewerActionMenu.add(writeFeatures);
197 final JMenu fetchAttributes = new JMenu(MessageManager.formatMessage(
198 "label.fetch_viewer_attributes", chimera));
199 fetchAttributes.setToolTipText(MessageManager.formatMessage(
200 "label.fetch_viewer_attributes_tip", chimera));
201 fetchAttributes.addMouseListener(new MouseAdapter()
205 public void mouseEntered(MouseEvent e)
207 buildAttributesMenu(fetchAttributes);
210 viewerActionMenu.add(fetchAttributes);
214 * Asks Chimera for residues with the given attribute name, and set as
215 * features on the corresponding sequence positions (if any)
220 protected void getResidueAttributes(String attName)
222 jmb.copyStructureAttributesToFeatures(attName, getAlignmentPanel());
226 * Send a command to Chimera to create residue attributes for Jalview features
228 * The syntax is: setattr r <attName> <attValue> <atomSpec>
230 * For example: setattr r jv:chain "Ferredoxin-1, Chloroplastic" #0:94.A
233 protected void sendFeaturesToViewer()
235 jmb.sendFeaturesToViewer(getAlignmentPanel());
239 * add a single PDB structure to a new or existing Chimera view
246 public ChimeraViewFrame(PDBEntry pdbentry, SequenceI[] seq,
247 String[] chains, final AlignmentPanel ap)
250 String pdbId = pdbentry.getId();
253 * If the PDB file is already loaded, the user may just choose to add to an
254 * existing viewer (or cancel)
256 if (addAlreadyLoadedFile(seq, chains, ap, pdbId))
262 * Check if there are other Chimera views involving this alignment and give
263 * user the option to add and align this molecule to one of them (or cancel)
265 if (addToExistingViewer(pdbentry, seq, chains, ap, pdbId))
271 * If the options above are declined or do not apply, show the structure in
274 openNewChimera(ap, new PDBEntry[] { pdbentry },
275 new SequenceI[][] { seq });
279 * Create a helper to manage progress bar display
281 protected void createProgressBar()
283 if (progressBar == null)
285 progressBar = new ProgressBar(statusPanel, statusBar);
290 * Answers true if this viewer already involves the given PDB ID
293 protected boolean hasPdbId(String pdbId)
295 return jmb.hasPdbId(pdbId);
298 private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
302 jmb = new JalviewChimeraBindingModel(this,
303 ap.getStructureSelectionManager(), pdbentrys, seqs, null);
304 addAlignmentPanel(ap);
305 useAlignmentPanelForColourbyseq(ap);
306 if (pdbentrys.length > 1)
308 alignAddedStructures = true;
309 useAlignmentPanelForSuperposition(ap);
311 jmb.setColourBySequence(true);
312 setSize(400, 400); // probably should be a configurable/dynamic default here
315 addingStructures = false;
316 worker = new Thread(this);
319 this.addInternalFrameListener(new InternalFrameAdapter()
322 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
331 * Create a new viewer from saved session state data including Chimera session
334 * @param chimeraSessionFile
338 * @param colourByChimera
339 * @param colourBySequence
342 public ChimeraViewFrame(String chimeraSessionFile,
343 AlignmentPanel alignPanel, PDBEntry[] pdbArray,
344 SequenceI[][] seqsArray, boolean colourByChimera,
345 boolean colourBySequence, String newViewId)
348 setViewId(newViewId);
349 this.chimeraSessionFile = chimeraSessionFile;
350 openNewChimera(alignPanel, pdbArray, seqsArray);
353 jmb.setColourBySequence(false);
354 seqColour.setSelected(false);
355 viewerColour.setSelected(true);
357 else if (colourBySequence)
359 jmb.setColourBySequence(true);
360 seqColour.setSelected(true);
361 viewerColour.setSelected(false);
366 * create a new viewer containing several structures superimposed using the
373 public ChimeraViewFrame(PDBEntry[] pe, SequenceI[][] seqs,
377 openNewChimera(ap, pe, seqs);
381 * Default constructor
383 public ChimeraViewFrame()
388 * closeViewer will decide whether or not to close this frame
389 * depending on whether user chooses to Cancel or not
391 setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
395 * Returns a list of any Chimera viewers in the desktop. The list is
396 * restricted to those linked to the given alignment panel if it is not null.
399 protected List<StructureViewerBase> getViewersFor(AlignmentPanel ap)
401 List<StructureViewerBase> result = new ArrayList<StructureViewerBase>();
402 JInternalFrame[] frames = Desktop.instance.getAllFrames();
404 for (JInternalFrame frame : frames)
406 if (frame instanceof ChimeraViewFrame)
408 if (ap == null || ((StructureViewerBase) frame).isLinkedWith(ap))
410 result.add((StructureViewerBase) frame);
418 * Launch Chimera. If we have a chimera session file name, send Chimera the
419 * command to open its saved session file.
423 Desktop.addInternalFrame(this, jmb.getViewerTitle("Chimera", true),
424 getBounds().width, getBounds().height);
426 if (!jmb.launchChimera())
428 JvOptionPane.showMessageDialog(Desktop.desktop,
429 MessageManager.getString("label.chimera_failed"),
430 MessageManager.getString("label.error_loading_file"),
431 JvOptionPane.ERROR_MESSAGE);
436 if (this.chimeraSessionFile != null)
438 boolean opened = jmb.openSession(chimeraSessionFile);
442 .println("An error occurred opening Chimera session file "
443 + chimeraSessionFile);
447 jmb.startChimeraListener();
451 * If the list is not empty, add menu items for 'All' and each individual
452 * chain to the "View | Show Chain" sub-menu. Multiple selections are allowed.
457 void setChainMenuItems(List<String> chainNames)
459 chainMenu.removeAll();
460 if (chainNames == null || chainNames.isEmpty())
464 JMenuItem menuItem = new JMenuItem(
465 MessageManager.getString("label.all"));
466 menuItem.addActionListener(new ActionListener()
469 public void actionPerformed(ActionEvent evt)
471 allChainsSelected = true;
472 for (int i = 0; i < chainMenu.getItemCount(); i++)
474 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
476 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
479 showSelectedChains();
480 allChainsSelected = false;
484 chainMenu.add(menuItem);
486 for (String chainName : chainNames)
488 menuItem = new JCheckBoxMenuItem(chainName, true);
489 menuItem.addItemListener(new ItemListener()
492 public void itemStateChanged(ItemEvent evt)
494 if (!allChainsSelected)
496 showSelectedChains();
501 chainMenu.add(menuItem);
506 * Show only the selected chain(s) in the viewer
509 void showSelectedChains()
511 List<String> toshow = new ArrayList<String>();
512 for (int i = 0; i < chainMenu.getItemCount(); i++)
514 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
516 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
517 if (item.isSelected())
519 toshow.add(item.getText());
523 jmb.showChains(toshow);
527 * Close down this instance of Jalview's Chimera viewer, giving the user the
528 * option to close the associated Chimera window (process). They may wish to
529 * keep it open until they have had an opportunity to save any work.
531 * @param closeChimera
532 * if true, close any linked Chimera process; if false, prompt first
535 public void closeViewer(boolean closeChimera)
537 if (jmb != null && jmb.isChimeraRunning())
541 String prompt = MessageManager.formatMessage(
542 "label.confirm_close_chimera",
543 new Object[] { jmb.getViewerTitle("Chimera", false) });
544 prompt = JvSwingUtils.wrapTooltip(true, prompt);
545 int confirm = JvOptionPane.showConfirmDialog(this, prompt,
546 MessageManager.getString("label.close_viewer"),
547 JvOptionPane.YES_NO_CANCEL_OPTION);
549 * abort closure if user hits escape or Cancel
551 if (confirm == JvOptionPane.CANCEL_OPTION
552 || confirm == JvOptionPane.CLOSED_OPTION)
556 closeChimera = confirm == JvOptionPane.YES_OPTION;
558 jmb.closeViewer(closeChimera);
560 setAlignmentPanel(null);
564 // TODO: check for memory leaks where instance isn't finalised because jmb
565 // holds a reference to the window
571 * Open any newly added PDB structures in Chimera, having first fetched data
572 * from PDB (if not already saved).
578 // todo - record which pdbids were successfully imported.
579 StringBuilder errormsgs = new StringBuilder(128);
580 StringBuilder files = new StringBuilder(128);
581 List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
582 List<Integer> filePDBpos = new ArrayList<Integer>();
583 PDBEntry thePdbEntry = null;
584 StructureFile pdb = null;
587 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
588 // TODO: replace with reference fetching/transfer code (validate PDBentry
590 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
593 thePdbEntry = jmb.getPdbEntry(pi);
594 if (thePdbEntry.getFile() == null)
597 * Retrieve PDB data, save to file, attach to PDBEntry
599 file = fetchPdbFile(thePdbEntry);
602 errormsgs.append("'" + thePdbEntry.getId() + "' ");
608 * Got file already - ignore if already loaded in Chimera.
610 file = new File(thePdbEntry.getFile()).getAbsoluteFile()
612 if (curfiles != null && curfiles.length > 0)
614 addingStructures = true; // already files loaded.
615 for (int c = 0; c < curfiles.length; c++)
617 if (curfiles[c].equals(file))
627 filePDB.add(thePdbEntry);
628 filePDBpos.add(Integer.valueOf(pi));
629 files.append(" \"" + Platform.escapeString(file) + "\"");
632 } catch (OutOfMemoryError oomerror)
634 new OOMWarning("Retrieving PDB files: " + thePdbEntry.getId(),
636 } catch (Exception ex)
638 ex.printStackTrace();
639 errormsgs.append("When retrieving pdbfiles for '"
640 + thePdbEntry.getId() + "'");
642 if (errormsgs.length() > 0)
645 JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
646 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
647 new Object[] { errormsgs.toString() }),
648 MessageManager.getString("label.couldnt_load_file"),
649 JvOptionPane.ERROR_MESSAGE);
652 if (files.length() > 0)
654 jmb.setFinishedInit(false);
655 if (!addingStructures)
660 } catch (Exception ex)
662 Cache.log.error("Couldn't open Chimera viewer!", ex);
666 for (PDBEntry pe : filePDB)
669 if (pe.getFile() != null)
673 int pos = filePDBpos.get(num).intValue();
674 long startTime = startProgressBar("Chimera "
675 + MessageManager.getString("status.opening_file_for")
678 jmb.addSequence(pos, jmb.getSequence()[pos]);
679 File fl = new File(pe.getFile());
680 DataSourceType protocol = DataSourceType.URL;
685 protocol = DataSourceType.FILE;
687 } catch (Throwable e)
691 stopProgressBar("", startTime);
693 // Explicitly map to the filename used by Chimera ;
694 pdb = jmb.getSsm().setMapping(jmb.getSequence()[pos],
695 jmb.getChains()[pos], pe.getFile(), protocol);
696 stashFoundChains(pdb, pe.getFile());
697 } catch (OutOfMemoryError oomerror)
700 "When trying to open and map structures from Chimera!",
702 } catch (Exception ex)
704 Cache.log.error("Couldn't open " + pe.getFile()
705 + " in Chimera viewer!", ex);
708 Cache.log.debug("File locations are " + files);
714 jmb.setFinishedInit(true);
715 jmb.setLoadingFromArchive(false);
717 // refresh the sequence colours for the new structure(s)
718 for (AlignmentPanel ap : _colourwith)
720 jmb.updateColours(ap);
722 // do superposition if asked to
723 if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures)
725 new Thread(new Runnable()
730 alignStructs_withAllAlignPanels();
733 alignAddedStructures = false;
735 addingStructures = false;
742 * Fetch PDB data and save to a local file. Returns the full path to the file,
743 * or null if fetch fails.
745 * @param processingEntry
750 private void stashFoundChains(StructureFile pdb, String file)
752 for (int i = 0; i < pdb.getChains().size(); i++)
754 String chid = new String(pdb.getId() + ":"
755 + pdb.getChains().elementAt(i).id);
756 jmb.getChainNames().add(chid);
757 jmb.getChainFile().put(chid, file);
760 private String fetchPdbFile(PDBEntry processingEntry) throws Exception
762 // FIXME: this is duplicated code with Jmol frame ?
763 String filePath = null;
764 Pdb pdbclient = new Pdb();
765 AlignmentI pdbseq = null;
766 String pdbid = processingEntry.getId();
767 long handle = System.currentTimeMillis()
768 + Thread.currentThread().hashCode();
771 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
773 String msg = MessageManager.formatMessage("status.fetching_pdb",
774 new Object[] { pdbid });
775 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
776 // long hdl = startProgressBar(MessageManager.formatMessage(
777 // "status.fetching_pdb", new Object[]
781 pdbseq = pdbclient.getSequenceRecords(pdbid);
782 } catch (OutOfMemoryError oomerror)
784 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
787 msg = pdbid + " " + MessageManager.getString("label.state_completed");
788 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
789 // stopProgressBar(msg, hdl);
792 * If PDB data were saved and are not invalid (empty alignment), return the
795 if (pdbseq != null && pdbseq.getHeight() > 0)
797 // just use the file name from the first sequence's first PDBEntry
798 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
799 .elementAt(0).getFile()).getAbsolutePath();
800 processingEntry.setFile(filePath);
806 * Convenience method to update the progress bar if there is one. Be sure to
807 * call stopProgressBar with the returned handle to remove the message.
812 public long startProgressBar(String msg)
814 // TODO would rather have startProgress/stopProgress as the
815 // IProgressIndicator interface
816 long tm = random.nextLong();
817 if (progressBar != null)
819 progressBar.setProgressBar(msg, tm);
825 * End the progress bar with the specified handle, leaving a message (if not
826 * null) on the status bar
831 public void stopProgressBar(String msg, long handle)
833 if (progressBar != null)
835 progressBar.setProgressBar(msg, handle);
840 public void pdbFile_actionPerformed(ActionEvent actionEvent)
842 JalviewFileChooser chooser = new JalviewFileChooser(
843 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
845 chooser.setFileView(new JalviewFileView());
846 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
847 chooser.setToolTipText(MessageManager.getString("action.save"));
849 int value = chooser.showSaveDialog(this);
851 if (value == JalviewFileChooser.APPROVE_OPTION)
853 BufferedReader in = null;
856 // TODO: cope with multiple PDB files in view
857 in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
858 File outFile = chooser.getSelectedFile();
860 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
862 while ((data = in.readLine()) != null)
864 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
870 } catch (Exception ex)
872 ex.printStackTrace();
880 } catch (IOException e)
890 public void viewMapping_actionPerformed(ActionEvent actionEvent)
892 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
895 cap.appendText(jmb.printMappings());
896 } catch (OutOfMemoryError e)
899 "composing sequence-structure alignments for display in text box.",
904 jalview.gui.Desktop.addInternalFrame(cap,
905 MessageManager.getString("label.pdb_sequence_mapping"), 550,
910 public void eps_actionPerformed(ActionEvent e)
914 .getString("error.eps_generation_not_implemented"));
918 public void png_actionPerformed(ActionEvent e)
922 .getString("error.png_generation_not_implemented"));
926 public void viewerColour_actionPerformed(ActionEvent actionEvent)
928 if (viewerColour.isSelected())
930 // disable automatic sequence colouring.
931 jmb.setColourBySequence(false);
936 public void seqColour_actionPerformed(ActionEvent actionEvent)
938 jmb.setColourBySequence(seqColour.isSelected());
939 if (_colourwith == null)
941 _colourwith = new Vector<AlignmentPanel>();
943 if (jmb.isColourBySequence())
945 if (!jmb.isLoadingFromArchive())
947 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
949 // Make the currently displayed alignment panel the associated view
950 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
953 // Set the colour using the current view for the associated alignframe
954 for (AlignmentPanel ap : _colourwith)
956 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
962 public void chainColour_actionPerformed(ActionEvent actionEvent)
964 chainColour.setSelected(true);
969 public void chargeColour_actionPerformed(ActionEvent actionEvent)
971 chargeColour.setSelected(true);
972 jmb.colourByCharge();
976 public void zappoColour_actionPerformed(ActionEvent actionEvent)
978 zappoColour.setSelected(true);
979 jmb.setJalviewColourScheme(new ZappoColourScheme());
983 public void taylorColour_actionPerformed(ActionEvent actionEvent)
985 taylorColour.setSelected(true);
986 jmb.setJalviewColourScheme(new TaylorColourScheme());
990 public void hydroColour_actionPerformed(ActionEvent actionEvent)
992 hydroColour.setSelected(true);
993 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
997 public void helixColour_actionPerformed(ActionEvent actionEvent)
999 helixColour.setSelected(true);
1000 jmb.setJalviewColourScheme(new HelixColourScheme());
1004 public void strandColour_actionPerformed(ActionEvent actionEvent)
1006 strandColour.setSelected(true);
1007 jmb.setJalviewColourScheme(new StrandColourScheme());
1011 public void turnColour_actionPerformed(ActionEvent actionEvent)
1013 turnColour.setSelected(true);
1014 jmb.setJalviewColourScheme(new TurnColourScheme());
1018 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1020 buriedColour.setSelected(true);
1021 jmb.setJalviewColourScheme(new BuriedColourScheme());
1025 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1027 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1031 public void userColour_actionPerformed(ActionEvent actionEvent)
1033 userColour.setSelected(true);
1034 new UserDefinedColours(this, null);
1038 public void backGround_actionPerformed(ActionEvent actionEvent)
1040 java.awt.Color col = JColorChooser
1041 .showDialog(this, MessageManager
1042 .getString("label.select_backgroud_colour"), null);
1045 jmb.setBackgroundColour(col);
1050 public void showHelp_actionPerformed(ActionEvent actionEvent)
1054 jalview.util.BrowserLauncher
1055 .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
1056 } catch (Exception ex)
1061 public void updateTitleAndMenus()
1063 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1068 setChainMenuItems(jmb.getChainNames());
1070 this.setTitle(jmb.getViewerTitle("Chimera", true));
1071 // if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1073 viewerActionMenu.setVisible(true);
1075 if (!jmb.isLoadingFromArchive())
1077 seqColour_actionPerformed(null);
1085 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1089 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1091 alignStructs_withAllAlignPanels();
1094 private void alignStructs_withAllAlignPanels()
1096 if (getAlignmentPanel() == null)
1101 if (_alignwith.size() == 0)
1103 _alignwith.add(getAlignmentPanel());
1108 AlignmentI[] als = new Alignment[_alignwith.size()];
1109 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1110 int[] alm = new int[_alignwith.size()];
1113 for (AlignmentPanel ap : _alignwith)
1115 als[a] = ap.av.getAlignment();
1117 alc[a++] = ap.av.getColumnSelection();
1119 jmb.superposeStructures(als, alm, alc);
1120 } catch (Exception e)
1122 StringBuffer sp = new StringBuffer();
1123 for (AlignmentPanel ap : _alignwith)
1125 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1127 Cache.log.info("Couldn't align structures with the " + sp.toString()
1128 + "associated alignment panels.", e);
1133 public void setJalviewColourScheme(ColourSchemeI ucs)
1135 jmb.setJalviewColourScheme(ucs);
1142 * @return first alignment panel displaying given alignment, or the default
1145 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1147 for (AlignmentPanel ap : getAllAlignmentPanels())
1149 if (ap.av.getAlignment() == alignment)
1154 return getAlignmentPanel();
1158 public AAStructureBindingModel getBinding()
1164 * Ask Chimera to save its session to the designated file path, or to a
1165 * temporary file if the path is null. Returns the file path if successful,
1171 protected String saveSession(String filepath)
1173 String pathUsed = filepath;
1176 if (pathUsed == null)
1178 File tempFile = File.createTempFile("chimera", ".py");
1179 tempFile.deleteOnExit();
1180 pathUsed = tempFile.getPath();
1182 boolean result = jmb.saveSession(pathUsed);
1185 this.chimeraSessionFile = pathUsed;
1188 } catch (IOException e)
1195 * Returns a string representing the state of the Chimera session. This is
1196 * done by requesting Chimera to save its session to a temporary file, then
1197 * reading the file contents. Returns an empty string on any error.
1200 public String getStateInfo()
1202 String sessionFile = saveSession(null);
1203 if (sessionFile == null)
1207 InputStream is = null;
1210 File f = new File(sessionFile);
1211 byte[] bytes = new byte[(int) f.length()];
1212 is = new FileInputStream(sessionFile);
1214 return new String(bytes);
1215 } catch (IOException e)
1225 } catch (IOException e)
1234 protected void fitToWindow_actionPerformed()
1240 public ViewerType getViewerType()
1242 return ViewerType.CHIMERA;
1246 protected AAStructureBindingModel getBindingModel()
1252 protected List<String> getResidueAttributeNames()
1254 return jmb.getResidueAttributes();