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);
604 if (this.chimeraSessionFile != null)
606 boolean opened = jmb.openSession(chimeraSessionFile);
610 .println("An error occurred opening Chimera session file "
611 + chimeraSessionFile);
614 jmb.setFinishedInit(true);
616 jmb.startChimeraListener();
620 * If the list is not empty, add menu items for 'All' and each individual
621 * chain to the "View | Show Chain" sub-menu. Multiple selections are allowed.
625 void setChainMenuItems(List<String> chainNames)
627 chainMenu.removeAll();
628 if (chainNames == null || chainNames.isEmpty())
632 JMenuItem menuItem = new JMenuItem(
633 MessageManager.getString("label.all"));
634 menuItem.addActionListener(new ActionListener()
636 public void actionPerformed(ActionEvent evt)
638 allChainsSelected = true;
639 for (int i = 0; i < chainMenu.getItemCount(); i++)
641 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
643 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
646 showSelectedChains();
647 allChainsSelected = false;
651 chainMenu.add(menuItem);
653 for (String chainName : chainNames)
655 menuItem = new JCheckBoxMenuItem(chainName, true);
656 menuItem.addItemListener(new ItemListener()
658 public void itemStateChanged(ItemEvent evt)
660 if (!allChainsSelected)
662 showSelectedChains();
667 chainMenu.add(menuItem);
672 * Show only the selected chain(s) in the viewer
674 void showSelectedChains()
676 List<String> toshow = new ArrayList<String>();
677 for (int i = 0; i < chainMenu.getItemCount(); i++)
679 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
681 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
682 if (item.isSelected())
684 toshow.add(item.getText());
688 jmb.showChains(toshow);
692 * Close down this instance of Jalview's Chimera viewer, giving the user the
693 * option to close the associated Chimera window (process). They may wish to
694 * keep it open until they have had an opportunity to save any work.
696 * @param closeChimera
697 * if true, close any linked Chimera process; if false, prompt first
699 public void closeViewer(boolean closeChimera)
701 if (jmb.isChimeraRunning())
705 String prompt = MessageManager.formatMessage(
706 "label.confirm_close_chimera", new Object[]
707 { jmb.getViewerTitle("Chimera", false) });
708 prompt = JvSwingUtils.wrapTooltip(true, prompt);
709 int confirm = JOptionPane.showConfirmDialog(this, prompt,
710 MessageManager.getString("label.close_viewer"),
711 JOptionPane.YES_NO_OPTION);
712 closeChimera = confirm == JOptionPane.YES_OPTION;
714 jmb.closeViewer(closeChimera);
716 setAlignmentPanel(null);
720 // TODO: check for memory leaks where instance isn't finalised because jmb
721 // holds a reference to the window
726 * Open any newly added PDB structures in Chimera, having first fetched data
727 * from PDB (if not already saved).
732 // todo - record which pdbids were successfully imported.
733 StringBuilder errormsgs = new StringBuilder(128);
734 StringBuilder files = new StringBuilder(128);
735 List<PDBEntry> filePDB = new ArrayList<PDBEntry>();
736 List<Integer> filePDBpos = new ArrayList<Integer>();
737 PDBEntry thePdbEntry = null;
740 String[] curfiles = jmb.getPdbFile(); // files currently in viewer
741 // TODO: replace with reference fetching/transfer code (validate PDBentry
743 for (int pi = 0; pi < jmb.getPdbCount(); pi++)
746 thePdbEntry = jmb.getPdbEntry(pi);
747 if (thePdbEntry.getFile() == null)
750 * Retrieve PDB data, save to file, attach to PDBEntry
752 file = fetchPdbFile(thePdbEntry);
755 errormsgs.append("'" + thePdbEntry.getId() + "' ");
761 * Got file already - ignore if already loaded in Chimera.
763 file = new File(thePdbEntry.getFile()).getAbsoluteFile()
765 if (curfiles != null && curfiles.length > 0)
767 addingStructures = true; // already files loaded.
768 for (int c = 0; c < curfiles.length; c++)
770 if (curfiles[c].equals(file))
780 filePDB.add(thePdbEntry);
781 filePDBpos.add(Integer.valueOf(pi));
782 files.append(" \"" + Platform.escapeString(file) + "\"");
785 } catch (OutOfMemoryError oomerror)
787 new OOMWarning("Retrieving PDB files: " + thePdbEntry.getId(),
789 } catch (Exception ex)
791 ex.printStackTrace();
792 errormsgs.append("When retrieving pdbfiles for '"
793 + thePdbEntry.getId() + "'");
795 if (errormsgs.length() > 0)
798 JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
799 .formatMessage("label.pdb_entries_couldnt_be_retrieved",
801 { errormsgs.toString() }), MessageManager
802 .getString("label.couldnt_load_file"),
803 JOptionPane.ERROR_MESSAGE);
806 if (files.length() > 0)
808 if (!addingStructures)
813 } catch (Exception ex)
815 Cache.log.error("Couldn't open Chimera viewer!", ex);
819 for (PDBEntry pe : filePDB)
822 if (pe.getFile() != null)
826 int pos = filePDBpos.get(num).intValue();
827 long startTime = startProgressBar("Chimera "
828 + MessageManager.getString("status.opening_file"));
830 jmb.addSequence(pos, jmb.getSequence()[pos]);
831 File fl = new File(pe.getFile());
832 String protocol = AppletFormatAdapter.URL;
837 protocol = AppletFormatAdapter.FILE;
839 } catch (Throwable e)
843 stopProgressBar("", startTime);
845 // Explicitly map to the filename used by Chimera ;
846 jmb.getSsm().setMapping(jmb.getSequence()[pos],
847 jmb.getChains()[pos],
850 } catch (OutOfMemoryError oomerror)
853 "When trying to open and map structures from Chimera!",
855 } catch (Exception ex)
857 Cache.log.error("Couldn't open " + pe.getFile()
858 + " in Chimera viewer!", ex);
861 Cache.log.debug("File locations are " + files);
865 jmb.setFinishedInit(true);
866 jmb.setLoadingFromArchive(false);
868 // refresh the sequence colours for the new structure(s)
869 for (AlignmentPanel ap : _colourwith)
871 jmb.updateColours(ap);
873 // do superposition if asked to
874 if (alignAddedStructures)
876 new Thread(new Runnable()
880 alignStructs_withAllAlignPanels();
883 alignAddedStructures = false;
885 addingStructures = false;
892 * Fetch PDB data and save to a local file. Returns the full path to the file,
893 * or null if fetch fails.
895 * @param processingEntry
899 private String fetchPdbFile(PDBEntry processingEntry) throws Exception
901 String filePath = null;
902 Pdb pdbclient = new Pdb();
903 AlignmentI pdbseq = null;
904 String pdbid = processingEntry.getId();
905 long handle = System.currentTimeMillis()
906 + Thread.currentThread().hashCode();
909 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
911 String msg = MessageManager.formatMessage("status.fetching_pdb",
914 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
915 // long hdl = startProgressBar(MessageManager.formatMessage(
916 // "status.fetching_pdb", new Object[]
920 pdbseq = pdbclient.getSequenceRecords(pdbid);
921 } catch (OutOfMemoryError oomerror)
923 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
927 + MessageManager.getString("label.state_completed");
928 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
929 // stopProgressBar(msg, hdl);
932 * If PDB data were saved and are not invalid (empty alignment), return the
935 if (pdbseq != null && pdbseq.getHeight() > 0)
937 // just use the file name from the first sequence's first PDBEntry
938 filePath = new File(pdbseq.getSequenceAt(0).getPDBId()
939 .elementAt(0).getFile()).getAbsolutePath();
940 processingEntry.setFile(filePath);
946 * Convenience method to update the progress bar if there is one. Be sure to
947 * call stopProgressBar with the returned handle to remove the message.
952 public long startProgressBar(String msg)
954 // TODO would rather have startProgress/stopProgress as the
955 // IProgressIndicator interface
956 long tm = random.nextLong();
957 if (progressBar != null)
959 progressBar.setProgressBar(msg, tm);
965 * End the progress bar with the specified handle, leaving a message (if not
966 * null) on the status bar
971 public void stopProgressBar(String msg, long handle)
973 if (progressBar != null)
975 progressBar.setProgressBar(msg, handle);
980 public void pdbFile_actionPerformed(ActionEvent actionEvent)
982 JalviewFileChooser chooser = new JalviewFileChooser(
983 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
985 chooser.setFileView(new JalviewFileView());
986 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
987 chooser.setToolTipText(MessageManager.getString("action.save"));
989 int value = chooser.showSaveDialog(this);
991 if (value == JalviewFileChooser.APPROVE_OPTION)
993 BufferedReader in = null;
996 // TODO: cope with multiple PDB files in view
997 in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
998 File outFile = chooser.getSelectedFile();
1000 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
1002 while ((data = in.readLine()) != null)
1004 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
1010 } catch (Exception ex)
1012 ex.printStackTrace();
1020 } catch (IOException e)
1022 e.printStackTrace();
1030 public void viewMapping_actionPerformed(ActionEvent actionEvent)
1032 jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
1035 cap.appendText(jmb.printMappings());
1036 } catch (OutOfMemoryError e)
1039 "composing sequence-structure alignments for display in text box.",
1044 jalview.gui.Desktop.addInternalFrame(cap,
1045 MessageManager.getString("label.pdb_sequence_mapping"), 550,
1050 public void eps_actionPerformed(ActionEvent e)
1054 .getString("error.eps_generation_not_implemented"));
1058 public void png_actionPerformed(ActionEvent e)
1062 .getString("error.png_generation_not_implemented"));
1066 public void viewerColour_actionPerformed(ActionEvent actionEvent)
1068 if (viewerColour.isSelected())
1070 // disable automatic sequence colouring.
1071 jmb.setColourBySequence(false);
1076 public void seqColour_actionPerformed(ActionEvent actionEvent)
1078 jmb.setColourBySequence(seqColour.isSelected());
1079 if (_colourwith == null)
1081 _colourwith = new Vector<AlignmentPanel>();
1083 if (jmb.isColourBySequence())
1085 if (!jmb.isLoadingFromArchive())
1087 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
1089 // Make the currently displayed alignment panel the associated view
1090 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
1093 // Set the colour using the current view for the associated alignframe
1094 for (AlignmentPanel ap : _colourwith)
1096 jmb.colourBySequence(ap.av.isShowSequenceFeatures(), ap);
1102 public void chainColour_actionPerformed(ActionEvent actionEvent)
1104 chainColour.setSelected(true);
1105 jmb.colourByChain();
1109 public void chargeColour_actionPerformed(ActionEvent actionEvent)
1111 chargeColour.setSelected(true);
1112 jmb.colourByCharge();
1116 public void zappoColour_actionPerformed(ActionEvent actionEvent)
1118 zappoColour.setSelected(true);
1119 jmb.setJalviewColourScheme(new ZappoColourScheme());
1123 public void taylorColour_actionPerformed(ActionEvent actionEvent)
1125 taylorColour.setSelected(true);
1126 jmb.setJalviewColourScheme(new TaylorColourScheme());
1130 public void hydroColour_actionPerformed(ActionEvent actionEvent)
1132 hydroColour.setSelected(true);
1133 jmb.setJalviewColourScheme(new HydrophobicColourScheme());
1137 public void helixColour_actionPerformed(ActionEvent actionEvent)
1139 helixColour.setSelected(true);
1140 jmb.setJalviewColourScheme(new HelixColourScheme());
1144 public void strandColour_actionPerformed(ActionEvent actionEvent)
1146 strandColour.setSelected(true);
1147 jmb.setJalviewColourScheme(new StrandColourScheme());
1151 public void turnColour_actionPerformed(ActionEvent actionEvent)
1153 turnColour.setSelected(true);
1154 jmb.setJalviewColourScheme(new TurnColourScheme());
1158 public void buriedColour_actionPerformed(ActionEvent actionEvent)
1160 buriedColour.setSelected(true);
1161 jmb.setJalviewColourScheme(new BuriedColourScheme());
1165 public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
1167 setJalviewColourScheme(new PurinePyrimidineColourScheme());
1171 public void userColour_actionPerformed(ActionEvent actionEvent)
1173 userColour.setSelected(true);
1174 new UserDefinedColours(this, null);
1178 public void backGround_actionPerformed(ActionEvent actionEvent)
1180 java.awt.Color col = JColorChooser
1181 .showDialog(this, MessageManager
1182 .getString("label.select_backgroud_colour"), null);
1185 jmb.setBackgroundColour(col);
1190 public void showHelp_actionPerformed(ActionEvent actionEvent)
1194 jalview.util.BrowserLauncher
1195 .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
1196 } catch (Exception ex)
1201 public void updateTitleAndMenus()
1203 if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
1208 setChainMenuItems(jmb.getChainNames());
1210 this.setTitle(jmb.getViewerTitle("Chimera", true));
1211 if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1)
1213 viewerActionMenu.setVisible(true);
1215 if (!jmb.isLoadingFromArchive())
1217 seqColour_actionPerformed(null);
1225 * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
1229 protected void alignStructs_actionPerformed(ActionEvent actionEvent)
1231 alignStructs_withAllAlignPanels();
1234 private void alignStructs_withAllAlignPanels()
1236 if (getAlignmentPanel() == null)
1241 if (_alignwith.size() == 0)
1243 _alignwith.add(getAlignmentPanel());
1248 AlignmentI[] als = new Alignment[_alignwith.size()];
1249 ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
1250 int[] alm = new int[_alignwith.size()];
1253 for (AlignmentPanel ap : _alignwith)
1255 als[a] = ap.av.getAlignment();
1257 alc[a++] = ap.av.getColumnSelection();
1259 jmb.superposeStructures(als, alm, alc);
1260 } catch (Exception e)
1262 StringBuffer sp = new StringBuffer();
1263 for (AlignmentPanel ap : _alignwith)
1265 sp.append("'" + ap.alignFrame.getTitle() + "' ");
1267 Cache.log.info("Couldn't align structures with the " + sp.toString()
1268 + "associated alignment panels.", e);
1272 public void setJalviewColourScheme(ColourSchemeI ucs)
1274 jmb.setJalviewColourScheme(ucs);
1281 * @return first alignment panel displaying given alignment, or the default
1284 public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
1286 for (AlignmentPanel ap : getAllAlignmentPanels())
1288 if (ap.av.getAlignment() == alignment)
1293 return getAlignmentPanel();
1297 public AAStructureBindingModel getBinding()
1303 * Ask Chimera to save its session to the designated file path. Returns true
1304 * if successful, else false.
1309 public boolean saveSession(String filepath)
1311 boolean result = jmb.saveSession(filepath);
1314 this.chimeraSessionFile = filepath;
1320 * Returns the file path of the Chimera session file the last time it was
1321 * saved. If it was never saved, returns an empty string. There is no
1322 * guarantee that the Chimera session has not changed since it was saved.
1325 public String getStateInfo()
1327 return this.chimeraSessionFile == null ? "" : chimeraSessionFile;
1331 protected void fitToWindow_actionPerformed()