2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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 jalview.datamodel.AlignmentAnnotation;
24 import jalview.datamodel.Annotation;
25 import jalview.datamodel.PDBEntry;
26 import jalview.datamodel.Sequence;
27 import jalview.datamodel.SequenceI;
28 import jalview.io.AlignFile;
29 import jalview.io.FileParse;
30 import jalview.schemes.ResidueProperties;
31 import jalview.util.MessageManager;
33 import java.io.IOException;
34 import java.util.Hashtable;
37 import org.jmol.api.JmolStatusListener;
38 import org.jmol.api.JmolViewer;
39 import org.jmol.constant.EnumCallback;
40 import org.jmol.modelset.Group;
41 import org.jmol.modelset.Model;
42 import org.jmol.modelset.ModelSet;
43 import org.jmol.modelset.Polymer;
44 import org.jmol.modelsetbio.BioPolymer;
45 import org.jmol.viewer.Viewer;
46 import org.openscience.jmol.app.JmolApp;
49 * Import and process PDB files with Jmol
54 public class PDBFileWithJmol extends AlignFile implements
58 JmolApp jmolApp = null;
62 public PDBFileWithJmol(String inFile, String type) throws IOException
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)
100 throw new Error(MessageManager.formatMessage("error.jmol_version_not_compatible_with_jalview_version", new String[]{JmolViewer.getJmolVersion()}),
107 private void waitForScript(Viewer jmd)
109 while (jmd.isScriptExecuting())
115 } catch (InterruptedException x)
124 * @see jalview.io.AlignFile#parse()
127 public void parse() throws IOException
129 Viewer jmd = getJmolData();
130 jmd.openReader(getDataName(), getDataName(), getReader());
132 if (jmd.getModelCount() > 0)
134 ModelSet ms = jmd.getModelSet();
135 String structs = ms.calculateStructures(null, true, false, true);
136 // System.out.println("Structs\n"+structs);
137 for (Model model : ms.getModels())
139 for (int _bp = 0, _bpc = model.getBioPolymerCount(); _bp < _bpc; _bp++)
141 Polymer bp = model.getBioPolymer(_bp);
142 if (bp instanceof BioPolymer)
144 BioPolymer biopoly = (BioPolymer) bp;
145 char _lastChainId = 0;
146 int[] groups = biopoly.getLeadAtomIndices();
147 Group[] bpgrp = biopoly.getGroups();
148 char seq[] = new char[groups.length], secstr[] = new char[groups.length], secstrcode[] = new char[groups.length];
149 int groupc = 0, len = 0, firstrnum = 1, lastrnum = 0;
152 if (groupc >= groups.length
153 || ms.atoms[groups[groupc]].getChainID() != _lastChainId)
157 boolean isNa = (biopoly.isDna() || biopoly.isRna());
158 // normalise sequence from Jmol to jalview
159 int[] cinds = isNa ? ResidueProperties.nucleotideIndex : ResidueProperties.aaIndex;
160 int nonGap = isNa ? ResidueProperties.maxNucleotideIndex
161 : ResidueProperties.maxProteinIndex;
163 char newseq[] = new char[len];
164 Annotation asecstr[] = new Annotation[len+firstrnum-1];
165 for (int p = 0; p < len; p++)
167 newseq[p] = cinds[seq[p]] == nonGap ? ngc : seq[p];
168 if (secstr[p] >= 'A' && secstr[p] <= 'z')
170 asecstr[p] = new Annotation("" + secstr[p], null,
171 secstrcode[p], Float.NaN);
174 SequenceI sq = new Sequence("" + getDataName() + "|"
175 + model.getModelTitle() + "|" + _lastChainId,
176 newseq, firstrnum, lastrnum);
177 PDBEntry pdbe = new PDBEntry();
178 pdbe.setFile(getDataName());
179 pdbe.setId(getDataName());
180 pdbe.setProperty(new Hashtable());
181 // pdbe.getProperty().put("CHAIN", "" + _lastChainId);
182 pdbe.setChainCode(String.valueOf(_lastChainId));
185 // Need to put the number of models for this polymer somewhere for Chimera/others to grab
186 // pdbe.getProperty().put("PDBMODELS", biopoly.)
190 String mt = model.getModelTitle() == null ? getDataName()
191 : model.getModelTitle();
192 if (_lastChainId >= ' ')
196 AlignmentAnnotation ann = new AlignmentAnnotation(
197 "Secondary Structure",
198 "Secondary Structure for " + mt, asecstr);
199 ann.belowAlignment=true;
201 ann.autoCalculated=false;
202 ann.setCalcId(getClass().getName());
203 sq.addAlignmentAnnotation(ann);
204 ann.adjustForAlignment();
205 ann.validateRangeAndDisplay();
206 annotations.add(ann);
213 if (groupc < groups.length)
217 firstrnum = bpgrp[groupc].getResno();
218 _lastChainId = bpgrp[groupc].getChainID();
222 lastrnum = bpgrp[groupc].getResno();
224 seq[len] = bpgrp[groupc].getGroup1();
225 switch (bpgrp[groupc].getProteinStructureSubType())
228 if (secstr[len] == 0)
233 if (secstr[len] == 0)
238 if (secstr[len] == 0)
243 if (secstr[len] == 0)
247 secstrcode[len] = 'H';
251 secstrcode[len] = 'E';
259 } while (groupc++ < groups.length);
266 * lastScriptTermination = -9465; String dsspOut =
267 * jmd.evalString("calculate STRUCTURE"); if (dsspOut.equals("pending")) {
268 * while (lastScriptTermination == -9465) { try { Thread.sleep(50); }
269 * catch (Exception x) { } ; } } System.out.println(lastConsoleEcho);
277 * @see jalview.io.AlignFile#print()
280 public String print()
282 // TODO Auto-generated method stub
287 public void setCallbackFunction(String callbackType,
288 String callbackFunction)
290 // TODO Auto-generated method stub
295 * @Override public void notifyCallback(EnumCallback type, Object[] data) {
296 * try { switch (type) { case ERROR: case SCRIPT:
297 * notifyScriptTermination((String) data[2], ((Integer) data[3]).intValue());
298 * break; case MESSAGE: sendConsoleMessage((data == null) ? ((String) null) :
299 * (String) data[1]); break; case LOADSTRUCT: notifyFileLoaded((String)
300 * data[1], (String) data[2], (String) data[3], (String) data[4], ((Integer)
301 * data[5]).intValue());
303 * break; default: // System.err.println("Unhandled callback " + type + " " //
304 * + data[1].toString()); break; } } catch (Exception e) {
305 * System.err.println("Squashed Jmol callback handler error:");
306 * e.printStackTrace(); } }
308 public void notifyCallback(EnumCallback type, Object[] data)
310 String strInfo = (data == null || data[1] == null ? null : data[1]
315 sendConsoleEcho(strInfo);
318 notifyScriptTermination((String) data[2],
319 ((Integer) data[3]).intValue());
322 String mystatus = (String) data[3];
323 if (mystatus.indexOf("Picked") >= 0
324 || mystatus.indexOf("Sequence") >= 0)
327 sendConsoleMessage(strInfo);
329 else if (mystatus.indexOf("Completed") >= 0)
331 sendConsoleEcho(strInfo.substring(strInfo.lastIndexOf(",") + 2,
332 strInfo.length() - 1));
336 sendConsoleMessage(data == null ? null : strInfo);
339 sendConsoleMessage(strInfo);
346 private void notifyFileLoaded(String string, String string2,
347 String string3, String string4, int intValue)
349 // TODO Auto-generated method stub
353 String lastConsoleEcho = "";
355 private void sendConsoleEcho(String string)
357 lastConsoleEcho += string;
358 lastConsoleEcho += "\n";
361 String lastConsoleMessage = "";
363 private void sendConsoleMessage(String string)
365 lastConsoleMessage += string;
366 lastConsoleMessage += "\n";
369 int lastScriptTermination = -1;
371 String lastScriptMessage = "";
373 private void notifyScriptTermination(String string, int intValue)
375 lastScriptMessage += string;
376 lastScriptMessage += "\n";
377 lastScriptTermination = intValue;
381 public boolean notifyEnabled(EnumCallback callbackPick)
383 switch (callbackPick)
404 public String eval(String strEval)
406 // TODO Auto-generated method stub
411 public float[][] functionXY(String functionName, int x, int y)
413 // TODO Auto-generated method stub
418 public float[][][] functionXYZ(String functionName, int nx, int ny, int nz)
420 // TODO Auto-generated method stub
425 public String createImage(String fileName, String type,
426 Object text_or_bytes, int quality)
428 // TODO Auto-generated method stub
433 public Map<String, Object> getRegistryInfo()
435 // TODO Auto-generated method stub
440 public void showUrl(String url)
442 // TODO Auto-generated method stub
447 public void resizeInnerPanel(String data)
449 // TODO Auto-generated method stub