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 StringBuffer selcom[] = new StringBuffer[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 = (selcom[pdbfnum] = 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 selectioncom.append("((");
415 selectioncom.append(molsel.subSequence(1, molsel.length()-1));
416 selectioncom.append(" )& ");
417 selectioncom.append(pdbfnum+1);
418 selectioncom.append(".1)");
419 if (pdbfnum<files.length-1)
421 selectioncom.append("|");
426 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
428 if (pdbfnum == refStructure)
432 command.append("compare ");
434 command.append(1 + pdbfnum);
435 command.append(".1} {");
436 command.append(1 + refStructure);
437 command.append(".1} SUBSET {*.CA | *.P} ATOMS ");
439 // form the matched pair strings
441 for (int s = 0; s < 2; s++)
443 command.append(selcom[(s == 0 ? pdbfnum : refStructure)]);
445 command.append(" ROTATE TRANSLATE;\n");
447 System.out.println("Select regions:\n" + selectioncom.toString());
448 evalStateCommand("select *; cartoons off; backbone; select ("+selectioncom.toString()+"); cartoons; ");
449 // selcom.append("; ribbons; ");
450 System.out.println("Superimpose command(s):\n" + command.toString());
452 evalStateCommand(command.toString());
454 // evalStateCommand("select *; backbone; select "+selcom.toString()+"; cartoons; center "+selcom.toString());
457 public void evalStateCommand(String command)
460 if (lastCommand == null || !lastCommand.equals(command))
462 viewer.evalStringQuiet(command + "\n");
465 lastCommand = command;
469 * colour any structures associated with sequences in the given alignment
470 * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
471 * if colourBySequence is enabled.
473 public void colourBySequence(boolean showFeatures, AlignmentI alignment)
475 if (!colourBySequence)
481 String[] files = getPdbFile();
482 SequenceRenderer sr = getSequenceRenderer();
484 FeatureRenderer fr = null;
487 fr = getFeatureRenderer();
490 StringBuffer command = new StringBuffer();
492 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
494 StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
496 if (mapping == null || mapping.length < 1)
500 for (int s = 0; s < sequence[pdbfnum].length; s++)
502 for (int sp, m = 0; m < mapping.length; m++)
504 if (mapping[m].getSequence() == sequence[pdbfnum][s]
505 && (sp = alignment.findIndex(sequence[pdbfnum][s])) > -1)
507 SequenceI asp = alignment.getSequenceAt(sp);
508 for (int r = 0; r < asp.getLength(); r++)
510 // no mapping to gaps in sequence
511 if (jalview.util.Comparison.isGap(asp.getCharAt(r)))
515 int pos = mapping[m].getPDBResNum(asp.findPosition(r));
517 if (pos < 1 || pos == lastPos)
522 Color col = sr.getResidueBoxColour(sequence[pdbfnum][s], r);
525 col = fr.findFeatureColour(col, sequence[pdbfnum][s], r);
526 String newSelcom = (mapping[m].getChain() != " " ? ":"
527 + mapping[m].getChain() : "")
536 + col.getBlue() + "]";
537 if (command.toString().endsWith(newSelcom))
539 command = condenseCommand(command.toString(), pos);
542 // TODO: deal with case when buffer is too large for Jmol to parse
543 // - execute command and flush
545 command.append(";select " + pos);
546 command.append(newSelcom);
553 evalStateCommand(command.toString());
556 public boolean isColourBySequence()
558 return colourBySequence;
561 public void setColourBySequence(boolean colourBySequence)
563 this.colourBySequence = colourBySequence;
566 StringBuffer condenseCommand(String command, int pos)
569 StringBuffer sb = new StringBuffer(command.substring(0,
570 command.lastIndexOf("select") + 7));
572 command = command.substring(sb.length());
576 if (command.indexOf("-") > -1)
578 start = command.substring(0, command.indexOf("-"));
582 start = command.substring(0, command.indexOf(":"));
585 sb.append(start + "-" + pos + command.substring(command.indexOf(":")));
590 public void createImage(String file, String type, int quality)
592 System.out.println("JMOL CREATE IMAGE");
595 public String createImage(String fileName, String type,
596 Object textOrBytes, int quality)
598 System.out.println("JMOL CREATE IMAGE");
602 public String eval(String strEval)
604 // System.out.println(strEval);
605 // "# 'eval' is implemented only for the applet.";
609 // End StructureListener
610 // //////////////////////////
612 public float[][] functionXY(String functionName, int x, int y)
617 public float[][][] functionXYZ(String functionName, int nx, int ny, int nz)
619 // TODO Auto-generated method stub
623 public Color getColour(int atomIndex, int pdbResNum, String chain,
626 if (getModelNum(pdbfile) < 0)
628 // TODO: verify atomIndex is selecting correct model.
629 return new Color(viewer.getAtomArgb(atomIndex));
633 * returns the current featureRenderer that should be used to colour the
638 public abstract FeatureRenderer getFeatureRenderer();
641 * instruct the Jalview binding to update the pdbentries vector if necessary
642 * prior to matching the jmol view's contents to the list of structure files
643 * Jalview knows about.
645 public abstract void refreshPdbEntries();
647 private int getModelNum(String modelFileName)
649 String[] mfn = getPdbFile();
654 for (int i = 0; i < mfn.length; i++)
656 if (mfn[i].equalsIgnoreCase(modelFileName))
662 // ////////////////////////////////
663 // /StructureListener
664 public String[] getPdbFile()
666 if (modelFileNames == null)
668 String mset[] = new String[viewer.getModelCount()];
669 for (int i = 0; i < mset.length; i++)
671 mset[i] = viewer.getModelFileName(i);
673 modelFileNames = mset;
675 return modelFileNames;
679 * map from string to applet
681 public Map getRegistryInfo()
683 // TODO Auto-generated method stub
688 * returns the current sequenceRenderer that should be used to colour the
693 public abstract SequenceRenderer getSequenceRenderer();
695 // ///////////////////////////////
696 // JmolStatusListener
698 public void handlePopupMenu(int x, int y)
700 jmolpopup.show(x, y);
704 public void highlightAtom(int atomIndex, int pdbResNum, String chain,
707 if (modelFileNames == null)
712 // look up file model number for this pdbfile
715 // may need to adjust for URLencoding here - we don't worry about that yet.
716 while (mdlNum < modelFileNames.length
717 && !pdbfile.equals(modelFileNames[mdlNum]))
719 // System.out.println("nomatch:"+pdbfile+"\nmodelfn:"+fn);
722 if (mdlNum == modelFileNames.length)
728 // if (!pdbfile.equals(pdbentry.getFile()))
730 if (resetLastRes.length() > 0)
732 viewer.evalStringQuiet(resetLastRes.toString());
736 eval.append("select " + pdbResNum); // +modelNum
738 resetLastRes.setLength(0);
739 resetLastRes.append("select " + pdbResNum); // +modelNum
742 resetLastRes.append(":");
743 if (!chain.equals(" "))
746 resetLastRes.append(chain);
749 eval.append(" /" + (mdlNum + 1));
750 resetLastRes.append("/" + (mdlNum + 1));
752 eval.append(";wireframe 100;" + eval.toString() + " and not hetero;");
754 resetLastRes.append(";wireframe 0;" + resetLastRes.toString()
755 + " and not hetero; spacefill 0;");
757 eval.append("spacefill 200;select none");
759 viewer.evalStringQuiet(eval.toString());
764 boolean debug = true;
766 private void jmolHistory(boolean enable)
768 viewer.evalStringQuiet("History " + ((debug || enable) ? "on" : "off"));
771 public void loadInline(String string)
774 viewer.openStringInline(string);
777 public void mouseOverStructure(int atomIndex, String strInfo)
780 int mdlSep = strInfo.indexOf("/");
781 int chainSeparator = strInfo.indexOf(":"), chainSeparator1 = -1;
783 if (chainSeparator == -1)
785 chainSeparator = strInfo.indexOf(".");
786 if (mdlSep > -1 && mdlSep < chainSeparator)
788 chainSeparator1 = chainSeparator;
789 chainSeparator = mdlSep;
792 pdbResNum = Integer.parseInt(strInfo.substring(
793 strInfo.indexOf("]") + 1, chainSeparator));
797 if (strInfo.indexOf(":") > -1)
798 chainId = strInfo.substring(strInfo.indexOf(":") + 1,
799 strInfo.indexOf("."));
805 String pdbfilename = modelFileNames[frameNo]; // default is first or current
809 if (chainSeparator1 == -1)
811 chainSeparator1 = strInfo.indexOf(".", mdlSep);
813 String mdlId = (chainSeparator1 > -1) ? strInfo.substring(mdlSep + 1,
814 chainSeparator1) : strInfo.substring(mdlSep + 1);
817 // recover PDB filename for the model hovered over.
819 .getModelFileName(new Integer(mdlId).intValue() - 1);
820 } catch (Exception e)
825 if (lastMessage == null || !lastMessage.equals(strInfo))
826 ssm.mouseOverStructure(pdbResNum, chainId, pdbfilename);
828 lastMessage = strInfo;
831 public void notifyAtomHovered(int atomIndex, String strInfo, String data)
835 System.err.println("Ignoring additional hover info: " + data
836 + " (other info: '" + strInfo + "' pos " + atomIndex + ")");
838 mouseOverStructure(atomIndex, strInfo);
842 * { if (history != null && strStatus != null &&
843 * !strStatus.equals("Script completed")) { history.append("\n" + strStatus);
847 public void notifyAtomPicked(int atomIndex, String strInfo, String strData)
850 * this implements the toggle label behaviour copied from the original
851 * structure viewer, MCView
855 System.err.println("Ignoring additional pick data string " + strData);
857 int chainSeparator = strInfo.indexOf(":");
859 if (chainSeparator == -1)
860 chainSeparator = strInfo.indexOf(".");
862 String picked = strInfo.substring(strInfo.indexOf("]") + 1,
864 String mdlString = "";
865 if ((p = strInfo.indexOf(":")) > -1)
866 picked += strInfo.substring(p + 1, strInfo.indexOf("."));
868 if ((p = strInfo.indexOf("/")) > -1)
870 mdlString += strInfo.substring(p, strInfo.indexOf(" #"));
872 picked = "((" + picked + ".CA" + mdlString + ")|(" + picked + ".P"
876 if (!atomsPicked.contains(picked))
878 viewer.evalStringQuiet("select " + picked + ";label %n %r:%c");
879 atomsPicked.addElement(picked);
883 viewer.evalString("select " + picked + ";label off");
884 atomsPicked.removeElement(picked);
887 // TODO: in application this happens
889 // if (scriptWindow != null)
891 // scriptWindow.sendConsoleMessage(strInfo);
892 // scriptWindow.sendConsoleMessage("\n");
897 public void notifyCallback(int type, Object[] data)
903 case JmolConstants.CALLBACK_LOADSTRUCT:
904 notifyFileLoaded((String) data[1], (String) data[2],
905 (String) data[3], (String) data[4],
906 ((Integer) data[5]).intValue());
909 case JmolConstants.CALLBACK_PICK:
910 notifyAtomPicked(((Integer) data[2]).intValue(), (String) data[1],
912 // also highlight in alignment
913 case JmolConstants.CALLBACK_HOVER:
914 notifyAtomHovered(((Integer) data[2]).intValue(), (String) data[1],
917 case JmolConstants.CALLBACK_SCRIPT:
918 notifyScriptTermination((String) data[2],
919 ((Integer) data[3]).intValue());
921 case JmolConstants.CALLBACK_ECHO:
922 sendConsoleEcho((String) data[1]);
924 case JmolConstants.CALLBACK_MESSAGE:
925 sendConsoleMessage((data == null) ? ((String) null)
928 case JmolConstants.CALLBACK_ERROR:
929 // System.err.println("Ignoring error callback.");
931 case JmolConstants.CALLBACK_SYNC:
932 case JmolConstants.CALLBACK_RESIZE:
935 case JmolConstants.CALLBACK_MEASURE:
937 case JmolConstants.CALLBACK_CLICK:
940 System.err.println("Unhandled callback " + type + " "
941 + data[1].toString());
944 } catch (Exception e)
946 System.err.println("Squashed Jmol callback handler error:");
951 public boolean notifyEnabled(int callbackPick)
953 switch (callbackPick)
955 case JmolConstants.CALLBACK_ECHO:
956 case JmolConstants.CALLBACK_LOADSTRUCT:
957 case JmolConstants.CALLBACK_MEASURE:
958 case JmolConstants.CALLBACK_MESSAGE:
959 case JmolConstants.CALLBACK_PICK:
960 case JmolConstants.CALLBACK_SCRIPT:
961 case JmolConstants.CALLBACK_HOVER:
962 case JmolConstants.CALLBACK_ERROR:
964 case JmolConstants.CALLBACK_RESIZE:
965 case JmolConstants.CALLBACK_SYNC:
966 case JmolConstants.CALLBACK_CLICK:
967 case JmolConstants.CALLBACK_ANIMFRAME:
968 case JmolConstants.CALLBACK_MINIMIZATION:
973 public void notifyFileLoaded(String fullPathName, String fileName2,
974 String modelName, String errorMsg, int modelParts)
976 if (errorMsg != null)
978 fileLoadingError = errorMsg;
982 // the rest of this routine ignores the arguments, and simply interrogates
983 // the Jmol view to find out what structures it contains, and adds them to
984 // the structure selection manager.
985 fileLoadingError = null;
986 String[] oldmodels = modelFileNames;
987 modelFileNames = null;
988 chainNames = new Vector();
989 boolean notifyLoaded = false;
990 String[] modelfilenames = getPdbFile();
991 ssm = StructureSelectionManager.getStructureSelectionManager();
992 // first check if we've lost any structures
993 if (oldmodels != null && oldmodels.length > 0)
996 for (int i = 0; i < oldmodels.length; i++)
998 for (int n = 0; n < modelfilenames.length; n++)
1000 if (modelfilenames[n] == oldmodels[i])
1002 oldmodels[i] = null;
1006 if (oldmodels[i] != null)
1013 String[] oldmfn = new String[oldm];
1015 for (int i = 0; i < oldmodels.length; i++)
1017 if (oldmodels[i] != null)
1019 oldmfn[oldm++] = oldmodels[i];
1022 // deregister the Jmol instance for these structures - we'll add
1023 // ourselves again at the end for the current structure set.
1024 ssm.removeStructureViewerListener(this, oldmfn);
1027 refreshPdbEntries();
1028 for (int modelnum = 0; modelnum < modelfilenames.length; modelnum++)
1030 String fileName = modelfilenames[modelnum];
1031 if (fileName != null)
1033 boolean foundEntry = false;
1034 // search pdbentries and sequences to find correct pdbentry and
1035 // sequence[] pair for this filename
1036 if (pdbentry != null)
1038 for (int pe = 0; pe < pdbentry.length; pe++)
1040 if (pdbentry[pe].getFile().equals(fileName))
1046 // TODO: replace with getData ?
1047 pdb = ssm.setMapping(sequence[pe], chains[pe],
1048 pdbentry[pe].getFile(), AppletFormatAdapter.PASTE);
1049 pdbentry[pe].setFile("INLINE" + pdb.id);
1053 // TODO: Jmol can in principle retrieve from CLASSLOADER but
1056 // to be tested. See mantis bug
1057 // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
1058 String protocol = AppletFormatAdapter.URL;
1061 File fl = new java.io.File(pdbentry[pe].getFile());
1064 protocol = AppletFormatAdapter.FILE;
1066 } catch (Exception e)
1072 pdb = ssm.setMapping(sequence[pe], chains[pe],
1073 pdbentry[pe].getFile(), protocol);
1077 pdbentry[pe].setId(pdb.id);
1079 for (int i = 0; i < pdb.chains.size(); i++)
1081 chainNames.addElement(new String(pdb.id + ":"
1082 + ((MCview.PDBChain) pdb.chains.elementAt(i)).id));
1084 notifyLoaded = true;
1088 if (!foundEntry && associateNewStructs)
1090 // this is a foreign pdb file that jalview doesn't know about - add
1091 // it to the dataset and try to find a home - either on a matching
1092 // sequence or as a new sequence.
1093 String pdbcontent = viewer.getData("/" + (modelnum + 1) + ".1",
1095 // parse pdb file into a chain, etc.
1096 // locate best match for pdb in associated views and add mapping to
1098 // if properly registered then
1099 notifyLoaded = true;
1105 // so finally, update the jmol bits and pieces
1106 if (jmolpopup != null)
1108 jmolpopup.updateComputedMenus();
1110 if (!isLoadingFromArchive())
1112 viewer.evalStringQuiet("model 0; select backbone;restrict;cartoon;wireframe off;spacefill off");
1114 setLoadingFromArchive(false);
1115 // register ourselves as a listener and notify the gui that it needs to
1117 ssm.addStructureViewerListener(this);
1120 FeatureRenderer fr = getFeatureRenderer();
1129 public void notifyNewPickingModeMeasurement(int iatom, String strMeasure)
1131 notifyAtomPicked(iatom, strMeasure, null);
1134 public abstract void notifyScriptTermination(String strStatus,
1138 * display a message echoed from the jmol viewer
1142 public abstract void sendConsoleEcho(String strEcho); /*
1143 * { showConsole(true);
1145 * history.append("\n" +
1149 // /End JmolStatusListener
1150 // /////////////////////////////
1154 * status message - usually the response received after a script
1157 public abstract void sendConsoleMessage(String strStatus);
1159 public void setCallbackFunction(String callbackType,
1160 String callbackFunction)
1162 System.err.println("Ignoring set-callback request to associate "
1163 + callbackType + " with function " + callbackFunction);
1167 public void setJalviewColourScheme(ColourSchemeI cs)
1169 colourBySequence = false;
1178 // TODO: Switch between nucleotide or aa selection expressions
1179 Enumeration en = ResidueProperties.aa3Hash.keys();
1180 StringBuffer command = new StringBuffer("select *;color white;");
1181 while (en.hasMoreElements())
1183 res = en.nextElement().toString();
1184 index = ((Integer) ResidueProperties.aa3Hash.get(res)).intValue();
1188 col = cs.findColour(ResidueProperties.aa[index].charAt(0));
1190 command.append("select " + res + ";color[" + col.getRed() + ","
1191 + col.getGreen() + "," + col.getBlue() + "];");
1194 evalStateCommand(command.toString());
1198 public void showHelp()
1200 showUrl("http://jmol.sourceforge.net/docs/JmolUserGuide/", "jmolHelp");
1204 * open the URL somehow
1208 public abstract void showUrl(String url, String target);
1211 * called when the binding thinks the UI needs to be refreshed after a Jmol
1212 * state change. this could be because structures were loaded, or because an
1213 * error has occured.
1215 public abstract void refreshGUI();
1218 * @param renderPanel
1220 * - when true will initialise jmol's file IO system (should be false
1221 * in applet context)
1223 * @param documentBase
1225 * @param commandOptions
1227 public void allocateViewer(Component renderPanel, boolean jmolfileio,
1228 String htmlName, URL documentBase, URL codeBase,
1229 String commandOptions)
1231 viewer = JmolViewer.allocateViewer(renderPanel,
1232 (jmolfileio ? new SmarterJmolAdapter() : null), htmlName
1233 + ((Object) this).toString(), documentBase, codeBase,
1234 commandOptions, this);
1237 public void setLoadingFromArchive(boolean loadingFromArchive)
1239 this.loadingFromArchive = loadingFromArchive;
1242 public boolean isLoadingFromArchive()
1244 return loadingFromArchive;
1247 public void setBackgroundColour(java.awt.Color col)
1250 viewer.evalStringQuiet("background [" + col.getRed() + ","
1251 + col.getGreen() + "," + col.getBlue() + "];");