2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.rbvi.chimera;
23 import static org.junit.Assert.assertTrue;
24 import jalview.api.AlignmentViewPanel;
25 import jalview.api.FeatureRenderer;
26 import jalview.api.SequenceRenderer;
27 import jalview.api.SequenceStructureBinding;
28 import jalview.api.StructureSelectionManagerProvider;
29 import jalview.datamodel.AlignmentI;
30 import jalview.datamodel.ColumnSelection;
31 import jalview.datamodel.PDBEntry;
32 import jalview.datamodel.SequenceI;
33 import jalview.io.AppletFormatAdapter;
34 import jalview.schemes.ColourSchemeI;
35 import jalview.schemes.ResidueProperties;
36 import jalview.structure.StructureListener;
37 import jalview.structure.StructureMapping;
38 import jalview.structure.StructureSelectionManager;
39 import jalview.structures.models.SequenceStructureBindingModel;
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.Collection;
50 import java.util.Enumeration;
51 import java.util.HashMap;
52 import java.util.Hashtable;
53 import java.util.List;
55 import java.util.Vector;
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.constant.EnumCallback;
63 import org.jmol.popup.JmolPopup;
65 import ext.edu.ucsf.rbvi.strucviz2.ChimeraManager;
66 import ext.edu.ucsf.rbvi.strucviz2.ChimeraModel;
67 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
68 import ext.edu.ucsf.rbvi.strucviz2.StructureManager.ModelType;
69 import sun.rmi.runtime.Log;
71 public abstract class JalviewChimeraBinding extends
72 SequenceStructureBindingModel implements StructureListener,
73 SequenceStructureBinding, StructureSelectionManagerProvider
76 private StructureManager csm;
78 private ChimeraManager viewer;
81 * set if chimera state is being restored from some source - instructs binding
82 * not to apply default display style when structure set is updated for first
85 private boolean loadingFromArchive = false;
88 * second flag to indicate if the jmol viewer should ignore sequence colouring
89 * events from the structure manager because the GUI is still setting up
91 private boolean loadingFinished = true;
94 * state flag used to check if the Jmol viewer's paint method can be called
96 private boolean finishedInit = false;
98 public boolean isFinishedInit()
103 public void setFinishedInit(boolean finishedInit)
105 this.finishedInit = finishedInit;
108 boolean allChainsSelected = false;
111 * when true, try to search the associated datamodel for sequences that are
112 * associated with any unknown structures in the Jmol view.
114 private boolean associateNewStructs = false;
116 Vector atomsPicked = new Vector();
118 public Vector chainNames;
123 * array of target chains for seuqences - tied to pdbentry and sequence[]
125 protected String[][] chains;
127 boolean colourBySequence = true;
129 StringBuffer eval = new StringBuffer();
131 public String fileLoadingError;
133 private Map<String, List<ChimeraModel>> chimmaps = new HashMap<String, List<ChimeraModel>>();
135 private List<String> mdlToFile = new ArrayList<String>();
138 * the default or current model displayed if the model cannot be identified
139 * from the selection message
147 boolean loadedInline;
149 public boolean openFile(PDBEntry pe)
151 String file = pe.getFile();
154 List<ChimeraModel> oldList = viewer.getModelList();
155 viewer.openModel(file, ModelType.PDB_MODEL);
156 List<ChimeraModel> newList = viewer.getModelList();
157 if (oldList.size() < newList.size())
159 while (oldList.size() > 0)
164 chimmaps.put(file, newList);
165 for (ChimeraModel cm : newList)
167 while (mdlToFile.size()<1+cm.getModelNumber())
169 mdlToFile.add(new String(""));
171 mdlToFile.set(cm.getModelNumber(), file);
174 File fl = new File(file);
175 String protocol = AppletFormatAdapter.URL;
180 protocol = AppletFormatAdapter.FILE;
182 } catch (Exception e)
187 // Explicitly map to the filename used by Jmol ;
188 // pdbentry[pe].getFile(), protocol);
192 ssm.addStructureViewerListener(this);
193 // ssm.addSelectionListener(this);
194 FeatureRenderer fr = getFeatureRenderer(null);
203 } catch (Exception q)
205 log("Exception when trying to open model " + file + "\n"
213 * current set of model filenames loaded
215 String[] modelFileNames = null;
217 public PDBEntry[] pdbentry;
220 * datasource protocol for access to PDBEntrylatest
222 String protocol = null;
224 StringBuffer resetLastRes = new StringBuffer();
227 * sequences mapped to each pdbentry
229 public SequenceI[][] sequence;
231 public StructureSelectionManager ssm;
233 private List<String> lastReply;
235 public JalviewChimeraBinding(StructureSelectionManager ssm,
236 PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains,
240 this.sequence = sequenceIs;
241 this.chains = chains;
242 this.pdbentry = pdbentry;
243 this.protocol = protocol;
246 this.chains = new String[pdbentry.length][];
248 viewer = new ChimeraManager(
249 csm = new ext.edu.ucsf.rbvi.strucviz2.StructureManager(true));
251 * viewer = JmolViewer.allocateViewer(renderPanel, new SmarterJmolAdapter(),
252 * "jalviewJmol", ap.av.applet .getDocumentBase(),
253 * ap.av.applet.getCodeBase(), "", this);
255 * jmolpopup = JmolPopup.newJmolPopup(viewer, true, "Jmol", true);
259 public JalviewChimeraBinding(StructureSelectionManager ssm,
260 ChimeraManager viewer2)
264 csm = viewer.getStructureManager();
268 * construct a title string for the viewer window based on the data jalview
273 public String getViewerTitle()
275 if (sequence == null || pdbentry == null || sequence.length < 1
276 || pdbentry.length < 1 || sequence[0].length < 1)
278 return ("Jalview Chimera Window");
280 // TODO: give a more informative title when multiple structures are
282 StringBuffer title = new StringBuffer("Chimera view for "
283 + sequence[0][0].getName() + ":" + pdbentry[0].getId());
285 if (pdbentry[0].getProperty() != null)
287 if (pdbentry[0].getProperty().get("method") != null)
289 title.append(" Method: ");
290 title.append(pdbentry[0].getProperty().get("method"));
292 if (pdbentry[0].getProperty().get("chains") != null)
294 title.append(" Chain:");
295 title.append(pdbentry[0].getProperty().get("chains"));
298 return title.toString();
302 * prepare the view for a given set of models/chains. chainList contains
303 * strings of the form 'pdbfilename:Chaincode'
306 * list of chains to make visible
308 public void centerViewer(Vector chainList)
310 StringBuffer cmd = new StringBuffer();
313 for (int i = 0, iSize = chainList.size(); i < iSize; i++)
316 lbl = (String) chainList.elementAt(i);
320 mlength = lbl.indexOf(":", p);
321 } while (p < mlength && mlength < (lbl.length() - 2));
322 // TODO: lookup each pdb id and recover proper model number for it.
323 cmd.append("#" + getModelNum((String) chainFile.get(lbl)) + "."
324 + lbl.substring(mlength + 1) + " or ");
326 if (cmd.length() > 0)
327 cmd.setLength(cmd.length() - 4);
328 evalStateCommand("~display #*; ~ribbon #*; ribbon " + cmd + ";focus "
332 public void closeViewer()
334 ssm.removeStructureViewerListener(this, this.getPdbFile());
335 // and shut down Chimera
336 viewer.exitChimera();
337 // viewer.evalStringQuiet("zap");
338 // viewer.setJmolStatusListener(null);
341 releaseUIResources();
345 * called by JalviewJmolbinding after closeViewer is called - release any
346 * resources and references so they can be garbage collected.
348 protected abstract void releaseUIResources();
350 public void colourByChain()
352 colourBySequence = false;
353 // TODO: colour by chain should colour each chain distinctly across all
355 // TODO: http://issues.jalview.org/browse/JAL-628
356 evalStateCommand("select *;color chain");
359 public void colourByCharge()
361 colourBySequence = false;
362 evalStateCommand("colour *;color white;select ASP,GLU;color red;"
363 + "select LYS,ARG;color blue;select CYS;color yellow");
367 * superpose the structures associated with sequences in the alignment
368 * according to their corresponding positions.
370 public void superposeStructures(AlignmentI alignment)
372 superposeStructures(alignment, -1, null);
376 * superpose the structures associated with sequences in the alignment
377 * according to their corresponding positions. ded)
379 * @param refStructure
380 * - select which pdb file to use as reference (default is -1 - the
381 * first structure in the alignment)
383 public void superposeStructures(AlignmentI alignment, int refStructure)
385 superposeStructures(alignment, refStructure, null);
389 * superpose the structures associated with sequences in the alignment
390 * according to their corresponding positions. ded)
392 * @param refStructure
393 * - select which pdb file to use as reference (default is -1 - the
394 * first structure in the alignment)
398 public void superposeStructures(AlignmentI alignment, int refStructure,
399 ColumnSelection hiddenCols)
401 superposeStructures(new AlignmentI[]
402 { alignment }, new int[]
403 { refStructure }, new ColumnSelection[]
407 public void superposeStructures(AlignmentI[] _alignment,
408 int[] _refStructure, ColumnSelection[] _hiddenCols)
410 assert (_alignment.length == _refStructure.length && _alignment.length != _hiddenCols.length);
412 String[] files = getPdbFile();
413 // check to see if we are still waiting for Jmol files
414 long starttime = System.currentTimeMillis();
415 boolean waiting = true;
419 for (String file : files)
423 // HACK - in Jalview 2.8 this call may not be threadsafe so we catch
424 // every possible exception
425 StructureMapping[] sm = ssm.getMapping(file);
426 if (sm == null || sm.length == 0)
430 } catch (Exception x)
438 // we wait around for a reasonable time before we give up
440 && System.currentTimeMillis() < (10000 + 1000 * files.length + starttime));
444 .println("RUNTIME PROBLEM: Jmol seems to be taking a long time to process all the structures.");
447 StringBuffer selectioncom = new StringBuffer();
448 // In principle - nSeconds specifies the speed of animation for each
449 // superposition - but is seems to behave weirdly, so we don't specify it.
450 String nSeconds = " ";
451 if (files.length > 10)
453 nSeconds = " 0.00001 ";
457 nSeconds = " " + (2.0 / files.length) + " ";
458 // if (nSeconds).substring(0,5)+" ";
460 // see JAL-1345 - should really automatically turn off the animation for
461 // large numbers of structures, but Jmol doesn't seem to allow that.
463 // union of all aligned positions are collected together.
464 for (int a = 0; a < _alignment.length; a++)
466 int refStructure = _refStructure[a];
467 AlignmentI alignment = _alignment[a];
468 ColumnSelection hiddenCols = _hiddenCols[a];
470 && selectioncom.length() > 0
471 && !selectioncom.substring(selectioncom.length() - 1).equals(
474 selectioncom.append("|");
476 // process this alignment
477 if (refStructure >= files.length)
479 System.err.println("Invalid reference structure value "
483 if (refStructure < -1)
487 StringBuffer command = new StringBuffer();
489 boolean matched[] = new boolean[alignment.getWidth()];
490 for (int m = 0; m < matched.length; m++)
493 matched[m] = (hiddenCols != null) ? hiddenCols.isVisible(m) : true;
496 int commonrpositions[][] = new int[files.length][alignment.getWidth()];
497 String isel[] = new String[files.length];
498 // reference structure - all others are superposed in it
499 String[] targetC = new String[files.length];
500 String[] chainNames = new String[files.length];
501 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
503 StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
504 // RACE CONDITION - getMapping only returns Jmol loaded filenames once
505 // Jmol callback has completed.
506 if (mapping == null || mapping.length < 1)
509 "Implementation error - Jmol seems to be still working on getting its data - report at http://issues.jalview.org/browse/JAL-1016");
512 for (int s = 0; s < sequence[pdbfnum].length; s++)
514 for (int sp, m = 0; m < mapping.length; m++)
516 if (mapping[m].getSequence() == sequence[pdbfnum][s]
517 && (sp = alignment.findIndex(sequence[pdbfnum][s])) > -1)
519 if (refStructure == -1)
521 refStructure = pdbfnum;
523 SequenceI asp = alignment.getSequenceAt(sp);
524 for (int r = 0; r < matched.length; r++)
530 matched[r] = false; // assume this is not a good site
531 if (r >= asp.getLength())
536 if (jalview.util.Comparison.isGap(asp.getCharAt(r)))
538 // no mapping to gaps in sequence
541 int t = asp.findPosition(r); // sequence position
542 int apos = mapping[m].getAtomNum(t);
543 int pos = mapping[m].getPDBResNum(t);
545 if (pos < 1 || pos == lastPos)
547 // can't align unmapped sequence
550 matched[r] = true; // this is a good ite
552 // just record this residue position
553 commonrpositions[pdbfnum][r] = pos;
555 // create model selection suffix
556 isel[pdbfnum] = "/" + (pdbfnum + 1) + ".1";
557 if (mapping[m].getChain() == null
558 || mapping[m].getChain().trim().length() == 0)
560 targetC[pdbfnum] = "";
564 targetC[pdbfnum] = ":" + mapping[m].getChain();
566 chainNames[pdbfnum] = mapping[m].getPdbId()
568 // move on to next pdb file
569 s = sequence[pdbfnum].length;
576 // TODO: consider bailing if nmatched less than 4 because superposition
579 // TODO: refactor superposable position search (above) from jmol selection
580 // construction (below)
582 String[] selcom = new String[files.length];
584 // generate select statements to select regions to superimpose structures
586 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
588 String chainCd = targetC[pdbfnum];
591 StringBuffer molsel = new StringBuffer();
593 for (int r = 0; r < matched.length; r++)
601 if (lpos != commonrpositions[pdbfnum][r] - 1)
607 molsel.append(chainCd);
608 // molsel.append("} {");
614 // continuous run - and lpos >-1
617 // at the beginning, so add dash
623 lpos = commonrpositions[pdbfnum][r];
624 // molsel.append(lpos);
627 // add final selection phrase
631 molsel.append(chainCd);
634 if (molsel.length() > 1)
636 selcom[pdbfnum] = molsel.toString();
637 selectioncom.append("((");
638 selectioncom.append(selcom[pdbfnum].substring(1,
639 selcom[pdbfnum].length() - 1));
640 selectioncom.append(" )& ");
641 selectioncom.append(pdbfnum + 1);
642 selectioncom.append(".1)");
643 if (pdbfnum < files.length - 1)
645 selectioncom.append("|");
650 selcom[pdbfnum] = null;
654 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
656 if (pdbfnum == refStructure || selcom[pdbfnum] == null
657 || selcom[refStructure] == null)
661 command.append("echo ");
662 command.append("\"Superposing (");
663 command.append(chainNames[pdbfnum]);
664 command.append(") against reference (");
665 command.append(chainNames[refStructure]);
666 command.append(")\";\ncompare " + nSeconds);
668 command.append(1 + pdbfnum);
669 command.append(".1} {");
670 command.append(1 + refStructure);
671 command.append(".1} SUBSET {*.CA | *.P} ATOMS ");
673 // form the matched pair strings
675 for (int s = 0; s < 2; s++)
677 command.append(selcom[(s == 0 ? pdbfnum : refStructure)]);
679 command.append(" ROTATE TRANSLATE;\n");
681 if (selectioncom.length() > 0)
683 System.out.println("Select regions:\n" + selectioncom.toString());
684 evalStateCommand("select *; cartoons off; backbone; select ("
685 + selectioncom.toString() + "); cartoons; ");
686 // selcom.append("; ribbons; ");
688 .println("Superimpose command(s):\n" + command.toString());
690 evalStateCommand(command.toString());
693 if (selectioncom.length() > 0)
694 {// finally, mark all regions that were superposed.
695 if (selectioncom.substring(selectioncom.length() - 1).equals("|"))
697 selectioncom.setLength(selectioncom.length() - 1);
699 System.out.println("Select regions:\n" + selectioncom.toString());
700 evalStateCommand("select *; cartoons off; backbone; select ("
701 + selectioncom.toString() + "); cartoons; ");
702 // evalStateCommand("select *; backbone; select "+selcom.toString()+"; cartoons; center "+selcom.toString());
706 private void checkLaunched()
708 if (!viewer.isChimeraLaunched())
710 viewer.launchChimera(csm.getChimeraPaths());
712 if (!viewer.isChimeraLaunched())
714 log("Failed to launch Chimera!");
718 public void evalStateCommand(String command)
720 viewerCommandHistory(false);
722 if (lastCommand == null || !lastCommand.equals(command))
725 lastReply = viewer.sendChimeraCommand(command, true);
728 log("Response from command ('" + command + "') was:\n" + lastReply);
731 viewerCommandHistory(true);
732 lastCommand = command;
736 * colour any structures associated with sequences in the given alignment
737 * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
738 * if colourBySequence is enabled.
740 public void colourBySequence(boolean showFeatures,
741 jalview.api.AlignmentViewPanel alignmentv)
743 if (!colourBySequence || !loadingFinished)
749 String[] files = getPdbFile();
751 SequenceRenderer sr = getSequenceRenderer(alignmentv);
753 FeatureRenderer fr = null;
756 fr = getFeatureRenderer(alignmentv);
758 AlignmentI alignment = alignmentv.getAlignment();
760 for (jalview.structure.StructureMappingcommandSet cpdbbyseq : ChimeraCommands
761 .getColourBySequenceCommand(ssm, files, sequence, sr, fr,
763 for (String cbyseq : cpdbbyseq.commands)
765 evalStateCommand(cbyseq);
769 public boolean isColourBySequence()
771 return colourBySequence;
774 public void setColourBySequence(boolean colourBySequence)
776 this.colourBySequence = colourBySequence;
779 public void createImage(String file, String type, int quality)
781 System.out.println("JMOL CREATE IMAGE");
784 public String createImage(String fileName, String type,
785 Object textOrBytes, int quality)
787 System.out.println("JMOL CREATE IMAGE");
791 public String eval(String strEval)
793 // System.out.println(strEval);
794 // "# 'eval' is implemented only for the applet.";
798 // End StructureListener
799 // //////////////////////////
801 public float[][] functionXY(String functionName, int x, int y)
806 public float[][][] functionXYZ(String functionName, int nx, int ny, int nz)
808 // TODO Auto-generated method stub
812 public Color getColour(int atomIndex, int pdbResNum, String chain,
815 if (getModelNum(pdbfile) < 0)
817 log("get model / residue colour attribute unimplemented");
822 * returns the current featureRenderer that should be used to colour the
829 public abstract FeatureRenderer getFeatureRenderer(
830 AlignmentViewPanel alignment);
833 * instruct the Jalview binding to update the pdbentries vector if necessary
834 * prior to matching the jmol view's contents to the list of structure files
835 * Jalview knows about.
837 public abstract void refreshPdbEntries();
839 private int getModelNum(String modelFileName)
841 String[] mfn = getPdbFile();
846 for (int i = 0; i < mfn.length; i++)
848 if (mfn[i].equalsIgnoreCase(modelFileName))
855 * map between index of model filename returned from getPdbFile and the first
856 * index of models from this file in the viewer. Note - this is not trimmed -
857 * use getPdbFile to get number of unique models.
859 private int _modelFileNameMap[];
861 // ////////////////////////////////
862 // /StructureListener
863 public synchronized String[] getPdbFile()
867 return new String[0];
869 // if (modelFileNames == null)
871 // Collection<ChimeraModel> chimodels = viewer.getChimeraModels();
872 // _modelFileNameMap = new int[chimodels.size()];
874 // for (ChimeraModel chimodel : chimodels)
876 // String mdlName = chimodel.getModelName();
878 // modelFileNames = new String[j];
879 // // System.arraycopy(mset, 0, modelFileNames, 0, j);
882 return chimmaps.keySet().toArray(
883 modelFileNames = new String[chimmaps.size()]);
887 * map from string to applet
889 public Map getRegistryInfo()
891 // TODO Auto-generated method stub
896 * returns the current sequenceRenderer that should be used to colour the
903 public abstract SequenceRenderer getSequenceRenderer(
904 AlignmentViewPanel alignment);
907 public void highlightAtom(int atomIndex, int pdbResNum, String chain,
910 List<ChimeraModel> cms = chimmaps.get(pdbfile);
913 int mdlNum = cms.get(0).getModelNumber();
915 viewerCommandHistory(false);
916 viewer.stopListening();
917 if (resetLastRes.length() > 0)
919 viewer.sendChimeraCommand(resetLastRes.toString(), false);
923 eval.append("display "); // +modelNum
925 resetLastRes.setLength(0);
926 resetLastRes.append("~display ");
928 eval.append(" #" + (mdlNum));
929 resetLastRes.append("#" + (mdlNum));
931 // complete select string
933 eval.append(":" + pdbResNum);
934 resetLastRes.append(":" + pdbResNum);
935 if (!chain.equals(" "))
937 eval.append("." + chain);
938 resetLastRes.append("." + chain);
940 eval.append(eval.toString());
942 resetLastRes.append(resetLastRes.toString()
945 viewer.sendChimeraCommand(eval.toString(), false);
946 viewerCommandHistory(true);
947 viewer.startListening();
951 boolean debug = true;
953 private void log(String message)
955 System.err.println("## Chimera log: " + message);
958 private void viewerCommandHistory(boolean enable)
960 log("(Not yet implemented) History "
961 + ((debug || enable) ? "on" : "off"));
964 public void loadInline(String string)
968 // viewer.loadInline(strModel, isAppend);
970 // construct fake fullPathName and fileName so we can identify the file
972 // Then, construct pass a reader for the string to Jmol.
973 // ((org.jmol.Viewer.Viewer) viewer).loadModelFromFile(fullPathName,
974 // fileName, null, reader, false, null, null, 0);
975 // viewer.openStringInline(string);
976 log("cannot load inline in Chimera, yet");
979 public void mouseOverStructure(int atomIndex, String strInfo)
981 // function to parse a mouseOver event from Chimera
984 int alocsep = strInfo.indexOf("^");
985 int mdlSep = strInfo.indexOf("/");
986 int chainSeparator = strInfo.indexOf(":"), chainSeparator1 = -1;
988 if (chainSeparator == -1)
990 chainSeparator = strInfo.indexOf(".");
991 if (mdlSep > -1 && mdlSep < chainSeparator)
993 chainSeparator1 = chainSeparator;
994 chainSeparator = mdlSep;
997 // handle insertion codes
1000 pdbResNum = Integer.parseInt(strInfo.substring(
1001 strInfo.indexOf("]") + 1, alocsep));
1006 pdbResNum = Integer.parseInt(strInfo.substring(
1007 strInfo.indexOf("]") + 1, chainSeparator));
1011 if (strInfo.indexOf(":") > -1)
1012 chainId = strInfo.substring(strInfo.indexOf(":") + 1,
1013 strInfo.indexOf("."));
1019 String pdbfilename = modelFileNames[frameNo]; // default is first or current
1023 if (chainSeparator1 == -1)
1025 chainSeparator1 = strInfo.indexOf(".", mdlSep);
1027 String mdlId = (chainSeparator1 > -1) ? strInfo.substring(mdlSep + 1,
1028 chainSeparator1) : strInfo.substring(mdlSep + 1);
1031 // recover PDB filename for the model hovered over.
1032 int _mp = _modelFileNameMap.length - 1, mnumber = new Integer(mdlId)
1034 while (mnumber < _modelFileNameMap[_mp])
1038 pdbfilename = modelFileNames[_mp];
1039 if (pdbfilename == null)
1041 // pdbfilename = new File(viewer.getModelFileName(mnumber))
1042 // .getAbsolutePath();
1045 } catch (Exception e)
1050 if (lastMessage == null || !lastMessage.equals(strInfo))
1051 ssm.mouseOverStructure(pdbResNum, chainId, pdbfilename);
1053 lastMessage = strInfo;
1056 public void notifyAtomPicked(int atomIndex, String strInfo, String strData)
1059 * this implements the toggle label behaviour copied from the original
1060 * structure viewer, MCView
1062 if (strData != null)
1064 System.err.println("Ignoring additional pick data string " + strData);
1066 // rewrite these selections for chimera (DNA, RNA and protein)
1067 int chainSeparator = strInfo.indexOf(":");
1069 if (chainSeparator == -1)
1070 chainSeparator = strInfo.indexOf(".");
1072 String picked = strInfo.substring(strInfo.indexOf("]") + 1,
1074 String mdlString = "";
1075 if ((p = strInfo.indexOf(":")) > -1)
1076 picked += strInfo.substring(p + 1, strInfo.indexOf("."));
1078 if ((p = strInfo.indexOf("/")) > -1)
1080 mdlString += strInfo.substring(p, strInfo.indexOf(" #"));
1082 picked = "((" + picked + ".CA" + mdlString + ")|(" + picked + ".P"
1084 viewerCommandHistory(false);
1086 if (!atomsPicked.contains(picked))
1088 viewer.select(picked);
1089 atomsPicked.addElement(picked);
1093 viewer.select("not " + picked);
1094 atomsPicked.removeElement(picked);
1096 viewerCommandHistory(true);
1097 // TODO: in application this happens
1099 // if (scriptWindow != null)
1101 // scriptWindow.sendConsoleMessage(strInfo);
1102 // scriptWindow.sendConsoleMessage("\n");
1107 // incremented every time a load notification is successfully handled -
1108 // lightweight mechanism for other threads to detect when they can start
1109 // referrring to new structures.
1110 private long loadNotifiesHandled = 0;
1112 public long getLoadNotifiesHandled()
1114 return loadNotifiesHandled;
1117 public void notifyFileLoaded(String fullPathName, String fileName2,
1118 String modelName, String errorMsg, int modelParts)
1120 if (errorMsg != null)
1122 fileLoadingError = errorMsg;
1126 // TODO: deal sensibly with models loaded inLine:
1127 // modelName will be null, as will fullPathName.
1129 // the rest of this routine ignores the arguments, and simply interrogates
1130 // the Jmol view to find out what structures it contains, and adds them to
1131 // the structure selection manager.
1132 fileLoadingError = null;
1133 String[] oldmodels = modelFileNames;
1134 modelFileNames = null;
1135 chainNames = new Vector();
1136 chainFile = new Hashtable();
1137 boolean notifyLoaded = false;
1138 String[] modelfilenames = getPdbFile();
1139 // first check if we've lost any structures
1140 if (oldmodels != null && oldmodels.length > 0)
1143 for (int i = 0; i < oldmodels.length; i++)
1145 for (int n = 0; n < modelfilenames.length; n++)
1147 if (modelfilenames[n] == oldmodels[i])
1149 oldmodels[i] = null;
1153 if (oldmodels[i] != null)
1160 String[] oldmfn = new String[oldm];
1162 for (int i = 0; i < oldmodels.length; i++)
1164 if (oldmodels[i] != null)
1166 oldmfn[oldm++] = oldmodels[i];
1169 // deregister the Jmol instance for these structures - we'll add
1170 // ourselves again at the end for the current structure set.
1171 ssm.removeStructureViewerListener(this, oldmfn);
1175 // register ourselves as a listener and notify the gui that it needs to
1177 ssm.addStructureViewerListener(this);
1181 FeatureRenderer fr = getFeatureRenderer(null);
1187 loadNotifiesHandled++;
1189 setLoadingFromArchive(false);
1192 public void setJalviewColourScheme(ColourSchemeI cs)
1194 colourBySequence = false;
1202 viewerCommandHistory(false);
1203 // TODO: Switch between nucleotide or aa selection expressions
1204 Enumeration en = ResidueProperties.aa3Hash.keys();
1205 StringBuffer command = new StringBuffer("select *;color white;");
1206 while (en.hasMoreElements())
1208 res = en.nextElement().toString();
1209 index = ((Integer) ResidueProperties.aa3Hash.get(res)).intValue();
1213 col = cs.findColour(ResidueProperties.aa[index].charAt(0));
1214 // TODO: need colour string function and res selection here
1215 command.append("select " + res + ";color[" + col.getRed() + ","
1216 + col.getGreen() + "," + col.getBlue() + "];");
1219 evalStateCommand(command.toString());
1220 viewerCommandHistory(true);
1223 public void showHelp()
1226 showUrl("http://jmol.sourceforge.net/docs/JmolUserGuide/", "jmolHelp");
1230 * open the URL somehow
1234 public abstract void showUrl(String url, String target);
1237 * called when the binding thinks the UI needs to be refreshed after a Jmol
1238 * state change. this could be because structures were loaded, or because an
1239 * error has occured.
1241 public abstract void refreshGUI();
1243 public void componentResized(ComponentEvent e)
1248 public void componentMoved(ComponentEvent e)
1253 public void componentShown(ComponentEvent e)
1257 public void componentHidden(ComponentEvent e)
1261 public void setLoadingFromArchive(boolean loadingFromArchive)
1263 this.loadingFromArchive = loadingFromArchive;
1268 * @return true if Jmol is still restoring state or loading is still going on
1269 * (see setFinsihedLoadingFromArchive)
1271 public boolean isLoadingFromArchive()
1273 return loadingFromArchive && !loadingFinished;
1277 * modify flag which controls if sequence colouring events are honoured by the
1278 * binding. Should be true for normal operation
1280 * @param finishedLoading
1282 public void setFinishedLoadingFromArchive(boolean finishedLoading)
1284 loadingFinished = finishedLoading;
1287 public void setBackgroundColour(java.awt.Color col)
1289 viewerCommandHistory(false);
1290 // todo set background colour
1291 viewer.sendChimeraCommand(
1292 "background [" + col.getRed() + "," + col.getGreen() + ","
1293 + col.getBlue() + "];", false);
1294 viewerCommandHistory(true);
1298 * add structures and any known sequence associations
1300 * @returns the pdb entries added to the current set.
1302 public synchronized PDBEntry[] addSequenceAndChain(PDBEntry[] pdbe,
1303 SequenceI[][] seq, String[][] chns)
1306 Vector v = new Vector();
1307 Vector rtn = new Vector();
1308 for (int i = 0; i < pdbentry.length; i++)
1310 v.addElement(pdbentry[i]);
1312 for (int i = 0; i < pdbe.length; i++)
1314 int r = v.indexOf(pdbe[i]);
1315 if (r == -1 || r >= pdbentry.length)
1317 rtn.addElement(new int[]
1319 v.addElement(pdbe[i]);
1323 // just make sure the sequence/chain entries are all up to date
1324 addSequenceAndChain(r, seq[i], chns[i]);
1327 pdbe = new PDBEntry[v.size()];
1332 // expand the tied seuqence[] and string[] arrays
1333 SequenceI[][] sqs = new SequenceI[pdbentry.length][];
1334 String[][] sch = new String[pdbentry.length][];
1335 System.arraycopy(sequence, 0, sqs, 0, sequence.length);
1336 System.arraycopy(chains, 0, sch, 0, this.chains.length);
1339 pdbe = new PDBEntry[rtn.size()];
1340 for (int r = 0; r < pdbe.length; r++)
1342 int[] stri = ((int[]) rtn.elementAt(r));
1343 // record the pdb file as a new addition
1344 pdbe[r] = pdbentry[stri[0]];
1345 // and add the new sequence/chain entries
1346 addSequenceAndChain(stri[0], seq[stri[1]], chns[stri[1]]);
1356 public void addSequence(int pe, SequenceI[] seq)
1358 // add sequences to the pe'th pdbentry's seuqence set.
1359 addSequenceAndChain(pe, seq, null);
1362 private void addSequenceAndChain(int pe, SequenceI[] seq, String[] tchain)
1364 if (pe < 0 || pe >= pdbentry.length)
1367 "Implementation error - no corresponding pdbentry (for index "
1368 + pe + ") to add sequences mappings to");
1370 final String nullChain = "TheNullChain";
1371 Vector s = new Vector();
1372 Vector c = new Vector();
1375 chains = new String[pdbentry.length][];
1377 if (sequence[pe] != null)
1379 for (int i = 0; i < sequence[pe].length; i++)
1381 s.addElement(sequence[pe][i]);
1382 if (chains[pe] != null)
1384 if (i < chains[pe].length)
1386 c.addElement(chains[pe][i]);
1390 c.addElement(nullChain);
1395 if (tchain != null && tchain.length > 0)
1397 c.addElement(nullChain);
1402 for (int i = 0; i < seq.length; i++)
1404 if (!s.contains(seq[i]))
1406 s.addElement(seq[i]);
1407 if (tchain != null && i < tchain.length)
1409 c.addElement(tchain[i] == null ? nullChain : tchain[i]);
1413 SequenceI[] tmp = new SequenceI[s.size()];
1418 String[] tch = new String[c.size()];
1420 for (int i = 0; i < tch.length; i++)
1422 if (tch[i] == nullChain)
1438 * @return text report of alignment between pdbfile and any associated
1439 * alignment sequences
1441 public String printMapping(String pdbfile)
1443 return ssm.printMapping(pdbfile);