2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ext.jmol;
23 import jalview.api.AlignmentViewPanel;
24 import jalview.api.FeatureRenderer;
25 import jalview.api.SequenceRenderer;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.ColumnSelection;
28 import jalview.datamodel.PDBEntry;
29 import jalview.datamodel.SequenceI;
30 import jalview.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 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 boolean allChainsSelected = false;
71 * when true, try to search the associated datamodel for sequences that are
72 * associated with any unknown structures in the Jmol view.
74 private boolean associateNewStructs = false;
76 Vector<String> atomsPicked = new Vector<String>();
78 private List<String> chainNames;
80 Hashtable<String, String> chainFile;
83 * the default or current model displayed if the model cannot be identified
84 * from the selection message
88 // 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 ColumnSelection hiddenCols)
228 superposeStructures(new AlignmentI[] { alignment },
229 new int[] { refStructure },
230 new ColumnSelection[] { hiddenCols });
237 public String superposeStructures(AlignmentI[] _alignment,
238 int[] _refStructure, ColumnSelection[] _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 ColumnSelection hiddenCols = _hiddenCols[a];
284 && selectioncom.length() > 0
285 && !selectioncom.substring(selectioncom.length() - 1).equals(
288 selectioncom.append("|");
290 // process this alignment
291 if (refStructure >= files.length)
293 System.err.println("Invalid reference structure value "
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(
337 "label.insufficient_residues",
342 * generate select statements to select regions to superimpose structures
345 // TODO extract method to construct selection statements
346 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
348 String chainCd = ":" + structures[pdbfnum].chain;
351 StringBuilder molsel = new StringBuilder();
354 int nextColumnMatch = matched.nextSetBit(0);
355 while (nextColumnMatch != -1)
357 int pdbResNo = structures[pdbfnum].pdbResNo[nextColumnMatch];
358 if (lpos != pdbResNo - 1)
364 molsel.append(chainCd);
371 // continuous run - and lpos >-1
374 // at the beginning, so add dash
381 nextColumnMatch = matched.nextSetBit(nextColumnMatch + 1);
384 * add final selection phrase
389 molsel.append(chainCd);
392 if (molsel.length() > 1)
394 selcom[pdbfnum] = molsel.toString();
395 selectioncom.append("((");
396 selectioncom.append(selcom[pdbfnum].substring(1,
397 selcom[pdbfnum].length() - 1));
398 selectioncom.append(" )& ");
399 selectioncom.append(pdbfnum + 1);
400 selectioncom.append(".1)");
401 if (pdbfnum < files.length - 1)
403 selectioncom.append("|");
408 selcom[pdbfnum] = null;
412 StringBuilder command = new StringBuilder(256);
413 // command.append("set spinFps 10;\n");
415 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
417 if (pdbfnum == refStructure || selcom[pdbfnum] == null
418 || selcom[refStructure] == null)
422 command.append("echo ");
423 command.append("\"Superposing (");
424 command.append(structures[pdbfnum].pdbId);
425 command.append(") against reference (");
426 command.append(structures[refStructure].pdbId);
427 command.append(")\";\ncompare " + nSeconds);
429 command.append(Integer.toString(1 + pdbfnum));
430 command.append(".1} {");
431 command.append(Integer.toString(1 + refStructure));
432 // conformation=1 excludes alternate locations for CA (JAL-1757)
433 command.append(".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()+"; cartoons; center "+selcom.toString());
471 public void evalStateCommand(String command)
474 if (lastCommand == null || !lastCommand.equals(command))
476 viewer.evalStringQuiet(command + "\n");
479 lastCommand = command;
483 * Sends a set of colour commands to the structure viewer
485 * @param colourBySequenceCommands
488 protected void colourBySequence(
489 StructureMappingcommandSet[] colourBySequenceCommands)
491 for (StructureMappingcommandSet cpdbbyseq : colourBySequenceCommands)
493 for (String cbyseq : cpdbbyseq.commands)
495 executeWhenReady(cbyseq);
507 protected StructureMappingcommandSet[] getColourBySequenceCommands(
508 String[] files, SequenceRenderer sr, AlignmentViewPanel viewPanel)
510 return JmolCommands.getColourBySequenceCommand(getSsm(), files,
511 getSequence(), sr, viewPanel);
517 protected void executeWhenReady(String command)
519 evalStateCommand(command);
522 public void createImage(String file, String type, int quality)
524 System.out.println("JMOL CREATE IMAGE");
528 public String createImage(String fileName, String type,
529 Object textOrBytes, int quality)
531 System.out.println("JMOL CREATE IMAGE");
536 public String eval(String strEval)
538 // System.out.println(strEval);
539 // "# 'eval' is implemented only for the applet.";
543 // End StructureListener
544 // //////////////////////////
547 public float[][] functionXY(String functionName, int x, int y)
553 public float[][][] functionXYZ(String functionName, int nx, int ny, int nz)
555 // TODO Auto-generated method stub
559 public Color getColour(int atomIndex, int pdbResNum, String chain,
562 if (getModelNum(pdbfile) < 0)
566 // TODO: verify atomIndex is selecting correct model.
567 // return new Color(viewer.getAtomArgb(atomIndex)); Jmol 12.2.4
568 int colour = viewer.ms.at[atomIndex].atomPropertyInt(T.color);
569 return new Color(colour);
573 * instruct the Jalview binding to update the pdbentries vector if necessary
574 * prior to matching the jmol view's contents to the list of structure files
575 * Jalview knows about.
577 public abstract void refreshPdbEntries();
579 private int getModelNum(String modelFileName)
581 String[] mfn = getStructureFiles();
586 for (int i = 0; i < mfn.length; i++)
588 if (mfn[i].equalsIgnoreCase(modelFileName))
597 * map between index of model filename returned from getPdbFile and the first
598 * index of models from this file in the viewer. Note - this is not trimmed -
599 * use getPdbFile to get number of unique models.
601 private int _modelFileNameMap[];
603 // ////////////////////////////////
604 // /StructureListener
606 public synchronized String[] getPdbFilex()
610 return new String[0];
612 if (modelFileNames == null)
614 List<String> mset = new ArrayList<String>();
615 _modelFileNameMap = new int[viewer.ms.mc];
616 String m = viewer.ms.getModelFileName(0);
622 filePath = new File(m).getAbsolutePath();
623 } catch (AccessControlException x)
625 // usually not allowed to do this in applet
627 .println("jmolBinding: Using local file string from Jmol: "
630 if (filePath.indexOf("/file:") != -1)
632 // applet path with docroot - discard as format won't match pdbfile
636 _modelFileNameMap[0] = 0; // filename index for first model is always 0.
639 for (int i = 1; i < viewer.ms.mc; i++)
641 m = viewer.ms.getModelFileName(i);
647 filePath = new File(m).getAbsolutePath();
648 } catch (AccessControlException x)
650 // usually not allowed to do this in applet, so keep raw handle
651 // System.err.println("jmolBinding: Using local file string from Jmol: "+m);
656 * add this model unless it is read from a structure file we have
657 * already seen (example: 2MJW is an NMR structure with 10 models)
659 if (!mset.contains(filePath))
662 _modelFileNameMap[j] = i; // record the model index for the filename
666 modelFileNames = mset.toArray(new String[mset.size()]);
668 return modelFileNames;
672 public synchronized String[] getStructureFiles()
674 List<String> mset = new ArrayList<String>();
677 return new String[0];
680 if (modelFileNames == null)
682 int modelCount = viewer.ms.mc;
683 String filePath = null;
684 for (int i = 0; i < modelCount; ++i)
686 filePath = viewer.ms.getModelFileName(i);
687 if (!mset.contains(filePath))
692 modelFileNames = mset.toArray(new String[mset.size()]);
695 return modelFileNames;
698 * map from string to applet
701 public Map<String, Object> getRegistryInfo()
703 // TODO Auto-generated method stub
709 // ///////////////////////////////
710 // JmolStatusListener
712 public void handlePopupMenu(int x, int y)
714 // jmolpopup.show(x, y);
715 // jmolpopup.jpiShow(x, y);
719 * Highlight zero, one or more atoms on the structure
722 public void highlightAtoms(List<AtomSpec> atoms)
726 if (resetLastRes.length() > 0)
728 viewer.evalStringQuiet(resetLastRes.toString());
729 resetLastRes.setLength(0);
731 for (AtomSpec atom : atoms)
733 highlightAtom(atom.getAtomIndex(), atom.getPdbResNum(),
734 atom.getChain(), atom.getPdbFile());
740 public void highlightAtom(int atomIndex, int pdbResNum, String chain,
743 if (modelFileNames == null)
748 // look up file model number for this pdbfile
750 // may need to adjust for URLencoding here - we don't worry about that yet.
751 while (mdlNum < modelFileNames.length
752 && !pdbfile.equals(modelFileNames[mdlNum]))
756 if (mdlNum == modelFileNames.length)
763 StringBuilder cmd = new StringBuilder(64);
764 cmd.append("select " + pdbResNum); // +modelNum
766 resetLastRes.append("select " + pdbResNum); // +modelNum
769 resetLastRes.append(":");
770 if (!chain.equals(" "))
773 resetLastRes.append(chain);
776 cmd.append(" /" + (mdlNum + 1));
777 resetLastRes.append("/" + (mdlNum + 1));
779 cmd.append(";wireframe 100;" + cmd.toString() + " and not hetero;");
781 resetLastRes.append(";wireframe 0;" + resetLastRes.toString()
782 + " and not hetero; spacefill 0;");
784 cmd.append("spacefill 200;select none");
786 viewer.evalStringQuiet(cmd.toString());
791 boolean debug = true;
793 private void jmolHistory(boolean enable)
795 viewer.evalStringQuiet("History " + ((debug || enable) ? "on" : "off"));
798 public void loadInline(String string)
802 // viewer.loadInline(strModel, isAppend);
804 // construct fake fullPathName and fileName so we can identify the file
806 // Then, construct pass a reader for the string to Jmol.
807 // ((org.jmol.Viewer.Viewer) viewer).loadModelFromFile(fullPathName,
808 // fileName, null, reader, false, null, null, 0);
809 viewer.openStringInline(string);
812 public void mouseOverStructure(int atomIndex, String strInfo)
815 int alocsep = strInfo.indexOf("^");
816 int mdlSep = strInfo.indexOf("/");
817 int chainSeparator = strInfo.indexOf(":"), chainSeparator1 = -1;
819 if (chainSeparator == -1)
821 chainSeparator = strInfo.indexOf(".");
822 if (mdlSep > -1 && mdlSep < chainSeparator)
824 chainSeparator1 = chainSeparator;
825 chainSeparator = mdlSep;
828 // handle insertion codes
831 pdbResNum = Integer.parseInt(strInfo.substring(
832 strInfo.indexOf("]") + 1, alocsep));
837 pdbResNum = Integer.parseInt(strInfo.substring(
838 strInfo.indexOf("]") + 1, chainSeparator));
842 if (strInfo.indexOf(":") > -1)
844 chainId = strInfo.substring(strInfo.indexOf(":") + 1,
845 strInfo.indexOf("."));
852 String pdbfilename = modelFileNames[frameNo]; // default is first or current
856 if (chainSeparator1 == -1)
858 chainSeparator1 = strInfo.indexOf(".", mdlSep);
860 String mdlId = (chainSeparator1 > -1) ? strInfo.substring(mdlSep + 1,
861 chainSeparator1) : strInfo.substring(mdlSep + 1);
864 // recover PDB filename for the model hovered over.
865 int _mp = _modelFileNameMap.length - 1, mnumber = new Integer(mdlId)
867 while (mnumber < _modelFileNameMap[_mp])
871 pdbfilename = modelFileNames[_mp];
872 if (pdbfilename == null)
874 pdbfilename = new File(viewer.ms.getModelFileName(mnumber))
878 } catch (Exception e)
883 if (lastMessage == null || !lastMessage.equals(strInfo))
885 getSsm().mouseOverStructure(pdbResNum, chainId, pdbfilename);
888 lastMessage = strInfo;
891 public void notifyAtomHovered(int atomIndex, String strInfo, String data)
895 System.err.println("Ignoring additional hover info: " + data
896 + " (other info: '" + strInfo + "' pos " + atomIndex + ")");
898 mouseOverStructure(atomIndex, strInfo);
902 * { if (history != null && strStatus != null &&
903 * !strStatus.equals("Script completed")) { history.append("\n" + strStatus);
907 public void notifyAtomPicked(int atomIndex, String strInfo, String strData)
910 * this implements the toggle label behaviour copied from the original
911 * structure viewer, MCView
915 System.err.println("Ignoring additional pick data string " + strData);
917 int chainSeparator = strInfo.indexOf(":");
919 if (chainSeparator == -1)
921 chainSeparator = strInfo.indexOf(".");
924 String picked = strInfo.substring(strInfo.indexOf("]") + 1,
926 String mdlString = "";
927 if ((p = strInfo.indexOf(":")) > -1)
929 picked += strInfo.substring(p, strInfo.indexOf("."));
932 if ((p = strInfo.indexOf("/")) > -1)
934 mdlString += strInfo.substring(p, strInfo.indexOf(" #"));
936 picked = "((" + picked + ".CA" + mdlString + ")|(" + picked + ".P"
940 if (!atomsPicked.contains(picked))
942 viewer.evalStringQuiet("select " + picked + ";label %n %r:%c");
943 atomsPicked.addElement(picked);
947 viewer.evalString("select " + picked + ";label off");
948 atomsPicked.removeElement(picked);
951 // TODO: in application this happens
953 // if (scriptWindow != null)
955 // scriptWindow.sendConsoleMessage(strInfo);
956 // scriptWindow.sendConsoleMessage("\n");
962 public void notifyCallback(CBK type, Object[] data)
969 notifyFileLoaded((String) data[1], (String) data[2],
970 (String) data[3], (String) data[4],
971 ((Integer) data[5]).intValue());
975 notifyAtomPicked(((Integer) data[2]).intValue(), (String) data[1],
977 // also highlight in alignment
979 notifyAtomHovered(((Integer) data[2]).intValue(), (String) data[1],
983 notifyScriptTermination((String) data[2],
984 ((Integer) data[3]).intValue());
987 sendConsoleEcho((String) data[1]);
990 sendConsoleMessage((data == null) ? ((String) null)
994 // System.err.println("Ignoring error callback.");
1004 System.err.println("Unhandled callback " + type + " "
1005 + data[1].toString());
1008 } catch (Exception e)
1010 System.err.println("Squashed Jmol callback handler error:");
1011 e.printStackTrace();
1016 public boolean notifyEnabled(CBK callbackPick)
1018 switch (callbackPick)
1034 // incremented every time a load notification is successfully handled -
1035 // lightweight mechanism for other threads to detect when they can start
1036 // referrring to new structures.
1037 private long loadNotifiesHandled = 0;
1039 public long getLoadNotifiesHandled()
1041 return loadNotifiesHandled;
1044 public void notifyFileLoaded(String fullPathName, String fileName2,
1045 String modelName, String errorMsg, int modelParts)
1047 if (errorMsg != null)
1049 fileLoadingError = errorMsg;
1053 // TODO: deal sensibly with models loaded inLine:
1054 // modelName will be null, as will fullPathName.
1056 // the rest of this routine ignores the arguments, and simply interrogates
1057 // the Jmol view to find out what structures it contains, and adds them to
1058 // the structure selection manager.
1059 fileLoadingError = null;
1060 String[] oldmodels = modelFileNames;
1061 modelFileNames = null;
1062 chainNames = new ArrayList<String>();
1063 chainFile = new Hashtable<String, String>();
1064 boolean notifyLoaded = false;
1065 String[] modelfilenames = getStructureFiles();
1066 // first check if we've lost any structures
1067 if (oldmodels != null && oldmodels.length > 0)
1070 for (int i = 0; i < oldmodels.length; i++)
1072 for (int n = 0; n < modelfilenames.length; n++)
1074 if (modelfilenames[n] == oldmodels[i])
1076 oldmodels[i] = null;
1080 if (oldmodels[i] != null)
1087 String[] oldmfn = new String[oldm];
1089 for (int i = 0; i < oldmodels.length; i++)
1091 if (oldmodels[i] != null)
1093 oldmfn[oldm++] = oldmodels[i];
1096 // deregister the Jmol instance for these structures - we'll add
1097 // ourselves again at the end for the current structure set.
1098 getSsm().removeStructureViewerListener(this, oldmfn);
1101 refreshPdbEntries();
1102 for (int modelnum = 0; modelnum < modelfilenames.length; modelnum++)
1104 String fileName = modelfilenames[modelnum];
1105 boolean foundEntry = false;
1106 StructureFile pdb = null;
1107 String pdbfile = null;
1108 // model was probably loaded inline - so check the pdb file hashcode
1111 // calculate essential attributes for the pdb data imported inline.
1112 // prolly need to resolve modelnumber properly - for now just use our
1114 pdbfile = viewer.getData("" + (1 + _modelFileNameMap[modelnum])
1117 // search pdbentries and sequences to find correct pdbentry for this
1119 for (int pe = 0; pe < getPdbCount(); pe++)
1121 boolean matches = false;
1122 addSequence(pe, getSequence()[pe]);
1123 if (fileName == null)
1126 // see JAL-623 - need method of matching pasted data up
1128 pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe],
1129 pdbfile, DataSourceType.PASTE, getIProgressIndicator());
1130 getPdbEntry(modelnum).setFile("INLINE" + pdb.getId());
1137 File fl = new File(getPdbEntry(pe).getFile());
1138 matches = fl.equals(new File(fileName));
1142 // TODO: Jmol can in principle retrieve from CLASSLOADER but
1145 // to be tested. See mantis bug
1146 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
1147 DataSourceType protocol = DataSourceType.URL;
1152 protocol = DataSourceType.FILE;
1154 } catch (Exception e)
1159 // Explicitly map to the filename used by Jmol ;
1160 pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe],
1161 fileName, protocol, getIProgressIndicator());
1162 // pdbentry[pe].getFile(), protocol);
1168 // add an entry for every chain in the model
1169 for (int i = 0; i < pdb.getChains().size(); i++)
1171 String chid = new String(pdb.getId() + ":"
1172 + pdb.getChains().elementAt(i).id);
1173 chainFile.put(chid, fileName);
1174 chainNames.add(chid);
1176 notifyLoaded = true;
1180 if (!foundEntry && associateNewStructs)
1182 // this is a foreign pdb file that jalview doesn't know about - add
1183 // it to the dataset and try to find a home - either on a matching
1184 // sequence or as a new sequence.
1185 String pdbcontent = viewer.getData("/" + (modelnum + 1) + ".1",
1187 // parse pdb file into a chain, etc.
1188 // locate best match for pdb in associated views and add mapping to
1190 // if properly registered then
1191 notifyLoaded = true;
1196 // so finally, update the jmol bits and pieces
1197 // if (jmolpopup != null)
1199 // // potential for deadlock here:
1200 // // jmolpopup.updateComputedMenus();
1202 if (!isLoadingFromArchive())
1204 viewer.evalStringQuiet("model *; select backbone;restrict;cartoon;wireframe off;spacefill off");
1206 // register ourselves as a listener and notify the gui that it needs to
1208 getSsm().addStructureViewerListener(this);
1211 FeatureRenderer fr = getFeatureRenderer(null);
1217 loadNotifiesHandled++;
1219 setLoadingFromArchive(false);
1223 public List<String> getChainNames()
1228 protected abstract IProgressIndicator getIProgressIndicator();
1230 public void notifyNewPickingModeMeasurement(int iatom, String strMeasure)
1232 notifyAtomPicked(iatom, strMeasure, null);
1235 public abstract void notifyScriptTermination(String strStatus,
1239 * display a message echoed from the jmol viewer
1243 public abstract void sendConsoleEcho(String strEcho); /*
1244 * { showConsole(true);
1246 * history.append("\n" +
1250 // /End JmolStatusListener
1251 // /////////////////////////////
1255 * status message - usually the response received after a script
1258 public abstract void sendConsoleMessage(String strStatus);
1261 public void setCallbackFunction(String callbackType,
1262 String callbackFunction)
1264 System.err.println("Ignoring set-callback request to associate "
1265 + callbackType + " with function " + callbackFunction);
1270 public void setJalviewColourScheme(ColourSchemeI cs)
1272 colourBySequence = false;
1280 StringBuilder command = new StringBuilder(128);
1281 command.append("select *;color white;");
1282 List<String> residueSet = ResidueProperties.getResidues(isNucleotide(),
1284 for (String resName : residueSet)
1286 char res = resName.length() == 3 ? ResidueProperties
1287 .getSingleCharacterCode(resName) : resName.charAt(0);
1288 Color col = cs.findColour(res, 0, null, null, 0f);
1289 command.append("select " + resName + ";color[" + col.getRed() + ","
1290 + col.getGreen() + "," + col.getBlue() + "];");
1293 evalStateCommand(command.toString());
1297 public void showHelp()
1299 showUrl("http://jmol.sourceforge.net/docs/JmolUserGuide/", "jmolHelp");
1303 * open the URL somehow
1307 public abstract void showUrl(String url, String target);
1310 * called when the binding thinks the UI needs to be refreshed after a Jmol
1311 * state change. this could be because structures were loaded, or because an
1312 * error has occured.
1314 public abstract void refreshGUI();
1317 * called to show or hide the associated console window container.
1321 public abstract void showConsole(boolean show);
1324 * @param renderPanel
1326 * - when true will initialise jmol's file IO system (should be false
1327 * in applet context)
1329 * @param documentBase
1331 * @param commandOptions
1333 public void allocateViewer(Container renderPanel, boolean jmolfileio,
1334 String htmlName, URL documentBase, URL codeBase,
1335 String commandOptions)
1337 allocateViewer(renderPanel, jmolfileio, htmlName, documentBase,
1338 codeBase, commandOptions, null, null);
1343 * @param renderPanel
1345 * - when true will initialise jmol's file IO system (should be false
1346 * in applet context)
1348 * @param documentBase
1350 * @param commandOptions
1351 * @param consolePanel
1352 * - panel to contain Jmol console
1353 * @param buttonsToShow
1354 * - buttons to show on the console, in ordr
1356 public void allocateViewer(Container renderPanel, boolean jmolfileio,
1357 String htmlName, URL documentBase, URL codeBase,
1358 String commandOptions, final Container consolePanel,
1359 String buttonsToShow)
1361 if (commandOptions == null)
1363 commandOptions = "";
1365 viewer = (Viewer) JmolViewer.allocateViewer(renderPanel,
1366 (jmolfileio ? new SmarterJmolAdapter() : null), htmlName
1367 + ((Object) this).toString(), documentBase, codeBase,
1368 commandOptions, this);
1370 viewer.setJmolStatusListener(this); // extends JmolCallbackListener
1372 console = createJmolConsole(consolePanel, buttonsToShow);
1373 if (consolePanel != null)
1375 consolePanel.addComponentListener(this);
1381 protected abstract JmolAppConsoleInterface createJmolConsole(
1382 Container consolePanel, String buttonsToShow);
1384 protected org.jmol.api.JmolAppConsoleInterface console = null;
1387 public void setBackgroundColour(java.awt.Color col)
1390 viewer.evalStringQuiet("background [" + col.getRed() + ","
1391 + col.getGreen() + "," + col.getBlue() + "];");
1396 public int[] resizeInnerPanel(String data)
1398 // Jalview doesn't honour resize panel requests
1405 protected void closeConsole()
1407 if (console != null)
1411 console.setVisible(false);
1414 } catch (Exception x)
1423 * ComponentListener method
1426 public void componentMoved(ComponentEvent e)
1431 * ComponentListener method
1434 public void componentResized(ComponentEvent e)
1439 * ComponentListener method
1442 public void componentShown(ComponentEvent e)
1448 * ComponentListener method
1451 public void componentHidden(ComponentEvent e)