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 java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25 import java.awt.event.ItemEvent;
26 import java.awt.event.ItemListener;
27 import java.io.BufferedReader;
29 import java.io.FileOutputStream;
30 import java.io.FileReader;
31 import java.io.IOException;
32 import java.io.PrintWriter;
33 import java.util.ArrayList;
34 import java.util.List;
36 import java.util.Random;
38 import java.util.Vector;
40 import javax.swing.JCheckBoxMenuItem;
41 import javax.swing.JColorChooser;
42 import javax.swing.JInternalFrame;
43 import javax.swing.JMenu;
44 import javax.swing.JMenuItem;
45 import javax.swing.JOptionPane;
46 import javax.swing.event.InternalFrameAdapter;
47 import javax.swing.event.InternalFrameEvent;
48 import javax.swing.event.MenuEvent;
49 import javax.swing.event.MenuListener;
51 import jalview.bin.Cache;
52 import jalview.datamodel.Alignment;
53 import jalview.datamodel.AlignmentI;
54 import jalview.datamodel.ColumnSelection;
55 import jalview.datamodel.PDBEntry;
56 import jalview.datamodel.SequenceI;
57 import jalview.ext.rbvi.chimera.JalviewChimeraBinding;
58 import jalview.io.AppletFormatAdapter;
59 import jalview.io.JalviewFileChooser;
60 import jalview.io.JalviewFileView;
61 import jalview.schemes.BuriedColourScheme;
62 import jalview.schemes.ColourSchemeI;
63 import jalview.schemes.HelixColourScheme;
64 import jalview.schemes.HydrophobicColourScheme;
65 import jalview.schemes.PurinePyrimidineColourScheme;
66 import jalview.schemes.StrandColourScheme;
67 import jalview.schemes.TaylorColourScheme;
68 import jalview.schemes.TurnColourScheme;
69 import jalview.schemes.ZappoColourScheme;
70 import jalview.structures.models.AAStructureBindingModel;
71 import jalview.util.MessageManager;
72 import jalview.util.Platform;
73 import jalview.ws.dbsources.Pdb;
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 boolean alignAddedStructures = false;
90 * state flag for PDB retrieval thread
92 private boolean _started = false;
94 private boolean addingStructures = false;
96 private IProgressIndicator progressBar = null;
99 * pdb retrieval thread.
101 private Thread worker = null;
104 * Path to Chimera session file. This is set when an open Jalview/Chimera
105 * session is saved, or on restore from a Jalview project (if it holds the
106 * filename of any saved Chimera sessions).
108 private String chimeraSessionFile = null;
110 private Random random = new Random();
113 * Initialise menu options.
115 private void initMenus()
117 viewerActionMenu.setText(MessageManager.getString("label.chimera"));
118 viewerColour.setText(MessageManager
119 .getString("label.colour_with_chimera"));
120 viewerColour.setToolTipText(MessageManager
121 .getString("label.let_chimera_manage_structure_colours"));
122 helpItem.setText(MessageManager.getString("label.chimera_help"));
123 seqColour.setSelected(jmb.isColourBySequence());
124 viewerColour.setSelected(!jmb.isColourBySequence());
125 if (_colourwith == null)
127 _colourwith = new Vector<AlignmentPanel>();
129 if (_alignwith == null)
131 _alignwith = new Vector<AlignmentPanel>();
134 // save As not yet implemented
135 savemenu.setVisible(false);
137 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
138 MessageManager.getString("label.colour_by"), this, _colourwith,
142 public void itemStateChanged(ItemEvent e)
144 if (!seqColour.isSelected())
150 // update the Chimera display now.
151 seqColour_actionPerformed(null);
155 viewMenu.add(seqColourBy);
156 viewMenu.add(fitToWindow);
158 final ItemListener handler;
159 JMenu alpanels = new ViewSelectionMenu(
160 MessageManager.getString("label.superpose_with"), this,
161 _alignwith, handler = new ItemListener()
164 public void itemStateChanged(ItemEvent e)
166 alignStructs.setEnabled(_alignwith.size() > 0);
167 alignStructs.setToolTipText(MessageManager
169 "label.align_structures_using_linked_alignment_views",
171 { new Integer(_alignwith.size()).toString() }));
174 handler.itemStateChanged(null);
175 viewerActionMenu.add(alpanels);
176 viewerActionMenu.addMenuListener(new MenuListener()
180 public void menuSelected(MenuEvent e)
182 handler.itemStateChanged(null);
186 public void menuDeselected(MenuEvent e)
188 // TODO Auto-generated method stub
192 public void menuCanceled(MenuEvent e)
194 // TODO Auto-generated method stub
200 * add a single PDB structure to a new or existing Chimera view
207 public ChimeraViewFrame(PDBEntry pdbentry, SequenceI[] seq,
208 String[] chains, final AlignmentPanel ap)
213 * is the pdb file already loaded?
215 String pdbId = pdbentry.getId();
216 String alreadyMapped = ap.getStructureSelectionManager()
217 .alreadyMappedToFile(pdbId);
219 if (alreadyMapped != null)
221 int option = chooseAddSequencesToViewer(pdbId);
222 if (option == JOptionPane.CANCEL_OPTION)
226 if (option == JOptionPane.YES_OPTION)
228 addSequenceMappingsToStructure(seq, chains, ap, alreadyMapped);
234 * Check if there are other Chimera views involving this alignment and give
235 * user the option to add and align this molecule to one of them
237 List<ChimeraViewFrame> existingViews = getChimeraWindowsFor(ap);
238 for (ChimeraViewFrame view : existingViews)
240 // TODO: highlight view somehow
242 * JAL-1742 exclude view with this structure already mapped (don't offer
243 * to align chain B to chain A of the same structure)
245 if (view.hasPdbId(pdbId))
249 int option = chooseAlignStructureToViewer(pdbId, view);
250 if (option == JOptionPane.CANCEL_OPTION)
254 if (option == JOptionPane.YES_OPTION)
256 view.useAlignmentPanelForSuperposition(ap);
257 view.addStructure(pdbentry, seq, chains, true, ap.alignFrame);
263 * If the options above are declined or do not apply, open a new viewer
265 openNewChimera(ap, new PDBEntry[]
266 { pdbentry }, new SequenceI[][]
271 * Presents a dialog with the option to add an align a structure to an
272 * existing Chimera view
276 * @return YES, NO or CANCEL JOptionPane code
278 protected int chooseAlignStructureToViewer(String pdbId,
279 ChimeraViewFrame view)
281 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
282 MessageManager.formatMessage("label.add_pdbentry_to_view",
284 { pdbId, view.getTitle() }), MessageManager
285 .getString("label.align_to_existing_structure_view"),
286 JOptionPane.YES_NO_CANCEL_OPTION);
291 * Presents a dialog with the option to add sequences to a viewer which
292 * already has their structure open
295 * @return YES, NO or CANCEL JOptionPane code
297 protected int chooseAddSequencesToViewer(String pdbId)
299 int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
300 MessageManager.formatMessage(
301 "label.pdb_entry_is_already_displayed", new Object[]
302 { pdbId }), MessageManager.formatMessage(
303 "label.map_sequences_to_visible_window", new Object[]
304 { pdbId }), JOptionPane.YES_NO_CANCEL_OPTION);
309 * Adds mappings for the given sequences to an already opened PDB structure,
310 * and updates any viewers that have the PDB file
317 protected void addSequenceMappingsToStructure(SequenceI[] seq,
318 String[] chains, final AlignmentPanel ap, String pdbFilename)
320 // TODO : Fix multiple seq to one chain issue here.
322 * create the mappings
324 ap.getStructureSelectionManager().setMapping(seq, chains, pdbFilename,
325 AppletFormatAdapter.FILE);
328 * alert the FeatureRenderer to show new (PDB RESNUM) features
330 if (ap.getSeqPanel().seqCanvas.fr != null)
332 ap.getSeqPanel().seqCanvas.fr.featuresAdded();
333 ap.paintAlignment(true);
337 * add the sequences to any other Chimera viewers for this pdb file
339 // JBPNOTE: this looks like a binding routine, rather than a gui routine
340 for (JInternalFrame frame : Desktop.instance.getAllFrames())
342 if (frame instanceof ChimeraViewFrame)
344 ChimeraViewFrame chimeraView = ((ChimeraViewFrame) frame);
345 for (int pe = 0; pe < chimeraView.jmb.getPdbCount(); pe++)
347 if (chimeraView.jmb.getPdbEntry(pe).getFile().equals(pdbFilename))
349 chimeraView.jmb.addSequence(pe, seq);
350 chimeraView.addAlignmentPanel(ap);
352 * add it to the set of alignments used for colouring structure by
355 chimeraView.useAlignmentPanelForColourbyseq(ap);
356 chimeraView.buildActionMenu();
357 ap.getStructureSelectionManager().sequenceColoursChanged(ap);
366 * Create a helper to manage progress bar display
368 protected void createProgressBar()
370 if (progressBar == null)
372 progressBar = new ProgressBar(statusPanel, statusBar);
376 protected boolean hasPdbId(String pdbId)
378 return jmb.hasPdbId(pdbId);
381 private void openNewChimera(AlignmentPanel ap, PDBEntry[] pdbentrys,
385 String[][] chains = extractChains(seqs);
386 jmb = new JalviewChimeraBindingModel(this,
387 ap.getStructureSelectionManager(), pdbentrys, seqs, chains,
389 addAlignmentPanel(ap);
390 useAlignmentPanelForColourbyseq(ap);
391 if (pdbentrys.length > 1)
393 alignAddedStructures = true;
394 useAlignmentPanelForSuperposition(ap);
396 jmb.setColourBySequence(true);
397 setSize(400, 400); // probably should be a configurable/dynamic default here
400 addingStructures = false;
401 worker = new Thread(this);
404 this.addInternalFrameListener(new InternalFrameAdapter()
406 public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
415 * Retrieve chains for sequences by inspecting their PDB refs. The hope is
416 * that the first will be to the sequence's own chain. Really need a more
417 * managed way of doing this.
422 protected String[][] extractChains(SequenceI[][] seqs)
424 String[][] chains = new String[seqs.length][];
425 for (int i = 0; i < seqs.length; i++)
427 chains[i] = new String[seqs[i].length];
429 for (SequenceI seq : seqs[i])
432 if (seq.getDatasetSequence() != null)
434 Vector<PDBEntry> pdbrefs = seq.getDatasetSequence().getPDBId();
435 if (pdbrefs != null && pdbrefs.size() > 0)
437 chain = pdbrefs.get(0).getChainCode();
440 chains[i][seqno++] = chain;
447 * Create a new viewer from saved session state data including Chimera session
450 * @param chimeraSession
455 * @param colourByChimera
456 * @param colourBySequence
458 public ChimeraViewFrame(String chimeraSession, AlignmentPanel alignPanel,
460 SequenceI[][] seqsArray, boolean colourByChimera,
461 boolean colourBySequence)
464 this.chimeraSessionFile = chimeraSession;
465 openNewChimera(alignPanel, pdbArray, seqsArray);
468 jmb.setColourBySequence(false);
469 seqColour.setSelected(false);
470 viewerColour.setSelected(true);
472 else if (colourBySequence)
474 jmb.setColourBySequence(true);
475 seqColour.setSelected(true);
476 viewerColour.setSelected(false);
481 * create a new viewer containing several structures superimposed using the
488 public ChimeraViewFrame(PDBEntry[] pe, SequenceI[][] seqs,
492 openNewChimera(ap, pe, seqs);
495 public ChimeraViewFrame(Map<PDBEntry, List<SequenceI>> toView,
496 AlignmentPanel alignPanel)
501 * Convert the map of sequences per pdb entry into the tied arrays expected
504 * TODO pass the Map down to openNewChimera and its callees instead
506 final Set<PDBEntry> pdbEntries = toView.keySet();
507 PDBEntry[] pdbs = pdbEntries.toArray(new PDBEntry[pdbEntries.size()]);
508 SequenceI[][] seqsForPdbs = new SequenceI[pdbEntries.size()][];
509 for (int i = 0; i < pdbs.length; i++)
511 final List<SequenceI> seqsForPdb = toView.get(pdbs[i]);
512 seqsForPdbs[i] = seqsForPdb.toArray(new SequenceI[seqsForPdb.size()]);
515 openNewChimera(alignPanel, pdbs, seqsForPdbs);
519 * add a new structure (with associated sequences and chains) to this viewer,
520 * retrieving it if necessary first.
527 * if true, new structure(s) will be align using associated alignment
529 private void addStructure(final PDBEntry pdbentry, final SequenceI[] seq,
530 final String[] chains, final boolean b,
531 final IProgressIndicator alignFrame)
533 if (pdbentry.getFile() == null)
535 if (worker != null && worker.isAlive())
537 // a retrieval is in progress, wait around and add ourselves to the
539 new Thread(new Runnable()
543 while (worker != null && worker.isAlive() && _started)
547 Thread.sleep(100 + ((int) Math.random() * 100));
549 } catch (Exception e)
554 // and call ourselves again.
555 addStructure(pdbentry, seq, chains, b, alignFrame);
561 // otherwise, start adding the structure.
562 jmb.addSequenceAndChain(new PDBEntry[]
563 { pdbentry }, new SequenceI[][]
564 { seq }, new String[][]
566 addingStructures = true;
568 alignAddedStructures = b;
569 // progressBar = alignFrame; // visual indication happens on caller frame.
570 (worker = new Thread(this)).start();
574 private List<ChimeraViewFrame> getChimeraWindowsFor(AlignmentPanel apanel)
576 List<ChimeraViewFrame> result = new ArrayList<ChimeraViewFrame>();
577 JInternalFrame[] frames = Desktop.instance.getAllFrames();
579 for (JInternalFrame frame : frames)
581 if (frame instanceof ChimeraViewFrame)
583 if (((StructureViewerBase) frame).isLinkedWith(apanel))
585 result.add((ChimeraViewFrame) frame);
593 * Launch Chimera. If we have a chimera session file name, send Chimera the
594 * command to open its saved session file.
598 jmb.setFinishedInit(false);
599 jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle("Chimera", true),
600 getBounds().width, getBounds().height);
602 if (!jmb.launchChimera())
607 MessageManager.getString("label.chimera_failed"),
608 MessageManager.getString("label.error_loading_file"),
609 JOptionPane.ERROR_MESSAGE);
614 if (this.chimeraSessionFile != null)
616 boolean opened = jmb.openSession(chimeraSessionFile);
620 .println("An error occurred opening Chimera session file "
621 + chimeraSessionFile);
624 jmb.setFinishedInit(true);
626 jmb.startChimeraListener();
630 * If the list is not empty, add menu items for 'All' and each individual
631 * chain to the "View | Show Chain" sub-menu. Multiple selections are allowed.
635 void setChainMenuItems(List<String> chainNames)
637 chainMenu.removeAll();
638 if (chainNames == null || chainNames.isEmpty())
642 JMenuItem menuItem = new JMenuItem(
643 MessageManager.getString("label.all"));
644 menuItem.addActionListener(new ActionListener()
646 public void actionPerformed(ActionEvent evt)
648 allChainsSelected = true;
649 for (int i = 0; i < chainMenu.getItemCount(); i++)
651 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
653 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
656 showSelectedChains();
657 allChainsSelected = false;
661 chainMenu.add(menuItem);
663 for (String chainName : chainNames)
665 menuItem = new JCheckBoxMenuItem(chainName, true);
666 menuItem.addItemListener(new ItemListener()
668 public void itemStateChanged(ItemEvent evt)
670 if (!allChainsSelected)
672 showSelectedChains();
677 chainMenu.add(menuItem);
682 * Show only the selected chain(s) in the viewer
684 void showSelectedChains()
686 List<String> toshow = new ArrayList<String>();
687 for (int i = 0; i < chainMenu.getItemCount(); i++)
689 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
691 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
692 if (item.isSelected())
694 toshow.add(item.getText());
698 jmb.showChains(toshow);
702 * Close down this instance of Jalview's Chimera viewer, giving the user the
703 * option to close the associated Chimera window (process). They may wish to
704 * keep it open until they have had an opportunity to save any work.
706 * @param closeChimera
707 * if true, close any linked Chimera process; if false, prompt first
709 public void closeViewer(boolean closeChimera)
711 if (jmb.isChimeraRunning())
715 String prompt = MessageManager.formatMessage(
716 "label.confirm_close_chimera", new Object[]
717 { jmb.getViewerTitle("Chimera", false) });
718 prompt = JvSwingUtils.wrapTooltip(true, prompt);
719 int confirm = JOptionPane.showConfirmDialog(this, prompt,
720 MessageManager.getString("label.close_viewer"),
721 JOptionPane.YES_NO_OPTION);
722 closeChimera = confirm == JOptionPane.YES_OPTION;
724 jmb.closeViewer(closeChimera);
726 setAlignmentPanel(null);
730 // TODO: check for memory leaks where instance isn't finalised because jmb
731 // holds a reference to the window
736 * Open any newly added PDB structures in Chimera, having first fetched data
737 * from PDB (if not already saved).
742 // todo - record which pdbids were successfully imported.
743 StringBuilder errormsgs = new StringBuilder(128);
744 StringBuilder files = new StringBuilder(128);
745 List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
746 List<Integer> filePDBpos = new ArrayList<Integer>();
747 PDBEntry thePdbEntry = null;
750 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
751 // TODO: replace with reference fetching/transfer code (validate PDBentry
753 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
756 thePdbEntry = jmb.getPdbEntry(pi);
757 if (thePdbEntry.getFile() == null)
760 * Retrieve PDB data, save to file, attach to PDBEntry
762 file = fetchPdbFile(thePdbEntry);
765 errormsgs.append("'" + thePdbEntry.getId() + "' ");
771 * Got file already - ignore if already loaded in Chimera.
773 file = new File(thePdbEntry.getFile()).getAbsoluteFile()
775 if (curfiles != null && curfiles.length > 0)
777 addingStructures = true; // already files loaded.
778 for (int c = 0; c < curfiles.length; c++)
780 if (curfiles[c].equals(file))
790 filePDB.add(thePdbEntry);
791 filePDBpos.add(Integer.valueOf(pi));
792 files.append(" \"" + Platform.escapeString(file) + "\"");
795 } catch (OutOfMemoryError oomerror)
797 new OOMWarning("Retrieving PDB files: " + thePdbEntry.getId(),
799 } catch (Exception ex)
801 ex.printStackTrace();
802 errormsgs.append("When retrieving pdbfiles for '"
803 + thePdbEntry.getId() + "'");
805 if (errormsgs.length() > 0)
808 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
809 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
811 { errormsgs.toString() }), MessageManager
812 .getString("label.couldnt_load_file"),
813 JOptionPane.ERROR_MESSAGE);
816 if (files.length() > 0)
818 if (!addingStructures)
823 } catch (Exception ex)
825 Cache.log.error("Couldn't open Chimera viewer!", ex);
829 for (PDBEntry pe : filePDB)
832 if (pe.getFile() != null)
836 int pos = filePDBpos.get(num).intValue();
837 long startTime = startProgressBar("Chimera "
838 + MessageManager.getString("status.opening_file"));
840 jmb.addSequence(pos, jmb.getSequence()[pos]);
841 File fl = new File(pe.getFile());
842 String protocol = AppletFormatAdapter.URL;
847 protocol = AppletFormatAdapter.FILE;
849 } catch (Throwable e)
853 stopProgressBar("", startTime);
855 // Explicitly map to the filename used by Chimera ;
856 jmb.getSsm().setMapping(jmb.getSequence()[pos],
857 jmb.getChains()[pos],
860 } catch (OutOfMemoryError oomerror)
863 "When trying to open and map structures from Chimera!",
865 } catch (Exception ex)
867 Cache.log.error("Couldn't open " + pe.getFile()
868 + " in Chimera viewer!", ex);
871 Cache.log.debug("File locations are " + files);
875 jmb.setFinishedInit(true);
876 jmb.setLoadingFromArchive(false);
878 // refresh the sequence colours for the new structure(s)
879 for (AlignmentPanel ap : _colourwith)
881 jmb.updateColours(ap);
883 // do superposition if asked to
884 if (alignAddedStructures)
886 new Thread(new Runnable()
890 alignStructs_withAllAlignPanels();
893 alignAddedStructures = false;
895 addingStructures = false;
902 * Fetch PDB data and save to a local file. Returns the full path to the file,
903 * or null if fetch fails.
905 * @param processingEntry
909 private String fetchPdbFile(PDBEntry processingEntry) throws Exception
911 String filePath = null;
912 Pdb pdbclient = new Pdb();
913 AlignmentI pdbseq = null;
914 String pdbid = processingEntry.getId();
915 long handle = System.currentTimeMillis()
916 + Thread.currentThread().hashCode();
919 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
921 String msg = MessageManager.formatMessage("status.fetching_pdb",
924 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
925 // long hdl = startProgressBar(MessageManager.formatMessage(
926 // "status.fetching_pdb", new Object[]
930 pdbseq = pdbclient.getSequenceRecords(pdbid);
931 } catch (OutOfMemoryError oomerror)
933 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
937 + MessageManager.getString("label.state_completed");
938 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
939 // stopProgressBar(msg, hdl);
942 * If PDB data were saved and are not invalid (empty alignment), return the
945 if (pdbseq != null && pdbseq.getHeight() > 0)
947 // just use the file name from the first sequence's first PDBEntry
948 filePath = new File(pdbseq.getSequenceAt(0).getPDBId()
949 .elementAt(0).getFile()).getAbsolutePath();
950 processingEntry.setFile(filePath);
956 * Convenience method to update the progress bar if there is one. Be sure to
957 * call stopProgressBar with the returned handle to remove the message.
962 public long startProgressBar(String msg)
964 // TODO would rather have startProgress/stopProgress as the
965 // IProgressIndicator interface
966 long tm = random.nextLong();
967 if (progressBar != null)
969 progressBar.setProgressBar(msg, tm);
975 * End the progress bar with the specified handle, leaving a message (if not
976 * null) on the status bar
981 public void stopProgressBar(String msg, long handle)
983 if (progressBar != null)
985 progressBar.setProgressBar(msg, handle);
990 public void pdbFile_actionPerformed(ActionEvent actionEvent)
992 JalviewFileChooser chooser = new JalviewFileChooser(
993 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
995 chooser.setFileView(new JalviewFileView());
996 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
997 chooser.setToolTipText(MessageManager.getString("action.save"));
999 int value = chooser.showSaveDialog(this);
1001 if (value == JalviewFileChooser.APPROVE_OPTION)
1003 BufferedReader in = null;
1006 // TODO: cope with multiple PDB files in view
1007 in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
1008 File outFile = chooser.getSelectedFile();
1010 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
1012 while ((data = in.readLine()) != null)
1014 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
1020 } catch (Exception ex)
1022 ex.printStackTrace();
1030 } catch (IOException e)
1032 e.printStackTrace();
1040 public void viewMapping_actionPerformed(ActionEvent actionEvent)
1042 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
1045 cap.appendText(jmb.printMappings());
1046 } catch (OutOfMemoryError e)
1049 "composing sequence-structure alignments for display in text box.",
1054 jalview.gui.Desktop.addInternalFrame(cap,
1055 MessageManager.getString("label.pdb_sequence_mapping"), 550,
1060 public void eps_actionPerformed(ActionEvent e)
1064 .getString("error.eps_generation_not_implemented"));
1068 public void png_actionPerformed(ActionEvent e)
1072 .getString("error.png_generation_not_implemented"));
1076 public void viewerColour_actionPerformed(ActionEvent actionEvent)
1078 if (viewerColour.isSelected())
1080 // disable automatic sequence colouring.
1081 jmb.setColourBySequence(false);
1086 public void seqColour_actionPerformed(ActionEvent actionEvent)
1088 jmb.setColourBySequence(seqColour.isSelected());
1089 if (_colourwith == null)
1091 _colourwith = new Vector<AlignmentPanel>();
1093 if (jmb.isColourBySequence())
1095 if (!jmb.isLoadingFromArchive())
1097 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
1099 // Make the currently displayed alignment panel the associated view
1100 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
1103 // Set the colour using the current view for the associated alignframe
1104 for (AlignmentPanel ap : _colourwith)
1106 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
1112 public void chainColour_actionPerformed(ActionEvent actionEvent)
1114 chainColour.setSelected(true);
1115 jmb.colourByChain();
1119 public void chargeColour_actionPerformed(ActionEvent actionEvent)
1121 chargeColour.setSelected(true);
1122 jmb.colourByCharge();
1126 public void zappoColour_actionPerformed(ActionEvent actionEvent)
1128 zappoColour.setSelected(true);
1129 jmb.setJalviewColourScheme(new ZappoColourScheme());
1133 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1135 taylorColour.setSelected(true);
1136 jmb.setJalviewColourScheme(new TaylorColourScheme());
1140 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1142 hydroColour.setSelected(true);
1143 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1147 public void helixColour_actionPerformed(ActionEvent actionEvent)
1149 helixColour.setSelected(true);
1150 jmb.setJalviewColourScheme(new HelixColourScheme());
1154 public void strandColour_actionPerformed(ActionEvent actionEvent)
1156 strandColour.setSelected(true);
1157 jmb.setJalviewColourScheme(new StrandColourScheme());
1161 public void turnColour_actionPerformed(ActionEvent actionEvent)
1163 turnColour.setSelected(true);
1164 jmb.setJalviewColourScheme(new TurnColourScheme());
1168 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1170 buriedColour.setSelected(true);
1171 jmb.setJalviewColourScheme(new BuriedColourScheme());
1175 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1177 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1181 public void userColour_actionPerformed(ActionEvent actionEvent)
1183 userColour.setSelected(true);
1184 new UserDefinedColours(this, null);
1188 public void backGround_actionPerformed(ActionEvent actionEvent)
1190 java.awt.Color col = JColorChooser
1191 .showDialog(this, MessageManager
1192 .getString("label.select_backgroud_colour"), null);
1195 jmb.setBackgroundColour(col);
1200 public void showHelp_actionPerformed(ActionEvent actionEvent)
1204 jalview.util.BrowserLauncher
1205 .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
1206 } catch (Exception ex)
1211 public void updateTitleAndMenus()
1213 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1218 setChainMenuItems(jmb.getChainNames());
1220 this.setTitle(jmb.getViewerTitle("Chimera", true));
1221 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1223 viewerActionMenu.setVisible(true);
1225 if (!jmb.isLoadingFromArchive())
1227 seqColour_actionPerformed(null);
1235 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1239 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1241 alignStructs_withAllAlignPanels();
1244 private void alignStructs_withAllAlignPanels()
1246 if (getAlignmentPanel() == null)
1251 if (_alignwith.size() == 0)
1253 _alignwith.add(getAlignmentPanel());
1258 AlignmentI[] als = new Alignment[_alignwith.size()];
1259 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1260 int[] alm = new int[_alignwith.size()];
1263 for (AlignmentPanel ap : _alignwith)
1265 als[a] = ap.av.getAlignment();
1267 alc[a++] = ap.av.getColumnSelection();
1269 jmb.superposeStructures(als, alm, alc);
1270 } catch (Exception e)
1272 StringBuffer sp = new StringBuffer();
1273 for (AlignmentPanel ap : _alignwith)
1275 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1277 Cache.log.info("Couldn't align structures with the " + sp.toString()
1278 + "associated alignment panels.", e);
1282 public void setJalviewColourScheme(ColourSchemeI ucs)
1284 jmb.setJalviewColourScheme(ucs);
1291 * @return first alignment panel displaying given alignment, or the default
1294 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1296 for (AlignmentPanel ap : getAllAlignmentPanels())
1298 if (ap.av.getAlignment() == alignment)
1303 return getAlignmentPanel();
1307 public AAStructureBindingModel getBinding()
1313 * Ask Chimera to save its session to the designated file path. Returns true
1314 * if successful, else false.
1319 public boolean saveSession(String filepath)
1321 boolean result = jmb.saveSession(filepath);
1324 this.chimeraSessionFile = filepath;
1330 * Returns the file path of the Chimera session file the last time it was
1331 * saved. If it was never saved, returns an empty string. There is no
1332 * guarantee that the Chimera session has not changed since it was saved.
1335 public String getStateInfo()
1337 return this.chimeraSessionFile == null ? "" : chimeraSessionFile;
1341 protected void fitToWindow_actionPerformed()