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.security.AccessControlException;
48 import java.util.ArrayList;
49 import java.util.BitSet;
50 import java.util.Hashtable;
51 import java.util.List;
53 import java.util.Vector;
55 import javax.swing.SwingUtilities;
57 import org.jmol.adapter.smarter.SmarterJmolAdapter;
58 import org.jmol.api.JmolAppConsoleInterface;
59 import org.jmol.api.JmolSelectionListener;
60 import org.jmol.api.JmolStatusListener;
61 import org.jmol.api.JmolViewer;
62 import org.jmol.c.CBK;
63 import org.jmol.script.T;
64 import org.jmol.viewer.Viewer;
66 public abstract class JalviewJmolBinding extends AAStructureBindingModel
67 implements JmolStatusListener, JmolSelectionListener,
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?
98 StringBuffer resetLastRes = new StringBuffer();
100 public Viewer viewer;
102 public JalviewJmolBinding(StructureSelectionManager ssm,
103 PDBEntry[] pdbentry, SequenceI[][] sequenceIs,
104 DataSourceType protocol)
106 super(ssm, pdbentry, sequenceIs, protocol);
108 * viewer = JmolViewer.allocateViewer(renderPanel, new SmarterJmolAdapter(),
109 * "jalviewJmol", ap.av.applet .getDocumentBase(),
110 * ap.av.applet.getCodeBase(), "", this);
112 * jmolpopup = JmolPopup.newJmolPopup(viewer, true, "Jmol", true);
116 public JalviewJmolBinding(StructureSelectionManager ssm,
117 SequenceI[][] seqs, Viewer theViewer)
122 viewer.setJmolStatusListener(this);
123 viewer.addSelectionListener(this);
127 * construct a title string for the viewer window based on the data jalview
132 public String getViewerTitle()
134 return getViewerTitle("Jmol", true);
138 * prepare the view for a given set of models/chains. chainList contains
139 * strings of the form 'pdbfilename:Chaincode'
142 * list of chains to make visible
144 public void centerViewer(Vector<String> chainList)
146 StringBuilder cmd = new StringBuilder(128);
148 for (String lbl : chainList)
154 mlength = lbl.indexOf(":", p);
155 } while (p < mlength && mlength < (lbl.length() - 2));
156 // TODO: lookup each pdb id and recover proper model number for it.
157 cmd.append(":" + lbl.substring(mlength + 1) + " /"
158 + (1 + getModelNum(chainFile.get(lbl))) + " or ");
160 if (cmd.length() > 0)
162 cmd.setLength(cmd.length() - 4);
164 evalStateCommand("select *;restrict " + cmd + ";cartoon;center " + cmd);
167 public void closeViewer()
169 // remove listeners for all structures in viewer
170 getSsm().removeStructureViewerListener(this, this.getStructureFiles());
174 releaseUIResources();
178 public void colourByChain()
180 colourBySequence = false;
181 // TODO: colour by chain should colour each chain distinctly across all
183 // TODO: http://issues.jalview.org/browse/JAL-628
184 evalStateCommand("select *;color chain");
188 public void colourByCharge()
190 colourBySequence = false;
191 evalStateCommand("select *;color white;select ASP,GLU;color red;"
192 + "select LYS,ARG;color blue;select CYS;color yellow");
196 * superpose the structures associated with sequences in the alignment
197 * according to their corresponding positions.
199 public void superposeStructures(AlignmentI alignment)
201 superposeStructures(alignment, -1, null);
205 * superpose the structures associated with sequences in the alignment
206 * according to their corresponding positions. ded)
208 * @param refStructure
209 * - select which pdb file to use as reference (default is -1 - the
210 * first structure in the alignment)
212 public void superposeStructures(AlignmentI alignment, int refStructure)
214 superposeStructures(alignment, refStructure, null);
218 * superpose the structures associated with sequences in the alignment
219 * according to their corresponding positions. ded)
221 * @param refStructure
222 * - select which pdb file to use as reference (default is -1 - the
223 * first structure in the alignment)
227 public void superposeStructures(AlignmentI alignment, int refStructure,
228 HiddenColumns hiddenCols)
230 superposeStructures(new AlignmentI[] { alignment },
232 { refStructure }, new HiddenColumns[] { hiddenCols });
239 public String superposeStructures(AlignmentI[] _alignment,
240 int[] _refStructure, HiddenColumns[] _hiddenCols)
242 while (viewer.isScriptExecuting())
247 } catch (InterruptedException i)
253 * get the distinct structure files modelled
254 * (a file with multiple chains may map to multiple sequences)
256 String[] files = getStructureFiles();
257 if (!waitForFileLoad(files))
262 StringBuilder selectioncom = new StringBuilder(256);
263 // In principle - nSeconds specifies the speed of animation for each
264 // superposition - but is seems to behave weirdly, so we don't specify it.
265 String nSeconds = " ";
266 if (files.length > 10)
268 nSeconds = " 0.005 ";
272 nSeconds = " " + (2.0 / files.length) + " ";
273 // if (nSeconds).substring(0,5)+" ";
276 // see JAL-1345 - should really automatically turn off the animation for
277 // large numbers of structures, but Jmol doesn't seem to allow that.
279 // union of all aligned positions are collected together.
280 for (int a = 0; a < _alignment.length; a++)
282 int refStructure = _refStructure[a];
283 AlignmentI alignment = _alignment[a];
284 HiddenColumns hiddenCols = _hiddenCols[a];
285 if (a > 0 && selectioncom.length() > 0 && !selectioncom
286 .substring(selectioncom.length() - 1).equals("|"))
288 selectioncom.append("|");
290 // process this alignment
291 if (refStructure >= files.length)
294 "Invalid reference structure value " + refStructure);
299 * 'matched' bit j will be set for visible alignment columns j where
300 * all sequences have a residue with a mapping to the PDB structure
302 BitSet matched = new BitSet();
303 for (int m = 0; m < alignment.getWidth(); m++)
305 if (hiddenCols == null || hiddenCols.isVisible(m))
311 SuperposeData[] structures = new SuperposeData[files.length];
312 for (int f = 0; f < files.length; f++)
314 structures[f] = new SuperposeData(alignment.getWidth());
318 * Calculate the superposable alignment columns ('matched'), and the
319 * corresponding structure residue positions (structures.pdbResNo)
321 int candidateRefStructure = findSuperposableResidues(alignment,
322 matched, structures);
323 if (refStructure < 0)
326 * If no reference structure was specified, pick the first one that has
327 * a mapping in the alignment
329 refStructure = candidateRefStructure;
332 String[] selcom = new String[files.length];
333 int nmatched = matched.cardinality();
336 return (MessageManager.formatMessage("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)
433 ".1} SUBSET {(*.CA | *.P) and conformation=1} ATOMS ");
435 // for (int s = 0; s < 2; s++)
437 // command.append(selcom[(s == 0 ? pdbfnum : refStructure)]);
439 command.append(selcom[pdbfnum]);
440 command.append(selcom[refStructure]);
441 command.append(" ROTATE TRANSLATE;\n");
443 if (selectioncom.length() > 0)
445 // TODO is performing selectioncom redundant here? is done later on
446 // System.out.println("Select regions:\n" + selectioncom.toString());
447 evalStateCommand("select *; cartoons off; backbone; select ("
448 + selectioncom.toString() + "); cartoons; ");
449 // selcom.append("; ribbons; ");
450 String cmdString = command.toString();
451 // System.out.println("Superimpose command(s):\n" + cmdString);
453 evalStateCommand(cmdString);
456 if (selectioncom.length() > 0)
457 {// finally, mark all regions that were superposed.
458 if (selectioncom.substring(selectioncom.length() - 1).equals("|"))
460 selectioncom.setLength(selectioncom.length() - 1);
462 // System.out.println("Select regions:\n" + selectioncom.toString());
463 evalStateCommand("select *; cartoons off; backbone; select ("
464 + selectioncom.toString() + "); cartoons; ");
465 // evalStateCommand("select *; backbone; select "+selcom.toString()+";
466 // cartoons; center "+selcom.toString());
472 public void evalStateCommand(String command)
475 if (lastCommand == null || !lastCommand.equals(command))
477 viewer.evalStringQuiet(command + "\n");
480 lastCommand = command;
484 * Sends a set of colour commands to the structure viewer
486 * @param colourBySequenceCommands
489 protected void colourBySequence(
490 final StructureMappingcommandSet[] colourBySequenceCommands)
492 SwingUtilities.invokeLater(new Runnable()
497 for (StructureMappingcommandSet cpdbbyseq : colourBySequenceCommands)
499 for (String cbyseq : cpdbbyseq.commands)
501 executeWhenReady(cbyseq);
515 protected StructureMappingcommandSet[] getColourBySequenceCommands(
516 String[] files, SequenceRenderer sr, AlignmentViewPanel viewPanel)
518 return JmolCommands.getColourBySequenceCommand(getSsm(), files,
519 getSequence(), sr, viewPanel);
525 protected void executeWhenReady(String command)
527 evalStateCommand(command);
530 public void createImage(String file, String type, int quality)
532 System.out.println("JMOL CREATE IMAGE");
536 public String createImage(String fileName, String type,
537 Object textOrBytes, int quality)
539 System.out.println("JMOL CREATE IMAGE");
544 public String eval(String strEval)
546 // System.out.println(strEval);
547 // "# 'eval' is implemented only for the applet.";
551 // End StructureListener
552 // //////////////////////////
555 public float[][] functionXY(String functionName, int x, int y)
561 public float[][][] functionXYZ(String functionName, int nx, int ny,
564 // TODO Auto-generated method stub
568 public Color getColour(int atomIndex, int pdbResNum, String chain,
571 if (getModelNum(pdbfile) < 0)
575 // TODO: verify atomIndex is selecting correct model.
576 // return new Color(viewer.getAtomArgb(atomIndex)); Jmol 12.2.4
577 int colour = viewer.ms.at[atomIndex].atomPropertyInt(T.color);
578 return new Color(colour);
582 * instruct the Jalview binding to update the pdbentries vector if necessary
583 * prior to matching the jmol view's contents to the list of structure files
584 * Jalview knows about.
586 public abstract void refreshPdbEntries();
588 private int getModelNum(String modelFileName)
590 String[] mfn = getStructureFiles();
595 for (int i = 0; i < mfn.length; i++)
597 if (mfn[i].equalsIgnoreCase(modelFileName))
606 * map between index of model filename returned from getPdbFile and the first
607 * index of models from this file in the viewer. Note - this is not trimmed -
608 * use getPdbFile to get number of unique models.
610 private int _modelFileNameMap[];
612 // ////////////////////////////////
613 // /StructureListener
615 public synchronized String[] getPdbFilex()
619 return new String[0];
621 if (modelFileNames == null)
623 List<String> mset = new ArrayList<>();
624 _modelFileNameMap = new int[viewer.ms.mc];
625 String m = viewer.ms.getModelFileName(0);
631 filePath = new File(m).getAbsolutePath();
632 } catch (AccessControlException x)
634 // usually not allowed to do this in applet
636 "jmolBinding: Using local file string from Jmol: " + m);
638 if (filePath.indexOf("/file:") != -1)
640 // applet path with docroot - discard as format won't match pdbfile
644 _modelFileNameMap[0] = 0; // filename index for first model is always 0.
647 for (int i = 1; i < viewer.ms.mc; i++)
649 m = viewer.ms.getModelFileName(i);
655 filePath = new File(m).getAbsolutePath();
656 } catch (AccessControlException x)
658 // usually not allowed to do this in applet, so keep raw handle
659 // System.err.println("jmolBinding: Using local file string from
665 * add this model unless it is read from a structure file we have
666 * already seen (example: 2MJW is an NMR structure with 10 models)
668 if (!mset.contains(filePath))
671 _modelFileNameMap[j] = i; // record the model index for the filename
675 modelFileNames = mset.toArray(new String[mset.size()]);
677 return modelFileNames;
681 public synchronized String[] getStructureFiles()
683 List<String> mset = new ArrayList<>();
686 return new String[0];
689 if (modelFileNames == null)
691 int modelCount = viewer.ms.mc;
692 String filePath = null;
693 for (int i = 0; i < modelCount; ++i)
695 filePath = viewer.ms.getModelFileName(i);
696 if (!mset.contains(filePath))
701 modelFileNames = mset.toArray(new String[mset.size()]);
704 return modelFileNames;
708 * map from string to applet
711 public Map<String, Object> getRegistryInfo()
713 // TODO Auto-generated method stub
717 // ///////////////////////////////
718 // JmolStatusListener
720 public void handlePopupMenu(int x, int y)
722 // jmolpopup.show(x, y);
723 // jmolpopup.jpiShow(x, y);
727 * Highlight zero, one or more atoms on the structure
730 public void highlightAtoms(List<AtomSpec> atoms)
734 if (resetLastRes.length() > 0)
736 viewer.evalStringQuiet(resetLastRes.toString());
737 resetLastRes.setLength(0);
739 for (AtomSpec atom : atoms)
741 highlightAtom(atom.getAtomIndex(), atom.getPdbResNum(),
742 atom.getChain(), atom.getPdbFile());
748 public void highlightAtom(int atomIndex, int pdbResNum, String chain,
751 if (modelFileNames == null)
756 // look up file model number for this pdbfile
758 // may need to adjust for URLencoding here - we don't worry about that yet.
759 while (mdlNum < modelFileNames.length
760 && !pdbfile.equals(modelFileNames[mdlNum]))
764 if (mdlNum == modelFileNames.length)
771 StringBuilder cmd = new StringBuilder(64);
772 cmd.append("select " + pdbResNum); // +modelNum
774 resetLastRes.append("select " + pdbResNum); // +modelNum
777 resetLastRes.append(":");
778 if (!chain.equals(" "))
781 resetLastRes.append(chain);
784 cmd.append(" /" + (mdlNum + 1));
785 resetLastRes.append("/" + (mdlNum + 1));
787 cmd.append(";wireframe 100;" + cmd.toString() + " and not hetero;");
789 resetLastRes.append(";wireframe 0;" + resetLastRes.toString()
790 + " and not hetero; spacefill 0;");
792 cmd.append("spacefill 200;select none");
794 viewer.evalStringQuiet(cmd.toString());
799 boolean debug = true;
801 private void jmolHistory(boolean enable)
803 viewer.evalStringQuiet("History " + ((debug || enable) ? "on" : "off"));
806 public void loadInline(String string)
810 // viewer.loadInline(strModel, isAppend);
812 // construct fake fullPathName and fileName so we can identify the file
814 // Then, construct pass a reader for the string to Jmol.
815 // ((org.jmol.Viewer.Viewer) viewer).loadModelFromFile(fullPathName,
816 // fileName, null, reader, false, null, null, 0);
817 viewer.openStringInline(string);
820 public void mouseOverStructure(int atomIndex, String strInfo)
823 int alocsep = strInfo.indexOf("^");
824 int mdlSep = strInfo.indexOf("/");
825 int chainSeparator = strInfo.indexOf(":"), chainSeparator1 = -1;
827 if (chainSeparator == -1)
829 chainSeparator = strInfo.indexOf(".");
830 if (mdlSep > -1 && mdlSep < chainSeparator)
832 chainSeparator1 = chainSeparator;
833 chainSeparator = mdlSep;
836 // handle insertion codes
839 pdbResNum = Integer.parseInt(
840 strInfo.substring(strInfo.indexOf("]") + 1, alocsep));
845 pdbResNum = Integer.parseInt(
846 strInfo.substring(strInfo.indexOf("]") + 1, chainSeparator));
850 if (strInfo.indexOf(":") > -1)
852 chainId = strInfo.substring(strInfo.indexOf(":") + 1,
853 strInfo.indexOf("."));
860 String pdbfilename = modelFileNames[frameNo]; // default is first or current
864 if (chainSeparator1 == -1)
866 chainSeparator1 = strInfo.indexOf(".", mdlSep);
868 String mdlId = (chainSeparator1 > -1)
869 ? strInfo.substring(mdlSep + 1, chainSeparator1)
870 : strInfo.substring(mdlSep + 1);
873 // recover PDB filename for the model hovered over.
874 int _mp = _modelFileNameMap.length - 1,
875 mnumber = new Integer(mdlId).intValue() - 1;
876 while (mnumber < _modelFileNameMap[_mp])
880 pdbfilename = modelFileNames[_mp];
881 if (pdbfilename == null)
883 pdbfilename = new File(viewer.ms.getModelFileName(mnumber))
887 } catch (Exception e)
892 if (lastMessage == null || !lastMessage.equals(strInfo))
894 getSsm().mouseOverStructure(pdbResNum, chainId, pdbfilename);
897 lastMessage = strInfo;
900 public void notifyAtomHovered(int atomIndex, String strInfo, String data)
904 System.err.println("Ignoring additional hover info: " + data
905 + " (other info: '" + strInfo + "' pos " + atomIndex + ")");
907 mouseOverStructure(atomIndex, strInfo);
911 * { if (history != null && strStatus != null &&
912 * !strStatus.equals("Script completed")) { history.append("\n" + strStatus);
916 public void notifyAtomPicked(int atomIndex, String strInfo,
920 * this implements the toggle label behaviour copied from the original
921 * structure viewer, MCView
925 System.err.println("Ignoring additional pick data string " + strData);
927 int chainSeparator = strInfo.indexOf(":");
929 if (chainSeparator == -1)
931 chainSeparator = strInfo.indexOf(".");
934 String picked = strInfo.substring(strInfo.indexOf("]") + 1,
936 String mdlString = "";
937 if ((p = strInfo.indexOf(":")) > -1)
939 picked += strInfo.substring(p, strInfo.indexOf("."));
942 if ((p = strInfo.indexOf("/")) > -1)
944 mdlString += strInfo.substring(p, strInfo.indexOf(" #"));
946 picked = "((" + picked + ".CA" + mdlString + ")|(" + picked + ".P"
950 if (!atomsPicked.contains(picked))
952 viewer.evalStringQuiet("select " + picked + ";label %n %r:%c");
953 atomsPicked.addElement(picked);
957 viewer.evalString("select " + picked + ";label off");
958 atomsPicked.removeElement(picked);
961 // TODO: in application this happens
963 // if (scriptWindow != null)
965 // scriptWindow.sendConsoleMessage(strInfo);
966 // scriptWindow.sendConsoleMessage("\n");
972 public void notifyCallback(CBK type, Object[] data)
979 notifyFileLoaded((String) data[1], (String) data[2],
980 (String) data[3], (String) data[4],
981 ((Integer) data[5]).intValue());
985 notifyAtomPicked(((Integer) data[2]).intValue(), (String) data[1],
987 // also highlight in alignment
988 // deliberate fall through
990 notifyAtomHovered(((Integer) data[2]).intValue(), (String) data[1],
994 notifyScriptTermination((String) data[2],
995 ((Integer) data[3]).intValue());
998 sendConsoleEcho((String) data[1]);
1002 (data == null) ? ((String) null) : (String) data[1]);
1005 // System.err.println("Ignoring error callback.");
1016 "Unhandled callback " + type + " " + data[1].toString());
1019 } catch (Exception e)
1021 System.err.println("Squashed Jmol callback handler error:");
1022 e.printStackTrace();
1027 public boolean notifyEnabled(CBK callbackPick)
1029 switch (callbackPick)
1045 // incremented every time a load notification is successfully handled -
1046 // lightweight mechanism for other threads to detect when they can start
1047 // referrring to new structures.
1048 private long loadNotifiesHandled = 0;
1050 public long getLoadNotifiesHandled()
1052 return loadNotifiesHandled;
1055 public void notifyFileLoaded(String fullPathName, String fileName2,
1056 String modelName, String errorMsg, int modelParts)
1058 if (errorMsg != null)
1060 fileLoadingError = errorMsg;
1064 // TODO: deal sensibly with models loaded inLine:
1065 // modelName will be null, as will fullPathName.
1067 // the rest of this routine ignores the arguments, and simply interrogates
1068 // the Jmol view to find out what structures it contains, and adds them to
1069 // the structure selection manager.
1070 fileLoadingError = null;
1071 String[] oldmodels = modelFileNames;
1072 modelFileNames = null;
1073 chainNames = new ArrayList<>();
1074 chainFile = new Hashtable<>();
1075 boolean notifyLoaded = false;
1076 String[] modelfilenames = getStructureFiles();
1077 // first check if we've lost any structures
1078 if (oldmodels != null && oldmodels.length > 0)
1081 for (int i = 0; i < oldmodels.length; i++)
1083 for (int n = 0; n < modelfilenames.length; n++)
1085 if (modelfilenames[n] == oldmodels[i])
1087 oldmodels[i] = null;
1091 if (oldmodels[i] != null)
1098 String[] oldmfn = new String[oldm];
1100 for (int i = 0; i < oldmodels.length; i++)
1102 if (oldmodels[i] != null)
1104 oldmfn[oldm++] = oldmodels[i];
1107 // deregister the Jmol instance for these structures - we'll add
1108 // ourselves again at the end for the current structure set.
1109 getSsm().removeStructureViewerListener(this, oldmfn);
1112 refreshPdbEntries();
1113 for (int modelnum = 0; modelnum < modelfilenames.length; modelnum++)
1115 String fileName = modelfilenames[modelnum];
1116 boolean foundEntry = false;
1117 StructureFile pdb = null;
1118 String pdbfile = null;
1119 // model was probably loaded inline - so check the pdb file hashcode
1122 // calculate essential attributes for the pdb data imported inline.
1123 // prolly need to resolve modelnumber properly - for now just use our
1125 pdbfile = viewer.getData(
1126 "" + (1 + _modelFileNameMap[modelnum]) + ".0", "PDB");
1128 // search pdbentries and sequences to find correct pdbentry for this
1130 for (int pe = 0; pe < getPdbCount(); pe++)
1132 boolean matches = false;
1133 addSequence(pe, getSequence()[pe]);
1134 if (fileName == null)
1137 // see JAL-623 - need method of matching pasted data up
1139 pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe],
1140 pdbfile, DataSourceType.PASTE,
1141 getIProgressIndicator());
1142 getPdbEntry(modelnum).setFile("INLINE" + pdb.getId());
1149 File fl = new File(getPdbEntry(pe).getFile());
1150 matches = fl.equals(new File(fileName));
1154 // TODO: Jmol can in principle retrieve from CLASSLOADER but
1157 // to be tested. See mantis bug
1158 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
1159 DataSourceType protocol = DataSourceType.URL;
1164 protocol = DataSourceType.FILE;
1166 } catch (Exception e)
1171 // Explicitly map to the filename used by Jmol ;
1172 pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe],
1173 fileName, protocol, getIProgressIndicator());
1174 // pdbentry[pe].getFile(), protocol);
1180 // add an entry for every chain in the model
1181 for (int i = 0; i < pdb.getChains().size(); i++)
1183 String chid = new String(
1184 pdb.getId() + ":" + pdb.getChains().elementAt(i).id);
1185 chainFile.put(chid, fileName);
1186 chainNames.add(chid);
1188 notifyLoaded = true;
1192 if (!foundEntry && associateNewStructs)
1194 // this is a foreign pdb file that jalview doesn't know about - add
1195 // it to the dataset and try to find a home - either on a matching
1196 // sequence or as a new sequence.
1197 String pdbcontent = viewer.getData("/" + (modelnum + 1) + ".1",
1199 // parse pdb file into a chain, etc.
1200 // locate best match for pdb in associated views and add mapping to
1202 // if properly registered then
1203 notifyLoaded = true;
1208 // so finally, update the jmol bits and pieces
1209 // if (jmolpopup != null)
1211 // // potential for deadlock here:
1212 // // jmolpopup.updateComputedMenus();
1214 if (!isLoadingFromArchive())
1216 viewer.evalStringQuiet(
1217 "model *; select backbone;restrict;cartoon;wireframe off;spacefill off");
1219 // register ourselves as a listener and notify the gui that it needs to
1221 getSsm().addStructureViewerListener(this);
1224 FeatureRenderer fr = getFeatureRenderer(null);
1230 loadNotifiesHandled++;
1232 setLoadingFromArchive(false);
1236 public List<String> getChainNames()
1241 protected abstract IProgressIndicator getIProgressIndicator();
1243 public void notifyNewPickingModeMeasurement(int iatom, String strMeasure)
1245 notifyAtomPicked(iatom, strMeasure, null);
1248 public abstract void notifyScriptTermination(String strStatus,
1252 * display a message echoed from the jmol viewer
1256 public abstract void sendConsoleEcho(String strEcho); /*
1257 * { showConsole(true);
1259 * history.append("\n" +
1263 // /End JmolStatusListener
1264 // /////////////////////////////
1268 * status message - usually the response received after a script
1271 public abstract void sendConsoleMessage(String strStatus);
1274 public void setCallbackFunction(String callbackType,
1275 String callbackFunction)
1277 System.err.println("Ignoring set-callback request to associate "
1278 + callbackType + " with function " + callbackFunction);
1283 public void setJalviewColourScheme(ColourSchemeI cs)
1285 colourBySequence = false;
1293 StringBuilder command = new StringBuilder(128);
1294 command.append("select *;color white;");
1295 List<String> residueSet = ResidueProperties.getResidues(isNucleotide(),
1297 for (String resName : residueSet)
1299 char res = resName.length() == 3
1300 ? ResidueProperties.getSingleCharacterCode(resName)
1301 : resName.charAt(0);
1302 Color col = cs.findColour(res, 0, null, null, 0f);
1303 command.append("select " + resName + ";color[" + col.getRed() + ","
1304 + col.getGreen() + "," + col.getBlue() + "];");
1307 evalStateCommand(command.toString());
1311 public void showHelp()
1313 showUrl("http://jmol.sourceforge.net/docs/JmolUserGuide/", "jmolHelp");
1317 * open the URL somehow
1321 public abstract void showUrl(String url, String target);
1324 * called when the binding thinks the UI needs to be refreshed after a Jmol
1325 * state change. this could be because structures were loaded, or because an
1326 * error has occured.
1328 public abstract void refreshGUI();
1331 * called to show or hide the associated console window container.
1335 public abstract void showConsole(boolean show);
1338 * @param renderPanel
1340 * - when true will initialise jmol's file IO system (should be false
1341 * in applet context)
1343 * @param documentBase
1345 * @param commandOptions
1347 public void allocateViewer(Container renderPanel, boolean jmolfileio,
1348 String htmlName, URL documentBase, URL codeBase,
1349 String commandOptions)
1351 allocateViewer(renderPanel, jmolfileio, htmlName, documentBase,
1352 codeBase, commandOptions, null, null);
1357 * @param renderPanel
1359 * - when true will initialise jmol's file IO system (should be false
1360 * in applet context)
1362 * @param documentBase
1364 * @param commandOptions
1365 * @param consolePanel
1366 * - panel to contain Jmol console
1367 * @param buttonsToShow
1368 * - buttons to show on the console, in ordr
1370 public void allocateViewer(Container renderPanel, boolean jmolfileio,
1371 String htmlName, URL documentBase, URL codeBase,
1372 String commandOptions, final Container consolePanel,
1373 String buttonsToShow)
1375 if (commandOptions == null)
1377 commandOptions = "";
1379 viewer = (Viewer) JmolViewer.allocateViewer(renderPanel,
1380 (jmolfileio ? new SmarterJmolAdapter() : null),
1381 htmlName + ((Object) this).toString(), documentBase, codeBase,
1382 commandOptions, this);
1384 viewer.setJmolStatusListener(this); // extends JmolCallbackListener
1386 console = createJmolConsole(consolePanel, buttonsToShow);
1387 if (consolePanel != null)
1389 consolePanel.addComponentListener(this);
1395 protected abstract JmolAppConsoleInterface createJmolConsole(
1396 Container consolePanel, String buttonsToShow);
1398 protected org.jmol.api.JmolAppConsoleInterface console = null;
1401 public void setBackgroundColour(java.awt.Color col)
1404 viewer.evalStringQuiet("background [" + col.getRed() + ","
1405 + col.getGreen() + "," + col.getBlue() + "];");
1410 public int[] resizeInnerPanel(String data)
1412 // Jalview doesn't honour resize panel requests
1419 protected void closeConsole()
1421 if (console != null)
1425 console.setVisible(false);
1428 } catch (Exception x)
1437 * ComponentListener method
1440 public void componentMoved(ComponentEvent e)
1445 * ComponentListener method
1448 public void componentResized(ComponentEvent e)
1453 * ComponentListener method
1456 public void componentShown(ComponentEvent e)
1462 * ComponentListener method
1465 public void componentHidden(ComponentEvent e)