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) throws IOException
65 public PDBFileWithJmol(FileParse fp) throws IOException
70 public PDBFileWithJmol()
72 // TODO Auto-generated constructor stub
76 * create a headless jmol instance for dataprocessing
80 private Viewer getJmolData()
83 { // note that -o -n -x are all implied
84 jmolApp = new JmolApp();
85 jmolApp.isDataOnly = true;
86 jmolApp.haveConsole = false;
87 jmolApp.haveDisplay = false;
88 jmolApp.exitUponCompletion = true;
91 viewer = (Viewer) JmolViewer.allocateViewer(null, null, null, null,
92 null, jmolApp.commandOptions, this);
93 viewer.setScreenDimension(jmolApp.startupWidth,
94 jmolApp.startupHeight);
95 jmolApp.startViewer(viewer, null);
96 } catch (ClassCastException x)
100 + JmolViewer.getJmolVersion()
101 + " is not compatible with this version of Jalview. Report this problem at issues.jalview.org",
108 private void waitForScript(Viewer jmd)
110 while (jmd.isScriptExecuting())
116 } catch (InterruptedException x)
125 * @see jalview.io.AlignFile#parse()
128 public void parse() throws IOException
130 Viewer jmd = getJmolData();
131 jmd.openReader(getDataName(), getDataName(), getReader());
133 if (jmd.getModelCount() > 0)
135 ModelSet ms = jmd.getModelSet();
136 String structs = ms.calculateStructures(null, true, false, true);
137 // System.out.println("Structs\n"+structs);
138 for (Model model : ms.getModels())
140 for (int _bp = 0, _bpc = model.getBioPolymerCount(); _bp < _bpc; _bp++)
142 Polymer bp = model.getBioPolymer(_bp);
143 if (bp instanceof BioPolymer)
145 BioPolymer biopoly = (BioPolymer) bp;
146 char _lastChainId = 0;
147 int[] groups = biopoly.getLeadAtomIndices();
148 Group[] bpgrp = biopoly.getGroups();
149 char seq[] = new char[groups.length], secstr[] = new char[groups.length], secstrcode[] = new char[groups.length];
150 int groupc = 0, len = 0, firstrnum = 1, lastrnum = 0;
153 if (groupc >= groups.length
154 || ms.atoms[groups[groupc]].getChainID() != _lastChainId)
158 char newseq[] = new char[len];
159 System.arraycopy(seq, 0, newseq, 0, len);
160 Annotation asecstr[] = new Annotation[len+firstrnum-1];
161 for (int p = 0; p < len; p++)
163 if (secstr[p] >= 'A' && secstr[p] <= 'z')
165 asecstr[p] = new Annotation("" + secstr[p], null,
166 secstrcode[p], Float.NaN);
169 SequenceI sq = new Sequence("" + getDataName() + "|"
170 + model.getModelTitle() + "|" + _lastChainId,
171 newseq, firstrnum, lastrnum);
172 PDBEntry pdbe = new PDBEntry();
173 pdbe.setFile(getDataName());
174 pdbe.setId(getDataName());
176 pdbe.setProperty(new Hashtable());
177 pdbe.getProperty().put("CHAIN", "" + _lastChainId);
179 if (!(biopoly.isDna() || biopoly.isRna()))
181 AlignmentAnnotation ann = new AlignmentAnnotation(
182 "Secondary Structure",
183 "Secondary Structure from PDB File", asecstr);
184 ann.belowAlignment=true;
186 ann.autoCalculated=false;
187 ann.setCalcId(getClass().getName());
188 sq.addAlignmentAnnotation(ann);
189 ann.adjustForAlignment();
190 ann.validateRangeAndDisplay();
191 annotations.add(ann);
198 if (groupc < groups.length)
202 firstrnum = bpgrp[groupc].getResno();
203 _lastChainId = bpgrp[groupc].getChainID();
207 lastrnum = bpgrp[groupc].getResno();
209 seq[len] = bpgrp[groupc].getGroup1();
210 switch (bpgrp[groupc].getProteinStructureSubType())
213 if (secstr[len] == 0)
218 if (secstr[len] == 0)
223 if (secstr[len] == 0)
228 if (secstr[len] == 0)
232 secstrcode[len] = 'H';
236 secstrcode[len] = 'E';
244 } while (groupc++ < groups.length);
251 * lastScriptTermination = -9465; String dsspOut =
252 * jmd.evalString("calculate STRUCTURE"); if (dsspOut.equals("pending")) {
253 * while (lastScriptTermination == -9465) { try { Thread.sleep(50); }
254 * catch (Exception x) { } ; } } System.out.println(lastConsoleEcho);
262 * @see jalview.io.AlignFile#print()
265 public String print()
267 // TODO Auto-generated method stub
272 public void setCallbackFunction(String callbackType,
273 String callbackFunction)
275 // TODO Auto-generated method stub
280 * @Override public void notifyCallback(EnumCallback type, Object[] data) {
281 * try { switch (type) { case ERROR: case SCRIPT:
282 * notifyScriptTermination((String) data[2], ((Integer) data[3]).intValue());
283 * break; case MESSAGE: sendConsoleMessage((data == null) ? ((String) null) :
284 * (String) data[1]); break; case LOADSTRUCT: notifyFileLoaded((String)
285 * data[1], (String) data[2], (String) data[3], (String) data[4], ((Integer)
286 * data[5]).intValue());
288 * break; default: // System.err.println("Unhandled callback " + type + " " //
289 * + data[1].toString()); break; } } catch (Exception e) {
290 * System.err.println("Squashed Jmol callback handler error:");
291 * e.printStackTrace(); } }
293 public void notifyCallback(EnumCallback type, Object[] data)
295 String strInfo = (data == null || data[1] == null ? null : data[1]
300 sendConsoleEcho(strInfo);
303 notifyScriptTermination((String) data[2],
304 ((Integer) data[3]).intValue());
307 String mystatus = (String) data[3];
308 if (mystatus.indexOf("Picked") >= 0
309 || mystatus.indexOf("Sequence") >= 0) // picking mode
310 sendConsoleMessage(strInfo);
311 else if (mystatus.indexOf("Completed") >= 0)
312 sendConsoleEcho(strInfo.substring(strInfo.lastIndexOf(",") + 2,
313 strInfo.length() - 1));
316 sendConsoleMessage(data == null ? null : strInfo);
319 sendConsoleMessage(strInfo);
326 private void notifyFileLoaded(String string, String string2,
327 String string3, String string4, int intValue)
329 // TODO Auto-generated method stub
333 String lastConsoleEcho = "";
335 private void sendConsoleEcho(String string)
337 lastConsoleEcho += string;
338 lastConsoleEcho += "\n";
341 String lastConsoleMessage = "";
343 private void sendConsoleMessage(String string)
345 lastConsoleMessage += string;
346 lastConsoleMessage += "\n";
349 int lastScriptTermination = -1;
351 String lastScriptMessage = "";
353 private void notifyScriptTermination(String string, int intValue)
355 lastScriptMessage += string;
356 lastScriptMessage += "\n";
357 lastScriptTermination = intValue;
361 public boolean notifyEnabled(EnumCallback callbackPick)
363 switch (callbackPick)
384 public String eval(String strEval)
386 // TODO Auto-generated method stub
391 public float[][] functionXY(String functionName, int x, int y)
393 // TODO Auto-generated method stub
398 public float[][][] functionXYZ(String functionName, int nx, int ny, int nz)
400 // TODO Auto-generated method stub
405 public String createImage(String fileName, String type,
406 Object text_or_bytes, int quality)
408 // TODO Auto-generated method stub
413 public Map<String, Object> getRegistryInfo()
415 // TODO Auto-generated method stub
420 public void showUrl(String url)
422 // TODO Auto-generated method stub
427 public void resizeInnerPanel(String data)
429 // TODO Auto-generated method stub