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.Container;
25 import java.util.ArrayList;
26 import java.util.List;
29 import javax.swing.JComponent;
31 import org.jmol.api.JmolAppConsoleInterface;
32 import org.openscience.jmol.app.jmolpanel.console.AppConsole;
34 import jalview.api.AlignmentViewPanel;
35 import jalview.api.structures.JalviewStructureDisplayI;
36 import jalview.bin.Console;
37 import jalview.datamodel.AlignmentI;
38 import jalview.datamodel.PDBEntry;
39 import jalview.datamodel.SequenceI;
40 import jalview.ext.jmol.JalviewJmolBinding;
41 import jalview.io.DataSourceType;
42 import jalview.structure.StructureSelectionManager;
43 import jalview.util.MessageManager;
44 import jalview.util.Platform;
45 import jalview.ws.dbsources.EBIAlfaFold;
46 import jalview.ws.dbsources.Pdb;
47 import jalview.ws.utils.UrlDownloadClient;
48 import javajs.util.BS;
50 public class AppJmolBinding extends JalviewJmolBinding
52 public AppJmolBinding(AppJmol appJmol, StructureSelectionManager sSm,
53 PDBEntry[] pdbentry, SequenceI[][] sequenceIs,
54 DataSourceType protocol)
56 super(sSm, pdbentry, sequenceIs, protocol);
61 public SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment)
63 return new SequenceRenderer(((AlignmentPanel) alignment).av);
67 public void sendConsoleEcho(String strEcho)
71 console.sendConsoleEcho(strEcho);
76 public void sendConsoleMessage(String strStatus)
78 if (console != null && strStatus != null)
79 // && !strStatus.equals("Script completed"))
80 // should we squash the script completed string ?
82 console.sendConsoleMessage(strStatus);
87 public void showUrl(String url, String target)
91 jalview.util.BrowserLauncher.openURL(url);
94 Console.error("Failed to launch Jmol-associated url " + url, e);
95 // TODO: 2.6 : warn user if browser was not configured.
100 public void refreshGUI()
102 if (getMappedStructureCount() == 0)
107 // appJmolWindow.repaint();
108 javax.swing.SwingUtilities.invokeLater(new Runnable()
113 JalviewStructureDisplayI theViewer = getViewer();
114 // invokes colourbySequence() via seqColour_ActionPerformed()
115 theViewer.updateTitleAndMenus();
116 ((JComponent) theViewer).revalidate();
122 public void notifyScriptTermination(String strStatus, int msWalltime)
124 // todo - script termination doesn't happen ?
125 // if (console != null)
126 // console.notifyScriptTermination(strStatus,
131 public void showUrl(String url)
133 showUrl(url, "jmol");
136 public void newJmolPopup(String menuName)
138 // jmolpopup = new JmolAwtPopup();
139 // jmolpopup.jpiInitialize((viewer), menuName);
143 public void selectionChanged(BS arg0)
148 public void showConsole(boolean b)
150 getViewer().showConsole(b);
154 protected JmolAppConsoleInterface createJmolConsole(
155 Container consolePanel, String buttonsToShow)
157 jmolViewer.setJmolCallbackListener(this);
158 // BH comment: can't do this yet [for JS only, or generally?]
159 return Platform.isJS() ? null
160 : new AppConsole(jmolViewer, consolePanel, buttonsToShow);
164 protected void releaseUIResources()
171 public void releaseReferences(Object svl)
173 if (svl instanceof SeqPanel)
175 getViewer().removeAlignmentPanel(((SeqPanel) svl).ap);
180 public Map<String, Object> getJSpecViewProperty(String arg0)
182 // TODO Auto-generated method stub
186 @SuppressWarnings("unused")
187 public void cacheFiles(List<File> files)
195 Platform.cacheFileData(f);
200 * Retrieves and saves as file any modelled PDB entries for which we do not
201 * already have a file saved. Returns a list of absolute paths to structure
202 * files which were either retrieved, or already stored but not modelled in
203 * the structure viewer (i.e. files to add to the viewer display).
205 * Currently only used by Jmol - similar but different code used for Chimera/X
206 * and Pymol so still need to refactor
208 * @param structureViewer
209 * UI proxy for the structure viewer
210 * @return list of absolute paths to structures retrieved that need to be
211 * added to the display
213 public List<String> fetchPdbFiles(StructureViewerBase structureViewer)
215 // todo - record which pdbids were successfully imported.
216 StringBuilder errormsgs = new StringBuilder();
218 List<String> files = new ArrayList<>();
222 String[] filesInViewer = getStructureFiles();
223 // TODO: replace with reference fetching/transfer code (validate PDBentry
226 for (int pi = 0; pi < getPdbCount(); pi++)
228 PDBEntry strucEntry = getPdbEntry(pi);
230 String file = strucEntry.getFile();
233 pdbid = strucEntry.getId();
236 file = structureViewer.fetchPdbFile(strucEntry);
237 } catch (OutOfMemoryError oomerror)
239 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
240 } catch (Exception ex)
242 ex.printStackTrace();
243 errormsgs.append("'").append(pdbid).append("'");
252 errormsgs.append("'").append(pdbid).append("' ");
257 if (filesInViewer != null && filesInViewer.length > 0)
259 structureViewer.setAddingStructures(true); // already files loaded.
260 for (int c = 0; c < filesInViewer.length; c++)
262 if (Platform.pathEquals(filesInViewer[c], file))
275 } catch (OutOfMemoryError oomerror)
277 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
278 } catch (Exception ex)
280 ex.printStackTrace();
281 errormsgs.append("When retrieving pdbfiles : current was: '")
282 .append(pdbid).append("'");
284 if (errormsgs.length() > 0)
286 JvOptionPane.showInternalMessageDialog(Desktop.getInstance(),
287 MessageManager.formatMessage(
288 "label.pdb_entries_couldnt_be_retrieved", new String[]
289 { errormsgs.toString() }),
290 MessageManager.getString("label.couldnt_load_file"),
291 JvOptionPane.ERROR_MESSAGE);