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 javajs.awt.Dimension;
39 import org.jmol.api.JmolStatusListener;
40 import org.jmol.api.JmolViewer;
41 import org.jmol.c.CBK;
42 import org.jmol.modelset.Group;
43 import org.jmol.modelset.Model;
44 import org.jmol.modelset.ModelSet;
45 import org.jmol.modelsetbio.BioModel;
46 import org.jmol.modelsetbio.BioPolymer;
47 import org.jmol.viewer.Viewer;
48 import org.openscience.jmol.app.JmolApp;
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) throws IOException
69 public PDBFileWithJmol(FileParse fp) throws IOException
74 public PDBFileWithJmol()
76 // TODO Auto-generated constructor stub
80 * create a headless jmol instance for dataprocessing
84 private Viewer getJmolData()
87 { // note that -o -n -x are all implied // TODO check for Jmol 14.2
88 jmolApp = new JmolApp();
89 jmolApp.isDataOnly = true;
90 jmolApp.haveConsole = false;
91 jmolApp.haveDisplay = false;
94 viewer = (Viewer) JmolViewer.allocateViewer(null, null, null, null,
95 null, "-x -o -n", this);
96 viewer.setScreenDimension(jmolApp.startupWidth,
97 jmolApp.startupHeight);
98 jmolApp.startViewer(viewer, null, false);
99 } catch (ClassCastException x)
101 throw new Error(MessageManager.formatMessage("error.jmol_version_not_compatible_with_jalview_version", new String[]{JmolViewer.getJmolVersion()}),
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());
136 ModelSet ms = jmd.ms;
137 // Jmol 14.2 added third argument doReport = false
138 ms.calculateStructures(null, true, false, false, true);
139 // System.out.println("Structs\n"+structs);
142 for (Model model : ms.am)
145 for (BioPolymer bp : ((BioModel) model).bioPolymers)
147 int lastChainId = 0; // int value of character e.g. 65 for A
148 String lastChainIdAlpha = "";
150 int[] groups = bp.getLeadAtomIndices();
151 char seq[] = new char[groups.length], secstr[] = new char[groups.length], secstrcode[] = new char[groups.length];
152 int groupc = 0, len = 0, firstrnum = 1, lastrnum = 0;
156 if (groupc >= groups.length
157 || ms.at[groups[groupc]].group.chain.chainID != lastChainId)
160 * on change of chain (or at end), construct the sequence and
161 * secondary structure annotation for the last chain
165 boolean isNa = bp.isNucleic();
166 // normalise sequence from Jmol to jalview
167 int[] cinds = isNa ? ResidueProperties.nucleotideIndex
168 : ResidueProperties.aaIndex;
169 int nonGap = isNa ? ResidueProperties.maxNucleotideIndex
170 : ResidueProperties.maxProteinIndex;
172 char newseq[] = new char[len];
173 Annotation asecstr[] = new Annotation[len + firstrnum - 1];
174 for (int p = 0; p < len; p++)
176 newseq[p] = cinds[seq[p]] == nonGap ? ngc : seq[p];
177 if (secstr[p] >= 'A' && secstr[p] <= 'z')
179 asecstr[p] = new Annotation("" + secstr[p], null,
180 secstrcode[p], Float.NaN);
183 String modelTitle = (String) ms
184 .getInfo(modelIndex, "title");
185 SequenceI sq = new Sequence("" + getDataName() + "|"
186 + modelTitle + "|" + lastChainIdAlpha, newseq,
187 firstrnum, lastrnum);
188 PDBEntry pdbe = new PDBEntry();
189 pdbe.setFile(getDataName());
190 pdbe.setId(getDataName());
191 pdbe.setProperty(new Hashtable());
192 // pdbe.getProperty().put("CHAIN", "" + _lastChainId);
193 pdbe.setChainCode(lastChainIdAlpha);
196 // Need to put the number of models for this polymer somewhere
197 // for Chimera/others to grab
198 // pdbe.getProperty().put("PDBMODELS", biopoly.)
202 String mt = modelTitle == null ? getDataName()
204 if (lastChainId >= ' ')
206 mt += lastChainIdAlpha;
208 AlignmentAnnotation ann = new AlignmentAnnotation(
209 "Secondary Structure", "Secondary Structure for "
211 ann.belowAlignment = true;
213 ann.autoCalculated = false;
214 ann.setCalcId(getClass().getName());
215 sq.addAlignmentAnnotation(ann);
216 ann.adjustForAlignment();
217 ann.validateRangeAndDisplay();
218 annotations.add(ann);
225 if (groupc < groups.length)
227 group = ms.at[groups[groupc]].group;
230 firstrnum = group.getResno();
231 lastChainId = group.chain.chainID;
232 lastChainIdAlpha = group.chain.getIDStr();
236 lastrnum = group.getResno();
238 seq[len] = group.getGroup1();
239 switch (group.getProteinStructureSubType())
242 if (secstr[len] == 0)
247 if (secstr[len] == 0)
252 if (secstr[len] == 0)
257 if (secstr[len] == 0)
261 secstrcode[len] = 'H';
265 secstrcode[len] = 'E';
273 } while (groupc++ < groups.length);
278 * lastScriptTermination = -9465; String dsspOut =
279 * jmd.evalString("calculate STRUCTURE"); if (dsspOut.equals("pending")) {
280 * while (lastScriptTermination == -9465) { try { Thread.sleep(50); }
281 * catch (Exception x) { } ; } } System.out.println(lastConsoleEcho);
289 * @see jalview.io.AlignFile#print()
292 public String print()
294 // TODO Auto-generated method stub
299 public void setCallbackFunction(String callbackType,
300 String callbackFunction)
302 // TODO Auto-generated method stub
307 * @Override public void notifyCallback(EnumCallback type, Object[] data) {
308 * try { switch (type) { case ERROR: case SCRIPT:
309 * notifyScriptTermination((String) data[2], ((Integer) data[3]).intValue());
310 * break; case MESSAGE: sendConsoleMessage((data == null) ? ((String) null) :
311 * (String) data[1]); break; case LOADSTRUCT: notifyFileLoaded((String)
312 * data[1], (String) data[2], (String) data[3], (String) data[4], ((Integer)
313 * data[5]).intValue());
315 * break; default: // System.err.println("Unhandled callback " + type + " " //
316 * + data[1].toString()); break; } } catch (Exception e) {
317 * System.err.println("Squashed Jmol callback handler error:");
318 * e.printStackTrace(); } }
320 public void notifyCallback(CBK type, Object[] data)
322 String strInfo = (data == null || data[1] == null ? null : data[1]
327 sendConsoleEcho(strInfo);
330 notifyScriptTermination((String) data[2],
331 ((Integer) data[3]).intValue());
334 String mystatus = (String) data[3];
335 if (mystatus.indexOf("Picked") >= 0
336 || mystatus.indexOf("Sequence") >= 0)
339 sendConsoleMessage(strInfo);
341 else if (mystatus.indexOf("Completed") >= 0)
343 sendConsoleEcho(strInfo.substring(strInfo.lastIndexOf(",") + 2,
344 strInfo.length() - 1));
348 sendConsoleMessage(data == null ? null : strInfo);
351 sendConsoleMessage(strInfo);
358 String lastConsoleEcho = "";
360 private void sendConsoleEcho(String string)
362 lastConsoleEcho += string;
363 lastConsoleEcho += "\n";
366 String lastConsoleMessage = "";
368 private void sendConsoleMessage(String string)
370 lastConsoleMessage += string;
371 lastConsoleMessage += "\n";
374 int lastScriptTermination = -1;
376 String lastScriptMessage = "";
378 private void notifyScriptTermination(String string, int intValue)
380 lastScriptMessage += string;
381 lastScriptMessage += "\n";
382 lastScriptTermination = intValue;
386 public boolean notifyEnabled(CBK callbackPick)
388 switch (callbackPick)
402 public String eval(String strEval)
404 // TODO Auto-generated method stub
409 public float[][] functionXY(String functionName, int x, int y)
411 // TODO Auto-generated method stub
416 public float[][][] functionXYZ(String functionName, int nx, int ny, int nz)
418 // TODO Auto-generated method stub
423 public String createImage(String fileName, String type,
424 Object text_or_bytes, int quality)
426 // TODO Auto-generated method stub
431 public Map<String, Object> getRegistryInfo()
433 // TODO Auto-generated method stub
438 public void showUrl(String url)
440 // TODO Auto-generated method stub
445 public Dimension resizeInnerPanel(String data)
451 public Map<String, Object> getJSpecViewProperty(String arg0)