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;
23 import org.jmol.api.JmolStatusListener;
24 import org.jmol.api.JmolViewer;
25 import org.jmol.constant.EnumCallback;
26 import org.jmol.modelset.Group;
27 import org.jmol.modelset.Model;
28 import org.jmol.modelset.ModelSet;
29 import org.jmol.modelset.Polymer;
30 import org.jmol.modelsetbio.BioPolymer;
31 import org.jmol.viewer.Viewer;
32 import org.openscience.jmol.app.JmolApp;
34 import jalview.datamodel.AlignmentAnnotation;
35 import jalview.datamodel.Annotation;
36 import jalview.datamodel.PDBEntry;
37 import jalview.datamodel.Sequence;
38 import jalview.datamodel.SequenceI;
39 import jalview.io.AlignFile;
42 * Import and process PDB files with Jmol
47 public class PDBFileWithJmol extends AlignFile implements
51 JmolApp jmolApp = null;
55 public PDBFileWithJmol(String inFile, String type)
61 public PDBFileWithJmol()
63 // TODO Auto-generated constructor stub
67 * create a headless jmol instance for dataprocessing
71 private Viewer getJmolData()
74 { // note that -o -n -x are all implied
75 jmolApp = new JmolApp();
76 jmolApp.isDataOnly = true;
77 jmolApp.haveConsole = false;
78 jmolApp.haveDisplay = false;
79 jmolApp.exitUponCompletion = true;
82 viewer = (Viewer) JmolViewer.allocateViewer(null, null, null, null,
83 null, jmolApp.commandOptions, this);
84 viewer.setScreenDimension(jmolApp.startupWidth,
85 jmolApp.startupHeight);
86 jmolApp.startViewer(viewer, null);
87 } catch (ClassCastException x)
91 + JmolViewer.getJmolVersion()
92 + " is not compatible with this version of Jalview. Report this problem at issues.jalview.org",
99 private void waitForScript(Viewer jmd)
101 while (jmd.isScriptExecuting())
107 } catch (InterruptedException x)
116 * @see jalview.io.AlignFile#parse()
119 public void parse() throws IOException
121 Viewer jmd = getJmolData();
122 jmd.openReader(getDataName(), getDataName(), getReader());
124 if (jmd.getModelCount() > 0)
126 ModelSet ms = jmd.getModelSet();
127 String structs = ms.calculateStructures(null, true, false, true);
128 // System.out.println("Structs\n"+structs);
129 for (Model model : ms.getModels())
131 for (int _bp = 0, _bpc = model.getBioPolymerCount(); _bp < _bpc; _bp++)
133 Polymer bp = model.getBioPolymer(_bp);
134 if (bp instanceof BioPolymer)
136 BioPolymer biopoly = (BioPolymer) bp;
137 char _lastChainId = 0;
138 int[] groups = biopoly.getLeadAtomIndices();
139 Group[] bpgrp = biopoly.getGroups();
140 char seq[] = new char[groups.length], secstr[] = new char[groups.length], secstrcode[] = new char[groups.length];
141 int groupc = 0, len = 0, firstrnum = 1, lastrnum = 0;
144 if (groupc >= groups.length
145 || ms.atoms[groups[groupc]].getChainID() != _lastChainId)
149 char newseq[] = new char[len];
150 System.arraycopy(seq, 0, newseq, 0, len);
151 Annotation asecstr[] = new Annotation[len];
152 for (int p = 0; p < len; p++)
154 if (secstr[p] >= 'A' && secstr[p] <= 'z')
156 asecstr[p] = new Annotation("" + secstr[p], null,
157 secstrcode[p], Float.NaN);
160 SequenceI sq = new Sequence("" + getDataName() + "|"
161 + model.getModelTitle() + "|" + _lastChainId,
162 newseq, firstrnum, lastrnum);
163 PDBEntry pdbe = new PDBEntry();
164 pdbe.setFile(getDataName());
165 pdbe.setId(getDataName());
168 if (!(biopoly.isDna() || biopoly.isRna()))
170 AlignmentAnnotation ann = new AlignmentAnnotation(
171 "Secondary Structure",
172 "Secondary Structure from PDB File", asecstr);
173 sq.addAlignmentAnnotation(ann);
174 annotations.add(ann);
181 if (groupc < groups.length)
185 firstrnum = bpgrp[groupc].getResno();
186 _lastChainId = bpgrp[groupc].getChainID();
190 lastrnum = bpgrp[groupc].getResno();
192 seq[len] = bpgrp[groupc].getGroup1();
193 switch (bpgrp[groupc].getProteinStructureSubType())
196 if (secstr[len] == 0)
201 if (secstr[len] == 0)
206 if (secstr[len] == 0)
211 if (secstr[len] == 0)
215 secstrcode[len] = 'H';
219 secstrcode[len] = 'E';
227 } while (groupc++ < groups.length);
234 * lastScriptTermination = -9465; String dsspOut =
235 * jmd.evalString("calculate STRUCTURE"); if (dsspOut.equals("pending")) {
236 * while (lastScriptTermination == -9465) { try { Thread.sleep(50); }
237 * catch (Exception x) { } ; } } System.out.println(lastConsoleEcho);
245 * @see jalview.io.AlignFile#print()
248 public String print()
250 // TODO Auto-generated method stub
255 public void setCallbackFunction(String callbackType,
256 String callbackFunction)
258 // TODO Auto-generated method stub
263 * @Override public void notifyCallback(EnumCallback type, Object[] data) {
264 * try { switch (type) { case ERROR: case SCRIPT:
265 * notifyScriptTermination((String) data[2], ((Integer) data[3]).intValue());
266 * break; case MESSAGE: sendConsoleMessage((data == null) ? ((String) null) :
267 * (String) data[1]); break; case LOADSTRUCT: notifyFileLoaded((String)
268 * data[1], (String) data[2], (String) data[3], (String) data[4], ((Integer)
269 * data[5]).intValue());
271 * break; default: // System.err.println("Unhandled callback " + type + " " //
272 * + data[1].toString()); break; } } catch (Exception e) {
273 * System.err.println("Squashed Jmol callback handler error:");
274 * e.printStackTrace(); } }
276 public void notifyCallback(EnumCallback type, Object[] data)
278 String strInfo = (data == null || data[1] == null ? null : data[1]
283 sendConsoleEcho(strInfo);
286 notifyScriptTermination((String) data[2],
287 ((Integer) data[3]).intValue());
290 String mystatus = (String) data[3];
291 if (mystatus.indexOf("Picked") >= 0
292 || mystatus.indexOf("Sequence") >= 0) // picking mode
293 sendConsoleMessage(strInfo);
294 else if (mystatus.indexOf("Completed") >= 0)
295 sendConsoleEcho(strInfo.substring(strInfo.lastIndexOf(",") + 2,
296 strInfo.length() - 1));
299 sendConsoleMessage(data == null ? null : strInfo);
302 sendConsoleMessage(strInfo);
309 private void notifyFileLoaded(String string, String string2,
310 String string3, String string4, int intValue)
312 // TODO Auto-generated method stub
316 String lastConsoleEcho = "";
318 private void sendConsoleEcho(String string)
320 lastConsoleEcho += string;
321 lastConsoleEcho += "\n";
324 String lastConsoleMessage = "";
326 private void sendConsoleMessage(String string)
328 lastConsoleMessage += string;
329 lastConsoleMessage += "\n";
332 int lastScriptTermination = -1;
334 String lastScriptMessage = "";
336 private void notifyScriptTermination(String string, int intValue)
338 lastScriptMessage += string;
339 lastScriptMessage += "\n";
340 lastScriptTermination = intValue;
344 public boolean notifyEnabled(EnumCallback callbackPick)
346 switch (callbackPick)
367 public String eval(String strEval)
369 // TODO Auto-generated method stub
374 public float[][] functionXY(String functionName, int x, int y)
376 // TODO Auto-generated method stub
381 public float[][][] functionXYZ(String functionName, int nx, int ny, int nz)
383 // TODO Auto-generated method stub
388 public String createImage(String fileName, String type,
389 Object text_or_bytes, int quality)
391 // TODO Auto-generated method stub
396 public Map<String, Object> getRegistryInfo()
398 // TODO Auto-generated method stub
403 public void showUrl(String url)
405 // TODO Auto-generated method stub
410 public void resizeInnerPanel(String data)
412 // TODO Auto-generated method stub