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.ChimeraCommands;
30 import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
31 import jalview.gui.StructureViewer.ViewerType;
32 import jalview.io.AppletFormatAdapter;
33 import jalview.io.JalviewFileChooser;
34 import jalview.io.JalviewFileView;
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.Collections;
65 import java.util.List;
66 import java.util.Random;
67 import java.util.Vector;
69 import javax.swing.JCheckBoxMenuItem;
70 import javax.swing.JColorChooser;
71 import javax.swing.JInternalFrame;
72 import javax.swing.JMenu;
73 import javax.swing.JMenuItem;
74 import javax.swing.JOptionPane;
75 import javax.swing.event.InternalFrameAdapter;
76 import javax.swing.event.InternalFrameEvent;
77 import javax.swing.event.MenuEvent;
78 import javax.swing.event.MenuListener;
81 * GUI elements for handling an external chimera display
86 public class ChimeraViewFrame extends StructureViewerBase
88 private JalviewChimeraBinding jmb;
90 private boolean allChainsSelected = false;
92 private IProgressIndicator progressBar = null;
95 * Path to Chimera session file. This is set when an open Jalview/Chimera
96 * session is saved, or on restore from a Jalview project (if it holds the
97 * filename of any saved Chimera sessions).
99 private String chimeraSessionFile = null;
101 private Random random = new Random();
104 * Initialise menu options.
106 private void initMenus()
108 viewerActionMenu.setText(MessageManager.getString("label.chimera"));
109 viewerColour.setText(MessageManager
110 .getString("label.colour_with_chimera"));
111 viewerColour.setToolTipText(MessageManager
112 .getString("label.let_chimera_manage_structure_colours"));
113 helpItem.setText(MessageManager.getString("label.chimera_help"));
114 seqColour.setSelected(jmb.isColourBySequence());
115 viewerColour.setSelected(!jmb.isColourBySequence());
116 if (_colourwith == null)
118 _colourwith = new Vector<AlignmentPanel>();
120 if (_alignwith == null)
122 _alignwith = new Vector<AlignmentPanel>();
125 // save As not yet implemented
126 savemenu.setVisible(false);
128 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
129 MessageManager.getString("label.colour_by"), this, _colourwith,
133 public void itemStateChanged(ItemEvent e)
135 if (!seqColour.isSelected())
141 // update the Chimera display now.
142 seqColour_actionPerformed(null);
146 viewMenu.add(seqColourBy);
147 viewMenu.add(fitToWindow);
149 final ItemListener handler;
150 JMenu alpanels = new ViewSelectionMenu(
151 MessageManager.getString("label.superpose_with"), this,
152 _alignwith, handler = new ItemListener()
155 public void itemStateChanged(ItemEvent e)
157 alignStructs.setEnabled(_alignwith.size() > 0);
158 alignStructs.setToolTipText(MessageManager
160 "label.align_structures_using_linked_alignment_views",
161 new Object[] { new Integer(_alignwith
162 .size()).toString() }));
165 handler.itemStateChanged(null);
166 viewerActionMenu.add(alpanels);
167 viewerActionMenu.addMenuListener(new MenuListener()
171 public void menuSelected(MenuEvent e)
173 handler.itemStateChanged(null);
177 public void menuDeselected(MenuEvent e)
179 // TODO Auto-generated method stub
183 public void menuCanceled(MenuEvent e)
185 // TODO Auto-generated method stub
189 JMenuItem writeFeatures = new JMenuItem(
190 MessageManager.getString("label.create_chimera_attributes"));
191 writeFeatures.setToolTipText(MessageManager
192 .getString("label.create_chimera_attributes_tip"));
193 writeFeatures.addActionListener(new ActionListener()
196 public void actionPerformed(ActionEvent e)
198 sendFeaturesToChimera();
201 viewerActionMenu.add(writeFeatures);
203 final JMenu fetchAttributes = new JMenu("Fetch Chimera attributes");
205 .setToolTipText("Copy Chimera attribute to Jalview feature");
206 fetchAttributes.addMouseListener(new MouseAdapter()
210 public void mouseEntered(MouseEvent e)
212 buildAttributesMenu(fetchAttributes);
215 viewerActionMenu.add(fetchAttributes);
220 * Query Chimera for its residue attribute names and add them as items off the
223 * @param attributesMenu
225 protected void buildAttributesMenu(JMenu attributesMenu)
227 List<String> atts = jmb.sendChimeraCommand("list resattr", true);
232 attributesMenu.removeAll();
233 Collections.sort(atts);
234 for (String att : atts)
236 final String attName = att.split(" ")[1];
239 * ignore 'jv_*' attributes, as these are Jalview features that have
240 * been transferred to residue attributes in Chimera!
242 if (!attName.startsWith(ChimeraCommands.NAMESPACE_PREFIX))
244 JMenuItem menuItem = new JMenuItem(attName);
245 menuItem.addActionListener(new ActionListener()
248 public void actionPerformed(ActionEvent e)
250 getChimeraAttributes(attName);
253 attributesMenu.add(menuItem);
259 * Read residues in Chimera with the given attribute name, and set as features
260 * on the corresponding sequence positions (if any)
264 protected void getChimeraAttributes(String attName)
266 jmb.copyStructureAttributesToFeatures(attName, getAlignmentPanel());
270 * Send a command to Chimera to create residue attributes for Jalview features
272 * The syntax is: setattr r <attName> <attValue> <atomSpec>
274 * For example: setattr r jv:chain "Ferredoxin-1, Chloroplastic" #0:94.A
276 protected void sendFeaturesToChimera()
278 jmb.sendFeaturesToViewer(getAlignmentPanel());
282 * add a single PDB structure to a new or existing Chimera view
289 public ChimeraViewFrame(PDBEntry pdbentry, SequenceI[] seq,
290 String[] chains, final AlignmentPanel ap)
293 String pdbId = pdbentry.getId();
296 * If the PDB file is already loaded, the user may just choose to add to an
297 * existing viewer (or cancel)
299 if (addAlreadyLoadedFile(seq, chains, ap, pdbId))
305 * Check if there are other Chimera views involving this alignment and give
306 * user the option to add and align this molecule to one of them (or cancel)
308 if (addToExistingViewer(pdbentry, seq, chains, ap, pdbId))
314 * If the options above are declined or do not apply, show the structure in
317 openNewChimera(ap, new PDBEntry[] { pdbentry },
318 new SequenceI[][] { seq });
322 * Create a helper to manage progress bar display
324 protected void createProgressBar()
326 if (progressBar == null)
328 progressBar = new ProgressBar(statusPanel, statusBar);
333 * Answers true if this viewer already involves the given PDB ID
336 protected boolean hasPdbId(String pdbId)
338 return jmb.hasPdbId(pdbId);
341 private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
345 // FIXME extractChains needs pdbentries to match IDs to PDBEntry(s) on seqs
346 String[][] chains = extractChains(seqs);
347 jmb = new JalviewChimeraBindingModel(this,
348 ap.getStructureSelectionManager(), pdbentrys, seqs, chains,
350 addAlignmentPanel(ap);
351 useAlignmentPanelForColourbyseq(ap);
352 if (pdbentrys.length > 1)
354 alignAddedStructures = true;
355 useAlignmentPanelForSuperposition(ap);
357 jmb.setColourBySequence(true);
358 setSize(400, 400); // probably should be a configurable/dynamic default here
361 addingStructures = false;
362 worker = new Thread(this);
365 this.addInternalFrameListener(new InternalFrameAdapter()
368 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
377 * Retrieve chains for sequences by inspecting their PDB refs. The hope is
378 * that the first will be to the sequence's own chain. Really need a more
379 * managed way of doing this.
384 protected String[][] extractChains(SequenceI[][] seqs)
386 String[][] chains = new String[seqs.length][];
387 for (int i = 0; i < seqs.length; i++)
389 chains[i] = new String[seqs[i].length];
391 for (SequenceI seq : seqs[i])
394 if (seq.getDatasetSequence() != null)
396 Vector<PDBEntry> pdbrefs = seq.getDatasetSequence()
398 if (pdbrefs != null && pdbrefs.size() > 0)
400 // FIXME: SequenceI.PDBEntry[0] chain mapping used for
401 // ChimeraViewFrame. Is this even used ???
403 chain = pdbrefs.get(0).getChainCode();
406 chains[i][seqno++] = chain;
413 * Create a new viewer from saved session state data including Chimera session
416 * @param chimeraSessionFile
420 * @param colourByChimera
421 * @param colourBySequence
424 public ChimeraViewFrame(String chimeraSessionFile,
425 AlignmentPanel alignPanel, PDBEntry[] pdbArray,
426 SequenceI[][] seqsArray, boolean colourByChimera,
427 boolean colourBySequence, String newViewId)
430 setViewId(newViewId);
431 this.chimeraSessionFile = chimeraSessionFile;
432 openNewChimera(alignPanel, pdbArray, seqsArray);
435 jmb.setColourBySequence(false);
436 seqColour.setSelected(false);
437 viewerColour.setSelected(true);
439 else if (colourBySequence)
441 jmb.setColourBySequence(true);
442 seqColour.setSelected(true);
443 viewerColour.setSelected(false);
448 * create a new viewer containing several structures superimposed using the
455 public ChimeraViewFrame(PDBEntry[] pe, SequenceI[][] seqs,
459 openNewChimera(ap, pe, seqs);
463 * Default constructor
465 public ChimeraViewFrame()
470 * closeViewer will decide whether or not to close this frame
471 * depending on whether user chooses to Cancel or not
473 setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
477 * Returns a list of any Chimera viewers in the desktop. The list is
478 * restricted to those linked to the given alignment panel if it is not null.
481 protected List<StructureViewerBase> getViewersFor(AlignmentPanel ap)
483 List<StructureViewerBase> result = new ArrayList<StructureViewerBase>();
484 JInternalFrame[] frames = Desktop.instance.getAllFrames();
486 for (JInternalFrame frame : frames)
488 if (frame instanceof ChimeraViewFrame)
490 if (ap == null || ((StructureViewerBase) frame).isLinkedWith(ap))
492 result.add((StructureViewerBase) frame);
500 * Launch Chimera. If we have a chimera session file name, send Chimera the
501 * command to open its saved session file.
505 jalview.gui.Desktop.addInternalFrame(this,
506 jmb.getViewerTitle("Chimera", true), getBounds().width,
509 if (!jmb.launchChimera())
511 JOptionPane.showMessageDialog(Desktop.desktop,
512 MessageManager.getString("label.chimera_failed"),
513 MessageManager.getString("label.error_loading_file"),
514 JOptionPane.ERROR_MESSAGE);
519 if (this.chimeraSessionFile != null)
521 boolean opened = jmb.openSession(chimeraSessionFile);
525 .println("An error occurred opening Chimera session file "
526 + chimeraSessionFile);
530 jmb.startChimeraListener();
534 * If the list is not empty, add menu items for 'All' and each individual
535 * chain to the "View | Show Chain" sub-menu. Multiple selections are allowed.
539 void setChainMenuItems(List<String> chainNames)
541 chainMenu.removeAll();
542 if (chainNames == null || chainNames.isEmpty())
546 JMenuItem menuItem = new JMenuItem(
547 MessageManager.getString("label.all"));
548 menuItem.addActionListener(new ActionListener()
551 public void actionPerformed(ActionEvent evt)
553 allChainsSelected = true;
554 for (int i = 0; i < chainMenu.getItemCount(); i++)
556 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
558 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
561 showSelectedChains();
562 allChainsSelected = false;
566 chainMenu.add(menuItem);
568 for (String chainName : chainNames)
570 menuItem = new JCheckBoxMenuItem(chainName, true);
571 menuItem.addItemListener(new ItemListener()
574 public void itemStateChanged(ItemEvent evt)
576 if (!allChainsSelected)
578 showSelectedChains();
583 chainMenu.add(menuItem);
588 * Show only the selected chain(s) in the viewer
590 void showSelectedChains()
592 List<String> toshow = new ArrayList<String>();
593 for (int i = 0; i < chainMenu.getItemCount(); i++)
595 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
597 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
598 if (item.isSelected())
600 toshow.add(item.getText());
604 jmb.showChains(toshow);
608 * Close down this instance of Jalview's Chimera viewer, giving the user the
609 * option to close the associated Chimera window (process). They may wish to
610 * keep it open until they have had an opportunity to save any work.
612 * @param closeChimera
613 * if true, close any linked Chimera process; if false, prompt first
616 public void closeViewer(boolean closeChimera)
618 if (jmb != null && jmb.isChimeraRunning())
622 String prompt = MessageManager.formatMessage(
623 "label.confirm_close_chimera",
624 new Object[] { jmb.getViewerTitle("Chimera", false) });
625 prompt = JvSwingUtils.wrapTooltip(true, prompt);
626 int confirm = JOptionPane.showConfirmDialog(this, prompt,
627 MessageManager.getString("label.close_viewer"),
628 JOptionPane.YES_NO_CANCEL_OPTION);
630 * abort closure if user hits escape or Cancel
632 if (confirm == JOptionPane.CANCEL_OPTION
633 || confirm == JOptionPane.CLOSED_OPTION)
637 closeChimera = confirm == JOptionPane.YES_OPTION;
639 jmb.closeViewer(closeChimera);
641 setAlignmentPanel(null);
645 // TODO: check for memory leaks where instance isn't finalised because jmb
646 // holds a reference to the window
652 * Open any newly added PDB structures in Chimera, having first fetched data
653 * from PDB (if not already saved).
659 // todo - record which pdbids were successfully imported.
660 StringBuilder errormsgs = new StringBuilder(128);
661 StringBuilder files = new StringBuilder(128);
662 List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
663 List<Integer> filePDBpos = new ArrayList<Integer>();
664 PDBEntry thePdbEntry = null;
667 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
668 // TODO: replace with reference fetching/transfer code (validate PDBentry
670 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
673 thePdbEntry = jmb.getPdbEntry(pi);
674 if (thePdbEntry.getFile() == null)
677 * Retrieve PDB data, save to file, attach to PDBEntry
679 file = fetchPdbFile(thePdbEntry);
682 errormsgs.append("'" + thePdbEntry.getId() + "' ");
688 * Got file already - ignore if already loaded in Chimera.
690 file = new File(thePdbEntry.getFile()).getAbsoluteFile()
692 if (curfiles != null && curfiles.length > 0)
694 addingStructures = true; // already files loaded.
695 for (int c = 0; c < curfiles.length; c++)
697 if (curfiles[c].equals(file))
707 filePDB.add(thePdbEntry);
708 filePDBpos.add(Integer.valueOf(pi));
709 files.append(" \"" + Platform.escapeString(file) + "\"");
712 } catch (OutOfMemoryError oomerror)
714 new OOMWarning("Retrieving PDB files: " + thePdbEntry.getId(),
716 } catch (Exception ex)
718 ex.printStackTrace();
719 errormsgs.append("When retrieving pdbfiles for '"
720 + thePdbEntry.getId() + "'");
722 if (errormsgs.length() > 0)
725 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
726 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
727 new Object[] { errormsgs.toString() }),
728 MessageManager.getString("label.couldnt_load_file"),
729 JOptionPane.ERROR_MESSAGE);
732 if (files.length() > 0)
734 jmb.setFinishedInit(false);
735 if (!addingStructures)
740 } catch (Exception ex)
742 Cache.log.error("Couldn't open Chimera viewer!", ex);
747 for (PDBEntry pe : filePDB)
750 if (pe.getFile() != null)
754 int pos = filePDBpos.get(num).intValue();
755 long startTime = startProgressBar("Chimera "
756 + MessageManager.getString("status.opening_file_for")
759 jmb.addSequence(pos, jmb.getSequence()[pos]);
760 File fl = new File(pe.getFile());
761 String protocol = AppletFormatAdapter.URL;
766 protocol = AppletFormatAdapter.FILE;
768 } catch (Throwable e)
772 stopProgressBar("", startTime);
774 // Explicitly map to the filename used by Chimera ;
775 jmb.getSsm().setMapping(jmb.getSequence()[pos],
776 jmb.getChains()[pos], pe.getFile(), protocol);
777 } catch (OutOfMemoryError oomerror)
780 "When trying to open and map structures from Chimera!",
782 } catch (Exception ex)
784 Cache.log.error("Couldn't open " + pe.getFile()
785 + " in Chimera viewer!", ex);
788 Cache.log.debug("File locations are " + files);
793 jmb.setFinishedInit(true);
794 jmb.setLoadingFromArchive(false);
796 // refresh the sequence colours for the new structure(s)
797 for (AlignmentPanel ap : _colourwith)
799 jmb.updateColours(ap);
801 // do superposition if asked to
802 if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures)
804 new Thread(new Runnable()
809 alignStructs_withAllAlignPanels();
812 alignAddedStructures = false;
814 addingStructures = false;
821 * Fetch PDB data and save to a local file. Returns the full path to the file,
822 * or null if fetch fails.
824 * @param processingEntry
828 private String fetchPdbFile(PDBEntry processingEntry) throws Exception
830 // FIXME: this is duplicated code with Jmol frame ?
831 String filePath = null;
832 Pdb pdbclient = new Pdb();
833 AlignmentI pdbseq = null;
834 String pdbid = processingEntry.getId();
835 long handle = System.currentTimeMillis()
836 + Thread.currentThread().hashCode();
839 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
841 String msg = MessageManager.formatMessage("status.fetching_pdb",
842 new Object[] { pdbid });
843 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
844 // long hdl = startProgressBar(MessageManager.formatMessage(
845 // "status.fetching_pdb", new Object[]
849 pdbseq = pdbclient.getSequenceRecords(pdbid);
850 } catch (OutOfMemoryError oomerror)
852 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
855 msg = pdbid + " " + MessageManager.getString("label.state_completed");
856 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
857 // stopProgressBar(msg, hdl);
860 * If PDB data were saved and are not invalid (empty alignment), return the
863 if (pdbseq != null && pdbseq.getHeight() > 0)
865 // just use the file name from the first sequence's first PDBEntry
866 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
867 .elementAt(0).getFile()).getAbsolutePath();
868 processingEntry.setFile(filePath);
874 * Convenience method to update the progress bar if there is one. Be sure to
875 * call stopProgressBar with the returned handle to remove the message.
880 public long startProgressBar(String msg)
882 // TODO would rather have startProgress/stopProgress as the
883 // IProgressIndicator interface
884 long tm = random.nextLong();
885 if (progressBar != null)
887 progressBar.setProgressBar(msg, tm);
893 * End the progress bar with the specified handle, leaving a message (if not
894 * null) on the status bar
899 public void stopProgressBar(String msg, long handle)
901 if (progressBar != null)
903 progressBar.setProgressBar(msg, handle);
908 public void pdbFile_actionPerformed(ActionEvent actionEvent)
910 JalviewFileChooser chooser = new JalviewFileChooser(
911 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
913 chooser.setFileView(new JalviewFileView());
914 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
915 chooser.setToolTipText(MessageManager.getString("action.save"));
917 int value = chooser.showSaveDialog(this);
919 if (value == JalviewFileChooser.APPROVE_OPTION)
921 BufferedReader in = null;
924 // TODO: cope with multiple PDB files in view
925 in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
926 File outFile = chooser.getSelectedFile();
928 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
930 while ((data = in.readLine()) != null)
932 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
938 } catch (Exception ex)
940 ex.printStackTrace();
948 } catch (IOException e)
958 public void viewMapping_actionPerformed(ActionEvent actionEvent)
960 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
963 cap.appendText(jmb.printMappings());
964 } catch (OutOfMemoryError e)
967 "composing sequence-structure alignments for display in text box.",
972 jalview.gui.Desktop.addInternalFrame(cap,
973 MessageManager.getString("label.pdb_sequence_mapping"), 550,
978 public void eps_actionPerformed(ActionEvent e)
982 .getString("error.eps_generation_not_implemented"));
986 public void png_actionPerformed(ActionEvent e)
990 .getString("error.png_generation_not_implemented"));
994 public void viewerColour_actionPerformed(ActionEvent actionEvent)
996 if (viewerColour.isSelected())
998 // disable automatic sequence colouring.
999 jmb.setColourBySequence(false);
1004 public void seqColour_actionPerformed(ActionEvent actionEvent)
1006 jmb.setColourBySequence(seqColour.isSelected());
1007 if (_colourwith == null)
1009 _colourwith = new Vector<AlignmentPanel>();
1011 if (jmb.isColourBySequence())
1013 if (!jmb.isLoadingFromArchive())
1015 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
1017 // Make the currently displayed alignment panel the associated view
1018 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
1021 // Set the colour using the current view for the associated alignframe
1022 for (AlignmentPanel ap : _colourwith)
1024 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
1030 public void chainColour_actionPerformed(ActionEvent actionEvent)
1032 chainColour.setSelected(true);
1033 jmb.colourByChain();
1037 public void chargeColour_actionPerformed(ActionEvent actionEvent)
1039 chargeColour.setSelected(true);
1040 jmb.colourByCharge();
1044 public void zappoColour_actionPerformed(ActionEvent actionEvent)
1046 zappoColour.setSelected(true);
1047 jmb.setJalviewColourScheme(new ZappoColourScheme());
1051 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1053 taylorColour.setSelected(true);
1054 jmb.setJalviewColourScheme(new TaylorColourScheme());
1058 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1060 hydroColour.setSelected(true);
1061 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1065 public void helixColour_actionPerformed(ActionEvent actionEvent)
1067 helixColour.setSelected(true);
1068 jmb.setJalviewColourScheme(new HelixColourScheme());
1072 public void strandColour_actionPerformed(ActionEvent actionEvent)
1074 strandColour.setSelected(true);
1075 jmb.setJalviewColourScheme(new StrandColourScheme());
1079 public void turnColour_actionPerformed(ActionEvent actionEvent)
1081 turnColour.setSelected(true);
1082 jmb.setJalviewColourScheme(new TurnColourScheme());
1086 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1088 buriedColour.setSelected(true);
1089 jmb.setJalviewColourScheme(new BuriedColourScheme());
1093 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1095 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1099 public void userColour_actionPerformed(ActionEvent actionEvent)
1101 userColour.setSelected(true);
1102 new UserDefinedColours(this, null);
1106 public void backGround_actionPerformed(ActionEvent actionEvent)
1108 java.awt.Color col = JColorChooser
1109 .showDialog(this, MessageManager
1110 .getString("label.select_backgroud_colour"), null);
1113 jmb.setBackgroundColour(col);
1118 public void showHelp_actionPerformed(ActionEvent actionEvent)
1122 jalview.util.BrowserLauncher
1123 .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
1124 } catch (Exception ex)
1129 public void updateTitleAndMenus()
1131 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1136 setChainMenuItems(jmb.getChainNames());
1138 this.setTitle(jmb.getViewerTitle("Chimera", true));
1139 // if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1141 viewerActionMenu.setVisible(true);
1143 if (!jmb.isLoadingFromArchive())
1145 seqColour_actionPerformed(null);
1153 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1157 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1159 alignStructs_withAllAlignPanels();
1162 private void alignStructs_withAllAlignPanels()
1164 if (getAlignmentPanel() == null)
1169 if (_alignwith.size() == 0)
1171 _alignwith.add(getAlignmentPanel());
1176 AlignmentI[] als = new Alignment[_alignwith.size()];
1177 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1178 int[] alm = new int[_alignwith.size()];
1181 for (AlignmentPanel ap : _alignwith)
1183 als[a] = ap.av.getAlignment();
1185 alc[a++] = ap.av.getColumnSelection();
1187 jmb.superposeStructures(als, alm, alc);
1188 } catch (Exception e)
1190 StringBuffer sp = new StringBuffer();
1191 for (AlignmentPanel ap : _alignwith)
1193 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1195 Cache.log.info("Couldn't align structures with the " + sp.toString()
1196 + "associated alignment panels.", e);
1201 public void setJalviewColourScheme(ColourSchemeI ucs)
1203 jmb.setJalviewColourScheme(ucs);
1210 * @return first alignment panel displaying given alignment, or the default
1213 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1215 for (AlignmentPanel ap : getAllAlignmentPanels())
1217 if (ap.av.getAlignment() == alignment)
1222 return getAlignmentPanel();
1226 public AAStructureBindingModel getBinding()
1232 * Ask Chimera to save its session to the designated file path, or to a
1233 * temporary file if the path is null. Returns the file path if successful,
1239 protected String saveSession(String filepath)
1241 String pathUsed = filepath;
1244 if (pathUsed == null)
1246 File tempFile = File.createTempFile("chimera", ".py");
1247 tempFile.deleteOnExit();
1248 pathUsed = tempFile.getPath();
1250 boolean result = jmb.saveSession(pathUsed);
1253 this.chimeraSessionFile = pathUsed;
1256 } catch (IOException e)
1263 * Returns a string representing the state of the Chimera session. This is
1264 * done by requesting Chimera to save its session to a temporary file, then
1265 * reading the file contents. Returns an empty string on any error.
1268 public String getStateInfo()
1270 String sessionFile = saveSession(null);
1271 if (sessionFile == null)
1275 InputStream is = null;
1278 File f = new File(sessionFile);
1279 byte[] bytes = new byte[(int) f.length()];
1280 is = new FileInputStream(sessionFile);
1282 return new String(bytes);
1283 } catch (IOException e)
1293 } catch (IOException e)
1302 protected void fitToWindow_actionPerformed()
1308 public ViewerType getViewerType()
1310 return ViewerType.CHIMERA;
1314 protected AAStructureBindingModel getBindingModel()