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 java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25 import java.awt.event.ItemEvent;
26 import java.awt.event.ItemListener;
27 import java.io.BufferedReader;
29 import java.io.FileOutputStream;
30 import java.io.FileReader;
31 import java.io.IOException;
32 import java.io.PrintWriter;
33 import java.util.ArrayList;
34 import java.util.List;
35 import java.util.Random;
36 import java.util.Vector;
38 import javax.swing.JCheckBoxMenuItem;
39 import javax.swing.JColorChooser;
40 import javax.swing.JInternalFrame;
41 import javax.swing.JMenu;
42 import javax.swing.JMenuItem;
43 import javax.swing.JOptionPane;
44 import javax.swing.event.InternalFrameAdapter;
45 import javax.swing.event.InternalFrameEvent;
46 import javax.swing.event.MenuEvent;
47 import javax.swing.event.MenuListener;
49 import jalview.bin.Cache;
50 import jalview.datamodel.Alignment;
51 import jalview.datamodel.AlignmentI;
52 import jalview.datamodel.ColumnSelection;
53 import jalview.datamodel.PDBEntry;
54 import jalview.datamodel.SequenceI;
55 import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
56 import jalview.io.AppletFormatAdapter;
57 import jalview.io.JalviewFileChooser;
58 import jalview.io.JalviewFileView;
59 import jalview.schemes.BuriedColourScheme;
60 import jalview.schemes.ColourSchemeI;
61 import jalview.schemes.HelixColourScheme;
62 import jalview.schemes.HydrophobicColourScheme;
63 import jalview.schemes.PurinePyrimidineColourScheme;
64 import jalview.schemes.StrandColourScheme;
65 import jalview.schemes.TaylorColourScheme;
66 import jalview.schemes.TurnColourScheme;
67 import jalview.schemes.ZappoColourScheme;
68 import jalview.structures.models.AAStructureBindingModel;
69 import jalview.util.MessageManager;
70 import jalview.util.Platform;
71 import jalview.ws.dbsources.Pdb;
74 * GUI elements for handlnig an external chimera display
79 public class ChimeraViewFrame extends StructureViewerBase
81 private JalviewChimeraBinding jmb;
83 private boolean allChainsSelected = false;
85 private boolean alignAddedStructures = false;
88 * state flag for PDB retrieval thread
90 private boolean _started = false;
92 private boolean addingStructures = false;
94 private IProgressIndicator progressBar = null;
97 * pdb retrieval thread.
99 private Thread worker = null;
102 * Path to Chimera session file. This is set when an open Jalview/Chimera
103 * session is saved, or on restore from a Jalview project (if it holds the
104 * filename of any saved Chimera sessions).
106 private String chimeraSessionFile = null;
108 private Random random = new Random();
111 * Initialise menu options.
113 private void initMenus()
115 viewerActionMenu.setText(MessageManager.getString("label.chimera"));
116 viewerColour.setText(MessageManager
117 .getString("label.colour_with_chimera"));
118 viewerColour.setToolTipText(MessageManager
119 .getString("label.let_chimera_manage_structure_colours"));
120 helpItem.setText(MessageManager.getString("label.chimera_help"));
121 seqColour.setSelected(jmb.isColourBySequence());
122 viewerColour.setSelected(!jmb.isColourBySequence());
123 if (_colourwith == null)
125 _colourwith = new Vector<AlignmentPanel>();
127 if (_alignwith == null)
129 _alignwith = new Vector<AlignmentPanel>();
132 // save As not yet implemented
133 savemenu.setVisible(false);
135 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
136 MessageManager.getString("label.colour_by"), this, _colourwith,
140 public void itemStateChanged(ItemEvent e)
142 if (!seqColour.isSelected())
148 // update the Chimera display now.
149 seqColour_actionPerformed(null);
153 viewMenu.add(seqColourBy);
154 final ItemListener handler;
155 JMenu alpanels = new ViewSelectionMenu(
156 MessageManager.getString("label.superpose_with"), this,
157 _alignwith, handler = new ItemListener()
160 public void itemStateChanged(ItemEvent e)
162 alignStructs.setEnabled(_alignwith.size() > 0);
163 alignStructs.setToolTipText(MessageManager
165 "label.align_structures_using_linked_alignment_views",
167 { new Integer(_alignwith.size()).toString() }));
170 handler.itemStateChanged(null);
171 viewerActionMenu.add(alpanels);
172 viewerActionMenu.addMenuListener(new MenuListener()
176 public void menuSelected(MenuEvent e)
178 handler.itemStateChanged(null);
182 public void menuDeselected(MenuEvent e)
184 // TODO Auto-generated method stub
188 public void menuCanceled(MenuEvent e)
190 // TODO Auto-generated method stub
196 * add a single PDB structure to a new or existing Chimera view
203 public ChimeraViewFrame(PDBEntry pdbentry, SequenceI[] seq,
204 String[] chains, final AlignmentPanel ap)
207 progressBar = ap.alignFrame;
208 // ////////////////////////////////
209 // Is the pdb file already loaded?
210 String alreadyMapped = ap.getStructureSelectionManager()
211 .alreadyMappedToFile(pdbentry.getId());
213 if (alreadyMapped != null)
215 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
216 MessageManager.formatMessage(
217 "label.pdb_entry_is_already_displayed", new Object[]
218 { pdbentry.getId() }), MessageManager.formatMessage(
219 "label.map_sequences_to_visible_window", new Object[]
220 { pdbentry.getId() }),
221 JOptionPane.YES_NO_CANCEL_OPTION);
223 if (option == JOptionPane.CANCEL_OPTION)
227 if (option == JOptionPane.YES_OPTION)
229 // TODO : Fix multiple seq to one chain issue here.
230 ap.getStructureSelectionManager().setMapping(seq, chains,
231 alreadyMapped, AppletFormatAdapter.FILE);
232 if (ap.getSeqPanel().seqCanvas.fr != null)
234 ap.getSeqPanel().seqCanvas.fr.featuresAdded();
235 ap.paintAlignment(true);
238 // Now this ChimeraViewFrame is mapped to new sequences. We must add
239 // them to the existing array
240 JInternalFrame[] frames = Desktop.instance.getAllFrames();
242 for (JInternalFrame frame : frames)
244 if (frame instanceof ChimeraViewFrame)
246 final ChimeraViewFrame topView = ((ChimeraViewFrame) frame);
247 // JBPNOTE: this looks like a binding routine, rather than a gui
249 for (int pe = 0; pe < topView.jmb.getPdbCount(); pe++)
251 if (topView.jmb.getPdbEntry(pe).getFile()
255 topView.jmb.addSequence(pe, seq);
256 topView.addAlignmentPanel(ap);
257 // add it to the set used for colouring
258 topView.useAlignmentPanelForColourbyseq(ap);
259 topView.buildActionMenu();
260 ap.getStructureSelectionManager()
261 .sequenceColoursChanged(ap);
271 // /////////////////////////////////
272 // Check if there are other Chimera views involving this alignment
273 // and prompt user about adding this molecule to one of them
274 List<ChimeraViewFrame> existingViews = getChimeraWindowsFor(ap);
275 for (ChimeraViewFrame topView : existingViews)
277 // TODO: highlight topView in view somehow
279 * JAL-1742 exclude view with this structure already mapped (don't offer
280 * to align chain B to chain A of the same structure)
282 if (topView.hasPdbId(pdbentry.getId()))
286 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
287 MessageManager.formatMessage("label.add_pdbentry_to_view",
289 { pdbentry.getId(), topView.getTitle() }),
291 .getString("label.align_to_existing_structure_view"),
292 JOptionPane.YES_NO_CANCEL_OPTION);
293 if (option == JOptionPane.CANCEL_OPTION)
297 if (option == JOptionPane.YES_OPTION)
299 topView.useAlignmentPanelForSuperposition(ap);
300 topView.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
304 // /////////////////////////////////
305 openNewChimera(ap, new PDBEntry[]
306 { pdbentry }, new SequenceI[][]
311 * Create a helper to manage progress bar display
313 protected void createProgressBar()
315 if (progressBar == null)
317 progressBar = new ProgressBar(statusPanel, statusBar);
321 protected boolean hasPdbId(String pdbId)
323 return jmb.hasPdbId(pdbId);
326 private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
331 jmb = new JalviewChimeraBindingModel(this,
332 ap.getStructureSelectionManager(), pdbentrys, seqs, null, null);
333 addAlignmentPanel(ap);
334 useAlignmentPanelForColourbyseq(ap);
335 if (pdbentrys.length > 1)
337 alignAddedStructures = true;
338 useAlignmentPanelForSuperposition(ap);
340 jmb.setColourBySequence(true);
341 setSize(400, 400); // probably should be a configurable/dynamic default here
344 addingStructures = false;
345 worker = new Thread(this);
348 this.addInternalFrameListener(new InternalFrameAdapter()
350 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
359 * create a new viewer containing several structures superimposed using the
366 public ChimeraViewFrame(AlignmentPanel ap, PDBEntry[] pe,
370 openNewChimera(ap, pe, seqs);
374 * Create a new viewer from saved session state data including Chimera session
377 * @param chimeraSession
382 * @param colourByChimera
383 * @param colourBySequence
385 public ChimeraViewFrame(String chimeraSession, AlignmentPanel alignPanel,
387 SequenceI[][] seqsArray, boolean colourByChimera,
388 boolean colourBySequence)
391 this.chimeraSessionFile = chimeraSession;
392 openNewChimera(alignPanel, pdbArray, seqsArray);
395 jmb.setColourBySequence(false);
396 seqColour.setSelected(false);
397 viewerColour.setSelected(true);
399 else if (colourBySequence)
401 jmb.setColourBySequence(true);
402 seqColour.setSelected(true);
403 viewerColour.setSelected(false);
408 * add a new structure (with associated sequences and chains) to this viewer,
409 * retrieving it if necessary first.
416 * if true, new structure(s) will be align using associated alignment
418 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
419 final String[] chains, final boolean b,
420 final IProgressIndicator alignFrame)
422 if (pdbentry.getFile() == null)
424 if (worker != null && worker.isAlive())
426 // a retrieval is in progress, wait around and add ourselves to the
428 new Thread(new Runnable()
432 while (worker != null && worker.isAlive() && _started)
436 Thread.sleep(100 + ((int) Math.random() * 100));
438 } catch (Exception e)
443 // and call ourselves again.
444 addStructure(pdbentry, seq, chains, b, alignFrame);
450 // otherwise, start adding the structure.
451 jmb.addSequenceAndChain(new PDBEntry[]
452 { pdbentry }, new SequenceI[][]
453 { seq }, new String[][]
455 addingStructures = true;
457 alignAddedStructures = b;
458 progressBar = alignFrame; // visual indication happens on caller frame.
459 (worker = new Thread(this)).start();
463 private List<ChimeraViewFrame> getChimeraWindowsFor(AlignmentPanel apanel)
465 List<ChimeraViewFrame> result = new ArrayList<ChimeraViewFrame>();
466 JInternalFrame[] frames = Desktop.instance.getAllFrames();
468 for (JInternalFrame frame : frames)
470 if (frame instanceof ChimeraViewFrame)
472 if (((StructureViewerBase) frame).isLinkedWith(apanel))
474 result.add((ChimeraViewFrame) frame);
482 * Launch Chimera. If we have a chimera session file name, send Chimera the
483 * command to open its saved session file.
487 jmb.setFinishedInit(false);
488 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle("Chimera", true),
489 getBounds().width, getBounds().height);
492 * Pass an empty 'command' to launch Chimera
494 jmb.evalStateCommand("", false);
496 if (this.chimeraSessionFile != null)
498 boolean opened = jmb.openSession(chimeraSessionFile);
502 .println("An error occurred opening Chimera session file "
503 + chimeraSessionFile);
506 jmb.setFinishedInit(true);
508 jmb.startChimeraListener();
511 void setChainMenuItems(List<String> chainNames)
513 chainMenu.removeAll();
514 if (chainNames == null)
518 JMenuItem menuItem = new JMenuItem(
519 MessageManager.getString("label.all"));
520 menuItem.addActionListener(new ActionListener()
522 public void actionPerformed(ActionEvent evt)
524 allChainsSelected = true;
525 for (int i = 0; i < chainMenu.getItemCount(); i++)
527 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
529 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
533 allChainsSelected = false;
537 chainMenu.add(menuItem);
539 for (String chainName : chainNames)
541 menuItem = new JCheckBoxMenuItem(chainName, true);
542 menuItem.addItemListener(new ItemListener()
544 public void itemStateChanged(ItemEvent evt)
546 if (!allChainsSelected)
553 chainMenu.add(menuItem);
559 List<String> toshow = new ArrayList<String>();
560 for (int i = 0; i < chainMenu.getItemCount(); i++)
562 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
564 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
565 if (item.isSelected())
567 toshow.add(item.getText());
571 jmb.centerViewer(toshow);
575 * Close down this instance of Jalview's Chimera viewer, giving the user the
576 * option to close the associated Chimera window (process). They may wish to
577 * keep it open until they have had an opportunity to save any work.
579 * @param closeChimera
580 * if true, close any linked Chimera process; if false, prompt first
582 public void closeViewer(boolean closeChimera)
584 if (jmb.isChimeraRunning())
588 String prompt = MessageManager.formatMessage(
589 "label.confirm_close_chimera", new Object[]
590 { jmb.getViewerTitle("Chimera", false) });
591 prompt = JvSwingUtils.wrapTooltip(true, prompt);
592 int confirm = JOptionPane.showConfirmDialog(this, prompt,
593 MessageManager.getString("label.close_viewer"),
594 JOptionPane.YES_NO_OPTION);
595 closeChimera = confirm == JOptionPane.YES_OPTION;
597 jmb.closeViewer(closeChimera);
599 setAlignmentPanel(null);
603 // TODO: check for memory leaks where instance isn't finalised because jmb
604 // holds a reference to the window
609 * Open any newly added PDB structures in Chimera, having first fetched data
610 * from PDB (if not already saved).
615 // todo - record which pdbids were successfully imported.
616 StringBuilder errormsgs = new StringBuilder(128);
617 StringBuilder files = new StringBuilder(128);
618 List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
619 List<Integer> filePDBpos = new ArrayList<Integer>();
620 PDBEntry thePdbEntry = null;
623 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
624 // TODO: replace with reference fetching/transfer code (validate PDBentry
626 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
629 thePdbEntry = jmb.getPdbEntry(pi);
630 if (thePdbEntry.getFile() == null)
633 * Retrieve PDB data, save to file, attach to PDBEntry
635 file = fetchPdbFile(thePdbEntry);
638 errormsgs.append("'" + thePdbEntry.getId() + "' ");
644 * Got file already - ignore if already loaded in Chimera.
646 file = new File(thePdbEntry.getFile()).getAbsoluteFile()
648 if (curfiles != null && curfiles.length > 0)
650 addingStructures = true; // already files loaded.
651 for (int c = 0; c < curfiles.length; c++)
653 if (curfiles[c].equals(file))
663 filePDB.add(thePdbEntry);
664 filePDBpos.add(Integer.valueOf(pi));
665 files.append(" \"" + Platform.escapeString(file) + "\"");
668 } catch (OutOfMemoryError oomerror)
670 new OOMWarning("Retrieving PDB files: " + thePdbEntry.getId(),
672 } catch (Exception ex)
674 ex.printStackTrace();
675 errormsgs.append("When retrieving pdbfiles for '"
676 + thePdbEntry.getId() + "'");
678 if (errormsgs.length() > 0)
681 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
682 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
684 { errormsgs.toString() }), MessageManager
685 .getString("label.couldnt_load_file"),
686 JOptionPane.ERROR_MESSAGE);
689 if (files.length() > 0)
691 if (!addingStructures)
696 } catch (Exception ex)
698 Cache.log.error("Couldn't open Chimera viewer!", ex);
702 for (PDBEntry pe : filePDB)
705 if (pe.getFile() != null)
709 int pos = filePDBpos.get(num).intValue();
710 long startTime = startProgressBar("Chimera "
711 + MessageManager.getString("status.opening_file"));
713 jmb.addSequence(pos, jmb.getSequence()[pos]);
714 File fl = new File(pe.getFile());
715 String protocol = AppletFormatAdapter.URL;
720 protocol = AppletFormatAdapter.FILE;
722 } catch (Throwable e)
726 stopProgressBar("", startTime);
728 // Explicitly map to the filename used by Chimera ;
729 // TODO: use pe.getId() instead of pe.getFile() ?
730 jmb.getSsm().setMapping(jmb.getSequence()[pos], null,
733 } catch (OutOfMemoryError oomerror)
736 "When trying to open and map structures from Chimera!",
738 } catch (Exception ex)
740 Cache.log.error("Couldn't open " + pe.getFile()
741 + " in Chimera viewer!", ex);
744 Cache.log.debug("File locations are " + files);
748 jmb.setFinishedInit(true);
749 jmb.setLoadingFromArchive(false);
751 // refresh the sequence colours for the new structure(s)
752 for (AlignmentPanel ap : _colourwith)
754 jmb.updateColours(ap);
756 // do superposition if asked to
757 if (alignAddedStructures)
759 new Thread(new Runnable()
763 alignStructs_withAllAlignPanels();
766 alignAddedStructures = false;
768 addingStructures = false;
775 * Fetch PDB data and save to a local file. Returns the full path to the file,
776 * or null if fetch fails.
778 * @param processingEntry
782 private String fetchPdbFile(PDBEntry processingEntry) throws Exception
784 String filePath = null;
785 Pdb pdbclient = new Pdb();
786 AlignmentI pdbseq = null;
787 String pdbid = processingEntry.getId();
788 long hdl = startProgressBar(MessageManager.formatMessage(
789 "status.fetching_pdb", new Object[]
793 pdbseq = pdbclient.getSequenceRecords(pdbid);
794 } catch (OutOfMemoryError oomerror)
796 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
799 String msg = pdbid + " "
800 + MessageManager.getString("label.state_completed");
801 stopProgressBar(msg, hdl);
804 * If PDB data were saved and are not invalid (empty alignment), return the
807 if (pdbseq != null && pdbseq.getHeight() > 0)
809 // just use the file name from the first sequence's first PDBEntry
810 filePath = new File(pdbseq.getSequenceAt(0).getPDBId()
811 .elementAt(0).getFile()).getAbsolutePath();
812 processingEntry.setFile(filePath);
818 * Convenience method to update the progress bar if there is one. Be sure to
819 * call stopProgressBar with the returned handle to remove the message.
824 public long startProgressBar(String msg)
826 // TODO would rather have startProgress/stopProgress as the
827 // IProgressIndicator interface
828 long tm = random.nextLong();
829 if (progressBar != null)
831 progressBar.setProgressBar(msg, tm);
836 public void stopProgressBar(String msg, long handle)
838 if (progressBar != null)
840 progressBar.setProgressBar(msg, handle);
845 public void pdbFile_actionPerformed(ActionEvent actionEvent)
847 JalviewFileChooser chooser = new JalviewFileChooser(
848 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
850 chooser.setFileView(new JalviewFileView());
851 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
852 chooser.setToolTipText(MessageManager.getString("action.save"));
854 int value = chooser.showSaveDialog(this);
856 if (value == JalviewFileChooser.APPROVE_OPTION)
858 BufferedReader in = null;
861 // TODO: cope with multiple PDB files in view
862 in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
863 File outFile = chooser.getSelectedFile();
865 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
867 while ((data = in.readLine()) != null)
869 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
875 } catch (Exception ex)
877 ex.printStackTrace();
885 } catch (IOException e)
895 public void viewMapping_actionPerformed(ActionEvent actionEvent)
897 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
900 for (int pdbe = 0; pdbe < jmb.getPdbCount(); pdbe++)
902 cap.appendText(jmb.printMapping(jmb.getPdbEntry(pdbe).getFile()));
903 cap.appendText("\n");
905 } catch (OutOfMemoryError e)
908 "composing sequence-structure alignments for display in text box.",
913 jalview.gui.Desktop.addInternalFrame(cap,
914 MessageManager.getString("label.pdb_sequence_mapping"), 550,
919 public void eps_actionPerformed(ActionEvent e)
923 .getString("error.eps_generation_not_implemented"));
927 public void png_actionPerformed(ActionEvent e)
931 .getString("error.png_generation_not_implemented"));
935 public void viewerColour_actionPerformed(ActionEvent actionEvent)
937 if (viewerColour.isSelected())
939 // disable automatic sequence colouring.
940 jmb.setColourBySequence(false);
945 public void seqColour_actionPerformed(ActionEvent actionEvent)
947 jmb.setColourBySequence(seqColour.isSelected());
948 if (_colourwith == null)
950 _colourwith = new Vector<AlignmentPanel>();
952 if (jmb.isColourBySequence())
954 if (!jmb.isLoadingFromArchive())
956 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
958 // Make the currently displayed alignment panel the associated view
959 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
962 // Set the colour using the current view for the associated alignframe
963 for (AlignmentPanel ap : _colourwith)
965 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
971 public void chainColour_actionPerformed(ActionEvent actionEvent)
973 chainColour.setSelected(true);
978 public void chargeColour_actionPerformed(ActionEvent actionEvent)
980 chargeColour.setSelected(true);
981 jmb.colourByCharge();
985 public void zappoColour_actionPerformed(ActionEvent actionEvent)
987 zappoColour.setSelected(true);
988 jmb.setJalviewColourScheme(new ZappoColourScheme());
992 public void taylorColour_actionPerformed(ActionEvent actionEvent)
994 taylorColour.setSelected(true);
995 jmb.setJalviewColourScheme(new TaylorColourScheme());
999 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1001 hydroColour.setSelected(true);
1002 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1006 public void helixColour_actionPerformed(ActionEvent actionEvent)
1008 helixColour.setSelected(true);
1009 jmb.setJalviewColourScheme(new HelixColourScheme());
1013 public void strandColour_actionPerformed(ActionEvent actionEvent)
1015 strandColour.setSelected(true);
1016 jmb.setJalviewColourScheme(new StrandColourScheme());
1020 public void turnColour_actionPerformed(ActionEvent actionEvent)
1022 turnColour.setSelected(true);
1023 jmb.setJalviewColourScheme(new TurnColourScheme());
1027 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1029 buriedColour.setSelected(true);
1030 jmb.setJalviewColourScheme(new BuriedColourScheme());
1034 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1036 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1040 public void userColour_actionPerformed(ActionEvent actionEvent)
1042 userColour.setSelected(true);
1043 new UserDefinedColours(this, null);
1047 public void backGround_actionPerformed(ActionEvent actionEvent)
1049 java.awt.Color col = JColorChooser
1050 .showDialog(this, MessageManager
1051 .getString("label.select_backgroud_colour"), null);
1054 jmb.setBackgroundColour(col);
1059 public void showHelp_actionPerformed(ActionEvent actionEvent)
1063 jalview.util.BrowserLauncher
1064 .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
1065 } catch (Exception ex)
1070 public void updateTitleAndMenus()
1072 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1077 setChainMenuItems(jmb.getChainNames());
1079 this.setTitle(jmb.getViewerTitle("Chimera", true));
1080 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1082 viewerActionMenu.setVisible(true);
1084 if (!jmb.isLoadingFromArchive())
1086 seqColour_actionPerformed(null);
1094 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1098 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1100 alignStructs_withAllAlignPanels();
1103 private void alignStructs_withAllAlignPanels()
1105 if (getAlignmentPanel() == null)
1110 if (_alignwith.size() == 0)
1112 _alignwith.add(getAlignmentPanel());
1117 AlignmentI[] als = new Alignment[_alignwith.size()];
1118 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1119 int[] alm = new int[_alignwith.size()];
1122 for (AlignmentPanel ap : _alignwith)
1124 als[a] = ap.av.getAlignment();
1126 alc[a++] = ap.av.getColumnSelection();
1128 jmb.superposeStructures(als, alm, alc);
1129 } catch (Exception e)
1131 StringBuffer sp = new StringBuffer();
1132 for (AlignmentPanel ap : _alignwith)
1134 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1136 Cache.log.info("Couldn't align structures with the " + sp.toString()
1137 + "associated alignment panels.", e);
1143 public void setJalviewColourScheme(ColourSchemeI ucs)
1145 jmb.setJalviewColourScheme(ucs);
1152 * @return first alignment panel displaying given alignment, or the default
1155 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1157 for (AlignmentPanel ap : getAllAlignmentPanels())
1159 if (ap.av.getAlignment() == alignment)
1164 return getAlignmentPanel();
1168 public AAStructureBindingModel getBinding()
1174 * Ask Chimera to save its session to the designated file path. Returns true
1175 * if successful, else false.
1180 public boolean saveSession(String filepath)
1182 boolean result = jmb.saveSession(filepath);
1185 this.chimeraSessionFile = filepath;
1191 * Returns the file path of the Chimera session file the last time it was
1192 * saved. If it was never saved, returns an empty string. There is no
1193 * guarantee that the Chimera session has not changed since it was saved.
1196 public String getStateInfo()
1198 return this.chimeraSessionFile;