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",
160 { new Integer(_alignwith.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 String[][] chains = extractChains(seqs);
253 jmb = new JalviewChimeraBindingModel(this,
254 ap.getStructureSelectionManager(), pdbentrys, seqs, chains,
256 addAlignmentPanel(ap);
257 useAlignmentPanelForColourbyseq(ap);
258 if (pdbentrys.length > 1)
260 alignAddedStructures = true;
261 useAlignmentPanelForSuperposition(ap);
263 jmb.setColourBySequence(true);
264 setSize(400, 400); // probably should be a configurable/dynamic default here
267 addingStructures = false;
268 worker = new Thread(this);
271 this.addInternalFrameListener(new InternalFrameAdapter()
273 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
282 * Retrieve chains for sequences by inspecting their PDB refs. The hope is
283 * that the first will be to the sequence's own chain. Really need a more
284 * managed way of doing this.
289 protected String[][] extractChains(SequenceI[][] seqs)
291 String[][] chains = new String[seqs.length][];
292 for (int i = 0; i < seqs.length; i++)
294 chains[i] = new String[seqs[i].length];
296 for (SequenceI seq : seqs[i])
299 if (seq.getDatasetSequence() != null)
301 Vector<PDBEntry> pdbrefs = seq.getDatasetSequence().getAllPDBEntries();
302 if (pdbrefs != null && pdbrefs.size() > 0)
304 chain = pdbrefs.get(0).getChainCode();
307 chains[i][seqno++] = chain;
314 * Create a new viewer from saved session state data including Chimera session
317 * @param chimeraSessionFile
321 * @param colourByChimera
322 * @param colourBySequence
325 public ChimeraViewFrame(String chimeraSessionFile,
326 AlignmentPanel alignPanel,
328 SequenceI[][] seqsArray, boolean colourByChimera,
329 boolean colourBySequence, String newViewId)
332 setViewId(newViewId);
333 this.chimeraSessionFile = chimeraSessionFile;
334 openNewChimera(alignPanel, pdbArray, seqsArray);
337 jmb.setColourBySequence(false);
338 seqColour.setSelected(false);
339 viewerColour.setSelected(true);
341 else if (colourBySequence)
343 jmb.setColourBySequence(true);
344 seqColour.setSelected(true);
345 viewerColour.setSelected(false);
350 * create a new viewer containing several structures superimposed using the
357 public ChimeraViewFrame(PDBEntry[] pe, SequenceI[][] seqs,
361 openNewChimera(ap, pe, seqs);
364 public ChimeraViewFrame(Map<PDBEntry, List<SequenceI>> toView,
365 AlignmentPanel alignPanel)
370 * Convert the map of sequences per pdb entry into the tied arrays expected
373 * TODO pass the Map down to openNewChimera and its callees instead
375 final Set<PDBEntry> pdbEntries = toView.keySet();
376 PDBEntry[] pdbs = pdbEntries.toArray(new PDBEntry[pdbEntries.size()]);
377 SequenceI[][] seqsForPdbs = new SequenceI[pdbEntries.size()][];
378 for (int i = 0; i < pdbs.length; i++)
380 final List<SequenceI> seqsForPdb = toView.get(pdbs[i]);
381 seqsForPdbs[i] = seqsForPdb.toArray(new SequenceI[seqsForPdb.size()]);
384 openNewChimera(alignPanel, pdbs, seqsForPdbs);
388 * Returns a list of any Chimera viewers in the desktop. The list is
389 * restricted to those linked to the given alignment panel if it is not null.
392 protected List<StructureViewerBase> getViewersFor(AlignmentPanel ap)
394 List<StructureViewerBase> result = new ArrayList<StructureViewerBase>();
395 JInternalFrame[] frames = Desktop.instance.getAllFrames();
397 for (JInternalFrame frame : frames)
399 if (frame instanceof ChimeraViewFrame)
401 if (ap == null || ((StructureViewerBase) frame).isLinkedWith(ap))
403 result.add((StructureViewerBase) frame);
411 * Launch Chimera. If we have a chimera session file name, send Chimera the
412 * command to open its saved session file.
416 jmb.setFinishedInit(false);
417 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle("Chimera", true),
418 getBounds().width, getBounds().height);
420 if (!jmb.launchChimera())
425 MessageManager.getString("label.chimera_failed"),
426 MessageManager.getString("label.error_loading_file"),
427 JOptionPane.ERROR_MESSAGE);
432 if (this.chimeraSessionFile != null)
434 boolean opened = jmb.openSession(chimeraSessionFile);
438 .println("An error occurred opening Chimera session file "
439 + chimeraSessionFile);
442 jmb.setFinishedInit(true);
444 jmb.startChimeraListener();
448 * If the list is not empty, add menu items for 'All' and each individual
449 * chain to the "View | Show Chain" sub-menu. Multiple selections are allowed.
453 void setChainMenuItems(List<String> chainNames)
455 chainMenu.removeAll();
456 if (chainNames == null || chainNames.isEmpty())
460 JMenuItem menuItem = new JMenuItem(
461 MessageManager.getString("label.all"));
462 menuItem.addActionListener(new ActionListener()
464 public void actionPerformed(ActionEvent evt)
466 allChainsSelected = true;
467 for (int i = 0; i < chainMenu.getItemCount(); i++)
469 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
471 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
474 showSelectedChains();
475 allChainsSelected = false;
479 chainMenu.add(menuItem);
481 for (String chainName : chainNames)
483 menuItem = new JCheckBoxMenuItem(chainName, true);
484 menuItem.addItemListener(new ItemListener()
486 public void itemStateChanged(ItemEvent evt)
488 if (!allChainsSelected)
490 showSelectedChains();
495 chainMenu.add(menuItem);
500 * Show only the selected chain(s) in the viewer
502 void showSelectedChains()
504 List<String> toshow = new ArrayList<String>();
505 for (int i = 0; i < chainMenu.getItemCount(); i++)
507 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
509 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
510 if (item.isSelected())
512 toshow.add(item.getText());
516 jmb.showChains(toshow);
520 * Close down this instance of Jalview's Chimera viewer, giving the user the
521 * option to close the associated Chimera window (process). They may wish to
522 * keep it open until they have had an opportunity to save any work.
524 * @param closeChimera
525 * if true, close any linked Chimera process; if false, prompt first
527 public void closeViewer(boolean closeChimera)
529 if (jmb != null && jmb.isChimeraRunning())
533 String prompt = MessageManager.formatMessage(
534 "label.confirm_close_chimera", new Object[]
535 { jmb.getViewerTitle("Chimera", false) });
536 prompt = JvSwingUtils.wrapTooltip(true, prompt);
537 int confirm = JOptionPane.showConfirmDialog(this, prompt,
538 MessageManager.getString("label.close_viewer"),
539 JOptionPane.YES_NO_OPTION);
540 closeChimera = confirm == JOptionPane.YES_OPTION;
542 jmb.closeViewer(closeChimera);
544 setAlignmentPanel(null);
548 // TODO: check for memory leaks where instance isn't finalised because jmb
549 // holds a reference to the window
554 * Open any newly added PDB structures in Chimera, having first fetched data
555 * from PDB (if not already saved).
560 // todo - record which pdbids were successfully imported.
561 StringBuilder errormsgs = new StringBuilder(128);
562 StringBuilder files = new StringBuilder(128);
563 List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
564 List<Integer> filePDBpos = new ArrayList<Integer>();
565 PDBEntry thePdbEntry = null;
568 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
569 // TODO: replace with reference fetching/transfer code (validate PDBentry
571 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
574 thePdbEntry = jmb.getPdbEntry(pi);
575 if (thePdbEntry.getFile() == null)
578 * Retrieve PDB data, save to file, attach to PDBEntry
580 file = fetchPdbFile(thePdbEntry);
583 errormsgs.append("'" + thePdbEntry.getId() + "' ");
589 * Got file already - ignore if already loaded in Chimera.
591 file = new File(thePdbEntry.getFile()).getAbsoluteFile()
593 if (curfiles != null && curfiles.length > 0)
595 addingStructures = true; // already files loaded.
596 for (int c = 0; c < curfiles.length; c++)
598 if (curfiles[c].equals(file))
608 filePDB.add(thePdbEntry);
609 filePDBpos.add(Integer.valueOf(pi));
610 files.append(" \"" + Platform.escapeString(file) + "\"");
613 } catch (OutOfMemoryError oomerror)
615 new OOMWarning("Retrieving PDB files: " + thePdbEntry.getId(),
617 } catch (Exception ex)
619 ex.printStackTrace();
620 errormsgs.append("When retrieving pdbfiles for '"
621 + thePdbEntry.getId() + "'");
623 if (errormsgs.length() > 0)
626 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
627 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
629 { errormsgs.toString() }), MessageManager
630 .getString("label.couldnt_load_file"),
631 JOptionPane.ERROR_MESSAGE);
634 if (files.length() > 0)
636 if (!addingStructures)
641 } catch (Exception ex)
643 Cache.log.error("Couldn't open Chimera viewer!", ex);
647 for (PDBEntry pe : filePDB)
650 if (pe.getFile() != null)
654 int pos = filePDBpos.get(num).intValue();
655 long startTime = startProgressBar("Chimera "
656 + MessageManager.getString("status.opening_file"));
658 jmb.addSequence(pos, jmb.getSequence()[pos]);
659 File fl = new File(pe.getFile());
660 String protocol = AppletFormatAdapter.URL;
665 protocol = AppletFormatAdapter.FILE;
667 } catch (Throwable e)
671 stopProgressBar("", startTime);
673 // Explicitly map to the filename used by Chimera ;
674 jmb.getSsm().setMapping(jmb.getSequence()[pos],
675 jmb.getChains()[pos],
678 } catch (OutOfMemoryError oomerror)
681 "When trying to open and map structures from Chimera!",
683 } catch (Exception ex)
685 Cache.log.error("Couldn't open " + pe.getFile()
686 + " in Chimera viewer!", ex);
689 Cache.log.debug("File locations are " + files);
693 jmb.setFinishedInit(true);
694 jmb.setLoadingFromArchive(false);
696 // refresh the sequence colours for the new structure(s)
697 for (AlignmentPanel ap : _colourwith)
699 jmb.updateColours(ap);
701 // do superposition if asked to
702 if (alignAddedStructures)
704 new Thread(new Runnable()
708 alignStructs_withAllAlignPanels();
711 alignAddedStructures = false;
713 addingStructures = false;
720 * Fetch PDB data and save to a local file. Returns the full path to the file,
721 * or null if fetch fails.
723 * @param processingEntry
727 private String fetchPdbFile(PDBEntry processingEntry) throws Exception
729 String filePath = null;
730 Pdb pdbclient = new Pdb();
731 AlignmentI pdbseq = null;
732 String pdbid = processingEntry.getId();
733 long handle = System.currentTimeMillis()
734 + Thread.currentThread().hashCode();
737 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
739 String msg = MessageManager.formatMessage("status.fetching_pdb",
742 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
743 // long hdl = startProgressBar(MessageManager.formatMessage(
744 // "status.fetching_pdb", new Object[]
748 pdbseq = pdbclient.getSequenceRecords(pdbid);
749 } catch (OutOfMemoryError oomerror)
751 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
755 + MessageManager.getString("label.state_completed");
756 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
757 // stopProgressBar(msg, hdl);
760 * If PDB data were saved and are not invalid (empty alignment), return the
763 if (pdbseq != null && pdbseq.getHeight() > 0)
765 // just use the file name from the first sequence's first PDBEntry
766 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
767 .elementAt(0).getFile()).getAbsolutePath();
768 processingEntry.setFile(filePath);
774 * Convenience method to update the progress bar if there is one. Be sure to
775 * call stopProgressBar with the returned handle to remove the message.
780 public long startProgressBar(String msg)
782 // TODO would rather have startProgress/stopProgress as the
783 // IProgressIndicator interface
784 long tm = random.nextLong();
785 if (progressBar != null)
787 progressBar.setProgressBar(msg, tm);
793 * End the progress bar with the specified handle, leaving a message (if not
794 * null) on the status bar
799 public void stopProgressBar(String msg, long handle)
801 if (progressBar != null)
803 progressBar.setProgressBar(msg, handle);
808 public void pdbFile_actionPerformed(ActionEvent actionEvent)
810 JalviewFileChooser chooser = new JalviewFileChooser(
811 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
813 chooser.setFileView(new JalviewFileView());
814 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
815 chooser.setToolTipText(MessageManager.getString("action.save"));
817 int value = chooser.showSaveDialog(this);
819 if (value == JalviewFileChooser.APPROVE_OPTION)
821 BufferedReader in = null;
824 // TODO: cope with multiple PDB files in view
825 in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
826 File outFile = chooser.getSelectedFile();
828 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
830 while ((data = in.readLine()) != null)
832 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
838 } catch (Exception ex)
840 ex.printStackTrace();
848 } catch (IOException e)
858 public void viewMapping_actionPerformed(ActionEvent actionEvent)
860 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
863 cap.appendText(jmb.printMappings());
864 } catch (OutOfMemoryError e)
867 "composing sequence-structure alignments for display in text box.",
872 jalview.gui.Desktop.addInternalFrame(cap,
873 MessageManager.getString("label.pdb_sequence_mapping"), 550,
878 public void eps_actionPerformed(ActionEvent e)
882 .getString("error.eps_generation_not_implemented"));
886 public void png_actionPerformed(ActionEvent e)
890 .getString("error.png_generation_not_implemented"));
894 public void viewerColour_actionPerformed(ActionEvent actionEvent)
896 if (viewerColour.isSelected())
898 // disable automatic sequence colouring.
899 jmb.setColourBySequence(false);
904 public void seqColour_actionPerformed(ActionEvent actionEvent)
906 jmb.setColourBySequence(seqColour.isSelected());
907 if (_colourwith == null)
909 _colourwith = new Vector<AlignmentPanel>();
911 if (jmb.isColourBySequence())
913 if (!jmb.isLoadingFromArchive())
915 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
917 // Make the currently displayed alignment panel the associated view
918 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
921 // Set the colour using the current view for the associated alignframe
922 for (AlignmentPanel ap : _colourwith)
924 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
930 public void chainColour_actionPerformed(ActionEvent actionEvent)
932 chainColour.setSelected(true);
937 public void chargeColour_actionPerformed(ActionEvent actionEvent)
939 chargeColour.setSelected(true);
940 jmb.colourByCharge();
944 public void zappoColour_actionPerformed(ActionEvent actionEvent)
946 zappoColour.setSelected(true);
947 jmb.setJalviewColourScheme(new ZappoColourScheme());
951 public void taylorColour_actionPerformed(ActionEvent actionEvent)
953 taylorColour.setSelected(true);
954 jmb.setJalviewColourScheme(new TaylorColourScheme());
958 public void hydroColour_actionPerformed(ActionEvent actionEvent)
960 hydroColour.setSelected(true);
961 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
965 public void helixColour_actionPerformed(ActionEvent actionEvent)
967 helixColour.setSelected(true);
968 jmb.setJalviewColourScheme(new HelixColourScheme());
972 public void strandColour_actionPerformed(ActionEvent actionEvent)
974 strandColour.setSelected(true);
975 jmb.setJalviewColourScheme(new StrandColourScheme());
979 public void turnColour_actionPerformed(ActionEvent actionEvent)
981 turnColour.setSelected(true);
982 jmb.setJalviewColourScheme(new TurnColourScheme());
986 public void buriedColour_actionPerformed(ActionEvent actionEvent)
988 buriedColour.setSelected(true);
989 jmb.setJalviewColourScheme(new BuriedColourScheme());
993 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
995 setJalviewColourScheme(new PurinePyrimidineColourScheme());
999 public void userColour_actionPerformed(ActionEvent actionEvent)
1001 userColour.setSelected(true);
1002 new UserDefinedColours(this, null);
1006 public void backGround_actionPerformed(ActionEvent actionEvent)
1008 java.awt.Color col = JColorChooser
1009 .showDialog(this, MessageManager
1010 .getString("label.select_backgroud_colour"), null);
1013 jmb.setBackgroundColour(col);
1018 public void showHelp_actionPerformed(ActionEvent actionEvent)
1022 jalview.util.BrowserLauncher
1023 .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
1024 } catch (Exception ex)
1029 public void updateTitleAndMenus()
1031 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1036 setChainMenuItems(jmb.getChainNames());
1038 this.setTitle(jmb.getViewerTitle("Chimera", true));
1039 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1041 viewerActionMenu.setVisible(true);
1043 if (!jmb.isLoadingFromArchive())
1045 seqColour_actionPerformed(null);
1053 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1057 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1059 alignStructs_withAllAlignPanels();
1062 private void alignStructs_withAllAlignPanels()
1064 if (getAlignmentPanel() == null)
1069 if (_alignwith.size() == 0)
1071 _alignwith.add(getAlignmentPanel());
1076 AlignmentI[] als = new Alignment[_alignwith.size()];
1077 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1078 int[] alm = new int[_alignwith.size()];
1081 for (AlignmentPanel ap : _alignwith)
1083 als[a] = ap.av.getAlignment();
1085 alc[a++] = ap.av.getColumnSelection();
1087 jmb.superposeStructures(als, alm, alc);
1088 } catch (Exception e)
1090 StringBuffer sp = new StringBuffer();
1091 for (AlignmentPanel ap : _alignwith)
1093 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1095 Cache.log.info("Couldn't align structures with the " + sp.toString()
1096 + "associated alignment panels.", e);
1100 public void setJalviewColourScheme(ColourSchemeI ucs)
1102 jmb.setJalviewColourScheme(ucs);
1109 * @return first alignment panel displaying given alignment, or the default
1112 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1114 for (AlignmentPanel ap : getAllAlignmentPanels())
1116 if (ap.av.getAlignment() == alignment)
1121 return getAlignmentPanel();
1125 public AAStructureBindingModel getBinding()
1131 * Ask Chimera to save its session to the designated file path, or to a
1132 * temporary file if the path is null. Returns the file path if successful,
1138 protected String saveSession(String filepath)
1140 String pathUsed = filepath;
1143 if (pathUsed == null)
1145 File tempFile = File.createTempFile("chimera", ".py");
1146 tempFile.deleteOnExit();
1147 pathUsed = tempFile.getPath();
1149 boolean result = jmb.saveSession(pathUsed);
1152 this.chimeraSessionFile = pathUsed;
1155 } catch (IOException e)
1162 * Returns a string representing the state of the Chimera session. This is
1163 * done by requesting Chimera to save its session to a temporary file, then
1164 * reading the file contents. Returns an empty string on any error.
1167 public String getStateInfo()
1169 String sessionFile = saveSession(null);
1170 if (sessionFile == null)
1174 InputStream is = null;
1177 File f = new File(sessionFile);
1178 byte[] bytes = new byte[(int) f.length()];
1179 is = new FileInputStream(sessionFile);
1181 return new String(bytes);
1182 } catch (IOException e)
1192 } catch (IOException e)
1201 protected void fitToWindow_actionPerformed()
1207 public ViewerType getViewerType()
1209 return ViewerType.CHIMERA;
1213 protected AAStructureBindingModel getBindingModel()