2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.
21 package jalview.ext.jmol;
23 import java.io.IOException;
24 import java.util.Hashtable;
27 import org.jmol.api.JmolStatusListener;
28 import org.jmol.api.JmolViewer;
29 import org.jmol.constant.EnumCallback;
30 import org.jmol.modelset.Group;
31 import org.jmol.modelset.Model;
32 import org.jmol.modelset.ModelSet;
33 import org.jmol.modelset.Polymer;
34 import org.jmol.modelsetbio.BioPolymer;
35 import org.jmol.viewer.Viewer;
36 import org.openscience.jmol.app.JmolApp;
38 import jalview.datamodel.AlignmentAnnotation;
39 import jalview.datamodel.Annotation;
40 import jalview.datamodel.PDBEntry;
41 import jalview.datamodel.Sequence;
42 import jalview.datamodel.SequenceI;
43 import jalview.io.AlignFile;
44 import jalview.io.FileParse;
47 * Import and process PDB files with Jmol
52 public class PDBFileWithJmol extends AlignFile implements
56 JmolApp jmolApp = null;
60 public PDBFileWithJmol(String inFile, String type)
67 public PDBFileWithJmol(FileParse fp) throws IOException
72 public PDBFileWithJmol()
74 // TODO Auto-generated constructor stub
78 * create a headless jmol instance for dataprocessing
82 private Viewer getJmolData()
85 { // note that -o -n -x are all implied
86 jmolApp = new JmolApp();
87 jmolApp.isDataOnly = true;
88 jmolApp.haveConsole = false;
89 jmolApp.haveDisplay = false;
90 jmolApp.exitUponCompletion = true;
93 viewer = (Viewer) JmolViewer.allocateViewer(null, null, null, null,
94 null, jmolApp.commandOptions, this);
95 viewer.setScreenDimension(jmolApp.startupWidth,
96 jmolApp.startupHeight);
97 jmolApp.startViewer(viewer, null);
98 } catch (ClassCastException x)
102 + JmolViewer.getJmolVersion()
103 + " is not compatible with this version of Jalview. Report this problem at issues.jalview.org",
110 private void waitForScript(Viewer jmd)
112 while (jmd.isScriptExecuting())
118 } catch (InterruptedException x)
127 * @see jalview.io.AlignFile#parse()
130 public void parse() throws IOException
132 Viewer jmd = getJmolData();
133 jmd.openReader(getDataName(), getDataName(), getReader());
135 if (jmd.getModelCount() > 0)
137 ModelSet ms = jmd.getModelSet();
138 String structs = ms.calculateStructures(null, true, false, true);
139 // System.out.println("Structs\n"+structs);
140 for (Model model : ms.getModels())
142 for (int _bp = 0, _bpc = model.getBioPolymerCount(); _bp < _bpc; _bp++)
144 Polymer bp = model.getBioPolymer(_bp);
145 if (bp instanceof BioPolymer)
147 BioPolymer biopoly = (BioPolymer) bp;
148 char _lastChainId = 0;
149 int[] groups = biopoly.getLeadAtomIndices();
150 Group[] bpgrp = biopoly.getGroups();
151 char seq[] = new char[groups.length], secstr[] = new char[groups.length], secstrcode[] = new char[groups.length];
152 int groupc = 0, len = 0, firstrnum = 1, lastrnum = 0;
155 if (groupc >= groups.length
156 || ms.atoms[groups[groupc]].getChainID() != _lastChainId)
160 char newseq[] = new char[len];
161 System.arraycopy(seq, 0, newseq, 0, len);
162 Annotation asecstr[] = new Annotation[len];
163 for (int p = 0; p < len; p++)
165 if (secstr[p] >= 'A' && secstr[p] <= 'z')
167 asecstr[p] = new Annotation("" + secstr[p], null,
168 secstrcode[p], Float.NaN);
171 SequenceI sq = new Sequence("" + getDataName() + "|"
172 + model.getModelTitle() + "|" + _lastChainId,
173 newseq, firstrnum, lastrnum);
174 PDBEntry pdbe = new PDBEntry();
175 pdbe.setFile(getDataName());
176 pdbe.setId(getDataName());
178 pdbe.setProperty(new Hashtable());
179 pdbe.getProperty().put("CHAIN",""+_lastChainId);
181 if (!(biopoly.isDna() || biopoly.isRna()))
183 AlignmentAnnotation ann = new AlignmentAnnotation(
184 "Secondary Structure",
185 "Secondary Structure from PDB File", asecstr);
186 ann.setCalcId(getClass().getName());
187 sq.addAlignmentAnnotation(ann);
188 annotations.add(ann);
195 if (groupc < groups.length)
199 firstrnum = bpgrp[groupc].getResno();
200 _lastChainId = bpgrp[groupc].getChainID();
204 lastrnum = bpgrp[groupc].getResno();
206 seq[len] = bpgrp[groupc].getGroup1();
207 switch (bpgrp[groupc].getProteinStructureSubType())
210 if (secstr[len] == 0)
215 if (secstr[len] == 0)
220 if (secstr[len] == 0)
225 if (secstr[len] == 0)
229 secstrcode[len] = 'H';
233 secstrcode[len] = 'E';
241 } while (groupc++ < groups.length);
248 * lastScriptTermination = -9465; String dsspOut =
249 * jmd.evalString("calculate STRUCTURE"); if (dsspOut.equals("pending")) {
250 * while (lastScriptTermination == -9465) { try { Thread.sleep(50); }
251 * catch (Exception x) { } ; } } System.out.println(lastConsoleEcho);
259 * @see jalview.io.AlignFile#print()
262 public String print()
264 // TODO Auto-generated method stub
269 public void setCallbackFunction(String callbackType,
270 String callbackFunction)
272 // TODO Auto-generated method stub
277 * @Override public void notifyCallback(EnumCallback type, Object[] data) {
278 * try { switch (type) { case ERROR: case SCRIPT:
279 * notifyScriptTermination((String) data[2], ((Integer) data[3]).intValue());
280 * break; case MESSAGE: sendConsoleMessage((data == null) ? ((String) null) :
281 * (String) data[1]); break; case LOADSTRUCT: notifyFileLoaded((String)
282 * data[1], (String) data[2], (String) data[3], (String) data[4], ((Integer)
283 * data[5]).intValue());
285 * break; default: // System.err.println("Unhandled callback " + type + " " //
286 * + data[1].toString()); break; } } catch (Exception e) {
287 * System.err.println("Squashed Jmol callback handler error:");
288 * e.printStackTrace(); } }
290 public void notifyCallback(EnumCallback type, Object[] data)
292 String strInfo = (data == null || data[1] == null ? null : data[1]
297 sendConsoleEcho(strInfo);
300 notifyScriptTermination((String) data[2],
301 ((Integer) data[3]).intValue());
304 String mystatus = (String) data[3];
305 if (mystatus.indexOf("Picked") >= 0
306 || mystatus.indexOf("Sequence") >= 0) // picking mode
307 sendConsoleMessage(strInfo);
308 else if (mystatus.indexOf("Completed") >= 0)
309 sendConsoleEcho(strInfo.substring(strInfo.lastIndexOf(",") + 2,
310 strInfo.length() - 1));
313 sendConsoleMessage(data == null ? null : strInfo);
316 sendConsoleMessage(strInfo);
323 private void notifyFileLoaded(String string, String string2,
324 String string3, String string4, int intValue)
326 // TODO Auto-generated method stub
330 String lastConsoleEcho = "";
332 private void sendConsoleEcho(String string)
334 lastConsoleEcho += string;
335 lastConsoleEcho += "\n";
338 String lastConsoleMessage = "";
340 private void sendConsoleMessage(String string)
342 lastConsoleMessage += string;
343 lastConsoleMessage += "\n";
346 int lastScriptTermination = -1;
348 String lastScriptMessage = "";
350 private void notifyScriptTermination(String string, int intValue)
352 lastScriptMessage += string;
353 lastScriptMessage += "\n";
354 lastScriptTermination = intValue;
358 public boolean notifyEnabled(EnumCallback callbackPick)
360 switch (callbackPick)
381 public String eval(String strEval)
383 // TODO Auto-generated method stub
388 public float[][] functionXY(String functionName, int x, int y)
390 // TODO Auto-generated method stub
395 public float[][][] functionXYZ(String functionName, int nx, int ny, int nz)
397 // TODO Auto-generated method stub
402 public String createImage(String fileName, String type,
403 Object text_or_bytes, int quality)
405 // TODO Auto-generated method stub
410 public Map<String, Object> getRegistryInfo()
412 // TODO Auto-generated method stub
417 public void showUrl(String url)
419 // TODO Auto-generated method stub
424 public void resizeInnerPanel(String data)
426 // TODO Auto-generated method stub