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.Color;
24 import java.awt.Component;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.awt.event.ItemEvent;
28 import java.awt.event.ItemListener;
29 import java.io.BufferedReader;
31 import java.io.FileOutputStream;
32 import java.io.FileReader;
33 import java.io.IOException;
34 import java.io.PrintWriter;
35 import java.util.ArrayList;
36 import java.util.List;
37 import java.util.Random;
38 import java.util.Vector;
40 import javax.swing.ButtonGroup;
41 import javax.swing.JCheckBoxMenuItem;
42 import javax.swing.JMenu;
43 import javax.swing.JMenuItem;
44 import javax.swing.JRadioButtonMenuItem;
45 import javax.swing.event.MenuEvent;
46 import javax.swing.event.MenuListener;
48 import jalview.api.AlignmentViewPanel;
49 import jalview.bin.Cache;
50 import jalview.datamodel.AlignmentI;
51 import jalview.datamodel.PDBEntry;
52 import jalview.datamodel.SequenceI;
53 import jalview.gui.JalviewColourChooser.ColourChooserListener;
54 import jalview.gui.StructureViewer.ViewerType;
55 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
56 import jalview.io.DataSourceType;
57 import jalview.io.JalviewFileChooser;
58 import jalview.io.JalviewFileView;
59 import jalview.jbgui.GStructureViewer;
60 import jalview.schemes.ColourSchemeI;
61 import jalview.schemes.ColourSchemes;
62 import jalview.structure.StructureMapping;
63 import jalview.structures.models.AAStructureBindingModel;
64 import jalview.util.BrowserLauncher;
65 import jalview.util.MessageManager;
66 import jalview.ws.dbsources.EBIAlfaFold;
67 import jalview.ws.dbsources.Pdb;
68 import jalview.ws.utils.UrlDownloadClient;
71 * Base class with common functionality for JMol, Chimera or other structure
77 public abstract class StructureViewerBase extends GStructureViewer
78 implements Runnable, ViewSetProvider
81 * names for colour options (additional to Jalview colour schemes)
85 BySequence, ByChain, ChargeCysteine, ByViewer
89 * list of sequenceSet ids associated with the view
91 protected List<String> _aps = new ArrayList<>();
94 * list of alignment panels to use for superposition
96 protected Vector<AlignmentViewPanel> _alignwith = new Vector<>();
99 * list of alignment panels that are used for colouring structures by aligned
102 protected Vector<AlignmentViewPanel> _colourwith = new Vector<>();
104 private String viewId = null;
106 private AlignmentPanel ap;
108 protected boolean alignAddedStructures = false;
110 protected volatile boolean _started = false;
112 protected volatile boolean addingStructures = false;
114 protected Thread worker = null;
116 protected boolean allChainsSelected = false;
118 protected JMenu viewSelectionMenu;
121 * set after sequence colouring has been applied for this structure viewer.
122 * used to determine if the final sequence/structure mapping has been
125 protected volatile boolean seqColoursApplied = false;
127 private IProgressIndicator progressBar = null;
129 private Random random = new Random();
132 * Default constructor
134 public StructureViewerBase()
140 * @return true if added structures should be aligned to existing one(s)
143 public boolean isAlignAddedStructures()
145 return alignAddedStructures;
151 * if added structures should be aligned to existing one(s)
154 public void setAlignAddedStructures(boolean alignAdded)
156 alignAddedStructures = alignAdded;
160 * called by the binding model to indicate when adding structures is happening or has been completed
161 * @param addingStructures
163 public synchronized void setAddingStructures(boolean addingStructures)
165 this.addingStructures = addingStructures;
171 * @return true if this Jmol instance is linked with the given alignPanel
173 public boolean isLinkedWith(AlignmentPanel ap2)
175 return _aps.contains(ap2.av.getSequenceSetId());
178 public boolean isUsedforaligment(AlignmentViewPanel ap2)
181 return (_alignwith != null) && _alignwith.contains(ap2);
185 public boolean isUsedForColourBy(AlignmentViewPanel ap2)
187 return (_colourwith != null) && _colourwith.contains(ap2);
192 * @return TRUE if the view is NOT being coloured by the alignment colours.
194 public boolean isColouredByViewer()
196 return !getBinding().isColourBySequence();
199 public String getViewId()
203 viewId = System.currentTimeMillis() + "." + this.hashCode();
208 protected void setViewId(String viewId)
210 this.viewId = viewId;
213 protected void buildActionMenu()
215 if (_alignwith == null)
217 _alignwith = new Vector<>();
219 if (_alignwith.size() == 0 && ap != null)
224 for (Component c : viewerActionMenu.getMenuComponents())
226 if (c != alignStructs)
228 viewerActionMenu.remove((JMenuItem) c);
234 public AlignmentPanel getAlignmentPanel()
239 protected void setAlignmentPanel(AlignmentPanel alp)
245 public AlignmentPanel[] getAllAlignmentPanels()
247 AlignmentPanel[] t, list = new AlignmentPanel[0];
248 for (String setid : _aps)
250 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
253 t = new AlignmentPanel[list.length + panels.length];
254 System.arraycopy(list, 0, t, 0, list.length);
255 System.arraycopy(panels, 0, t, list.length, panels.length);
264 * set the primary alignmentPanel reference and add another alignPanel to the
265 * list of ones to use for colouring and aligning
269 public void addAlignmentPanel(AlignmentPanel nap)
271 if (getAlignmentPanel() == null)
273 setAlignmentPanel(nap);
275 if (!_aps.contains(nap.av.getSequenceSetId()))
277 _aps.add(nap.av.getSequenceSetId());
282 * remove any references held to the given alignment panel
287 public void removeAlignmentPanel(AlignmentViewPanel nap)
291 _alignwith.remove(nap);
292 _colourwith.remove(nap);
293 if (getAlignmentPanel() == nap)
295 setAlignmentPanel(null);
296 for (AlignmentPanel aps : getAllAlignmentPanels())
300 setAlignmentPanel(aps);
305 } catch (Exception ex)
308 if (getAlignmentPanel() != null)
314 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
316 addAlignmentPanel(nap);
317 if (!_alignwith.contains(nap))
323 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
325 if (_alignwith.contains(nap))
327 _alignwith.remove(nap);
331 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
332 boolean enableColourBySeq)
334 useAlignmentPanelForColourbyseq(nap);
335 getBinding().setColourBySequence(enableColourBySeq);
336 seqColour.setSelected(enableColourBySeq);
337 viewerColour.setSelected(!enableColourBySeq);
340 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
342 addAlignmentPanel(nap);
343 if (!_colourwith.contains(nap))
345 _colourwith.add(nap);
349 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
351 if (_colourwith.contains(nap))
353 _colourwith.remove(nap);
357 public abstract ViewerType getViewerType();
360 * add a new structure (with associated sequences and chains) to this viewer,
361 * retrieving it if necessary first.
367 * if true, new structure(s) will be aligned using associated
371 protected void addStructure(final PDBEntry pdbentry,
372 final SequenceI[] seqs, final String[] chains,
373 final IProgressIndicator alignFrame)
375 if (pdbentry.getFile() == null)
377 if (worker != null && worker.isAlive())
379 // a retrieval is in progress, wait around and add ourselves to the
381 new Thread(new Runnable()
386 while (worker != null && worker.isAlive() && _started)
390 Thread.sleep(100 + ((int) Math.random() * 100));
392 } catch (Exception e)
396 // and call ourselves again.
397 addStructure(pdbentry, seqs, chains, alignFrame);
403 // otherwise, start adding the structure.
404 getBinding().addSequenceAndChain(new PDBEntry[] { pdbentry },
406 { seqs }, new String[][] { chains });
407 addingStructures = true;
409 worker = new Thread(this);
414 protected boolean hasPdbId(String pdbId)
416 return getBinding().hasPdbId(pdbId);
420 * Returns a list of any viewer of the instantiated type. The list is
421 * restricted to those linked to the given alignment panel if it is not null.
423 protected List<StructureViewerBase> getViewersFor(AlignmentPanel alp)
425 return Desktop.instance.getStructureViewers(alp, this.getClass());
429 public void addToExistingViewer(PDBEntry pdbentry, SequenceI[] seq,
430 String[] chains, final AlignmentViewPanel apanel, String pdbId)
433 * JAL-1742 exclude view with this structure already mapped (don't offer
434 * to align chain B to chain A of the same structure); code may defend
435 * against this possibility before we reach here
441 AlignmentPanel alignPanel = (AlignmentPanel) apanel; // Implementation error if this
443 useAlignmentPanelForSuperposition(alignPanel);
444 addStructure(pdbentry, seq, chains, alignPanel.alignFrame);
448 * Adds mappings for the given sequences to an already opened PDB structure,
449 * and updates any viewers that have the PDB file
456 public void addSequenceMappingsToStructure(SequenceI[] seq,
457 String[] chains, final AlignmentViewPanel alpanel,
460 AlignmentPanel apanel = (AlignmentPanel) alpanel;
462 // TODO : Fix multiple seq to one chain issue here.
464 * create the mappings
466 apanel.getStructureSelectionManager().setMapping(seq, chains,
467 pdbFilename, DataSourceType.FILE, getProgressIndicator());
470 * alert the FeatureRenderer to show new (PDB RESNUM) features
472 if (apanel.getSeqPanel().seqCanvas.fr != null)
474 apanel.getSeqPanel().seqCanvas.fr.featuresAdded();
475 // note - we don't do a refresh for structure here because we do it
476 // explicitly for all panels later on
477 apanel.paintAlignment(true, false);
481 * add the sequences to any other viewers (of the same type) for this pdb
484 // JBPNOTE: this looks like a binding routine, rather than a gui routine
485 for (StructureViewerBase viewer : getViewersFor(null))
487 AAStructureBindingModel bindingModel = viewer.getBinding();
488 for (int pe = 0; pe < bindingModel.getPdbCount(); pe++)
490 if (bindingModel.getPdbEntry(pe).getFile().equals(pdbFilename))
492 bindingModel.addSequence(pe, seq);
493 viewer.addAlignmentPanel(apanel);
495 * add it to the set of alignments used for colouring structure by
498 viewer.useAlignmentPanelForColourbyseq(apanel);
499 viewer.buildActionMenu();
500 apanel.getStructureSelectionManager()
501 .sequenceColoursChanged(apanel);
509 public boolean addAlreadyLoadedFile(SequenceI[] seq, String[] chains,
510 final AlignmentViewPanel apanel, String pdbId)
512 String alreadyMapped = apanel.getStructureSelectionManager()
513 .alreadyMappedToFile(pdbId);
515 if (alreadyMapped == null)
520 addSequenceMappingsToStructure(seq, chains, apanel, alreadyMapped);
524 void setChainMenuItems(List<String> chainNames)
526 chainMenu.removeAll();
527 if (chainNames == null || chainNames.isEmpty())
531 JMenuItem menuItem = new JMenuItem(
532 MessageManager.getString("label.all"));
533 menuItem.addActionListener(new ActionListener()
536 public void actionPerformed(ActionEvent evt)
538 allChainsSelected = true;
539 for (int i = 0; i < chainMenu.getItemCount(); i++)
541 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
543 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
546 showSelectedChains();
547 allChainsSelected = false;
551 chainMenu.add(menuItem);
553 for (String chain : chainNames)
555 menuItem = new JCheckBoxMenuItem(chain, true);
556 menuItem.addItemListener(new ItemListener()
559 public void itemStateChanged(ItemEvent evt)
561 if (!allChainsSelected)
563 showSelectedChains();
568 chainMenu.add(menuItem);
573 * Action on selecting one of Jalview's registered colour schemes
576 public void changeColour_actionPerformed(String colourSchemeName)
578 AlignmentI al = getAlignmentPanel().av.getAlignment();
579 ColourSchemeI cs = ColourSchemes.getInstance()
580 .getColourScheme(colourSchemeName, getAlignmentPanel().av, al,
582 getBinding().colourByJalviewColourScheme(cs);
586 * Builds the colour menu
588 protected void buildColourMenu()
590 colourMenu.removeAll();
591 AlignmentI al = getAlignmentPanel().av.getAlignment();
594 * add colour by sequence, by chain, by charge and cysteine
596 colourMenu.add(seqColour);
597 colourMenu.add(chainColour);
598 colourMenu.add(chargeColour);
599 chargeColour.setEnabled(!al.isNucleotide());
602 * add all 'simple' (per-residue) colour schemes registered to Jalview
604 ButtonGroup itemGroup = ColourMenuHelper.addMenuItems(colourMenu, this,
608 * add 'colour by viewer' (menu item text is set in subclasses)
610 viewerColour.setSelected(false);
611 viewerColour.addActionListener(new ActionListener()
614 public void actionPerformed(ActionEvent actionEvent)
616 viewerColour_actionPerformed();
619 colourMenu.add(viewerColour);
622 * add 'set background colour'
624 JMenuItem backGround = new JMenuItem();
626 .setText(MessageManager.getString("action.background_colour"));
627 backGround.addActionListener(new ActionListener()
630 public void actionPerformed(ActionEvent actionEvent)
632 background_actionPerformed();
635 colourMenu.add(backGround);
638 * add colour buttons to a group so their selection is
639 * mutually exclusive (background colour is a separate option)
641 itemGroup.add(seqColour);
642 itemGroup.add(chainColour);
643 itemGroup.add(chargeColour);
644 itemGroup.add(viewerColour);
648 * Construct menu items
650 protected void initMenus()
652 AAStructureBindingModel binding = getBinding();
654 seqColour = new JRadioButtonMenuItem();
655 seqColour.setText(MessageManager.getString("action.by_sequence"));
656 seqColour.setName(ViewerColour.BySequence.name());
657 seqColour.setSelected(binding.isColourBySequence());
658 seqColour.addActionListener(new ActionListener()
661 public void actionPerformed(ActionEvent actionEvent)
663 seqColour_actionPerformed();
667 chainColour = new JRadioButtonMenuItem();
668 chainColour.setText(MessageManager.getString("action.by_chain"));
669 chainColour.setName(ViewerColour.ByChain.name());
670 chainColour.addActionListener(new ActionListener()
673 public void actionPerformed(ActionEvent actionEvent)
675 chainColour_actionPerformed();
679 chargeColour = new JRadioButtonMenuItem();
680 chargeColour.setText(MessageManager.getString("label.charge_cysteine"));
681 chargeColour.setName(ViewerColour.ChargeCysteine.name());
682 chargeColour.addActionListener(new ActionListener()
685 public void actionPerformed(ActionEvent actionEvent)
687 chargeColour_actionPerformed();
691 viewerColour = new JRadioButtonMenuItem();
693 .setText(MessageManager.getString("label.colour_with_viewer"));
694 viewerColour.setToolTipText(MessageManager
695 .getString("label.let_viewer_manage_structure_colours"));
696 viewerColour.setName(ViewerColour.ByViewer.name());
697 viewerColour.setSelected(!binding.isColourBySequence());
699 if (_colourwith == null)
701 _colourwith = new Vector<>();
703 if (_alignwith == null)
705 _alignwith = new Vector<>();
708 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
709 MessageManager.getString("label.colour_by"), this, _colourwith,
713 public void itemStateChanged(ItemEvent e)
715 if (!seqColour.isSelected())
721 // update the viewer display now.
722 seqColour_actionPerformed();
726 viewMenu.add(seqColourBy);
728 final ItemListener handler = new ItemListener()
731 public void itemStateChanged(ItemEvent e)
733 if (_alignwith.isEmpty())
735 alignStructs.setEnabled(false);
736 alignStructs.setToolTipText(null);
740 alignStructs.setEnabled(true);
741 alignStructs.setToolTipText(MessageManager.formatMessage(
742 "label.align_structures_using_linked_alignment_views",
747 viewSelectionMenu = new ViewSelectionMenu(
748 MessageManager.getString("label.superpose_with"), this,
749 _alignwith, handler);
750 handler.itemStateChanged(null);
751 viewerActionMenu.add(viewSelectionMenu, 0);
752 viewerActionMenu.addMenuListener(new MenuListener()
755 public void menuSelected(MenuEvent e)
757 handler.itemStateChanged(null);
761 public void menuDeselected(MenuEvent e)
766 public void menuCanceled(MenuEvent e)
771 viewerActionMenu.setText(getViewerName());
772 helpItem.setText(MessageManager.formatMessage("label.viewer_help",
779 * Sends commands to the structure viewer to superimpose structures based on
780 * currently associated alignments. May optionally return an error message for
784 protected String alignStructsWithAllAlignPanels()
786 if (getAlignmentPanel() == null)
791 if (_alignwith.size() == 0)
793 _alignwith.add(getAlignmentPanel());
799 reply = getBinding().superposeStructures(_alignwith);
800 if (reply != null && !reply.isEmpty())
802 String text = MessageManager
803 .formatMessage("error.superposition_failed", reply);
804 statusBar.setText(text);
806 } catch (Exception e)
808 StringBuffer sp = new StringBuffer();
809 for (AlignmentViewPanel alignPanel : _alignwith)
811 sp.append("'" + alignPanel.getViewName() + "' ");
813 Cache.log.info("Couldn't align structures with the " + sp.toString()
814 + "associated alignment panels.", e);
820 * Opens a colour chooser dialog, and applies the chosen colour to the
821 * background of the structure viewer
824 public void background_actionPerformed()
826 String ttl = MessageManager.getString("label.select_background_colour");
827 ColourChooserListener listener = new ColourChooserListener()
830 public void colourSelected(Color c)
832 getBinding().setBackgroundColour(c);
835 JalviewColourChooser.showColourChooser(this, ttl, null, listener);
839 public void viewerColour_actionPerformed()
841 if (viewerColour.isSelected())
843 // disable automatic sequence colouring.
844 getBinding().setColourBySequence(false);
849 public void chainColour_actionPerformed()
851 chainColour.setSelected(true);
852 getBinding().colourByChain();
856 public void chargeColour_actionPerformed()
858 chargeColour.setSelected(true);
859 getBinding().colourByCharge();
863 public void seqColour_actionPerformed()
865 AAStructureBindingModel binding = getBinding();
866 binding.setColourBySequence(seqColour.isSelected());
867 if (_colourwith == null)
869 _colourwith = new Vector<>();
871 if (binding.isColourBySequence())
873 if (!binding.isLoadingFromArchive())
875 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
877 // Make the currently displayed alignment panel the associated view
878 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
881 // Set the colour using the current view for the associated alignframe
882 for (AlignmentViewPanel alignPanel : _colourwith)
884 binding.colourBySequence(alignPanel);
886 seqColoursApplied = true;
891 public void pdbFile_actionPerformed()
893 // TODO: JAL-3048 not needed for Jalview-JS - save PDB file
894 JalviewFileChooser chooser = new JalviewFileChooser(
895 Cache.getProperty("LAST_DIRECTORY"));
897 chooser.setFileView(new JalviewFileView());
898 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
899 chooser.setToolTipText(MessageManager.getString("action.save"));
901 int value = chooser.showSaveDialog(this);
903 if (value == JalviewFileChooser.APPROVE_OPTION)
905 BufferedReader in = null;
908 // TODO: cope with multiple PDB files in view
909 in = new BufferedReader(
910 new FileReader(getBinding().getStructureFiles()[0]));
911 File outFile = chooser.getSelectedFile();
913 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
915 while ((data = in.readLine()) != null)
917 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
923 } catch (Exception ex)
925 ex.printStackTrace();
933 } catch (IOException e)
943 public void viewMapping_actionPerformed()
945 CutAndPasteTransfer cap = new CutAndPasteTransfer();
948 cap.appendText(getBinding().printMappings());
949 } catch (OutOfMemoryError e)
952 "composing sequence-structure alignments for display in text box.",
957 Desktop.addInternalFrame(cap,
958 MessageManager.getString("label.pdb_sequence_mapping"), 550,
962 protected abstract String getViewerName();
965 * Configures the title and menu items of the viewer panel.
968 public void updateTitleAndMenus()
970 AAStructureBindingModel binding = getBinding();
971 if (binding.hasFileLoadingError())
976 setChainMenuItems(binding.getChainNames());
978 this.setTitle(binding.getViewerTitle(getViewerName(), true));
981 * enable 'Superpose with' if more than one mapped structure
983 viewSelectionMenu.setEnabled(false);
984 if (getBinding().getMappedStructureCount() > 1
985 && getBinding().getSequence().length > 1)
987 viewSelectionMenu.setEnabled(true);
991 * Show action menu if it has any enabled items
993 viewerActionMenu.setVisible(false);
994 for (int i = 0; i < viewerActionMenu.getItemCount(); i++)
996 if (viewerActionMenu.getItem(i).isEnabled())
998 viewerActionMenu.setVisible(true);
1003 if (!binding.isLoadingFromArchive())
1005 seqColour_actionPerformed();
1010 public String toString()
1016 public boolean hasMapping()
1018 if (worker != null && (addingStructures || _started))
1022 if (getBinding() == null)
1024 if (_aps == null || _aps.size() == 0)
1026 // viewer has been closed, but we did at some point run.
1031 String[] pdbids = getBinding().getStructureFiles();
1037 for (String pdbid:pdbids) {
1038 StructureMapping sm[] = getBinding().getSsm().getMapping(pdbid);
1039 if (sm!=null && sm.length>0 && sm[0]!=null) {
1043 // only return true if there is a mapping for every structure file we have loaded
1044 if (p == 0 || p != pdbids.length)
1048 // and that coloring has been applied
1049 return seqColoursApplied;
1053 public void raiseViewer()
1059 public long startProgressBar(String msg)
1061 // TODO would rather have startProgress/stopProgress as the
1062 // IProgressIndicator interface
1063 long tm = random.nextLong();
1064 if (progressBar != null)
1066 progressBar.setProgressBar(msg, tm);
1072 public void stopProgressBar(String msg, long handle)
1074 if (progressBar != null)
1076 progressBar.setProgressBar(msg, handle);
1080 protected IProgressIndicator getProgressIndicator()
1085 protected void setProgressIndicator(IProgressIndicator pi)
1090 public void setProgressMessage(String message, long id)
1092 if (progressBar != null)
1094 progressBar.setProgressBar(message, id);
1099 public void showConsole(boolean show)
1101 // default does nothing
1105 * Show only the selected chain(s) in the viewer
1107 protected void showSelectedChains()
1109 List<String> toshow = new ArrayList<>();
1110 for (int i = 0; i < chainMenu.getItemCount(); i++)
1112 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
1114 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
1115 if (item.isSelected())
1117 toshow.add(item.getText());
1121 getBinding().showChains(toshow);
1125 * Tries to fetch a PDB file and save to a temporary local file. Returns the
1126 * saved file path if successful, or null if not.
1128 * @param processingEntry
1131 protected String fetchPdbFile(PDBEntry processingEntry)
1133 String filePath = null;
1134 Pdb pdbclient = new Pdb();
1135 EBIAlfaFold afclient = new EBIAlfaFold();
1136 AlignmentI pdbseq = null;
1137 String pdbid = processingEntry.getId();
1138 long handle = System.currentTimeMillis()
1139 + Thread.currentThread().hashCode();
1142 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
1144 String msg = MessageManager.formatMessage("status.fetching_pdb",
1147 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
1148 // long hdl = startProgressBar(MessageManager.formatMessage(
1149 // "status.fetching_pdb", new Object[]
1153 if (afclient.isValidReference(pdbid))
1155 pdbseq = afclient.getSequenceRecords(pdbid);
1157 if (processingEntry.hasRetrievalUrl())
1159 // retrieve from URL to new local tmpfile
1160 File tmpFile = File.createTempFile(pdbid,
1161 "." + (PDBEntry.Type.MMCIF.toString().equals(
1162 processingEntry.getType().toString()) ? "cif"
1164 String fromUrl = processingEntry.getRetrievalUrl();
1165 UrlDownloadClient.download(fromUrl, tmpFile);
1167 // may not need this check ?
1168 String file = tmpFile.getAbsolutePath();
1171 pdbseq = EBIAlfaFold.importDownloadedStructureFromUrl(fromUrl,tmpFile,pdbid,null,null,null);
1174 pdbseq = pdbclient.getSequenceRecords(pdbid);
1177 } catch (Exception e)
1180 "Error retrieving PDB id " + pdbid + ": " + e.getMessage());
1183 msg = pdbid + " " + MessageManager.getString("label.state_completed");
1184 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
1185 // stopProgressBar(msg, hdl);
1188 * If PDB data were saved and are not invalid (empty alignment), return the
1191 if (pdbseq != null && pdbseq.getHeight() > 0)
1193 // just use the file name from the first sequence's first PDBEntry
1194 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
1195 .elementAt(0).getFile()).getAbsolutePath();
1196 processingEntry.setFile(filePath);
1202 * If supported, saves the state of the structure viewer to a temporary file
1203 * and returns the file, else returns null
1207 public File saveSession()
1209 // TODO: a wait loop to ensure the file is written fully before returning?
1210 return getBinding() == null ? null : getBinding().saveSession();
1214 * Close down this instance of Jalview's Chimera viewer, giving the user the
1215 * option to close the associated Chimera window (process). They may wish to
1216 * keep it open until they have had an opportunity to save any work.
1219 * if true, close any linked Chimera process; if false, prompt first
1222 public void closeViewer(boolean forceClose)
1224 AAStructureBindingModel binding = getBinding();
1225 if (binding != null && binding.isViewerRunning())
1229 String viewerName = getViewerName();
1230 String prompt = MessageManager
1231 .formatMessage("label.confirm_close_viewer", new Object[]
1232 { binding.getViewerTitle(viewerName, false), viewerName });
1233 prompt = JvSwingUtils.wrapTooltip(true, prompt);
1234 int confirm = JvOptionPane.showConfirmDialog(this, prompt,
1235 MessageManager.getString("label.close_viewer"),
1236 JvOptionPane.YES_NO_CANCEL_OPTION);
1238 * abort closure if user hits escape or Cancel
1240 if (confirm == JvOptionPane.CANCEL_OPTION
1241 || confirm == JvOptionPane.CLOSED_OPTION)
1245 forceClose = confirm == JvOptionPane.YES_OPTION;
1248 if (binding != null)
1250 binding.closeViewer(forceClose);
1252 setAlignmentPanel(null);
1255 _colourwith.clear();
1256 // TODO: check for memory leaks where instance isn't finalised because jmb
1257 // holds a reference to the window
1263 public void showHelp_actionPerformed()
1267 String url = getBinding().getHelpURL();
1270 BrowserLauncher.openURL(url);
1272 } catch (IOException ex)
1275 .println("Show " + getViewerName() + " failed with: "
1280 public boolean hasViewerActionsMenu()
1282 return viewerActionMenu!=null && viewerActionMenu.isEnabled() && viewerActionMenu.getItemCount()>0 && viewerActionMenu.isVisible();