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.bin.Console;
51 import jalview.datamodel.AlignmentI;
52 import jalview.datamodel.PDBEntry;
53 import jalview.datamodel.SequenceI;
54 import jalview.gui.JalviewColourChooser.ColourChooserListener;
55 import jalview.gui.StructureViewer.ViewerType;
56 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
57 import jalview.io.DataSourceType;
58 import jalview.io.JalviewFileChooser;
59 import jalview.io.JalviewFileView;
60 import jalview.jbgui.GStructureViewer;
61 import jalview.schemes.ColourSchemeI;
62 import jalview.schemes.ColourSchemes;
63 import jalview.structure.StructureMapping;
64 import jalview.structures.models.AAStructureBindingModel;
65 import jalview.util.BrowserLauncher;
66 import jalview.util.MessageManager;
67 import jalview.ws.dbsources.EBIAlfaFold;
68 import jalview.ws.dbsources.Pdb;
69 import jalview.ws.utils.UrlDownloadClient;
72 * Base class with common functionality for JMol, Chimera or other structure
78 public abstract class StructureViewerBase extends GStructureViewer
79 implements Runnable, ViewSetProvider
82 * names for colour options (additional to Jalview colour schemes)
86 BySequence, ByChain, ChargeCysteine, ByViewer
90 * list of sequenceSet ids associated with the view
92 protected List<String> _aps = new ArrayList<>();
95 * list of alignment panels to use for superposition
97 protected Vector<AlignmentViewPanel> _alignwith = new Vector<>();
100 * list of alignment panels that are used for colouring structures by aligned
103 protected Vector<AlignmentViewPanel> _colourwith = new Vector<>();
105 private String viewId = null;
107 private AlignmentPanel ap;
109 protected boolean alignAddedStructures = false;
111 protected volatile boolean _started = false;
113 protected volatile boolean addingStructures = false;
115 protected Thread worker = null;
117 protected boolean allChainsSelected = false;
119 protected JMenu viewSelectionMenu;
122 * set after sequence colouring has been applied for this structure viewer.
123 * used to determine if the final sequence/structure mapping has been
126 protected volatile boolean seqColoursApplied = false;
128 private IProgressIndicator progressBar = null;
130 private Random random = new Random();
133 * Default constructor
135 public StructureViewerBase()
141 * @return true if added structures should be aligned to existing one(s)
144 public boolean isAlignAddedStructures()
146 return alignAddedStructures;
152 * if added structures should be aligned to existing one(s)
155 public void setAlignAddedStructures(boolean alignAdded)
157 alignAddedStructures = alignAdded;
161 * called by the binding model to indicate when adding structures is happening or has been completed
162 * @param addingStructures
164 public synchronized void setAddingStructures(boolean addingStructures)
166 this.addingStructures = addingStructures;
172 * @return true if this Jmol instance is linked with the given alignPanel
174 public boolean isLinkedWith(AlignmentPanel ap2)
176 return _aps.contains(ap2.av.getSequenceSetId());
179 public boolean isUsedforaligment(AlignmentViewPanel ap2)
182 return (_alignwith != null) && _alignwith.contains(ap2);
186 public boolean isUsedForColourBy(AlignmentViewPanel ap2)
188 return (_colourwith != null) && _colourwith.contains(ap2);
193 * @return TRUE if the view is NOT being coloured by the alignment colours.
195 public boolean isColouredByViewer()
197 return !getBinding().isColourBySequence();
200 public String getViewId()
204 viewId = System.currentTimeMillis() + "." + this.hashCode();
209 protected void setViewId(String viewId)
211 this.viewId = viewId;
214 protected void buildActionMenu()
216 if (_alignwith == null)
218 _alignwith = new Vector<>();
220 if (_alignwith.size() == 0 && ap != null)
225 // TODO: refactor to allow concrete classes to register buttons for adding
227 // currently have to override to add buttons back in after they are cleared
229 for (Component c : viewerActionMenu.getMenuComponents())
231 if (c != alignStructs)
233 viewerActionMenu.remove((JMenuItem) c);
239 public AlignmentPanel getAlignmentPanel()
244 protected void setAlignmentPanel(AlignmentPanel alp)
250 public AlignmentPanel[] getAllAlignmentPanels()
252 AlignmentPanel[] t, list = new AlignmentPanel[0];
253 for (String setid : _aps)
255 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
258 t = new AlignmentPanel[list.length + panels.length];
259 System.arraycopy(list, 0, t, 0, list.length);
260 System.arraycopy(panels, 0, t, list.length, panels.length);
269 * set the primary alignmentPanel reference and add another alignPanel to the
270 * list of ones to use for colouring and aligning
274 public void addAlignmentPanel(AlignmentPanel nap)
276 if (getAlignmentPanel() == null)
278 setAlignmentPanel(nap);
280 if (!_aps.contains(nap.av.getSequenceSetId()))
282 _aps.add(nap.av.getSequenceSetId());
287 * remove any references held to the given alignment panel
292 public void removeAlignmentPanel(AlignmentViewPanel nap)
296 _alignwith.remove(nap);
297 _colourwith.remove(nap);
298 if (getAlignmentPanel() == nap)
300 setAlignmentPanel(null);
301 for (AlignmentPanel aps : getAllAlignmentPanels())
305 setAlignmentPanel(aps);
310 } catch (Exception ex)
313 if (getAlignmentPanel() != null)
319 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
321 addAlignmentPanel(nap);
322 if (!_alignwith.contains(nap))
328 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
330 if (_alignwith.contains(nap))
332 _alignwith.remove(nap);
336 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
337 boolean enableColourBySeq)
339 useAlignmentPanelForColourbyseq(nap);
340 getBinding().setColourBySequence(enableColourBySeq);
341 seqColour.setSelected(enableColourBySeq);
342 viewerColour.setSelected(!enableColourBySeq);
345 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
347 addAlignmentPanel(nap);
348 if (!_colourwith.contains(nap))
350 _colourwith.add(nap);
354 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
356 if (_colourwith.contains(nap))
358 _colourwith.remove(nap);
362 public abstract ViewerType getViewerType();
365 * add a new structure (with associated sequences and chains) to this viewer,
366 * retrieving it if necessary first.
372 * if true, new structure(s) will be aligned using associated
376 protected void addStructure(final PDBEntry pdbentry,
377 final SequenceI[] seqs, final String[] chains,
378 final IProgressIndicator alignFrame)
380 if (pdbentry.getFile() == null)
382 if (worker != null && worker.isAlive())
384 // a retrieval is in progress, wait around and add ourselves to the
386 new Thread(new Runnable()
391 while (worker != null && worker.isAlive() && _started)
395 Thread.sleep(100 + ((int) Math.random() * 100));
397 } catch (Exception e)
401 // and call ourselves again.
402 addStructure(pdbentry, seqs, chains, alignFrame);
408 // otherwise, start adding the structure.
409 getBinding().addSequenceAndChain(new PDBEntry[] { pdbentry },
411 { seqs }, new String[][] { chains });
412 addingStructures = true;
414 worker = new Thread(this);
419 protected boolean hasPdbId(String pdbId)
421 return getBinding().hasPdbId(pdbId);
425 * Returns a list of any viewer of the instantiated type. The list is
426 * restricted to those linked to the given alignment panel if it is not null.
428 protected List<StructureViewerBase> getViewersFor(AlignmentPanel alp)
430 return Desktop.instance.getStructureViewers(alp, this.getClass());
434 public void addToExistingViewer(PDBEntry pdbentry, SequenceI[] seq,
435 String[] chains, final AlignmentViewPanel apanel, String pdbId)
438 * JAL-1742 exclude view with this structure already mapped (don't offer
439 * to align chain B to chain A of the same structure); code may defend
440 * against this possibility before we reach here
446 AlignmentPanel alignPanel = (AlignmentPanel) apanel; // Implementation error if this
448 useAlignmentPanelForSuperposition(alignPanel);
449 addStructure(pdbentry, seq, chains, alignPanel.alignFrame);
453 * Adds mappings for the given sequences to an already opened PDB structure,
454 * and updates any viewers that have the PDB file
461 public void addSequenceMappingsToStructure(SequenceI[] seq,
462 String[] chains, final AlignmentViewPanel alpanel,
465 AlignmentPanel apanel = (AlignmentPanel) alpanel;
467 // TODO : Fix multiple seq to one chain issue here.
469 * create the mappings
471 apanel.getStructureSelectionManager().setMapping(seq, chains,
472 pdbFilename, DataSourceType.FILE, getProgressIndicator());
475 * alert the FeatureRenderer to show new (PDB RESNUM) features
477 if (apanel.getSeqPanel().seqCanvas.fr != null)
479 apanel.getSeqPanel().seqCanvas.fr.featuresAdded();
480 // note - we don't do a refresh for structure here because we do it
481 // explicitly for all panels later on
482 apanel.paintAlignment(true, false);
486 * add the sequences to any other viewers (of the same type) for this pdb
489 // JBPNOTE: this looks like a binding routine, rather than a gui routine
490 for (StructureViewerBase viewer : getViewersFor(null))
492 AAStructureBindingModel bindingModel = viewer.getBinding();
493 for (int pe = 0; pe < bindingModel.getPdbCount(); pe++)
495 if (bindingModel.getPdbEntry(pe).getFile().equals(pdbFilename))
497 bindingModel.addSequence(pe, seq);
498 viewer.addAlignmentPanel(apanel);
500 * add it to the set of alignments used for colouring structure by
503 viewer.useAlignmentPanelForColourbyseq(apanel);
504 viewer.buildActionMenu();
505 apanel.getStructureSelectionManager()
506 .sequenceColoursChanged(apanel);
514 public boolean addAlreadyLoadedFile(SequenceI[] seq, String[] chains,
515 final AlignmentViewPanel apanel, String pdbId)
517 String alreadyMapped = apanel.getStructureSelectionManager()
518 .alreadyMappedToFile(pdbId);
520 if (alreadyMapped == null)
525 addSequenceMappingsToStructure(seq, chains, apanel, alreadyMapped);
529 void setChainMenuItems(List<String> chainNames)
531 chainMenu.removeAll();
532 if (chainNames == null || chainNames.isEmpty())
536 JMenuItem menuItem = new JMenuItem(
537 MessageManager.getString("label.all"));
538 menuItem.addActionListener(new ActionListener()
541 public void actionPerformed(ActionEvent evt)
543 allChainsSelected = true;
544 for (int i = 0; i < chainMenu.getItemCount(); i++)
546 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
548 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
551 showSelectedChains();
552 allChainsSelected = false;
556 chainMenu.add(menuItem);
558 for (String chain : chainNames)
560 menuItem = new JCheckBoxMenuItem(chain, true);
561 menuItem.addItemListener(new ItemListener()
564 public void itemStateChanged(ItemEvent evt)
566 if (!allChainsSelected)
568 showSelectedChains();
573 chainMenu.add(menuItem);
578 * Action on selecting one of Jalview's registered colour schemes
581 public void changeColour_actionPerformed(String colourSchemeName)
583 AlignmentI al = getAlignmentPanel().av.getAlignment();
584 ColourSchemeI cs = ColourSchemes.getInstance()
585 .getColourScheme(colourSchemeName, getAlignmentPanel().av, al,
587 getBinding().colourByJalviewColourScheme(cs);
591 * Builds the colour menu
593 protected void buildColourMenu()
595 colourMenu.removeAll();
596 AlignmentI al = getAlignmentPanel().av.getAlignment();
599 * add colour by sequence, by chain, by charge and cysteine
601 colourMenu.add(seqColour);
602 colourMenu.add(chainColour);
603 colourMenu.add(chargeColour);
604 chargeColour.setEnabled(!al.isNucleotide());
607 * add all 'simple' (per-residue) colour schemes registered to Jalview
609 ButtonGroup itemGroup = ColourMenuHelper.addMenuItems(colourMenu, this,
613 * add 'colour by viewer' (menu item text is set in subclasses)
615 viewerColour.setSelected(false);
616 viewerColour.addActionListener(new ActionListener()
619 public void actionPerformed(ActionEvent actionEvent)
621 viewerColour_actionPerformed();
624 colourMenu.add(viewerColour);
627 * add 'set background colour'
629 JMenuItem backGround = new JMenuItem();
631 .setText(MessageManager.getString("action.background_colour"));
632 backGround.addActionListener(new ActionListener()
635 public void actionPerformed(ActionEvent actionEvent)
637 background_actionPerformed();
640 colourMenu.add(backGround);
643 * add colour buttons to a group so their selection is
644 * mutually exclusive (background colour is a separate option)
646 itemGroup.add(seqColour);
647 itemGroup.add(chainColour);
648 itemGroup.add(chargeColour);
649 itemGroup.add(viewerColour);
653 * Construct menu items
655 protected void initMenus()
657 AAStructureBindingModel binding = getBinding();
659 seqColour = new JRadioButtonMenuItem();
660 seqColour.setText(MessageManager.getString("action.by_sequence"));
661 seqColour.setName(ViewerColour.BySequence.name());
662 seqColour.setSelected(binding.isColourBySequence());
663 seqColour.addActionListener(new ActionListener()
666 public void actionPerformed(ActionEvent actionEvent)
668 seqColour_actionPerformed();
672 chainColour = new JRadioButtonMenuItem();
673 chainColour.setText(MessageManager.getString("action.by_chain"));
674 chainColour.setName(ViewerColour.ByChain.name());
675 chainColour.addActionListener(new ActionListener()
678 public void actionPerformed(ActionEvent actionEvent)
680 chainColour_actionPerformed();
684 chargeColour = new JRadioButtonMenuItem();
685 chargeColour.setText(MessageManager.getString("label.charge_cysteine"));
686 chargeColour.setName(ViewerColour.ChargeCysteine.name());
687 chargeColour.addActionListener(new ActionListener()
690 public void actionPerformed(ActionEvent actionEvent)
692 chargeColour_actionPerformed();
696 viewerColour = new JRadioButtonMenuItem();
698 .setText(MessageManager.getString("label.colour_with_viewer"));
699 viewerColour.setToolTipText(MessageManager
700 .getString("label.let_viewer_manage_structure_colours"));
701 viewerColour.setName(ViewerColour.ByViewer.name());
702 viewerColour.setSelected(!binding.isColourBySequence());
704 if (_colourwith == null)
706 _colourwith = new Vector<>();
708 if (_alignwith == null)
710 _alignwith = new Vector<>();
713 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
714 MessageManager.getString("label.colour_by"), this, _colourwith,
718 public void itemStateChanged(ItemEvent e)
720 if (!seqColour.isSelected())
726 // update the viewer display now.
727 seqColour_actionPerformed();
731 viewMenu.add(seqColourBy);
733 final ItemListener handler = new ItemListener()
736 public void itemStateChanged(ItemEvent e)
738 if (_alignwith.isEmpty())
740 alignStructs.setEnabled(false);
741 alignStructs.setToolTipText(null);
745 alignStructs.setEnabled(true);
746 alignStructs.setToolTipText(MessageManager.formatMessage(
747 "label.align_structures_using_linked_alignment_views",
752 viewSelectionMenu = new ViewSelectionMenu(
753 MessageManager.getString("label.superpose_with"), this,
754 _alignwith, handler);
755 handler.itemStateChanged(null);
756 viewerActionMenu.add(viewSelectionMenu, 0);
757 viewerActionMenu.addMenuListener(new MenuListener()
760 public void menuSelected(MenuEvent e)
762 handler.itemStateChanged(null);
766 public void menuDeselected(MenuEvent e)
771 public void menuCanceled(MenuEvent e)
776 viewerActionMenu.setText(getViewerName());
777 helpItem.setText(MessageManager.formatMessage("label.viewer_help",
784 * Sends commands to the structure viewer to superimpose structures based on
785 * currently associated alignments. May optionally return an error message for
789 protected String alignStructsWithAllAlignPanels()
791 if (getAlignmentPanel() == null)
796 if (_alignwith.size() == 0)
798 _alignwith.add(getAlignmentPanel());
804 reply = getBinding().superposeStructures(_alignwith);
805 if (reply != null && !reply.isEmpty())
807 String text = MessageManager
808 .formatMessage("error.superposition_failed", reply);
809 statusBar.setText(text);
811 } catch (Exception e)
813 StringBuffer sp = new StringBuffer();
814 for (AlignmentViewPanel alignPanel : _alignwith)
816 sp.append("'" + alignPanel.getViewName() + "' ");
818 Console.info("Couldn't align structures with the " + sp.toString()
819 + "associated alignment panels.", e);
825 * Opens a colour chooser dialog, and applies the chosen colour to the
826 * background of the structure viewer
829 public void background_actionPerformed()
831 String ttl = MessageManager.getString("label.select_background_colour");
832 ColourChooserListener listener = new ColourChooserListener()
835 public void colourSelected(Color c)
837 getBinding().setBackgroundColour(c);
840 JalviewColourChooser.showColourChooser(this, ttl, null, listener);
844 public void viewerColour_actionPerformed()
846 if (viewerColour.isSelected())
848 // disable automatic sequence colouring.
849 getBinding().setColourBySequence(false);
854 public void chainColour_actionPerformed()
856 chainColour.setSelected(true);
857 getBinding().colourByChain();
861 public void chargeColour_actionPerformed()
863 chargeColour.setSelected(true);
864 getBinding().colourByCharge();
868 public void seqColour_actionPerformed()
870 AAStructureBindingModel binding = getBinding();
871 binding.setColourBySequence(seqColour.isSelected());
872 if (_colourwith == null)
874 _colourwith = new Vector<>();
876 if (binding.isColourBySequence())
878 if (!binding.isLoadingFromArchive())
880 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
882 // Make the currently displayed alignment panel the associated view
883 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
886 // Set the colour using the current view for the associated alignframe
887 for (AlignmentViewPanel alignPanel : _colourwith)
889 binding.colourBySequence(alignPanel);
891 seqColoursApplied = true;
896 public void pdbFile_actionPerformed()
898 // TODO: JAL-3048 not needed for Jalview-JS - save PDB file
899 JalviewFileChooser chooser = new JalviewFileChooser(
900 Cache.getProperty("LAST_DIRECTORY"));
902 chooser.setFileView(new JalviewFileView());
903 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
904 chooser.setToolTipText(MessageManager.getString("action.save"));
906 int value = chooser.showSaveDialog(this);
908 if (value == JalviewFileChooser.APPROVE_OPTION)
910 BufferedReader in = null;
913 // TODO: cope with multiple PDB files in view
914 in = new BufferedReader(
915 new FileReader(getBinding().getStructureFiles()[0]));
916 File outFile = chooser.getSelectedFile();
918 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
920 while ((data = in.readLine()) != null)
922 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
928 } catch (Exception ex)
930 ex.printStackTrace();
938 } catch (IOException e)
948 public void viewMapping_actionPerformed()
950 CutAndPasteTransfer cap = new CutAndPasteTransfer();
953 cap.appendText(getBinding().printMappings());
954 } catch (OutOfMemoryError e)
957 "composing sequence-structure alignments for display in text box.",
962 Desktop.addInternalFrame(cap,
963 MessageManager.getString("label.pdb_sequence_mapping"), 550,
967 protected abstract String getViewerName();
970 * Configures the title and menu items of the viewer panel.
973 public void updateTitleAndMenus()
975 AAStructureBindingModel binding = getBinding();
976 if (binding.hasFileLoadingError())
981 setChainMenuItems(binding.getChainNames());
983 this.setTitle(binding.getViewerTitle(getViewerName(), true));
986 * enable 'Superpose with' if more than one mapped structure
988 viewSelectionMenu.setEnabled(false);
989 if (getBinding().getMappedStructureCount() > 1
990 && getBinding().getSequence().length > 1)
992 viewSelectionMenu.setEnabled(true);
996 * Show action menu if it has any enabled items
998 viewerActionMenu.setVisible(false);
999 for (int i = 0; i < viewerActionMenu.getItemCount(); i++)
1001 if (viewerActionMenu.getItem(i).isEnabled())
1003 viewerActionMenu.setVisible(true);
1008 if (!binding.isLoadingFromArchive())
1010 seqColour_actionPerformed();
1015 public String toString()
1021 public boolean hasMapping()
1023 if (worker != null && (addingStructures || _started))
1027 if (getBinding() == null)
1029 if (_aps == null || _aps.size() == 0)
1031 // viewer has been closed, but we did at some point run.
1036 String[] pdbids = getBinding().getStructureFiles();
1042 for (String pdbid:pdbids) {
1043 StructureMapping sm[] = getBinding().getSsm().getMapping(pdbid);
1044 if (sm!=null && sm.length>0 && sm[0]!=null) {
1048 // only return true if there is a mapping for every structure file we have loaded
1049 if (p == 0 || p != pdbids.length)
1053 // and that coloring has been applied
1054 return seqColoursApplied;
1058 public void raiseViewer()
1064 public long startProgressBar(String msg)
1066 // TODO would rather have startProgress/stopProgress as the
1067 // IProgressIndicator interface
1068 long tm = random.nextLong();
1069 if (progressBar != null)
1071 progressBar.setProgressBar(msg, tm);
1077 public void stopProgressBar(String msg, long handle)
1079 if (progressBar != null)
1081 progressBar.setProgressBar(msg, handle);
1085 protected IProgressIndicator getProgressIndicator()
1090 protected void setProgressIndicator(IProgressIndicator pi)
1095 public void setProgressMessage(String message, long id)
1097 if (progressBar != null)
1099 progressBar.setProgressBar(message, id);
1104 public void showConsole(boolean show)
1106 // default does nothing
1110 * Show only the selected chain(s) in the viewer
1112 protected void showSelectedChains()
1114 List<String> toshow = new ArrayList<>();
1115 for (int i = 0; i < chainMenu.getItemCount(); i++)
1117 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
1119 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
1120 if (item.isSelected())
1122 toshow.add(item.getText());
1126 getBinding().showChains(toshow);
1130 * Tries to fetch a PDB file and save to a temporary local file. Returns the
1131 * saved file path if successful, or null if not.
1133 * @param processingEntry
1136 protected String fetchPdbFile(PDBEntry processingEntry)
1138 String filePath = null;
1139 Pdb pdbclient = new Pdb();
1140 EBIAlfaFold afclient = new EBIAlfaFold();
1141 AlignmentI pdbseq = null;
1142 String pdbid = processingEntry.getId();
1143 long handle = System.currentTimeMillis()
1144 + Thread.currentThread().hashCode();
1147 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
1149 String msg = MessageManager.formatMessage("status.fetching_pdb",
1152 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
1153 // long hdl = startProgressBar(MessageManager.formatMessage(
1154 // "status.fetching_pdb", new Object[]
1158 if (afclient.isValidReference(pdbid))
1160 pdbseq = afclient.getSequenceRecords(pdbid,processingEntry.getRetrievalUrl());
1162 if (processingEntry.hasRetrievalUrl())
1164 String safePDBId = java.net.URLEncoder.encode(pdbid,"UTF-8").replace("%","__");
1166 // retrieve from URL to new local tmpfile
1167 File tmpFile = File.createTempFile(safePDBId,
1168 "." + (PDBEntry.Type.MMCIF.toString().equals(
1169 processingEntry.getType().toString()) ? "cif"
1171 String fromUrl = processingEntry.getRetrievalUrl();
1172 UrlDownloadClient.download(fromUrl, tmpFile);
1174 // may not need this check ?
1175 String file = tmpFile.getAbsolutePath();
1178 pdbseq = EBIAlfaFold.importDownloadedStructureFromUrl(fromUrl,tmpFile,pdbid,null,null,null);
1181 pdbseq = pdbclient.getSequenceRecords(pdbid);
1184 } catch (Exception e)
1187 "Error retrieving PDB id " + pdbid + ": " + e.getMessage());
1190 msg = pdbid + " " + MessageManager.getString("label.state_completed");
1191 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
1192 // stopProgressBar(msg, hdl);
1195 * If PDB data were saved and are not invalid (empty alignment), return the
1198 if (pdbseq != null && pdbseq.getHeight() > 0)
1200 // just use the file name from the first sequence's first PDBEntry
1201 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
1202 .elementAt(0).getFile()).getAbsolutePath();
1203 processingEntry.setFile(filePath);
1209 * If supported, saves the state of the structure viewer to a temporary file
1210 * and returns the file, else returns null
1214 public File saveSession()
1216 if (getBinding() == null) { return null;}
1217 File session = getBinding().saveSession();
1218 long l = session.length();
1223 } catch (InterruptedException e) {
1225 long nextl = session.length();
1236 * Close down this instance of Jalview's Chimera viewer, giving the user the
1237 * option to close the associated Chimera window (process). They may wish to
1238 * keep it open until they have had an opportunity to save any work.
1241 * if true, close any linked Chimera process; if false, prompt first
1244 public void closeViewer(boolean forceClose)
1246 AAStructureBindingModel binding = getBinding();
1247 if (binding != null && binding.isViewerRunning())
1251 String viewerName = getViewerName();
1252 String prompt = MessageManager
1253 .formatMessage("label.confirm_close_viewer", new Object[]
1254 { binding.getViewerTitle(viewerName, false), viewerName });
1255 prompt = JvSwingUtils.wrapTooltip(true, prompt);
1256 int confirm = JvOptionPane.showConfirmDialog(this, prompt,
1257 MessageManager.getString("label.close_viewer"),
1258 JvOptionPane.YES_NO_CANCEL_OPTION);
1260 * abort closure if user hits escape or Cancel
1262 if (confirm == JvOptionPane.CANCEL_OPTION
1263 || confirm == JvOptionPane.CLOSED_OPTION)
1267 forceClose = confirm == JvOptionPane.YES_OPTION;
1270 if (binding != null)
1272 binding.closeViewer(forceClose);
1274 setAlignmentPanel(null);
1277 _colourwith.clear();
1278 // TODO: check for memory leaks where instance isn't finalised because jmb
1279 // holds a reference to the window
1285 public void showHelp_actionPerformed()
1289 String url = getBinding().getHelpURL();
1292 BrowserLauncher.openURL(url);
1294 } catch (IOException ex)
1297 .println("Show " + getViewerName() + " failed with: "
1302 public boolean hasViewerActionsMenu()
1304 return viewerActionMenu != null && viewerActionMenu.isEnabled()
1305 && viewerActionMenu.getItemCount() > 0
1306 && viewerActionMenu.isVisible();