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.DataSourceType;
32 import jalview.io.JalviewFileChooser;
33 import jalview.io.JalviewFileView;
34 import jalview.io.StructureFile;
35 import jalview.schemes.BuriedColourScheme;
36 import jalview.schemes.ColourSchemeI;
37 import jalview.schemes.HelixColourScheme;
38 import jalview.schemes.HydrophobicColourScheme;
39 import jalview.schemes.PurinePyrimidineColourScheme;
40 import jalview.schemes.StrandColourScheme;
41 import jalview.schemes.TaylorColourScheme;
42 import jalview.schemes.TurnColourScheme;
43 import jalview.schemes.ZappoColourScheme;
44 import jalview.structures.models.AAStructureBindingModel;
45 import jalview.util.MessageManager;
46 import jalview.util.Platform;
47 import jalview.ws.dbsources.Pdb;
49 import java.awt.event.ActionEvent;
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.event.InternalFrameAdapter;
70 import javax.swing.event.InternalFrameEvent;
71 import javax.swing.event.MenuEvent;
72 import javax.swing.event.MenuListener;
75 * GUI elements for handling an external chimera display
80 public class ChimeraViewFrame extends StructureViewerBase
82 private JalviewChimeraBinding jmb;
84 private boolean allChainsSelected = false;
86 private IProgressIndicator progressBar = null;
89 * Path to Chimera session file. This is set when an open Jalview/Chimera
90 * session is saved, or on restore from a Jalview project (if it holds the
91 * filename of any saved Chimera sessions).
93 private String chimeraSessionFile = null;
95 private Random random = new Random();
98 * Initialise menu options.
100 private void initMenus()
102 viewerActionMenu.setText(MessageManager.getString("label.chimera"));
103 viewerColour.setText(MessageManager
104 .getString("label.colour_with_chimera"));
105 viewerColour.setToolTipText(MessageManager
106 .getString("label.let_chimera_manage_structure_colours"));
107 helpItem.setText(MessageManager.getString("label.chimera_help"));
108 seqColour.setSelected(jmb.isColourBySequence());
109 viewerColour.setSelected(!jmb.isColourBySequence());
110 if (_colourwith == null)
112 _colourwith = new Vector<AlignmentPanel>();
114 if (_alignwith == null)
116 _alignwith = new Vector<AlignmentPanel>();
119 // save As not yet implemented
120 savemenu.setVisible(false);
122 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
123 MessageManager.getString("label.colour_by"), this, _colourwith,
127 public void itemStateChanged(ItemEvent e)
129 if (!seqColour.isSelected())
135 // update the Chimera display now.
136 seqColour_actionPerformed(null);
140 viewMenu.add(seqColourBy);
141 viewMenu.add(fitToWindow);
143 final ItemListener handler;
144 JMenu alpanels = new ViewSelectionMenu(
145 MessageManager.getString("label.superpose_with"), this,
146 _alignwith, handler = new ItemListener()
149 public void itemStateChanged(ItemEvent e)
151 alignStructs.setEnabled(_alignwith.size() > 0);
152 alignStructs.setToolTipText(MessageManager
154 "label.align_structures_using_linked_alignment_views",
155 new Object[] { new Integer(_alignwith
156 .size()).toString() }));
159 handler.itemStateChanged(null);
160 viewerActionMenu.add(alpanels);
161 viewerActionMenu.addMenuListener(new MenuListener()
165 public void menuSelected(MenuEvent e)
167 handler.itemStateChanged(null);
171 public void menuDeselected(MenuEvent e)
173 // TODO Auto-generated method stub
177 public void menuCanceled(MenuEvent e)
179 // TODO Auto-generated method stub
185 * add a single PDB structure to a new or existing Chimera view
192 public ChimeraViewFrame(PDBEntry pdbentry, SequenceI[] seq,
193 String[] chains, final AlignmentPanel ap)
196 String pdbId = pdbentry.getId();
199 * If the PDB file is already loaded, the user may just choose to add to an
200 * existing viewer (or cancel)
202 if (addAlreadyLoadedFile(seq, chains, ap, pdbId))
208 * Check if there are other Chimera views involving this alignment and give
209 * user the option to add and align this molecule to one of them (or cancel)
211 if (addToExistingViewer(pdbentry, seq, chains, ap, pdbId))
217 * If the options above are declined or do not apply, show the structure in
220 openNewChimera(ap, new PDBEntry[] { pdbentry },
221 new SequenceI[][] { seq });
225 * Create a helper to manage progress bar display
227 protected void createProgressBar()
229 if (progressBar == null)
231 progressBar = new ProgressBar(statusPanel, statusBar);
236 * Answers true if this viewer already involves the given PDB ID
239 protected boolean hasPdbId(String pdbId)
241 return jmb.hasPdbId(pdbId);
244 private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
248 // FIXME extractChains needs pdbentries to match IDs to PDBEntry(s) on seqs
249 jmb = new JalviewChimeraBindingModel(this,
250 ap.getStructureSelectionManager(), pdbentrys, seqs, null);
251 addAlignmentPanel(ap);
252 useAlignmentPanelForColourbyseq(ap);
253 if (pdbentrys.length > 1)
255 alignAddedStructures = true;
256 useAlignmentPanelForSuperposition(ap);
258 jmb.setColourBySequence(true);
259 setSize(400, 400); // probably should be a configurable/dynamic default here
262 addingStructures = false;
263 worker = new Thread(this);
266 this.addInternalFrameListener(new InternalFrameAdapter()
269 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
280 * Create a new viewer from saved session state data including Chimera session
283 * @param chimeraSessionFile
287 * @param colourByChimera
288 * @param colourBySequence
291 public ChimeraViewFrame(String chimeraSessionFile,
292 AlignmentPanel alignPanel, PDBEntry[] pdbArray,
293 SequenceI[][] seqsArray, boolean colourByChimera,
294 boolean colourBySequence, String newViewId)
297 setViewId(newViewId);
298 this.chimeraSessionFile = chimeraSessionFile;
299 openNewChimera(alignPanel, pdbArray, seqsArray);
302 jmb.setColourBySequence(false);
303 seqColour.setSelected(false);
304 viewerColour.setSelected(true);
306 else if (colourBySequence)
308 jmb.setColourBySequence(true);
309 seqColour.setSelected(true);
310 viewerColour.setSelected(false);
315 * create a new viewer containing several structures superimposed using the
322 public ChimeraViewFrame(PDBEntry[] pe, SequenceI[][] seqs,
326 openNewChimera(ap, pe, seqs);
330 * Default constructor
332 public ChimeraViewFrame()
337 * closeViewer will decide whether or not to close this frame
338 * depending on whether user chooses to Cancel or not
340 setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
344 * Returns a list of any Chimera viewers in the desktop. The list is
345 * restricted to those linked to the given alignment panel if it is not null.
348 protected List<StructureViewerBase> getViewersFor(AlignmentPanel ap)
350 List<StructureViewerBase> result = new ArrayList<StructureViewerBase>();
351 JInternalFrame[] frames = Desktop.instance.getAllFrames();
353 for (JInternalFrame frame : frames)
355 if (frame instanceof ChimeraViewFrame)
357 if (ap == null || ((StructureViewerBase) frame).isLinkedWith(ap))
359 result.add((StructureViewerBase) frame);
367 * Launch Chimera. If we have a chimera session file name, send Chimera the
368 * command to open its saved session file.
372 jmb.setFinishedInit(false);
373 jalview.gui.Desktop.addInternalFrame(this,
374 jmb.getViewerTitle("Chimera", true), getBounds().width,
377 if (!jmb.launchChimera())
379 JvOptionPane.showMessageDialog(Desktop.desktop,
380 MessageManager.getString("label.chimera_failed"),
381 MessageManager.getString("label.error_loading_file"),
382 JvOptionPane.ERROR_MESSAGE);
387 if (this.chimeraSessionFile != null)
389 boolean opened = jmb.openSession(chimeraSessionFile);
393 .println("An error occurred opening Chimera session file "
394 + chimeraSessionFile);
397 jmb.setFinishedInit(true);
399 jmb.startChimeraListener();
404 * Show only the selected chain(s) in the viewer
407 void showSelectedChains()
409 List<String> toshow = new ArrayList<String>();
410 for (int i = 0; i < chainMenu.getItemCount(); i++)
412 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
414 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
415 if (item.isSelected())
417 toshow.add(item.getText());
421 jmb.showChains(toshow);
425 * Close down this instance of Jalview's Chimera viewer, giving the user the
426 * option to close the associated Chimera window (process). They may wish to
427 * keep it open until they have had an opportunity to save any work.
429 * @param closeChimera
430 * if true, close any linked Chimera process; if false, prompt first
433 public void closeViewer(boolean closeChimera)
435 if (jmb != null && jmb.isChimeraRunning())
439 String prompt = MessageManager.formatMessage(
440 "label.confirm_close_chimera",
441 new Object[] { jmb.getViewerTitle("Chimera", false) });
442 prompt = JvSwingUtils.wrapTooltip(true, prompt);
443 int confirm = JvOptionPane.showConfirmDialog(this, prompt,
444 MessageManager.getString("label.close_viewer"),
445 JvOptionPane.YES_NO_CANCEL_OPTION);
447 * abort closure if user hits escape or Cancel
449 if (confirm == JvOptionPane.CANCEL_OPTION
450 || confirm == JvOptionPane.CLOSED_OPTION)
454 closeChimera = confirm == JvOptionPane.YES_OPTION;
456 jmb.closeViewer(closeChimera);
458 setAlignmentPanel(null);
462 // TODO: check for memory leaks where instance isn't finalised because jmb
463 // holds a reference to the window
469 * Open any newly added PDB structures in Chimera, having first fetched data
470 * from PDB (if not already saved).
476 // todo - record which pdbids were successfully imported.
477 StringBuilder errormsgs = new StringBuilder(128);
478 StringBuilder files = new StringBuilder(128);
479 List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
480 List<Integer> filePDBpos = new ArrayList<Integer>();
481 PDBEntry thePdbEntry = null;
482 StructureFile pdb = null;
485 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
486 // TODO: replace with reference fetching/transfer code (validate PDBentry
488 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
491 thePdbEntry = jmb.getPdbEntry(pi);
492 if (thePdbEntry.getFile() == null)
495 * Retrieve PDB data, save to file, attach to PDBEntry
497 file = fetchPdbFile(thePdbEntry);
500 errormsgs.append("'" + thePdbEntry.getId() + "' ");
506 * Got file already - ignore if already loaded in Chimera.
508 file = new File(thePdbEntry.getFile()).getAbsoluteFile()
510 if (curfiles != null && curfiles.length > 0)
512 addingStructures = true; // already files loaded.
513 for (int c = 0; c < curfiles.length; c++)
515 if (curfiles[c].equals(file))
525 filePDB.add(thePdbEntry);
526 filePDBpos.add(Integer.valueOf(pi));
527 files.append(" \"" + Platform.escapeString(file) + "\"");
530 } catch (OutOfMemoryError oomerror)
532 new OOMWarning("Retrieving PDB files: " + thePdbEntry.getId(),
534 } catch (Exception ex)
536 ex.printStackTrace();
537 errormsgs.append("When retrieving pdbfiles for '"
538 + thePdbEntry.getId() + "'");
540 if (errormsgs.length() > 0)
543 JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
544 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
545 new Object[] { errormsgs.toString() }),
546 MessageManager.getString("label.couldnt_load_file"),
547 JvOptionPane.ERROR_MESSAGE);
550 if (files.length() > 0)
552 if (!addingStructures)
557 } catch (Exception ex)
559 Cache.log.error("Couldn't open Chimera viewer!", ex);
563 for (PDBEntry pe : filePDB)
566 if (pe.getFile() != null)
570 int pos = filePDBpos.get(num).intValue();
571 long startTime = startProgressBar("Chimera "
572 + MessageManager.getString("status.opening_file_for")
575 jmb.addSequence(pos, jmb.getSequence()[pos]);
576 File fl = new File(pe.getFile());
577 DataSourceType protocol = DataSourceType.URL;
582 protocol = DataSourceType.FILE;
584 } catch (Throwable e)
588 stopProgressBar("", startTime);
590 // Explicitly map to the filename used by Chimera ;
591 pdb = jmb.getSsm().setMapping(jmb.getSequence()[pos],
592 jmb.getChains()[pos], pe.getFile(), protocol,
594 stashFoundChains(pdb, pe.getFile());
595 } catch (OutOfMemoryError oomerror)
598 "When trying to open and map structures from Chimera!",
600 } catch (Exception ex)
602 Cache.log.error("Couldn't open " + pe.getFile()
603 + " in Chimera viewer!", ex);
606 Cache.log.debug("File locations are " + files);
611 jmb.setFinishedInit(true);
612 jmb.setLoadingFromArchive(false);
614 // refresh the sequence colours for the new structure(s)
615 for (AlignmentPanel ap : _colourwith)
617 jmb.updateColours(ap);
619 // do superposition if asked to
620 if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures)
622 new Thread(new Runnable()
627 alignStructs_withAllAlignPanels();
630 alignAddedStructures = false;
632 addingStructures = false;
639 * Fetch PDB data and save to a local file. Returns the full path to the file,
640 * or null if fetch fails. TODO: refactor to common with Jmol ? duplication
642 * @param processingEntry
647 private void stashFoundChains(StructureFile pdb, String file)
649 for (int i = 0; i < pdb.getChains().size(); i++)
651 String chid = new String(pdb.getId() + ":"
652 + pdb.getChains().elementAt(i).id);
653 jmb.getChainNames().add(chid);
654 jmb.getChainFile().put(chid, file);
657 private String fetchPdbFile(PDBEntry processingEntry) throws Exception
659 // FIXME: this is duplicated code with Jmol frame ?
660 String filePath = null;
661 Pdb pdbclient = new Pdb();
662 AlignmentI pdbseq = null;
663 String pdbid = processingEntry.getId();
664 long handle = System.currentTimeMillis()
665 + Thread.currentThread().hashCode();
668 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
670 String msg = MessageManager.formatMessage("status.fetching_pdb",
671 new Object[] { pdbid });
672 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
673 // long hdl = startProgressBar(MessageManager.formatMessage(
674 // "status.fetching_pdb", new Object[]
678 pdbseq = pdbclient.getSequenceRecords(pdbid);
679 } catch (OutOfMemoryError oomerror)
681 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
684 msg = pdbid + " " + MessageManager.getString("label.state_completed");
685 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
686 // stopProgressBar(msg, hdl);
689 * If PDB data were saved and are not invalid (empty alignment), return the
692 if (pdbseq != null && pdbseq.getHeight() > 0)
694 // just use the file name from the first sequence's first PDBEntry
695 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
696 .elementAt(0).getFile()).getAbsolutePath();
697 processingEntry.setFile(filePath);
703 * Convenience method to update the progress bar if there is one. Be sure to
704 * call stopProgressBar with the returned handle to remove the message.
709 public long startProgressBar(String msg)
711 // TODO would rather have startProgress/stopProgress as the
712 // IProgressIndicator interface
713 long tm = random.nextLong();
714 if (progressBar != null)
716 progressBar.setProgressBar(msg, tm);
722 * End the progress bar with the specified handle, leaving a message (if not
723 * null) on the status bar
728 public void stopProgressBar(String msg, long handle)
730 if (progressBar != null)
732 progressBar.setProgressBar(msg, handle);
737 public void pdbFile_actionPerformed(ActionEvent actionEvent)
739 JalviewFileChooser chooser = new JalviewFileChooser(
740 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
742 chooser.setFileView(new JalviewFileView());
743 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
744 chooser.setToolTipText(MessageManager.getString("action.save"));
746 int value = chooser.showSaveDialog(this);
748 if (value == JalviewFileChooser.APPROVE_OPTION)
750 BufferedReader in = null;
753 // TODO: cope with multiple PDB files in view
754 in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
755 File outFile = chooser.getSelectedFile();
757 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
759 while ((data = in.readLine()) != null)
761 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
767 } catch (Exception ex)
769 ex.printStackTrace();
777 } catch (IOException e)
787 public void viewMapping_actionPerformed(ActionEvent actionEvent)
789 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
792 cap.appendText(jmb.printMappings());
793 } catch (OutOfMemoryError e)
796 "composing sequence-structure alignments for display in text box.",
801 jalview.gui.Desktop.addInternalFrame(cap,
802 MessageManager.getString("label.pdb_sequence_mapping"), 550,
807 public void eps_actionPerformed(ActionEvent e)
811 .getString("error.eps_generation_not_implemented"));
815 public void png_actionPerformed(ActionEvent e)
819 .getString("error.png_generation_not_implemented"));
823 public void viewerColour_actionPerformed(ActionEvent actionEvent)
825 if (viewerColour.isSelected())
827 // disable automatic sequence colouring.
828 jmb.setColourBySequence(false);
833 public void seqColour_actionPerformed(ActionEvent actionEvent)
835 jmb.setColourBySequence(seqColour.isSelected());
836 if (_colourwith == null)
838 _colourwith = new Vector<AlignmentPanel>();
840 if (jmb.isColourBySequence())
842 if (!jmb.isLoadingFromArchive())
844 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
846 // Make the currently displayed alignment panel the associated view
847 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
850 // Set the colour using the current view for the associated alignframe
851 for (AlignmentPanel ap : _colourwith)
853 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
859 public void chainColour_actionPerformed(ActionEvent actionEvent)
861 chainColour.setSelected(true);
866 public void chargeColour_actionPerformed(ActionEvent actionEvent)
868 chargeColour.setSelected(true);
869 jmb.colourByCharge();
873 public void zappoColour_actionPerformed(ActionEvent actionEvent)
875 zappoColour.setSelected(true);
876 jmb.setJalviewColourScheme(new ZappoColourScheme());
880 public void taylorColour_actionPerformed(ActionEvent actionEvent)
882 taylorColour.setSelected(true);
883 jmb.setJalviewColourScheme(new TaylorColourScheme());
887 public void hydroColour_actionPerformed(ActionEvent actionEvent)
889 hydroColour.setSelected(true);
890 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
894 public void helixColour_actionPerformed(ActionEvent actionEvent)
896 helixColour.setSelected(true);
897 jmb.setJalviewColourScheme(new HelixColourScheme());
901 public void strandColour_actionPerformed(ActionEvent actionEvent)
903 strandColour.setSelected(true);
904 jmb.setJalviewColourScheme(new StrandColourScheme());
908 public void turnColour_actionPerformed(ActionEvent actionEvent)
910 turnColour.setSelected(true);
911 jmb.setJalviewColourScheme(new TurnColourScheme());
915 public void buriedColour_actionPerformed(ActionEvent actionEvent)
917 buriedColour.setSelected(true);
918 jmb.setJalviewColourScheme(new BuriedColourScheme());
922 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
924 setJalviewColourScheme(new PurinePyrimidineColourScheme());
928 public void userColour_actionPerformed(ActionEvent actionEvent)
930 userColour.setSelected(true);
931 new UserDefinedColours(this, null);
935 public void backGround_actionPerformed(ActionEvent actionEvent)
937 java.awt.Color col = JColorChooser
938 .showDialog(this, MessageManager
939 .getString("label.select_backgroud_colour"), null);
942 jmb.setBackgroundColour(col);
947 public void showHelp_actionPerformed(ActionEvent actionEvent)
951 jalview.util.BrowserLauncher
952 .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
953 } catch (Exception ex)
958 public void updateTitleAndMenus()
960 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
965 setChainMenuItems(jmb.getChainNames());
967 this.setTitle(jmb.getViewerTitle("Chimera", true));
968 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
970 viewerActionMenu.setVisible(true);
972 if (!jmb.isLoadingFromArchive())
974 seqColour_actionPerformed(null);
982 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
986 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
988 alignStructs_withAllAlignPanels();
991 private void alignStructs_withAllAlignPanels()
993 if (getAlignmentPanel() == null)
998 if (_alignwith.size() == 0)
1000 _alignwith.add(getAlignmentPanel());
1005 AlignmentI[] als = new Alignment[_alignwith.size()];
1006 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1007 int[] alm = new int[_alignwith.size()];
1010 for (AlignmentPanel ap : _alignwith)
1012 als[a] = ap.av.getAlignment();
1014 alc[a++] = ap.av.getColumnSelection();
1016 jmb.superposeStructures(als, alm, alc);
1017 } catch (Exception e)
1019 StringBuffer sp = new StringBuffer();
1020 for (AlignmentPanel ap : _alignwith)
1022 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1024 Cache.log.info("Couldn't align structures with the " + sp.toString()
1025 + "associated alignment panels.", e);
1030 public void setJalviewColourScheme(ColourSchemeI ucs)
1032 jmb.setJalviewColourScheme(ucs);
1039 * @return first alignment panel displaying given alignment, or the default
1042 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1044 for (AlignmentPanel ap : getAllAlignmentPanels())
1046 if (ap.av.getAlignment() == alignment)
1051 return getAlignmentPanel();
1055 public AAStructureBindingModel getBinding()
1061 * Ask Chimera to save its session to the designated file path, or to a
1062 * temporary file if the path is null. Returns the file path if successful,
1068 protected String saveSession(String filepath)
1070 String pathUsed = filepath;
1073 if (pathUsed == null)
1075 File tempFile = File.createTempFile("chimera", ".py");
1076 tempFile.deleteOnExit();
1077 pathUsed = tempFile.getPath();
1079 boolean result = jmb.saveSession(pathUsed);
1082 this.chimeraSessionFile = pathUsed;
1085 } catch (IOException e)
1092 * Returns a string representing the state of the Chimera session. This is
1093 * done by requesting Chimera to save its session to a temporary file, then
1094 * reading the file contents. Returns an empty string on any error.
1097 public String getStateInfo()
1099 String sessionFile = saveSession(null);
1100 if (sessionFile == null)
1104 InputStream is = null;
1107 File f = new File(sessionFile);
1108 byte[] bytes = new byte[(int) f.length()];
1109 is = new FileInputStream(sessionFile);
1111 return new String(bytes);
1112 } catch (IOException e)
1122 } catch (IOException e)
1131 protected void fitToWindow_actionPerformed()
1137 public ViewerType getViewerType()
1139 return ViewerType.CHIMERA;
1143 protected AAStructureBindingModel getBindingModel()
1149 protected IProgressIndicator getIProgressIndicator()