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.AlignViewportI;
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);
507 protected StructureMappingcommandSet[] getColourBySequenceCommands(
508 String[] files, SequenceRenderer sr, FeatureRenderer fr,
509 AlignViewportI viewport)
511 return JmolCommands.getColourBySequenceCommand(getSsm(), files,
512 getSequence(), sr, fr, viewport);
518 protected void executeWhenReady(String command)
520 evalStateCommand(command);
523 public void createImage(String file, String type, int quality)
525 System.out.println("JMOL CREATE IMAGE");
529 public String createImage(String fileName, String type,
530 Object textOrBytes, int quality)
532 System.out.println("JMOL CREATE IMAGE");
537 public String eval(String strEval)
539 // System.out.println(strEval);
540 // "# 'eval' is implemented only for the applet.";
544 // End StructureListener
545 // //////////////////////////
548 public float[][] functionXY(String functionName, int x, int y)
554 public float[][][] functionXYZ(String functionName, int nx, int ny, int nz)
556 // TODO Auto-generated method stub
560 public Color getColour(int atomIndex, int pdbResNum, String chain,
563 if (getModelNum(pdbfile) < 0)
567 // TODO: verify atomIndex is selecting correct model.
568 // return new Color(viewer.getAtomArgb(atomIndex)); Jmol 12.2.4
569 int colour = viewer.ms.at[atomIndex].atomPropertyInt(T.color);
570 return new Color(colour);
574 * instruct the Jalview binding to update the pdbentries vector if necessary
575 * prior to matching the jmol view's contents to the list of structure files
576 * Jalview knows about.
578 public abstract void refreshPdbEntries();
580 private int getModelNum(String modelFileName)
582 String[] mfn = getPdbFile();
587 for (int i = 0; i < mfn.length; i++)
589 if (mfn[i].equalsIgnoreCase(modelFileName))
598 * map between index of model filename returned from getPdbFile and the first
599 * index of models from this file in the viewer. Note - this is not trimmed -
600 * use getPdbFile to get number of unique models.
602 private int _modelFileNameMap[];
604 // ////////////////////////////////
605 // /StructureListener
607 public synchronized String[] getPdbFile()
611 return new String[0];
613 if (modelFileNames == null)
615 List<String> mset = new ArrayList<String>();
616 _modelFileNameMap = new int[viewer.ms.mc];
617 String m = viewer.ms.getModelFileName(0);
623 filePath = new File(m).getAbsolutePath();
624 } catch (AccessControlException x)
626 // usually not allowed to do this in applet
628 .println("jmolBinding: Using local file string from Jmol: "
631 if (filePath.indexOf("/file:") != -1)
633 // applet path with docroot - discard as format won't match pdbfile
637 _modelFileNameMap[0] = 0; // filename index for first model is always 0.
640 for (int i = 1; i < viewer.ms.mc; i++)
642 m = viewer.ms.getModelFileName(i);
648 filePath = new File(m).getAbsolutePath();
649 } catch (AccessControlException x)
651 // usually not allowed to do this in applet, so keep raw handle
652 // System.err.println("jmolBinding: Using local file string from Jmol: "+m);
657 * add this model unless it is read from a structure file we have
658 * already seen (example: 2MJW is an NMR structure with 10 models)
660 if (!mset.contains(filePath))
663 _modelFileNameMap[j] = i; // record the model index for the filename
667 modelFileNames = mset.toArray(new String[mset.size()]);
669 return modelFileNames;
673 * map from string to applet
676 public Map<String, Object> getRegistryInfo()
678 // TODO Auto-generated method stub
684 // ///////////////////////////////
685 // JmolStatusListener
687 public void handlePopupMenu(int x, int y)
689 // jmolpopup.show(x, y);
690 // jmolpopup.jpiShow(x, y);
694 * Highlight zero, one or more atoms on the structure
697 public void highlightAtoms(List<AtomSpec> atoms)
701 if (resetLastRes.length() > 0)
703 viewer.evalStringQuiet(resetLastRes.toString());
704 resetLastRes.setLength(0);
706 for (AtomSpec atom : atoms)
708 highlightAtom(atom.getAtomIndex(), atom.getPdbResNum(),
709 atom.getChain(), atom.getPdbFile());
715 public void highlightAtom(int atomIndex, int pdbResNum, String chain,
718 if (modelFileNames == null)
723 // look up file model number for this pdbfile
725 // may need to adjust for URLencoding here - we don't worry about that yet.
726 while (mdlNum < modelFileNames.length
727 && !pdbfile.equals(modelFileNames[mdlNum]))
731 if (mdlNum == modelFileNames.length)
738 StringBuilder cmd = new StringBuilder(64);
739 cmd.append("select " + pdbResNum); // +modelNum
741 resetLastRes.append("select " + pdbResNum); // +modelNum
744 resetLastRes.append(":");
745 if (!chain.equals(" "))
748 resetLastRes.append(chain);
751 cmd.append(" /" + (mdlNum + 1));
752 resetLastRes.append("/" + (mdlNum + 1));
754 cmd.append(";wireframe 100;" + cmd.toString() + " and not hetero;");
756 resetLastRes.append(";wireframe 0;" + resetLastRes.toString()
757 + " and not hetero; spacefill 0;");
759 cmd.append("spacefill 200;select none");
761 viewer.evalStringQuiet(cmd.toString());
766 boolean debug = true;
768 private void jmolHistory(boolean enable)
770 viewer.evalStringQuiet("History " + ((debug || enable) ? "on" : "off"));
773 public void loadInline(String string)
777 // viewer.loadInline(strModel, isAppend);
779 // construct fake fullPathName and fileName so we can identify the file
781 // Then, construct pass a reader for the string to Jmol.
782 // ((org.jmol.Viewer.Viewer) viewer).loadModelFromFile(fullPathName,
783 // fileName, null, reader, false, null, null, 0);
784 viewer.openStringInline(string);
787 public void mouseOverStructure(int atomIndex, String strInfo)
790 int alocsep = strInfo.indexOf("^");
791 int mdlSep = strInfo.indexOf("/");
792 int chainSeparator = strInfo.indexOf(":"), chainSeparator1 = -1;
794 if (chainSeparator == -1)
796 chainSeparator = strInfo.indexOf(".");
797 if (mdlSep > -1 && mdlSep < chainSeparator)
799 chainSeparator1 = chainSeparator;
800 chainSeparator = mdlSep;
803 // handle insertion codes
806 pdbResNum = Integer.parseInt(strInfo.substring(
807 strInfo.indexOf("]") + 1, alocsep));
812 pdbResNum = Integer.parseInt(strInfo.substring(
813 strInfo.indexOf("]") + 1, chainSeparator));
817 if (strInfo.indexOf(":") > -1)
819 chainId = strInfo.substring(strInfo.indexOf(":") + 1,
820 strInfo.indexOf("."));
827 String pdbfilename = modelFileNames[frameNo]; // default is first or current
831 if (chainSeparator1 == -1)
833 chainSeparator1 = strInfo.indexOf(".", mdlSep);
835 String mdlId = (chainSeparator1 > -1) ? strInfo.substring(mdlSep + 1,
836 chainSeparator1) : strInfo.substring(mdlSep + 1);
839 // recover PDB filename for the model hovered over.
840 int _mp = _modelFileNameMap.length - 1, mnumber = new Integer(mdlId)
842 while (mnumber < _modelFileNameMap[_mp])
846 pdbfilename = modelFileNames[_mp];
847 if (pdbfilename == null)
849 pdbfilename = new File(viewer.ms.getModelFileName(mnumber))
853 } catch (Exception e)
858 if (lastMessage == null || !lastMessage.equals(strInfo))
860 getSsm().mouseOverStructure(pdbResNum, chainId, pdbfilename);
863 lastMessage = strInfo;
866 public void notifyAtomHovered(int atomIndex, String strInfo, String data)
870 System.err.println("Ignoring additional hover info: " + data
871 + " (other info: '" + strInfo + "' pos " + atomIndex + ")");
873 mouseOverStructure(atomIndex, strInfo);
877 * { if (history != null && strStatus != null &&
878 * !strStatus.equals("Script completed")) { history.append("\n" + strStatus);
882 public void notifyAtomPicked(int atomIndex, String strInfo, String strData)
885 * this implements the toggle label behaviour copied from the original
886 * structure viewer, MCView
890 System.err.println("Ignoring additional pick data string " + strData);
892 int chainSeparator = strInfo.indexOf(":");
894 if (chainSeparator == -1)
896 chainSeparator = strInfo.indexOf(".");
899 String picked = strInfo.substring(strInfo.indexOf("]") + 1,
901 String mdlString = "";
902 if ((p = strInfo.indexOf(":")) > -1)
904 picked += strInfo.substring(p, strInfo.indexOf("."));
907 if ((p = strInfo.indexOf("/")) > -1)
909 mdlString += strInfo.substring(p, strInfo.indexOf(" #"));
911 picked = "((" + picked + ".CA" + mdlString + ")|(" + picked + ".P"
915 if (!atomsPicked.contains(picked))
917 viewer.evalStringQuiet("select " + picked + ";label %n %r:%c");
918 atomsPicked.addElement(picked);
922 viewer.evalString("select " + picked + ";label off");
923 atomsPicked.removeElement(picked);
926 // TODO: in application this happens
928 // if (scriptWindow != null)
930 // scriptWindow.sendConsoleMessage(strInfo);
931 // scriptWindow.sendConsoleMessage("\n");
937 public void notifyCallback(CBK type, Object[] data)
944 notifyFileLoaded((String) data[1], (String) data[2],
945 (String) data[3], (String) data[4],
946 ((Integer) data[5]).intValue());
950 notifyAtomPicked(((Integer) data[2]).intValue(), (String) data[1],
952 // also highlight in alignment
954 notifyAtomHovered(((Integer) data[2]).intValue(), (String) data[1],
958 notifyScriptTermination((String) data[2],
959 ((Integer) data[3]).intValue());
962 sendConsoleEcho((String) data[1]);
965 sendConsoleMessage((data == null) ? ((String) null)
969 // System.err.println("Ignoring error callback.");
979 System.err.println("Unhandled callback " + type + " "
980 + data[1].toString());
983 } catch (Exception e)
985 System.err.println("Squashed Jmol callback handler error:");
991 public boolean notifyEnabled(CBK callbackPick)
993 switch (callbackPick)
1009 // incremented every time a load notification is successfully handled -
1010 // lightweight mechanism for other threads to detect when they can start
1011 // referrring to new structures.
1012 private long loadNotifiesHandled = 0;
1014 public long getLoadNotifiesHandled()
1016 return loadNotifiesHandled;
1019 public void notifyFileLoaded(String fullPathName, String fileName2,
1020 String modelName, String errorMsg, int modelParts)
1022 if (errorMsg != null)
1024 fileLoadingError = errorMsg;
1028 // TODO: deal sensibly with models loaded inLine:
1029 // modelName will be null, as will fullPathName.
1031 // the rest of this routine ignores the arguments, and simply interrogates
1032 // the Jmol view to find out what structures it contains, and adds them to
1033 // the structure selection manager.
1034 fileLoadingError = null;
1035 String[] oldmodels = modelFileNames;
1036 modelFileNames = null;
1037 chainNames = new ArrayList<String>();
1038 chainFile = new Hashtable<String, String>();
1039 boolean notifyLoaded = false;
1040 String[] modelfilenames = getPdbFile();
1041 // first check if we've lost any structures
1042 if (oldmodels != null && oldmodels.length > 0)
1045 for (int i = 0; i < oldmodels.length; i++)
1047 for (int n = 0; n < modelfilenames.length; n++)
1049 if (modelfilenames[n] == oldmodels[i])
1051 oldmodels[i] = null;
1055 if (oldmodels[i] != null)
1062 String[] oldmfn = new String[oldm];
1064 for (int i = 0; i < oldmodels.length; i++)
1066 if (oldmodels[i] != null)
1068 oldmfn[oldm++] = oldmodels[i];
1071 // deregister the Jmol instance for these structures - we'll add
1072 // ourselves again at the end for the current structure set.
1073 getSsm().removeStructureViewerListener(this, oldmfn);
1076 refreshPdbEntries();
1077 for (int modelnum = 0; modelnum < modelfilenames.length; modelnum++)
1079 String fileName = modelfilenames[modelnum];
1080 boolean foundEntry = false;
1081 StructureFile pdb = null;
1082 String pdbfile = null;
1083 // model was probably loaded inline - so check the pdb file hashcode
1086 // calculate essential attributes for the pdb data imported inline.
1087 // prolly need to resolve modelnumber properly - for now just use our
1089 pdbfile = viewer.getData("" + (1 + _modelFileNameMap[modelnum])
1092 // search pdbentries and sequences to find correct pdbentry for this
1094 for (int pe = 0; pe < getPdbCount(); pe++)
1096 boolean matches = false;
1097 addSequence(pe, getSequence()[pe]);
1098 if (fileName == null)
1101 // see JAL-623 - need method of matching pasted data up
1103 pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe],
1104 pdbfile, DataSourceType.PASTE);
1105 getPdbEntry(modelnum).setFile("INLINE" + pdb.getId());
1112 File fl = new File(getPdbEntry(pe).getFile());
1113 matches = fl.equals(new File(fileName));
1117 // TODO: Jmol can in principle retrieve from CLASSLOADER but
1120 // to be tested. See mantis bug
1121 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
1122 DataSourceType protocol = DataSourceType.URL;
1127 protocol = DataSourceType.FILE;
1129 } catch (Exception e)
1134 // Explicitly map to the filename used by Jmol ;
1135 pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe],
1136 fileName, protocol);
1137 // pdbentry[pe].getFile(), protocol);
1143 // add an entry for every chain in the model
1144 for (int i = 0; i < pdb.getChains().size(); i++)
1146 String chid = new String(pdb.getId() + ":"
1147 + pdb.getChains().elementAt(i).id);
1148 chainFile.put(chid, fileName);
1149 chainNames.add(chid);
1151 notifyLoaded = true;
1155 if (!foundEntry && associateNewStructs)
1157 // this is a foreign pdb file that jalview doesn't know about - add
1158 // it to the dataset and try to find a home - either on a matching
1159 // sequence or as a new sequence.
1160 String pdbcontent = viewer.getData("/" + (modelnum + 1) + ".1",
1162 // parse pdb file into a chain, etc.
1163 // locate best match for pdb in associated views and add mapping to
1165 // if properly registered then
1166 notifyLoaded = true;
1171 // so finally, update the jmol bits and pieces
1172 // if (jmolpopup != null)
1174 // // potential for deadlock here:
1175 // // jmolpopup.updateComputedMenus();
1177 if (!isLoadingFromArchive())
1179 viewer.evalStringQuiet("model *; select backbone;restrict;cartoon;wireframe off;spacefill off");
1181 // register ourselves as a listener and notify the gui that it needs to
1183 getSsm().addStructureViewerListener(this);
1186 FeatureRenderer fr = getFeatureRenderer(null);
1192 loadNotifiesHandled++;
1194 setLoadingFromArchive(false);
1198 public List<String> getChainNames()
1203 public void notifyNewPickingModeMeasurement(int iatom, String strMeasure)
1205 notifyAtomPicked(iatom, strMeasure, null);
1208 public abstract void notifyScriptTermination(String strStatus,
1212 * display a message echoed from the jmol viewer
1216 public abstract void sendConsoleEcho(String strEcho); /*
1217 * { showConsole(true);
1219 * history.append("\n" +
1223 // /End JmolStatusListener
1224 // /////////////////////////////
1228 * status message - usually the response received after a script
1231 public abstract void sendConsoleMessage(String strStatus);
1234 public void setCallbackFunction(String callbackType,
1235 String callbackFunction)
1237 System.err.println("Ignoring set-callback request to associate "
1238 + callbackType + " with function " + callbackFunction);
1243 public void setJalviewColourScheme(ColourSchemeI cs)
1245 colourBySequence = false;
1253 StringBuilder command = new StringBuilder(128);
1254 command.append("select *;color white;");
1255 List<String> residueSet = ResidueProperties.getResidues(isNucleotide(),
1257 for (String resName : residueSet)
1259 char res = resName.length() == 3 ? ResidueProperties
1260 .getSingleCharacterCode(resName) : resName.charAt(0);
1261 Color col = cs.findColour(res, 0, null, null, 0f);
1262 command.append("select " + resName + ";color[" + col.getRed() + ","
1263 + col.getGreen() + "," + col.getBlue() + "];");
1266 evalStateCommand(command.toString());
1270 public void showHelp()
1272 showUrl("http://jmol.sourceforge.net/docs/JmolUserGuide/", "jmolHelp");
1276 * open the URL somehow
1280 public abstract void showUrl(String url, String target);
1283 * called when the binding thinks the UI needs to be refreshed after a Jmol
1284 * state change. this could be because structures were loaded, or because an
1285 * error has occured.
1287 public abstract void refreshGUI();
1290 * called to show or hide the associated console window container.
1294 public abstract void showConsole(boolean show);
1297 * @param renderPanel
1299 * - when true will initialise jmol's file IO system (should be false
1300 * in applet context)
1302 * @param documentBase
1304 * @param commandOptions
1306 public void allocateViewer(Container renderPanel, boolean jmolfileio,
1307 String htmlName, URL documentBase, URL codeBase,
1308 String commandOptions)
1310 allocateViewer(renderPanel, jmolfileio, htmlName, documentBase,
1311 codeBase, commandOptions, null, null);
1316 * @param renderPanel
1318 * - when true will initialise jmol's file IO system (should be false
1319 * in applet context)
1321 * @param documentBase
1323 * @param commandOptions
1324 * @param consolePanel
1325 * - panel to contain Jmol console
1326 * @param buttonsToShow
1327 * - buttons to show on the console, in ordr
1329 public void allocateViewer(Container renderPanel, boolean jmolfileio,
1330 String htmlName, URL documentBase, URL codeBase,
1331 String commandOptions, final Container consolePanel,
1332 String buttonsToShow)
1334 if (commandOptions == null)
1336 commandOptions = "";
1338 viewer = (Viewer) JmolViewer.allocateViewer(renderPanel,
1339 (jmolfileio ? new SmarterJmolAdapter() : null), htmlName
1340 + ((Object) this).toString(), documentBase, codeBase,
1341 commandOptions, this);
1343 viewer.setJmolStatusListener(this); // extends JmolCallbackListener
1345 console = createJmolConsole(consolePanel, buttonsToShow);
1346 if (consolePanel != null)
1348 consolePanel.addComponentListener(this);
1354 protected abstract JmolAppConsoleInterface createJmolConsole(
1355 Container consolePanel, String buttonsToShow);
1357 protected org.jmol.api.JmolAppConsoleInterface console = null;
1360 public void setBackgroundColour(java.awt.Color col)
1363 viewer.evalStringQuiet("background [" + col.getRed() + ","
1364 + col.getGreen() + "," + col.getBlue() + "];");
1369 public int[] resizeInnerPanel(String data)
1371 // Jalview doesn't honour resize panel requests
1378 protected void closeConsole()
1380 if (console != null)
1384 console.setVisible(false);
1387 } catch (Exception x)
1396 * ComponentListener method
1399 public void componentMoved(ComponentEvent e)
1404 * ComponentListener method
1407 public void componentResized(ComponentEvent e)
1412 * ComponentListener method
1415 public void componentShown(ComponentEvent e)
1421 * ComponentListener method
1424 public void componentHidden(ComponentEvent e)