2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.ViewSelectionMenu.ViewSetProvider;
31 import jalview.io.AppletFormatAdapter;
32 import jalview.io.JalviewFileChooser;
33 import jalview.io.JalviewFileView;
34 import jalview.jbgui.GStructureViewer;
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.Component;
50 import java.awt.event.ActionEvent;
51 import java.awt.event.ActionListener;
52 import java.awt.event.ItemEvent;
53 import java.awt.event.ItemListener;
54 import java.io.BufferedReader;
56 import java.io.FileOutputStream;
57 import java.io.FileReader;
58 import java.io.IOException;
59 import java.io.PrintWriter;
60 import java.util.ArrayList;
61 import java.util.List;
62 import java.util.Vector;
64 import javax.swing.JCheckBoxMenuItem;
65 import javax.swing.JColorChooser;
66 import javax.swing.JInternalFrame;
67 import javax.swing.JMenu;
68 import javax.swing.JMenuItem;
69 import javax.swing.JOptionPane;
70 import javax.swing.event.InternalFrameAdapter;
71 import javax.swing.event.InternalFrameEvent;
72 import javax.swing.event.MenuEvent;
73 import javax.swing.event.MenuListener;
76 * GUI elements for handlnig an external chimera display
81 public class ChimeraViewFrame extends GStructureViewer implements Runnable,
84 private JalviewChimeraBinding jmb;
86 private boolean allChainsSelected = false;
88 private boolean alignAddedStructures = false;
93 * state flag for PDB retrieval thread
95 private boolean _started = false;
97 private boolean addingStructures = false;
99 private IProgressIndicator progressBar = null;
102 * pdb retrieval thread.
104 private Thread worker = null;
107 * Initialise menu options.
109 private void initMenus()
111 viewerActionMenu.setText(MessageManager.getString("label.chimera"));
112 viewerColour.setText(MessageManager
113 .getString("label.colour_with_chimera"));
114 viewerColour.setToolTipText(MessageManager
115 .getString("label.let_chimera_manage_structure_colours"));
116 helpItem.setText(MessageManager.getString("label.chimera_help"));
117 seqColour.setSelected(jmb.isColourBySequence());
118 viewerColour.setSelected(!jmb.isColourBySequence());
119 if (_colourwith == null)
121 _colourwith = new Vector<AlignmentPanel>();
123 if (_alignwith == null)
125 _alignwith = new Vector<AlignmentPanel>();
128 // save As not yet implemented
129 savemenu.setVisible(false);
131 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
132 MessageManager.getString("label.colour_by"), this, _colourwith,
136 public void itemStateChanged(ItemEvent e)
138 if (!seqColour.isSelected())
144 // update the Chimera display now.
145 seqColour_actionPerformed(null);
149 viewMenu.add(seqColourBy);
150 final ItemListener handler;
151 JMenu alpanels = new ViewSelectionMenu(
152 MessageManager.getString("label.superpose_with"), this,
153 _alignwith, handler = new ItemListener()
156 public void itemStateChanged(ItemEvent e)
158 alignStructs.setEnabled(_alignwith.size() > 0);
159 alignStructs.setToolTipText(MessageManager
161 "label.align_structures_using_linked_alignment_views",
163 { new Integer(_alignwith.size()).toString() }));
166 handler.itemStateChanged(null);
167 viewerActionMenu.add(alpanels);
168 viewerActionMenu.addMenuListener(new MenuListener()
172 public void menuSelected(MenuEvent e)
174 handler.itemStateChanged(null);
178 public void menuDeselected(MenuEvent e)
180 // TODO Auto-generated method stub
184 public void menuCanceled(MenuEvent e)
186 // TODO Auto-generated method stub
192 * add a single PDB structure to a new or existing Chimera view
199 public ChimeraViewFrame(PDBEntry pdbentry, SequenceI[] seq,
200 String[] chains, final AlignmentPanel ap)
203 progressBar = ap.alignFrame;
204 // ////////////////////////////////
205 // Is the pdb file already loaded?
206 String alreadyMapped = ap.getStructureSelectionManager()
207 .alreadyMappedToFile(pdbentry.getId());
209 if (alreadyMapped != null)
211 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
212 MessageManager.formatMessage(
213 "label.pdb_entry_is_already_displayed", new Object[]
214 { pdbentry.getId() }), MessageManager.formatMessage(
215 "label.map_sequences_to_visible_window", new Object[]
216 { pdbentry.getId() }),
217 JOptionPane.YES_NO_CANCEL_OPTION);
219 if (option == JOptionPane.CANCEL_OPTION)
223 if (option == JOptionPane.YES_OPTION)
225 // TODO : Fix multiple seq to one chain issue here.
226 ap.getStructureSelectionManager().setMapping(seq, chains,
227 alreadyMapped, AppletFormatAdapter.FILE);
228 if (ap.getSeqPanel().seqCanvas.fr != null)
230 ap.getSeqPanel().seqCanvas.fr.featuresAdded();
231 ap.paintAlignment(true);
234 // Now this ChimeraViewFrame is mapped to new sequences. We must add
235 // them to the existing array
236 JInternalFrame[] frames = Desktop.instance.getAllFrames();
238 for (JInternalFrame frame : frames)
240 if (frame instanceof ChimeraViewFrame)
242 final ChimeraViewFrame topView = ((ChimeraViewFrame) frame);
243 // JBPNOTE: this looks like a binding routine, rather than a gui
245 for (int pe = 0; pe < topView.jmb.getPdbCount(); pe++)
247 if (topView.jmb.getPdbEntry(pe).getFile()
251 topView.jmb.addSequence(pe, seq);
252 topView.addAlignmentPanel(ap);
253 // add it to the set used for colouring
254 topView.useAlignmentPanelForColourbyseq(ap);
255 topView.buildChimeraActionMenu();
256 ap.getStructureSelectionManager()
257 .sequenceColoursChanged(ap);
267 // /////////////////////////////////
268 // Check if there are other Chimera views involving this alignment
269 // and prompt user about adding this molecule to one of them
270 List<ChimeraViewFrame> existingViews = getChimeraWindowsFor(ap);
271 for (ChimeraViewFrame topView : existingViews)
273 // TODO: highlight topView in view somehow
274 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
275 MessageManager.formatMessage("label.add_pdbentry_to_view",
277 { pdbentry.getId(), topView.getTitle() }),
279 .getString("label.align_to_existing_structure_view"),
280 JOptionPane.YES_NO_CANCEL_OPTION);
281 if (option == JOptionPane.CANCEL_OPTION)
285 if (option == JOptionPane.YES_OPTION)
287 topView.useAlignmentPanelForSuperposition(ap);
288 topView.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
292 // /////////////////////////////////
293 openNewChimera(ap, new PDBEntry[]
294 { pdbentry }, new SequenceI[][]
298 private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
301 progressBar = ap.alignFrame;
302 jmb = new JalviewChimeraBindingModel(this,
303 ap.getStructureSelectionManager(), pdbentrys, seqs, null, 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
316 addingStructures = false;
317 worker = new Thread(this);
320 this.addInternalFrameListener(new InternalFrameAdapter()
322 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
331 * create a new viewer containing several structures superimposed using the
338 public ChimeraViewFrame(AlignmentPanel ap, PDBEntry[] pe,
342 openNewChimera(ap, pe, seqs);
345 public AlignmentPanel[] getAllAlignmentPanels()
347 AlignmentPanel[] t, list = new AlignmentPanel[0];
348 for (String setid : _aps)
350 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
353 t = new AlignmentPanel[list.length + panels.length];
354 System.arraycopy(list, 0, t, 0, list.length);
355 System.arraycopy(panels, 0, t, list.length, panels.length);
364 * set the primary alignmentPanel reference and add another alignPanel to the
365 * list of ones to use for colouring and aligning
369 public void addAlignmentPanel(AlignmentPanel nap)
375 if (!_aps.contains(nap.av.getSequenceSetId()))
377 _aps.add(nap.av.getSequenceSetId());
382 * remove any references held to the given alignment panel
386 public void removeAlignmentPanel(AlignmentPanel nap)
390 _alignwith.remove(nap);
391 _colourwith.remove(nap);
395 for (AlignmentPanel aps : getAllAlignmentPanels())
404 } catch (Exception ex)
409 buildChimeraActionMenu();
413 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
415 addAlignmentPanel(nap);
416 if (!_alignwith.contains(nap))
422 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
424 if (_alignwith.contains(nap))
426 _alignwith.remove(nap);
430 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
431 boolean enableColourBySeq)
433 useAlignmentPanelForColourbyseq(nap);
434 jmb.setColourBySequence(enableColourBySeq);
435 seqColour.setSelected(enableColourBySeq);
436 viewerColour.setSelected(!enableColourBySeq);
439 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
441 addAlignmentPanel(nap);
442 if (!_colourwith.contains(nap))
444 _colourwith.add(nap);
448 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
450 if (_colourwith.contains(nap))
452 _colourwith.remove(nap);
457 * add a new structure (with associated sequences and chains) to this viewer,
458 * retrieving it if necessary first.
465 * if true, new structure(s) will be align using associated alignment
467 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
468 final String[] chains, final boolean b,
469 final IProgressIndicator alignFrame)
471 if (pdbentry.getFile() == null)
473 if (worker != null && worker.isAlive())
475 // a retrieval is in progress, wait around and add ourselves to the
477 new Thread(new Runnable()
481 while (worker != null && worker.isAlive() && _started)
485 Thread.sleep(100 + ((int) Math.random() * 100));
487 } catch (Exception e)
492 // and call ourselves again.
493 addStructure(pdbentry, seq, chains, b, alignFrame);
499 // otherwise, start adding the structure.
500 jmb.addSequenceAndChain(new PDBEntry[]
501 { pdbentry }, new SequenceI[][]
502 { seq }, new String[][]
504 addingStructures = true;
506 alignAddedStructures = b;
507 progressBar = alignFrame; // visual indication happens on caller frame.
508 (worker = new Thread(this)).start();
512 private List<ChimeraViewFrame> getChimeraWindowsFor(AlignmentPanel apanel)
514 List<ChimeraViewFrame> result = new ArrayList<ChimeraViewFrame>();
515 JInternalFrame[] frames = Desktop.instance.getAllFrames();
517 for (JInternalFrame frame : frames)
519 if (frame instanceof ChimeraViewFrame)
521 if (((ChimeraViewFrame) frame).isLinkedWith(apanel))
523 result.add((ChimeraViewFrame) frame);
530 void initChimera(String command)
532 jmb.setFinishedInit(false);
533 // TODO: consider waiting until the structure/view is fully loaded before
535 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle("Chimera", true),
536 getBounds().width, getBounds().height);
541 jmb.evalStateCommand(command, false);
542 jmb.setFinishedInit(true);
545 void setChainMenuItems(List<String> chainNames)
547 chainMenu.removeAll();
548 if (chainNames == null)
552 JMenuItem menuItem = new JMenuItem(
553 MessageManager.getString("label.all"));
554 menuItem.addActionListener(new ActionListener()
556 public void actionPerformed(ActionEvent evt)
558 allChainsSelected = true;
559 for (int i = 0; i < chainMenu.getItemCount(); i++)
561 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
563 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
567 allChainsSelected = false;
571 chainMenu.add(menuItem);
573 for (String chainName : chainNames)
575 menuItem = new JCheckBoxMenuItem(chainName, true);
576 menuItem.addItemListener(new ItemListener()
578 public void itemStateChanged(ItemEvent evt)
580 if (!allChainsSelected)
587 chainMenu.add(menuItem);
593 List<String> toshow = new ArrayList<String>();
594 for (int i = 0; i < chainMenu.getItemCount(); i++)
596 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
598 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
599 if (item.isSelected())
601 toshow.add(item.getText());
605 jmb.centerViewer(toshow);
609 * Close down this instance of Jalview's Chimera viewer, giving the user the
610 * option to close the associated Chimera window (process). They may wish to
611 * keep it open until they have had an opportunity to save any work.
613 public void closeViewer()
615 if (jmb.isChimeraRunning())
617 String prompt = MessageManager
618 .formatMessage("label.confirm_close_chimera", new Object[]
619 { jmb.getViewerTitle("Chimera", false) });
620 prompt = JvSwingUtils.wrapTooltip(true, prompt);
621 int confirm = JOptionPane.showConfirmDialog(this, prompt,
622 MessageManager.getString("label.close_viewer"),
623 JOptionPane.YES_NO_OPTION);
624 jmb.closeViewer(confirm == JOptionPane.YES_OPTION);
630 // TODO: check for memory leaks where instance isn't finalised because jmb
631 // holds a reference to the window
636 * Open any newly added PDB structures in Chimera, having first fetched data
637 * from PDB (if not already saved).
642 // todo - record which pdbids were successfully imported.
643 StringBuilder errormsgs = new StringBuilder(128);
644 StringBuilder files = new StringBuilder(128);
645 List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
646 List<Integer> filePDBpos = new ArrayList<Integer>();
647 PDBEntry thePdbEntry = null;
650 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
651 // TODO: replace with reference fetching/transfer code (validate PDBentry
653 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
656 thePdbEntry = jmb.getPdbEntry(pi);
657 if (thePdbEntry.getFile() == null)
660 * Retrieve PDB data, save to file, attach to PDBEntry
662 file = fetchPdbFile(thePdbEntry);
665 errormsgs.append("'" + thePdbEntry.getId() + "' ");
671 * Got file already - ignore if already loaded in Chimera.
673 file = new File(thePdbEntry.getFile()).getAbsoluteFile()
675 if (curfiles != null && curfiles.length > 0)
677 addingStructures = true; // already files loaded.
678 for (int c = 0; c < curfiles.length; c++)
680 if (curfiles[c].equals(file))
690 filePDB.add(thePdbEntry);
691 filePDBpos.add(Integer.valueOf(pi));
692 files.append(" \"" + Platform.escapeString(file) + "\"");
695 } catch (OutOfMemoryError oomerror)
697 new OOMWarning("Retrieving PDB files: " + thePdbEntry.getId(),
699 } catch (Exception ex)
701 ex.printStackTrace();
702 errormsgs.append("When retrieving pdbfiles for '"
703 + thePdbEntry.getId() + "'");
705 if (errormsgs.length() > 0)
708 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
709 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
711 { errormsgs.toString() }), MessageManager
712 .getString("label.couldnt_load_file"),
713 JOptionPane.ERROR_MESSAGE);
716 if (files.length() > 0)
718 if (!addingStructures)
723 } catch (Exception ex)
725 Cache.log.error("Couldn't open Chimera viewer!", ex);
729 for (PDBEntry pe : filePDB)
732 if (pe.getFile() != null)
736 int pos = filePDBpos.get(num).intValue();
738 jmb.addSequence(pos, jmb.getSequence()[pos]);
739 File fl = new File(pe.getFile());
740 String protocol = AppletFormatAdapter.URL;
745 protocol = AppletFormatAdapter.FILE;
747 } catch (Throwable e)
750 // Explicitly map to the filename used by Chimera ;
751 // TODO: use pe.getId() instead of pe.getFile() ?
752 jmb.getSsm().setMapping(jmb.getSequence()[pos], null,
755 } catch (OutOfMemoryError oomerror)
758 "When trying to open and map structures from Chimera!",
760 } catch (Exception ex)
762 Cache.log.error("Couldn't open " + pe.getFile()
763 + " in Chimera viewer!", ex);
766 Cache.log.debug("File locations are " + files);
770 jmb.setFinishedInit(true);
771 jmb.setLoadingFromArchive(false);
773 // refresh the sequence colours for the new structure(s)
774 for (AlignmentPanel ap : _colourwith)
776 jmb.updateColours(ap);
778 // do superposition if asked to
779 if (alignAddedStructures)
781 new Thread(new Runnable()
785 alignStructs_withAllAlignPanels();
788 alignAddedStructures = false;
790 addingStructures = false;
797 * Fetch PDB data and save to a local file. Returns the full path to the file,
798 * or null if fetch fails.
800 * @param processingEntry
804 private String fetchPdbFile(PDBEntry processingEntry) throws Exception
806 String filePath = null;
807 Pdb pdbclient = new Pdb();
808 AlignmentI pdbseq = null;
809 String pdbid = processingEntry.getId();
810 long hdl = pdbid.hashCode() - System.currentTimeMillis();
811 if (progressBar != null)
813 progressBar.setProgressBar(MessageManager.formatMessage(
814 "status.fetching_pdb", new Object[]
819 pdbseq = pdbclient.getSequenceRecords(pdbid);
820 } catch (OutOfMemoryError oomerror)
822 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
825 if (progressBar != null)
832 .getString("label.state_completed"),
837 * If PDB data were saved and are not invalid (empty alignment), return the
840 if (pdbseq != null && pdbseq.getHeight() > 0)
842 // just use the file name from the first sequence's first PDBEntry
843 filePath = new File(((PDBEntry) pdbseq.getSequenceAt(0).getPDBId()
844 .elementAt(0)).getFile()).getAbsolutePath();
845 processingEntry.setFile(filePath);
851 public void pdbFile_actionPerformed(ActionEvent actionEvent)
853 JalviewFileChooser chooser = new JalviewFileChooser(
854 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
856 chooser.setFileView(new JalviewFileView());
857 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
858 chooser.setToolTipText(MessageManager.getString("action.save"));
860 int value = chooser.showSaveDialog(this);
862 if (value == JalviewFileChooser.APPROVE_OPTION)
864 BufferedReader in = null;
867 // TODO: cope with multiple PDB files in view
868 in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
869 File outFile = chooser.getSelectedFile();
871 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
873 while ((data = in.readLine()) != null)
875 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
881 } catch (Exception ex)
883 ex.printStackTrace();
891 } catch (IOException e)
901 public void viewMapping_actionPerformed(ActionEvent actionEvent)
903 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
906 for (int pdbe = 0; pdbe < jmb.getPdbCount(); pdbe++)
908 cap.appendText(jmb.printMapping(jmb.getPdbEntry(pdbe).getFile()));
909 cap.appendText("\n");
911 } catch (OutOfMemoryError e)
914 "composing sequence-structure alignments for display in text box.",
919 jalview.gui.Desktop.addInternalFrame(cap,
920 MessageManager.getString("label.pdb_sequence_mapping"), 550,
925 public void eps_actionPerformed(ActionEvent e)
929 .getString("error.eps_generation_not_implemented"));
933 public void png_actionPerformed(ActionEvent e)
937 .getString("error.png_generation_not_implemented"));
941 public void viewerColour_actionPerformed(ActionEvent actionEvent)
943 if (viewerColour.isSelected())
945 // disable automatic sequence colouring.
946 jmb.setColourBySequence(false);
951 public void seqColour_actionPerformed(ActionEvent actionEvent)
953 jmb.setColourBySequence(seqColour.isSelected());
954 if (_colourwith == null)
956 _colourwith = new Vector<AlignmentPanel>();
958 if (jmb.isColourBySequence())
960 if (!jmb.isLoadingFromArchive())
962 if (_colourwith.size() == 0 && ap != null)
964 // Make the currently displayed alignment panel the associated view
965 _colourwith.add(ap.alignFrame.alignPanel);
968 // Set the colour using the current view for the associated alignframe
969 for (AlignmentPanel ap : _colourwith)
971 jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
977 public void chainColour_actionPerformed(ActionEvent actionEvent)
979 chainColour.setSelected(true);
984 public void chargeColour_actionPerformed(ActionEvent actionEvent)
986 chargeColour.setSelected(true);
987 jmb.colourByCharge();
991 public void zappoColour_actionPerformed(ActionEvent actionEvent)
993 zappoColour.setSelected(true);
994 jmb.setJalviewColourScheme(new ZappoColourScheme());
998 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1000 taylorColour.setSelected(true);
1001 jmb.setJalviewColourScheme(new TaylorColourScheme());
1005 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1007 hydroColour.setSelected(true);
1008 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1012 public void helixColour_actionPerformed(ActionEvent actionEvent)
1014 helixColour.setSelected(true);
1015 jmb.setJalviewColourScheme(new HelixColourScheme());
1019 public void strandColour_actionPerformed(ActionEvent actionEvent)
1021 strandColour.setSelected(true);
1022 jmb.setJalviewColourScheme(new StrandColourScheme());
1026 public void turnColour_actionPerformed(ActionEvent actionEvent)
1028 turnColour.setSelected(true);
1029 jmb.setJalviewColourScheme(new TurnColourScheme());
1033 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1035 buriedColour.setSelected(true);
1036 jmb.setJalviewColourScheme(new BuriedColourScheme());
1040 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1042 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1046 public void userColour_actionPerformed(ActionEvent actionEvent)
1048 userColour.setSelected(true);
1049 new UserDefinedColours(this, null);
1053 public void backGround_actionPerformed(ActionEvent actionEvent)
1055 java.awt.Color col = JColorChooser
1056 .showDialog(this, MessageManager
1057 .getString("label.select_backgroud_colour"), null);
1060 jmb.setBackgroundColour(col);
1065 public void showHelp_actionPerformed(ActionEvent actionEvent)
1069 jalview.util.BrowserLauncher
1070 .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
1071 } catch (Exception ex)
1076 public void updateTitleAndMenus()
1078 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1083 setChainMenuItems(jmb.chainNames);
1085 this.setTitle(jmb.getViewerTitle("Chimera", true));
1086 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1088 viewerActionMenu.setVisible(true);
1090 if (!jmb.isLoadingFromArchive())
1092 seqColour_actionPerformed(null);
1096 protected void buildChimeraActionMenu()
1098 if (_alignwith == null)
1100 _alignwith = new Vector<AlignmentPanel>();
1102 if (_alignwith.size() == 0 && ap != null)
1107 for (Component c : viewerActionMenu.getMenuComponents())
1109 if (c != alignStructs)
1111 viewerActionMenu.remove((JMenuItem) c);
1120 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1124 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1126 alignStructs_withAllAlignPanels();
1129 private void alignStructs_withAllAlignPanels()
1136 if (_alignwith.size() == 0)
1143 AlignmentI[] als = new Alignment[_alignwith.size()];
1144 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1145 int[] alm = new int[_alignwith.size()];
1148 for (AlignmentPanel ap : _alignwith)
1150 als[a] = ap.av.getAlignment();
1152 alc[a++] = ap.av.getColumnSelection();
1154 jmb.superposeStructures(als, alm, alc);
1155 } catch (Exception e)
1157 StringBuffer sp = new StringBuffer();
1158 for (AlignmentPanel ap : _alignwith)
1160 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1162 Cache.log.info("Couldn't align structures with the " + sp.toString()
1163 + "associated alignment panels.", e);
1169 public void setJalviewColourScheme(ColourSchemeI ucs)
1171 jmb.setJalviewColourScheme(ucs);
1178 * @return first alignment panel displaying given alignment, or the default
1181 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1183 for (AlignmentPanel ap : getAllAlignmentPanels())
1185 if (ap.av.getAlignment() == alignment)
1194 public AAStructureBindingModel getBinding()
1200 * Ask Chimera to save its session to the designated file path. Returns true
1201 * if successful, else false.
1205 public boolean saveSession(String filepath)
1207 return jmb.saveSession(filepath);