2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.bin.Cache;
24 import jalview.datamodel.Alignment;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.ColumnSelection;
27 import jalview.datamodel.PDBEntry;
28 import jalview.datamodel.SequenceI;
29 import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
30 import jalview.gui.StructureViewer.ViewerType;
31 import jalview.io.AppletFormatAdapter;
32 import jalview.io.JalviewFileChooser;
33 import jalview.io.JalviewFileView;
34 import jalview.schemes.BuriedColourScheme;
35 import jalview.schemes.ColourSchemeI;
36 import jalview.schemes.HelixColourScheme;
37 import jalview.schemes.HydrophobicColourScheme;
38 import jalview.schemes.PurinePyrimidineColourScheme;
39 import jalview.schemes.StrandColourScheme;
40 import jalview.schemes.TaylorColourScheme;
41 import jalview.schemes.TurnColourScheme;
42 import jalview.schemes.ZappoColourScheme;
43 import jalview.structures.models.AAStructureBindingModel;
44 import jalview.util.MessageManager;
45 import jalview.util.Platform;
46 import jalview.ws.dbsources.Pdb;
48 import java.awt.event.ActionEvent;
49 import java.awt.event.ActionListener;
50 import java.awt.event.ItemEvent;
51 import java.awt.event.ItemListener;
52 import java.io.BufferedReader;
54 import java.io.FileInputStream;
55 import java.io.FileOutputStream;
56 import java.io.FileReader;
57 import java.io.IOException;
58 import java.io.InputStream;
59 import java.io.PrintWriter;
60 import java.util.ArrayList;
61 import java.util.List;
62 import java.util.Random;
63 import java.util.Vector;
65 import javax.swing.JCheckBoxMenuItem;
66 import javax.swing.JColorChooser;
67 import javax.swing.JInternalFrame;
68 import javax.swing.JMenu;
69 import javax.swing.JMenuItem;
70 import javax.swing.JOptionPane;
71 import javax.swing.event.InternalFrameAdapter;
72 import javax.swing.event.InternalFrameEvent;
73 import javax.swing.event.MenuEvent;
74 import javax.swing.event.MenuListener;
77 * GUI elements for handling an external chimera display
82 public class ChimeraViewFrame extends StructureViewerBase
84 private JalviewChimeraBinding jmb;
86 private boolean allChainsSelected = false;
88 private IProgressIndicator progressBar = null;
91 * Path to Chimera session file. This is set when an open Jalview/Chimera
92 * session is saved, or on restore from a Jalview project (if it holds the
93 * filename of any saved Chimera sessions).
95 private String chimeraSessionFile = null;
97 private Random random = new Random();
100 * Initialise menu options.
102 private void initMenus()
104 viewerActionMenu.setText(MessageManager.getString("label.chimera"));
105 viewerColour.setText(MessageManager
106 .getString("label.colour_with_chimera"));
107 viewerColour.setToolTipText(MessageManager
108 .getString("label.let_chimera_manage_structure_colours"));
109 helpItem.setText(MessageManager.getString("label.chimera_help"));
110 seqColour.setSelected(jmb.isColourBySequence());
111 viewerColour.setSelected(!jmb.isColourBySequence());
112 if (_colourwith == null)
114 _colourwith = new Vector<AlignmentPanel>();
116 if (_alignwith == null)
118 _alignwith = new Vector<AlignmentPanel>();
121 // save As not yet implemented
122 savemenu.setVisible(false);
124 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
125 MessageManager.getString("label.colour_by"), this, _colourwith,
129 public void itemStateChanged(ItemEvent e)
131 if (!seqColour.isSelected())
137 // update the Chimera display now.
138 seqColour_actionPerformed(null);
142 viewMenu.add(seqColourBy);
143 viewMenu.add(fitToWindow);
145 final ItemListener handler;
146 JMenu alpanels = new ViewSelectionMenu(
147 MessageManager.getString("label.superpose_with"), this,
148 _alignwith, handler = new ItemListener()
151 public void itemStateChanged(ItemEvent e)
153 alignStructs.setEnabled(_alignwith.size() > 0);
154 alignStructs.setToolTipText(MessageManager
156 "label.align_structures_using_linked_alignment_views",
157 new Object[] { new Integer(_alignwith
158 .size()).toString() }));
161 handler.itemStateChanged(null);
162 viewerActionMenu.add(alpanels);
163 viewerActionMenu.addMenuListener(new MenuListener()
167 public void menuSelected(MenuEvent e)
169 handler.itemStateChanged(null);
173 public void menuDeselected(MenuEvent e)
175 // TODO Auto-generated method stub
179 public void menuCanceled(MenuEvent e)
181 // TODO Auto-generated method stub
184 JMenuItem writeFeatures = new JMenuItem(
185 MessageManager.getString("label.create_chimera_attributes"));
186 writeFeatures.setToolTipText(MessageManager
187 .getString("label.create_chimera_attributes_tip"));
188 writeFeatures.addActionListener(new ActionListener()
191 public void actionPerformed(ActionEvent e)
193 sendFeaturesToChimera();
196 viewerActionMenu.add(writeFeatures);
200 * Send a command to Chimera to create residue attributes for Jalview features
202 * The syntax is: setattr r <attName> <attValue> <atomSpec>
204 * For example: setattr r jv:chain "Ferredoxin-1, Chloroplastic" #0:94.A
206 protected void sendFeaturesToChimera()
208 jmb.sendFeaturesToChimera(getAlignmentPanel());
212 * add a single PDB structure to a new or existing Chimera view
219 public ChimeraViewFrame(PDBEntry pdbentry, SequenceI[] seq,
220 String[] chains, final AlignmentPanel ap)
223 String pdbId = pdbentry.getId();
226 * If the PDB file is already loaded, the user may just choose to add to an
227 * existing viewer (or cancel)
229 if (addAlreadyLoadedFile(seq, chains, ap, pdbId))
235 * Check if there are other Chimera views involving this alignment and give
236 * user the option to add and align this molecule to one of them (or cancel)
238 if (addToExistingViewer(pdbentry, seq, chains, ap, pdbId))
244 * If the options above are declined or do not apply, show the structure in
247 openNewChimera(ap, new PDBEntry[] { pdbentry },
248 new SequenceI[][] { seq });
252 * Create a helper to manage progress bar display
254 protected void createProgressBar()
256 if (progressBar == null)
258 progressBar = new ProgressBar(statusPanel, statusBar);
263 * Answers true if this viewer already involves the given PDB ID
266 protected boolean hasPdbId(String pdbId)
268 return jmb.hasPdbId(pdbId);
271 private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
275 // FIXME extractChains needs pdbentries to match IDs to PDBEntry(s) on seqs
276 String[][] chains = extractChains(seqs);
277 jmb = new JalviewChimeraBindingModel(this,
278 ap.getStructureSelectionManager(), pdbentrys, seqs, chains,
280 addAlignmentPanel(ap);
281 useAlignmentPanelForColourbyseq(ap);
282 if (pdbentrys.length > 1)
284 alignAddedStructures = true;
285 useAlignmentPanelForSuperposition(ap);
287 jmb.setColourBySequence(true);
288 setSize(400, 400); // probably should be a configurable/dynamic default here
291 addingStructures = false;
292 worker = new Thread(this);
295 this.addInternalFrameListener(new InternalFrameAdapter()
298 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
307 * Retrieve chains for sequences by inspecting their PDB refs. The hope is
308 * that the first will be to the sequence's own chain. Really need a more
309 * managed way of doing this.
314 protected String[][] extractChains(SequenceI[][] seqs)
316 String[][] chains = new String[seqs.length][];
317 for (int i = 0; i < seqs.length; i++)
319 chains[i] = new String[seqs[i].length];
321 for (SequenceI seq : seqs[i])
324 if (seq.getDatasetSequence() != null)
326 Vector<PDBEntry> pdbrefs = seq.getDatasetSequence()
328 if (pdbrefs != null && pdbrefs.size() > 0)
330 // FIXME: SequenceI.PDBEntry[0] chain mapping used for
331 // ChimeraViewFrame. Is this even used ???
333 chain = pdbrefs.get(0).getChainCode();
336 chains[i][seqno++] = chain;
343 * Create a new viewer from saved session state data including Chimera session
346 * @param chimeraSessionFile
350 * @param colourByChimera
351 * @param colourBySequence
354 public ChimeraViewFrame(String chimeraSessionFile,
355 AlignmentPanel alignPanel, PDBEntry[] pdbArray,
356 SequenceI[][] seqsArray, boolean colourByChimera,
357 boolean colourBySequence, String newViewId)
360 setViewId(newViewId);
361 this.chimeraSessionFile = chimeraSessionFile;
362 openNewChimera(alignPanel, pdbArray, seqsArray);
365 jmb.setColourBySequence(false);
366 seqColour.setSelected(false);
367 viewerColour.setSelected(true);
369 else if (colourBySequence)
371 jmb.setColourBySequence(true);
372 seqColour.setSelected(true);
373 viewerColour.setSelected(false);
378 * create a new viewer containing several structures superimposed using the
385 public ChimeraViewFrame(PDBEntry[] pe, SequenceI[][] seqs,
389 openNewChimera(ap, pe, seqs);
393 * Default constructor
395 public ChimeraViewFrame()
400 * closeViewer will decide whether or not to close this frame
401 * depending on whether user chooses to Cancel or not
403 setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
407 * Returns a list of any Chimera viewers in the desktop. The list is
408 * restricted to those linked to the given alignment panel if it is not null.
411 protected List<StructureViewerBase> getViewersFor(AlignmentPanel ap)
413 List<StructureViewerBase> result = new ArrayList<StructureViewerBase>();
414 JInternalFrame[] frames = Desktop.instance.getAllFrames();
416 for (JInternalFrame frame : frames)
418 if (frame instanceof ChimeraViewFrame)
420 if (ap == null || ((StructureViewerBase) frame).isLinkedWith(ap))
422 result.add((StructureViewerBase) frame);
430 * Launch Chimera. If we have a chimera session file name, send Chimera the
431 * command to open its saved session file.
435 jalview.gui.Desktop.addInternalFrame(this,
436 jmb.getViewerTitle("Chimera", true), getBounds().width,
439 if (!jmb.launchChimera())
441 JOptionPane.showMessageDialog(Desktop.desktop,
442 MessageManager.getString("label.chimera_failed"),
443 MessageManager.getString("label.error_loading_file"),
444 JOptionPane.ERROR_MESSAGE);
449 if (this.chimeraSessionFile != null)
451 boolean opened = jmb.openSession(chimeraSessionFile);
455 .println("An error occurred opening Chimera session file "
456 + chimeraSessionFile);
460 jmb.startChimeraListener();
464 * If the list is not empty, add menu items for 'All' and each individual
465 * chain to the "View | Show Chain" sub-menu. Multiple selections are allowed.
469 void setChainMenuItems(List<String> chainNames)
471 chainMenu.removeAll();
472 if (chainNames == null || chainNames.isEmpty())
476 JMenuItem menuItem = new JMenuItem(
477 MessageManager.getString("label.all"));
478 menuItem.addActionListener(new ActionListener()
481 public void actionPerformed(ActionEvent evt)
483 allChainsSelected = true;
484 for (int i = 0; i < chainMenu.getItemCount(); i++)
486 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
488 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
491 showSelectedChains();
492 allChainsSelected = false;
496 chainMenu.add(menuItem);
498 for (String chainName : chainNames)
500 menuItem = new JCheckBoxMenuItem(chainName, true);
501 menuItem.addItemListener(new ItemListener()
504 public void itemStateChanged(ItemEvent evt)
506 if (!allChainsSelected)
508 showSelectedChains();
513 chainMenu.add(menuItem);
518 * Show only the selected chain(s) in the viewer
520 void showSelectedChains()
522 List<String> toshow = new ArrayList<String>();
523 for (int i = 0; i < chainMenu.getItemCount(); i++)
525 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
527 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
528 if (item.isSelected())
530 toshow.add(item.getText());
534 jmb.showChains(toshow);
538 * Close down this instance of Jalview's Chimera viewer, giving the user the
539 * option to close the associated Chimera window (process). They may wish to
540 * keep it open until they have had an opportunity to save any work.
542 * @param closeChimera
543 * if true, close any linked Chimera process; if false, prompt first
546 public void closeViewer(boolean closeChimera)
548 if (jmb != null && jmb.isChimeraRunning())
552 String prompt = MessageManager.formatMessage(
553 "label.confirm_close_chimera",
554 new Object[] { jmb.getViewerTitle("Chimera", false) });
555 prompt = JvSwingUtils.wrapTooltip(true, prompt);
556 int confirm = JOptionPane.showConfirmDialog(this, prompt,
557 MessageManager.getString("label.close_viewer"),
558 JOptionPane.YES_NO_CANCEL_OPTION);
560 * abort closure if user hits escape or Cancel
562 if (confirm == JOptionPane.CANCEL_OPTION
563 || confirm == JOptionPane.CLOSED_OPTION)
567 closeChimera = confirm == JOptionPane.YES_OPTION;
569 jmb.closeViewer(closeChimera);
571 setAlignmentPanel(null);
575 // TODO: check for memory leaks where instance isn't finalised because jmb
576 // holds a reference to the window
582 * Open any newly added PDB structures in Chimera, having first fetched data
583 * from PDB (if not already saved).
589 // todo - record which pdbids were successfully imported.
590 StringBuilder errormsgs = new StringBuilder(128);
591 StringBuilder files = new StringBuilder(128);
592 List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
593 List<Integer> filePDBpos = new ArrayList<Integer>();
594 PDBEntry thePdbEntry = null;
597 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
598 // TODO: replace with reference fetching/transfer code (validate PDBentry
600 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
603 thePdbEntry = jmb.getPdbEntry(pi);
604 if (thePdbEntry.getFile() == null)
607 * Retrieve PDB data, save to file, attach to PDBEntry
609 file = fetchPdbFile(thePdbEntry);
612 errormsgs.append("'" + thePdbEntry.getId() + "' ");
618 * Got file already - ignore if already loaded in Chimera.
620 file = new File(thePdbEntry.getFile()).getAbsoluteFile()
622 if (curfiles != null && curfiles.length > 0)
624 addingStructures = true; // already files loaded.
625 for (int c = 0; c < curfiles.length; c++)
627 if (curfiles[c].equals(file))
637 filePDB.add(thePdbEntry);
638 filePDBpos.add(Integer.valueOf(pi));
639 files.append(" \"" + Platform.escapeString(file) + "\"");
642 } catch (OutOfMemoryError oomerror)
644 new OOMWarning("Retrieving PDB files: " + thePdbEntry.getId(),
646 } catch (Exception ex)
648 ex.printStackTrace();
649 errormsgs.append("When retrieving pdbfiles for '"
650 + thePdbEntry.getId() + "'");
652 if (errormsgs.length() > 0)
655 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
656 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
657 new Object[] { errormsgs.toString() }),
658 MessageManager.getString("label.couldnt_load_file"),
659 JOptionPane.ERROR_MESSAGE);
662 if (files.length() > 0)
664 jmb.setFinishedInit(false);
665 if (!addingStructures)
670 } catch (Exception ex)
672 Cache.log.error("Couldn't open Chimera viewer!", ex);
677 for (PDBEntry pe : filePDB)
680 if (pe.getFile() != null)
684 int pos = filePDBpos.get(num).intValue();
685 long startTime = startProgressBar("Chimera "
686 + MessageManager.getString("status.opening_file_for")
689 jmb.addSequence(pos, jmb.getSequence()[pos]);
690 File fl = new File(pe.getFile());
691 String protocol = AppletFormatAdapter.URL;
696 protocol = AppletFormatAdapter.FILE;
698 } catch (Throwable e)
702 stopProgressBar("", startTime);
704 // Explicitly map to the filename used by Chimera ;
705 jmb.getSsm().setMapping(jmb.getSequence()[pos],
706 jmb.getChains()[pos], pe.getFile(), protocol);
707 } catch (OutOfMemoryError oomerror)
710 "When trying to open and map structures from Chimera!",
712 } catch (Exception ex)
714 Cache.log.error("Couldn't open " + pe.getFile()
715 + " in Chimera viewer!", ex);
718 Cache.log.debug("File locations are " + files);
723 jmb.setFinishedInit(true);
724 jmb.setLoadingFromArchive(false);
726 // refresh the sequence colours for the new structure(s)
727 for (AlignmentPanel ap : _colourwith)
729 jmb.updateColours(ap);
731 // do superposition if asked to
732 if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures)
734 new Thread(new Runnable()
739 alignStructs_withAllAlignPanels();
742 alignAddedStructures = false;
744 addingStructures = false;
751 * Fetch PDB data and save to a local file. Returns the full path to the file,
752 * or null if fetch fails.
754 * @param processingEntry
758 private String fetchPdbFile(PDBEntry processingEntry) throws Exception
760 // FIXME: this is duplicated code with Jmol frame ?
761 String filePath = null;
762 Pdb pdbclient = new Pdb();
763 AlignmentI pdbseq = null;
764 String pdbid = processingEntry.getId();
765 long handle = System.currentTimeMillis()
766 + Thread.currentThread().hashCode();
769 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
771 String msg = MessageManager.formatMessage("status.fetching_pdb",
772 new Object[] { pdbid });
773 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
774 // long hdl = startProgressBar(MessageManager.formatMessage(
775 // "status.fetching_pdb", new Object[]
779 pdbseq = pdbclient.getSequenceRecords(pdbid);
780 } catch (OutOfMemoryError oomerror)
782 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
785 msg = pdbid + " " + MessageManager.getString("label.state_completed");
786 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
787 // stopProgressBar(msg, hdl);
790 * If PDB data were saved and are not invalid (empty alignment), return the
793 if (pdbseq != null && pdbseq.getHeight() > 0)
795 // just use the file name from the first sequence's first PDBEntry
796 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
797 .elementAt(0).getFile()).getAbsolutePath();
798 processingEntry.setFile(filePath);
804 * Convenience method to update the progress bar if there is one. Be sure to
805 * call stopProgressBar with the returned handle to remove the message.
810 public long startProgressBar(String msg)
812 // TODO would rather have startProgress/stopProgress as the
813 // IProgressIndicator interface
814 long tm = random.nextLong();
815 if (progressBar != null)
817 progressBar.setProgressBar(msg, tm);
823 * End the progress bar with the specified handle, leaving a message (if not
824 * null) on the status bar
829 public void stopProgressBar(String msg, long handle)
831 if (progressBar != null)
833 progressBar.setProgressBar(msg, handle);
838 public void pdbFile_actionPerformed(ActionEvent actionEvent)
840 JalviewFileChooser chooser = new JalviewFileChooser(
841 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
843 chooser.setFileView(new JalviewFileView());
844 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
845 chooser.setToolTipText(MessageManager.getString("action.save"));
847 int value = chooser.showSaveDialog(this);
849 if (value == JalviewFileChooser.APPROVE_OPTION)
851 BufferedReader in = null;
854 // TODO: cope with multiple PDB files in view
855 in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
856 File outFile = chooser.getSelectedFile();
858 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
860 while ((data = in.readLine()) != null)
862 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
868 } catch (Exception ex)
870 ex.printStackTrace();
878 } catch (IOException e)
888 public void viewMapping_actionPerformed(ActionEvent actionEvent)
890 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
893 cap.appendText(jmb.printMappings());
894 } catch (OutOfMemoryError e)
897 "composing sequence-structure alignments for display in text box.",
902 jalview.gui.Desktop.addInternalFrame(cap,
903 MessageManager.getString("label.pdb_sequence_mapping"), 550,
908 public void eps_actionPerformed(ActionEvent e)
912 .getString("error.eps_generation_not_implemented"));
916 public void png_actionPerformed(ActionEvent e)
920 .getString("error.png_generation_not_implemented"));
924 public void viewerColour_actionPerformed(ActionEvent actionEvent)
926 if (viewerColour.isSelected())
928 // disable automatic sequence colouring.
929 jmb.setColourBySequence(false);
934 public void seqColour_actionPerformed(ActionEvent actionEvent)
936 jmb.setColourBySequence(seqColour.isSelected());
937 if (_colourwith == null)
939 _colourwith = new Vector<AlignmentPanel>();
941 if (jmb.isColourBySequence())
943 if (!jmb.isLoadingFromArchive())
945 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
947 // Make the currently displayed alignment panel the associated view
948 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
951 // Set the colour using the current view for the associated alignframe
952 for (AlignmentPanel ap : _colourwith)
954 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
960 public void chainColour_actionPerformed(ActionEvent actionEvent)
962 chainColour.setSelected(true);
967 public void chargeColour_actionPerformed(ActionEvent actionEvent)
969 chargeColour.setSelected(true);
970 jmb.colourByCharge();
974 public void zappoColour_actionPerformed(ActionEvent actionEvent)
976 zappoColour.setSelected(true);
977 jmb.setJalviewColourScheme(new ZappoColourScheme());
981 public void taylorColour_actionPerformed(ActionEvent actionEvent)
983 taylorColour.setSelected(true);
984 jmb.setJalviewColourScheme(new TaylorColourScheme());
988 public void hydroColour_actionPerformed(ActionEvent actionEvent)
990 hydroColour.setSelected(true);
991 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
995 public void helixColour_actionPerformed(ActionEvent actionEvent)
997 helixColour.setSelected(true);
998 jmb.setJalviewColourScheme(new HelixColourScheme());
1002 public void strandColour_actionPerformed(ActionEvent actionEvent)
1004 strandColour.setSelected(true);
1005 jmb.setJalviewColourScheme(new StrandColourScheme());
1009 public void turnColour_actionPerformed(ActionEvent actionEvent)
1011 turnColour.setSelected(true);
1012 jmb.setJalviewColourScheme(new TurnColourScheme());
1016 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1018 buriedColour.setSelected(true);
1019 jmb.setJalviewColourScheme(new BuriedColourScheme());
1023 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1025 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1029 public void userColour_actionPerformed(ActionEvent actionEvent)
1031 userColour.setSelected(true);
1032 new UserDefinedColours(this, null);
1036 public void backGround_actionPerformed(ActionEvent actionEvent)
1038 java.awt.Color col = JColorChooser
1039 .showDialog(this, MessageManager
1040 .getString("label.select_backgroud_colour"), null);
1043 jmb.setBackgroundColour(col);
1048 public void showHelp_actionPerformed(ActionEvent actionEvent)
1052 jalview.util.BrowserLauncher
1053 .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
1054 } catch (Exception ex)
1059 public void updateTitleAndMenus()
1061 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1066 setChainMenuItems(jmb.getChainNames());
1068 this.setTitle(jmb.getViewerTitle("Chimera", true));
1069 // if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1071 viewerActionMenu.setVisible(true);
1073 if (!jmb.isLoadingFromArchive())
1075 seqColour_actionPerformed(null);
1083 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1087 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1089 alignStructs_withAllAlignPanels();
1092 private void alignStructs_withAllAlignPanels()
1094 if (getAlignmentPanel() == null)
1099 if (_alignwith.size() == 0)
1101 _alignwith.add(getAlignmentPanel());
1106 AlignmentI[] als = new Alignment[_alignwith.size()];
1107 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1108 int[] alm = new int[_alignwith.size()];
1111 for (AlignmentPanel ap : _alignwith)
1113 als[a] = ap.av.getAlignment();
1115 alc[a++] = ap.av.getColumnSelection();
1117 jmb.superposeStructures(als, alm, alc);
1118 } catch (Exception e)
1120 StringBuffer sp = new StringBuffer();
1121 for (AlignmentPanel ap : _alignwith)
1123 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1125 Cache.log.info("Couldn't align structures with the " + sp.toString()
1126 + "associated alignment panels.", e);
1131 public void setJalviewColourScheme(ColourSchemeI ucs)
1133 jmb.setJalviewColourScheme(ucs);
1140 * @return first alignment panel displaying given alignment, or the default
1143 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1145 for (AlignmentPanel ap : getAllAlignmentPanels())
1147 if (ap.av.getAlignment() == alignment)
1152 return getAlignmentPanel();
1156 public AAStructureBindingModel getBinding()
1162 * Ask Chimera to save its session to the designated file path, or to a
1163 * temporary file if the path is null. Returns the file path if successful,
1169 protected String saveSession(String filepath)
1171 String pathUsed = filepath;
1174 if (pathUsed == null)
1176 File tempFile = File.createTempFile("chimera", ".py");
1177 tempFile.deleteOnExit();
1178 pathUsed = tempFile.getPath();
1180 boolean result = jmb.saveSession(pathUsed);
1183 this.chimeraSessionFile = pathUsed;
1186 } catch (IOException e)
1193 * Returns a string representing the state of the Chimera session. This is
1194 * done by requesting Chimera to save its session to a temporary file, then
1195 * reading the file contents. Returns an empty string on any error.
1198 public String getStateInfo()
1200 String sessionFile = saveSession(null);
1201 if (sessionFile == null)
1205 InputStream is = null;
1208 File f = new File(sessionFile);
1209 byte[] bytes = new byte[(int) f.length()];
1210 is = new FileInputStream(sessionFile);
1212 return new String(bytes);
1213 } catch (IOException e)
1223 } catch (IOException e)
1232 protected void fitToWindow_actionPerformed()
1238 public ViewerType getViewerType()
1240 return ViewerType.CHIMERA;
1244 protected AAStructureBindingModel getBindingModel()