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.HiddenColumns;
28 import jalview.datamodel.PDBEntry;
29 import jalview.datamodel.SequenceI;
30 import jalview.gui.IProgressIndicator;
31 import jalview.io.DataSourceType;
32 import jalview.io.StructureFile;
33 import jalview.schemes.ColourSchemeI;
34 import jalview.schemes.ResidueProperties;
35 import jalview.structure.AtomSpec;
36 import jalview.structure.StructureMappingcommandSet;
37 import jalview.structure.StructureSelectionManager;
38 import jalview.structures.models.AAStructureBindingModel;
39 import jalview.util.MessageManager;
41 import java.awt.Color;
42 import java.awt.Container;
43 import java.awt.event.ComponentEvent;
44 import java.awt.event.ComponentListener;
47 import java.util.ArrayList;
48 import java.util.BitSet;
49 import java.util.Hashtable;
50 import java.util.List;
52 import java.util.StringTokenizer;
53 import java.util.Vector;
55 import org.jmol.adapter.smarter.SmarterJmolAdapter;
56 import org.jmol.api.JmolAppConsoleInterface;
57 import org.jmol.api.JmolSelectionListener;
58 import org.jmol.api.JmolStatusListener;
59 import org.jmol.api.JmolViewer;
60 import org.jmol.c.CBK;
61 import org.jmol.script.T;
62 import org.jmol.viewer.Viewer;
64 public abstract class JalviewJmolBinding extends AAStructureBindingModel
65 implements JmolStatusListener, JmolSelectionListener,
68 private String lastMessage;
70 boolean allChainsSelected = false;
73 * when true, try to search the associated datamodel for sequences that are
74 * associated with any unknown structures in the Jmol view.
76 private boolean associateNewStructs = false;
78 Vector<String> atomsPicked = new Vector<>();
80 private List<String> chainNames;
82 Hashtable<String, String> chainFile;
85 * the default or current model displayed if the model cannot be identified
86 * from the selection message
90 // protected JmolGenericPopup jmolpopup; // not used - remove?
96 StringBuffer resetLastRes = new StringBuffer();
100 public JalviewJmolBinding(StructureSelectionManager ssm,
101 PDBEntry[] pdbentry, SequenceI[][] sequenceIs,
102 DataSourceType protocol)
104 super(ssm, pdbentry, sequenceIs, protocol);
106 * viewer = JmolViewer.allocateViewer(renderPanel, new SmarterJmolAdapter(),
107 * "jalviewJmol", ap.av.applet .getDocumentBase(),
108 * ap.av.applet.getCodeBase(), "", this);
110 * jmolpopup = JmolPopup.newJmolPopup(viewer, true, "Jmol", true);
114 public JalviewJmolBinding(StructureSelectionManager ssm,
115 SequenceI[][] seqs, Viewer theViewer)
120 viewer.setJmolStatusListener(this);
121 viewer.addSelectionListener(this);
125 * construct a title string for the viewer window based on the data jalview
130 public String getViewerTitle()
132 return getViewerTitle("Jmol", true);
136 * prepare the view for a given set of models/chains. chainList contains
137 * strings of the form 'pdbfilename:Chaincode'
140 * list of chains to make visible
142 public void centerViewer(Vector<String> chainList)
144 StringBuilder cmd = new StringBuilder(128);
146 for (String lbl : chainList)
152 mlength = lbl.indexOf(":", p);
153 } while (p < mlength && mlength < (lbl.length() - 2));
154 // TODO: lookup each pdb id and recover proper model number for it.
155 cmd.append(":" + lbl.substring(mlength + 1) + " /"
156 + (1 + getModelNum(chainFile.get(lbl))) + " or ");
158 if (cmd.length() > 0)
160 cmd.setLength(cmd.length() - 4);
162 evalStateCommand("select *;restrict " + cmd + ";cartoon;center " + cmd);
165 public void closeViewer()
167 // remove listeners for all structures in viewer
168 getSsm().removeStructureViewerListener(this, this.getStructureFiles());
172 releaseUIResources();
176 public void colourByChain()
178 colourBySequence = false;
179 // TODO: colour by chain should colour each chain distinctly across all
181 // TODO: http://issues.jalview.org/browse/JAL-628
182 evalStateCommand("select *;color chain");
186 public void colourByCharge()
188 colourBySequence = false;
189 evalStateCommand("select *;color white;select ASP,GLU;color red;"
190 + "select LYS,ARG;color blue;select CYS;color yellow");
194 * superpose the structures associated with sequences in the alignment
195 * according to their corresponding positions.
197 public void superposeStructures(AlignmentI alignment)
199 superposeStructures(alignment, -1, null);
203 * superpose the structures associated with sequences in the alignment
204 * according to their corresponding positions. ded)
206 * @param refStructure
207 * - select which pdb file to use as reference (default is -1 - the
208 * first structure in the alignment)
210 public void superposeStructures(AlignmentI alignment, int refStructure)
212 superposeStructures(alignment, refStructure, null);
216 * superpose the structures associated with sequences in the alignment
217 * according to their corresponding positions. ded)
219 * @param refStructure
220 * - select which pdb file to use as reference (default is -1 - the
221 * first structure in the alignment)
225 public void superposeStructures(AlignmentI alignment, int refStructure,
226 HiddenColumns hiddenCols)
228 superposeStructures(new AlignmentI[] { alignment },
230 { refStructure }, new HiddenColumns[] { hiddenCols });
237 public String superposeStructures(AlignmentI[] _alignment,
238 int[] _refStructure, HiddenColumns[] _hiddenCols)
240 while (viewer.isScriptExecuting())
245 } catch (InterruptedException i)
251 * get the distinct structure files modelled
252 * (a file with multiple chains may map to multiple sequences)
254 String[] files = getStructureFiles();
255 if (!waitForFileLoad(files))
260 StringBuilder selectioncom = new StringBuilder(256);
261 // In principle - nSeconds specifies the speed of animation for each
262 // superposition - but is seems to behave weirdly, so we don't specify it.
263 String nSeconds = " ";
264 if (files.length > 10)
266 nSeconds = " 0.005 ";
270 nSeconds = " " + (2.0 / files.length) + " ";
271 // if (nSeconds).substring(0,5)+" ";
274 // see JAL-1345 - should really automatically turn off the animation for
275 // large numbers of structures, but Jmol doesn't seem to allow that.
277 // union of all aligned positions are collected together.
278 for (int a = 0; a < _alignment.length; a++)
280 int refStructure = _refStructure[a];
281 AlignmentI alignment = _alignment[a];
282 HiddenColumns hiddenCols = _hiddenCols[a];
283 if (a > 0 && selectioncom.length() > 0 && !selectioncom
284 .substring(selectioncom.length() - 1).equals("|"))
286 selectioncom.append("|");
288 // process this alignment
289 if (refStructure >= files.length)
292 "Invalid reference structure value " + refStructure);
297 * 'matched' bit j will be set for visible alignment columns j where
298 * all sequences have a residue with a mapping to the PDB structure
300 BitSet matched = new BitSet();
301 for (int m = 0; m < alignment.getWidth(); m++)
303 if (hiddenCols == null || hiddenCols.isVisible(m))
309 SuperposeData[] structures = new SuperposeData[files.length];
310 for (int f = 0; f < files.length; f++)
312 structures[f] = new SuperposeData(alignment.getWidth());
316 * Calculate the superposable alignment columns ('matched'), and the
317 * corresponding structure residue positions (structures.pdbResNo)
319 int candidateRefStructure = findSuperposableResidues(alignment,
320 matched, structures);
321 if (refStructure < 0)
324 * If no reference structure was specified, pick the first one that has
325 * a mapping in the alignment
327 refStructure = candidateRefStructure;
330 String[] selcom = new String[files.length];
331 int nmatched = matched.cardinality();
334 return (MessageManager.formatMessage("label.insufficient_residues",
339 * generate select statements to select regions to superimpose structures
342 // TODO extract method to construct selection statements
343 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
345 String chainCd = ":" + structures[pdbfnum].chain;
348 StringBuilder molsel = new StringBuilder();
351 int nextColumnMatch = matched.nextSetBit(0);
352 while (nextColumnMatch != -1)
354 int pdbResNo = structures[pdbfnum].pdbResNo[nextColumnMatch];
355 if (lpos != pdbResNo - 1)
361 molsel.append(chainCd);
368 // continuous run - and lpos >-1
371 // at the beginning, so add dash
378 nextColumnMatch = matched.nextSetBit(nextColumnMatch + 1);
381 * add final selection phrase
386 molsel.append(chainCd);
389 if (molsel.length() > 1)
391 selcom[pdbfnum] = molsel.toString();
392 selectioncom.append("((");
393 selectioncom.append(selcom[pdbfnum].substring(1,
394 selcom[pdbfnum].length() - 1));
395 selectioncom.append(" )& ");
396 selectioncom.append(pdbfnum + 1);
397 selectioncom.append(".1)");
398 if (pdbfnum < files.length - 1)
400 selectioncom.append("|");
405 selcom[pdbfnum] = null;
409 StringBuilder command = new StringBuilder(256);
410 // command.append("set spinFps 10;\n");
412 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
414 if (pdbfnum == refStructure || selcom[pdbfnum] == null
415 || selcom[refStructure] == null)
419 command.append("echo ");
420 command.append("\"Superposing (");
421 command.append(structures[pdbfnum].pdbId);
422 command.append(") against reference (");
423 command.append(structures[refStructure].pdbId);
424 command.append(")\";\ncompare " + nSeconds);
426 command.append(Integer.toString(1 + pdbfnum));
427 command.append(".1} {");
428 command.append(Integer.toString(1 + refStructure));
429 // conformation=1 excludes alternate locations for CA (JAL-1757)
431 ".1} SUBSET {(*.CA | *.P) and conformation=1} ATOMS ");
433 // for (int s = 0; s < 2; s++)
435 // command.append(selcom[(s == 0 ? pdbfnum : refStructure)]);
437 command.append(selcom[pdbfnum]);
438 command.append(selcom[refStructure]);
439 command.append(" ROTATE TRANSLATE;\n");
441 if (selectioncom.length() > 0)
443 // TODO is performing selectioncom redundant here? is done later on
444 // System.out.println("Select regions:\n" + selectioncom.toString());
445 evalStateCommand("select *; cartoons off; backbone; select ("
446 + selectioncom.toString() + "); cartoons; ");
447 // selcom.append("; ribbons; ");
448 String cmdString = command.toString();
449 // System.out.println("Superimpose command(s):\n" + cmdString);
451 evalStateCommand(cmdString);
454 if (selectioncom.length() > 0)
455 {// finally, mark all regions that were superposed.
456 if (selectioncom.substring(selectioncom.length() - 1).equals("|"))
458 selectioncom.setLength(selectioncom.length() - 1);
460 // System.out.println("Select regions:\n" + selectioncom.toString());
461 evalStateCommand("select *; cartoons off; backbone; select ("
462 + selectioncom.toString() + "); cartoons; ");
463 // evalStateCommand("select *; backbone; select "+selcom.toString()+";
464 // 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;
481 Thread colourby = null;
483 * Sends a set of colour commands to the structure viewer
485 * @param colourBySequenceCommands
488 protected void colourBySequence(
489 final StructureMappingcommandSet[] colourBySequenceCommands)
491 if (colourby != null)
493 colourby.interrupt();
496 colourby = new Thread(new Runnable()
501 for (StructureMappingcommandSet cpdbbyseq : colourBySequenceCommands)
503 for (String cbyseq : cpdbbyseq.commands)
505 executeWhenReady(cbyseq);
520 protected StructureMappingcommandSet[] getColourBySequenceCommands(
521 String[] files, SequenceRenderer sr, AlignmentViewPanel viewPanel)
523 return JmolCommands.getColourBySequenceCommand(getSsm(), files,
524 getSequence(), sr, viewPanel);
530 protected void executeWhenReady(String command)
532 evalStateCommand(command);
535 public void createImage(String file, String type, int quality)
537 System.out.println("JMOL CREATE IMAGE");
541 public String createImage(String fileName, String type,
542 Object textOrBytes, int quality)
544 System.out.println("JMOL CREATE IMAGE");
549 public String eval(String strEval)
551 // System.out.println(strEval);
552 // "# 'eval' is implemented only for the applet.";
556 // End StructureListener
557 // //////////////////////////
560 public float[][] functionXY(String functionName, int x, int y)
566 public float[][][] functionXYZ(String functionName, int nx, int ny,
569 // TODO Auto-generated method stub
573 public Color getColour(int atomIndex, int pdbResNum, String chain,
576 if (getModelNum(pdbfile) < 0)
580 // TODO: verify atomIndex is selecting correct model.
581 // return new Color(viewer.getAtomArgb(atomIndex)); Jmol 12.2.4
582 int colour = viewer.ms.at[atomIndex].atomPropertyInt(T.color);
583 return new Color(colour);
587 * instruct the Jalview binding to update the pdbentries vector if necessary
588 * prior to matching the jmol view's contents to the list of structure files
589 * Jalview knows about.
591 public abstract void refreshPdbEntries();
593 private int getModelNum(String modelFileName)
595 String[] mfn = getStructureFiles();
600 for (int i = 0; i < mfn.length; i++)
602 if (mfn[i].equalsIgnoreCase(modelFileName))
611 * map between index of model filename returned from getPdbFile and the first
612 * index of models from this file in the viewer. Note - this is not trimmed -
613 * use getPdbFile to get number of unique models.
615 private int _modelFileNameMap[];
618 public synchronized String[] getStructureFiles()
620 List<String> mset = new ArrayList<>();
623 return new String[0];
626 if (modelFileNames == null)
628 int modelCount = viewer.ms.mc;
629 String filePath = null;
630 for (int i = 0; i < modelCount; ++i)
632 filePath = viewer.ms.getModelFileName(i);
633 if (!mset.contains(filePath))
638 modelFileNames = mset.toArray(new String[mset.size()]);
641 return modelFileNames;
645 * map from string to applet
648 public Map<String, Object> getRegistryInfo()
650 // TODO Auto-generated method stub
654 // ///////////////////////////////
655 // JmolStatusListener
657 public void handlePopupMenu(int x, int y)
659 // jmolpopup.show(x, y);
660 // jmolpopup.jpiShow(x, y);
664 * Highlight zero, one or more atoms on the structure
667 public void highlightAtoms(List<AtomSpec> atoms)
671 if (resetLastRes.length() > 0)
673 viewer.evalStringQuiet(resetLastRes.toString());
674 resetLastRes.setLength(0);
676 for (AtomSpec atom : atoms)
678 highlightAtom(atom.getAtomIndex(), atom.getPdbResNum(),
679 atom.getChain(), atom.getPdbFile());
685 public void highlightAtom(int atomIndex, int pdbResNum, String chain,
688 if (modelFileNames == null)
693 // look up file model number for this pdbfile
695 // may need to adjust for URLencoding here - we don't worry about that yet.
696 while (mdlNum < modelFileNames.length
697 && !pdbfile.equals(modelFileNames[mdlNum]))
701 if (mdlNum == modelFileNames.length)
708 StringBuilder cmd = new StringBuilder(64);
709 cmd.append("select " + pdbResNum); // +modelNum
711 resetLastRes.append("select " + pdbResNum); // +modelNum
714 resetLastRes.append(":");
715 if (!chain.equals(" "))
718 resetLastRes.append(chain);
721 cmd.append(" /" + (mdlNum + 1));
722 resetLastRes.append("/" + (mdlNum + 1));
724 cmd.append(";wireframe 100;" + cmd.toString() + " and not hetero;");
726 resetLastRes.append(";wireframe 0;" + resetLastRes.toString()
727 + " and not hetero; spacefill 0;");
729 cmd.append("spacefill 200;select none");
731 viewer.evalStringQuiet(cmd.toString());
736 boolean debug = true;
738 private void jmolHistory(boolean enable)
740 viewer.evalStringQuiet("History " + ((debug || enable) ? "on" : "off"));
743 public void loadInline(String string)
747 // viewer.loadInline(strModel, isAppend);
749 // construct fake fullPathName and fileName so we can identify the file
751 // Then, construct pass a reader for the string to Jmol.
752 // ((org.jmol.Viewer.Viewer) viewer).loadModelFromFile(fullPathName,
753 // fileName, null, reader, false, null, null, 0);
754 viewer.openStringInline(string);
757 protected void mouseOverStructure(int atomIndex, final String strInfo)
760 int alocsep = strInfo.indexOf("^");
761 int mdlSep = strInfo.indexOf("/");
762 int chainSeparator = strInfo.indexOf(":"), chainSeparator1 = -1;
764 if (chainSeparator == -1)
766 chainSeparator = strInfo.indexOf(".");
767 if (mdlSep > -1 && mdlSep < chainSeparator)
769 chainSeparator1 = chainSeparator;
770 chainSeparator = mdlSep;
773 // handle insertion codes
776 pdbResNum = Integer.parseInt(
777 strInfo.substring(strInfo.indexOf("]") + 1, alocsep));
782 pdbResNum = Integer.parseInt(
783 strInfo.substring(strInfo.indexOf("]") + 1, chainSeparator));
787 if (strInfo.indexOf(":") > -1)
789 chainId = strInfo.substring(strInfo.indexOf(":") + 1,
790 strInfo.indexOf("."));
797 String pdbfilename = modelFileNames[frameNo]; // default is first or current
801 if (chainSeparator1 == -1)
803 chainSeparator1 = strInfo.indexOf(".", mdlSep);
805 String mdlId = (chainSeparator1 > -1)
806 ? strInfo.substring(mdlSep + 1, chainSeparator1)
807 : strInfo.substring(mdlSep + 1);
810 // recover PDB filename for the model hovered over.
811 int mnumber = Integer.valueOf(mdlId).intValue() - 1;
812 if (_modelFileNameMap != null)
814 int _mp = _modelFileNameMap.length - 1;
816 while (mnumber < _modelFileNameMap[_mp])
820 pdbfilename = modelFileNames[_mp];
824 if (mnumber >= 0 && mnumber < modelFileNames.length)
826 pdbfilename = modelFileNames[mnumber];
829 if (pdbfilename == null)
831 pdbfilename = new File(viewer.ms.getModelFileName(mnumber))
835 } catch (Exception e)
841 * highlight position on alignment(s); if some text is returned,
842 * show this as a second line on the structure hover tooltip
844 String label = getSsm().mouseOverStructure(pdbResNum, chainId,
848 // change comma to pipe separator (newline token for Jmol)
849 label = label.replace(',', '|');
850 StringTokenizer toks = new StringTokenizer(strInfo, " ");
851 StringBuilder sb = new StringBuilder();
852 sb.append("select ").append(String.valueOf(pdbResNum)).append(":")
853 .append(chainId).append("/1");
854 sb.append(";set hoverLabel \"").append(toks.nextToken()).append(" ")
855 .append(toks.nextToken());
856 sb.append("|").append(label).append("\"");
857 evalStateCommand(sb.toString());
861 public void notifyAtomHovered(int atomIndex, String strInfo, String data)
863 if (strInfo.equals(lastMessage))
867 lastMessage = strInfo;
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,
886 * this implements the toggle label behaviour copied from the original
887 * structure viewer, MCView
891 System.err.println("Ignoring additional pick data string " + strData);
893 int chainSeparator = strInfo.indexOf(":");
895 if (chainSeparator == -1)
897 chainSeparator = strInfo.indexOf(".");
900 String picked = strInfo.substring(strInfo.indexOf("]") + 1,
902 String mdlString = "";
903 if ((p = strInfo.indexOf(":")) > -1)
905 picked += strInfo.substring(p, strInfo.indexOf("."));
908 if ((p = strInfo.indexOf("/")) > -1)
910 mdlString += strInfo.substring(p, strInfo.indexOf(" #"));
912 picked = "((" + picked + ".CA" + mdlString + ")|(" + picked + ".P"
916 if (!atomsPicked.contains(picked))
918 viewer.evalStringQuiet("select " + picked + ";label %n %r:%c");
919 atomsPicked.addElement(picked);
923 viewer.evalString("select " + picked + ";label off");
924 atomsPicked.removeElement(picked);
927 // TODO: in application this happens
929 // if (scriptWindow != null)
931 // scriptWindow.sendConsoleMessage(strInfo);
932 // scriptWindow.sendConsoleMessage("\n");
938 public void notifyCallback(CBK type, Object[] data)
945 notifyFileLoaded((String) data[1], (String) data[2],
946 (String) data[3], (String) data[4],
947 ((Integer) data[5]).intValue());
951 notifyAtomPicked(((Integer) data[2]).intValue(), (String) data[1],
953 // also highlight in alignment
954 // deliberate fall through
956 notifyAtomHovered(((Integer) data[2]).intValue(), (String) data[1],
960 notifyScriptTermination((String) data[2],
961 ((Integer) data[3]).intValue());
964 sendConsoleEcho((String) data[1]);
968 (data == null) ? ((String) null) : (String) data[1]);
971 // System.err.println("Ignoring error callback.");
982 "Unhandled callback " + type + " " + data[1].toString());
985 } catch (Exception e)
987 System.err.println("Squashed Jmol callback handler error:");
993 public boolean notifyEnabled(CBK callbackPick)
995 switch (callbackPick)
1011 // incremented every time a load notification is successfully handled -
1012 // lightweight mechanism for other threads to detect when they can start
1013 // referrring to new structures.
1014 private long loadNotifiesHandled = 0;
1016 public long getLoadNotifiesHandled()
1018 return loadNotifiesHandled;
1021 public void notifyFileLoaded(String fullPathName, String fileName2,
1022 String modelName, String errorMsg, int modelParts)
1024 if (errorMsg != null)
1026 fileLoadingError = errorMsg;
1030 // TODO: deal sensibly with models loaded inLine:
1031 // modelName will be null, as will fullPathName.
1033 // the rest of this routine ignores the arguments, and simply interrogates
1034 // the Jmol view to find out what structures it contains, and adds them to
1035 // the structure selection manager.
1036 fileLoadingError = null;
1037 String[] oldmodels = modelFileNames;
1038 modelFileNames = null;
1039 chainNames = new ArrayList<>();
1040 chainFile = new Hashtable<>();
1041 boolean notifyLoaded = false;
1042 String[] modelfilenames = getStructureFiles();
1043 // first check if we've lost any structures
1044 if (oldmodels != null && oldmodels.length > 0)
1047 for (int i = 0; i < oldmodels.length; i++)
1049 for (int n = 0; n < modelfilenames.length; n++)
1051 if (modelfilenames[n] == oldmodels[i])
1053 oldmodels[i] = null;
1057 if (oldmodels[i] != null)
1064 String[] oldmfn = new String[oldm];
1066 for (int i = 0; i < oldmodels.length; i++)
1068 if (oldmodels[i] != null)
1070 oldmfn[oldm++] = oldmodels[i];
1073 // deregister the Jmol instance for these structures - we'll add
1074 // ourselves again at the end for the current structure set.
1075 getSsm().removeStructureViewerListener(this, oldmfn);
1078 refreshPdbEntries();
1079 for (int modelnum = 0; modelnum < modelfilenames.length; modelnum++)
1081 String fileName = modelfilenames[modelnum];
1082 boolean foundEntry = false;
1083 StructureFile pdb = null;
1084 String pdbfile = null;
1085 // model was probably loaded inline - so check the pdb file hashcode
1088 // calculate essential attributes for the pdb data imported inline.
1089 // prolly need to resolve modelnumber properly - for now just use our
1091 pdbfile = viewer.getData(
1092 "" + (1 + _modelFileNameMap[modelnum]) + ".0", "PDB");
1094 // search pdbentries and sequences to find correct pdbentry for this
1096 for (int pe = 0; pe < getPdbCount(); pe++)
1098 boolean matches = false;
1099 addSequence(pe, getSequence()[pe]);
1100 if (fileName == null)
1103 // see JAL-623 - need method of matching pasted data up
1105 pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe],
1106 pdbfile, DataSourceType.PASTE,
1107 getIProgressIndicator());
1108 getPdbEntry(modelnum).setFile("INLINE" + pdb.getId());
1115 File fl = new File(getPdbEntry(pe).getFile());
1116 matches = fl.equals(new File(fileName));
1120 // TODO: Jmol can in principle retrieve from CLASSLOADER but
1123 // to be tested. See mantis bug
1124 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
1125 DataSourceType protocol = DataSourceType.URL;
1130 protocol = DataSourceType.FILE;
1132 } catch (Exception e)
1137 // Explicitly map to the filename used by Jmol ;
1138 pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe],
1139 fileName, protocol, getIProgressIndicator());
1140 // pdbentry[pe].getFile(), protocol);
1146 // add an entry for every chain in the model
1147 for (int i = 0; i < pdb.getChains().size(); i++)
1149 String chid = new String(
1150 pdb.getId() + ":" + pdb.getChains().elementAt(i).id);
1151 chainFile.put(chid, fileName);
1152 chainNames.add(chid);
1154 notifyLoaded = true;
1158 if (!foundEntry && associateNewStructs)
1160 // this is a foreign pdb file that jalview doesn't know about - add
1161 // it to the dataset and try to find a home - either on a matching
1162 // sequence or as a new sequence.
1163 String pdbcontent = viewer.getData("/" + (modelnum + 1) + ".1",
1165 // parse pdb file into a chain, etc.
1166 // locate best match for pdb in associated views and add mapping to
1168 // if properly registered then
1169 notifyLoaded = true;
1174 // so finally, update the jmol bits and pieces
1175 // if (jmolpopup != null)
1177 // // potential for deadlock here:
1178 // // jmolpopup.updateComputedMenus();
1180 if (!isLoadingFromArchive())
1182 viewer.evalStringQuiet(
1183 "model *; select backbone;restrict;cartoon;wireframe off;spacefill off");
1185 // register ourselves as a listener and notify the gui that it needs to
1187 getSsm().addStructureViewerListener(this);
1190 FeatureRenderer fr = getFeatureRenderer(null);
1196 loadNotifiesHandled++;
1198 setLoadingFromArchive(false);
1202 public List<String> getChainNames()
1207 protected IProgressIndicator getIProgressIndicator()
1212 public void notifyNewPickingModeMeasurement(int iatom, String strMeasure)
1214 notifyAtomPicked(iatom, strMeasure, null);
1217 public abstract void notifyScriptTermination(String strStatus,
1221 * display a message echoed from the jmol viewer
1225 public abstract void sendConsoleEcho(String strEcho); /*
1226 * { showConsole(true);
1228 * history.append("\n" +
1232 // /End JmolStatusListener
1233 // /////////////////////////////
1237 * status message - usually the response received after a script
1240 public abstract void sendConsoleMessage(String strStatus);
1243 public void setCallbackFunction(String callbackType,
1244 String callbackFunction)
1246 System.err.println("Ignoring set-callback request to associate "
1247 + callbackType + " with function " + callbackFunction);
1252 public void setJalviewColourScheme(ColourSchemeI cs)
1254 colourBySequence = false;
1262 StringBuilder command = new StringBuilder(128);
1263 command.append("select *;color white;");
1264 List<String> residueSet = ResidueProperties.getResidues(isNucleotide(),
1266 for (String resName : residueSet)
1268 char res = resName.length() == 3
1269 ? ResidueProperties.getSingleCharacterCode(resName)
1270 : resName.charAt(0);
1271 Color col = cs.findColour(res, 0, null, null, 0f);
1272 command.append("select " + resName + ";color[" + col.getRed() + ","
1273 + col.getGreen() + "," + col.getBlue() + "];");
1276 evalStateCommand(command.toString());
1280 public void showHelp()
1282 showUrl("http://jmol.sourceforge.net/docs/JmolUserGuide/", "jmolHelp");
1286 * open the URL somehow
1290 public abstract void showUrl(String url, String target);
1293 * called when the binding thinks the UI needs to be refreshed after a Jmol
1294 * state change. this could be because structures were loaded, or because an
1295 * error has occured.
1297 public abstract void refreshGUI();
1300 * called to show or hide the associated console window container.
1304 public abstract void showConsole(boolean show);
1307 * @param renderPanel
1309 * - when true will initialise jmol's file IO system (should be false
1310 * in applet context)
1312 * @param documentBase
1314 * @param commandOptions
1316 public void allocateViewer(Container renderPanel, boolean jmolfileio,
1317 String htmlName, URL documentBase, URL codeBase,
1318 String commandOptions)
1320 allocateViewer(renderPanel, jmolfileio, htmlName, documentBase,
1321 codeBase, commandOptions, null, null);
1326 * @param renderPanel
1328 * - when true will initialise jmol's file IO system (should be false
1329 * in applet context)
1331 * @param documentBase
1333 * @param commandOptions
1334 * @param consolePanel
1335 * - panel to contain Jmol console
1336 * @param buttonsToShow
1337 * - buttons to show on the console, in ordr
1339 public void allocateViewer(Container renderPanel, boolean jmolfileio,
1340 String htmlName, URL documentBase, URL codeBase,
1341 String commandOptions, final Container consolePanel,
1342 String buttonsToShow)
1344 if (commandOptions == null)
1346 commandOptions = "";
1348 viewer = (Viewer) JmolViewer.allocateViewer(renderPanel,
1349 (jmolfileio ? new SmarterJmolAdapter() : null),
1350 htmlName + ((Object) this).toString(), documentBase, codeBase,
1351 commandOptions, this);
1353 viewer.setJmolStatusListener(this); // extends JmolCallbackListener
1355 console = createJmolConsole(consolePanel, buttonsToShow);
1356 if (consolePanel != null)
1358 consolePanel.addComponentListener(this);
1364 protected abstract JmolAppConsoleInterface createJmolConsole(
1365 Container consolePanel, String buttonsToShow);
1367 protected org.jmol.api.JmolAppConsoleInterface console = null;
1370 public void setBackgroundColour(java.awt.Color col)
1373 viewer.evalStringQuiet("background [" + col.getRed() + ","
1374 + col.getGreen() + "," + col.getBlue() + "];");
1379 public int[] resizeInnerPanel(String data)
1381 // Jalview doesn't honour resize panel requests
1388 protected void closeConsole()
1390 if (console != null)
1394 console.setVisible(false);
1397 } catch (Exception x)
1406 * ComponentListener method
1409 public void componentMoved(ComponentEvent e)
1414 * ComponentListener method
1417 public void componentResized(ComponentEvent e)
1422 * ComponentListener method
1425 public void componentShown(ComponentEvent e)
1431 * ComponentListener method
1434 public void componentHidden(ComponentEvent e)