2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.ext.jmol;
23 import java.applet.Applet;
25 import java.awt.event.*;
27 import jalview.api.FeatureRenderer;
28 import jalview.api.SequenceRenderer;
29 import jalview.api.SequenceStructureBinding;
30 import jalview.datamodel.*;
31 import jalview.structure.*;
34 import org.jmol.api.*;
35 import org.jmol.adapter.smarter.SmarterJmolAdapter;
37 import org.jmol.popup.*;
38 import org.jmol.viewer.JmolConstants;
40 import jalview.schemes.*;
42 public abstract class JalviewJmolBinding implements StructureListener,
43 JmolStatusListener, SequenceStructureBinding, JmolSelectionListener
47 * set if Jmol state is being restored from some source - instructs binding
48 * not to apply default display style when structure set is updated for first
51 private boolean loadingFromArchive = false;
54 * state flag used to check if the Jmol viewer's paint method can be called
56 private boolean finishedInit = false;
58 public boolean isFinishedInit()
63 public void setFinishedInit(boolean finishedInit)
65 this.finishedInit = finishedInit;
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 atomsPicked = new Vector();
78 public Vector chainNames;
81 * array of target chains for seuqences - tied to pdbentry and sequence[]
83 protected String[][] chains;
85 boolean colourBySequence = true;
87 StringBuffer eval = new StringBuffer();
89 public String fileLoadingError;
92 * the default or current model displayed if the model cannot be identified
93 * from the selection message
97 protected JmolPopup jmolpopup;
103 boolean loadedInline;
106 * current set of model filenames loaded in the Jmol instance
108 String[] modelFileNames = null;
110 public PDBEntry[] pdbentry;
113 * datasource protocol for access to PDBEntry
115 String protocol = null;
117 StringBuffer resetLastRes = new StringBuffer();
120 * sequences mapped to each pdbentry
122 public SequenceI[][] sequence;
124 StructureSelectionManager ssm;
126 public JmolViewer viewer;
128 public JalviewJmolBinding(PDBEntry[] pdbentry, SequenceI[][] sequenceIs,
129 String[][] chains, String protocol)
131 this.sequence = sequenceIs;
132 this.chains = chains;
133 this.pdbentry = pdbentry;
134 this.protocol = protocol;
137 this.chains = new String[pdbentry.length][];
140 * viewer = JmolViewer.allocateViewer(renderPanel, new SmarterJmolAdapter(),
141 * "jalviewJmol", ap.av.applet .getDocumentBase(),
142 * ap.av.applet.getCodeBase(), "", this);
144 * jmolpopup = JmolPopup.newJmolPopup(viewer, true, "Jmol", true);
148 public JalviewJmolBinding(JmolViewer viewer2)
151 viewer.setJmolStatusListener(this);
152 viewer.addSelectionListener(this);
156 * construct a title string for the viewer window based on the data jalview
161 public String getViewerTitle()
163 if (sequence == null || pdbentry == null || sequence.length < 1
164 || pdbentry.length < 1)
166 return ("Jalview Jmol Window");
168 StringBuffer title = new StringBuffer(sequence[0][0].getName() + ":"
169 + pdbentry[0].getId());
171 if (pdbentry[0].getProperty() != null)
173 if (pdbentry[0].getProperty().get("method") != null)
175 title.append(" Method: ");
176 title.append(pdbentry[0].getProperty().get("method"));
178 if (pdbentry[0].getProperty().get("chains") != null)
180 title.append(" Chain:");
181 title.append(pdbentry[0].getProperty().get("chains"));
184 return title.toString();
188 * prepare the view for a given set of models/chains. chainList contains
189 * strings of the form 'pdbfilename:Chaincode'
192 * list of chains to make visible
194 public void centerViewer(Vector chainList)
196 StringBuffer cmd = new StringBuffer();
199 for (int i = 0, iSize = chainList.size(); i < iSize; i++)
202 lbl = (String) chainList.elementAt(i);
206 mlength = lbl.indexOf(":", p);
207 } while (p < mlength && mlength < (lbl.length() - 2));
208 cmd.append(":" + lbl.substring(mlength + 1) + " /"
209 + getModelNum(lbl.substring(0, mlength)) + " or ");
211 if (cmd.length() > 0)
212 cmd.setLength(cmd.length() - 4);
213 evalStateCommand("select *;restrict " + cmd + ";cartoon;center " + cmd);
216 public void closeViewer()
218 viewer.setModeMouse(org.jmol.viewer.JmolConstants.MOUSE_NONE);
219 // remove listeners for all structures in viewer
220 StructureSelectionManager.getStructureSelectionManager()
221 .removeStructureViewerListener(this, this.getPdbFile());
222 // and shut down jmol
223 viewer.evalStringQuiet("zap");
224 viewer.setJmolStatusListener(null);
229 public void colourByChain()
231 colourBySequence = false;
232 evalStateCommand("select *;color chain");
235 public void colourByCharge()
237 colourBySequence = false;
238 evalStateCommand("select *;color white;select ASP,GLU;color red;"
239 + "select LYS,ARG;color blue;select CYS;color yellow");
243 * superpose the structures associated with sequences in the alignment
244 * according to their corresponding positions.
246 public void superposeStructures(AlignmentI alignment)
248 superposeStructures(alignment, -1, null);
252 * superpose the structures associated with sequences in the alignment
253 * according to their corresponding positions. ded)
255 * @param refStructure
256 * - select which pdb file to use as reference (default is -1 - the
257 * first structure in the alignment)
259 public void superposeStructures(AlignmentI alignment, int refStructure)
261 superposeStructures(alignment, refStructure, null);
265 * superpose the structures associated with sequences in the alignment
266 * according to their corresponding positions. ded)
267 * @param refStructure
268 * - select which pdb file to use as reference (default is -1 - the
269 * first structure in the alignment)
270 * @param hiddenCols TODO
272 public void superposeStructures(AlignmentI alignment, int refStructure, ColumnSelection hiddenCols)
274 String[] files = getPdbFile();
275 if (refStructure>=files.length)
277 System.err.println("Invalid reference structure value "+refStructure);
284 StringBuffer command = new StringBuffer(), selectioncom = new StringBuffer();
286 boolean matched[] = new boolean[alignment.getWidth()];
287 for (int m = 0; m < matched.length; m++)
290 matched[m] = (hiddenCols!=null) ? hiddenCols.isVisible(m) : true;
293 int commonrpositions[][] = new int[files.length][alignment.getWidth()];
294 String isel[] = new String[files.length];
295 // reference structure - all others are superposed in it
296 String[] targetC = new String[files.length];
297 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
299 StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
301 if (mapping == null || mapping.length < 1)
305 for (int s = 0; s < sequence[pdbfnum].length; s++)
307 for (int sp, m = 0; m < mapping.length; m++)
309 if (mapping[m].getSequence() == sequence[pdbfnum][s]
310 && (sp = alignment.findIndex(sequence[pdbfnum][s])) > -1)
312 if (refStructure == -1)
314 refStructure = pdbfnum;
316 SequenceI asp = alignment.getSequenceAt(sp);
317 for (int r = 0; r < matched.length; r++)
323 matched[r] = false; // assume this is not a good site
324 if (r >= asp.getLength())
329 if (jalview.util.Comparison.isGap(asp.getCharAt(r)))
331 // no mapping to gaps in sequence
334 int t = asp.findPosition(r); // sequence position
335 int apos = mapping[m].getAtomNum(t);
336 int pos = mapping[m].getPDBResNum(t);
338 if (pos < 1 || pos == lastPos)
340 // can't align unmapped sequence
343 matched[r] = true; // this is a good ite
345 // just record this residue position
346 commonrpositions[pdbfnum][r] = pos;
348 // create model selection suffix
349 isel[pdbfnum] = "/" + (pdbfnum + 1) + ".1";
350 if (mapping[m].getChain() == null
351 || mapping[m].getChain().trim().length() == 0)
353 targetC[pdbfnum] = "";
357 targetC[pdbfnum] = ":" + mapping[m].getChain();
359 // move on to next pdb file
360 s = sequence[pdbfnum].length;
366 String[] selcom = new String[files.length];
367 // generate select statements to select regions to superimpose structures
369 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
371 String chainCd = targetC[pdbfnum];
374 StringBuffer molsel = new StringBuffer();
376 for (int r = 0; r < matched.length; r++)
381 if (lpos != commonrpositions[pdbfnum][r] - 1)
387 molsel.append(chainCd);
388 // molsel.append("} {");
394 // continuous run - and lpos >-1
397 // at the beginning, so add dash
403 lpos = commonrpositions[pdbfnum][r];
404 // molsel.append(lpos);
407 // add final selection phrase
411 molsel.append(chainCd);
414 selcom[pdbfnum] = molsel.toString();
415 selectioncom.append("((");
416 selectioncom.append(selcom[pdbfnum].substring(1, selcom[pdbfnum].length()-1));
417 selectioncom.append(" )& ");
418 selectioncom.append(pdbfnum+1);
419 selectioncom.append(".1)");
420 if (pdbfnum<files.length-1)
422 selectioncom.append("|");
427 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
429 if (pdbfnum == refStructure)
433 command.append("compare ");
435 command.append(1 + pdbfnum);
436 command.append(".1} {");
437 command.append(1 + refStructure);
438 command.append(".1} SUBSET {*.CA | *.P} ATOMS ");
440 // form the matched pair strings
442 for (int s = 0; s < 2; s++)
444 command.append(selcom[(s == 0 ? pdbfnum : refStructure)]);
446 command.append(" ROTATE TRANSLATE;\n");
448 System.out.println("Select regions:\n" + selectioncom.toString());
449 evalStateCommand("select *; cartoons off; backbone; select ("+selectioncom.toString()+"); cartoons; ");
450 // selcom.append("; ribbons; ");
451 System.out.println("Superimpose command(s):\n" + command.toString());
453 evalStateCommand(command.toString());
455 // evalStateCommand("select *; backbone; select "+selcom.toString()+"; cartoons; center "+selcom.toString());
458 public void evalStateCommand(String command)
461 if (lastCommand == null || !lastCommand.equals(command))
463 viewer.evalStringQuiet(command + "\n");
466 lastCommand = command;
470 * colour any structures associated with sequences in the given alignment
471 * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
472 * if colourBySequence is enabled.
474 public void colourBySequence(boolean showFeatures, AlignmentI alignment)
476 if (!colourBySequence)
482 String[] files = getPdbFile();
483 SequenceRenderer sr = getSequenceRenderer();
485 FeatureRenderer fr = null;
488 fr = getFeatureRenderer();
491 StringBuffer command = new StringBuffer();
493 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
495 StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
497 if (mapping == null || mapping.length < 1)
501 for (int s = 0; s < sequence[pdbfnum].length; s++)
503 for (int sp, m = 0; m < mapping.length; m++)
505 if (mapping[m].getSequence() == sequence[pdbfnum][s]
506 && (sp = alignment.findIndex(sequence[pdbfnum][s])) > -1)
508 SequenceI asp = alignment.getSequenceAt(sp);
509 for (int r = 0; r < asp.getLength(); r++)
511 // no mapping to gaps in sequence
512 if (jalview.util.Comparison.isGap(asp.getCharAt(r)))
516 int pos = mapping[m].getPDBResNum(asp.findPosition(r));
518 if (pos < 1 || pos == lastPos)
523 Color col = sr.getResidueBoxColour(sequence[pdbfnum][s], r);
526 col = fr.findFeatureColour(col, sequence[pdbfnum][s], r);
527 String newSelcom = (mapping[m].getChain() != " " ? ":"
528 + mapping[m].getChain() : "")
537 + col.getBlue() + "]";
538 if (command.toString().endsWith(newSelcom))
540 command = condenseCommand(command.toString(), pos);
543 // TODO: deal with case when buffer is too large for Jmol to parse
544 // - execute command and flush
546 command.append(";select " + pos);
547 command.append(newSelcom);
554 evalStateCommand(command.toString());
557 public boolean isColourBySequence()
559 return colourBySequence;
562 public void setColourBySequence(boolean colourBySequence)
564 this.colourBySequence = colourBySequence;
567 StringBuffer condenseCommand(String command, int pos)
570 StringBuffer sb = new StringBuffer(command.substring(0,
571 command.lastIndexOf("select") + 7));
573 command = command.substring(sb.length());
577 if (command.indexOf("-") > -1)
579 start = command.substring(0, command.indexOf("-"));
583 start = command.substring(0, command.indexOf(":"));
586 sb.append(start + "-" + pos + command.substring(command.indexOf(":")));
591 public void createImage(String file, String type, int quality)
593 System.out.println("JMOL CREATE IMAGE");
596 public String createImage(String fileName, String type,
597 Object textOrBytes, int quality)
599 System.out.println("JMOL CREATE IMAGE");
603 public String eval(String strEval)
605 // System.out.println(strEval);
606 // "# 'eval' is implemented only for the applet.";
610 // End StructureListener
611 // //////////////////////////
613 public float[][] functionXY(String functionName, int x, int y)
618 public float[][][] functionXYZ(String functionName, int nx, int ny, int nz)
620 // TODO Auto-generated method stub
624 public Color getColour(int atomIndex, int pdbResNum, String chain,
627 if (getModelNum(pdbfile) < 0)
629 // TODO: verify atomIndex is selecting correct model.
630 return new Color(viewer.getAtomArgb(atomIndex));
634 * returns the current featureRenderer that should be used to colour the
639 public abstract FeatureRenderer getFeatureRenderer();
642 * instruct the Jalview binding to update the pdbentries vector if necessary
643 * prior to matching the jmol view's contents to the list of structure files
644 * Jalview knows about.
646 public abstract void refreshPdbEntries();
648 private int getModelNum(String modelFileName)
650 String[] mfn = getPdbFile();
655 for (int i = 0; i < mfn.length; i++)
657 if (mfn[i].equalsIgnoreCase(modelFileName))
663 // ////////////////////////////////
664 // /StructureListener
665 public String[] getPdbFile()
667 if (modelFileNames == null)
669 String mset[] = new String[viewer.getModelCount()];
670 for (int i = 0; i < mset.length; i++)
672 mset[i] = viewer.getModelFileName(i);
674 modelFileNames = mset;
676 return modelFileNames;
680 * map from string to applet
682 public Map getRegistryInfo()
684 // TODO Auto-generated method stub
689 * returns the current sequenceRenderer that should be used to colour the
694 public abstract SequenceRenderer getSequenceRenderer();
696 // ///////////////////////////////
697 // JmolStatusListener
699 public void handlePopupMenu(int x, int y)
701 jmolpopup.show(x, y);
705 public void highlightAtom(int atomIndex, int pdbResNum, String chain,
708 if (modelFileNames == null)
713 // look up file model number for this pdbfile
716 // may need to adjust for URLencoding here - we don't worry about that yet.
717 while (mdlNum < modelFileNames.length
718 && !pdbfile.equals(modelFileNames[mdlNum]))
720 // System.out.println("nomatch:"+pdbfile+"\nmodelfn:"+fn);
723 if (mdlNum == modelFileNames.length)
729 // if (!pdbfile.equals(pdbentry.getFile()))
731 if (resetLastRes.length() > 0)
733 viewer.evalStringQuiet(resetLastRes.toString());
737 eval.append("select " + pdbResNum); // +modelNum
739 resetLastRes.setLength(0);
740 resetLastRes.append("select " + pdbResNum); // +modelNum
743 resetLastRes.append(":");
744 if (!chain.equals(" "))
747 resetLastRes.append(chain);
750 eval.append(" /" + (mdlNum + 1));
751 resetLastRes.append("/" + (mdlNum + 1));
753 eval.append(";wireframe 100;" + eval.toString() + " and not hetero;");
755 resetLastRes.append(";wireframe 0;" + resetLastRes.toString()
756 + " and not hetero; spacefill 0;");
758 eval.append("spacefill 200;select none");
760 viewer.evalStringQuiet(eval.toString());
765 boolean debug = true;
767 private void jmolHistory(boolean enable)
769 viewer.evalStringQuiet("History " + ((debug || enable) ? "on" : "off"));
772 public void loadInline(String string)
775 viewer.openStringInline(string);
778 public void mouseOverStructure(int atomIndex, String strInfo)
781 int mdlSep = strInfo.indexOf("/");
782 int chainSeparator = strInfo.indexOf(":"), chainSeparator1 = -1;
784 if (chainSeparator == -1)
786 chainSeparator = strInfo.indexOf(".");
787 if (mdlSep > -1 && mdlSep < chainSeparator)
789 chainSeparator1 = chainSeparator;
790 chainSeparator = mdlSep;
793 pdbResNum = Integer.parseInt(strInfo.substring(
794 strInfo.indexOf("]") + 1, chainSeparator));
798 if (strInfo.indexOf(":") > -1)
799 chainId = strInfo.substring(strInfo.indexOf(":") + 1,
800 strInfo.indexOf("."));
806 String pdbfilename = modelFileNames[frameNo]; // default is first or current
810 if (chainSeparator1 == -1)
812 chainSeparator1 = strInfo.indexOf(".", mdlSep);
814 String mdlId = (chainSeparator1 > -1) ? strInfo.substring(mdlSep + 1,
815 chainSeparator1) : strInfo.substring(mdlSep + 1);
818 // recover PDB filename for the model hovered over.
820 .getModelFileName(new Integer(mdlId).intValue() - 1);
821 } catch (Exception e)
826 if (lastMessage == null || !lastMessage.equals(strInfo))
827 ssm.mouseOverStructure(pdbResNum, chainId, pdbfilename);
829 lastMessage = strInfo;
832 public void notifyAtomHovered(int atomIndex, String strInfo, String data)
836 System.err.println("Ignoring additional hover info: " + data
837 + " (other info: '" + strInfo + "' pos " + atomIndex + ")");
839 mouseOverStructure(atomIndex, strInfo);
843 * { if (history != null && strStatus != null &&
844 * !strStatus.equals("Script completed")) { history.append("\n" + strStatus);
848 public void notifyAtomPicked(int atomIndex, String strInfo, String strData)
851 * this implements the toggle label behaviour copied from the original
852 * structure viewer, MCView
856 System.err.println("Ignoring additional pick data string " + strData);
858 int chainSeparator = strInfo.indexOf(":");
860 if (chainSeparator == -1)
861 chainSeparator = strInfo.indexOf(".");
863 String picked = strInfo.substring(strInfo.indexOf("]") + 1,
865 String mdlString = "";
866 if ((p = strInfo.indexOf(":")) > -1)
867 picked += strInfo.substring(p + 1, strInfo.indexOf("."));
869 if ((p = strInfo.indexOf("/")) > -1)
871 mdlString += strInfo.substring(p, strInfo.indexOf(" #"));
873 picked = "((" + picked + ".CA" + mdlString + ")|(" + picked + ".P"
877 if (!atomsPicked.contains(picked))
879 viewer.evalStringQuiet("select " + picked + ";label %n %r:%c");
880 atomsPicked.addElement(picked);
884 viewer.evalString("select " + picked + ";label off");
885 atomsPicked.removeElement(picked);
888 // TODO: in application this happens
890 // if (scriptWindow != null)
892 // scriptWindow.sendConsoleMessage(strInfo);
893 // scriptWindow.sendConsoleMessage("\n");
898 public void notifyCallback(int type, Object[] data)
904 case JmolConstants.CALLBACK_LOADSTRUCT:
905 notifyFileLoaded((String) data[1], (String) data[2],
906 (String) data[3], (String) data[4],
907 ((Integer) data[5]).intValue());
910 case JmolConstants.CALLBACK_PICK:
911 notifyAtomPicked(((Integer) data[2]).intValue(), (String) data[1],
913 // also highlight in alignment
914 case JmolConstants.CALLBACK_HOVER:
915 notifyAtomHovered(((Integer) data[2]).intValue(), (String) data[1],
918 case JmolConstants.CALLBACK_SCRIPT:
919 notifyScriptTermination((String) data[2],
920 ((Integer) data[3]).intValue());
922 case JmolConstants.CALLBACK_ECHO:
923 sendConsoleEcho((String) data[1]);
925 case JmolConstants.CALLBACK_MESSAGE:
926 sendConsoleMessage((data == null) ? ((String) null)
929 case JmolConstants.CALLBACK_ERROR:
930 // System.err.println("Ignoring error callback.");
932 case JmolConstants.CALLBACK_SYNC:
933 case JmolConstants.CALLBACK_RESIZE:
936 case JmolConstants.CALLBACK_MEASURE:
938 case JmolConstants.CALLBACK_CLICK:
941 System.err.println("Unhandled callback " + type + " "
942 + data[1].toString());
945 } catch (Exception e)
947 System.err.println("Squashed Jmol callback handler error:");
952 public boolean notifyEnabled(int callbackPick)
954 switch (callbackPick)
956 case JmolConstants.CALLBACK_ECHO:
957 case JmolConstants.CALLBACK_LOADSTRUCT:
958 case JmolConstants.CALLBACK_MEASURE:
959 case JmolConstants.CALLBACK_MESSAGE:
960 case JmolConstants.CALLBACK_PICK:
961 case JmolConstants.CALLBACK_SCRIPT:
962 case JmolConstants.CALLBACK_HOVER:
963 case JmolConstants.CALLBACK_ERROR:
965 case JmolConstants.CALLBACK_RESIZE:
966 case JmolConstants.CALLBACK_SYNC:
967 case JmolConstants.CALLBACK_CLICK:
968 case JmolConstants.CALLBACK_ANIMFRAME:
969 case JmolConstants.CALLBACK_MINIMIZATION:
974 public void notifyFileLoaded(String fullPathName, String fileName2,
975 String modelName, String errorMsg, int modelParts)
977 if (errorMsg != null)
979 fileLoadingError = errorMsg;
983 // the rest of this routine ignores the arguments, and simply interrogates
984 // the Jmol view to find out what structures it contains, and adds them to
985 // the structure selection manager.
986 fileLoadingError = null;
987 String[] oldmodels = modelFileNames;
988 modelFileNames = null;
989 chainNames = new Vector();
990 boolean notifyLoaded = false;
991 String[] modelfilenames = getPdbFile();
992 ssm = StructureSelectionManager.getStructureSelectionManager();
993 // first check if we've lost any structures
994 if (oldmodels != null && oldmodels.length > 0)
997 for (int i = 0; i < oldmodels.length; i++)
999 for (int n = 0; n < modelfilenames.length; n++)
1001 if (modelfilenames[n] == oldmodels[i])
1003 oldmodels[i] = null;
1007 if (oldmodels[i] != null)
1014 String[] oldmfn = new String[oldm];
1016 for (int i = 0; i < oldmodels.length; i++)
1018 if (oldmodels[i] != null)
1020 oldmfn[oldm++] = oldmodels[i];
1023 // deregister the Jmol instance for these structures - we'll add
1024 // ourselves again at the end for the current structure set.
1025 ssm.removeStructureViewerListener(this, oldmfn);
1028 refreshPdbEntries();
1029 for (int modelnum = 0; modelnum < modelfilenames.length; modelnum++)
1031 String fileName = modelfilenames[modelnum];
1032 if (fileName != null)
1034 boolean foundEntry = false;
1035 // search pdbentries and sequences to find correct pdbentry and
1036 // sequence[] pair for this filename
1037 if (pdbentry != null)
1039 for (int pe = 0; pe < pdbentry.length; pe++)
1041 if (pdbentry[pe].getFile().equals(fileName))
1047 // TODO: replace with getData ?
1048 pdb = ssm.setMapping(sequence[pe], chains[pe],
1049 pdbentry[pe].getFile(), AppletFormatAdapter.PASTE);
1050 pdbentry[pe].setFile("INLINE" + pdb.id);
1054 // TODO: Jmol can in principle retrieve from CLASSLOADER but
1057 // to be tested. See mantis bug
1058 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
1059 String protocol = AppletFormatAdapter.URL;
1062 File fl = new java.io.File(pdbentry[pe].getFile());
1065 protocol = AppletFormatAdapter.FILE;
1067 } catch (Exception e)
1073 pdb = ssm.setMapping(sequence[pe], chains[pe],
1074 pdbentry[pe].getFile(), protocol);
1078 pdbentry[pe].setId(pdb.id);
1080 for (int i = 0; i < pdb.chains.size(); i++)
1082 chainNames.addElement(new String(pdb.id + ":"
1083 + ((MCview.PDBChain) pdb.chains.elementAt(i)).id));
1085 notifyLoaded = true;
1089 if (!foundEntry && associateNewStructs)
1091 // this is a foreign pdb file that jalview doesn't know about - add
1092 // it to the dataset and try to find a home - either on a matching
1093 // sequence or as a new sequence.
1094 String pdbcontent = viewer.getData("/" + (modelnum + 1) + ".1",
1096 // parse pdb file into a chain, etc.
1097 // locate best match for pdb in associated views and add mapping to
1099 // if properly registered then
1100 notifyLoaded = true;
1106 // so finally, update the jmol bits and pieces
1107 if (jmolpopup != null)
1109 jmolpopup.updateComputedMenus();
1111 if (!isLoadingFromArchive())
1113 viewer.evalStringQuiet("model 0; select backbone;restrict;cartoon;wireframe off;spacefill off");
1115 setLoadingFromArchive(false);
1116 // register ourselves as a listener and notify the gui that it needs to
1118 ssm.addStructureViewerListener(this);
1121 FeatureRenderer fr = getFeatureRenderer();
1130 public void notifyNewPickingModeMeasurement(int iatom, String strMeasure)
1132 notifyAtomPicked(iatom, strMeasure, null);
1135 public abstract void notifyScriptTermination(String strStatus,
1139 * display a message echoed from the jmol viewer
1143 public abstract void sendConsoleEcho(String strEcho); /*
1144 * { showConsole(true);
1146 * history.append("\n" +
1150 // /End JmolStatusListener
1151 // /////////////////////////////
1155 * status message - usually the response received after a script
1158 public abstract void sendConsoleMessage(String strStatus);
1160 public void setCallbackFunction(String callbackType,
1161 String callbackFunction)
1163 System.err.println("Ignoring set-callback request to associate "
1164 + callbackType + " with function " + callbackFunction);
1168 public void setJalviewColourScheme(ColourSchemeI cs)
1170 colourBySequence = false;
1179 // TODO: Switch between nucleotide or aa selection expressions
1180 Enumeration en = ResidueProperties.aa3Hash.keys();
1181 StringBuffer command = new StringBuffer("select *;color white;");
1182 while (en.hasMoreElements())
1184 res = en.nextElement().toString();
1185 index = ((Integer) ResidueProperties.aa3Hash.get(res)).intValue();
1189 col = cs.findColour(ResidueProperties.aa[index].charAt(0));
1191 command.append("select " + res + ";color[" + col.getRed() + ","
1192 + col.getGreen() + "," + col.getBlue() + "];");
1195 evalStateCommand(command.toString());
1199 public void showHelp()
1201 showUrl("http://jmol.sourceforge.net/docs/JmolUserGuide/", "jmolHelp");
1205 * open the URL somehow
1209 public abstract void showUrl(String url, String target);
1212 * called when the binding thinks the UI needs to be refreshed after a Jmol
1213 * state change. this could be because structures were loaded, or because an
1214 * error has occured.
1216 public abstract void refreshGUI();
1219 * @param renderPanel
1221 * - when true will initialise jmol's file IO system (should be false
1222 * in applet context)
1224 * @param documentBase
1226 * @param commandOptions
1228 public void allocateViewer(Component renderPanel, boolean jmolfileio,
1229 String htmlName, URL documentBase, URL codeBase,
1230 String commandOptions)
1232 viewer = JmolViewer.allocateViewer(renderPanel,
1233 (jmolfileio ? new SmarterJmolAdapter() : null), htmlName
1234 + ((Object) this).toString(), documentBase, codeBase,
1235 commandOptions, this);
1238 public void setLoadingFromArchive(boolean loadingFromArchive)
1240 this.loadingFromArchive = loadingFromArchive;
1243 public boolean isLoadingFromArchive()
1245 return loadingFromArchive;
1248 public void setBackgroundColour(java.awt.Color col)
1251 viewer.evalStringQuiet("background [" + col.getRed() + ","
1252 + col.getGreen() + "," + col.getBlue() + "];");