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("Write Jalview features");
186 .setToolTipText("Create attributes in Chimera for features in Jalview");
187 writeFeatures.addActionListener(new ActionListener()
190 public void actionPerformed(ActionEvent e)
192 sendFeaturesToChimera();
195 viewerActionMenu.add(writeFeatures);
198 protected void sendFeaturesToChimera()
200 // TODO Auto-generated method stub
205 * add a single PDB structure to a new or existing Chimera view
212 public ChimeraViewFrame(PDBEntry pdbentry, SequenceI[] seq,
213 String[] chains, final AlignmentPanel ap)
216 String pdbId = pdbentry.getId();
219 * If the PDB file is already loaded, the user may just choose to add to an
220 * existing viewer (or cancel)
222 if (addAlreadyLoadedFile(seq, chains, ap, pdbId))
228 * Check if there are other Chimera views involving this alignment and give
229 * user the option to add and align this molecule to one of them (or cancel)
231 if (addToExistingViewer(pdbentry, seq, chains, ap, pdbId))
237 * If the options above are declined or do not apply, show the structure in
240 openNewChimera(ap, new PDBEntry[] { pdbentry },
241 new SequenceI[][] { seq });
245 * Create a helper to manage progress bar display
247 protected void createProgressBar()
249 if (progressBar == null)
251 progressBar = new ProgressBar(statusPanel, statusBar);
256 * Answers true if this viewer already involves the given PDB ID
259 protected boolean hasPdbId(String pdbId)
261 return jmb.hasPdbId(pdbId);
264 private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
268 // FIXME extractChains needs pdbentries to match IDs to PDBEntry(s) on seqs
269 String[][] chains = extractChains(seqs);
270 jmb = new JalviewChimeraBindingModel(this,
271 ap.getStructureSelectionManager(), pdbentrys, seqs, chains,
273 addAlignmentPanel(ap);
274 useAlignmentPanelForColourbyseq(ap);
275 if (pdbentrys.length > 1)
277 alignAddedStructures = true;
278 useAlignmentPanelForSuperposition(ap);
280 jmb.setColourBySequence(true);
281 setSize(400, 400); // probably should be a configurable/dynamic default here
284 addingStructures = false;
285 worker = new Thread(this);
288 this.addInternalFrameListener(new InternalFrameAdapter()
291 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
300 * Retrieve chains for sequences by inspecting their PDB refs. The hope is
301 * that the first will be to the sequence's own chain. Really need a more
302 * managed way of doing this.
307 protected String[][] extractChains(SequenceI[][] seqs)
309 String[][] chains = new String[seqs.length][];
310 for (int i = 0; i < seqs.length; i++)
312 chains[i] = new String[seqs[i].length];
314 for (SequenceI seq : seqs[i])
317 if (seq.getDatasetSequence() != null)
319 Vector<PDBEntry> pdbrefs = seq.getDatasetSequence()
321 if (pdbrefs != null && pdbrefs.size() > 0)
323 // FIXME: SequenceI.PDBEntry[0] chain mapping used for
324 // ChimeraViewFrame. Is this even used ???
326 chain = pdbrefs.get(0).getChainCode();
329 chains[i][seqno++] = chain;
336 * Create a new viewer from saved session state data including Chimera session
339 * @param chimeraSessionFile
343 * @param colourByChimera
344 * @param colourBySequence
347 public ChimeraViewFrame(String chimeraSessionFile,
348 AlignmentPanel alignPanel, PDBEntry[] pdbArray,
349 SequenceI[][] seqsArray, boolean colourByChimera,
350 boolean colourBySequence, String newViewId)
353 setViewId(newViewId);
354 this.chimeraSessionFile = chimeraSessionFile;
355 openNewChimera(alignPanel, pdbArray, seqsArray);
358 jmb.setColourBySequence(false);
359 seqColour.setSelected(false);
360 viewerColour.setSelected(true);
362 else if (colourBySequence)
364 jmb.setColourBySequence(true);
365 seqColour.setSelected(true);
366 viewerColour.setSelected(false);
371 * create a new viewer containing several structures superimposed using the
378 public ChimeraViewFrame(PDBEntry[] pe, SequenceI[][] seqs,
382 openNewChimera(ap, pe, seqs);
386 * Default constructor
388 public ChimeraViewFrame()
393 * closeViewer will decide whether or not to close this frame
394 * depending on whether user chooses to Cancel or not
396 setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
400 * Returns a list of any Chimera viewers in the desktop. The list is
401 * restricted to those linked to the given alignment panel if it is not null.
404 protected List<StructureViewerBase> getViewersFor(AlignmentPanel ap)
406 List<StructureViewerBase> result = new ArrayList<StructureViewerBase>();
407 JInternalFrame[] frames = Desktop.instance.getAllFrames();
409 for (JInternalFrame frame : frames)
411 if (frame instanceof ChimeraViewFrame)
413 if (ap == null || ((StructureViewerBase) frame).isLinkedWith(ap))
415 result.add((StructureViewerBase) frame);
423 * Launch Chimera. If we have a chimera session file name, send Chimera the
424 * command to open its saved session file.
428 jmb.setFinishedInit(false);
429 jalview.gui.Desktop.addInternalFrame(this,
430 jmb.getViewerTitle("Chimera", true), getBounds().width,
433 if (!jmb.launchChimera())
435 JOptionPane.showMessageDialog(Desktop.desktop,
436 MessageManager.getString("label.chimera_failed"),
437 MessageManager.getString("label.error_loading_file"),
438 JOptionPane.ERROR_MESSAGE);
443 if (this.chimeraSessionFile != null)
445 boolean opened = jmb.openSession(chimeraSessionFile);
449 .println("An error occurred opening Chimera session file "
450 + chimeraSessionFile);
453 jmb.setFinishedInit(true);
455 jmb.startChimeraListener();
459 * If the list is not empty, add menu items for 'All' and each individual
460 * chain to the "View | Show Chain" sub-menu. Multiple selections are allowed.
464 void setChainMenuItems(List<String> chainNames)
466 chainMenu.removeAll();
467 if (chainNames == null || chainNames.isEmpty())
471 JMenuItem menuItem = new JMenuItem(
472 MessageManager.getString("label.all"));
473 menuItem.addActionListener(new ActionListener()
476 public void actionPerformed(ActionEvent evt)
478 allChainsSelected = true;
479 for (int i = 0; i < chainMenu.getItemCount(); i++)
481 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
483 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
486 showSelectedChains();
487 allChainsSelected = false;
491 chainMenu.add(menuItem);
493 for (String chainName : chainNames)
495 menuItem = new JCheckBoxMenuItem(chainName, true);
496 menuItem.addItemListener(new ItemListener()
499 public void itemStateChanged(ItemEvent evt)
501 if (!allChainsSelected)
503 showSelectedChains();
508 chainMenu.add(menuItem);
513 * Show only the selected chain(s) in the viewer
515 void showSelectedChains()
517 List<String> toshow = new ArrayList<String>();
518 for (int i = 0; i < chainMenu.getItemCount(); i++)
520 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
522 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
523 if (item.isSelected())
525 toshow.add(item.getText());
529 jmb.showChains(toshow);
533 * Close down this instance of Jalview's Chimera viewer, giving the user the
534 * option to close the associated Chimera window (process). They may wish to
535 * keep it open until they have had an opportunity to save any work.
537 * @param closeChimera
538 * if true, close any linked Chimera process; if false, prompt first
541 public void closeViewer(boolean closeChimera)
543 if (jmb != null && jmb.isChimeraRunning())
547 String prompt = MessageManager.formatMessage(
548 "label.confirm_close_chimera",
549 new Object[] { jmb.getViewerTitle("Chimera", false) });
550 prompt = JvSwingUtils.wrapTooltip(true, prompt);
551 int confirm = JOptionPane.showConfirmDialog(this, prompt,
552 MessageManager.getString("label.close_viewer"),
553 JOptionPane.YES_NO_CANCEL_OPTION);
555 * abort closure if user hits escape or Cancel
557 if (confirm == JOptionPane.CANCEL_OPTION
558 || confirm == JOptionPane.CLOSED_OPTION)
562 closeChimera = confirm == JOptionPane.YES_OPTION;
564 jmb.closeViewer(closeChimera);
566 setAlignmentPanel(null);
570 // TODO: check for memory leaks where instance isn't finalised because jmb
571 // holds a reference to the window
577 * Open any newly added PDB structures in Chimera, having first fetched data
578 * from PDB (if not already saved).
584 // todo - record which pdbids were successfully imported.
585 StringBuilder errormsgs = new StringBuilder(128);
586 StringBuilder files = new StringBuilder(128);
587 List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
588 List<Integer> filePDBpos = new ArrayList<Integer>();
589 PDBEntry thePdbEntry = null;
592 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
593 // TODO: replace with reference fetching/transfer code (validate PDBentry
595 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
598 thePdbEntry = jmb.getPdbEntry(pi);
599 if (thePdbEntry.getFile() == null)
602 * Retrieve PDB data, save to file, attach to PDBEntry
604 file = fetchPdbFile(thePdbEntry);
607 errormsgs.append("'" + thePdbEntry.getId() + "' ");
613 * Got file already - ignore if already loaded in Chimera.
615 file = new File(thePdbEntry.getFile()).getAbsoluteFile()
617 if (curfiles != null && curfiles.length > 0)
619 addingStructures = true; // already files loaded.
620 for (int c = 0; c < curfiles.length; c++)
622 if (curfiles[c].equals(file))
632 filePDB.add(thePdbEntry);
633 filePDBpos.add(Integer.valueOf(pi));
634 files.append(" \"" + Platform.escapeString(file) + "\"");
637 } catch (OutOfMemoryError oomerror)
639 new OOMWarning("Retrieving PDB files: " + thePdbEntry.getId(),
641 } catch (Exception ex)
643 ex.printStackTrace();
644 errormsgs.append("When retrieving pdbfiles for '"
645 + thePdbEntry.getId() + "'");
647 if (errormsgs.length() > 0)
650 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
651 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
652 new Object[] { errormsgs.toString() }),
653 MessageManager.getString("label.couldnt_load_file"),
654 JOptionPane.ERROR_MESSAGE);
657 if (files.length() > 0)
659 if (!addingStructures)
664 } catch (Exception ex)
666 Cache.log.error("Couldn't open Chimera viewer!", ex);
670 for (PDBEntry pe : filePDB)
673 if (pe.getFile() != null)
677 int pos = filePDBpos.get(num).intValue();
678 long startTime = startProgressBar("Chimera "
679 + MessageManager.getString("status.opening_file_for")
682 jmb.addSequence(pos, jmb.getSequence()[pos]);
683 File fl = new File(pe.getFile());
684 String protocol = AppletFormatAdapter.URL;
689 protocol = AppletFormatAdapter.FILE;
691 } catch (Throwable e)
695 stopProgressBar("", startTime);
697 // Explicitly map to the filename used by Chimera ;
698 jmb.getSsm().setMapping(jmb.getSequence()[pos],
699 jmb.getChains()[pos], pe.getFile(), protocol);
700 } catch (OutOfMemoryError oomerror)
703 "When trying to open and map structures from Chimera!",
705 } catch (Exception ex)
707 Cache.log.error("Couldn't open " + pe.getFile()
708 + " in Chimera viewer!", ex);
711 Cache.log.debug("File locations are " + files);
715 jmb.setFinishedInit(true);
716 jmb.setLoadingFromArchive(false);
718 // refresh the sequence colours for the new structure(s)
719 for (AlignmentPanel ap : _colourwith)
721 jmb.updateColours(ap);
723 // do superposition if asked to
724 if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures)
726 new Thread(new Runnable()
731 alignStructs_withAllAlignPanels();
734 alignAddedStructures = false;
736 addingStructures = false;
743 * Fetch PDB data and save to a local file. Returns the full path to the file,
744 * or null if fetch fails.
746 * @param processingEntry
750 private String fetchPdbFile(PDBEntry processingEntry) throws Exception
752 // FIXME: this is duplicated code with Jmol frame ?
753 String filePath = null;
754 Pdb pdbclient = new Pdb();
755 AlignmentI pdbseq = null;
756 String pdbid = processingEntry.getId();
757 long handle = System.currentTimeMillis()
758 + Thread.currentThread().hashCode();
761 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
763 String msg = MessageManager.formatMessage("status.fetching_pdb",
764 new Object[] { pdbid });
765 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
766 // long hdl = startProgressBar(MessageManager.formatMessage(
767 // "status.fetching_pdb", new Object[]
771 pdbseq = pdbclient.getSequenceRecords(pdbid);
772 } catch (OutOfMemoryError oomerror)
774 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
777 msg = pdbid + " " + MessageManager.getString("label.state_completed");
778 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
779 // stopProgressBar(msg, hdl);
782 * If PDB data were saved and are not invalid (empty alignment), return the
785 if (pdbseq != null && pdbseq.getHeight() > 0)
787 // just use the file name from the first sequence's first PDBEntry
788 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
789 .elementAt(0).getFile()).getAbsolutePath();
790 processingEntry.setFile(filePath);
796 * Convenience method to update the progress bar if there is one. Be sure to
797 * call stopProgressBar with the returned handle to remove the message.
802 public long startProgressBar(String msg)
804 // TODO would rather have startProgress/stopProgress as the
805 // IProgressIndicator interface
806 long tm = random.nextLong();
807 if (progressBar != null)
809 progressBar.setProgressBar(msg, tm);
815 * End the progress bar with the specified handle, leaving a message (if not
816 * null) on the status bar
821 public void stopProgressBar(String msg, long handle)
823 if (progressBar != null)
825 progressBar.setProgressBar(msg, handle);
830 public void pdbFile_actionPerformed(ActionEvent actionEvent)
832 JalviewFileChooser chooser = new JalviewFileChooser(
833 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
835 chooser.setFileView(new JalviewFileView());
836 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
837 chooser.setToolTipText(MessageManager.getString("action.save"));
839 int value = chooser.showSaveDialog(this);
841 if (value == JalviewFileChooser.APPROVE_OPTION)
843 BufferedReader in = null;
846 // TODO: cope with multiple PDB files in view
847 in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
848 File outFile = chooser.getSelectedFile();
850 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
852 while ((data = in.readLine()) != null)
854 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
860 } catch (Exception ex)
862 ex.printStackTrace();
870 } catch (IOException e)
880 public void viewMapping_actionPerformed(ActionEvent actionEvent)
882 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
885 cap.appendText(jmb.printMappings());
886 } catch (OutOfMemoryError e)
889 "composing sequence-structure alignments for display in text box.",
894 jalview.gui.Desktop.addInternalFrame(cap,
895 MessageManager.getString("label.pdb_sequence_mapping"), 550,
900 public void eps_actionPerformed(ActionEvent e)
904 .getString("error.eps_generation_not_implemented"));
908 public void png_actionPerformed(ActionEvent e)
912 .getString("error.png_generation_not_implemented"));
916 public void viewerColour_actionPerformed(ActionEvent actionEvent)
918 if (viewerColour.isSelected())
920 // disable automatic sequence colouring.
921 jmb.setColourBySequence(false);
926 public void seqColour_actionPerformed(ActionEvent actionEvent)
928 jmb.setColourBySequence(seqColour.isSelected());
929 if (_colourwith == null)
931 _colourwith = new Vector<AlignmentPanel>();
933 if (jmb.isColourBySequence())
935 if (!jmb.isLoadingFromArchive())
937 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
939 // Make the currently displayed alignment panel the associated view
940 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
943 // Set the colour using the current view for the associated alignframe
944 for (AlignmentPanel ap : _colourwith)
946 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
952 public void chainColour_actionPerformed(ActionEvent actionEvent)
954 chainColour.setSelected(true);
959 public void chargeColour_actionPerformed(ActionEvent actionEvent)
961 chargeColour.setSelected(true);
962 jmb.colourByCharge();
966 public void zappoColour_actionPerformed(ActionEvent actionEvent)
968 zappoColour.setSelected(true);
969 jmb.setJalviewColourScheme(new ZappoColourScheme());
973 public void taylorColour_actionPerformed(ActionEvent actionEvent)
975 taylorColour.setSelected(true);
976 jmb.setJalviewColourScheme(new TaylorColourScheme());
980 public void hydroColour_actionPerformed(ActionEvent actionEvent)
982 hydroColour.setSelected(true);
983 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
987 public void helixColour_actionPerformed(ActionEvent actionEvent)
989 helixColour.setSelected(true);
990 jmb.setJalviewColourScheme(new HelixColourScheme());
994 public void strandColour_actionPerformed(ActionEvent actionEvent)
996 strandColour.setSelected(true);
997 jmb.setJalviewColourScheme(new StrandColourScheme());
1001 public void turnColour_actionPerformed(ActionEvent actionEvent)
1003 turnColour.setSelected(true);
1004 jmb.setJalviewColourScheme(new TurnColourScheme());
1008 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1010 buriedColour.setSelected(true);
1011 jmb.setJalviewColourScheme(new BuriedColourScheme());
1015 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1017 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1021 public void userColour_actionPerformed(ActionEvent actionEvent)
1023 userColour.setSelected(true);
1024 new UserDefinedColours(this, null);
1028 public void backGround_actionPerformed(ActionEvent actionEvent)
1030 java.awt.Color col = JColorChooser
1031 .showDialog(this, MessageManager
1032 .getString("label.select_backgroud_colour"), null);
1035 jmb.setBackgroundColour(col);
1040 public void showHelp_actionPerformed(ActionEvent actionEvent)
1044 jalview.util.BrowserLauncher
1045 .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
1046 } catch (Exception ex)
1051 public void updateTitleAndMenus()
1053 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1058 setChainMenuItems(jmb.getChainNames());
1060 this.setTitle(jmb.getViewerTitle("Chimera", true));
1061 // if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1063 viewerActionMenu.setVisible(true);
1065 if (!jmb.isLoadingFromArchive())
1067 seqColour_actionPerformed(null);
1075 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1079 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1081 alignStructs_withAllAlignPanels();
1084 private void alignStructs_withAllAlignPanels()
1086 if (getAlignmentPanel() == null)
1091 if (_alignwith.size() == 0)
1093 _alignwith.add(getAlignmentPanel());
1098 AlignmentI[] als = new Alignment[_alignwith.size()];
1099 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1100 int[] alm = new int[_alignwith.size()];
1103 for (AlignmentPanel ap : _alignwith)
1105 als[a] = ap.av.getAlignment();
1107 alc[a++] = ap.av.getColumnSelection();
1109 jmb.superposeStructures(als, alm, alc);
1110 } catch (Exception e)
1112 StringBuffer sp = new StringBuffer();
1113 for (AlignmentPanel ap : _alignwith)
1115 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1117 Cache.log.info("Couldn't align structures with the " + sp.toString()
1118 + "associated alignment panels.", e);
1123 public void setJalviewColourScheme(ColourSchemeI ucs)
1125 jmb.setJalviewColourScheme(ucs);
1132 * @return first alignment panel displaying given alignment, or the default
1135 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1137 for (AlignmentPanel ap : getAllAlignmentPanels())
1139 if (ap.av.getAlignment() == alignment)
1144 return getAlignmentPanel();
1148 public AAStructureBindingModel getBinding()
1154 * Ask Chimera to save its session to the designated file path, or to a
1155 * temporary file if the path is null. Returns the file path if successful,
1161 protected String saveSession(String filepath)
1163 String pathUsed = filepath;
1166 if (pathUsed == null)
1168 File tempFile = File.createTempFile("chimera", ".py");
1169 tempFile.deleteOnExit();
1170 pathUsed = tempFile.getPath();
1172 boolean result = jmb.saveSession(pathUsed);
1175 this.chimeraSessionFile = pathUsed;
1178 } catch (IOException e)
1185 * Returns a string representing the state of the Chimera session. This is
1186 * done by requesting Chimera to save its session to a temporary file, then
1187 * reading the file contents. Returns an empty string on any error.
1190 public String getStateInfo()
1192 String sessionFile = saveSession(null);
1193 if (sessionFile == null)
1197 InputStream is = null;
1200 File f = new File(sessionFile);
1201 byte[] bytes = new byte[(int) f.length()];
1202 is = new FileInputStream(sessionFile);
1204 return new String(bytes);
1205 } catch (IOException e)
1215 } catch (IOException e)
1224 protected void fitToWindow_actionPerformed()
1230 public ViewerType getViewerType()
1232 return ViewerType.CHIMERA;
1236 protected AAStructureBindingModel getBindingModel()