2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.bin.Cache;
24 import jalview.datamodel.Alignment;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.ColumnSelection;
27 import jalview.datamodel.PDBEntry;
28 import jalview.datamodel.SequenceI;
29 import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
30 import jalview.gui.StructureViewer.ViewerType;
31 import jalview.io.AppletFormatAdapter;
32 import jalview.io.JalviewFileChooser;
33 import jalview.io.JalviewFileView;
34 import jalview.schemes.BuriedColourScheme;
35 import jalview.schemes.ColourSchemeI;
36 import jalview.schemes.HelixColourScheme;
37 import jalview.schemes.HydrophobicColourScheme;
38 import jalview.schemes.PurinePyrimidineColourScheme;
39 import jalview.schemes.StrandColourScheme;
40 import jalview.schemes.TaylorColourScheme;
41 import jalview.schemes.TurnColourScheme;
42 import jalview.schemes.ZappoColourScheme;
43 import jalview.structures.models.AAStructureBindingModel;
44 import jalview.util.MessageManager;
45 import jalview.util.Platform;
46 import jalview.ws.dbsources.Pdb;
48 import java.awt.event.ActionEvent;
49 import java.awt.event.ActionListener;
50 import java.awt.event.ItemEvent;
51 import java.awt.event.ItemListener;
52 import java.io.BufferedReader;
54 import java.io.FileInputStream;
55 import java.io.FileOutputStream;
56 import java.io.FileReader;
57 import java.io.IOException;
58 import java.io.InputStream;
59 import java.io.PrintWriter;
60 import java.util.ArrayList;
61 import java.util.List;
63 import java.util.Random;
65 import java.util.Vector;
67 import javax.swing.JCheckBoxMenuItem;
68 import javax.swing.JColorChooser;
69 import javax.swing.JInternalFrame;
70 import javax.swing.JMenu;
71 import javax.swing.JMenuItem;
72 import javax.swing.JOptionPane;
73 import javax.swing.event.InternalFrameAdapter;
74 import javax.swing.event.InternalFrameEvent;
75 import javax.swing.event.MenuEvent;
76 import javax.swing.event.MenuListener;
79 * GUI elements for handling an external chimera display
84 public class ChimeraViewFrame extends StructureViewerBase
86 private JalviewChimeraBinding jmb;
88 private boolean allChainsSelected = false;
90 private IProgressIndicator progressBar = null;
93 * Path to Chimera session file. This is set when an open Jalview/Chimera
94 * session is saved, or on restore from a Jalview project (if it holds the
95 * filename of any saved Chimera sessions).
97 private String chimeraSessionFile = null;
99 private Random random = new Random();
102 * Initialise menu options.
104 private void initMenus()
106 viewerActionMenu.setText(MessageManager.getString("label.chimera"));
107 viewerColour.setText(MessageManager
108 .getString("label.colour_with_chimera"));
109 viewerColour.setToolTipText(MessageManager
110 .getString("label.let_chimera_manage_structure_colours"));
111 helpItem.setText(MessageManager.getString("label.chimera_help"));
112 seqColour.setSelected(jmb.isColourBySequence());
113 viewerColour.setSelected(!jmb.isColourBySequence());
114 if (_colourwith == null)
116 _colourwith = new Vector<AlignmentPanel>();
118 if (_alignwith == null)
120 _alignwith = new Vector<AlignmentPanel>();
123 // save As not yet implemented
124 savemenu.setVisible(false);
126 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
127 MessageManager.getString("label.colour_by"), this, _colourwith,
131 public void itemStateChanged(ItemEvent e)
133 if (!seqColour.isSelected())
139 // update the Chimera display now.
140 seqColour_actionPerformed(null);
144 viewMenu.add(seqColourBy);
145 viewMenu.add(fitToWindow);
147 final ItemListener handler;
148 JMenu alpanels = new ViewSelectionMenu(
149 MessageManager.getString("label.superpose_with"), this,
150 _alignwith, handler = new ItemListener()
153 public void itemStateChanged(ItemEvent e)
155 alignStructs.setEnabled(_alignwith.size() > 0);
156 alignStructs.setToolTipText(MessageManager
158 "label.align_structures_using_linked_alignment_views",
159 new Object[] { new Integer(_alignwith
160 .size()).toString() }));
163 handler.itemStateChanged(null);
164 viewerActionMenu.add(alpanels);
165 viewerActionMenu.addMenuListener(new MenuListener()
169 public void menuSelected(MenuEvent e)
171 handler.itemStateChanged(null);
175 public void menuDeselected(MenuEvent e)
177 // TODO Auto-generated method stub
181 public void menuCanceled(MenuEvent e)
183 // TODO Auto-generated method stub
189 * add a single PDB structure to a new or existing Chimera view
196 public ChimeraViewFrame(PDBEntry pdbentry, SequenceI[] seq,
197 String[] chains, final AlignmentPanel ap)
200 String pdbId = pdbentry.getId();
203 * If the PDB file is already loaded, the user may just choose to add to an
204 * existing viewer (or cancel)
206 if (addAlreadyLoadedFile(seq, chains, ap, pdbId))
212 * Check if there are other Chimera views involving this alignment and give
213 * user the option to add and align this molecule to one of them (or cancel)
215 if (addToExistingViewer(pdbentry, seq, chains, ap, pdbId))
221 * If the options above are declined or do not apply, show the structure in
224 openNewChimera(ap, new PDBEntry[] { pdbentry },
225 new SequenceI[][] { seq });
229 * Create a helper to manage progress bar display
231 protected void createProgressBar()
233 if (progressBar == null)
235 progressBar = new ProgressBar(statusPanel, statusBar);
240 * Answers true if this viewer already involves the given PDB ID
243 protected boolean hasPdbId(String pdbId)
245 return jmb.hasPdbId(pdbId);
248 private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
252 // FIXME extractChains needs pdbentries to match IDs to PDBEntry(s) on seqs
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 // FIXME: SequenceI.PDBEntry[0] chain mapping used for
308 // ChimeraViewFrame. Is this even used ???
310 chain = pdbrefs.get(0).getChainCode();
313 chains[i][seqno++] = chain;
320 * Create a new viewer from saved session state data including Chimera session
323 * @param chimeraSessionFile
327 * @param colourByChimera
328 * @param colourBySequence
331 public ChimeraViewFrame(String chimeraSessionFile,
332 AlignmentPanel alignPanel, PDBEntry[] pdbArray,
333 SequenceI[][] seqsArray, boolean colourByChimera,
334 boolean colourBySequence, String newViewId)
337 setViewId(newViewId);
338 this.chimeraSessionFile = chimeraSessionFile;
339 openNewChimera(alignPanel, pdbArray, seqsArray);
342 jmb.setColourBySequence(false);
343 seqColour.setSelected(false);
344 viewerColour.setSelected(true);
346 else if (colourBySequence)
348 jmb.setColourBySequence(true);
349 seqColour.setSelected(true);
350 viewerColour.setSelected(false);
355 * create a new viewer containing several structures superimposed using the
362 public ChimeraViewFrame(PDBEntry[] pe, SequenceI[][] seqs,
366 openNewChimera(ap, pe, seqs);
370 * Default constructor
372 public ChimeraViewFrame()
377 * closeViewer will decide whether or not to close this frame
378 * depending on whether user chooses to Cancel or not
380 setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
384 * Returns a list of any Chimera viewers in the desktop. The list is
385 * restricted to those linked to the given alignment panel if it is not null.
388 protected List<StructureViewerBase> getViewersFor(AlignmentPanel ap)
390 List<StructureViewerBase> result = new ArrayList<StructureViewerBase>();
391 JInternalFrame[] frames = Desktop.instance.getAllFrames();
393 for (JInternalFrame frame : frames)
395 if (frame instanceof ChimeraViewFrame)
397 if (ap == null || ((StructureViewerBase) frame).isLinkedWith(ap))
399 result.add((StructureViewerBase) frame);
407 * Launch Chimera. If we have a chimera session file name, send Chimera the
408 * command to open its saved session file.
412 jmb.setFinishedInit(false);
413 jalview.gui.Desktop.addInternalFrame(this,
414 jmb.getViewerTitle("Chimera", true), getBounds().width,
417 if (!jmb.launchChimera())
419 JOptionPane.showMessageDialog(Desktop.desktop,
420 MessageManager.getString("label.chimera_failed"),
421 MessageManager.getString("label.error_loading_file"),
422 JOptionPane.ERROR_MESSAGE);
427 if (this.chimeraSessionFile != null)
429 boolean opened = jmb.openSession(chimeraSessionFile);
433 .println("An error occurred opening Chimera session file "
434 + chimeraSessionFile);
437 jmb.setFinishedInit(true);
439 jmb.startChimeraListener();
443 * If the list is not empty, add menu items for 'All' and each individual
444 * chain to the "View | Show Chain" sub-menu. Multiple selections are allowed.
448 void setChainMenuItems(List<String> chainNames)
450 chainMenu.removeAll();
451 if (chainNames == null || chainNames.isEmpty())
455 JMenuItem menuItem = new JMenuItem(
456 MessageManager.getString("label.all"));
457 menuItem.addActionListener(new ActionListener()
460 public void actionPerformed(ActionEvent evt)
462 allChainsSelected = true;
463 for (int i = 0; i < chainMenu.getItemCount(); i++)
465 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
467 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
470 showSelectedChains();
471 allChainsSelected = false;
475 chainMenu.add(menuItem);
477 for (String chainName : chainNames)
479 menuItem = new JCheckBoxMenuItem(chainName, true);
480 menuItem.addItemListener(new ItemListener()
483 public void itemStateChanged(ItemEvent evt)
485 if (!allChainsSelected)
487 showSelectedChains();
492 chainMenu.add(menuItem);
497 * Show only the selected chain(s) in the viewer
499 void showSelectedChains()
501 List<String> toshow = new ArrayList<String>();
502 for (int i = 0; i < chainMenu.getItemCount(); i++)
504 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
506 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
507 if (item.isSelected())
509 toshow.add(item.getText());
513 jmb.showChains(toshow);
517 * Close down this instance of Jalview's Chimera viewer, giving the user the
518 * option to close the associated Chimera window (process). They may wish to
519 * keep it open until they have had an opportunity to save any work.
521 * @param closeChimera
522 * if true, close any linked Chimera process; if false, prompt first
525 public void closeViewer(boolean closeChimera)
527 if (jmb != null && jmb.isChimeraRunning())
531 String prompt = MessageManager.formatMessage(
532 "label.confirm_close_chimera",
533 new Object[] { jmb.getViewerTitle("Chimera", false) });
534 prompt = JvSwingUtils.wrapTooltip(true, prompt);
535 int confirm = JOptionPane.showConfirmDialog(this, prompt,
536 MessageManager.getString("label.close_viewer"),
537 JOptionPane.YES_NO_CANCEL_OPTION);
538 if (confirm == JOptionPane.CANCEL_OPTION)
542 closeChimera = confirm == JOptionPane.YES_OPTION;
544 jmb.closeViewer(closeChimera);
546 setAlignmentPanel(null);
550 // TODO: check for memory leaks where instance isn't finalised because jmb
551 // holds a reference to the window
557 * Open any newly added PDB structures in Chimera, having first fetched data
558 * from PDB (if not already saved).
564 // todo - record which pdbids were successfully imported.
565 StringBuilder errormsgs = new StringBuilder(128);
566 StringBuilder files = new StringBuilder(128);
567 List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
568 List<Integer> filePDBpos = new ArrayList<Integer>();
569 PDBEntry thePdbEntry = null;
572 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
573 // TODO: replace with reference fetching/transfer code (validate PDBentry
575 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
578 thePdbEntry = jmb.getPdbEntry(pi);
579 if (thePdbEntry.getFile() == null)
582 * Retrieve PDB data, save to file, attach to PDBEntry
584 file = fetchPdbFile(thePdbEntry);
587 errormsgs.append("'" + thePdbEntry.getId() + "' ");
593 * Got file already - ignore if already loaded in Chimera.
595 file = new File(thePdbEntry.getFile()).getAbsoluteFile()
597 if (curfiles != null && curfiles.length > 0)
599 addingStructures = true; // already files loaded.
600 for (int c = 0; c < curfiles.length; c++)
602 if (curfiles[c].equals(file))
612 filePDB.add(thePdbEntry);
613 filePDBpos.add(Integer.valueOf(pi));
614 files.append(" \"" + Platform.escapeString(file) + "\"");
617 } catch (OutOfMemoryError oomerror)
619 new OOMWarning("Retrieving PDB files: " + thePdbEntry.getId(),
621 } catch (Exception ex)
623 ex.printStackTrace();
624 errormsgs.append("When retrieving pdbfiles for '"
625 + thePdbEntry.getId() + "'");
627 if (errormsgs.length() > 0)
630 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
631 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
632 new Object[] { errormsgs.toString() }),
633 MessageManager.getString("label.couldnt_load_file"),
634 JOptionPane.ERROR_MESSAGE);
637 if (files.length() > 0)
639 if (!addingStructures)
644 } catch (Exception ex)
646 Cache.log.error("Couldn't open Chimera viewer!", ex);
650 for (PDBEntry pe : filePDB)
653 if (pe.getFile() != null)
657 int pos = filePDBpos.get(num).intValue();
658 long startTime = startProgressBar("Chimera "
659 + MessageManager.getString("status.opening_file_for")
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 // FIXME: this is duplicated code with Jmol frame ?
733 String filePath = null;
734 Pdb pdbclient = new Pdb();
735 AlignmentI pdbseq = null;
736 String pdbid = processingEntry.getId();
737 long handle = System.currentTimeMillis()
738 + Thread.currentThread().hashCode();
741 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
743 String msg = MessageManager.formatMessage("status.fetching_pdb",
744 new Object[] { pdbid });
745 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
746 // long hdl = startProgressBar(MessageManager.formatMessage(
747 // "status.fetching_pdb", new Object[]
751 pdbseq = pdbclient.getSequenceRecords(pdbid);
752 } catch (OutOfMemoryError oomerror)
754 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
757 msg = pdbid + " " + MessageManager.getString("label.state_completed");
758 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
759 // stopProgressBar(msg, hdl);
762 * If PDB data were saved and are not invalid (empty alignment), return the
765 if (pdbseq != null && pdbseq.getHeight() > 0)
767 // just use the file name from the first sequence's first PDBEntry
768 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
769 .elementAt(0).getFile()).getAbsolutePath();
770 processingEntry.setFile(filePath);
776 * Convenience method to update the progress bar if there is one. Be sure to
777 * call stopProgressBar with the returned handle to remove the message.
782 public long startProgressBar(String msg)
784 // TODO would rather have startProgress/stopProgress as the
785 // IProgressIndicator interface
786 long tm = random.nextLong();
787 if (progressBar != null)
789 progressBar.setProgressBar(msg, tm);
795 * End the progress bar with the specified handle, leaving a message (if not
796 * null) on the status bar
801 public void stopProgressBar(String msg, long handle)
803 if (progressBar != null)
805 progressBar.setProgressBar(msg, handle);
810 public void pdbFile_actionPerformed(ActionEvent actionEvent)
812 JalviewFileChooser chooser = new JalviewFileChooser(
813 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
815 chooser.setFileView(new JalviewFileView());
816 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
817 chooser.setToolTipText(MessageManager.getString("action.save"));
819 int value = chooser.showSaveDialog(this);
821 if (value == JalviewFileChooser.APPROVE_OPTION)
823 BufferedReader in = null;
826 // TODO: cope with multiple PDB files in view
827 in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
828 File outFile = chooser.getSelectedFile();
830 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
832 while ((data = in.readLine()) != null)
834 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
840 } catch (Exception ex)
842 ex.printStackTrace();
850 } catch (IOException e)
860 public void viewMapping_actionPerformed(ActionEvent actionEvent)
862 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
865 cap.appendText(jmb.printMappings());
866 } catch (OutOfMemoryError e)
869 "composing sequence-structure alignments for display in text box.",
874 jalview.gui.Desktop.addInternalFrame(cap,
875 MessageManager.getString("label.pdb_sequence_mapping"), 550,
880 public void eps_actionPerformed(ActionEvent e)
884 .getString("error.eps_generation_not_implemented"));
888 public void png_actionPerformed(ActionEvent e)
892 .getString("error.png_generation_not_implemented"));
896 public void viewerColour_actionPerformed(ActionEvent actionEvent)
898 if (viewerColour.isSelected())
900 // disable automatic sequence colouring.
901 jmb.setColourBySequence(false);
906 public void seqColour_actionPerformed(ActionEvent actionEvent)
908 jmb.setColourBySequence(seqColour.isSelected());
909 if (_colourwith == null)
911 _colourwith = new Vector<AlignmentPanel>();
913 if (jmb.isColourBySequence())
915 if (!jmb.isLoadingFromArchive())
917 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
919 // Make the currently displayed alignment panel the associated view
920 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
923 // Set the colour using the current view for the associated alignframe
924 for (AlignmentPanel ap : _colourwith)
926 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
932 public void chainColour_actionPerformed(ActionEvent actionEvent)
934 chainColour.setSelected(true);
939 public void chargeColour_actionPerformed(ActionEvent actionEvent)
941 chargeColour.setSelected(true);
942 jmb.colourByCharge();
946 public void zappoColour_actionPerformed(ActionEvent actionEvent)
948 zappoColour.setSelected(true);
949 jmb.setJalviewColourScheme(new ZappoColourScheme());
953 public void taylorColour_actionPerformed(ActionEvent actionEvent)
955 taylorColour.setSelected(true);
956 jmb.setJalviewColourScheme(new TaylorColourScheme());
960 public void hydroColour_actionPerformed(ActionEvent actionEvent)
962 hydroColour.setSelected(true);
963 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
967 public void helixColour_actionPerformed(ActionEvent actionEvent)
969 helixColour.setSelected(true);
970 jmb.setJalviewColourScheme(new HelixColourScheme());
974 public void strandColour_actionPerformed(ActionEvent actionEvent)
976 strandColour.setSelected(true);
977 jmb.setJalviewColourScheme(new StrandColourScheme());
981 public void turnColour_actionPerformed(ActionEvent actionEvent)
983 turnColour.setSelected(true);
984 jmb.setJalviewColourScheme(new TurnColourScheme());
988 public void buriedColour_actionPerformed(ActionEvent actionEvent)
990 buriedColour.setSelected(true);
991 jmb.setJalviewColourScheme(new BuriedColourScheme());
995 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
997 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1001 public void userColour_actionPerformed(ActionEvent actionEvent)
1003 userColour.setSelected(true);
1004 new UserDefinedColours(this, null);
1008 public void backGround_actionPerformed(ActionEvent actionEvent)
1010 java.awt.Color col = JColorChooser
1011 .showDialog(this, MessageManager
1012 .getString("label.select_backgroud_colour"), null);
1015 jmb.setBackgroundColour(col);
1020 public void showHelp_actionPerformed(ActionEvent actionEvent)
1024 jalview.util.BrowserLauncher
1025 .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
1026 } catch (Exception ex)
1031 public void updateTitleAndMenus()
1033 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1038 setChainMenuItems(jmb.getChainNames());
1040 this.setTitle(jmb.getViewerTitle("Chimera", true));
1041 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1043 viewerActionMenu.setVisible(true);
1045 if (!jmb.isLoadingFromArchive())
1047 seqColour_actionPerformed(null);
1055 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1059 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1061 alignStructs_withAllAlignPanels();
1064 private void alignStructs_withAllAlignPanels()
1066 if (getAlignmentPanel() == null)
1071 if (_alignwith.size() == 0)
1073 _alignwith.add(getAlignmentPanel());
1078 AlignmentI[] als = new Alignment[_alignwith.size()];
1079 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1080 int[] alm = new int[_alignwith.size()];
1083 for (AlignmentPanel ap : _alignwith)
1085 als[a] = ap.av.getAlignment();
1087 alc[a++] = ap.av.getColumnSelection();
1089 jmb.superposeStructures(als, alm, alc);
1090 } catch (Exception e)
1092 StringBuffer sp = new StringBuffer();
1093 for (AlignmentPanel ap : _alignwith)
1095 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1097 Cache.log.info("Couldn't align structures with the " + sp.toString()
1098 + "associated alignment panels.", e);
1103 public void setJalviewColourScheme(ColourSchemeI ucs)
1105 jmb.setJalviewColourScheme(ucs);
1112 * @return first alignment panel displaying given alignment, or the default
1115 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1117 for (AlignmentPanel ap : getAllAlignmentPanels())
1119 if (ap.av.getAlignment() == alignment)
1124 return getAlignmentPanel();
1128 public AAStructureBindingModel getBinding()
1134 * Ask Chimera to save its session to the designated file path, or to a
1135 * temporary file if the path is null. Returns the file path if successful,
1141 protected String saveSession(String filepath)
1143 String pathUsed = filepath;
1146 if (pathUsed == null)
1148 File tempFile = File.createTempFile("chimera", ".py");
1149 tempFile.deleteOnExit();
1150 pathUsed = tempFile.getPath();
1152 boolean result = jmb.saveSession(pathUsed);
1155 this.chimeraSessionFile = pathUsed;
1158 } catch (IOException e)
1165 * Returns a string representing the state of the Chimera session. This is
1166 * done by requesting Chimera to save its session to a temporary file, then
1167 * reading the file contents. Returns an empty string on any error.
1170 public String getStateInfo()
1172 String sessionFile = saveSession(null);
1173 if (sessionFile == null)
1177 InputStream is = null;
1180 File f = new File(sessionFile);
1181 byte[] bytes = new byte[(int) f.length()];
1182 is = new FileInputStream(sessionFile);
1184 return new String(bytes);
1185 } catch (IOException e)
1195 } catch (IOException e)
1204 protected void fitToWindow_actionPerformed()
1210 public ViewerType getViewerType()
1212 return ViewerType.CHIMERA;
1216 protected AAStructureBindingModel getBindingModel()