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.JOptionPane;
70 import javax.swing.event.InternalFrameAdapter;
71 import javax.swing.event.InternalFrameEvent;
72 import javax.swing.event.MenuEvent;
73 import javax.swing.event.MenuListener;
76 * GUI elements for handling an external chimera display
81 public class ChimeraViewFrame extends StructureViewerBase
83 private JalviewChimeraBinding jmb;
85 private boolean allChainsSelected = false;
87 private IProgressIndicator progressBar = null;
90 * Path to Chimera session file. This is set when an open Jalview/Chimera
91 * session is saved, or on restore from a Jalview project (if it holds the
92 * filename of any saved Chimera sessions).
94 private String chimeraSessionFile = null;
96 private Random random = new Random();
99 * Initialise menu options.
101 private void initMenus()
103 viewerActionMenu.setText(MessageManager.getString("label.chimera"));
104 viewerColour.setText(MessageManager
105 .getString("label.colour_with_chimera"));
106 viewerColour.setToolTipText(MessageManager
107 .getString("label.let_chimera_manage_structure_colours"));
108 helpItem.setText(MessageManager.getString("label.chimera_help"));
109 seqColour.setSelected(jmb.isColourBySequence());
110 viewerColour.setSelected(!jmb.isColourBySequence());
111 if (_colourwith == null)
113 _colourwith = new Vector<AlignmentPanel>();
115 if (_alignwith == null)
117 _alignwith = new Vector<AlignmentPanel>();
120 // save As not yet implemented
121 savemenu.setVisible(false);
123 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
124 MessageManager.getString("label.colour_by"), this, _colourwith,
128 public void itemStateChanged(ItemEvent e)
130 if (!seqColour.isSelected())
136 // update the Chimera display now.
137 seqColour_actionPerformed(null);
141 viewMenu.add(seqColourBy);
142 viewMenu.add(fitToWindow);
144 final ItemListener handler;
145 JMenu alpanels = new ViewSelectionMenu(
146 MessageManager.getString("label.superpose_with"), this,
147 _alignwith, handler = new ItemListener()
150 public void itemStateChanged(ItemEvent e)
152 alignStructs.setEnabled(_alignwith.size() > 0);
153 alignStructs.setToolTipText(MessageManager
155 "label.align_structures_using_linked_alignment_views",
156 new Object[] { new Integer(_alignwith
157 .size()).toString() }));
160 handler.itemStateChanged(null);
161 viewerActionMenu.add(alpanels);
162 viewerActionMenu.addMenuListener(new MenuListener()
166 public void menuSelected(MenuEvent e)
168 handler.itemStateChanged(null);
172 public void menuDeselected(MenuEvent e)
174 // TODO Auto-generated method stub
178 public void menuCanceled(MenuEvent e)
180 // TODO Auto-generated method stub
186 * add a single PDB structure to a new or existing Chimera view
193 public ChimeraViewFrame(PDBEntry pdbentry, SequenceI[] seq,
194 String[] chains, final AlignmentPanel ap)
197 String pdbId = pdbentry.getId();
200 * If the PDB file is already loaded, the user may just choose to add to an
201 * existing viewer (or cancel)
203 if (addAlreadyLoadedFile(seq, chains, ap, pdbId))
209 * Check if there are other Chimera views involving this alignment and give
210 * user the option to add and align this molecule to one of them (or cancel)
212 if (addToExistingViewer(pdbentry, seq, chains, ap, pdbId))
218 * If the options above are declined or do not apply, show the structure in
221 openNewChimera(ap, new PDBEntry[] { pdbentry },
222 new SequenceI[][] { seq });
226 * Create a helper to manage progress bar display
228 protected void createProgressBar()
230 if (progressBar == null)
232 progressBar = new ProgressBar(statusPanel, statusBar);
237 * Answers true if this viewer already involves the given PDB ID
240 protected boolean hasPdbId(String pdbId)
242 return jmb.hasPdbId(pdbId);
245 private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
249 // FIXME extractChains needs pdbentries to match IDs to PDBEntry(s) on seqs
250 jmb = new JalviewChimeraBindingModel(this,
251 ap.getStructureSelectionManager(), pdbentrys, seqs, null);
252 addAlignmentPanel(ap);
253 useAlignmentPanelForColourbyseq(ap);
254 if (pdbentrys.length > 1)
256 alignAddedStructures = true;
257 useAlignmentPanelForSuperposition(ap);
259 jmb.setColourBySequence(true);
260 setSize(400, 400); // probably should be a configurable/dynamic default here
263 addingStructures = false;
264 worker = new Thread(this);
267 this.addInternalFrameListener(new InternalFrameAdapter()
270 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
281 * Create a new viewer from saved session state data including Chimera session
284 * @param chimeraSessionFile
288 * @param colourByChimera
289 * @param colourBySequence
292 public ChimeraViewFrame(String chimeraSessionFile,
293 AlignmentPanel alignPanel, PDBEntry[] pdbArray,
294 SequenceI[][] seqsArray, boolean colourByChimera,
295 boolean colourBySequence, String newViewId)
298 setViewId(newViewId);
299 this.chimeraSessionFile = chimeraSessionFile;
300 openNewChimera(alignPanel, pdbArray, seqsArray);
303 jmb.setColourBySequence(false);
304 seqColour.setSelected(false);
305 viewerColour.setSelected(true);
307 else if (colourBySequence)
309 jmb.setColourBySequence(true);
310 seqColour.setSelected(true);
311 viewerColour.setSelected(false);
316 * create a new viewer containing several structures superimposed using the
323 public ChimeraViewFrame(PDBEntry[] pe, SequenceI[][] seqs,
327 openNewChimera(ap, pe, seqs);
331 * Default constructor
333 public ChimeraViewFrame()
338 * closeViewer will decide whether or not to close this frame
339 * depending on whether user chooses to Cancel or not
341 setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
345 * Returns a list of any Chimera viewers in the desktop. The list is
346 * restricted to those linked to the given alignment panel if it is not null.
349 protected List<StructureViewerBase> getViewersFor(AlignmentPanel ap)
351 List<StructureViewerBase> result = new ArrayList<StructureViewerBase>();
352 JInternalFrame[] frames = Desktop.instance.getAllFrames();
354 for (JInternalFrame frame : frames)
356 if (frame instanceof ChimeraViewFrame)
358 if (ap == null || ((StructureViewerBase) frame).isLinkedWith(ap))
360 result.add((StructureViewerBase) frame);
368 * Launch Chimera. If we have a chimera session file name, send Chimera the
369 * command to open its saved session file.
373 jmb.setFinishedInit(false);
374 jalview.gui.Desktop.addInternalFrame(this,
375 jmb.getViewerTitle("Chimera", true), getBounds().width,
378 if (!jmb.launchChimera())
380 JvOptionPane.showMessageDialog(Desktop.desktop,
381 MessageManager.getString("label.chimera_failed"),
382 MessageManager.getString("label.error_loading_file"),
383 JvOptionPane.ERROR_MESSAGE);
388 if (this.chimeraSessionFile != null)
390 boolean opened = jmb.openSession(chimeraSessionFile);
394 .println("An error occurred opening Chimera session file "
395 + chimeraSessionFile);
398 jmb.setFinishedInit(true);
400 jmb.startChimeraListener();
405 * Show only the selected chain(s) in the viewer
408 void showSelectedChains()
410 List<String> toshow = new ArrayList<String>();
411 for (int i = 0; i < chainMenu.getItemCount(); i++)
413 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
415 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
416 if (item.isSelected())
418 toshow.add(item.getText());
422 jmb.showChains(toshow);
426 * Close down this instance of Jalview's Chimera viewer, giving the user the
427 * option to close the associated Chimera window (process). They may wish to
428 * keep it open until they have had an opportunity to save any work.
430 * @param closeChimera
431 * if true, close any linked Chimera process; if false, prompt first
434 public void closeViewer(boolean closeChimera)
436 if (jmb != null && jmb.isChimeraRunning())
440 String prompt = MessageManager.formatMessage(
441 "label.confirm_close_chimera",
442 new Object[] { jmb.getViewerTitle("Chimera", false) });
443 prompt = JvSwingUtils.wrapTooltip(true, prompt);
444 int confirm = JvOptionPane.showConfirmDialog(this, prompt,
445 MessageManager.getString("label.close_viewer"),
446 JvOptionPane.YES_NO_CANCEL_OPTION);
448 * abort closure if user hits escape or Cancel
450 if (confirm == JvOptionPane.CANCEL_OPTION
451 || confirm == JvOptionPane.CLOSED_OPTION)
455 closeChimera = confirm == JvOptionPane.YES_OPTION;
457 jmb.closeViewer(closeChimera);
459 setAlignmentPanel(null);
463 // TODO: check for memory leaks where instance isn't finalised because jmb
464 // holds a reference to the window
470 * Open any newly added PDB structures in Chimera, having first fetched data
471 * from PDB (if not already saved).
477 // todo - record which pdbids were successfully imported.
478 StringBuilder errormsgs = new StringBuilder(128);
479 StringBuilder files = new StringBuilder(128);
480 List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
481 List<Integer> filePDBpos = new ArrayList<Integer>();
482 PDBEntry thePdbEntry = null;
483 StructureFile pdb = null;
486 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
487 // TODO: replace with reference fetching/transfer code (validate PDBentry
489 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
492 thePdbEntry = jmb.getPdbEntry(pi);
493 if (thePdbEntry.getFile() == null)
496 * Retrieve PDB data, save to file, attach to PDBEntry
498 file = fetchPdbFile(thePdbEntry);
501 errormsgs.append("'" + thePdbEntry.getId() + "' ");
507 * Got file already - ignore if already loaded in Chimera.
509 file = new File(thePdbEntry.getFile()).getAbsoluteFile()
511 if (curfiles != null && curfiles.length > 0)
513 addingStructures = true; // already files loaded.
514 for (int c = 0; c < curfiles.length; c++)
516 if (curfiles[c].equals(file))
526 filePDB.add(thePdbEntry);
527 filePDBpos.add(Integer.valueOf(pi));
528 files.append(" \"" + Platform.escapeString(file) + "\"");
531 } catch (OutOfMemoryError oomerror)
533 new OOMWarning("Retrieving PDB files: " + thePdbEntry.getId(),
535 } catch (Exception ex)
537 ex.printStackTrace();
538 errormsgs.append("When retrieving pdbfiles for '"
539 + thePdbEntry.getId() + "'");
541 if (errormsgs.length() > 0)
544 JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
545 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
546 new Object[] { errormsgs.toString() }),
547 MessageManager.getString("label.couldnt_load_file"),
548 JvOptionPane.ERROR_MESSAGE);
551 if (files.length() > 0)
553 if (!addingStructures)
558 } catch (Exception ex)
560 Cache.log.error("Couldn't open Chimera viewer!", ex);
564 for (PDBEntry pe : filePDB)
567 if (pe.getFile() != null)
571 int pos = filePDBpos.get(num).intValue();
572 long startTime = startProgressBar("Chimera "
573 + MessageManager.getString("status.opening_file_for")
576 jmb.addSequence(pos, jmb.getSequence()[pos]);
577 File fl = new File(pe.getFile());
578 DataSourceType protocol = DataSourceType.URL;
583 protocol = DataSourceType.FILE;
585 } catch (Throwable e)
589 stopProgressBar("", startTime);
591 // Explicitly map to the filename used by Chimera ;
592 pdb = jmb.getSsm().setMapping(jmb.getSequence()[pos],
593 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.
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()