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;
30 import javax.swing.SwingUtilities;
32 import org.jmol.api.AtomIndexIterator;
33 import org.jmol.api.JmolAppConsoleInterface;
34 import org.jmol.modelset.Atom;
35 import org.jmol.modelset.Model;
36 import org.openscience.jmol.app.jmolpanel.console.AppConsole;
38 import jalview.api.AlignmentViewPanel;
39 import jalview.api.structures.JalviewStructureDisplayI;
40 import jalview.bin.Cache;
41 import jalview.datamodel.AlignmentI;
42 import jalview.datamodel.PDBEntry;
43 import jalview.datamodel.SequenceI;
44 import jalview.ext.jmol.JalviewJmolBinding;
45 import jalview.io.DataSourceType;
46 import jalview.structure.AtomSpec;
47 import jalview.structure.StructureSelectionManager;
48 import jalview.util.MessageManager;
49 import jalview.util.Platform;
50 import jalview.ws.dbsources.EBIAlfaFold;
51 import jalview.ws.dbsources.Pdb;
52 import jalview.ws.utils.UrlDownloadClient;
53 import javajs.util.BS;
55 public class AppJmolBinding extends JalviewJmolBinding
57 public AppJmolBinding(AppJmol appJmol, StructureSelectionManager sSm,
58 PDBEntry[] pdbentry, SequenceI[][] sequenceIs,
59 DataSourceType protocol)
61 super(sSm, pdbentry, sequenceIs, protocol);
66 public SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment)
68 return new SequenceRenderer(((AlignmentPanel) alignment).av);
72 public void sendConsoleEcho(String strEcho)
76 console.sendConsoleEcho(strEcho);
81 public void sendConsoleMessage(String strStatus)
83 if (console != null && strStatus != null)
84 // && !strStatus.equals("Script completed"))
85 // should we squash the script completed string ?
87 console.sendConsoleMessage(strStatus);
92 public void showUrl(String url, String target)
96 jalview.util.BrowserLauncher.openURL(url);
99 Cache.log.error("Failed to launch Jmol-associated url " + url, e);
100 // TODO: 2.6 : warn user if browser was not configured.
105 public void refreshGUI()
107 if (getMappedStructureCount() == 0)
112 // appJmolWindow.repaint();
113 javax.swing.SwingUtilities.invokeLater(new Runnable()
118 JalviewStructureDisplayI theViewer = getViewer();
119 // invokes colourbySequence() via seqColour_ActionPerformed()
120 theViewer.updateTitleAndMenus();
121 ((JComponent) theViewer).revalidate();
127 public void notifyScriptTermination(String strStatus, int msWalltime)
129 // todo - script termination doesn't happen ?
130 // if (console != null)
131 // console.notifyScriptTermination(strStatus,
136 public void showUrl(String url)
138 showUrl(url, "jmol");
141 public void newJmolPopup(String menuName)
143 // jmolpopup = new JmolAwtPopup();
144 // jmolpopup.jpiInitialize((viewer), menuName);
148 public void selectionChanged(BS arg0)
150 SwingUtilities.invokeLater(new Runnable() {
157 public void showConsole(boolean b)
159 getViewer().showConsole(b);
163 protected JmolAppConsoleInterface createJmolConsole(
164 Container consolePanel, String buttonsToShow)
166 jmolViewer.setJmolCallbackListener(this);
167 // BH comment: can't do this yet [for JS only, or generally?]
168 return Platform.isJS() ? null
169 : new AppConsole(jmolViewer, consolePanel, buttonsToShow);
173 protected void releaseUIResources()
180 public void releaseReferences(Object svl)
182 if (svl instanceof SeqPanel)
184 getViewer().removeAlignmentPanel(((SeqPanel) svl).ap);
189 public Map<String, Object> getJSpecViewProperty(String arg0)
191 // TODO Auto-generated method stub
195 @SuppressWarnings("unused")
196 public void cacheFiles(List<File> files)
204 Platform.cacheFileData(f);
209 * Retrieves and saves as file any modelled PDB entries for which we do not
210 * already have a file saved. Returns a list of absolute paths to structure
211 * files which were either retrieved, or already stored but not modelled in
212 * the structure viewer (i.e. files to add to the viewer display).
214 * Currently only used by Jmol - similar but different code used for Chimera/X
215 * and Pymol so still need to refactor
217 * @param structureViewer
218 * UI proxy for the structure viewer
219 * @return list of absolute paths to structures retrieved that need to be
220 * added to the display
222 public List<String> fetchPdbFiles(StructureViewerBase structureViewer)
224 // todo - record which pdbids were successfully imported.
225 StringBuilder errormsgs = new StringBuilder();
227 List<String> files = new ArrayList<>();
231 String[] filesInViewer = getStructureFiles();
232 // TODO: replace with reference fetching/transfer code (validate PDBentry
235 for (int pi = 0; pi < getPdbCount(); pi++)
237 PDBEntry strucEntry = getPdbEntry(pi);
239 String file = strucEntry.getFile();
242 pdbid = strucEntry.getId();
244 file = structureViewer.fetchPdbFile(strucEntry);
245 } catch (OutOfMemoryError oomerror)
247 new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
248 } catch (Exception ex)
250 ex.printStackTrace();
251 errormsgs.append("'").append(pdbid).append("'");
260 errormsgs.append("'").append(pdbid).append("' ");
265 if (filesInViewer != null && filesInViewer.length > 0)
267 structureViewer.setAddingStructures(true); // already files loaded.
268 for (int c = 0; c < filesInViewer.length; c++)
270 if (Platform.pathEquals(filesInViewer[c], file))
283 } catch (OutOfMemoryError oomerror)
285 new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
286 } catch (Exception ex)
288 ex.printStackTrace();
289 errormsgs.append("When retrieving pdbfiles : current was: '")
290 .append(pdbid).append("'");
292 if (errormsgs.length() > 0)
294 JvOptionPane.showInternalMessageDialog(Desktop.desktop,
295 MessageManager.formatMessage(
296 "label.pdb_entries_couldnt_be_retrieved", new String[]
297 { errormsgs.toString() }),
298 MessageManager.getString("label.couldnt_load_file"),
299 JvOptionPane.ERROR_MESSAGE);