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.UserColourScheme;
44 import jalview.schemes.ZappoColourScheme;
45 import jalview.structures.models.AAStructureBindingModel;
46 import jalview.util.MessageManager;
47 import jalview.util.Platform;
48 import jalview.ws.dbsources.Pdb;
50 import java.awt.Color;
51 import java.awt.event.ActionEvent;
52 import java.awt.event.ItemEvent;
53 import java.awt.event.ItemListener;
54 import java.io.BufferedReader;
56 import java.io.FileInputStream;
57 import java.io.FileOutputStream;
58 import java.io.FileReader;
59 import java.io.IOException;
60 import java.io.InputStream;
61 import java.io.PrintWriter;
62 import java.util.ArrayList;
63 import java.util.List;
64 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.event.InternalFrameAdapter;
72 import javax.swing.event.InternalFrameEvent;
73 import javax.swing.event.MenuEvent;
74 import javax.swing.event.MenuListener;
77 * GUI elements for handling an external chimera display
82 public class ChimeraViewFrame extends StructureViewerBase
84 private JalviewChimeraBinding jmb;
86 private boolean allChainsSelected = false;
88 private IProgressIndicator progressBar = null;
91 * Path to Chimera session file. This is set when an open Jalview/Chimera
92 * session is saved, or on restore from a Jalview project (if it holds the
93 * filename of any saved Chimera sessions).
95 private String chimeraSessionFile = null;
97 private Random random = new Random();
100 * Initialise menu options.
102 private void initMenus()
104 viewerActionMenu.setText(MessageManager.getString("label.chimera"));
105 viewerColour.setText(MessageManager
106 .getString("label.colour_with_chimera"));
107 viewerColour.setToolTipText(MessageManager
108 .getString("label.let_chimera_manage_structure_colours"));
109 helpItem.setText(MessageManager.getString("label.chimera_help"));
110 seqColour.setSelected(jmb.isColourBySequence());
111 viewerColour.setSelected(!jmb.isColourBySequence());
112 if (_colourwith == null)
114 _colourwith = new Vector<AlignmentPanel>();
116 if (_alignwith == null)
118 _alignwith = new Vector<AlignmentPanel>();
121 // save As not yet implemented
122 savemenu.setVisible(false);
124 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
125 MessageManager.getString("label.colour_by"), this, _colourwith,
129 public void itemStateChanged(ItemEvent e)
131 if (!seqColour.isSelected())
137 // update the Chimera display now.
138 seqColour_actionPerformed(null);
142 viewMenu.add(seqColourBy);
143 viewMenu.add(fitToWindow);
145 final ItemListener handler;
146 JMenu alpanels = new ViewSelectionMenu(
147 MessageManager.getString("label.superpose_with"), this,
148 _alignwith, handler = new ItemListener()
151 public void itemStateChanged(ItemEvent e)
153 alignStructs.setEnabled(_alignwith.size() > 0);
154 alignStructs.setToolTipText(MessageManager
156 "label.align_structures_using_linked_alignment_views",
157 new Object[] { new Integer(_alignwith
158 .size()).toString() }));
161 handler.itemStateChanged(null);
162 viewerActionMenu.add(alpanels);
163 viewerActionMenu.addMenuListener(new MenuListener()
167 public void menuSelected(MenuEvent e)
169 handler.itemStateChanged(null);
173 public void menuDeselected(MenuEvent e)
175 // TODO Auto-generated method stub
179 public void menuCanceled(MenuEvent e)
181 // TODO Auto-generated method stub
187 * add a single PDB structure to a new or existing Chimera view
194 public ChimeraViewFrame(PDBEntry pdbentry, SequenceI[] seq,
195 String[] chains, final AlignmentPanel ap)
198 String pdbId = pdbentry.getId();
201 * If the PDB file is already loaded, the user may just choose to add to an
202 * existing viewer (or cancel)
204 if (addAlreadyLoadedFile(seq, chains, ap, pdbId))
210 * Check if there are other Chimera views involving this alignment and give
211 * user the option to add and align this molecule to one of them (or cancel)
213 if (addToExistingViewer(pdbentry, seq, chains, ap, pdbId))
219 * If the options above are declined or do not apply, show the structure in
222 openNewChimera(ap, new PDBEntry[] { pdbentry },
223 new SequenceI[][] { seq });
227 * Create a helper to manage progress bar display
229 protected void createProgressBar()
231 if (progressBar == null)
233 progressBar = new ProgressBar(statusPanel, statusBar);
238 * Answers true if this viewer already involves the given PDB ID
241 protected boolean hasPdbId(String pdbId)
243 return jmb.hasPdbId(pdbId);
246 private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
250 // FIXME extractChains needs pdbentries to match IDs to PDBEntry(s) on seqs
251 jmb = new JalviewChimeraBindingModel(this,
252 ap.getStructureSelectionManager(), pdbentrys, seqs, null);
253 addAlignmentPanel(ap);
254 useAlignmentPanelForColourbyseq(ap);
255 if (pdbentrys.length > 1)
257 alignAddedStructures = true;
258 useAlignmentPanelForSuperposition(ap);
260 jmb.setColourBySequence(true);
261 setSize(400, 400); // probably should be a configurable/dynamic default here
264 addingStructures = false;
265 worker = new Thread(this);
268 this.addInternalFrameListener(new InternalFrameAdapter()
271 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
282 * Create a new viewer from saved session state data including Chimera session
285 * @param chimeraSessionFile
289 * @param colourByChimera
290 * @param colourBySequence
293 public ChimeraViewFrame(String chimeraSessionFile,
294 AlignmentPanel alignPanel, PDBEntry[] pdbArray,
295 SequenceI[][] seqsArray, boolean colourByChimera,
296 boolean colourBySequence, String newViewId)
299 setViewId(newViewId);
300 this.chimeraSessionFile = chimeraSessionFile;
301 openNewChimera(alignPanel, pdbArray, seqsArray);
304 jmb.setColourBySequence(false);
305 seqColour.setSelected(false);
306 viewerColour.setSelected(true);
308 else if (colourBySequence)
310 jmb.setColourBySequence(true);
311 seqColour.setSelected(true);
312 viewerColour.setSelected(false);
317 * create a new viewer containing several structures superimposed using the
324 public ChimeraViewFrame(PDBEntry[] pe, SequenceI[][] seqs,
328 openNewChimera(ap, pe, seqs);
332 * Default constructor
334 public ChimeraViewFrame()
339 * closeViewer will decide whether or not to close this frame
340 * depending on whether user chooses to Cancel or not
342 setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
346 * Returns a list of any Chimera viewers in the desktop. The list is
347 * restricted to those linked to the given alignment panel if it is not null.
350 protected List<StructureViewerBase> getViewersFor(AlignmentPanel ap)
352 List<StructureViewerBase> result = new ArrayList<StructureViewerBase>();
353 JInternalFrame[] frames = Desktop.instance.getAllFrames();
355 for (JInternalFrame frame : frames)
357 if (frame instanceof ChimeraViewFrame)
359 if (ap == null || ((StructureViewerBase) frame).isLinkedWith(ap))
361 result.add((StructureViewerBase) frame);
369 * Launch Chimera. If we have a chimera session file name, send Chimera the
370 * command to open its saved session file.
374 jmb.setFinishedInit(false);
375 jalview.gui.Desktop.addInternalFrame(this,
376 jmb.getViewerTitle("Chimera", true), getBounds().width,
379 if (!jmb.launchChimera())
381 JvOptionPane.showMessageDialog(Desktop.desktop,
382 MessageManager.getString("label.chimera_failed"),
383 MessageManager.getString("label.error_loading_file"),
384 JvOptionPane.ERROR_MESSAGE);
389 if (this.chimeraSessionFile != null)
391 boolean opened = jmb.openSession(chimeraSessionFile);
395 .println("An error occurred opening Chimera session file "
396 + chimeraSessionFile);
399 jmb.setFinishedInit(true);
401 jmb.startChimeraListener();
406 * Show only the selected chain(s) in the viewer
409 void showSelectedChains()
411 List<String> toshow = new ArrayList<String>();
412 for (int i = 0; i < chainMenu.getItemCount(); i++)
414 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
416 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
417 if (item.isSelected())
419 toshow.add(item.getText());
423 jmb.showChains(toshow);
427 * Close down this instance of Jalview's Chimera viewer, giving the user the
428 * option to close the associated Chimera window (process). They may wish to
429 * keep it open until they have had an opportunity to save any work.
431 * @param closeChimera
432 * if true, close any linked Chimera process; if false, prompt first
435 public void closeViewer(boolean closeChimera)
437 if (jmb != null && jmb.isChimeraRunning())
441 String prompt = MessageManager.formatMessage(
442 "label.confirm_close_chimera",
443 new Object[] { jmb.getViewerTitle("Chimera", false) });
444 prompt = JvSwingUtils.wrapTooltip(true, prompt);
445 int confirm = JvOptionPane.showConfirmDialog(this, prompt,
446 MessageManager.getString("label.close_viewer"),
447 JvOptionPane.YES_NO_CANCEL_OPTION);
449 * abort closure if user hits escape or Cancel
451 if (confirm == JvOptionPane.CANCEL_OPTION
452 || confirm == JvOptionPane.CLOSED_OPTION)
456 closeChimera = confirm == JvOptionPane.YES_OPTION;
458 jmb.closeViewer(closeChimera);
460 setAlignmentPanel(null);
464 // TODO: check for memory leaks where instance isn't finalised because jmb
465 // holds a reference to the window
471 * Open any newly added PDB structures in Chimera, having first fetched data
472 * from PDB (if not already saved).
478 // todo - record which pdbids were successfully imported.
479 StringBuilder errormsgs = new StringBuilder(128);
480 StringBuilder files = new StringBuilder(128);
481 List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
482 List<Integer> filePDBpos = new ArrayList<Integer>();
483 PDBEntry thePdbEntry = null;
484 StructureFile pdb = null;
487 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
488 // TODO: replace with reference fetching/transfer code (validate PDBentry
490 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
493 thePdbEntry = jmb.getPdbEntry(pi);
494 if (thePdbEntry.getFile() == null)
497 * Retrieve PDB data, save to file, attach to PDBEntry
499 file = fetchPdbFile(thePdbEntry);
502 errormsgs.append("'" + thePdbEntry.getId() + "' ");
508 * Got file already - ignore if already loaded in Chimera.
510 file = new File(thePdbEntry.getFile()).getAbsoluteFile()
512 if (curfiles != null && curfiles.length > 0)
514 addingStructures = true; // already files loaded.
515 for (int c = 0; c < curfiles.length; c++)
517 if (curfiles[c].equals(file))
527 filePDB.add(thePdbEntry);
528 filePDBpos.add(Integer.valueOf(pi));
529 files.append(" \"" + Platform.escapeString(file) + "\"");
532 } catch (OutOfMemoryError oomerror)
534 new OOMWarning("Retrieving PDB files: " + thePdbEntry.getId(),
536 } catch (Exception ex)
538 ex.printStackTrace();
539 errormsgs.append("When retrieving pdbfiles for '"
540 + thePdbEntry.getId() + "'");
542 if (errormsgs.length() > 0)
545 JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
546 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
547 new Object[] { errormsgs.toString() }),
548 MessageManager.getString("label.couldnt_load_file"),
549 JvOptionPane.ERROR_MESSAGE);
552 if (files.length() > 0)
554 if (!addingStructures)
559 } catch (Exception ex)
561 Cache.log.error("Couldn't open Chimera viewer!", ex);
565 for (PDBEntry pe : filePDB)
568 if (pe.getFile() != null)
572 int pos = filePDBpos.get(num).intValue();
573 long startTime = startProgressBar("Chimera "
574 + MessageManager.getString("status.opening_file_for")
577 jmb.addSequence(pos, jmb.getSequence()[pos]);
578 File fl = new File(pe.getFile());
579 DataSourceType protocol = DataSourceType.URL;
584 protocol = DataSourceType.FILE;
586 } catch (Throwable e)
590 stopProgressBar("", startTime);
592 // Explicitly map to the filename used by Chimera ;
593 pdb = jmb.getSsm().setMapping(jmb.getSequence()[pos],
594 jmb.getChains()[pos], pe.getFile(), protocol);
595 stashFoundChains(pdb, pe.getFile());
596 } catch (OutOfMemoryError oomerror)
599 "When trying to open and map structures from Chimera!",
601 } catch (Exception ex)
603 Cache.log.error("Couldn't open " + pe.getFile()
604 + " in Chimera viewer!", ex);
607 Cache.log.debug("File locations are " + files);
612 jmb.setFinishedInit(true);
613 jmb.setLoadingFromArchive(false);
615 // refresh the sequence colours for the new structure(s)
616 for (AlignmentPanel ap : _colourwith)
618 jmb.updateColours(ap);
620 // do superposition if asked to
621 if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures)
623 new Thread(new Runnable()
628 alignStructs_withAllAlignPanels();
631 alignAddedStructures = false;
633 addingStructures = false;
640 * Fetch PDB data and save to a local file. Returns the full path to the file,
641 * or null if fetch fails.
643 * @param processingEntry
648 private void stashFoundChains(StructureFile pdb, String file)
650 for (int i = 0; i < pdb.getChains().size(); i++)
652 String chid = new String(pdb.getId() + ":"
653 + pdb.getChains().elementAt(i).id);
654 jmb.getChainNames().add(chid);
655 jmb.getChainFile().put(chid, file);
658 private String fetchPdbFile(PDBEntry processingEntry) throws Exception
660 // FIXME: this is duplicated code with Jmol frame ?
661 String filePath = null;
662 Pdb pdbclient = new Pdb();
663 AlignmentI pdbseq = null;
664 String pdbid = processingEntry.getId();
665 long handle = System.currentTimeMillis()
666 + Thread.currentThread().hashCode();
669 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
671 String msg = MessageManager.formatMessage("status.fetching_pdb",
672 new Object[] { pdbid });
673 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
674 // long hdl = startProgressBar(MessageManager.formatMessage(
675 // "status.fetching_pdb", new Object[]
679 pdbseq = pdbclient.getSequenceRecords(pdbid);
680 } catch (OutOfMemoryError oomerror)
682 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
685 msg = pdbid + " " + MessageManager.getString("label.state_completed");
686 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
687 // stopProgressBar(msg, hdl);
690 * If PDB data were saved and are not invalid (empty alignment), return the
693 if (pdbseq != null && pdbseq.getHeight() > 0)
695 // just use the file name from the first sequence's first PDBEntry
696 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
697 .elementAt(0).getFile()).getAbsolutePath();
698 processingEntry.setFile(filePath);
704 * Convenience method to update the progress bar if there is one. Be sure to
705 * call stopProgressBar with the returned handle to remove the message.
710 public long startProgressBar(String msg)
712 // TODO would rather have startProgress/stopProgress as the
713 // IProgressIndicator interface
714 long tm = random.nextLong();
715 if (progressBar != null)
717 progressBar.setProgressBar(msg, tm);
723 * End the progress bar with the specified handle, leaving a message (if not
724 * null) on the status bar
729 public void stopProgressBar(String msg, long handle)
731 if (progressBar != null)
733 progressBar.setProgressBar(msg, handle);
738 public void pdbFile_actionPerformed(ActionEvent actionEvent)
740 JalviewFileChooser chooser = new JalviewFileChooser(
741 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
743 chooser.setFileView(new JalviewFileView());
744 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
745 chooser.setToolTipText(MessageManager.getString("action.save"));
747 int value = chooser.showSaveDialog(this);
749 if (value == JalviewFileChooser.APPROVE_OPTION)
751 BufferedReader in = null;
754 // TODO: cope with multiple PDB files in view
755 in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
756 File outFile = chooser.getSelectedFile();
758 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
760 while ((data = in.readLine()) != null)
762 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
768 } catch (Exception ex)
770 ex.printStackTrace();
778 } catch (IOException e)
788 public void viewMapping_actionPerformed(ActionEvent actionEvent)
790 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
793 cap.appendText(jmb.printMappings());
794 } catch (OutOfMemoryError e)
797 "composing sequence-structure alignments for display in text box.",
802 jalview.gui.Desktop.addInternalFrame(cap,
803 MessageManager.getString("label.pdb_sequence_mapping"), 550,
808 public void eps_actionPerformed(ActionEvent e)
812 .getString("error.eps_generation_not_implemented"));
816 public void png_actionPerformed(ActionEvent e)
820 .getString("error.png_generation_not_implemented"));
824 public void viewerColour_actionPerformed(ActionEvent actionEvent)
826 if (viewerColour.isSelected())
828 // disable automatic sequence colouring.
829 jmb.setColourBySequence(false);
834 public void seqColour_actionPerformed(ActionEvent actionEvent)
836 jmb.setColourBySequence(seqColour.isSelected());
837 if (_colourwith == null)
839 _colourwith = new Vector<AlignmentPanel>();
841 if (jmb.isColourBySequence())
843 if (!jmb.isLoadingFromArchive())
845 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
847 // Make the currently displayed alignment panel the associated view
848 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
851 // Set the colour using the current view for the associated alignframe
852 for (AlignmentPanel ap : _colourwith)
854 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
860 public void chainColour_actionPerformed(ActionEvent actionEvent)
862 chainColour.setSelected(true);
867 public void chargeColour_actionPerformed(ActionEvent actionEvent)
869 chargeColour.setSelected(true);
870 jmb.colourByCharge();
874 public void zappoColour_actionPerformed(ActionEvent actionEvent)
876 zappoColour.setSelected(true);
877 jmb.setJalviewColourScheme(new ZappoColourScheme());
881 public void taylorColour_actionPerformed(ActionEvent actionEvent)
883 taylorColour.setSelected(true);
884 jmb.setJalviewColourScheme(new TaylorColourScheme());
888 public void hydroColour_actionPerformed(ActionEvent actionEvent)
890 hydroColour.setSelected(true);
891 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
895 public void helixColour_actionPerformed(ActionEvent actionEvent)
897 helixColour.setSelected(true);
898 jmb.setJalviewColourScheme(new HelixColourScheme());
902 public void strandColour_actionPerformed(ActionEvent actionEvent)
904 strandColour.setSelected(true);
905 jmb.setJalviewColourScheme(new StrandColourScheme());
909 public void turnColour_actionPerformed(ActionEvent actionEvent)
911 turnColour.setSelected(true);
912 jmb.setJalviewColourScheme(new TurnColourScheme());
916 public void buriedColour_actionPerformed(ActionEvent actionEvent)
918 buriedColour.setSelected(true);
919 jmb.setJalviewColourScheme(new BuriedColourScheme());
923 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
925 setJalviewColourScheme(new PurinePyrimidineColourScheme());
929 public void userColour_actionPerformed(ActionEvent e)
931 if (e.getActionCommand().equals(
932 MessageManager.getString("action.user_defined")))
934 new UserDefinedColours(this, null);
938 UserColourScheme udc = UserDefinedColours.getUserColourSchemes().get(
939 e.getActionCommand());
940 jmb.setJalviewColourScheme(udc);
945 public void backGround_actionPerformed(ActionEvent actionEvent)
947 Color col = JColorChooser.showDialog(this,
948 MessageManager.getString("label.select_background_colour"),
952 jmb.setBackgroundColour(col);
957 public void showHelp_actionPerformed(ActionEvent actionEvent)
961 jalview.util.BrowserLauncher
962 .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
963 } catch (Exception ex)
968 public void updateTitleAndMenus()
970 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
975 setChainMenuItems(jmb.getChainNames());
977 this.setTitle(jmb.getViewerTitle("Chimera", true));
978 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
980 viewerActionMenu.setVisible(true);
982 if (!jmb.isLoadingFromArchive())
984 seqColour_actionPerformed(null);
992 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
996 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
998 alignStructs_withAllAlignPanels();
1001 private void alignStructs_withAllAlignPanels()
1003 if (getAlignmentPanel() == null)
1008 if (_alignwith.size() == 0)
1010 _alignwith.add(getAlignmentPanel());
1015 AlignmentI[] als = new Alignment[_alignwith.size()];
1016 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1017 int[] alm = new int[_alignwith.size()];
1020 for (AlignmentPanel ap : _alignwith)
1022 als[a] = ap.av.getAlignment();
1024 alc[a++] = ap.av.getColumnSelection();
1026 jmb.superposeStructures(als, alm, alc);
1027 } catch (Exception e)
1029 StringBuffer sp = new StringBuffer();
1030 for (AlignmentPanel ap : _alignwith)
1032 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1034 Cache.log.info("Couldn't align structures with the " + sp.toString()
1035 + "associated alignment panels.", e);
1040 public void setJalviewColourScheme(ColourSchemeI ucs)
1042 jmb.setJalviewColourScheme(ucs);
1049 * @return first alignment panel displaying given alignment, or the default
1052 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1054 for (AlignmentPanel ap : getAllAlignmentPanels())
1056 if (ap.av.getAlignment() == alignment)
1061 return getAlignmentPanel();
1065 public AAStructureBindingModel getBinding()
1071 * Ask Chimera to save its session to the designated file path, or to a
1072 * temporary file if the path is null. Returns the file path if successful,
1078 protected String saveSession(String filepath)
1080 String pathUsed = filepath;
1083 if (pathUsed == null)
1085 File tempFile = File.createTempFile("chimera", ".py");
1086 tempFile.deleteOnExit();
1087 pathUsed = tempFile.getPath();
1089 boolean result = jmb.saveSession(pathUsed);
1092 this.chimeraSessionFile = pathUsed;
1095 } catch (IOException e)
1102 * Returns a string representing the state of the Chimera session. This is
1103 * done by requesting Chimera to save its session to a temporary file, then
1104 * reading the file contents. Returns an empty string on any error.
1107 public String getStateInfo()
1109 String sessionFile = saveSession(null);
1110 if (sessionFile == null)
1114 InputStream is = null;
1117 File f = new File(sessionFile);
1118 byte[] bytes = new byte[(int) f.length()];
1119 is = new FileInputStream(sessionFile);
1121 return new String(bytes);
1122 } catch (IOException e)
1132 } catch (IOException e)
1141 protected void fitToWindow_actionPerformed()
1147 public ViewerType getViewerType()
1149 return ViewerType.CHIMERA;
1153 protected AAStructureBindingModel getBindingModel()