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 javax.xml.parsers.ParserConfigurationException;
25 import org.jmol.api.JmolStatusListener;
26 import org.jmol.api.JmolViewer;
27 import org.jmol.constant.EnumCallback;
28 import org.jmol.constant.EnumStructure;
29 import org.jmol.modelset.Chain;
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;
37 import org.xml.sax.SAXException;
39 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
40 import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
41 import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
42 import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses;
43 import jalview.datamodel.AlignmentAnnotation;
44 import jalview.datamodel.Annotation;
45 import jalview.datamodel.PDBEntry;
46 import jalview.datamodel.Sequence;
47 import jalview.datamodel.SequenceI;
48 import jalview.io.AlignFile;
51 * Import and process PDB files with Jmol
56 public class PDBFileWithJmol extends AlignFile implements
60 JmolApp jmolApp = null;
64 public PDBFileWithJmol(String inFile, String type)
65 throws ExceptionUnmatchedClosingParentheses, IOException,
66 ExceptionFileFormatOrSyntax, ParserConfigurationException,
67 SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed,
73 public PDBFileWithJmol()
75 // TODO Auto-generated constructor stub
79 * create a headless jmol instance for dataprocessing
83 private Viewer getJmolData()
86 { // note that -o -n -x are all implied
87 jmolApp = new JmolApp();
88 jmolApp.isDataOnly = true;
89 jmolApp.haveConsole = false;
90 jmolApp.haveDisplay = false;
91 jmolApp.exitUponCompletion = true;
94 viewer = (Viewer) JmolViewer.allocateViewer(null, null, null, null,
95 null, jmolApp.commandOptions, this);
96 viewer.setScreenDimension(jmolApp.startupWidth,
97 jmolApp.startupHeight);
98 jmolApp.startViewer(viewer, null);
99 } catch (ClassCastException x)
103 + JmolViewer.getJmolVersion()
104 + " is not compatible with this version of Jalview. Report this problem at issues.jalview.org",
111 private void waitForScript(Viewer jmd)
113 while (jmd.isScriptExecuting())
119 } catch (InterruptedException x)
128 * @see jalview.io.AlignFile#parse()
131 public void parse() throws IOException, ExceptionFileFormatOrSyntax,
132 ParserConfigurationException, SAXException,
133 ExceptionPermissionDenied, ExceptionLoadingFailed,
134 InterruptedException, ExceptionUnmatchedClosingParentheses
136 Viewer jmd = getJmolData();
137 jmd.openReader(getDataName(), getDataName(), getReader());
139 if (jmd.getModelCount() > 0)
141 ModelSet ms = jmd.getModelSet();
142 String structs = ms.calculateStructures(null, true, false, true);
143 // System.out.println("Structs\n"+structs);
144 for (Model model : ms.getModels())
146 for (int _bp = 0, _bpc = model.getBioPolymerCount(); _bp < _bpc; _bp++)
148 Polymer bp = model.getBioPolymer(_bp);
149 if (bp instanceof BioPolymer)
151 BioPolymer biopoly = (BioPolymer) bp;
152 char _lastChainId = 0;
153 int[] groups = biopoly.getLeadAtomIndices();
154 Group[] bpgrp = biopoly.getGroups();
155 char seq[] = new char[groups.length], secstr[] = new char[groups.length], secstrcode[] = new char[groups.length];
156 int groupc = 0, len = 0, firstrnum = 1, lastrnum = 0;
159 if (groupc >= groups.length
160 || ms.atoms[groups[groupc]].getChainID() != _lastChainId)
164 char newseq[] = new char[len];
165 System.arraycopy(seq, 0, newseq, 0, len);
166 Annotation asecstr[] = new Annotation[len];
167 for (int p = 0; p < len; p++)
169 if (secstr[p] >= 'A' && secstr[p] <= 'z')
171 asecstr[p] = new Annotation("" + secstr[p], null,
172 secstrcode[p], Float.NaN);
175 SequenceI sq = new Sequence("" + getDataName() + "|"
176 + model.getModelTitle() + "|" + _lastChainId,
177 newseq, firstrnum, lastrnum);
178 PDBEntry pdbe = new PDBEntry();
179 pdbe.setFile(getDataName());
180 pdbe.setId(getDataName());
183 if (!(biopoly.isDna() || biopoly.isRna()))
185 AlignmentAnnotation ann = new AlignmentAnnotation(
186 "Secondary Structure",
187 "Secondary Structure from PDB File", asecstr);
188 sq.addAlignmentAnnotation(ann);
189 annotations.add(ann);
196 if (groupc < groups.length)
200 firstrnum = bpgrp[groupc].getResno();
201 _lastChainId = bpgrp[groupc].getChainID();
205 lastrnum = bpgrp[groupc].getResno();
207 seq[len] = bpgrp[groupc].getGroup1();
208 switch (bpgrp[groupc].getProteinStructureSubType())
211 if (secstr[len] == 0)
216 if (secstr[len] == 0)
221 if (secstr[len] == 0)
226 if (secstr[len] == 0)
230 secstrcode[len] = 'H';
234 secstrcode[len] = 'E';
242 } while (groupc++ < groups.length);
249 * lastScriptTermination = -9465; String dsspOut =
250 * jmd.evalString("calculate STRUCTURE"); if (dsspOut.equals("pending")) {
251 * while (lastScriptTermination == -9465) { try { Thread.sleep(50); }
252 * catch (Exception x) { } ; } } System.out.println(lastConsoleEcho);
260 * @see jalview.io.AlignFile#print()
263 public String print()
265 // TODO Auto-generated method stub
270 public void setCallbackFunction(String callbackType,
271 String callbackFunction)
273 // TODO Auto-generated method stub
278 * @Override public void notifyCallback(EnumCallback type, Object[] data) {
279 * try { switch (type) { case ERROR: case SCRIPT:
280 * notifyScriptTermination((String) data[2], ((Integer) data[3]).intValue());
281 * break; case MESSAGE: sendConsoleMessage((data == null) ? ((String) null) :
282 * (String) data[1]); break; case LOADSTRUCT: notifyFileLoaded((String)
283 * data[1], (String) data[2], (String) data[3], (String) data[4], ((Integer)
284 * data[5]).intValue());
286 * break; default: // System.err.println("Unhandled callback " + type + " " //
287 * + data[1].toString()); break; } } catch (Exception e) {
288 * System.err.println("Squashed Jmol callback handler error:");
289 * e.printStackTrace(); } }
291 public void notifyCallback(EnumCallback type, Object[] data)
293 String strInfo = (data == null || data[1] == null ? null : data[1]
298 sendConsoleEcho(strInfo);
301 notifyScriptTermination((String) data[2],
302 ((Integer) data[3]).intValue());
305 String mystatus = (String) data[3];
306 if (mystatus.indexOf("Picked") >= 0
307 || mystatus.indexOf("Sequence") >= 0) // picking mode
308 sendConsoleMessage(strInfo);
309 else if (mystatus.indexOf("Completed") >= 0)
310 sendConsoleEcho(strInfo.substring(strInfo.lastIndexOf(",") + 2,
311 strInfo.length() - 1));
314 sendConsoleMessage(data == null ? null : strInfo);
317 sendConsoleMessage(strInfo);
324 private void notifyFileLoaded(String string, String string2,
325 String string3, String string4, int intValue)
327 // TODO Auto-generated method stub
331 String lastConsoleEcho = "";
333 private void sendConsoleEcho(String string)
335 lastConsoleEcho += string;
336 lastConsoleEcho += "\n";
339 String lastConsoleMessage = "";
341 private void sendConsoleMessage(String string)
343 lastConsoleMessage += string;
344 lastConsoleMessage += "\n";
347 int lastScriptTermination = -1;
349 String lastScriptMessage = "";
351 private void notifyScriptTermination(String string, int intValue)
353 lastScriptMessage += string;
354 lastScriptMessage += "\n";
355 lastScriptTermination = intValue;
359 public boolean notifyEnabled(EnumCallback callbackPick)
361 switch (callbackPick)
382 public String eval(String strEval)
384 // TODO Auto-generated method stub
389 public float[][] functionXY(String functionName, int x, int y)
391 // TODO Auto-generated method stub
396 public float[][][] functionXYZ(String functionName, int nx, int ny, int nz)
398 // TODO Auto-generated method stub
403 public String createImage(String fileName, String type,
404 Object text_or_bytes, int quality)
406 // TODO Auto-generated method stub
411 public Map<String, Object> getRegistryInfo()
413 // TODO Auto-generated method stub
418 public void showUrl(String url)
420 // TODO Auto-generated method stub
425 public void resizeInnerPanel(String data)
427 // TODO Auto-generated method stub