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.api.AlignmentViewPanel;
24 import jalview.api.FeatureRenderer;
25 import jalview.api.SequenceRenderer;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.ColumnSelection;
28 import jalview.datamodel.PDBEntry;
29 import jalview.datamodel.SequenceI;
30 import jalview.io.DataSourceType;
31 import jalview.io.StructureFile;
32 import jalview.schemes.ColourSchemeI;
33 import jalview.schemes.ResidueProperties;
34 import jalview.structure.AtomSpec;
35 import jalview.structure.StructureMappingcommandSet;
36 import jalview.structure.StructureSelectionManager;
37 import jalview.structures.models.AAStructureBindingModel;
38 import jalview.util.MessageManager;
40 import java.awt.Color;
41 import java.awt.Container;
42 import java.awt.event.ComponentEvent;
43 import java.awt.event.ComponentListener;
46 import java.security.AccessControlException;
47 import java.util.ArrayList;
48 import java.util.BitSet;
49 import java.util.Hashtable;
50 import java.util.List;
52 import java.util.Vector;
54 import org.jmol.adapter.smarter.SmarterJmolAdapter;
55 import org.jmol.api.JmolAppConsoleInterface;
56 import org.jmol.api.JmolSelectionListener;
57 import org.jmol.api.JmolStatusListener;
58 import org.jmol.api.JmolViewer;
59 import org.jmol.c.CBK;
60 import org.jmol.script.T;
61 import org.jmol.viewer.Viewer;
63 public abstract class JalviewJmolBinding extends AAStructureBindingModel
64 implements JmolStatusListener, JmolSelectionListener,
67 boolean allChainsSelected = false;
70 * when true, try to search the associated datamodel for sequences that are
71 * associated with any unknown structures in the Jmol view.
73 private boolean associateNewStructs = false;
75 Vector<String> atomsPicked = new Vector<String>();
77 private List<String> chainNames;
79 Hashtable<String, String> chainFile;
82 * the default or current model displayed if the model cannot be identified
83 * from the selection message
87 // protected JmolGenericPopup jmolpopup; // not used - remove?
95 StringBuffer resetLastRes = new StringBuffer();
99 public JalviewJmolBinding(StructureSelectionManager ssm,
100 PDBEntry[] pdbentry, SequenceI[][] sequenceIs,
101 DataSourceType protocol)
103 super(ssm, pdbentry, sequenceIs, protocol);
105 * viewer = JmolViewer.allocateViewer(renderPanel, new SmarterJmolAdapter(),
106 * "jalviewJmol", ap.av.applet .getDocumentBase(),
107 * ap.av.applet.getCodeBase(), "", this);
109 * jmolpopup = JmolPopup.newJmolPopup(viewer, true, "Jmol", true);
113 public JalviewJmolBinding(StructureSelectionManager ssm,
114 SequenceI[][] seqs, Viewer theViewer)
119 viewer.setJmolStatusListener(this);
120 viewer.addSelectionListener(this);
124 * construct a title string for the viewer window based on the data jalview
129 public String getViewerTitle()
131 return getViewerTitle("Jmol", true);
135 * prepare the view for a given set of models/chains. chainList contains
136 * strings of the form 'pdbfilename:Chaincode'
139 * list of chains to make visible
141 public void centerViewer(Vector<String> chainList)
143 StringBuilder cmd = new StringBuilder(128);
145 for (String lbl : chainList)
151 mlength = lbl.indexOf(":", p);
152 } while (p < mlength && mlength < (lbl.length() - 2));
153 // TODO: lookup each pdb id and recover proper model number for it.
154 cmd.append(":" + lbl.substring(mlength + 1) + " /"
155 + (1 + getModelNum(chainFile.get(lbl))) + " or ");
157 if (cmd.length() > 0)
159 cmd.setLength(cmd.length() - 4);
161 evalStateCommand("select *;restrict " + cmd + ";cartoon;center " + cmd);
164 public void closeViewer()
166 // remove listeners for all structures in viewer
167 getSsm().removeStructureViewerListener(this, this.getPdbFile());
171 releaseUIResources();
175 public void colourByChain()
177 colourBySequence = false;
178 // TODO: colour by chain should colour each chain distinctly across all
180 // TODO: http://issues.jalview.org/browse/JAL-628
181 evalStateCommand("select *;color chain");
185 public void colourByCharge()
187 colourBySequence = false;
188 evalStateCommand("select *;color white;select ASP,GLU;color red;"
189 + "select LYS,ARG;color blue;select CYS;color yellow");
193 * superpose the structures associated with sequences in the alignment
194 * according to their corresponding positions.
196 public void superposeStructures(AlignmentI alignment)
198 superposeStructures(alignment, -1, null);
202 * superpose the structures associated with sequences in the alignment
203 * according to their corresponding positions. ded)
205 * @param refStructure
206 * - select which pdb file to use as reference (default is -1 - the
207 * first structure in the alignment)
209 public void superposeStructures(AlignmentI alignment, int refStructure)
211 superposeStructures(alignment, refStructure, null);
215 * superpose the structures associated with sequences in the alignment
216 * according to their corresponding positions. ded)
218 * @param refStructure
219 * - select which pdb file to use as reference (default is -1 - the
220 * first structure in the alignment)
224 public void superposeStructures(AlignmentI alignment, int refStructure,
225 ColumnSelection hiddenCols)
227 superposeStructures(new AlignmentI[] { alignment },
228 new int[] { refStructure },
229 new ColumnSelection[] { hiddenCols });
236 public String superposeStructures(AlignmentI[] _alignment,
237 int[] _refStructure, ColumnSelection[] _hiddenCols)
239 while (viewer.isScriptExecuting())
244 } catch (InterruptedException i)
250 * get the distinct structure files modelled
251 * (a file with multiple chains may map to multiple sequences)
253 String[] files = getPdbFile();
254 if (!waitForFileLoad(files))
259 StringBuilder selectioncom = new StringBuilder(256);
260 // In principle - nSeconds specifies the speed of animation for each
261 // superposition - but is seems to behave weirdly, so we don't specify it.
262 String nSeconds = " ";
263 if (files.length > 10)
265 nSeconds = " 0.005 ";
269 nSeconds = " " + (2.0 / files.length) + " ";
270 // if (nSeconds).substring(0,5)+" ";
273 // see JAL-1345 - should really automatically turn off the animation for
274 // large numbers of structures, but Jmol doesn't seem to allow that.
276 // union of all aligned positions are collected together.
277 for (int a = 0; a < _alignment.length; a++)
279 int refStructure = _refStructure[a];
280 AlignmentI alignment = _alignment[a];
281 ColumnSelection hiddenCols = _hiddenCols[a];
283 && selectioncom.length() > 0
284 && !selectioncom.substring(selectioncom.length() - 1).equals(
287 selectioncom.append("|");
289 // process this alignment
290 if (refStructure >= files.length)
292 System.err.println("Invalid reference structure value "
298 * 'matched' bit j will be set for visible alignment columns j where
299 * all sequences have a residue with a mapping to the PDB structure
301 BitSet matched = new BitSet();
302 for (int m = 0; m < alignment.getWidth(); m++)
304 if (hiddenCols == null || hiddenCols.isVisible(m))
310 SuperposeData[] structures = new SuperposeData[files.length];
311 for (int f = 0; f < files.length; f++)
313 structures[f] = new SuperposeData(alignment.getWidth());
317 * Calculate the superposable alignment columns ('matched'), and the
318 * corresponding structure residue positions (structures.pdbResNo)
320 int candidateRefStructure = findSuperposableResidues(alignment,
321 matched, structures);
322 if (refStructure < 0)
325 * If no reference structure was specified, pick the first one that has
326 * a mapping in the alignment
328 refStructure = candidateRefStructure;
331 String[] selcom = new String[files.length];
332 int nmatched = matched.cardinality();
335 return (MessageManager.formatMessage(
336 "label.insufficient_residues",
341 * generate select statements to select regions to superimpose structures
344 // TODO extract method to construct selection statements
345 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
347 String chainCd = ":" + structures[pdbfnum].chain;
350 StringBuilder molsel = new StringBuilder();
353 int nextColumnMatch = matched.nextSetBit(0);
354 while (nextColumnMatch != -1)
356 int pdbResNo = structures[pdbfnum].pdbResNo[nextColumnMatch];
357 if (lpos != pdbResNo - 1)
363 molsel.append(chainCd);
370 // continuous run - and lpos >-1
373 // at the beginning, so add dash
380 nextColumnMatch = matched.nextSetBit(nextColumnMatch + 1);
383 * add final selection phrase
388 molsel.append(chainCd);
391 if (molsel.length() > 1)
393 selcom[pdbfnum] = molsel.toString();
394 selectioncom.append("((");
395 selectioncom.append(selcom[pdbfnum].substring(1,
396 selcom[pdbfnum].length() - 1));
397 selectioncom.append(" )& ");
398 selectioncom.append(pdbfnum + 1);
399 selectioncom.append(".1)");
400 if (pdbfnum < files.length - 1)
402 selectioncom.append("|");
407 selcom[pdbfnum] = null;
411 StringBuilder command = new StringBuilder(256);
412 // command.append("set spinFps 10;\n");
414 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
416 if (pdbfnum == refStructure || selcom[pdbfnum] == null
417 || selcom[refStructure] == null)
421 command.append("echo ");
422 command.append("\"Superposing (");
423 command.append(structures[pdbfnum].pdbId);
424 command.append(") against reference (");
425 command.append(structures[refStructure].pdbId);
426 command.append(")\";\ncompare " + nSeconds);
428 command.append(Integer.toString(1 + pdbfnum));
429 command.append(".1} {");
430 command.append(Integer.toString(1 + refStructure));
431 // conformation=1 excludes alternate locations for CA (JAL-1757)
432 command.append(".1} SUBSET {(*.CA | *.P) and conformation=1} ATOMS ");
434 // for (int s = 0; s < 2; s++)
436 // command.append(selcom[(s == 0 ? pdbfnum : refStructure)]);
438 command.append(selcom[pdbfnum]);
439 command.append(selcom[refStructure]);
440 command.append(" ROTATE TRANSLATE;\n");
442 if (selectioncom.length() > 0)
444 // TODO is performing selectioncom redundant here? is done later on
445 // System.out.println("Select regions:\n" + selectioncom.toString());
446 evalStateCommand("select *; cartoons off; backbone; select ("
447 + selectioncom.toString() + "); cartoons; ");
448 // selcom.append("; ribbons; ");
449 String cmdString = command.toString();
450 // System.out.println("Superimpose command(s):\n" + cmdString);
452 evalStateCommand(cmdString);
455 if (selectioncom.length() > 0)
456 {// finally, mark all regions that were superposed.
457 if (selectioncom.substring(selectioncom.length() - 1).equals("|"))
459 selectioncom.setLength(selectioncom.length() - 1);
461 // System.out.println("Select regions:\n" + selectioncom.toString());
462 evalStateCommand("select *; cartoons off; backbone; select ("
463 + selectioncom.toString() + "); cartoons; ");
464 // evalStateCommand("select *; backbone; select "+selcom.toString()+"; cartoons; center "+selcom.toString());
470 public void evalStateCommand(String command)
473 if (lastCommand == null || !lastCommand.equals(command))
475 viewer.evalStringQuiet(command + "\n");
478 lastCommand = command;
482 * Sends a set of colour commands to the structure viewer
484 * @param colourBySequenceCommands
487 protected void colourBySequence(
488 StructureMappingcommandSet[] colourBySequenceCommands)
490 for (StructureMappingcommandSet cpdbbyseq : colourBySequenceCommands)
492 for (String cbyseq : cpdbbyseq.commands)
494 executeWhenReady(cbyseq);
506 protected StructureMappingcommandSet[] getColourBySequenceCommands(
507 String[] files, SequenceRenderer sr, AlignmentViewPanel viewPanel)
509 return JmolCommands.getColourBySequenceCommand(getSsm(), files,
510 getSequence(), sr, viewPanel);
516 protected void executeWhenReady(String command)
518 evalStateCommand(command);
521 public void createImage(String file, String type, int quality)
523 System.out.println("JMOL CREATE IMAGE");
527 public String createImage(String fileName, String type,
528 Object textOrBytes, int quality)
530 System.out.println("JMOL CREATE IMAGE");
535 public String eval(String strEval)
537 // System.out.println(strEval);
538 // "# 'eval' is implemented only for the applet.";
542 // End StructureListener
543 // //////////////////////////
546 public float[][] functionXY(String functionName, int x, int y)
552 public float[][][] functionXYZ(String functionName, int nx, int ny, int nz)
554 // TODO Auto-generated method stub
558 public Color getColour(int atomIndex, int pdbResNum, String chain,
561 if (getModelNum(pdbfile) < 0)
565 // TODO: verify atomIndex is selecting correct model.
566 // return new Color(viewer.getAtomArgb(atomIndex)); Jmol 12.2.4
567 int colour = viewer.ms.at[atomIndex].atomPropertyInt(T.color);
568 return new Color(colour);
572 * instruct the Jalview binding to update the pdbentries vector if necessary
573 * prior to matching the jmol view's contents to the list of structure files
574 * Jalview knows about.
576 public abstract void refreshPdbEntries();
578 private int getModelNum(String modelFileName)
580 String[] mfn = getPdbFile();
585 for (int i = 0; i < mfn.length; i++)
587 if (mfn[i].equalsIgnoreCase(modelFileName))
596 * map between index of model filename returned from getPdbFile and the first
597 * index of models from this file in the viewer. Note - this is not trimmed -
598 * use getPdbFile to get number of unique models.
600 private int _modelFileNameMap[];
602 // ////////////////////////////////
603 // /StructureListener
605 public synchronized String[] getPdbFile()
609 return new String[0];
611 if (modelFileNames == null)
613 List<String> mset = new ArrayList<String>();
614 _modelFileNameMap = new int[viewer.ms.mc];
615 String m = viewer.ms.getModelFileName(0);
621 filePath = new File(m).getAbsolutePath();
622 } catch (AccessControlException x)
624 // usually not allowed to do this in applet
626 .println("jmolBinding: Using local file string from Jmol: "
629 if (filePath.indexOf("/file:") != -1)
631 // applet path with docroot - discard as format won't match pdbfile
635 _modelFileNameMap[0] = 0; // filename index for first model is always 0.
638 for (int i = 1; i < viewer.ms.mc; i++)
640 m = viewer.ms.getModelFileName(i);
646 filePath = new File(m).getAbsolutePath();
647 } catch (AccessControlException x)
649 // usually not allowed to do this in applet, so keep raw handle
650 // System.err.println("jmolBinding: Using local file string from Jmol: "+m);
655 * add this model unless it is read from a structure file we have
656 * already seen (example: 2MJW is an NMR structure with 10 models)
658 if (!mset.contains(filePath))
661 _modelFileNameMap[j] = i; // record the model index for the filename
665 modelFileNames = mset.toArray(new String[mset.size()]);
667 return modelFileNames;
671 * map from string to applet
674 public Map<String, Object> getRegistryInfo()
676 // TODO Auto-generated method stub
682 // ///////////////////////////////
683 // JmolStatusListener
685 public void handlePopupMenu(int x, int y)
687 // jmolpopup.show(x, y);
688 // jmolpopup.jpiShow(x, y);
692 * Highlight zero, one or more atoms on the structure
695 public void highlightAtoms(List<AtomSpec> atoms)
699 if (resetLastRes.length() > 0)
701 viewer.evalStringQuiet(resetLastRes.toString());
702 resetLastRes.setLength(0);
704 for (AtomSpec atom : atoms)
706 highlightAtom(atom.getAtomIndex(), atom.getPdbResNum(),
707 atom.getChain(), atom.getPdbFile());
713 public void highlightAtom(int atomIndex, int pdbResNum, String chain,
716 if (modelFileNames == null)
721 // look up file model number for this pdbfile
723 // may need to adjust for URLencoding here - we don't worry about that yet.
724 while (mdlNum < modelFileNames.length
725 && !pdbfile.equals(modelFileNames[mdlNum]))
729 if (mdlNum == modelFileNames.length)
736 StringBuilder cmd = new StringBuilder(64);
737 cmd.append("select " + pdbResNum); // +modelNum
739 resetLastRes.append("select " + pdbResNum); // +modelNum
742 resetLastRes.append(":");
743 if (!chain.equals(" "))
746 resetLastRes.append(chain);
749 cmd.append(" /" + (mdlNum + 1));
750 resetLastRes.append("/" + (mdlNum + 1));
752 cmd.append(";wireframe 100;" + cmd.toString() + " and not hetero;");
754 resetLastRes.append(";wireframe 0;" + resetLastRes.toString()
755 + " and not hetero; spacefill 0;");
757 cmd.append("spacefill 200;select none");
759 viewer.evalStringQuiet(cmd.toString());
764 boolean debug = true;
766 private void jmolHistory(boolean enable)
768 viewer.evalStringQuiet("History " + ((debug || enable) ? "on" : "off"));
771 public void loadInline(String string)
775 // viewer.loadInline(strModel, isAppend);
777 // construct fake fullPathName and fileName so we can identify the file
779 // Then, construct pass a reader for the string to Jmol.
780 // ((org.jmol.Viewer.Viewer) viewer).loadModelFromFile(fullPathName,
781 // fileName, null, reader, false, null, null, 0);
782 viewer.openStringInline(string);
785 public void mouseOverStructure(int atomIndex, String strInfo)
788 int alocsep = strInfo.indexOf("^");
789 int mdlSep = strInfo.indexOf("/");
790 int chainSeparator = strInfo.indexOf(":"), chainSeparator1 = -1;
792 if (chainSeparator == -1)
794 chainSeparator = strInfo.indexOf(".");
795 if (mdlSep > -1 && mdlSep < chainSeparator)
797 chainSeparator1 = chainSeparator;
798 chainSeparator = mdlSep;
801 // handle insertion codes
804 pdbResNum = Integer.parseInt(strInfo.substring(
805 strInfo.indexOf("]") + 1, alocsep));
810 pdbResNum = Integer.parseInt(strInfo.substring(
811 strInfo.indexOf("]") + 1, chainSeparator));
815 if (strInfo.indexOf(":") > -1)
817 chainId = strInfo.substring(strInfo.indexOf(":") + 1,
818 strInfo.indexOf("."));
825 String pdbfilename = modelFileNames[frameNo]; // default is first or current
829 if (chainSeparator1 == -1)
831 chainSeparator1 = strInfo.indexOf(".", mdlSep);
833 String mdlId = (chainSeparator1 > -1) ? strInfo.substring(mdlSep + 1,
834 chainSeparator1) : strInfo.substring(mdlSep + 1);
837 // recover PDB filename for the model hovered over.
838 int _mp = _modelFileNameMap.length - 1, mnumber = new Integer(mdlId)
840 while (mnumber < _modelFileNameMap[_mp])
844 pdbfilename = modelFileNames[_mp];
845 if (pdbfilename == null)
847 pdbfilename = new File(viewer.ms.getModelFileName(mnumber))
851 } catch (Exception e)
856 if (lastMessage == null || !lastMessage.equals(strInfo))
858 getSsm().mouseOverStructure(pdbResNum, chainId, pdbfilename);
861 lastMessage = strInfo;
864 public void notifyAtomHovered(int atomIndex, String strInfo, String data)
868 System.err.println("Ignoring additional hover info: " + data
869 + " (other info: '" + strInfo + "' pos " + atomIndex + ")");
871 mouseOverStructure(atomIndex, strInfo);
875 * { if (history != null && strStatus != null &&
876 * !strStatus.equals("Script completed")) { history.append("\n" + strStatus);
880 public void notifyAtomPicked(int atomIndex, String strInfo, String strData)
883 * this implements the toggle label behaviour copied from the original
884 * structure viewer, MCView
888 System.err.println("Ignoring additional pick data string " + strData);
890 int chainSeparator = strInfo.indexOf(":");
892 if (chainSeparator == -1)
894 chainSeparator = strInfo.indexOf(".");
897 String picked = strInfo.substring(strInfo.indexOf("]") + 1,
899 String mdlString = "";
900 if ((p = strInfo.indexOf(":")) > -1)
902 picked += strInfo.substring(p, strInfo.indexOf("."));
905 if ((p = strInfo.indexOf("/")) > -1)
907 mdlString += strInfo.substring(p, strInfo.indexOf(" #"));
909 picked = "((" + picked + ".CA" + mdlString + ")|(" + picked + ".P"
913 if (!atomsPicked.contains(picked))
915 viewer.evalStringQuiet("select " + picked + ";label %n %r:%c");
916 atomsPicked.addElement(picked);
920 viewer.evalString("select " + picked + ";label off");
921 atomsPicked.removeElement(picked);
924 // TODO: in application this happens
926 // if (scriptWindow != null)
928 // scriptWindow.sendConsoleMessage(strInfo);
929 // scriptWindow.sendConsoleMessage("\n");
935 public void notifyCallback(CBK type, Object[] data)
942 notifyFileLoaded((String) data[1], (String) data[2],
943 (String) data[3], (String) data[4],
944 ((Integer) data[5]).intValue());
948 notifyAtomPicked(((Integer) data[2]).intValue(), (String) data[1],
950 // also highlight in alignment
952 notifyAtomHovered(((Integer) data[2]).intValue(), (String) data[1],
956 notifyScriptTermination((String) data[2],
957 ((Integer) data[3]).intValue());
960 sendConsoleEcho((String) data[1]);
963 sendConsoleMessage((data == null) ? ((String) null)
967 // System.err.println("Ignoring error callback.");
977 System.err.println("Unhandled callback " + type + " "
978 + data[1].toString());
981 } catch (Exception e)
983 System.err.println("Squashed Jmol callback handler error:");
989 public boolean notifyEnabled(CBK callbackPick)
991 switch (callbackPick)
1007 // incremented every time a load notification is successfully handled -
1008 // lightweight mechanism for other threads to detect when they can start
1009 // referrring to new structures.
1010 private long loadNotifiesHandled = 0;
1012 public long getLoadNotifiesHandled()
1014 return loadNotifiesHandled;
1017 public void notifyFileLoaded(String fullPathName, String fileName2,
1018 String modelName, String errorMsg, int modelParts)
1020 if (errorMsg != null)
1022 fileLoadingError = errorMsg;
1026 // TODO: deal sensibly with models loaded inLine:
1027 // modelName will be null, as will fullPathName.
1029 // the rest of this routine ignores the arguments, and simply interrogates
1030 // the Jmol view to find out what structures it contains, and adds them to
1031 // the structure selection manager.
1032 fileLoadingError = null;
1033 String[] oldmodels = modelFileNames;
1034 modelFileNames = null;
1035 chainNames = new ArrayList<String>();
1036 chainFile = new Hashtable<String, String>();
1037 boolean notifyLoaded = false;
1038 String[] modelfilenames = getPdbFile();
1039 // first check if we've lost any structures
1040 if (oldmodels != null && oldmodels.length > 0)
1043 for (int i = 0; i < oldmodels.length; i++)
1045 for (int n = 0; n < modelfilenames.length; n++)
1047 if (modelfilenames[n] == oldmodels[i])
1049 oldmodels[i] = null;
1053 if (oldmodels[i] != null)
1060 String[] oldmfn = new String[oldm];
1062 for (int i = 0; i < oldmodels.length; i++)
1064 if (oldmodels[i] != null)
1066 oldmfn[oldm++] = oldmodels[i];
1069 // deregister the Jmol instance for these structures - we'll add
1070 // ourselves again at the end for the current structure set.
1071 getSsm().removeStructureViewerListener(this, oldmfn);
1074 refreshPdbEntries();
1075 for (int modelnum = 0; modelnum < modelfilenames.length; modelnum++)
1077 String fileName = modelfilenames[modelnum];
1078 boolean foundEntry = false;
1079 StructureFile pdb = null;
1080 String pdbfile = null;
1081 // model was probably loaded inline - so check the pdb file hashcode
1084 // calculate essential attributes for the pdb data imported inline.
1085 // prolly need to resolve modelnumber properly - for now just use our
1087 pdbfile = viewer.getData("" + (1 + _modelFileNameMap[modelnum])
1090 // search pdbentries and sequences to find correct pdbentry for this
1092 for (int pe = 0; pe < getPdbCount(); pe++)
1094 boolean matches = false;
1095 addSequence(pe, getSequence()[pe]);
1096 if (fileName == null)
1099 // see JAL-623 - need method of matching pasted data up
1101 pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe],
1102 pdbfile, DataSourceType.PASTE);
1103 getPdbEntry(modelnum).setFile("INLINE" + pdb.getId());
1110 File fl = new File(getPdbEntry(pe).getFile());
1111 matches = fl.equals(new File(fileName));
1115 // TODO: Jmol can in principle retrieve from CLASSLOADER but
1118 // to be tested. See mantis bug
1119 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
1120 DataSourceType protocol = DataSourceType.URL;
1125 protocol = DataSourceType.FILE;
1127 } catch (Exception e)
1132 // Explicitly map to the filename used by Jmol ;
1133 pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe],
1134 fileName, protocol);
1135 // pdbentry[pe].getFile(), protocol);
1141 // add an entry for every chain in the model
1142 for (int i = 0; i < pdb.getChains().size(); i++)
1144 String chid = new String(pdb.getId() + ":"
1145 + pdb.getChains().elementAt(i).id);
1146 chainFile.put(chid, fileName);
1147 chainNames.add(chid);
1149 notifyLoaded = true;
1153 if (!foundEntry && associateNewStructs)
1155 // this is a foreign pdb file that jalview doesn't know about - add
1156 // it to the dataset and try to find a home - either on a matching
1157 // sequence or as a new sequence.
1158 String pdbcontent = viewer.getData("/" + (modelnum + 1) + ".1",
1160 // parse pdb file into a chain, etc.
1161 // locate best match for pdb in associated views and add mapping to
1163 // if properly registered then
1164 notifyLoaded = true;
1169 // so finally, update the jmol bits and pieces
1170 // if (jmolpopup != null)
1172 // // potential for deadlock here:
1173 // // jmolpopup.updateComputedMenus();
1175 if (!isLoadingFromArchive())
1177 viewer.evalStringQuiet("model *; select backbone;restrict;cartoon;wireframe off;spacefill off");
1179 // register ourselves as a listener and notify the gui that it needs to
1181 getSsm().addStructureViewerListener(this);
1184 FeatureRenderer fr = getFeatureRenderer(null);
1187 loadNotifiesHandled++;
1189 setLoadingFromArchive(false);
1193 public List<String> getChainNames()
1198 public void notifyNewPickingModeMeasurement(int iatom, String strMeasure)
1200 notifyAtomPicked(iatom, strMeasure, null);
1203 public abstract void notifyScriptTermination(String strStatus,
1207 * display a message echoed from the jmol viewer
1211 public abstract void sendConsoleEcho(String strEcho); /*
1212 * { showConsole(true);
1214 * history.append("\n" +
1218 // /End JmolStatusListener
1219 // /////////////////////////////
1223 * status message - usually the response received after a script
1226 public abstract void sendConsoleMessage(String strStatus);
1229 public void setCallbackFunction(String callbackType,
1230 String callbackFunction)
1232 System.err.println("Ignoring set-callback request to associate "
1233 + callbackType + " with function " + callbackFunction);
1238 public void setJalviewColourScheme(ColourSchemeI cs)
1240 colourBySequence = false;
1248 StringBuilder command = new StringBuilder(128);
1249 command.append("select *;color white;");
1250 List<String> residueSet = ResidueProperties.getResidues(isNucleotide(),
1252 for (String resName : residueSet)
1254 char res = resName.length() == 3 ? ResidueProperties
1255 .getSingleCharacterCode(resName) : resName.charAt(0);
1256 Color col = cs.findColour(res, 0, null, null, 0f);
1257 command.append("select " + resName + ";color[" + col.getRed() + ","
1258 + col.getGreen() + "," + col.getBlue() + "];");
1261 evalStateCommand(command.toString());
1265 public void showHelp()
1267 showUrl("http://jmol.sourceforge.net/docs/JmolUserGuide/", "jmolHelp");
1271 * open the URL somehow
1275 public abstract void showUrl(String url, String target);
1278 * called when the binding thinks the UI needs to be refreshed after a Jmol
1279 * state change. this could be because structures were loaded, or because an
1280 * error has occured.
1282 public abstract void refreshGUI();
1285 * called to show or hide the associated console window container.
1289 public abstract void showConsole(boolean show);
1292 * @param renderPanel
1294 * - when true will initialise jmol's file IO system (should be false
1295 * in applet context)
1297 * @param documentBase
1299 * @param commandOptions
1301 public void allocateViewer(Container renderPanel, boolean jmolfileio,
1302 String htmlName, URL documentBase, URL codeBase,
1303 String commandOptions)
1305 allocateViewer(renderPanel, jmolfileio, htmlName, documentBase,
1306 codeBase, commandOptions, null, null);
1311 * @param renderPanel
1313 * - when true will initialise jmol's file IO system (should be false
1314 * in applet context)
1316 * @param documentBase
1318 * @param commandOptions
1319 * @param consolePanel
1320 * - panel to contain Jmol console
1321 * @param buttonsToShow
1322 * - buttons to show on the console, in ordr
1324 public void allocateViewer(Container renderPanel, boolean jmolfileio,
1325 String htmlName, URL documentBase, URL codeBase,
1326 String commandOptions, final Container consolePanel,
1327 String buttonsToShow)
1329 if (commandOptions == null)
1331 commandOptions = "";
1333 viewer = (Viewer) JmolViewer.allocateViewer(renderPanel,
1334 (jmolfileio ? new SmarterJmolAdapter() : null), htmlName
1335 + ((Object) this).toString(), documentBase, codeBase,
1336 commandOptions, this);
1338 viewer.setJmolStatusListener(this); // extends JmolCallbackListener
1340 console = createJmolConsole(consolePanel, buttonsToShow);
1341 if (consolePanel != null)
1343 consolePanel.addComponentListener(this);
1349 protected abstract JmolAppConsoleInterface createJmolConsole(
1350 Container consolePanel, String buttonsToShow);
1352 protected org.jmol.api.JmolAppConsoleInterface console = null;
1355 public void setBackgroundColour(java.awt.Color col)
1358 viewer.evalStringQuiet("background [" + col.getRed() + ","
1359 + col.getGreen() + "," + col.getBlue() + "];");
1364 public int[] resizeInnerPanel(String data)
1366 // Jalview doesn't honour resize panel requests
1373 protected void closeConsole()
1375 if (console != null)
1379 console.setVisible(false);
1382 } catch (Exception x)
1391 * ComponentListener method
1394 public void componentMoved(ComponentEvent e)
1399 * ComponentListener method
1402 public void componentResized(ComponentEvent e)
1407 * ComponentListener method
1410 public void componentShown(ComponentEvent e)
1416 * ComponentListener method
1419 public void componentHidden(ComponentEvent e)