2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.bin.Cache;
24 import jalview.datamodel.Alignment;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.ColumnSelection;
27 import jalview.datamodel.PDBEntry;
28 import jalview.datamodel.SequenceI;
29 import jalview.ext.rbvi.chimera.ChimeraCommands;
30 import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
31 import jalview.gui.StructureViewer.ViewerType;
32 import jalview.io.AppletFormatAdapter;
33 import jalview.io.JalviewFileChooser;
34 import jalview.io.JalviewFileView;
35 import jalview.io.StructureFile;
36 import jalview.schemes.BuriedColourScheme;
37 import jalview.schemes.ColourSchemeI;
38 import jalview.schemes.HelixColourScheme;
39 import jalview.schemes.HydrophobicColourScheme;
40 import jalview.schemes.PurinePyrimidineColourScheme;
41 import jalview.schemes.StrandColourScheme;
42 import jalview.schemes.TaylorColourScheme;
43 import jalview.schemes.TurnColourScheme;
44 import jalview.schemes.ZappoColourScheme;
45 import jalview.structures.models.AAStructureBindingModel;
46 import jalview.util.MessageManager;
47 import jalview.util.Platform;
48 import jalview.ws.dbsources.Pdb;
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.awt.event.MouseAdapter;
55 import java.awt.event.MouseEvent;
56 import java.io.BufferedReader;
58 import java.io.FileInputStream;
59 import java.io.FileOutputStream;
60 import java.io.FileReader;
61 import java.io.IOException;
62 import java.io.InputStream;
63 import java.io.PrintWriter;
64 import java.util.ArrayList;
65 import java.util.Collections;
66 import java.util.List;
67 import java.util.Random;
68 import java.util.Vector;
70 import javax.swing.JCheckBoxMenuItem;
71 import javax.swing.JColorChooser;
72 import javax.swing.JInternalFrame;
73 import javax.swing.JMenu;
74 import javax.swing.JMenuItem;
75 import javax.swing.JOptionPane;
76 import javax.swing.event.InternalFrameAdapter;
77 import javax.swing.event.InternalFrameEvent;
78 import javax.swing.event.MenuEvent;
79 import javax.swing.event.MenuListener;
82 * GUI elements for handling an external chimera display
87 public class ChimeraViewFrame extends StructureViewerBase
89 private JalviewChimeraBinding jmb;
91 private boolean allChainsSelected = false;
93 private IProgressIndicator progressBar = null;
96 * Path to Chimera session file. This is set when an open Jalview/Chimera
97 * session is saved, or on restore from a Jalview project (if it holds the
98 * filename of any saved Chimera sessions).
100 private String chimeraSessionFile = null;
102 private Random random = new Random();
105 * Initialise menu options.
107 private void initMenus()
109 viewerActionMenu.setText(MessageManager.getString("label.chimera"));
110 viewerColour.setText(MessageManager
111 .getString("label.colour_with_chimera"));
112 viewerColour.setToolTipText(MessageManager
113 .getString("label.let_chimera_manage_structure_colours"));
114 helpItem.setText(MessageManager.getString("label.chimera_help"));
115 seqColour.setSelected(jmb.isColourBySequence());
116 viewerColour.setSelected(!jmb.isColourBySequence());
117 if (_colourwith == null)
119 _colourwith = new Vector<AlignmentPanel>();
121 if (_alignwith == null)
123 _alignwith = new Vector<AlignmentPanel>();
126 // save As not yet implemented
127 savemenu.setVisible(false);
129 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
130 MessageManager.getString("label.colour_by"), this, _colourwith,
134 public void itemStateChanged(ItemEvent e)
136 if (!seqColour.isSelected())
142 // update the Chimera display now.
143 seqColour_actionPerformed(null);
147 viewMenu.add(seqColourBy);
148 viewMenu.add(fitToWindow);
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",
162 new Object[] { new Integer(_alignwith
163 .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
190 JMenuItem writeFeatures = new JMenuItem(
191 MessageManager.getString("label.create_chimera_attributes"));
192 writeFeatures.setToolTipText(MessageManager
193 .getString("label.create_chimera_attributes_tip"));
194 writeFeatures.addActionListener(new ActionListener()
197 public void actionPerformed(ActionEvent e)
199 sendFeaturesToChimera();
202 viewerActionMenu.add(writeFeatures);
204 final JMenu fetchAttributes = new JMenu("Fetch Chimera attributes");
206 .setToolTipText("Copy Chimera attribute to Jalview feature");
207 fetchAttributes.addMouseListener(new MouseAdapter()
211 public void mouseEntered(MouseEvent e)
213 buildAttributesMenu(fetchAttributes);
216 viewerActionMenu.add(fetchAttributes);
221 * Query Chimera for its residue attribute names and add them as items off the
224 * @param attributesMenu
226 protected void buildAttributesMenu(JMenu attributesMenu)
228 List<String> atts = jmb.sendChimeraCommand("list resattr", true);
233 attributesMenu.removeAll();
234 Collections.sort(atts);
235 for (String att : atts)
237 final String attName = att.split(" ")[1];
240 * ignore 'jv_*' attributes, as these are Jalview features that have
241 * been transferred to residue attributes in Chimera!
243 if (!attName.startsWith(ChimeraCommands.NAMESPACE_PREFIX))
245 JMenuItem menuItem = new JMenuItem(attName);
246 menuItem.addActionListener(new ActionListener()
249 public void actionPerformed(ActionEvent e)
251 getChimeraAttributes(attName);
254 attributesMenu.add(menuItem);
260 * Read residues in Chimera with the given attribute name, and set as features
261 * on the corresponding sequence positions (if any)
265 protected void getChimeraAttributes(String attName)
267 jmb.copyStructureAttributesToFeatures(attName, getAlignmentPanel());
271 * Send a command to Chimera to create residue attributes for Jalview features
273 * The syntax is: setattr r <attName> <attValue> <atomSpec>
275 * For example: setattr r jv:chain "Ferredoxin-1, Chloroplastic" #0:94.A
277 protected void sendFeaturesToChimera()
279 jmb.sendFeaturesToViewer(getAlignmentPanel());
283 * add a single PDB structure to a new or existing Chimera view
290 public ChimeraViewFrame(PDBEntry pdbentry, SequenceI[] seq,
291 String[] chains, final AlignmentPanel ap)
294 String pdbId = pdbentry.getId();
297 * If the PDB file is already loaded, the user may just choose to add to an
298 * existing viewer (or cancel)
300 if (addAlreadyLoadedFile(seq, chains, ap, pdbId))
306 * Check if there are other Chimera views involving this alignment and give
307 * user the option to add and align this molecule to one of them (or cancel)
309 if (addToExistingViewer(pdbentry, seq, chains, ap, pdbId))
315 * If the options above are declined or do not apply, show the structure in
318 openNewChimera(ap, new PDBEntry[] { pdbentry },
319 new SequenceI[][] { seq });
323 * Create a helper to manage progress bar display
325 protected void createProgressBar()
327 if (progressBar == null)
329 progressBar = new ProgressBar(statusPanel, statusBar);
334 * Answers true if this viewer already involves the given PDB ID
337 protected boolean hasPdbId(String pdbId)
339 return jmb.hasPdbId(pdbId);
342 private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
346 jmb = new JalviewChimeraBindingModel(this,
347 ap.getStructureSelectionManager(), pdbentrys, seqs, null);
348 addAlignmentPanel(ap);
349 useAlignmentPanelForColourbyseq(ap);
350 if (pdbentrys.length > 1)
352 alignAddedStructures = true;
353 useAlignmentPanelForSuperposition(ap);
355 jmb.setColourBySequence(true);
356 setSize(400, 400); // probably should be a configurable/dynamic default here
359 addingStructures = false;
360 worker = new Thread(this);
363 this.addInternalFrameListener(new InternalFrameAdapter()
366 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
375 * Create a new viewer from saved session state data including Chimera session
378 * @param chimeraSessionFile
382 * @param colourByChimera
383 * @param colourBySequence
386 public ChimeraViewFrame(String chimeraSessionFile,
387 AlignmentPanel alignPanel, PDBEntry[] pdbArray,
388 SequenceI[][] seqsArray, boolean colourByChimera,
389 boolean colourBySequence, String newViewId)
392 setViewId(newViewId);
393 this.chimeraSessionFile = chimeraSessionFile;
394 openNewChimera(alignPanel, pdbArray, seqsArray);
397 jmb.setColourBySequence(false);
398 seqColour.setSelected(false);
399 viewerColour.setSelected(true);
401 else if (colourBySequence)
403 jmb.setColourBySequence(true);
404 seqColour.setSelected(true);
405 viewerColour.setSelected(false);
410 * create a new viewer containing several structures superimposed using the
417 public ChimeraViewFrame(PDBEntry[] pe, SequenceI[][] seqs,
421 openNewChimera(ap, pe, seqs);
425 * Default constructor
427 public ChimeraViewFrame()
432 * closeViewer will decide whether or not to close this frame
433 * depending on whether user chooses to Cancel or not
435 setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
439 * Returns a list of any Chimera viewers in the desktop. The list is
440 * restricted to those linked to the given alignment panel if it is not null.
443 protected List<StructureViewerBase> getViewersFor(AlignmentPanel ap)
445 List<StructureViewerBase> result = new ArrayList<StructureViewerBase>();
446 JInternalFrame[] frames = Desktop.instance.getAllFrames();
448 for (JInternalFrame frame : frames)
450 if (frame instanceof ChimeraViewFrame)
452 if (ap == null || ((StructureViewerBase) frame).isLinkedWith(ap))
454 result.add((StructureViewerBase) frame);
462 * Launch Chimera. If we have a chimera session file name, send Chimera the
463 * command to open its saved session file.
467 Desktop.addInternalFrame(this, jmb.getViewerTitle("Chimera", true),
468 getBounds().width, getBounds().height);
470 if (!jmb.launchChimera())
472 JOptionPane.showMessageDialog(Desktop.desktop,
473 MessageManager.getString("label.chimera_failed"),
474 MessageManager.getString("label.error_loading_file"),
475 JOptionPane.ERROR_MESSAGE);
480 if (this.chimeraSessionFile != null)
482 boolean opened = jmb.openSession(chimeraSessionFile);
486 .println("An error occurred opening Chimera session file "
487 + chimeraSessionFile);
491 jmb.startChimeraListener();
495 * If the list is not empty, add menu items for 'All' and each individual
496 * chain to the "View | Show Chain" sub-menu. Multiple selections are allowed.
501 void setChainMenuItems(List<String> chainNames)
503 chainMenu.removeAll();
504 if (chainNames == null || chainNames.isEmpty())
508 JMenuItem menuItem = new JMenuItem(
509 MessageManager.getString("label.all"));
510 menuItem.addActionListener(new ActionListener()
513 public void actionPerformed(ActionEvent evt)
515 allChainsSelected = true;
516 for (int i = 0; i < chainMenu.getItemCount(); i++)
518 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
520 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
523 showSelectedChains();
524 allChainsSelected = false;
528 chainMenu.add(menuItem);
530 for (String chainName : chainNames)
532 menuItem = new JCheckBoxMenuItem(chainName, true);
533 menuItem.addItemListener(new ItemListener()
536 public void itemStateChanged(ItemEvent evt)
538 if (!allChainsSelected)
540 showSelectedChains();
545 chainMenu.add(menuItem);
550 * Show only the selected chain(s) in the viewer
553 void showSelectedChains()
555 List<String> toshow = new ArrayList<String>();
556 for (int i = 0; i < chainMenu.getItemCount(); i++)
558 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
560 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
561 if (item.isSelected())
563 toshow.add(item.getText());
567 jmb.showChains(toshow);
571 * Close down this instance of Jalview's Chimera viewer, giving the user the
572 * option to close the associated Chimera window (process). They may wish to
573 * keep it open until they have had an opportunity to save any work.
575 * @param closeChimera
576 * if true, close any linked Chimera process; if false, prompt first
579 public void closeViewer(boolean closeChimera)
581 if (jmb != null && jmb.isChimeraRunning())
585 String prompt = MessageManager.formatMessage(
586 "label.confirm_close_chimera",
587 new Object[] { jmb.getViewerTitle("Chimera", false) });
588 prompt = JvSwingUtils.wrapTooltip(true, prompt);
589 int confirm = JOptionPane.showConfirmDialog(this, prompt,
590 MessageManager.getString("label.close_viewer"),
591 JOptionPane.YES_NO_CANCEL_OPTION);
593 * abort closure if user hits escape or Cancel
595 if (confirm == JOptionPane.CANCEL_OPTION
596 || confirm == JOptionPane.CLOSED_OPTION)
600 closeChimera = confirm == JOptionPane.YES_OPTION;
602 jmb.closeViewer(closeChimera);
604 setAlignmentPanel(null);
608 // TODO: check for memory leaks where instance isn't finalised because jmb
609 // holds a reference to the window
615 * Open any newly added PDB structures in Chimera, having first fetched data
616 * from PDB (if not already saved).
622 // todo - record which pdbids were successfully imported.
623 StringBuilder errormsgs = new StringBuilder(128);
624 StringBuilder files = new StringBuilder(128);
625 List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
626 List<Integer> filePDBpos = new ArrayList<Integer>();
627 PDBEntry thePdbEntry = null;
628 StructureFile pdb = null;
631 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
632 // TODO: replace with reference fetching/transfer code (validate PDBentry
634 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
637 thePdbEntry = jmb.getPdbEntry(pi);
638 if (thePdbEntry.getFile() == null)
641 * Retrieve PDB data, save to file, attach to PDBEntry
643 file = fetchPdbFile(thePdbEntry);
646 errormsgs.append("'" + thePdbEntry.getId() + "' ");
652 * Got file already - ignore if already loaded in Chimera.
654 file = new File(thePdbEntry.getFile()).getAbsoluteFile()
656 if (curfiles != null && curfiles.length > 0)
658 addingStructures = true; // already files loaded.
659 for (int c = 0; c < curfiles.length; c++)
661 if (curfiles[c].equals(file))
671 filePDB.add(thePdbEntry);
672 filePDBpos.add(Integer.valueOf(pi));
673 files.append(" \"" + Platform.escapeString(file) + "\"");
676 } catch (OutOfMemoryError oomerror)
678 new OOMWarning("Retrieving PDB files: " + thePdbEntry.getId(),
680 } catch (Exception ex)
682 ex.printStackTrace();
683 errormsgs.append("When retrieving pdbfiles for '"
684 + thePdbEntry.getId() + "'");
686 if (errormsgs.length() > 0)
689 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
690 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
691 new Object[] { errormsgs.toString() }),
692 MessageManager.getString("label.couldnt_load_file"),
693 JOptionPane.ERROR_MESSAGE);
696 if (files.length() > 0)
698 jmb.setFinishedInit(false);
699 if (!addingStructures)
704 } catch (Exception ex)
706 Cache.log.error("Couldn't open Chimera viewer!", ex);
710 for (PDBEntry pe : filePDB)
713 if (pe.getFile() != null)
717 int pos = filePDBpos.get(num).intValue();
718 long startTime = startProgressBar("Chimera "
719 + MessageManager.getString("status.opening_file_for")
722 jmb.addSequence(pos, jmb.getSequence()[pos]);
723 File fl = new File(pe.getFile());
724 String protocol = AppletFormatAdapter.URL;
729 protocol = AppletFormatAdapter.FILE;
731 } catch (Throwable e)
735 stopProgressBar("", startTime);
737 // Explicitly map to the filename used by Chimera ;
738 pdb = jmb.getSsm().setMapping(jmb.getSequence()[pos],
739 jmb.getChains()[pos], pe.getFile(), protocol);
740 stashFoundChains(pdb, pe.getFile());
741 } catch (OutOfMemoryError oomerror)
744 "When trying to open and map structures from Chimera!",
746 } catch (Exception ex)
748 Cache.log.error("Couldn't open " + pe.getFile()
749 + " in Chimera viewer!", ex);
752 Cache.log.debug("File locations are " + files);
758 jmb.setFinishedInit(true);
759 jmb.setLoadingFromArchive(false);
761 // refresh the sequence colours for the new structure(s)
762 for (AlignmentPanel ap : _colourwith)
764 jmb.updateColours(ap);
766 // do superposition if asked to
767 if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures)
769 new Thread(new Runnable()
774 alignStructs_withAllAlignPanels();
777 alignAddedStructures = false;
779 addingStructures = false;
786 * Fetch PDB data and save to a local file. Returns the full path to the file,
787 * or null if fetch fails.
789 * @param processingEntry
794 private void stashFoundChains(StructureFile pdb, String file)
796 for (int i = 0; i < pdb.getChains().size(); i++)
798 String chid = new String(pdb.getId() + ":"
799 + pdb.getChains().elementAt(i).id);
800 jmb.getChainNames().add(chid);
801 jmb.getChainFile().put(chid, file);
804 private String fetchPdbFile(PDBEntry processingEntry) throws Exception
806 // FIXME: this is duplicated code with Jmol frame ?
807 String filePath = null;
808 Pdb pdbclient = new Pdb();
809 AlignmentI pdbseq = null;
810 String pdbid = processingEntry.getId();
811 long handle = System.currentTimeMillis()
812 + Thread.currentThread().hashCode();
815 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
817 String msg = MessageManager.formatMessage("status.fetching_pdb",
818 new Object[] { pdbid });
819 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
820 // long hdl = startProgressBar(MessageManager.formatMessage(
821 // "status.fetching_pdb", new Object[]
825 pdbseq = pdbclient.getSequenceRecords(pdbid);
826 } catch (OutOfMemoryError oomerror)
828 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
831 msg = pdbid + " " + MessageManager.getString("label.state_completed");
832 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
833 // stopProgressBar(msg, hdl);
836 * If PDB data were saved and are not invalid (empty alignment), return the
839 if (pdbseq != null && pdbseq.getHeight() > 0)
841 // just use the file name from the first sequence's first PDBEntry
842 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
843 .elementAt(0).getFile()).getAbsolutePath();
844 processingEntry.setFile(filePath);
850 * Convenience method to update the progress bar if there is one. Be sure to
851 * call stopProgressBar with the returned handle to remove the message.
856 public long startProgressBar(String msg)
858 // TODO would rather have startProgress/stopProgress as the
859 // IProgressIndicator interface
860 long tm = random.nextLong();
861 if (progressBar != null)
863 progressBar.setProgressBar(msg, tm);
869 * End the progress bar with the specified handle, leaving a message (if not
870 * null) on the status bar
875 public void stopProgressBar(String msg, long handle)
877 if (progressBar != null)
879 progressBar.setProgressBar(msg, handle);
884 public void pdbFile_actionPerformed(ActionEvent actionEvent)
886 JalviewFileChooser chooser = new JalviewFileChooser(
887 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
889 chooser.setFileView(new JalviewFileView());
890 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
891 chooser.setToolTipText(MessageManager.getString("action.save"));
893 int value = chooser.showSaveDialog(this);
895 if (value == JalviewFileChooser.APPROVE_OPTION)
897 BufferedReader in = null;
900 // TODO: cope with multiple PDB files in view
901 in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
902 File outFile = chooser.getSelectedFile();
904 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
906 while ((data = in.readLine()) != null)
908 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
914 } catch (Exception ex)
916 ex.printStackTrace();
924 } catch (IOException e)
934 public void viewMapping_actionPerformed(ActionEvent actionEvent)
936 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
939 cap.appendText(jmb.printMappings());
940 } catch (OutOfMemoryError e)
943 "composing sequence-structure alignments for display in text box.",
948 jalview.gui.Desktop.addInternalFrame(cap,
949 MessageManager.getString("label.pdb_sequence_mapping"), 550,
954 public void eps_actionPerformed(ActionEvent e)
958 .getString("error.eps_generation_not_implemented"));
962 public void png_actionPerformed(ActionEvent e)
966 .getString("error.png_generation_not_implemented"));
970 public void viewerColour_actionPerformed(ActionEvent actionEvent)
972 if (viewerColour.isSelected())
974 // disable automatic sequence colouring.
975 jmb.setColourBySequence(false);
980 public void seqColour_actionPerformed(ActionEvent actionEvent)
982 jmb.setColourBySequence(seqColour.isSelected());
983 if (_colourwith == null)
985 _colourwith = new Vector<AlignmentPanel>();
987 if (jmb.isColourBySequence())
989 if (!jmb.isLoadingFromArchive())
991 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
993 // Make the currently displayed alignment panel the associated view
994 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
997 // Set the colour using the current view for the associated alignframe
998 for (AlignmentPanel ap : _colourwith)
1000 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
1006 public void chainColour_actionPerformed(ActionEvent actionEvent)
1008 chainColour.setSelected(true);
1009 jmb.colourByChain();
1013 public void chargeColour_actionPerformed(ActionEvent actionEvent)
1015 chargeColour.setSelected(true);
1016 jmb.colourByCharge();
1020 public void zappoColour_actionPerformed(ActionEvent actionEvent)
1022 zappoColour.setSelected(true);
1023 jmb.setJalviewColourScheme(new ZappoColourScheme());
1027 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1029 taylorColour.setSelected(true);
1030 jmb.setJalviewColourScheme(new TaylorColourScheme());
1034 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1036 hydroColour.setSelected(true);
1037 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1041 public void helixColour_actionPerformed(ActionEvent actionEvent)
1043 helixColour.setSelected(true);
1044 jmb.setJalviewColourScheme(new HelixColourScheme());
1048 public void strandColour_actionPerformed(ActionEvent actionEvent)
1050 strandColour.setSelected(true);
1051 jmb.setJalviewColourScheme(new StrandColourScheme());
1055 public void turnColour_actionPerformed(ActionEvent actionEvent)
1057 turnColour.setSelected(true);
1058 jmb.setJalviewColourScheme(new TurnColourScheme());
1062 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1064 buriedColour.setSelected(true);
1065 jmb.setJalviewColourScheme(new BuriedColourScheme());
1069 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1071 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1075 public void userColour_actionPerformed(ActionEvent actionEvent)
1077 userColour.setSelected(true);
1078 new UserDefinedColours(this, null);
1082 public void backGround_actionPerformed(ActionEvent actionEvent)
1084 java.awt.Color col = JColorChooser
1085 .showDialog(this, MessageManager
1086 .getString("label.select_backgroud_colour"), null);
1089 jmb.setBackgroundColour(col);
1094 public void showHelp_actionPerformed(ActionEvent actionEvent)
1098 jalview.util.BrowserLauncher
1099 .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
1100 } catch (Exception ex)
1105 public void updateTitleAndMenus()
1107 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1112 setChainMenuItems(jmb.getChainNames());
1114 this.setTitle(jmb.getViewerTitle("Chimera", true));
1115 // if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1117 viewerActionMenu.setVisible(true);
1119 if (!jmb.isLoadingFromArchive())
1121 seqColour_actionPerformed(null);
1129 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1133 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1135 alignStructs_withAllAlignPanels();
1138 private void alignStructs_withAllAlignPanels()
1140 if (getAlignmentPanel() == null)
1145 if (_alignwith.size() == 0)
1147 _alignwith.add(getAlignmentPanel());
1152 AlignmentI[] als = new Alignment[_alignwith.size()];
1153 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1154 int[] alm = new int[_alignwith.size()];
1157 for (AlignmentPanel ap : _alignwith)
1159 als[a] = ap.av.getAlignment();
1161 alc[a++] = ap.av.getColumnSelection();
1163 jmb.superposeStructures(als, alm, alc);
1164 } catch (Exception e)
1166 StringBuffer sp = new StringBuffer();
1167 for (AlignmentPanel ap : _alignwith)
1169 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1171 Cache.log.info("Couldn't align structures with the " + sp.toString()
1172 + "associated alignment panels.", e);
1177 public void setJalviewColourScheme(ColourSchemeI ucs)
1179 jmb.setJalviewColourScheme(ucs);
1186 * @return first alignment panel displaying given alignment, or the default
1189 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1191 for (AlignmentPanel ap : getAllAlignmentPanels())
1193 if (ap.av.getAlignment() == alignment)
1198 return getAlignmentPanel();
1202 public AAStructureBindingModel getBinding()
1208 * Ask Chimera to save its session to the designated file path, or to a
1209 * temporary file if the path is null. Returns the file path if successful,
1215 protected String saveSession(String filepath)
1217 String pathUsed = filepath;
1220 if (pathUsed == null)
1222 File tempFile = File.createTempFile("chimera", ".py");
1223 tempFile.deleteOnExit();
1224 pathUsed = tempFile.getPath();
1226 boolean result = jmb.saveSession(pathUsed);
1229 this.chimeraSessionFile = pathUsed;
1232 } catch (IOException e)
1239 * Returns a string representing the state of the Chimera session. This is
1240 * done by requesting Chimera to save its session to a temporary file, then
1241 * reading the file contents. Returns an empty string on any error.
1244 public String getStateInfo()
1246 String sessionFile = saveSession(null);
1247 if (sessionFile == null)
1251 InputStream is = null;
1254 File f = new File(sessionFile);
1255 byte[] bytes = new byte[(int) f.length()];
1256 is = new FileInputStream(sessionFile);
1258 return new String(bytes);
1259 } catch (IOException e)
1269 } catch (IOException e)
1278 protected void fitToWindow_actionPerformed()
1284 public ViewerType getViewerType()
1286 return ViewerType.CHIMERA;
1290 protected AAStructureBindingModel getBindingModel()