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 // TODO: refactor to allow concrete classes to register buttons for adding
226 // currently have to override to add buttons back in after they are cleared
228 for (Component c : viewerActionMenu.getMenuComponents())
230 if (c != alignStructs)
232 viewerActionMenu.remove((JMenuItem) c);
238 public AlignmentPanel getAlignmentPanel()
243 protected void setAlignmentPanel(AlignmentPanel alp)
249 public AlignmentPanel[] getAllAlignmentPanels()
251 AlignmentPanel[] t, list = new AlignmentPanel[0];
252 for (String setid : _aps)
254 AlignmentPanel[] panels = PaintRefresher.getAssociatedPanels(setid);
257 t = new AlignmentPanel[list.length + panels.length];
258 System.arraycopy(list, 0, t, 0, list.length);
259 System.arraycopy(panels, 0, t, list.length, panels.length);
268 * set the primary alignmentPanel reference and add another alignPanel to the
269 * list of ones to use for colouring and aligning
273 public void addAlignmentPanel(AlignmentPanel nap)
275 if (getAlignmentPanel() == null)
277 setAlignmentPanel(nap);
279 if (!_aps.contains(nap.av.getSequenceSetId()))
281 _aps.add(nap.av.getSequenceSetId());
286 * remove any references held to the given alignment panel
291 public void removeAlignmentPanel(AlignmentViewPanel nap)
295 _alignwith.remove(nap);
296 _colourwith.remove(nap);
297 if (getAlignmentPanel() == nap)
299 setAlignmentPanel(null);
300 for (AlignmentPanel aps : getAllAlignmentPanels())
304 setAlignmentPanel(aps);
309 } catch (Exception ex)
312 if (getAlignmentPanel() != null)
318 public void useAlignmentPanelForSuperposition(AlignmentPanel nap)
320 addAlignmentPanel(nap);
321 if (!_alignwith.contains(nap))
327 public void excludeAlignmentPanelForSuperposition(AlignmentPanel nap)
329 if (_alignwith.contains(nap))
331 _alignwith.remove(nap);
335 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap,
336 boolean enableColourBySeq)
338 useAlignmentPanelForColourbyseq(nap);
339 getBinding().setColourBySequence(enableColourBySeq);
340 seqColour.setSelected(enableColourBySeq);
341 viewerColour.setSelected(!enableColourBySeq);
344 public void useAlignmentPanelForColourbyseq(AlignmentPanel nap)
346 addAlignmentPanel(nap);
347 if (!_colourwith.contains(nap))
349 _colourwith.add(nap);
353 public void excludeAlignmentPanelForColourbyseq(AlignmentPanel nap)
355 if (_colourwith.contains(nap))
357 _colourwith.remove(nap);
361 public abstract ViewerType getViewerType();
364 * add a new structure (with associated sequences and chains) to this viewer,
365 * retrieving it if necessary first.
371 * if true, new structure(s) will be aligned using associated
375 protected void addStructure(final PDBEntry pdbentry,
376 final SequenceI[] seqs, final String[] chains,
377 final IProgressIndicator alignFrame)
379 if (pdbentry.getFile() == null)
381 if (worker != null && worker.isAlive())
383 // a retrieval is in progress, wait around and add ourselves to the
385 new Thread(new Runnable()
390 while (worker != null && worker.isAlive() && _started)
394 Thread.sleep(100 + ((int) Math.random() * 100));
396 } catch (Exception e)
400 // and call ourselves again.
401 addStructure(pdbentry, seqs, chains, alignFrame);
407 // otherwise, start adding the structure.
408 getBinding().addSequenceAndChain(new PDBEntry[] { pdbentry },
410 { seqs }, new String[][] { chains });
411 addingStructures = true;
413 worker = new Thread(this);
418 protected boolean hasPdbId(String pdbId)
420 return getBinding().hasPdbId(pdbId);
424 * Returns a list of any viewer of the instantiated type. The list is
425 * restricted to those linked to the given alignment panel if it is not null.
427 protected List<StructureViewerBase> getViewersFor(AlignmentPanel alp)
429 return Desktop.instance.getStructureViewers(alp, this.getClass());
433 public void addToExistingViewer(PDBEntry pdbentry, SequenceI[] seq,
434 String[] chains, final AlignmentViewPanel apanel, String pdbId)
437 * JAL-1742 exclude view with this structure already mapped (don't offer
438 * to align chain B to chain A of the same structure); code may defend
439 * against this possibility before we reach here
445 AlignmentPanel alignPanel = (AlignmentPanel) apanel; // Implementation error if this
447 useAlignmentPanelForSuperposition(alignPanel);
448 addStructure(pdbentry, seq, chains, alignPanel.alignFrame);
452 * Adds mappings for the given sequences to an already opened PDB structure,
453 * and updates any viewers that have the PDB file
460 public void addSequenceMappingsToStructure(SequenceI[] seq,
461 String[] chains, final AlignmentViewPanel alpanel,
464 AlignmentPanel apanel = (AlignmentPanel) alpanel;
466 // TODO : Fix multiple seq to one chain issue here.
468 * create the mappings
470 apanel.getStructureSelectionManager().setMapping(seq, chains,
471 pdbFilename, DataSourceType.FILE, getProgressIndicator());
474 * alert the FeatureRenderer to show new (PDB RESNUM) features
476 if (apanel.getSeqPanel().seqCanvas.fr != null)
478 apanel.getSeqPanel().seqCanvas.fr.featuresAdded();
479 // note - we don't do a refresh for structure here because we do it
480 // explicitly for all panels later on
481 apanel.paintAlignment(true, false);
485 * add the sequences to any other viewers (of the same type) for this pdb
488 // JBPNOTE: this looks like a binding routine, rather than a gui routine
489 for (StructureViewerBase viewer : getViewersFor(null))
491 AAStructureBindingModel bindingModel = viewer.getBinding();
492 for (int pe = 0; pe < bindingModel.getPdbCount(); pe++)
494 if (bindingModel.getPdbEntry(pe).getFile().equals(pdbFilename))
496 bindingModel.addSequence(pe, seq);
497 viewer.addAlignmentPanel(apanel);
499 * add it to the set of alignments used for colouring structure by
502 viewer.useAlignmentPanelForColourbyseq(apanel);
503 viewer.buildActionMenu();
504 apanel.getStructureSelectionManager()
505 .sequenceColoursChanged(apanel);
513 public boolean addAlreadyLoadedFile(SequenceI[] seq, String[] chains,
514 final AlignmentViewPanel apanel, String pdbId)
516 String alreadyMapped = apanel.getStructureSelectionManager()
517 .alreadyMappedToFile(pdbId);
519 if (alreadyMapped == null)
524 addSequenceMappingsToStructure(seq, chains, apanel, alreadyMapped);
528 void setChainMenuItems(List<String> chainNames)
530 chainMenu.removeAll();
531 if (chainNames == null || chainNames.isEmpty())
535 JMenuItem menuItem = new JMenuItem(
536 MessageManager.getString("label.all"));
537 menuItem.addActionListener(new ActionListener()
540 public void actionPerformed(ActionEvent evt)
542 allChainsSelected = true;
543 for (int i = 0; i < chainMenu.getItemCount(); i++)
545 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
547 ((JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
550 showSelectedChains();
551 allChainsSelected = false;
555 chainMenu.add(menuItem);
557 for (String chain : chainNames)
559 menuItem = new JCheckBoxMenuItem(chain, true);
560 menuItem.addItemListener(new ItemListener()
563 public void itemStateChanged(ItemEvent evt)
565 if (!allChainsSelected)
567 showSelectedChains();
572 chainMenu.add(menuItem);
577 * Action on selecting one of Jalview's registered colour schemes
580 public void changeColour_actionPerformed(String colourSchemeName)
582 AlignmentI al = getAlignmentPanel().av.getAlignment();
583 ColourSchemeI cs = ColourSchemes.getInstance()
584 .getColourScheme(colourSchemeName, getAlignmentPanel().av, al,
586 getBinding().colourByJalviewColourScheme(cs);
590 * Builds the colour menu
592 protected void buildColourMenu()
594 colourMenu.removeAll();
595 AlignmentI al = getAlignmentPanel().av.getAlignment();
598 * add colour by sequence, by chain, by charge and cysteine
600 colourMenu.add(seqColour);
601 colourMenu.add(chainColour);
602 colourMenu.add(chargeColour);
603 chargeColour.setEnabled(!al.isNucleotide());
606 * add all 'simple' (per-residue) colour schemes registered to Jalview
608 ButtonGroup itemGroup = ColourMenuHelper.addMenuItems(colourMenu, this,
612 * add 'colour by viewer' (menu item text is set in subclasses)
614 viewerColour.setSelected(false);
615 viewerColour.addActionListener(new ActionListener()
618 public void actionPerformed(ActionEvent actionEvent)
620 viewerColour_actionPerformed();
623 colourMenu.add(viewerColour);
626 * add 'set background colour'
628 JMenuItem backGround = new JMenuItem();
630 .setText(MessageManager.getString("action.background_colour"));
631 backGround.addActionListener(new ActionListener()
634 public void actionPerformed(ActionEvent actionEvent)
636 background_actionPerformed();
639 colourMenu.add(backGround);
642 * add colour buttons to a group so their selection is
643 * mutually exclusive (background colour is a separate option)
645 itemGroup.add(seqColour);
646 itemGroup.add(chainColour);
647 itemGroup.add(chargeColour);
648 itemGroup.add(viewerColour);
652 * Construct menu items
654 protected void initMenus()
656 AAStructureBindingModel binding = getBinding();
658 seqColour = new JRadioButtonMenuItem();
659 seqColour.setText(MessageManager.getString("action.by_sequence"));
660 seqColour.setName(ViewerColour.BySequence.name());
661 seqColour.setSelected(binding.isColourBySequence());
662 seqColour.addActionListener(new ActionListener()
665 public void actionPerformed(ActionEvent actionEvent)
667 seqColour_actionPerformed();
671 chainColour = new JRadioButtonMenuItem();
672 chainColour.setText(MessageManager.getString("action.by_chain"));
673 chainColour.setName(ViewerColour.ByChain.name());
674 chainColour.addActionListener(new ActionListener()
677 public void actionPerformed(ActionEvent actionEvent)
679 chainColour_actionPerformed();
683 chargeColour = new JRadioButtonMenuItem();
684 chargeColour.setText(MessageManager.getString("label.charge_cysteine"));
685 chargeColour.setName(ViewerColour.ChargeCysteine.name());
686 chargeColour.addActionListener(new ActionListener()
689 public void actionPerformed(ActionEvent actionEvent)
691 chargeColour_actionPerformed();
695 viewerColour = new JRadioButtonMenuItem();
697 .setText(MessageManager.getString("label.colour_with_viewer"));
698 viewerColour.setToolTipText(MessageManager
699 .getString("label.let_viewer_manage_structure_colours"));
700 viewerColour.setName(ViewerColour.ByViewer.name());
701 viewerColour.setSelected(!binding.isColourBySequence());
703 if (_colourwith == null)
705 _colourwith = new Vector<>();
707 if (_alignwith == null)
709 _alignwith = new Vector<>();
712 ViewSelectionMenu seqColourBy = new ViewSelectionMenu(
713 MessageManager.getString("label.colour_by"), this, _colourwith,
717 public void itemStateChanged(ItemEvent e)
719 if (!seqColour.isSelected())
725 // update the viewer display now.
726 seqColour_actionPerformed();
730 viewMenu.add(seqColourBy);
732 final ItemListener handler = new ItemListener()
735 public void itemStateChanged(ItemEvent e)
737 if (_alignwith.isEmpty())
739 alignStructs.setEnabled(false);
740 alignStructs.setToolTipText(null);
744 alignStructs.setEnabled(true);
745 alignStructs.setToolTipText(MessageManager.formatMessage(
746 "label.align_structures_using_linked_alignment_views",
751 viewSelectionMenu = new ViewSelectionMenu(
752 MessageManager.getString("label.superpose_with"), this,
753 _alignwith, handler);
754 handler.itemStateChanged(null);
755 viewerActionMenu.add(viewSelectionMenu, 0);
756 viewerActionMenu.addMenuListener(new MenuListener()
759 public void menuSelected(MenuEvent e)
761 handler.itemStateChanged(null);
765 public void menuDeselected(MenuEvent e)
770 public void menuCanceled(MenuEvent e)
775 viewerActionMenu.setText(getViewerName());
776 helpItem.setText(MessageManager.formatMessage("label.viewer_help",
783 * Sends commands to the structure viewer to superimpose structures based on
784 * currently associated alignments. May optionally return an error message for
788 protected String alignStructsWithAllAlignPanels()
790 if (getAlignmentPanel() == null)
795 if (_alignwith.size() == 0)
797 _alignwith.add(getAlignmentPanel());
803 reply = getBinding().superposeStructures(_alignwith);
804 if (reply != null && !reply.isEmpty())
806 String text = MessageManager
807 .formatMessage("error.superposition_failed", reply);
808 statusBar.setText(text);
810 } catch (Exception e)
812 StringBuffer sp = new StringBuffer();
813 for (AlignmentViewPanel alignPanel : _alignwith)
815 sp.append("'" + alignPanel.getViewName() + "' ");
817 Cache.log.info("Couldn't align structures with the " + sp.toString()
818 + "associated alignment panels.", e);
824 * Opens a colour chooser dialog, and applies the chosen colour to the
825 * background of the structure viewer
828 public void background_actionPerformed()
830 String ttl = MessageManager.getString("label.select_background_colour");
831 ColourChooserListener listener = new ColourChooserListener()
834 public void colourSelected(Color c)
836 getBinding().setBackgroundColour(c);
839 JalviewColourChooser.showColourChooser(this, ttl, null, listener);
843 public void viewerColour_actionPerformed()
845 if (viewerColour.isSelected())
847 // disable automatic sequence colouring.
848 getBinding().setColourBySequence(false);
853 public void chainColour_actionPerformed()
855 chainColour.setSelected(true);
856 getBinding().colourByChain();
860 public void chargeColour_actionPerformed()
862 chargeColour.setSelected(true);
863 getBinding().colourByCharge();
867 public void seqColour_actionPerformed()
869 AAStructureBindingModel binding = getBinding();
870 binding.setColourBySequence(seqColour.isSelected());
871 if (_colourwith == null)
873 _colourwith = new Vector<>();
875 if (binding.isColourBySequence())
877 if (!binding.isLoadingFromArchive())
879 if (_colourwith.size() == 0 && getAlignmentPanel() != null)
881 // Make the currently displayed alignment panel the associated view
882 _colourwith.add(getAlignmentPanel().alignFrame.alignPanel);
885 // Set the colour using the current view for the associated alignframe
886 for (AlignmentViewPanel alignPanel : _colourwith)
888 binding.colourBySequence(alignPanel);
890 seqColoursApplied = true;
895 public void pdbFile_actionPerformed()
897 // TODO: JAL-3048 not needed for Jalview-JS - save PDB file
898 JalviewFileChooser chooser = new JalviewFileChooser(
899 Cache.getProperty("LAST_DIRECTORY"));
901 chooser.setFileView(new JalviewFileView());
902 chooser.setDialogTitle(MessageManager.getString("label.save_pdb_file"));
903 chooser.setToolTipText(MessageManager.getString("action.save"));
905 int value = chooser.showSaveDialog(this);
907 if (value == JalviewFileChooser.APPROVE_OPTION)
909 BufferedReader in = null;
912 // TODO: cope with multiple PDB files in view
913 in = new BufferedReader(
914 new FileReader(getBinding().getStructureFiles()[0]));
915 File outFile = chooser.getSelectedFile();
917 PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
919 while ((data = in.readLine()) != null)
921 if (!(data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1))
927 } catch (Exception ex)
929 ex.printStackTrace();
937 } catch (IOException e)
947 public void viewMapping_actionPerformed()
949 CutAndPasteTransfer cap = new CutAndPasteTransfer();
952 cap.appendText(getBinding().printMappings());
953 } catch (OutOfMemoryError e)
956 "composing sequence-structure alignments for display in text box.",
961 Desktop.addInternalFrame(cap,
962 MessageManager.getString("label.pdb_sequence_mapping"), 550,
966 protected abstract String getViewerName();
969 * Configures the title and menu items of the viewer panel.
972 public void updateTitleAndMenus()
974 AAStructureBindingModel binding = getBinding();
975 if (binding.hasFileLoadingError())
980 setChainMenuItems(binding.getChainNames());
982 this.setTitle(binding.getViewerTitle(getViewerName(), true));
985 * enable 'Superpose with' if more than one mapped structure
987 viewSelectionMenu.setEnabled(false);
988 if (getBinding().getMappedStructureCount() > 1
989 && getBinding().getSequence().length > 1)
991 viewSelectionMenu.setEnabled(true);
995 * Show action menu if it has any enabled items
997 viewerActionMenu.setVisible(false);
998 for (int i = 0; i < viewerActionMenu.getItemCount(); i++)
1000 if (viewerActionMenu.getItem(i).isEnabled())
1002 viewerActionMenu.setVisible(true);
1007 if (!binding.isLoadingFromArchive())
1009 seqColour_actionPerformed();
1014 public String toString()
1020 public boolean hasMapping()
1022 if (worker != null && (addingStructures || _started))
1026 if (getBinding() == null)
1028 if (_aps == null || _aps.size() == 0)
1030 // viewer has been closed, but we did at some point run.
1035 String[] pdbids = getBinding().getStructureFiles();
1041 for (String pdbid:pdbids) {
1042 StructureMapping sm[] = getBinding().getSsm().getMapping(pdbid);
1043 if (sm!=null && sm.length>0 && sm[0]!=null) {
1047 // only return true if there is a mapping for every structure file we have loaded
1048 if (p == 0 || p != pdbids.length)
1052 // and that coloring has been applied
1053 return seqColoursApplied;
1057 public void raiseViewer()
1063 public long startProgressBar(String msg)
1065 // TODO would rather have startProgress/stopProgress as the
1066 // IProgressIndicator interface
1067 long tm = random.nextLong();
1068 if (progressBar != null)
1070 progressBar.setProgressBar(msg, tm);
1076 public void stopProgressBar(String msg, long handle)
1078 if (progressBar != null)
1080 progressBar.setProgressBar(msg, handle);
1084 protected IProgressIndicator getProgressIndicator()
1089 protected void setProgressIndicator(IProgressIndicator pi)
1094 public void setProgressMessage(String message, long id)
1096 if (progressBar != null)
1098 progressBar.setProgressBar(message, id);
1103 public void showConsole(boolean show)
1105 // default does nothing
1109 * Show only the selected chain(s) in the viewer
1111 protected void showSelectedChains()
1113 List<String> toshow = new ArrayList<>();
1114 for (int i = 0; i < chainMenu.getItemCount(); i++)
1116 if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
1118 JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
1119 if (item.isSelected())
1121 toshow.add(item.getText());
1125 getBinding().showChains(toshow);
1129 * Tries to fetch a PDB file and save to a temporary local file. Returns the
1130 * saved file path if successful, or null if not.
1132 * @param processingEntry
1135 protected String fetchPdbFile(PDBEntry processingEntry)
1137 String filePath = null;
1138 Pdb pdbclient = new Pdb();
1139 EBIAlfaFold afclient = new EBIAlfaFold();
1140 AlignmentI pdbseq = null;
1141 String pdbid = processingEntry.getId();
1142 long handle = System.currentTimeMillis()
1143 + Thread.currentThread().hashCode();
1146 * Write 'fetching PDB' progress on AlignFrame as we are not yet visible
1148 String msg = MessageManager.formatMessage("status.fetching_pdb",
1151 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
1152 // long hdl = startProgressBar(MessageManager.formatMessage(
1153 // "status.fetching_pdb", new Object[]
1157 if (afclient.isValidReference(pdbid))
1159 pdbseq = afclient.getSequenceRecords(pdbid,processingEntry.getRetrievalUrl());
1161 if (processingEntry.hasRetrievalUrl())
1163 String safePDBId = java.net.URLEncoder.encode(pdbid,"UTF-8");
1165 // retrieve from URL to new local tmpfile
1166 File tmpFile = File.createTempFile(safePDBId,
1167 "." + (PDBEntry.Type.MMCIF.toString().equals(
1168 processingEntry.getType().toString()) ? "cif"
1170 String fromUrl = processingEntry.getRetrievalUrl();
1171 UrlDownloadClient.download(fromUrl, tmpFile);
1173 // may not need this check ?
1174 String file = tmpFile.getAbsolutePath();
1177 pdbseq = EBIAlfaFold.importDownloadedStructureFromUrl(fromUrl,tmpFile,pdbid,null,null,null);
1180 pdbseq = pdbclient.getSequenceRecords(pdbid);
1183 } catch (Exception e)
1186 "Error retrieving PDB id " + pdbid + ": " + e.getMessage());
1189 msg = pdbid + " " + MessageManager.getString("label.state_completed");
1190 getAlignmentPanel().alignFrame.setProgressBar(msg, handle);
1191 // stopProgressBar(msg, hdl);
1194 * If PDB data were saved and are not invalid (empty alignment), return the
1197 if (pdbseq != null && pdbseq.getHeight() > 0)
1199 // just use the file name from the first sequence's first PDBEntry
1200 filePath = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
1201 .elementAt(0).getFile()).getAbsolutePath();
1202 processingEntry.setFile(filePath);
1208 * If supported, saves the state of the structure viewer to a temporary file
1209 * and returns the file, else returns null
1213 public File saveSession()
1215 if (getBinding() == null) { return null;}
1216 File session = getBinding().saveSession();
1217 long l = session.length();
1222 } catch (InterruptedException e) {
1224 long nextl = session.length();
1235 * Close down this instance of Jalview's Chimera viewer, giving the user the
1236 * option to close the associated Chimera window (process). They may wish to
1237 * keep it open until they have had an opportunity to save any work.
1240 * if true, close any linked Chimera process; if false, prompt first
1243 public void closeViewer(boolean forceClose)
1245 AAStructureBindingModel binding = getBinding();
1246 if (binding != null && binding.isViewerRunning())
1250 String viewerName = getViewerName();
1251 String prompt = MessageManager
1252 .formatMessage("label.confirm_close_viewer", new Object[]
1253 { binding.getViewerTitle(viewerName, false), viewerName });
1254 prompt = JvSwingUtils.wrapTooltip(true, prompt);
1255 int confirm = JvOptionPane.showConfirmDialog(this, prompt,
1256 MessageManager.getString("label.close_viewer"),
1257 JvOptionPane.YES_NO_CANCEL_OPTION);
1259 * abort closure if user hits escape or Cancel
1261 if (confirm == JvOptionPane.CANCEL_OPTION
1262 || confirm == JvOptionPane.CLOSED_OPTION)
1266 forceClose = confirm == JvOptionPane.YES_OPTION;
1269 if (binding != null)
1271 binding.closeViewer(forceClose);
1273 setAlignmentPanel(null);
1276 _colourwith.clear();
1277 // TODO: check for memory leaks where instance isn't finalised because jmb
1278 // holds a reference to the window
1284 public void showHelp_actionPerformed()
1288 String url = getBinding().getHelpURL();
1291 BrowserLauncher.openURL(url);
1293 } catch (IOException ex)
1296 .println("Show " + getViewerName() + " failed with: "
1301 public boolean hasViewerActionsMenu()
1303 return viewerActionMenu != null && viewerActionMenu.isEnabled()
1304 && viewerActionMenu.getItemCount() > 0
1305 && viewerActionMenu.isVisible();