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;
45 import jalview.util.MessageManager;
48 * Import and process PDB files with Jmol
53 public class PDBFileWithJmol extends AlignFile implements
57 JmolApp jmolApp = null;
61 public PDBFileWithJmol(String inFile, String type) throws IOException
66 public PDBFileWithJmol(FileParse fp) throws IOException
71 public PDBFileWithJmol()
73 // TODO Auto-generated constructor stub
77 * create a headless jmol instance for dataprocessing
81 private Viewer getJmolData()
84 { // note that -o -n -x are all implied
85 jmolApp = new JmolApp();
86 jmolApp.isDataOnly = true;
87 jmolApp.haveConsole = false;
88 jmolApp.haveDisplay = false;
89 jmolApp.exitUponCompletion = true;
92 viewer = (Viewer) JmolViewer.allocateViewer(null, null, null, null,
93 null, jmolApp.commandOptions, this);
94 viewer.setScreenDimension(jmolApp.startupWidth,
95 jmolApp.startupHeight);
96 jmolApp.startViewer(viewer, null);
97 } catch (ClassCastException x)
99 throw new Error(MessageManager.formatMessage("error.jmol_version_not_compatible_with_jalview_version", new String[]{JmolViewer.getJmolVersion()}),
106 private void waitForScript(Viewer jmd)
108 while (jmd.isScriptExecuting())
114 } catch (InterruptedException x)
123 * @see jalview.io.AlignFile#parse()
126 public void parse() throws IOException
128 Viewer jmd = getJmolData();
129 jmd.openReader(getDataName(), getDataName(), getReader());
131 if (jmd.getModelCount() > 0)
133 ModelSet ms = jmd.getModelSet();
134 String structs = ms.calculateStructures(null, true, false, true);
135 // System.out.println("Structs\n"+structs);
136 for (Model model : ms.getModels())
138 for (int _bp = 0, _bpc = model.getBioPolymerCount(); _bp < _bpc; _bp++)
140 Polymer bp = model.getBioPolymer(_bp);
141 if (bp instanceof BioPolymer)
143 BioPolymer biopoly = (BioPolymer) bp;
144 char _lastChainId = 0;
145 int[] groups = biopoly.getLeadAtomIndices();
146 Group[] bpgrp = biopoly.getGroups();
147 char seq[] = new char[groups.length], secstr[] = new char[groups.length], secstrcode[] = new char[groups.length];
148 int groupc = 0, len = 0, firstrnum = 1, lastrnum = 0;
151 if (groupc >= groups.length
152 || ms.atoms[groups[groupc]].getChainID() != _lastChainId)
156 char newseq[] = new char[len];
157 System.arraycopy(seq, 0, newseq, 0, len);
158 Annotation asecstr[] = new Annotation[len+firstrnum-1];
159 for (int p = 0; p < len; p++)
161 if (secstr[p] >= 'A' && secstr[p] <= 'z')
163 asecstr[p] = new Annotation("" + secstr[p], null,
164 secstrcode[p], Float.NaN);
167 SequenceI sq = new Sequence("" + getDataName() + "|"
168 + model.getModelTitle() + "|" + _lastChainId,
169 newseq, firstrnum, lastrnum);
170 PDBEntry pdbe = new PDBEntry();
171 pdbe.setFile(getDataName());
172 pdbe.setId(getDataName());
174 pdbe.setProperty(new Hashtable());
175 pdbe.getProperty().put("CHAIN", "" + _lastChainId);
177 // Need to put the number of models for this polymer somewhere for Chimera/others to grab
178 // pdbe.getProperty().put("PDBMODELS", biopoly.)
180 if (!(biopoly.isDna() || biopoly.isRna()))
182 AlignmentAnnotation ann = new AlignmentAnnotation(
183 "Secondary Structure",
184 "Secondary Structure from PDB File", asecstr);
185 ann.belowAlignment=true;
187 ann.autoCalculated=false;
188 ann.setCalcId(getClass().getName());
189 sq.addAlignmentAnnotation(ann);
190 ann.adjustForAlignment();
191 ann.validateRangeAndDisplay();
192 annotations.add(ann);
199 if (groupc < groups.length)
203 firstrnum = bpgrp[groupc].getResno();
204 _lastChainId = bpgrp[groupc].getChainID();
208 lastrnum = bpgrp[groupc].getResno();
210 seq[len] = bpgrp[groupc].getGroup1();
211 switch (bpgrp[groupc].getProteinStructureSubType())
214 if (secstr[len] == 0)
219 if (secstr[len] == 0)
224 if (secstr[len] == 0)
229 if (secstr[len] == 0)
233 secstrcode[len] = 'H';
237 secstrcode[len] = 'E';
245 } while (groupc++ < groups.length);
252 * lastScriptTermination = -9465; String dsspOut =
253 * jmd.evalString("calculate STRUCTURE"); if (dsspOut.equals("pending")) {
254 * while (lastScriptTermination == -9465) { try { Thread.sleep(50); }
255 * catch (Exception x) { } ; } } System.out.println(lastConsoleEcho);
263 * @see jalview.io.AlignFile#print()
266 public String print()
268 // TODO Auto-generated method stub
273 public void setCallbackFunction(String callbackType,
274 String callbackFunction)
276 // TODO Auto-generated method stub
281 * @Override public void notifyCallback(EnumCallback type, Object[] data) {
282 * try { switch (type) { case ERROR: case SCRIPT:
283 * notifyScriptTermination((String) data[2], ((Integer) data[3]).intValue());
284 * break; case MESSAGE: sendConsoleMessage((data == null) ? ((String) null) :
285 * (String) data[1]); break; case LOADSTRUCT: notifyFileLoaded((String)
286 * data[1], (String) data[2], (String) data[3], (String) data[4], ((Integer)
287 * data[5]).intValue());
289 * break; default: // System.err.println("Unhandled callback " + type + " " //
290 * + data[1].toString()); break; } } catch (Exception e) {
291 * System.err.println("Squashed Jmol callback handler error:");
292 * e.printStackTrace(); } }
294 public void notifyCallback(EnumCallback type, Object[] data)
296 String strInfo = (data == null || data[1] == null ? null : data[1]
301 sendConsoleEcho(strInfo);
304 notifyScriptTermination((String) data[2],
305 ((Integer) data[3]).intValue());
308 String mystatus = (String) data[3];
309 if (mystatus.indexOf("Picked") >= 0
310 || mystatus.indexOf("Sequence") >= 0) // picking mode
311 sendConsoleMessage(strInfo);
312 else if (mystatus.indexOf("Completed") >= 0)
313 sendConsoleEcho(strInfo.substring(strInfo.lastIndexOf(",") + 2,
314 strInfo.length() - 1));
317 sendConsoleMessage(data == null ? null : strInfo);
320 sendConsoleMessage(strInfo);
327 private void notifyFileLoaded(String string, String string2,
328 String string3, String string4, int intValue)
330 // TODO Auto-generated method stub
334 String lastConsoleEcho = "";
336 private void sendConsoleEcho(String string)
338 lastConsoleEcho += string;
339 lastConsoleEcho += "\n";
342 String lastConsoleMessage = "";
344 private void sendConsoleMessage(String string)
346 lastConsoleMessage += string;
347 lastConsoleMessage += "\n";
350 int lastScriptTermination = -1;
352 String lastScriptMessage = "";
354 private void notifyScriptTermination(String string, int intValue)
356 lastScriptMessage += string;
357 lastScriptMessage += "\n";
358 lastScriptTermination = intValue;
362 public boolean notifyEnabled(EnumCallback callbackPick)
364 switch (callbackPick)
385 public String eval(String strEval)
387 // TODO Auto-generated method stub
392 public float[][] functionXY(String functionName, int x, int y)
394 // TODO Auto-generated method stub
399 public float[][][] functionXYZ(String functionName, int nx, int ny, int nz)
401 // TODO Auto-generated method stub
406 public String createImage(String fileName, String type,
407 Object text_or_bytes, int quality)
409 // TODO Auto-generated method stub
414 public Map<String, Object> getRegistryInfo()
416 // TODO Auto-generated method stub
421 public void showUrl(String url)
423 // TODO Auto-generated method stub
428 public void resizeInnerPanel(String data)
430 // TODO Auto-generated method stub