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;
63 import java.util.Random;
65 import java.util.Vector;
67 import javax.swing.JCheckBoxMenuItem;
68 import javax.swing.JColorChooser;
69 import javax.swing.JInternalFrame;
70 import javax.swing.JMenu;
71 import javax.swing.JMenuItem;
72 import javax.swing.JOptionPane;
73 import javax.swing.event.InternalFrameAdapter;
74 import javax.swing.event.InternalFrameEvent;
75 import javax.swing.event.MenuEvent;
76 import javax.swing.event.MenuListener;
79 * GUI elements for handling an external chimera display
84 public class ChimeraViewFrame extends StructureViewerBase
86 private JalviewChimeraBinding jmb;
88 private boolean allChainsSelected = false;
90 private IProgressIndicator progressBar = null;
93 * Path to Chimera session file. This is set when an open Jalview/Chimera
94 * session is saved, or on restore from a Jalview project (if it holds the
95 * filename of any saved Chimera sessions).
97 private String chimeraSessionFile = null;
99 private Random random = new Random();
102 * Initialise menu options.
104 private void initMenus()
106 viewerActionMenu.setText(MessageManager.getString("label.chimera"));
107 viewerColour.setText(MessageManager
108 .getString("label.colour_with_chimera"));
109 viewerColour.setToolTipText(MessageManager
110 .getString("label.let_chimera_manage_structure_colours"));
111 helpItem.setText(MessageManager.getString("label.chimera_help"));
112 seqColour.setSelected(jmb.isColourBySequence());
113 viewerColour.setSelected(!jmb.isColourBySequence());
114 if (_colourwith == null)
116 _colourwith = new Vector<AlignmentPanel>();
118 if (_alignwith == null)
120 _alignwith = new Vector<AlignmentPanel>();
123 // save As not yet implemented
124 savemenu.setVisible(false);
126 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
127 MessageManager.getString("label.colour_by"), this, _colourwith,
131 public void itemStateChanged(ItemEvent e)
133 if (!seqColour.isSelected())
139 // update the Chimera display now.
140 seqColour_actionPerformed(null);
144 viewMenu.add(seqColourBy);
145 viewMenu.add(fitToWindow);
147 final ItemListener handler;
148 JMenu alpanels = new ViewSelectionMenu(
149 MessageManager.getString("label.superpose_with"), this,
150 _alignwith, handler = new ItemListener()
153 public void itemStateChanged(ItemEvent e)
155 alignStructs.setEnabled(_alignwith.size() > 0);
156 alignStructs.setToolTipText(MessageManager
158 "label.align_structures_using_linked_alignment_views",
159 new Object[] { new Integer(_alignwith
160 .size()).toString() }));
163 handler.itemStateChanged(null);
164 viewerActionMenu.add(alpanels);
165 viewerActionMenu.addMenuListener(new MenuListener()
169 public void menuSelected(MenuEvent e)
171 handler.itemStateChanged(null);
175 public void menuDeselected(MenuEvent e)
177 // TODO Auto-generated method stub
181 public void menuCanceled(MenuEvent e)
183 // TODO Auto-generated method stub
189 * add a single PDB structure to a new or existing Chimera view
196 public ChimeraViewFrame(PDBEntry pdbentry, SequenceI[] seq,
197 String[] chains, final AlignmentPanel ap)
200 String pdbId = pdbentry.getId();
203 * If the PDB file is already loaded, the user may just choose to add to an
204 * existing viewer (or cancel)
206 if (addAlreadyLoadedFile(seq, chains, ap, pdbId))
212 * Check if there are other Chimera views involving this alignment and give
213 * user the option to add and align this molecule to one of them (or cancel)
215 if (addToExistingViewer(pdbentry, seq, chains, ap, pdbId))
221 * If the options above are declined or do not apply, show the structure in
224 openNewChimera(ap, new PDBEntry[] { pdbentry },
225 new SequenceI[][] { seq });
229 * Create a helper to manage progress bar display
231 protected void createProgressBar()
233 if (progressBar == null)
235 progressBar = new ProgressBar(statusPanel, statusBar);
240 * Answers true if this viewer already involves the given PDB ID
243 protected boolean hasPdbId(String pdbId)
245 return jmb.hasPdbId(pdbId);
248 private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
252 String[][] chains = extractChains(seqs);
253 jmb = new JalviewChimeraBindingModel(this,
254 ap.getStructureSelectionManager(), pdbentrys, seqs, chains,
256 addAlignmentPanel(ap);
257 useAlignmentPanelForColourbyseq(ap);
258 if (pdbentrys.length > 1)
260 alignAddedStructures = true;
261 useAlignmentPanelForSuperposition(ap);
263 jmb.setColourBySequence(true);
264 setSize(400, 400); // probably should be a configurable/dynamic default here
267 addingStructures = false;
268 worker = new Thread(this);
271 this.addInternalFrameListener(new InternalFrameAdapter()
273 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
282 * Retrieve chains for sequences by inspecting their PDB refs. The hope is
283 * that the first will be to the sequence's own chain. Really need a more
284 * managed way of doing this.
289 protected String[][] extractChains(SequenceI[][] seqs)
291 String[][] chains = new String[seqs.length][];
292 for (int i = 0; i < seqs.length; i++)
294 chains[i] = new String[seqs[i].length];
296 for (SequenceI seq : seqs[i])
299 if (seq.getDatasetSequence() != null)
301 Vector<PDBEntry> pdbrefs = seq.getDatasetSequence()
303 if (pdbrefs != null && pdbrefs.size() > 0)
305 chain = pdbrefs.get(0).getChainCode();
308 chains[i][seqno++] = chain;
315 * Create a new viewer from saved session state data including Chimera session
318 * @param chimeraSessionFile
322 * @param colourByChimera
323 * @param colourBySequence
326 public ChimeraViewFrame(String chimeraSessionFile,
327 AlignmentPanel alignPanel, PDBEntry[] pdbArray,
328 SequenceI[][] seqsArray, boolean colourByChimera,
329 boolean colourBySequence, String newViewId)
332 setViewId(newViewId);
333 this.chimeraSessionFile = chimeraSessionFile;
334 openNewChimera(alignPanel, pdbArray, seqsArray);
337 jmb.setColourBySequence(false);
338 seqColour.setSelected(false);
339 viewerColour.setSelected(true);
341 else if (colourBySequence)
343 jmb.setColourBySequence(true);
344 seqColour.setSelected(true);
345 viewerColour.setSelected(false);
350 * create a new viewer containing several structures superimposed using the
357 public ChimeraViewFrame(PDBEntry[] pe, SequenceI[][] seqs,
361 openNewChimera(ap, pe, seqs);
364 public ChimeraViewFrame(Map<PDBEntry, List<SequenceI>> toView,
365 AlignmentPanel alignPanel)
370 * Convert the map of sequences per pdb entry into the tied arrays expected
373 * TODO pass the Map down to openNewChimera and its callees instead
375 final Set<PDBEntry> pdbEntries = toView.keySet();
376 PDBEntry[] pdbs = pdbEntries.toArray(new PDBEntry[pdbEntries.size()]);
377 SequenceI[][] seqsForPdbs = new SequenceI[pdbEntries.size()][];
378 for (int i = 0; i < pdbs.length; i++)
380 final List<SequenceI> seqsForPdb = toView.get(pdbs[i]);
381 seqsForPdbs[i] = seqsForPdb.toArray(new SequenceI[seqsForPdb.size()]);
384 openNewChimera(alignPanel, pdbs, seqsForPdbs);
388 * Returns a list of any Chimera viewers in the desktop. The list is
389 * restricted to those linked to the given alignment panel if it is not null.
392 protected List<StructureViewerBase> getViewersFor(AlignmentPanel ap)
394 List<StructureViewerBase> result = new ArrayList<StructureViewerBase>();
395 JInternalFrame[] frames = Desktop.instance.getAllFrames();
397 for (JInternalFrame frame : frames)
399 if (frame instanceof ChimeraViewFrame)
401 if (ap == null || ((StructureViewerBase) frame).isLinkedWith(ap))
403 result.add((StructureViewerBase) frame);
411 * Launch Chimera. If we have a chimera session file name, send Chimera the
412 * command to open its saved session file.
416 jmb.setFinishedInit(false);
417 jalview.gui.Desktop.addInternalFrame(this,
418 jmb.getViewerTitle("Chimera", true), getBounds().width,
421 if (!jmb.launchChimera())
423 JOptionPane.showMessageDialog(Desktop.desktop,
424 MessageManager.getString("label.chimera_failed"),
425 MessageManager.getString("label.error_loading_file"),
426 JOptionPane.ERROR_MESSAGE);
431 if (this.chimeraSessionFile != null)
433 boolean opened = jmb.openSession(chimeraSessionFile);
437 .println("An error occurred opening Chimera session file "
438 + chimeraSessionFile);
441 jmb.setFinishedInit(true);
443 jmb.startChimeraListener();
447 * If the list is not empty, add menu items for 'All' and each individual
448 * chain to the "View | Show Chain" sub-menu. Multiple selections are allowed.
452 void setChainMenuItems(List<String> chainNames)
454 chainMenu.removeAll();
455 if (chainNames == null || chainNames.isEmpty())
459 JMenuItem menuItem = new JMenuItem(
460 MessageManager.getString("label.all"));
461 menuItem.addActionListener(new ActionListener()
463 public void actionPerformed(ActionEvent evt)
465 allChainsSelected = true;
466 for (int i = 0; i < chainMenu.getItemCount(); i++)
468 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
470 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
473 showSelectedChains();
474 allChainsSelected = false;
478 chainMenu.add(menuItem);
480 for (String chainName : chainNames)
482 menuItem = new JCheckBoxMenuItem(chainName, true);
483 menuItem.addItemListener(new ItemListener()
485 public void itemStateChanged(ItemEvent evt)
487 if (!allChainsSelected)
489 showSelectedChains();
494 chainMenu.add(menuItem);
499 * Show only the selected chain(s) in the viewer
501 void showSelectedChains()
503 List<String> toshow = new ArrayList<String>();
504 for (int i = 0; i < chainMenu.getItemCount(); i++)
506 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
508 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
509 if (item.isSelected())
511 toshow.add(item.getText());
515 jmb.showChains(toshow);
519 * Close down this instance of Jalview's Chimera viewer, giving the user the
520 * option to close the associated Chimera window (process). They may wish to
521 * keep it open until they have had an opportunity to save any work.
523 * @param closeChimera
524 * if true, close any linked Chimera process; if false, prompt first
526 public void closeViewer(boolean closeChimera)
528 if (jmb != null && jmb.isChimeraRunning())
532 String prompt = MessageManager.formatMessage(
533 "label.confirm_close_chimera",
534 new Object[] { jmb.getViewerTitle("Chimera", false) });
535 prompt = JvSwingUtils.wrapTooltip(true, prompt);
536 int confirm = JOptionPane.showConfirmDialog(this, prompt,
537 MessageManager.getString("label.close_viewer"),
538 JOptionPane.YES_NO_OPTION);
539 closeChimera = confirm == JOptionPane.YES_OPTION;
541 jmb.closeViewer(closeChimera);
543 setAlignmentPanel(null);
547 // TODO: check for memory leaks where instance isn't finalised because jmb
548 // holds a reference to the window
553 * Open any newly added PDB structures in Chimera, having first fetched data
554 * from PDB (if not already saved).
559 // todo - record which pdbids were successfully imported.
560 StringBuilder errormsgs = new StringBuilder(128);
561 StringBuilder files = new StringBuilder(128);
562 List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
563 List<Integer> filePDBpos = new ArrayList<Integer>();
564 PDBEntry thePdbEntry = null;
567 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
568 // TODO: replace with reference fetching/transfer code (validate PDBentry
570 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
573 thePdbEntry = jmb.getPdbEntry(pi);
574 if (thePdbEntry.getFile() == null)
577 * Retrieve PDB data, save to file, attach to PDBEntry
579 file = fetchPdbFile(thePdbEntry);
582 errormsgs.append("'" + thePdbEntry.getId() + "' ");
588 * Got file already - ignore if already loaded in Chimera.
590 file = new File(thePdbEntry.getFile()).getAbsoluteFile()
592 if (curfiles != null && curfiles.length > 0)
594 addingStructures = true; // already files loaded.
595 for (int c = 0; c < curfiles.length; c++)
597 if (curfiles[c].equals(file))
607 filePDB.add(thePdbEntry);
608 filePDBpos.add(Integer.valueOf(pi));
609 files.append(" \"" + Platform.escapeString(file) + "\"");
612 } catch (OutOfMemoryError oomerror)
614 new OOMWarning("Retrieving PDB files: " + thePdbEntry.getId(),
616 } catch (Exception ex)
618 ex.printStackTrace();
619 errormsgs.append("When retrieving pdbfiles for '"
620 + thePdbEntry.getId() + "'");
622 if (errormsgs.length() > 0)
625 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
626 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
627 new Object[] { errormsgs.toString() }),
628 MessageManager.getString("label.couldnt_load_file"),
629 JOptionPane.ERROR_MESSAGE);
632 if (files.length() > 0)
634 if (!addingStructures)
639 } catch (Exception ex)
641 Cache.log.error("Couldn't open Chimera viewer!", ex);
645 for (PDBEntry pe : filePDB)
648 if (pe.getFile() != null)
652 int pos = filePDBpos.get(num).intValue();
653 long startTime = startProgressBar("Chimera "
654 + MessageManager.getString("status.opening_file"));
656 jmb.addSequence(pos, jmb.getSequence()[pos]);
657 File fl = new File(pe.getFile());
658 String protocol = AppletFormatAdapter.URL;
663 protocol = AppletFormatAdapter.FILE;
665 } catch (Throwable e)
669 stopProgressBar("", startTime);
671 // Explicitly map to the filename used by Chimera ;
672 jmb.getSsm().setMapping(jmb.getSequence()[pos],
673 jmb.getChains()[pos], pe.getFile(), protocol);
674 } catch (OutOfMemoryError oomerror)
677 "When trying to open and map structures from Chimera!",
679 } catch (Exception ex)
681 Cache.log.error("Couldn't open " + pe.getFile()
682 + " in Chimera viewer!", ex);
685 Cache.log.debug("File locations are " + files);
689 jmb.setFinishedInit(true);
690 jmb.setLoadingFromArchive(false);
692 // refresh the sequence colours for the new structure(s)
693 for (AlignmentPanel ap : _colourwith)
695 jmb.updateColours(ap);
697 // do superposition if asked to
698 if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures)
700 new Thread(new Runnable()
704 alignStructs_withAllAlignPanels();
707 alignAddedStructures = false;
709 addingStructures = false;
716 * Fetch PDB data and save to a local file. Returns the full path to the file,
717 * or null if fetch fails.
719 * @param processingEntry
723 private String fetchPdbFile(PDBEntry processingEntry) throws Exception
725 String filePath = null;
726 Pdb pdbclient = new Pdb();
727 AlignmentI pdbseq = null;
728 String pdbid = processingEntry.getId();
729 long handle = System.currentTimeMillis()
730 + Thread.currentThread().hashCode();
733 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
735 String msg = MessageManager.formatMessage("status.fetching_pdb",
736 new Object[] { pdbid });
737 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
738 // long hdl = startProgressBar(MessageManager.formatMessage(
739 // "status.fetching_pdb", new Object[]
743 pdbseq = pdbclient.getSequenceRecords(pdbid);
744 } catch (OutOfMemoryError oomerror)
746 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
749 msg = pdbid + " " + MessageManager.getString("label.state_completed");
750 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
751 // stopProgressBar(msg, hdl);
754 * If PDB data were saved and are not invalid (empty alignment), return the
757 if (pdbseq != null && pdbseq.getHeight() > 0)
759 // just use the file name from the first sequence's first PDBEntry
760 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
761 .elementAt(0).getFile()).getAbsolutePath();
762 processingEntry.setFile(filePath);
768 * Convenience method to update the progress bar if there is one. Be sure to
769 * call stopProgressBar with the returned handle to remove the message.
774 public long startProgressBar(String msg)
776 // TODO would rather have startProgress/stopProgress as the
777 // IProgressIndicator interface
778 long tm = random.nextLong();
779 if (progressBar != null)
781 progressBar.setProgressBar(msg, tm);
787 * End the progress bar with the specified handle, leaving a message (if not
788 * null) on the status bar
793 public void stopProgressBar(String msg, long handle)
795 if (progressBar != null)
797 progressBar.setProgressBar(msg, handle);
802 public void pdbFile_actionPerformed(ActionEvent actionEvent)
804 JalviewFileChooser chooser = new JalviewFileChooser(
805 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
807 chooser.setFileView(new JalviewFileView());
808 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
809 chooser.setToolTipText(MessageManager.getString("action.save"));
811 int value = chooser.showSaveDialog(this);
813 if (value == JalviewFileChooser.APPROVE_OPTION)
815 BufferedReader in = null;
818 // TODO: cope with multiple PDB files in view
819 in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
820 File outFile = chooser.getSelectedFile();
822 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
824 while ((data = in.readLine()) != null)
826 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
832 } catch (Exception ex)
834 ex.printStackTrace();
842 } catch (IOException e)
852 public void viewMapping_actionPerformed(ActionEvent actionEvent)
854 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
857 cap.appendText(jmb.printMappings());
858 } catch (OutOfMemoryError e)
861 "composing sequence-structure alignments for display in text box.",
866 jalview.gui.Desktop.addInternalFrame(cap,
867 MessageManager.getString("label.pdb_sequence_mapping"), 550,
872 public void eps_actionPerformed(ActionEvent e)
876 .getString("error.eps_generation_not_implemented"));
880 public void png_actionPerformed(ActionEvent e)
884 .getString("error.png_generation_not_implemented"));
888 public void viewerColour_actionPerformed(ActionEvent actionEvent)
890 if (viewerColour.isSelected())
892 // disable automatic sequence colouring.
893 jmb.setColourBySequence(false);
898 public void seqColour_actionPerformed(ActionEvent actionEvent)
900 jmb.setColourBySequence(seqColour.isSelected());
901 if (_colourwith == null)
903 _colourwith = new Vector<AlignmentPanel>();
905 if (jmb.isColourBySequence())
907 if (!jmb.isLoadingFromArchive())
909 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
911 // Make the currently displayed alignment panel the associated view
912 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
915 // Set the colour using the current view for the associated alignframe
916 for (AlignmentPanel ap : _colourwith)
918 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
924 public void chainColour_actionPerformed(ActionEvent actionEvent)
926 chainColour.setSelected(true);
931 public void chargeColour_actionPerformed(ActionEvent actionEvent)
933 chargeColour.setSelected(true);
934 jmb.colourByCharge();
938 public void zappoColour_actionPerformed(ActionEvent actionEvent)
940 zappoColour.setSelected(true);
941 jmb.setJalviewColourScheme(new ZappoColourScheme());
945 public void taylorColour_actionPerformed(ActionEvent actionEvent)
947 taylorColour.setSelected(true);
948 jmb.setJalviewColourScheme(new TaylorColourScheme());
952 public void hydroColour_actionPerformed(ActionEvent actionEvent)
954 hydroColour.setSelected(true);
955 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
959 public void helixColour_actionPerformed(ActionEvent actionEvent)
961 helixColour.setSelected(true);
962 jmb.setJalviewColourScheme(new HelixColourScheme());
966 public void strandColour_actionPerformed(ActionEvent actionEvent)
968 strandColour.setSelected(true);
969 jmb.setJalviewColourScheme(new StrandColourScheme());
973 public void turnColour_actionPerformed(ActionEvent actionEvent)
975 turnColour.setSelected(true);
976 jmb.setJalviewColourScheme(new TurnColourScheme());
980 public void buriedColour_actionPerformed(ActionEvent actionEvent)
982 buriedColour.setSelected(true);
983 jmb.setJalviewColourScheme(new BuriedColourScheme());
987 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
989 setJalviewColourScheme(new PurinePyrimidineColourScheme());
993 public void userColour_actionPerformed(ActionEvent actionEvent)
995 userColour.setSelected(true);
996 new UserDefinedColours(this, null);
1000 public void backGround_actionPerformed(ActionEvent actionEvent)
1002 java.awt.Color col = JColorChooser
1003 .showDialog(this, MessageManager
1004 .getString("label.select_backgroud_colour"), null);
1007 jmb.setBackgroundColour(col);
1012 public void showHelp_actionPerformed(ActionEvent actionEvent)
1016 jalview.util.BrowserLauncher
1017 .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
1018 } catch (Exception ex)
1023 public void updateTitleAndMenus()
1025 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1030 setChainMenuItems(jmb.getChainNames());
1032 this.setTitle(jmb.getViewerTitle("Chimera", true));
1033 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1035 viewerActionMenu.setVisible(true);
1037 if (!jmb.isLoadingFromArchive())
1039 seqColour_actionPerformed(null);
1047 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1051 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1053 alignStructs_withAllAlignPanels();
1056 private void alignStructs_withAllAlignPanels()
1058 if (getAlignmentPanel() == null)
1063 if (_alignwith.size() == 0)
1065 _alignwith.add(getAlignmentPanel());
1070 AlignmentI[] als = new Alignment[_alignwith.size()];
1071 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1072 int[] alm = new int[_alignwith.size()];
1075 for (AlignmentPanel ap : _alignwith)
1077 als[a] = ap.av.getAlignment();
1079 alc[a++] = ap.av.getColumnSelection();
1081 jmb.superposeStructures(als, alm, alc);
1082 } catch (Exception e)
1084 StringBuffer sp = new StringBuffer();
1085 for (AlignmentPanel ap : _alignwith)
1087 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1089 Cache.log.info("Couldn't align structures with the " + sp.toString()
1090 + "associated alignment panels.", e);
1094 public void setJalviewColourScheme(ColourSchemeI ucs)
1096 jmb.setJalviewColourScheme(ucs);
1103 * @return first alignment panel displaying given alignment, or the default
1106 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1108 for (AlignmentPanel ap : getAllAlignmentPanels())
1110 if (ap.av.getAlignment() == alignment)
1115 return getAlignmentPanel();
1119 public AAStructureBindingModel getBinding()
1125 * Ask Chimera to save its session to the designated file path, or to a
1126 * temporary file if the path is null. Returns the file path if successful,
1132 protected String saveSession(String filepath)
1134 String pathUsed = filepath;
1137 if (pathUsed == null)
1139 File tempFile = File.createTempFile("chimera", ".py");
1140 tempFile.deleteOnExit();
1141 pathUsed = tempFile.getPath();
1143 boolean result = jmb.saveSession(pathUsed);
1146 this.chimeraSessionFile = pathUsed;
1149 } catch (IOException e)
1156 * Returns a string representing the state of the Chimera session. This is
1157 * done by requesting Chimera to save its session to a temporary file, then
1158 * reading the file contents. Returns an empty string on any error.
1161 public String getStateInfo()
1163 String sessionFile = saveSession(null);
1164 if (sessionFile == null)
1168 InputStream is = null;
1171 File f = new File(sessionFile);
1172 byte[] bytes = new byte[(int) f.length()];
1173 is = new FileInputStream(sessionFile);
1175 return new String(bytes);
1176 } catch (IOException e)
1186 } catch (IOException e)
1195 protected void fitToWindow_actionPerformed()
1201 public ViewerType getViewerType()
1203 return ViewerType.CHIMERA;
1207 protected AAStructureBindingModel getBindingModel()