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);
146 viewMenu.add(highlightSelection);
148 final ItemListener handler;
149 JMenu alpanels = new ViewSelectionMenu(
150 MessageManager.getString("label.superpose_with"), this,
151 _alignwith, handler = new ItemListener()
154 public void itemStateChanged(ItemEvent e)
156 alignStructs.setEnabled(_alignwith.size() > 0);
157 alignStructs.setToolTipText(MessageManager
159 "label.align_structures_using_linked_alignment_views",
160 new Object[] { new Integer(_alignwith
161 .size()).toString() }));
164 handler.itemStateChanged(null);
165 viewerActionMenu.add(alpanels);
166 viewerActionMenu.addMenuListener(new MenuListener()
170 public void menuSelected(MenuEvent e)
172 handler.itemStateChanged(null);
176 public void menuDeselected(MenuEvent e)
178 // TODO Auto-generated method stub
182 public void menuCanceled(MenuEvent e)
184 // TODO Auto-generated method stub
190 * add a single PDB structure to a new or existing Chimera view
197 public ChimeraViewFrame(PDBEntry pdbentry, SequenceI[] seq,
198 String[] chains, final AlignmentPanel ap)
201 String pdbId = pdbentry.getId();
204 * If the PDB file is already loaded, the user may just choose to add to an
205 * existing viewer (or cancel)
207 if (addAlreadyLoadedFile(seq, chains, ap, pdbId))
213 * Check if there are other Chimera views involving this alignment and give
214 * user the option to add and align this molecule to one of them (or cancel)
216 if (addToExistingViewer(pdbentry, seq, chains, ap, pdbId))
222 * If the options above are declined or do not apply, show the structure in
225 openNewChimera(ap, new PDBEntry[] { pdbentry },
226 new SequenceI[][] { seq });
230 * Create a helper to manage progress bar display
232 protected void createProgressBar()
234 if (progressBar == null)
236 progressBar = new ProgressBar(statusPanel, statusBar);
241 * Answers true if this viewer already involves the given PDB ID
244 protected boolean hasPdbId(String pdbId)
246 return jmb.hasPdbId(pdbId);
249 private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
253 String[][] chains = extractChains(seqs);
254 jmb = new JalviewChimeraBindingModel(this,
255 ap.getStructureSelectionManager(), pdbentrys, seqs, chains,
257 addAlignmentPanel(ap);
258 useAlignmentPanelForColourbyseq(ap);
259 if (pdbentrys.length > 1)
261 alignAddedStructures = true;
262 useAlignmentPanelForSuperposition(ap);
264 jmb.setColourBySequence(true);
265 setSize(400, 400); // probably should be a configurable/dynamic default here
268 addingStructures = false;
269 worker = new Thread(this);
272 this.addInternalFrameListener(new InternalFrameAdapter()
275 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
284 * Retrieve chains for sequences by inspecting their PDB refs. The hope is
285 * that the first will be to the sequence's own chain. Really need a more
286 * managed way of doing this.
291 protected String[][] extractChains(SequenceI[][] seqs)
293 String[][] chains = new String[seqs.length][];
294 for (int i = 0; i < seqs.length; i++)
296 chains[i] = new String[seqs[i].length];
298 for (SequenceI seq : seqs[i])
301 if (seq.getDatasetSequence() != null)
303 Vector<PDBEntry> pdbrefs = seq.getDatasetSequence()
305 if (pdbrefs != null && pdbrefs.size() > 0)
307 chain = pdbrefs.get(0).getChainCode();
310 chains[i][seqno++] = chain;
317 * Create a new viewer from saved session state data including Chimera session
320 * @param chimeraSessionFile
324 * @param colourByChimera
325 * @param colourBySequence
328 public ChimeraViewFrame(String chimeraSessionFile,
329 AlignmentPanel alignPanel, PDBEntry[] pdbArray,
330 SequenceI[][] seqsArray, boolean colourByChimera,
331 boolean colourBySequence, String newViewId)
334 setViewId(newViewId);
335 this.chimeraSessionFile = chimeraSessionFile;
336 openNewChimera(alignPanel, pdbArray, seqsArray);
339 jmb.setColourBySequence(false);
340 seqColour.setSelected(false);
341 viewerColour.setSelected(true);
343 else if (colourBySequence)
345 jmb.setColourBySequence(true);
346 seqColour.setSelected(true);
347 viewerColour.setSelected(false);
352 * create a new viewer containing several structures superimposed using the
359 public ChimeraViewFrame(PDBEntry[] pe, SequenceI[][] seqs,
363 openNewChimera(ap, pe, seqs);
366 public ChimeraViewFrame(Map<PDBEntry, List<SequenceI>> toView,
367 AlignmentPanel alignPanel)
372 * Convert the map of sequences per pdb entry into the tied arrays expected
375 * TODO pass the Map down to openNewChimera and its callees instead
377 final Set<PDBEntry> pdbEntries = toView.keySet();
378 PDBEntry[] pdbs = pdbEntries.toArray(new PDBEntry[pdbEntries.size()]);
379 SequenceI[][] seqsForPdbs = new SequenceI[pdbEntries.size()][];
380 for (int i = 0; i < pdbs.length; i++)
382 final List<SequenceI> seqsForPdb = toView.get(pdbs[i]);
383 seqsForPdbs[i] = seqsForPdb.toArray(new SequenceI[seqsForPdb.size()]);
386 openNewChimera(alignPanel, pdbs, seqsForPdbs);
390 * Returns a list of any Chimera viewers in the desktop. The list is
391 * restricted to those linked to the given alignment panel if it is not null.
394 protected List<StructureViewerBase> getViewersFor(AlignmentPanel ap)
396 List<StructureViewerBase> result = new ArrayList<StructureViewerBase>();
397 JInternalFrame[] frames = Desktop.instance.getAllFrames();
399 for (JInternalFrame frame : frames)
401 if (frame instanceof ChimeraViewFrame)
403 if (ap == null || ((StructureViewerBase) frame).isLinkedWith(ap))
405 result.add((StructureViewerBase) frame);
413 * Launch Chimera. If we have a chimera session file name, send Chimera the
414 * command to open its saved session file.
418 jmb.setFinishedInit(false);
419 jalview.gui.Desktop.addInternalFrame(this,
420 jmb.getViewerTitle("Chimera", true), getBounds().width,
423 if (!jmb.launchChimera())
425 JOptionPane.showMessageDialog(Desktop.desktop,
426 MessageManager.getString("label.chimera_failed"),
427 MessageManager.getString("label.error_loading_file"),
428 JOptionPane.ERROR_MESSAGE);
433 if (this.chimeraSessionFile != null)
435 boolean opened = jmb.openSession(chimeraSessionFile);
439 .println("An error occurred opening Chimera session file "
440 + chimeraSessionFile);
443 jmb.setFinishedInit(true);
445 jmb.startChimeraListener();
449 * If the list is not empty, add menu items for 'All' and each individual
450 * chain to the "View | Show Chain" sub-menu. Multiple selections are allowed.
454 void setChainMenuItems(List<String> chainNames)
456 chainMenu.removeAll();
457 if (chainNames == null || chainNames.isEmpty())
461 JMenuItem menuItem = new JMenuItem(
462 MessageManager.getString("label.all"));
463 menuItem.addActionListener(new ActionListener()
466 public void actionPerformed(ActionEvent evt)
468 allChainsSelected = true;
469 for (int i = 0; i < chainMenu.getItemCount(); i++)
471 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
473 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
476 showSelectedChains();
477 allChainsSelected = false;
481 chainMenu.add(menuItem);
483 for (String chainName : chainNames)
485 menuItem = new JCheckBoxMenuItem(chainName, true);
486 menuItem.addItemListener(new ItemListener()
489 public void itemStateChanged(ItemEvent evt)
491 if (!allChainsSelected)
493 showSelectedChains();
498 chainMenu.add(menuItem);
503 * Show only the selected chain(s) in the viewer
505 void showSelectedChains()
507 List<String> toshow = new ArrayList<String>();
508 for (int i = 0; i < chainMenu.getItemCount(); i++)
510 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
512 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
513 if (item.isSelected())
515 toshow.add(item.getText());
519 jmb.showChains(toshow);
523 * Close down this instance of Jalview's Chimera viewer, giving the user the
524 * option to close the associated Chimera window (process). They may wish to
525 * keep it open until they have had an opportunity to save any work.
527 * @param closeChimera
528 * if true, close any linked Chimera process; if false, prompt first
531 public void closeViewer(boolean closeChimera)
533 if (jmb != null && jmb.isChimeraRunning())
537 String prompt = MessageManager.formatMessage(
538 "label.confirm_close_chimera",
539 new Object[] { jmb.getViewerTitle("Chimera", false) });
540 prompt = JvSwingUtils.wrapTooltip(true, prompt);
541 int confirm = JOptionPane.showConfirmDialog(this, prompt,
542 MessageManager.getString("label.close_viewer"),
543 JOptionPane.YES_NO_OPTION);
544 closeChimera = confirm == JOptionPane.YES_OPTION;
546 jmb.closeViewer(closeChimera);
548 setAlignmentPanel(null);
552 // TODO: check for memory leaks where instance isn't finalised because jmb
553 // holds a reference to the window
558 * Open any newly added PDB structures in Chimera, having first fetched data
559 * from PDB (if not already saved).
565 // todo - record which pdbids were successfully imported.
566 StringBuilder errormsgs = new StringBuilder(128);
567 StringBuilder files = new StringBuilder(128);
568 List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
569 List<Integer> filePDBpos = new ArrayList<Integer>();
570 PDBEntry thePdbEntry = null;
573 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
574 // TODO: replace with reference fetching/transfer code (validate PDBentry
576 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
579 thePdbEntry = jmb.getPdbEntry(pi);
580 if (thePdbEntry.getFile() == null)
583 * Retrieve PDB data, save to file, attach to PDBEntry
585 file = fetchPdbFile(thePdbEntry);
588 errormsgs.append("'" + thePdbEntry.getId() + "' ");
594 * Got file already - ignore if already loaded in Chimera.
596 file = new File(thePdbEntry.getFile()).getAbsoluteFile()
598 if (curfiles != null && curfiles.length > 0)
600 addingStructures = true; // already files loaded.
601 for (int c = 0; c < curfiles.length; c++)
603 if (curfiles[c].equals(file))
613 filePDB.add(thePdbEntry);
614 filePDBpos.add(Integer.valueOf(pi));
615 files.append(" \"" + Platform.escapeString(file) + "\"");
618 } catch (OutOfMemoryError oomerror)
620 new OOMWarning("Retrieving PDB files: " + thePdbEntry.getId(),
622 } catch (Exception ex)
624 ex.printStackTrace();
625 errormsgs.append("When retrieving pdbfiles for '"
626 + thePdbEntry.getId() + "'");
628 if (errormsgs.length() > 0)
631 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
632 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
633 new Object[] { errormsgs.toString() }),
634 MessageManager.getString("label.couldnt_load_file"),
635 JOptionPane.ERROR_MESSAGE);
638 if (files.length() > 0)
640 if (!addingStructures)
645 } catch (Exception ex)
647 Cache.log.error("Couldn't open Chimera viewer!", ex);
651 for (PDBEntry pe : filePDB)
654 if (pe.getFile() != null)
658 int pos = filePDBpos.get(num).intValue();
659 long startTime = startProgressBar("Chimera "
660 + MessageManager.getString("status.opening_file"));
662 jmb.addSequence(pos, jmb.getSequence()[pos]);
663 File fl = new File(pe.getFile());
664 String protocol = AppletFormatAdapter.URL;
669 protocol = AppletFormatAdapter.FILE;
671 } catch (Throwable e)
675 stopProgressBar("", startTime);
677 // Explicitly map to the filename used by Chimera ;
678 jmb.getSsm().setMapping(jmb.getSequence()[pos],
679 jmb.getChains()[pos], pe.getFile(), protocol);
680 } catch (OutOfMemoryError oomerror)
683 "When trying to open and map structures from Chimera!",
685 } catch (Exception ex)
687 Cache.log.error("Couldn't open " + pe.getFile()
688 + " in Chimera viewer!", ex);
691 Cache.log.debug("File locations are " + files);
695 jmb.setFinishedInit(true);
696 jmb.setLoadingFromArchive(false);
698 // refresh the sequence colours for the new structure(s)
699 for (AlignmentPanel ap : _colourwith)
701 jmb.updateColours(ap);
703 // do superposition if asked to
704 if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures)
706 new Thread(new Runnable()
711 alignStructs_withAllAlignPanels();
714 alignAddedStructures = false;
716 addingStructures = false;
723 * Fetch PDB data and save to a local file. Returns the full path to the file,
724 * or null if fetch fails.
726 * @param processingEntry
730 private String fetchPdbFile(PDBEntry processingEntry) throws Exception
732 String filePath = null;
733 Pdb pdbclient = new Pdb();
734 AlignmentI pdbseq = null;
735 String pdbid = processingEntry.getId();
736 long handle = System.currentTimeMillis()
737 + Thread.currentThread().hashCode();
740 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
742 String msg = MessageManager.formatMessage("status.fetching_pdb",
743 new Object[] { pdbid });
744 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
745 // long hdl = startProgressBar(MessageManager.formatMessage(
746 // "status.fetching_pdb", new Object[]
750 pdbseq = pdbclient.getSequenceRecords(pdbid);
751 } catch (OutOfMemoryError oomerror)
753 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
756 msg = pdbid + " " + MessageManager.getString("label.state_completed");
757 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
758 // stopProgressBar(msg, hdl);
761 * If PDB data were saved and are not invalid (empty alignment), return the
764 if (pdbseq != null && pdbseq.getHeight() > 0)
766 // just use the file name from the first sequence's first PDBEntry
767 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
768 .elementAt(0).getFile()).getAbsolutePath();
769 processingEntry.setFile(filePath);
775 * Convenience method to update the progress bar if there is one. Be sure to
776 * call stopProgressBar with the returned handle to remove the message.
781 public long startProgressBar(String msg)
783 // TODO would rather have startProgress/stopProgress as the
784 // IProgressIndicator interface
785 long tm = random.nextLong();
786 if (progressBar != null)
788 progressBar.setProgressBar(msg, tm);
794 * End the progress bar with the specified handle, leaving a message (if not
795 * null) on the status bar
800 public void stopProgressBar(String msg, long handle)
802 if (progressBar != null)
804 progressBar.setProgressBar(msg, handle);
809 public void pdbFile_actionPerformed(ActionEvent actionEvent)
811 JalviewFileChooser chooser = new JalviewFileChooser(
812 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
814 chooser.setFileView(new JalviewFileView());
815 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
816 chooser.setToolTipText(MessageManager.getString("action.save"));
818 int value = chooser.showSaveDialog(this);
820 if (value == JalviewFileChooser.APPROVE_OPTION)
822 BufferedReader in = null;
825 // TODO: cope with multiple PDB files in view
826 in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
827 File outFile = chooser.getSelectedFile();
829 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
831 while ((data = in.readLine()) != null)
833 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
839 } catch (Exception ex)
841 ex.printStackTrace();
849 } catch (IOException e)
859 public void viewMapping_actionPerformed(ActionEvent actionEvent)
861 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
864 cap.appendText(jmb.printMappings());
865 } catch (OutOfMemoryError e)
868 "composing sequence-structure alignments for display in text box.",
873 jalview.gui.Desktop.addInternalFrame(cap,
874 MessageManager.getString("label.pdb_sequence_mapping"), 550,
879 public void eps_actionPerformed(ActionEvent e)
883 .getString("error.eps_generation_not_implemented"));
887 public void png_actionPerformed(ActionEvent e)
891 .getString("error.png_generation_not_implemented"));
895 public void viewerColour_actionPerformed(ActionEvent actionEvent)
897 if (viewerColour.isSelected())
899 // disable automatic sequence colouring.
900 jmb.setColourBySequence(false);
905 public void seqColour_actionPerformed(ActionEvent actionEvent)
907 jmb.setColourBySequence(seqColour.isSelected());
908 if (_colourwith == null)
910 _colourwith = new Vector<AlignmentPanel>();
912 if (jmb.isColourBySequence())
914 if (!jmb.isLoadingFromArchive())
916 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
918 // Make the currently displayed alignment panel the associated view
919 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
922 // Set the colour using the current view for the associated alignframe
923 for (AlignmentPanel ap : _colourwith)
925 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
931 public void chainColour_actionPerformed(ActionEvent actionEvent)
933 chainColour.setSelected(true);
938 public void chargeColour_actionPerformed(ActionEvent actionEvent)
940 chargeColour.setSelected(true);
941 jmb.colourByCharge();
945 public void zappoColour_actionPerformed(ActionEvent actionEvent)
947 zappoColour.setSelected(true);
948 jmb.setJalviewColourScheme(new ZappoColourScheme());
952 public void taylorColour_actionPerformed(ActionEvent actionEvent)
954 taylorColour.setSelected(true);
955 jmb.setJalviewColourScheme(new TaylorColourScheme());
959 public void hydroColour_actionPerformed(ActionEvent actionEvent)
961 hydroColour.setSelected(true);
962 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
966 public void helixColour_actionPerformed(ActionEvent actionEvent)
968 helixColour.setSelected(true);
969 jmb.setJalviewColourScheme(new HelixColourScheme());
973 public void strandColour_actionPerformed(ActionEvent actionEvent)
975 strandColour.setSelected(true);
976 jmb.setJalviewColourScheme(new StrandColourScheme());
980 public void turnColour_actionPerformed(ActionEvent actionEvent)
982 turnColour.setSelected(true);
983 jmb.setJalviewColourScheme(new TurnColourScheme());
987 public void buriedColour_actionPerformed(ActionEvent actionEvent)
989 buriedColour.setSelected(true);
990 jmb.setJalviewColourScheme(new BuriedColourScheme());
994 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
996 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1000 public void userColour_actionPerformed(ActionEvent actionEvent)
1002 userColour.setSelected(true);
1003 new UserDefinedColours(this, null);
1007 public void backGround_actionPerformed(ActionEvent actionEvent)
1009 java.awt.Color col = JColorChooser
1010 .showDialog(this, MessageManager
1011 .getString("label.select_backgroud_colour"), null);
1014 jmb.setBackgroundColour(col);
1019 public void showHelp_actionPerformed(ActionEvent actionEvent)
1023 jalview.util.BrowserLauncher
1024 .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
1025 } catch (Exception ex)
1030 public void updateTitleAndMenus()
1032 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1037 setChainMenuItems(jmb.getChainNames());
1039 this.setTitle(jmb.getViewerTitle("Chimera", true));
1040 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1042 viewerActionMenu.setVisible(true);
1044 if (!jmb.isLoadingFromArchive())
1046 seqColour_actionPerformed(null);
1054 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1058 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1060 alignStructs_withAllAlignPanels();
1063 private void alignStructs_withAllAlignPanels()
1065 if (getAlignmentPanel() == null)
1070 if (_alignwith.size() == 0)
1072 _alignwith.add(getAlignmentPanel());
1077 AlignmentI[] als = new Alignment[_alignwith.size()];
1078 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1079 int[] alm = new int[_alignwith.size()];
1082 for (AlignmentPanel ap : _alignwith)
1084 als[a] = ap.av.getAlignment();
1086 alc[a++] = ap.av.getColumnSelection();
1088 jmb.superposeStructures(als, alm, alc);
1089 } catch (Exception e)
1091 StringBuffer sp = new StringBuffer();
1092 for (AlignmentPanel ap : _alignwith)
1094 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1096 Cache.log.info("Couldn't align structures with the " + sp.toString()
1097 + "associated alignment panels.", e);
1102 public void setJalviewColourScheme(ColourSchemeI ucs)
1104 jmb.setJalviewColourScheme(ucs);
1111 * @return first alignment panel displaying given alignment, or the default
1114 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1116 for (AlignmentPanel ap : getAllAlignmentPanels())
1118 if (ap.av.getAlignment() == alignment)
1123 return getAlignmentPanel();
1127 public AAStructureBindingModel getBinding()
1133 * Ask Chimera to save its session to the designated file path, or to a
1134 * temporary file if the path is null. Returns the file path if successful,
1140 protected String saveSession(String filepath)
1142 String pathUsed = filepath;
1145 if (pathUsed == null)
1147 File tempFile = File.createTempFile("chimera", ".py");
1148 tempFile.deleteOnExit();
1149 pathUsed = tempFile.getPath();
1151 boolean result = jmb.saveSession(pathUsed);
1154 this.chimeraSessionFile = pathUsed;
1157 } catch (IOException e)
1164 * Returns a string representing the state of the Chimera session. This is
1165 * done by requesting Chimera to save its session to a temporary file, then
1166 * reading the file contents. Returns an empty string on any error.
1169 public String getStateInfo()
1171 String sessionFile = saveSession(null);
1172 if (sessionFile == null)
1176 InputStream is = null;
1179 File f = new File(sessionFile);
1180 byte[] bytes = new byte[(int) f.length()];
1181 is = new FileInputStream(sessionFile);
1183 return new String(bytes);
1184 } catch (IOException e)
1194 } catch (IOException e)
1203 protected void fitToWindow_actionPerformed()
1209 protected void highlightSelection_actionPerformed()
1211 jmb.highlightSelection(getAlignmentPanel());
1215 public ViewerType getViewerType()
1217 return ViewerType.CHIMERA;
1221 protected AAStructureBindingModel getBindingModel()