2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.ext.jmol;
20 import java.io.IOException;
21 import java.util.Hashtable;
24 import org.jmol.api.JmolStatusListener;
25 import org.jmol.api.JmolViewer;
26 import org.jmol.constant.EnumCallback;
27 import org.jmol.modelset.Group;
28 import org.jmol.modelset.Model;
29 import org.jmol.modelset.ModelSet;
30 import org.jmol.modelset.Polymer;
31 import org.jmol.modelsetbio.BioPolymer;
32 import org.jmol.viewer.Viewer;
33 import org.openscience.jmol.app.JmolApp;
35 import jalview.datamodel.AlignmentAnnotation;
36 import jalview.datamodel.Annotation;
37 import jalview.datamodel.PDBEntry;
38 import jalview.datamodel.Sequence;
39 import jalview.datamodel.SequenceI;
40 import jalview.io.AlignFile;
41 import jalview.io.FileParse;
44 * Import and process PDB files with Jmol
49 public class PDBFileWithJmol extends AlignFile implements
53 JmolApp jmolApp = null;
57 public PDBFileWithJmol(String inFile, String type)
64 public PDBFileWithJmol(FileParse fp) throws IOException
69 public PDBFileWithJmol()
71 // TODO Auto-generated constructor stub
75 * create a headless jmol instance for dataprocessing
79 private Viewer getJmolData()
82 { // note that -o -n -x are all implied
83 jmolApp = new JmolApp();
84 jmolApp.isDataOnly = true;
85 jmolApp.haveConsole = false;
86 jmolApp.haveDisplay = false;
87 jmolApp.exitUponCompletion = true;
90 viewer = (Viewer) JmolViewer.allocateViewer(null, null, null, null,
91 null, jmolApp.commandOptions, this);
92 viewer.setScreenDimension(jmolApp.startupWidth,
93 jmolApp.startupHeight);
94 jmolApp.startViewer(viewer, null);
95 } catch (ClassCastException x)
99 + JmolViewer.getJmolVersion()
100 + " is not compatible with this version of Jalview. Report this problem at issues.jalview.org",
107 private void waitForScript(Viewer jmd)
109 while (jmd.isScriptExecuting())
115 } catch (InterruptedException x)
124 * @see jalview.io.AlignFile#parse()
127 public void parse() throws IOException
129 Viewer jmd = getJmolData();
130 jmd.openReader(getDataName(), getDataName(), getReader());
132 if (jmd.getModelCount() > 0)
134 ModelSet ms = jmd.getModelSet();
135 String structs = ms.calculateStructures(null, true, false, true);
136 // System.out.println("Structs\n"+structs);
137 for (Model model : ms.getModels())
139 for (int _bp = 0, _bpc = model.getBioPolymerCount(); _bp < _bpc; _bp++)
141 Polymer bp = model.getBioPolymer(_bp);
142 if (bp instanceof BioPolymer)
144 BioPolymer biopoly = (BioPolymer) bp;
145 char _lastChainId = 0;
146 int[] groups = biopoly.getLeadAtomIndices();
147 Group[] bpgrp = biopoly.getGroups();
148 char seq[] = new char[groups.length], secstr[] = new char[groups.length], secstrcode[] = new char[groups.length];
149 int groupc = 0, len = 0, firstrnum = 1, lastrnum = 0;
152 if (groupc >= groups.length
153 || ms.atoms[groups[groupc]].getChainID() != _lastChainId)
157 char newseq[] = new char[len];
158 System.arraycopy(seq, 0, newseq, 0, len);
159 Annotation asecstr[] = new Annotation[len];
160 for (int p = 0; p < len; p++)
162 if (secstr[p] >= 'A' && secstr[p] <= 'z')
164 asecstr[p] = new Annotation("" + secstr[p], null,
165 secstrcode[p], Float.NaN);
168 SequenceI sq = new Sequence("" + getDataName() + "|"
169 + model.getModelTitle() + "|" + _lastChainId,
170 newseq, firstrnum, lastrnum);
171 PDBEntry pdbe = new PDBEntry();
172 pdbe.setFile(getDataName());
173 pdbe.setId(getDataName());
175 pdbe.setProperty(new Hashtable());
176 pdbe.getProperty().put("CHAIN",""+_lastChainId);
178 if (!(biopoly.isDna() || biopoly.isRna()))
180 AlignmentAnnotation ann = new AlignmentAnnotation(
181 "Secondary Structure",
182 "Secondary Structure from PDB File", asecstr);
183 ann.setCalcId(getClass().getName());
184 sq.addAlignmentAnnotation(ann);
185 annotations.add(ann);
192 if (groupc < groups.length)
196 firstrnum = bpgrp[groupc].getResno();
197 _lastChainId = bpgrp[groupc].getChainID();
201 lastrnum = bpgrp[groupc].getResno();
203 seq[len] = bpgrp[groupc].getGroup1();
204 switch (bpgrp[groupc].getProteinStructureSubType())
207 if (secstr[len] == 0)
212 if (secstr[len] == 0)
217 if (secstr[len] == 0)
222 if (secstr[len] == 0)
226 secstrcode[len] = 'H';
230 secstrcode[len] = 'E';
238 } while (groupc++ < groups.length);
245 * lastScriptTermination = -9465; String dsspOut =
246 * jmd.evalString("calculate STRUCTURE"); if (dsspOut.equals("pending")) {
247 * while (lastScriptTermination == -9465) { try { Thread.sleep(50); }
248 * catch (Exception x) { } ; } } System.out.println(lastConsoleEcho);
256 * @see jalview.io.AlignFile#print()
259 public String print()
261 // TODO Auto-generated method stub
266 public void setCallbackFunction(String callbackType,
267 String callbackFunction)
269 // TODO Auto-generated method stub
274 * @Override public void notifyCallback(EnumCallback type, Object[] data) {
275 * try { switch (type) { case ERROR: case SCRIPT:
276 * notifyScriptTermination((String) data[2], ((Integer) data[3]).intValue());
277 * break; case MESSAGE: sendConsoleMessage((data == null) ? ((String) null) :
278 * (String) data[1]); break; case LOADSTRUCT: notifyFileLoaded((String)
279 * data[1], (String) data[2], (String) data[3], (String) data[4], ((Integer)
280 * data[5]).intValue());
282 * break; default: // System.err.println("Unhandled callback " + type + " " //
283 * + data[1].toString()); break; } } catch (Exception e) {
284 * System.err.println("Squashed Jmol callback handler error:");
285 * e.printStackTrace(); } }
287 public void notifyCallback(EnumCallback type, Object[] data)
289 String strInfo = (data == null || data[1] == null ? null : data[1]
294 sendConsoleEcho(strInfo);
297 notifyScriptTermination((String) data[2],
298 ((Integer) data[3]).intValue());
301 String mystatus = (String) data[3];
302 if (mystatus.indexOf("Picked") >= 0
303 || mystatus.indexOf("Sequence") >= 0) // picking mode
304 sendConsoleMessage(strInfo);
305 else if (mystatus.indexOf("Completed") >= 0)
306 sendConsoleEcho(strInfo.substring(strInfo.lastIndexOf(",") + 2,
307 strInfo.length() - 1));
310 sendConsoleMessage(data == null ? null : strInfo);
313 sendConsoleMessage(strInfo);
320 private void notifyFileLoaded(String string, String string2,
321 String string3, String string4, int intValue)
323 // TODO Auto-generated method stub
327 String lastConsoleEcho = "";
329 private void sendConsoleEcho(String string)
331 lastConsoleEcho += string;
332 lastConsoleEcho += "\n";
335 String lastConsoleMessage = "";
337 private void sendConsoleMessage(String string)
339 lastConsoleMessage += string;
340 lastConsoleMessage += "\n";
343 int lastScriptTermination = -1;
345 String lastScriptMessage = "";
347 private void notifyScriptTermination(String string, int intValue)
349 lastScriptMessage += string;
350 lastScriptMessage += "\n";
351 lastScriptTermination = intValue;
355 public boolean notifyEnabled(EnumCallback callbackPick)
357 switch (callbackPick)
378 public String eval(String strEval)
380 // TODO Auto-generated method stub
385 public float[][] functionXY(String functionName, int x, int y)
387 // TODO Auto-generated method stub
392 public float[][][] functionXYZ(String functionName, int nx, int ny, int nz)
394 // TODO Auto-generated method stub
399 public String createImage(String fileName, String type,
400 Object text_or_bytes, int quality)
402 // TODO Auto-generated method stub
407 public Map<String, Object> getRegistryInfo()
409 // TODO Auto-generated method stub
414 public void showUrl(String url)
416 // TODO Auto-generated method stub
421 public void resizeInnerPanel(String data)
423 // TODO Auto-generated method stub