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.DataSourceType;
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.event.InternalFrameAdapter;
76 import javax.swing.event.InternalFrameEvent;
77 import javax.swing.event.MenuEvent;
78 import javax.swing.event.MenuListener;
81 * GUI elements for handling an external chimera display
86 public class ChimeraViewFrame extends StructureViewerBase
88 private JalviewChimeraBinding jmb;
90 private boolean allChainsSelected = false;
92 private IProgressIndicator progressBar = null;
95 * Path to Chimera session file. This is set when an open Jalview/Chimera
96 * session is saved, or on restore from a Jalview project (if it holds the
97 * filename of any saved Chimera sessions).
99 private String chimeraSessionFile = null;
101 private Random random = new Random();
104 * Initialise menu options.
106 private void initMenus()
108 viewerActionMenu.setText(MessageManager.getString("label.chimera"));
109 viewerColour.setText(MessageManager
110 .getString("label.colour_with_chimera"));
111 viewerColour.setToolTipText(MessageManager
112 .getString("label.let_chimera_manage_structure_colours"));
113 helpItem.setText(MessageManager.getString("label.chimera_help"));
114 seqColour.setSelected(jmb.isColourBySequence());
115 viewerColour.setSelected(!jmb.isColourBySequence());
116 if (_colourwith == null)
118 _colourwith = new Vector<AlignmentPanel>();
120 if (_alignwith == null)
122 _alignwith = new Vector<AlignmentPanel>();
125 // save As not yet implemented
126 savemenu.setVisible(false);
128 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
129 MessageManager.getString("label.colour_by"), this, _colourwith,
133 public void itemStateChanged(ItemEvent e)
135 if (!seqColour.isSelected())
141 // update the Chimera display now.
142 seqColour_actionPerformed(null);
146 viewMenu.add(seqColourBy);
147 viewMenu.add(fitToWindow);
149 final ItemListener handler;
150 JMenu alpanels = new ViewSelectionMenu(
151 MessageManager.getString("label.superpose_with"), this,
152 _alignwith, handler = new ItemListener()
155 public void itemStateChanged(ItemEvent e)
157 alignStructs.setEnabled(_alignwith.size() > 0);
158 alignStructs.setToolTipText(MessageManager
160 "label.align_structures_using_linked_alignment_views",
161 new Object[] { new Integer(_alignwith
162 .size()).toString() }));
165 handler.itemStateChanged(null);
166 viewerActionMenu.add(alpanels);
167 viewerActionMenu.addMenuListener(new MenuListener()
171 public void menuSelected(MenuEvent e)
173 handler.itemStateChanged(null);
177 public void menuDeselected(MenuEvent e)
179 // TODO Auto-generated method stub
183 public void menuCanceled(MenuEvent e)
185 // TODO Auto-generated method stub
189 JMenuItem writeFeatures = new JMenuItem(
190 MessageManager.getString("label.create_chimera_attributes"));
191 writeFeatures.setToolTipText(MessageManager
192 .getString("label.create_chimera_attributes_tip"));
193 writeFeatures.addActionListener(new ActionListener()
196 public void actionPerformed(ActionEvent e)
198 sendFeaturesToChimera();
201 viewerActionMenu.add(writeFeatures);
203 final JMenu fetchAttributes = new JMenu("Fetch Chimera attributes");
205 .setToolTipText("Copy Chimera attribute to Jalview feature");
206 fetchAttributes.addMouseListener(new MouseAdapter()
210 public void mouseEntered(MouseEvent e)
212 buildAttributesMenu(fetchAttributes);
215 viewerActionMenu.add(fetchAttributes);
220 * Query Chimera for its residue attribute names and add them as items off the
223 * @param attributesMenu
225 protected void buildAttributesMenu(JMenu attributesMenu)
227 List<String> atts = jmb.sendChimeraCommand("list resattr", true);
232 attributesMenu.removeAll();
233 Collections.sort(atts);
234 for (String att : atts)
236 final String attName = att.split(" ")[1];
239 * ignore 'jv_*' attributes, as these are Jalview features that have
240 * been transferred to residue attributes in Chimera!
242 if (!attName.startsWith(ChimeraCommands.NAMESPACE_PREFIX))
244 JMenuItem menuItem = new JMenuItem(attName);
245 menuItem.addActionListener(new ActionListener()
248 public void actionPerformed(ActionEvent e)
250 getChimeraAttributes(attName);
253 attributesMenu.add(menuItem);
259 * Read residues in Chimera with the given attribute name, and set as features
260 * on the corresponding sequence positions (if any)
264 protected void getChimeraAttributes(String attName)
266 jmb.copyStructureAttributesToFeatures(attName, getAlignmentPanel());
270 * Send a command to Chimera to create residue attributes for Jalview features
272 * The syntax is: setattr r <attName> <attValue> <atomSpec>
274 * For example: setattr r jv:chain "Ferredoxin-1, Chloroplastic" #0:94.A
276 protected void sendFeaturesToChimera()
278 jmb.sendFeaturesToViewer(getAlignmentPanel());
282 * add a single PDB structure to a new or existing Chimera view
289 public ChimeraViewFrame(PDBEntry pdbentry, SequenceI[] seq,
290 String[] chains, final AlignmentPanel ap)
293 String pdbId = pdbentry.getId();
296 * If the PDB file is already loaded, the user may just choose to add to an
297 * existing viewer (or cancel)
299 if (addAlreadyLoadedFile(seq, chains, ap, pdbId))
305 * Check if there are other Chimera views involving this alignment and give
306 * user the option to add and align this molecule to one of them (or cancel)
308 if (addToExistingViewer(pdbentry, seq, chains, ap, pdbId))
314 * If the options above are declined or do not apply, show the structure in
317 openNewChimera(ap, new PDBEntry[] { pdbentry },
318 new SequenceI[][] { seq });
322 * Create a helper to manage progress bar display
324 protected void createProgressBar()
326 if (progressBar == null)
328 progressBar = new ProgressBar(statusPanel, statusBar);
333 * Answers true if this viewer already involves the given PDB ID
336 protected boolean hasPdbId(String pdbId)
338 return jmb.hasPdbId(pdbId);
341 private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
345 jmb = new JalviewChimeraBindingModel(this,
346 ap.getStructureSelectionManager(), pdbentrys, seqs, null);
347 addAlignmentPanel(ap);
348 useAlignmentPanelForColourbyseq(ap);
349 if (pdbentrys.length > 1)
351 alignAddedStructures = true;
352 useAlignmentPanelForSuperposition(ap);
354 jmb.setColourBySequence(true);
355 setSize(400, 400); // probably should be a configurable/dynamic default here
358 addingStructures = false;
359 worker = new Thread(this);
362 this.addInternalFrameListener(new InternalFrameAdapter()
365 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
374 * Create a new viewer from saved session state data including Chimera session
377 * @param chimeraSessionFile
381 * @param colourByChimera
382 * @param colourBySequence
385 public ChimeraViewFrame(String chimeraSessionFile,
386 AlignmentPanel alignPanel, PDBEntry[] pdbArray,
387 SequenceI[][] seqsArray, boolean colourByChimera,
388 boolean colourBySequence, String newViewId)
391 setViewId(newViewId);
392 this.chimeraSessionFile = chimeraSessionFile;
393 openNewChimera(alignPanel, pdbArray, seqsArray);
396 jmb.setColourBySequence(false);
397 seqColour.setSelected(false);
398 viewerColour.setSelected(true);
400 else if (colourBySequence)
402 jmb.setColourBySequence(true);
403 seqColour.setSelected(true);
404 viewerColour.setSelected(false);
409 * create a new viewer containing several structures superimposed using the
416 public ChimeraViewFrame(PDBEntry[] pe, SequenceI[][] seqs,
420 openNewChimera(ap, pe, seqs);
424 * Default constructor
426 public ChimeraViewFrame()
431 * closeViewer will decide whether or not to close this frame
432 * depending on whether user chooses to Cancel or not
434 setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
439 * Launch Chimera. If we have a chimera session file name, send Chimera the
440 * command to open its saved session file.
444 Desktop.addInternalFrame(this, jmb.getViewerTitle("Chimera", true),
445 getBounds().width, getBounds().height);
447 if (!jmb.launchChimera())
449 JvOptionPane.showMessageDialog(Desktop.desktop,
450 MessageManager.getString("label.chimera_failed"),
451 MessageManager.getString("label.error_loading_file"),
452 JvOptionPane.ERROR_MESSAGE);
457 if (this.chimeraSessionFile != null)
459 boolean opened = jmb.openSession(chimeraSessionFile);
463 .println("An error occurred opening Chimera session file "
464 + chimeraSessionFile);
468 jmb.startChimeraListener();
472 * If the list is not empty, add menu items for 'All' and each individual
473 * chain to the "View | Show Chain" sub-menu. Multiple selections are allowed.
478 void setChainMenuItems(List<String> chainNames)
480 chainMenu.removeAll();
481 if (chainNames == null || chainNames.isEmpty())
485 JMenuItem menuItem = new JMenuItem(
486 MessageManager.getString("label.all"));
487 menuItem.addActionListener(new ActionListener()
490 public void actionPerformed(ActionEvent evt)
492 allChainsSelected = true;
493 for (int i = 0; i < chainMenu.getItemCount(); i++)
495 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
497 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
500 showSelectedChains();
501 allChainsSelected = false;
505 chainMenu.add(menuItem);
507 for (String chainName : chainNames)
509 menuItem = new JCheckBoxMenuItem(chainName, true);
510 menuItem.addItemListener(new ItemListener()
513 public void itemStateChanged(ItemEvent evt)
515 if (!allChainsSelected)
517 showSelectedChains();
522 chainMenu.add(menuItem);
527 * Show only the selected chain(s) in the viewer
530 void showSelectedChains()
532 List<String> toshow = new ArrayList<String>();
533 for (int i = 0; i < chainMenu.getItemCount(); i++)
535 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
537 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
538 if (item.isSelected())
540 toshow.add(item.getText());
544 jmb.showChains(toshow);
548 * Close down this instance of Jalview's Chimera viewer, giving the user the
549 * option to close the associated Chimera window (process). They may wish to
550 * keep it open until they have had an opportunity to save any work.
552 * @param forceCloseChimera
553 * if true, close any linked Chimera process; if false, prompt first
556 public void closeViewer(boolean forceCloseChimera)
560 if (jmb.isChimeraRunning())
563 * force close, or prompt to close, Chimera
565 if (!forceCloseChimera)
567 String prompt = MessageManager.formatMessage(
568 "label.confirm_close_chimera",
569 new Object[] { jmb.getViewerTitle("Chimera", false) });
570 prompt = JvSwingUtils.wrapTooltip(true, prompt);
571 int confirm = JvOptionPane.showConfirmDialog(this, prompt,
572 MessageManager.getString("label.close_viewer"),
573 JvOptionPane.YES_NO_CANCEL_OPTION);
575 * abort closure if user hits escape or Cancel
577 if (confirm == JvOptionPane.CANCEL_OPTION
578 || confirm == JvOptionPane.CLOSED_OPTION)
582 forceCloseChimera = confirm == JvOptionPane.YES_OPTION;
587 * close the viewer plus any side-effects e.g. remove mappings
588 * note we do this also if closing Chimera triggered this method
590 jmb.closeViewer(forceCloseChimera);
593 setAlignmentPanel(null);
597 // TODO: check for memory leaks where instance isn't finalised because jmb
598 // holds a reference to the window
604 * Open any newly added PDB structures in Chimera, having first fetched data
605 * from PDB (if not already saved).
611 // todo - record which pdbids were successfully imported.
612 StringBuilder errormsgs = new StringBuilder(128);
613 StringBuilder files = new StringBuilder(128);
614 List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
615 List<Integer> filePDBpos = new ArrayList<Integer>();
616 PDBEntry thePdbEntry = null;
617 StructureFile pdb = null;
620 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
621 // TODO: replace with reference fetching/transfer code (validate PDBentry
623 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
626 thePdbEntry = jmb.getPdbEntry(pi);
627 if (thePdbEntry.getFile() == null)
630 * Retrieve PDB data, save to file, attach to PDBEntry
632 file = fetchPdbFile(thePdbEntry);
635 errormsgs.append("'" + thePdbEntry.getId() + "' ");
641 * Got file already - ignore if already loaded in Chimera.
643 file = new File(thePdbEntry.getFile()).getAbsoluteFile()
645 if (curfiles != null && curfiles.length > 0)
647 addingStructures = true; // already files loaded.
648 for (int c = 0; c < curfiles.length; c++)
650 if (curfiles[c].equals(file))
660 filePDB.add(thePdbEntry);
661 filePDBpos.add(Integer.valueOf(pi));
662 files.append(" \"" + Platform.escapeString(file) + "\"");
665 } catch (OutOfMemoryError oomerror)
667 new OOMWarning("Retrieving PDB files: " + thePdbEntry.getId(),
669 } catch (Exception ex)
671 ex.printStackTrace();
672 errormsgs.append("When retrieving pdbfiles for '"
673 + thePdbEntry.getId() + "'");
675 if (errormsgs.length() > 0)
678 JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
679 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
680 new Object[] { errormsgs.toString() }),
681 MessageManager.getString("label.couldnt_load_file"),
682 JvOptionPane.ERROR_MESSAGE);
685 if (files.length() > 0)
687 jmb.setFinishedInit(false);
688 if (!addingStructures)
693 } catch (Exception ex)
695 Cache.log.error("Couldn't open Chimera viewer!", ex);
699 for (PDBEntry pe : filePDB)
702 if (pe.getFile() != null)
706 int pos = filePDBpos.get(num).intValue();
707 long startTime = startProgressBar("Chimera "
708 + MessageManager.getString("status.opening_file_for")
711 jmb.addSequence(pos, jmb.getSequence()[pos]);
712 File fl = new File(pe.getFile());
713 DataSourceType protocol = DataSourceType.URL;
718 protocol = DataSourceType.FILE;
720 } catch (Throwable e)
724 stopProgressBar("", startTime);
726 // Explicitly map to the filename used by Chimera ;
727 pdb = jmb.getSsm().setMapping(jmb.getSequence()[pos],
728 jmb.getChains()[pos], pe.getFile(), protocol);
729 stashFoundChains(pdb, pe.getFile());
730 } catch (OutOfMemoryError oomerror)
733 "When trying to open and map structures from Chimera!",
735 } catch (Exception ex)
737 Cache.log.error("Couldn't open " + pe.getFile()
738 + " in Chimera viewer!", ex);
741 Cache.log.debug("File locations are " + files);
747 jmb.setFinishedInit(true);
748 jmb.setLoadingFromArchive(false);
750 // refresh the sequence colours for the new structure(s)
751 for (AlignmentPanel ap : _colourwith)
753 jmb.updateColours(ap);
755 // do superposition if asked to
756 if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures)
758 new Thread(new Runnable()
763 alignStructs_withAllAlignPanels();
766 alignAddedStructures = false;
768 addingStructures = false;
775 * Fetch PDB data and save to a local file. Returns the full path to the file,
776 * or null if fetch fails.
778 * @param processingEntry
783 private void stashFoundChains(StructureFile pdb, String file)
785 for (int i = 0; i < pdb.getChains().size(); i++)
787 String chid = new String(pdb.getId() + ":"
788 + pdb.getChains().elementAt(i).id);
789 jmb.getChainNames().add(chid);
790 jmb.getChainFile().put(chid, file);
793 private String fetchPdbFile(PDBEntry processingEntry) throws Exception
795 // FIXME: this is duplicated code with Jmol frame ?
796 String filePath = null;
797 Pdb pdbclient = new Pdb();
798 AlignmentI pdbseq = null;
799 String pdbid = processingEntry.getId();
800 long handle = System.currentTimeMillis()
801 + Thread.currentThread().hashCode();
804 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
806 String msg = MessageManager.formatMessage("status.fetching_pdb",
807 new Object[] { pdbid });
808 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
809 // long hdl = startProgressBar(MessageManager.formatMessage(
810 // "status.fetching_pdb", new Object[]
814 pdbseq = pdbclient.getSequenceRecords(pdbid);
815 } catch (OutOfMemoryError oomerror)
817 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
820 msg = pdbid + " " + MessageManager.getString("label.state_completed");
821 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
822 // stopProgressBar(msg, hdl);
825 * If PDB data were saved and are not invalid (empty alignment), return the
828 if (pdbseq != null && pdbseq.getHeight() > 0)
830 // just use the file name from the first sequence's first PDBEntry
831 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
832 .elementAt(0).getFile()).getAbsolutePath();
833 processingEntry.setFile(filePath);
839 * Convenience method to update the progress bar if there is one. Be sure to
840 * call stopProgressBar with the returned handle to remove the message.
845 public long startProgressBar(String msg)
847 // TODO would rather have startProgress/stopProgress as the
848 // IProgressIndicator interface
849 long tm = random.nextLong();
850 if (progressBar != null)
852 progressBar.setProgressBar(msg, tm);
858 * End the progress bar with the specified handle, leaving a message (if not
859 * null) on the status bar
864 public void stopProgressBar(String msg, long handle)
866 if (progressBar != null)
868 progressBar.setProgressBar(msg, handle);
873 public void pdbFile_actionPerformed(ActionEvent actionEvent)
875 JalviewFileChooser chooser = new JalviewFileChooser(
876 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
878 chooser.setFileView(new JalviewFileView());
879 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
880 chooser.setToolTipText(MessageManager.getString("action.save"));
882 int value = chooser.showSaveDialog(this);
884 if (value == JalviewFileChooser.APPROVE_OPTION)
886 BufferedReader in = null;
889 // TODO: cope with multiple PDB files in view
890 in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
891 File outFile = chooser.getSelectedFile();
893 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
895 while ((data = in.readLine()) != null)
897 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
903 } catch (Exception ex)
905 ex.printStackTrace();
913 } catch (IOException e)
923 public void viewMapping_actionPerformed(ActionEvent actionEvent)
925 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
928 cap.appendText(jmb.printMappings());
929 } catch (OutOfMemoryError e)
932 "composing sequence-structure alignments for display in text box.",
937 jalview.gui.Desktop.addInternalFrame(cap,
938 MessageManager.getString("label.pdb_sequence_mapping"), 550,
943 public void eps_actionPerformed(ActionEvent e)
947 .getString("error.eps_generation_not_implemented"));
951 public void png_actionPerformed(ActionEvent e)
955 .getString("error.png_generation_not_implemented"));
959 public void viewerColour_actionPerformed(ActionEvent actionEvent)
961 if (viewerColour.isSelected())
963 // disable automatic sequence colouring.
964 jmb.setColourBySequence(false);
969 public void seqColour_actionPerformed(ActionEvent actionEvent)
971 jmb.setColourBySequence(seqColour.isSelected());
972 if (_colourwith == null)
974 _colourwith = new Vector<AlignmentPanel>();
976 if (jmb.isColourBySequence())
978 if (!jmb.isLoadingFromArchive())
980 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
982 // Make the currently displayed alignment panel the associated view
983 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
986 // Set the colour using the current view for the associated alignframe
987 for (AlignmentPanel ap : _colourwith)
989 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
995 public void chainColour_actionPerformed(ActionEvent actionEvent)
997 chainColour.setSelected(true);
1002 public void chargeColour_actionPerformed(ActionEvent actionEvent)
1004 chargeColour.setSelected(true);
1005 jmb.colourByCharge();
1009 public void zappoColour_actionPerformed(ActionEvent actionEvent)
1011 zappoColour.setSelected(true);
1012 jmb.setJalviewColourScheme(new ZappoColourScheme());
1016 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1018 taylorColour.setSelected(true);
1019 jmb.setJalviewColourScheme(new TaylorColourScheme());
1023 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1025 hydroColour.setSelected(true);
1026 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1030 public void helixColour_actionPerformed(ActionEvent actionEvent)
1032 helixColour.setSelected(true);
1033 jmb.setJalviewColourScheme(new HelixColourScheme());
1037 public void strandColour_actionPerformed(ActionEvent actionEvent)
1039 strandColour.setSelected(true);
1040 jmb.setJalviewColourScheme(new StrandColourScheme());
1044 public void turnColour_actionPerformed(ActionEvent actionEvent)
1046 turnColour.setSelected(true);
1047 jmb.setJalviewColourScheme(new TurnColourScheme());
1051 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1053 buriedColour.setSelected(true);
1054 jmb.setJalviewColourScheme(new BuriedColourScheme());
1058 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1060 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1064 public void userColour_actionPerformed(ActionEvent actionEvent)
1066 userColour.setSelected(true);
1067 new UserDefinedColours(this, null);
1071 public void backGround_actionPerformed(ActionEvent actionEvent)
1073 java.awt.Color col = JColorChooser
1074 .showDialog(this, MessageManager
1075 .getString("label.select_backgroud_colour"), null);
1078 jmb.setBackgroundColour(col);
1083 public void showHelp_actionPerformed(ActionEvent actionEvent)
1087 jalview.util.BrowserLauncher
1088 .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
1089 } catch (Exception ex)
1094 public void updateTitleAndMenus()
1096 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1101 setChainMenuItems(jmb.getChainNames());
1103 this.setTitle(jmb.getViewerTitle("Chimera", true));
1104 // if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1106 viewerActionMenu.setVisible(true);
1108 if (!jmb.isLoadingFromArchive())
1110 seqColour_actionPerformed(null);
1118 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1122 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1124 alignStructs_withAllAlignPanels();
1127 private void alignStructs_withAllAlignPanels()
1129 if (getAlignmentPanel() == null)
1134 if (_alignwith.size() == 0)
1136 _alignwith.add(getAlignmentPanel());
1141 AlignmentI[] als = new Alignment[_alignwith.size()];
1142 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1143 int[] alm = new int[_alignwith.size()];
1146 for (AlignmentPanel ap : _alignwith)
1148 als[a] = ap.av.getAlignment();
1150 alc[a++] = ap.av.getColumnSelection();
1152 jmb.superposeStructures(als, alm, alc);
1153 } catch (Exception e)
1155 StringBuffer sp = new StringBuffer();
1156 for (AlignmentPanel ap : _alignwith)
1158 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1160 Cache.log.info("Couldn't align structures with the " + sp.toString()
1161 + "associated alignment panels.", e);
1166 public void setJalviewColourScheme(ColourSchemeI ucs)
1168 jmb.setJalviewColourScheme(ucs);
1175 * @return first alignment panel displaying given alignment, or the default
1178 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1180 for (AlignmentPanel ap : getAllAlignmentPanels())
1182 if (ap.av.getAlignment() == alignment)
1187 return getAlignmentPanel();
1191 public AAStructureBindingModel getBinding()
1197 * Ask Chimera to save its session to the designated file path, or to a
1198 * temporary file if the path is null. Returns the file path if successful,
1204 protected String saveSession(String filepath)
1206 String pathUsed = filepath;
1209 if (pathUsed == null)
1211 File tempFile = File.createTempFile("chimera", ".py");
1212 tempFile.deleteOnExit();
1213 pathUsed = tempFile.getPath();
1215 boolean result = jmb.saveSession(pathUsed);
1218 this.chimeraSessionFile = pathUsed;
1221 } catch (IOException e)
1228 * Returns a string representing the state of the Chimera session. This is
1229 * done by requesting Chimera to save its session to a temporary file, then
1230 * reading the file contents. Returns an empty string on any error.
1233 public String getStateInfo()
1235 String sessionFile = saveSession(null);
1236 if (sessionFile == null)
1240 InputStream is = null;
1243 File f = new File(sessionFile);
1244 byte[] bytes = new byte[(int) f.length()];
1245 is = new FileInputStream(sessionFile);
1247 return new String(bytes);
1248 } catch (IOException e)
1258 } catch (IOException e)
1267 protected void fitToWindow_actionPerformed()
1273 public ViewerType getViewerType()
1275 return ViewerType.CHIMERA;
1279 protected AAStructureBindingModel getBindingModel()