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 jmb.setFinishedInit(false);
436 jalview.gui.Desktop.addInternalFrame(this,
437 jmb.getViewerTitle("Chimera", true), getBounds().width,
440 if (!jmb.launchChimera())
442 JOptionPane.showMessageDialog(Desktop.desktop,
443 MessageManager.getString("label.chimera_failed"),
444 MessageManager.getString("label.error_loading_file"),
445 JOptionPane.ERROR_MESSAGE);
450 if (this.chimeraSessionFile != null)
452 boolean opened = jmb.openSession(chimeraSessionFile);
456 .println("An error occurred opening Chimera session file "
457 + chimeraSessionFile);
460 jmb.setFinishedInit(true);
462 jmb.startChimeraListener();
466 * If the list is not empty, add menu items for 'All' and each individual
467 * chain to the "View | Show Chain" sub-menu. Multiple selections are allowed.
471 void setChainMenuItems(List<String> chainNames)
473 chainMenu.removeAll();
474 if (chainNames == null || chainNames.isEmpty())
478 JMenuItem menuItem = new JMenuItem(
479 MessageManager.getString("label.all"));
480 menuItem.addActionListener(new ActionListener()
483 public void actionPerformed(ActionEvent evt)
485 allChainsSelected = true;
486 for (int i = 0; i < chainMenu.getItemCount(); i++)
488 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
490 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
493 showSelectedChains();
494 allChainsSelected = false;
498 chainMenu.add(menuItem);
500 for (String chainName : chainNames)
502 menuItem = new JCheckBoxMenuItem(chainName, true);
503 menuItem.addItemListener(new ItemListener()
506 public void itemStateChanged(ItemEvent evt)
508 if (!allChainsSelected)
510 showSelectedChains();
515 chainMenu.add(menuItem);
520 * Show only the selected chain(s) in the viewer
522 void showSelectedChains()
524 List<String> toshow = new ArrayList<String>();
525 for (int i = 0; i < chainMenu.getItemCount(); i++)
527 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
529 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
530 if (item.isSelected())
532 toshow.add(item.getText());
536 jmb.showChains(toshow);
540 * Close down this instance of Jalview's Chimera viewer, giving the user the
541 * option to close the associated Chimera window (process). They may wish to
542 * keep it open until they have had an opportunity to save any work.
544 * @param closeChimera
545 * if true, close any linked Chimera process; if false, prompt first
548 public void closeViewer(boolean closeChimera)
550 if (jmb != null && jmb.isChimeraRunning())
554 String prompt = MessageManager.formatMessage(
555 "label.confirm_close_chimera",
556 new Object[] { jmb.getViewerTitle("Chimera", false) });
557 prompt = JvSwingUtils.wrapTooltip(true, prompt);
558 int confirm = JOptionPane.showConfirmDialog(this, prompt,
559 MessageManager.getString("label.close_viewer"),
560 JOptionPane.YES_NO_CANCEL_OPTION);
562 * abort closure if user hits escape or Cancel
564 if (confirm == JOptionPane.CANCEL_OPTION
565 || confirm == JOptionPane.CLOSED_OPTION)
569 closeChimera = confirm == JOptionPane.YES_OPTION;
571 jmb.closeViewer(closeChimera);
573 setAlignmentPanel(null);
577 // TODO: check for memory leaks where instance isn't finalised because jmb
578 // holds a reference to the window
584 * Open any newly added PDB structures in Chimera, having first fetched data
585 * from PDB (if not already saved).
591 // todo - record which pdbids were successfully imported.
592 StringBuilder errormsgs = new StringBuilder(128);
593 StringBuilder files = new StringBuilder(128);
594 List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
595 List<Integer> filePDBpos = new ArrayList<Integer>();
596 PDBEntry thePdbEntry = null;
599 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
600 // TODO: replace with reference fetching/transfer code (validate PDBentry
602 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
605 thePdbEntry = jmb.getPdbEntry(pi);
606 if (thePdbEntry.getFile() == null)
609 * Retrieve PDB data, save to file, attach to PDBEntry
611 file = fetchPdbFile(thePdbEntry);
614 errormsgs.append("'" + thePdbEntry.getId() + "' ");
620 * Got file already - ignore if already loaded in Chimera.
622 file = new File(thePdbEntry.getFile()).getAbsoluteFile()
624 if (curfiles != null && curfiles.length > 0)
626 addingStructures = true; // already files loaded.
627 for (int c = 0; c < curfiles.length; c++)
629 if (curfiles[c].equals(file))
639 filePDB.add(thePdbEntry);
640 filePDBpos.add(Integer.valueOf(pi));
641 files.append(" \"" + Platform.escapeString(file) + "\"");
644 } catch (OutOfMemoryError oomerror)
646 new OOMWarning("Retrieving PDB files: " + thePdbEntry.getId(),
648 } catch (Exception ex)
650 ex.printStackTrace();
651 errormsgs.append("When retrieving pdbfiles for '"
652 + thePdbEntry.getId() + "'");
654 if (errormsgs.length() > 0)
657 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
658 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
659 new Object[] { errormsgs.toString() }),
660 MessageManager.getString("label.couldnt_load_file"),
661 JOptionPane.ERROR_MESSAGE);
664 if (files.length() > 0)
666 if (!addingStructures)
671 } catch (Exception ex)
673 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);
722 jmb.setFinishedInit(true);
723 jmb.setLoadingFromArchive(false);
725 // refresh the sequence colours for the new structure(s)
726 for (AlignmentPanel ap : _colourwith)
728 jmb.updateColours(ap);
730 // do superposition if asked to
731 if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures)
733 new Thread(new Runnable()
738 alignStructs_withAllAlignPanels();
741 alignAddedStructures = false;
743 addingStructures = false;
750 * Fetch PDB data and save to a local file. Returns the full path to the file,
751 * or null if fetch fails.
753 * @param processingEntry
757 private String fetchPdbFile(PDBEntry processingEntry) throws Exception
759 // FIXME: this is duplicated code with Jmol frame ?
760 String filePath = null;
761 Pdb pdbclient = new Pdb();
762 AlignmentI pdbseq = null;
763 String pdbid = processingEntry.getId();
764 long handle = System.currentTimeMillis()
765 + Thread.currentThread().hashCode();
768 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
770 String msg = MessageManager.formatMessage("status.fetching_pdb",
771 new Object[] { pdbid });
772 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
773 // long hdl = startProgressBar(MessageManager.formatMessage(
774 // "status.fetching_pdb", new Object[]
778 pdbseq = pdbclient.getSequenceRecords(pdbid);
779 } catch (OutOfMemoryError oomerror)
781 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
784 msg = pdbid + " " + MessageManager.getString("label.state_completed");
785 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
786 // stopProgressBar(msg, hdl);
789 * If PDB data were saved and are not invalid (empty alignment), return the
792 if (pdbseq != null && pdbseq.getHeight() > 0)
794 // just use the file name from the first sequence's first PDBEntry
795 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
796 .elementAt(0).getFile()).getAbsolutePath();
797 processingEntry.setFile(filePath);
803 * Convenience method to update the progress bar if there is one. Be sure to
804 * call stopProgressBar with the returned handle to remove the message.
809 public long startProgressBar(String msg)
811 // TODO would rather have startProgress/stopProgress as the
812 // IProgressIndicator interface
813 long tm = random.nextLong();
814 if (progressBar != null)
816 progressBar.setProgressBar(msg, tm);
822 * End the progress bar with the specified handle, leaving a message (if not
823 * null) on the status bar
828 public void stopProgressBar(String msg, long handle)
830 if (progressBar != null)
832 progressBar.setProgressBar(msg, handle);
837 public void pdbFile_actionPerformed(ActionEvent actionEvent)
839 JalviewFileChooser chooser = new JalviewFileChooser(
840 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
842 chooser.setFileView(new JalviewFileView());
843 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
844 chooser.setToolTipText(MessageManager.getString("action.save"));
846 int value = chooser.showSaveDialog(this);
848 if (value == JalviewFileChooser.APPROVE_OPTION)
850 BufferedReader in = null;
853 // TODO: cope with multiple PDB files in view
854 in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
855 File outFile = chooser.getSelectedFile();
857 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
859 while ((data = in.readLine()) != null)
861 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
867 } catch (Exception ex)
869 ex.printStackTrace();
877 } catch (IOException e)
887 public void viewMapping_actionPerformed(ActionEvent actionEvent)
889 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
892 cap.appendText(jmb.printMappings());
893 } catch (OutOfMemoryError e)
896 "composing sequence-structure alignments for display in text box.",
901 jalview.gui.Desktop.addInternalFrame(cap,
902 MessageManager.getString("label.pdb_sequence_mapping"), 550,
907 public void eps_actionPerformed(ActionEvent e)
911 .getString("error.eps_generation_not_implemented"));
915 public void png_actionPerformed(ActionEvent e)
919 .getString("error.png_generation_not_implemented"));
923 public void viewerColour_actionPerformed(ActionEvent actionEvent)
925 if (viewerColour.isSelected())
927 // disable automatic sequence colouring.
928 jmb.setColourBySequence(false);
933 public void seqColour_actionPerformed(ActionEvent actionEvent)
935 jmb.setColourBySequence(seqColour.isSelected());
936 if (_colourwith == null)
938 _colourwith = new Vector<AlignmentPanel>();
940 if (jmb.isColourBySequence())
942 if (!jmb.isLoadingFromArchive())
944 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
946 // Make the currently displayed alignment panel the associated view
947 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
950 // Set the colour using the current view for the associated alignframe
951 for (AlignmentPanel ap : _colourwith)
953 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
959 public void chainColour_actionPerformed(ActionEvent actionEvent)
961 chainColour.setSelected(true);
966 public void chargeColour_actionPerformed(ActionEvent actionEvent)
968 chargeColour.setSelected(true);
969 jmb.colourByCharge();
973 public void zappoColour_actionPerformed(ActionEvent actionEvent)
975 zappoColour.setSelected(true);
976 jmb.setJalviewColourScheme(new ZappoColourScheme());
980 public void taylorColour_actionPerformed(ActionEvent actionEvent)
982 taylorColour.setSelected(true);
983 jmb.setJalviewColourScheme(new TaylorColourScheme());
987 public void hydroColour_actionPerformed(ActionEvent actionEvent)
989 hydroColour.setSelected(true);
990 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
994 public void helixColour_actionPerformed(ActionEvent actionEvent)
996 helixColour.setSelected(true);
997 jmb.setJalviewColourScheme(new HelixColourScheme());
1001 public void strandColour_actionPerformed(ActionEvent actionEvent)
1003 strandColour.setSelected(true);
1004 jmb.setJalviewColourScheme(new StrandColourScheme());
1008 public void turnColour_actionPerformed(ActionEvent actionEvent)
1010 turnColour.setSelected(true);
1011 jmb.setJalviewColourScheme(new TurnColourScheme());
1015 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1017 buriedColour.setSelected(true);
1018 jmb.setJalviewColourScheme(new BuriedColourScheme());
1022 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1024 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1028 public void userColour_actionPerformed(ActionEvent actionEvent)
1030 userColour.setSelected(true);
1031 new UserDefinedColours(this, null);
1035 public void backGround_actionPerformed(ActionEvent actionEvent)
1037 java.awt.Color col = JColorChooser
1038 .showDialog(this, MessageManager
1039 .getString("label.select_backgroud_colour"), null);
1042 jmb.setBackgroundColour(col);
1047 public void showHelp_actionPerformed(ActionEvent actionEvent)
1051 jalview.util.BrowserLauncher
1052 .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
1053 } catch (Exception ex)
1058 public void updateTitleAndMenus()
1060 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1065 setChainMenuItems(jmb.getChainNames());
1067 this.setTitle(jmb.getViewerTitle("Chimera", true));
1068 // if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1070 viewerActionMenu.setVisible(true);
1072 if (!jmb.isLoadingFromArchive())
1074 seqColour_actionPerformed(null);
1082 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1086 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1088 alignStructs_withAllAlignPanels();
1091 private void alignStructs_withAllAlignPanels()
1093 if (getAlignmentPanel() == null)
1098 if (_alignwith.size() == 0)
1100 _alignwith.add(getAlignmentPanel());
1105 AlignmentI[] als = new Alignment[_alignwith.size()];
1106 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1107 int[] alm = new int[_alignwith.size()];
1110 for (AlignmentPanel ap : _alignwith)
1112 als[a] = ap.av.getAlignment();
1114 alc[a++] = ap.av.getColumnSelection();
1116 jmb.superposeStructures(als, alm, alc);
1117 } catch (Exception e)
1119 StringBuffer sp = new StringBuffer();
1120 for (AlignmentPanel ap : _alignwith)
1122 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1124 Cache.log.info("Couldn't align structures with the " + sp.toString()
1125 + "associated alignment panels.", e);
1130 public void setJalviewColourScheme(ColourSchemeI ucs)
1132 jmb.setJalviewColourScheme(ucs);
1139 * @return first alignment panel displaying given alignment, or the default
1142 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1144 for (AlignmentPanel ap : getAllAlignmentPanels())
1146 if (ap.av.getAlignment() == alignment)
1151 return getAlignmentPanel();
1155 public AAStructureBindingModel getBinding()
1161 * Ask Chimera to save its session to the designated file path, or to a
1162 * temporary file if the path is null. Returns the file path if successful,
1168 protected String saveSession(String filepath)
1170 String pathUsed = filepath;
1173 if (pathUsed == null)
1175 File tempFile = File.createTempFile("chimera", ".py");
1176 tempFile.deleteOnExit();
1177 pathUsed = tempFile.getPath();
1179 boolean result = jmb.saveSession(pathUsed);
1182 this.chimeraSessionFile = pathUsed;
1185 } catch (IOException e)
1192 * Returns a string representing the state of the Chimera session. This is
1193 * done by requesting Chimera to save its session to a temporary file, then
1194 * reading the file contents. Returns an empty string on any error.
1197 public String getStateInfo()
1199 String sessionFile = saveSession(null);
1200 if (sessionFile == null)
1204 InputStream is = null;
1207 File f = new File(sessionFile);
1208 byte[] bytes = new byte[(int) f.length()];
1209 is = new FileInputStream(sessionFile);
1211 return new String(bytes);
1212 } catch (IOException e)
1222 } catch (IOException e)
1231 protected void fitToWindow_actionPerformed()
1237 public ViewerType getViewerType()
1239 return ViewerType.CHIMERA;
1243 protected AAStructureBindingModel getBindingModel()