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 jalview.api.AlignmentViewPanel;
24 import jalview.api.FeatureRenderer;
25 import jalview.api.SequenceRenderer;
26 import jalview.api.SequenceStructureBinding;
27 import jalview.api.StructureSelectionManagerProvider;
28 import jalview.datamodel.AlignmentI;
29 import jalview.datamodel.ColumnSelection;
30 import jalview.datamodel.PDBEntry;
31 import jalview.datamodel.SequenceI;
32 import jalview.io.AppletFormatAdapter;
33 import jalview.schemes.ColourSchemeI;
34 import jalview.schemes.ResidueProperties;
35 import jalview.structure.StructureListener;
36 import jalview.structure.StructureMapping;
37 import jalview.structure.StructureSelectionManager;
38 import jalview.structures.models.SequenceStructureBindingModel;
40 import java.awt.Color;
41 import java.awt.event.ComponentEvent;
43 import java.util.ArrayList;
44 import java.util.Enumeration;
45 import java.util.HashMap;
46 import java.util.Hashtable;
47 import java.util.List;
49 import java.util.Vector;
51 import ext.edu.ucsf.rbvi.strucviz2.ChimeraManager;
52 import ext.edu.ucsf.rbvi.strucviz2.ChimeraModel;
53 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
54 import ext.edu.ucsf.rbvi.strucviz2.StructureManager.ModelType;
56 public abstract class JalviewChimeraBinding extends
57 SequenceStructureBindingModel implements StructureListener,
58 SequenceStructureBinding, StructureSelectionManagerProvider
61 private StructureManager csm;
63 private ChimeraManager viewer;
66 * set if chimera state is being restored from some source - instructs binding
67 * not to apply default display style when structure set is updated for first
70 private boolean loadingFromArchive = false;
73 * second flag to indicate if the jmol viewer should ignore sequence colouring
74 * events from the structure manager because the GUI is still setting up
76 private boolean loadingFinished = true;
79 * state flag used to check if the Jmol viewer's paint method can be called
81 private boolean finishedInit = false;
83 public boolean isFinishedInit()
88 public void setFinishedInit(boolean finishedInit)
90 this.finishedInit = finishedInit;
93 boolean allChainsSelected = false;
96 * when true, try to search the associated datamodel for sequences that are
97 * associated with any unknown structures in the Jmol view.
99 private boolean associateNewStructs = false;
101 Vector atomsPicked = new Vector();
103 public Vector chainNames;
108 * array of target chains for seuqences - tied to pdbentry and sequence[]
110 protected String[][] chains;
112 boolean colourBySequence = true;
114 StringBuffer eval = new StringBuffer();
116 public String fileLoadingError;
118 private Map<String, List<ChimeraModel>> chimmaps = new HashMap<String, List<ChimeraModel>>();
120 private List<String> mdlToFile = new ArrayList<String>();
123 * the default or current model displayed if the model cannot be identified
124 * from the selection message
132 boolean loadedInline;
134 public boolean openFile(PDBEntry pe)
136 String file = pe.getFile();
139 List<ChimeraModel> oldList = viewer.getModelList();
140 viewer.openModel(file, ModelType.PDB_MODEL);
141 List<ChimeraModel> newList = viewer.getModelList();
142 if (oldList.size() < newList.size())
144 while (oldList.size() > 0)
149 chimmaps.put(file, newList);
150 for (ChimeraModel cm : newList)
152 while (mdlToFile.size() < 1 + cm.getModelNumber())
154 mdlToFile.add(new String(""));
156 mdlToFile.set(cm.getModelNumber(), file);
159 File fl = new File(file);
160 String protocol = AppletFormatAdapter.URL;
165 protocol = AppletFormatAdapter.FILE;
167 } catch (Exception e)
172 // Explicitly map to the filename used by Jmol ;
173 // pdbentry[pe].getFile(), protocol);
177 ssm.addStructureViewerListener(this);
178 // ssm.addSelectionListener(this);
179 FeatureRenderer fr = getFeatureRenderer(null);
188 } catch (Exception q)
190 log("Exception when trying to open model " + file + "\n"
198 * current set of model filenames loaded
200 String[] modelFileNames = null;
202 public PDBEntry[] pdbentry;
205 * datasource protocol for access to PDBEntrylatest
207 String protocol = null;
209 StringBuffer resetLastRes = new StringBuffer();
212 * sequences mapped to each pdbentry
214 public SequenceI[][] sequence;
216 public StructureSelectionManager ssm;
218 private List<String> lastReply;
220 public JalviewChimeraBinding(StructureSelectionManager ssm,
221 PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains,
225 this.sequence = sequenceIs;
226 this.chains = chains;
227 this.pdbentry = pdbentry;
228 this.protocol = protocol;
231 this.chains = new String[pdbentry.length][];
233 viewer = new ChimeraManager(
234 csm = new ext.edu.ucsf.rbvi.strucviz2.StructureManager(true));
236 * viewer = JmolViewer.allocateViewer(renderPanel, new SmarterJmolAdapter(),
237 * "jalviewJmol", ap.av.applet .getDocumentBase(),
238 * ap.av.applet.getCodeBase(), "", this);
240 * jmolpopup = JmolPopup.newJmolPopup(viewer, true, "Jmol", true);
244 public JalviewChimeraBinding(StructureSelectionManager ssm,
245 ChimeraManager viewer2)
249 csm = viewer.getStructureManager();
253 * construct a title string for the viewer window based on the data jalview
258 public String getViewerTitle()
260 if (sequence == null || pdbentry == null || sequence.length < 1
261 || pdbentry.length < 1 || sequence[0].length < 1)
263 return ("Jalview Chimera Window");
265 // TODO: give a more informative title when multiple structures are
267 StringBuffer title = new StringBuffer("Chimera view for "
268 + sequence[0][0].getName() + ":" + pdbentry[0].getId());
270 if (pdbentry[0].getProperty() != null)
272 if (pdbentry[0].getProperty().get("method") != null)
274 title.append(" Method: ");
275 title.append(pdbentry[0].getProperty().get("method"));
277 if (pdbentry[0].getProperty().get("chains") != null)
279 title.append(" Chain:");
280 title.append(pdbentry[0].getProperty().get("chains"));
283 return title.toString();
287 * prepare the view for a given set of models/chains. chainList contains
288 * strings of the form 'pdbfilename:Chaincode'
291 * list of chains to make visible
293 public void centerViewer(Vector chainList)
295 StringBuffer cmd = new StringBuffer();
298 for (int i = 0, iSize = chainList.size(); i < iSize; i++)
301 lbl = (String) chainList.elementAt(i);
305 mlength = lbl.indexOf(":", p);
306 } while (p < mlength && mlength < (lbl.length() - 2));
307 // TODO: lookup each pdb id and recover proper model number for it.
308 cmd.append("#" + getModelNum((String) chainFile.get(lbl)) + "."
309 + lbl.substring(mlength + 1) + " or ");
311 if (cmd.length() > 0)
312 cmd.setLength(cmd.length() - 4);
313 evalStateCommand("~display #*; ~ribbon #*; ribbon " + cmd + ";focus "
317 public void closeViewer()
319 ssm.removeStructureViewerListener(this, this.getPdbFile());
320 // and shut down Chimera
321 viewer.exitChimera();
322 // viewer.evalStringQuiet("zap");
323 // viewer.setJmolStatusListener(null);
326 releaseUIResources();
330 * called by JalviewJmolbinding after closeViewer is called - release any
331 * resources and references so they can be garbage collected.
333 protected abstract void releaseUIResources();
335 public void colourByChain()
337 colourBySequence = false;
338 // TODO: colour by chain should colour each chain distinctly across all
340 // TODO: http://issues.jalview.org/browse/JAL-628
341 evalStateCommand("select *;color chain",false);
344 public void colourByCharge()
346 colourBySequence = false;
347 evalStateCommand("colour *;color white;select ASP,GLU;color red;"
348 + "select LYS,ARG;color blue;select CYS;color yellow", false);
352 * superpose the structures associated with sequences in the alignment
353 * according to their corresponding positions.
355 public void superposeStructures(AlignmentI alignment)
357 superposeStructures(alignment, -1, null);
361 * superpose the structures associated with sequences in the alignment
362 * according to their corresponding positions. ded)
364 * @param refStructure
365 * - select which pdb file to use as reference (default is -1 - the
366 * first structure in the alignment)
368 public void superposeStructures(AlignmentI alignment, int refStructure)
370 superposeStructures(alignment, refStructure, null);
374 * superpose the structures associated with sequences in the alignment
375 * according to their corresponding positions. ded)
377 * @param refStructure
378 * - select which pdb file to use as reference (default is -1 - the
379 * first structure in the alignment)
383 public void superposeStructures(AlignmentI alignment, int refStructure,
384 ColumnSelection hiddenCols)
386 superposeStructures(new AlignmentI[]
387 { alignment }, new int[]
388 { refStructure }, new ColumnSelection[]
392 public void superposeStructures(AlignmentI[] _alignment,
393 int[] _refStructure, ColumnSelection[] _hiddenCols)
395 assert (_alignment.length == _refStructure.length && _alignment.length != _hiddenCols.length);
396 StringBuffer allComs = new StringBuffer(); // whole shebang for superposition
397 String[] files = getPdbFile();
398 // check to see if we are still waiting for Jmol files
399 long starttime = System.currentTimeMillis();
400 boolean waiting = true;
404 for (String file : files)
408 // HACK - in Jalview 2.8 this call may not be threadsafe so we catch
409 // every possible exception
410 StructureMapping[] sm = ssm.getMapping(file);
411 if (sm == null || sm.length == 0)
415 } catch (Exception x)
423 // we wait around for a reasonable time before we give up
425 && System.currentTimeMillis() < (10000 + 1000 * files.length + starttime));
429 .println("RUNTIME PROBLEM: Jmol seems to be taking a long time to process all the structures.");
433 StringBuffer selectioncom = new StringBuffer();
434 for (int a = 0; a < _alignment.length; a++)
436 int refStructure = _refStructure[a];
437 AlignmentI alignment = _alignment[a];
438 ColumnSelection hiddenCols = _hiddenCols[a];
440 && selectioncom.length() > 0
441 && !selectioncom.substring(selectioncom.length() - 1).equals(
444 selectioncom.append(" ");
446 // process this alignment
447 if (refStructure >= files.length)
449 System.err.println("Invalid reference structure value "
453 if (refStructure < -1)
457 StringBuffer command = new StringBuffer();
459 boolean matched[] = new boolean[alignment.getWidth()];
460 for (int m = 0; m < matched.length; m++)
463 matched[m] = (hiddenCols != null) ? hiddenCols.isVisible(m) : true;
466 int commonrpositions[][] = new int[files.length][alignment.getWidth()];
467 String isel[] = new String[files.length];
468 // reference structure - all others are superposed in it
469 String[] targetC = new String[files.length];
470 String[] chainNames = new String[files.length];
471 String[] atomS = new String[files.length];
472 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
474 StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
475 // RACE CONDITION - getMapping only returns Jmol loaded filenames once
476 // Jmol callback has completed.
477 if (mapping == null || mapping.length < 1)
480 "Implementation error - Chimera seems to be still working on getting its data - report at http://issues.jalview.org/browse/JAL-1016");
483 for (int s = 0; s < sequence[pdbfnum].length; s++)
485 for (int sp, m = 0; m < mapping.length; m++)
487 if (mapping[m].getSequence() == sequence[pdbfnum][s]
488 && (sp = alignment.findIndex(sequence[pdbfnum][s])) > -1)
490 if (refStructure == -1)
492 refStructure = pdbfnum;
494 SequenceI asp = alignment.getSequenceAt(sp);
495 for (int r = 0; r < matched.length; r++)
501 matched[r] = false; // assume this is not a good site
502 if (r >= asp.getLength())
507 if (jalview.util.Comparison.isGap(asp.getCharAt(r)))
509 // no mapping to gaps in sequence
512 int t = asp.findPosition(r); // sequence position
513 int apos = mapping[m].getAtomNum(t);
514 int pos = mapping[m].getPDBResNum(t);
516 if (pos < 1 || pos == lastPos)
518 // can't align unmapped sequence
521 matched[r] = true; // this is a good ite
523 // just record this residue position
524 commonrpositions[pdbfnum][r] = pos;
526 // create model selection suffix
527 isel[pdbfnum] = "#" + pdbfnum;
528 if (mapping[m].getChain() == null
529 || mapping[m].getChain().trim().length() == 0)
531 targetC[pdbfnum] = "";
535 targetC[pdbfnum] = "." + mapping[m].getChain();
537 chainNames[pdbfnum] = mapping[m].getPdbId()
539 atomS[pdbfnum] = asp.getRNA()!=null ? "P" : "CA";
540 // move on to next pdb file
541 s = sequence[pdbfnum].length;
548 // TODO: consider bailing if nmatched less than 4 because superposition
551 // TODO: refactor superposable position search (above) from jmol selection
552 // construction (below)
554 String[] selcom = new String[files.length];
557 // generate select statements to select regions to superimpose structures
559 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
561 String chainCd = targetC[pdbfnum];
564 StringBuffer molsel = new StringBuffer();
565 for (int r = 0; r < matched.length; r++)
573 if (lpos != commonrpositions[pdbfnum][r] - 1)
578 molsel.append((run ? "" : ":") + lpos);
579 molsel.append(chainCd);
585 // continuous run - and lpos >-1
588 // at the beginning, so add dash
589 molsel.append(":" + lpos);
594 lpos = commonrpositions[pdbfnum][r];
595 // molsel.append(lpos);
598 // add final selection phrase
601 molsel.append((run ? "" : ":") + lpos);
602 molsel.append(chainCd);
603 // molsel.append("");
605 if (molsel.length() > 1)
607 selcom[pdbfnum] = molsel.toString();
608 selectioncom.append("#" + pdbfnum);
609 selectioncom.append(selcom[pdbfnum]);
610 selectioncom.append(" ");
611 if (pdbfnum < files.length - 1)
613 selectioncom.append("| ");
618 selcom[pdbfnum] = null;
622 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
624 if (pdbfnum == refStructure || selcom[pdbfnum] == null
625 || selcom[refStructure] == null)
629 if (command.length()>0)
633 command.append("match");
635 // form the matched pair strings
636 for (int s = 0; s < 2; s++)
638 command.append(" #"+(s == 0 ? pdbfnum : refStructure)+".1");
639 // note - need to select on first model, otherwise it all goes wrong!
640 command.append(selcom[(s == 0 ? pdbfnum : refStructure)]);
641 command.append("@"+atomS[(s == 0 ? pdbfnum : refStructure)]); // match on backbone alpha/polyphosphate
644 if (selectioncom.length() > 0)
646 System.out.println("Select regions:\n" + selectioncom.toString());
648 .println("Superimpose command(s):\n" + command.toString());
649 allComs.append("~display all; chain @CA|P; ribbon "
650 + selectioncom.toString() + ";"+command.toString());
651 // selcom.append("; ribbons; ");
654 if (selectioncom.length() > 0)
655 {// finally, mark all regions that were superposed.
656 if (selectioncom.substring(selectioncom.length() - 1).equals("|"))
658 selectioncom.setLength(selectioncom.length() - 1);
660 System.out.println("Select regions:\n" + selectioncom.toString());
661 allComs.append("; ~display all; chain @CA|P; ribbon "
662 + selectioncom.toString() + "");
663 // evalStateCommand("select *; backbone; select "+selcom.toString()+"; cartoons; center "+selcom.toString());
664 evalStateCommand(allComs.toString(),false);
669 private void checkLaunched()
671 if (!viewer.isChimeraLaunched())
673 viewer.launchChimera(csm.getChimeraPaths());
675 if (!viewer.isChimeraLaunched())
677 log("Failed to launch Chimera!");
681 public void evalStateCommand(final String command, boolean resp)
683 viewerCommandHistory(false);
685 if (lastCommand == null || !lastCommand.equals(command))
687 // Thread t = new Thread(new Runnable()
692 lastReply = viewer.sendChimeraCommand(command, resp);
695 log("Response from command ('" + command + "') was:\n"
700 // TODO - use j7/8 thread management
704 // } catch (InterruptedException foo)
709 viewerCommandHistory(true);
710 lastCommand = command;
714 * colour any structures associated with sequences in the given alignment
715 * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
716 * if colourBySequence is enabled.
718 public void colourBySequence(boolean showFeatures,
719 jalview.api.AlignmentViewPanel alignmentv)
721 if (!colourBySequence || !loadingFinished)
727 String[] files = getPdbFile();
729 SequenceRenderer sr = getSequenceRenderer(alignmentv);
731 FeatureRenderer fr = null;
734 fr = getFeatureRenderer(alignmentv);
736 AlignmentI alignment = alignmentv.getAlignment();
738 for (jalview.structure.StructureMappingcommandSet cpdbbyseq : ChimeraCommands
739 .getColourBySequenceCommand(ssm, files, sequence, sr, fr,
741 for (String cbyseq : cpdbbyseq.commands)
744 evalStateCommand(cbyseq, false);
749 private void waitForChimera()
751 while (viewer.isBusy())
755 } catch (InterruptedException q)
760 public boolean isColourBySequence()
762 return colourBySequence;
765 public void setColourBySequence(boolean colourBySequence)
767 this.colourBySequence = colourBySequence;
770 public void createImage(String file, String type, int quality)
772 System.out.println("JMOL CREATE IMAGE");
775 public String createImage(String fileName, String type,
776 Object textOrBytes, int quality)
778 System.out.println("JMOL CREATE IMAGE");
782 public String eval(String strEval)
784 // System.out.println(strEval);
785 // "# 'eval' is implemented only for the applet.";
789 // End StructureListener
790 // //////////////////////////
792 public float[][] functionXY(String functionName, int x, int y)
797 public float[][][] functionXYZ(String functionName, int nx, int ny, int nz)
799 // TODO Auto-generated method stub
803 public Color getColour(int atomIndex, int pdbResNum, String chain,
806 if (getModelNum(pdbfile) < 0)
808 log("get model / residue colour attribute unimplemented");
813 * returns the current featureRenderer that should be used to colour the
820 public abstract FeatureRenderer getFeatureRenderer(
821 AlignmentViewPanel alignment);
824 * instruct the Jalview binding to update the pdbentries vector if necessary
825 * prior to matching the jmol view's contents to the list of structure files
826 * Jalview knows about.
828 public abstract void refreshPdbEntries();
830 private int getModelNum(String modelFileName)
832 String[] mfn = getPdbFile();
837 for (int i = 0; i < mfn.length; i++)
839 if (mfn[i].equalsIgnoreCase(modelFileName))
846 * map between index of model filename returned from getPdbFile and the first
847 * index of models from this file in the viewer. Note - this is not trimmed -
848 * use getPdbFile to get number of unique models.
850 private int _modelFileNameMap[];
852 // ////////////////////////////////
853 // /StructureListener
854 public synchronized String[] getPdbFile()
858 return new String[0];
860 // if (modelFileNames == null)
862 // Collection<ChimeraModel> chimodels = viewer.getChimeraModels();
863 // _modelFileNameMap = new int[chimodels.size()];
865 // for (ChimeraModel chimodel : chimodels)
867 // String mdlName = chimodel.getModelName();
869 // modelFileNames = new String[j];
870 // // System.arraycopy(mset, 0, modelFileNames, 0, j);
873 return chimmaps.keySet().toArray(
874 modelFileNames = new String[chimmaps.size()]);
878 * map from string to applet
880 public Map getRegistryInfo()
882 // TODO Auto-generated method stub
887 * returns the current sequenceRenderer that should be used to colour the
894 public abstract SequenceRenderer getSequenceRenderer(
895 AlignmentViewPanel alignment);
898 public void highlightAtom(int atomIndex, int pdbResNum, String chain,
901 List<ChimeraModel> cms = chimmaps.get(pdbfile);
904 int mdlNum = cms.get(0).getModelNumber();
906 viewerCommandHistory(false);
907 // viewer.stopListening();
908 if (resetLastRes.length() > 0)
911 eval.append(resetLastRes.toString() + ";");
914 eval.append("display "); // +modelNum
916 resetLastRes.setLength(0);
917 resetLastRes.append("~display ");
919 eval.append(" #" + (mdlNum));
920 resetLastRes.append(" #" + (mdlNum));
922 // complete select string
924 eval.append(":" + pdbResNum);
925 resetLastRes.append(":" + pdbResNum);
926 if (!chain.equals(" "))
928 eval.append("." + chain);
929 resetLastRes.append("." + chain);
932 viewer.sendChimeraCommand(eval.toString(), false);
933 viewerCommandHistory(true);
934 // viewer.startListening();
938 boolean debug = true;
940 private void log(String message)
942 System.err.println("## Chimera log: " + message);
945 private void viewerCommandHistory(boolean enable)
947 log("(Not yet implemented) History "
948 + ((debug || enable) ? "on" : "off"));
951 public void loadInline(String string)
955 // viewer.loadInline(strModel, isAppend);
957 // construct fake fullPathName and fileName so we can identify the file
959 // Then, construct pass a reader for the string to Jmol.
960 // ((org.jmol.Viewer.Viewer) viewer).loadModelFromFile(fullPathName,
961 // fileName, null, reader, false, null, null, 0);
962 // viewer.openStringInline(string);
963 log("cannot load inline in Chimera, yet");
966 public void mouseOverStructure(int atomIndex, String strInfo)
968 // function to parse a mouseOver event from Chimera
971 int alocsep = strInfo.indexOf("^");
972 int mdlSep = strInfo.indexOf("/");
973 int chainSeparator = strInfo.indexOf(":"), chainSeparator1 = -1;
975 if (chainSeparator == -1)
977 chainSeparator = strInfo.indexOf(".");
978 if (mdlSep > -1 && mdlSep < chainSeparator)
980 chainSeparator1 = chainSeparator;
981 chainSeparator = mdlSep;
984 // handle insertion codes
987 pdbResNum = Integer.parseInt(strInfo.substring(
988 strInfo.indexOf("]") + 1, alocsep));
993 pdbResNum = Integer.parseInt(strInfo.substring(
994 strInfo.indexOf("]") + 1, chainSeparator));
998 if (strInfo.indexOf(":") > -1)
999 chainId = strInfo.substring(strInfo.indexOf(":") + 1,
1000 strInfo.indexOf("."));
1006 String pdbfilename = modelFileNames[frameNo]; // default is first or current
1010 if (chainSeparator1 == -1)
1012 chainSeparator1 = strInfo.indexOf(".", mdlSep);
1014 String mdlId = (chainSeparator1 > -1) ? strInfo.substring(mdlSep + 1,
1015 chainSeparator1) : strInfo.substring(mdlSep + 1);
1018 // recover PDB filename for the model hovered over.
1019 int _mp = _modelFileNameMap.length - 1, mnumber = new Integer(mdlId)
1021 while (mnumber < _modelFileNameMap[_mp])
1025 pdbfilename = modelFileNames[_mp];
1026 if (pdbfilename == null)
1028 // pdbfilename = new File(viewer.getModelFileName(mnumber))
1029 // .getAbsolutePath();
1032 } catch (Exception e)
1037 if (lastMessage == null || !lastMessage.equals(strInfo))
1038 ssm.mouseOverStructure(pdbResNum, chainId, pdbfilename);
1040 lastMessage = strInfo;
1043 public void notifyAtomPicked(int atomIndex, String strInfo, String strData)
1046 * this implements the toggle label behaviour copied from the original
1047 * structure viewer, MCView
1049 if (strData != null)
1051 System.err.println("Ignoring additional pick data string " + strData);
1053 // rewrite these selections for chimera (DNA, RNA and protein)
1054 int chainSeparator = strInfo.indexOf(":");
1056 if (chainSeparator == -1)
1057 chainSeparator = strInfo.indexOf(".");
1059 String picked = strInfo.substring(strInfo.indexOf("]") + 1,
1061 String mdlString = "";
1062 if ((p = strInfo.indexOf(":")) > -1)
1063 picked += strInfo.substring(p + 1, strInfo.indexOf("."));
1065 if ((p = strInfo.indexOf("/")) > -1)
1067 mdlString += strInfo.substring(p, strInfo.indexOf(" #"));
1069 picked = "((" + picked + ".CA" + mdlString + ")|(" + picked + ".P"
1071 viewerCommandHistory(false);
1073 if (!atomsPicked.contains(picked))
1075 viewer.select(picked);
1076 atomsPicked.addElement(picked);
1080 viewer.select("not " + picked);
1081 atomsPicked.removeElement(picked);
1083 viewerCommandHistory(true);
1084 // TODO: in application this happens
1086 // if (scriptWindow != null)
1088 // scriptWindow.sendConsoleMessage(strInfo);
1089 // scriptWindow.sendConsoleMessage("\n");
1094 // incremented every time a load notification is successfully handled -
1095 // lightweight mechanism for other threads to detect when they can start
1096 // referrring to new structures.
1097 private long loadNotifiesHandled = 0;
1099 public long getLoadNotifiesHandled()
1101 return loadNotifiesHandled;
1104 public void notifyFileLoaded(String fullPathName, String fileName2,
1105 String modelName, String errorMsg, int modelParts)
1107 if (errorMsg != null)
1109 fileLoadingError = errorMsg;
1113 // TODO: deal sensibly with models loaded inLine:
1114 // modelName will be null, as will fullPathName.
1116 // the rest of this routine ignores the arguments, and simply interrogates
1117 // the Jmol view to find out what structures it contains, and adds them to
1118 // the structure selection manager.
1119 fileLoadingError = null;
1120 String[] oldmodels = modelFileNames;
1121 modelFileNames = null;
1122 chainNames = new Vector();
1123 chainFile = new Hashtable();
1124 boolean notifyLoaded = false;
1125 String[] modelfilenames = getPdbFile();
1126 // first check if we've lost any structures
1127 if (oldmodels != null && oldmodels.length > 0)
1130 for (int i = 0; i < oldmodels.length; i++)
1132 for (int n = 0; n < modelfilenames.length; n++)
1134 if (modelfilenames[n] == oldmodels[i])
1136 oldmodels[i] = null;
1140 if (oldmodels[i] != null)
1147 String[] oldmfn = new String[oldm];
1149 for (int i = 0; i < oldmodels.length; i++)
1151 if (oldmodels[i] != null)
1153 oldmfn[oldm++] = oldmodels[i];
1156 // deregister the Jmol instance for these structures - we'll add
1157 // ourselves again at the end for the current structure set.
1158 ssm.removeStructureViewerListener(this, oldmfn);
1162 // register ourselves as a listener and notify the gui that it needs to
1164 ssm.addStructureViewerListener(this);
1168 FeatureRenderer fr = getFeatureRenderer(null);
1174 loadNotifiesHandled++;
1176 setLoadingFromArchive(false);
1179 public void setJalviewColourScheme(ColourSchemeI cs)
1181 colourBySequence = false;
1189 viewerCommandHistory(false);
1190 // TODO: Switch between nucleotide or aa selection expressions
1191 Enumeration en = ResidueProperties.aa3Hash.keys();
1192 StringBuffer command = new StringBuffer("select *;color white;");
1193 while (en.hasMoreElements())
1195 res = en.nextElement().toString();
1196 index = ((Integer) ResidueProperties.aa3Hash.get(res)).intValue();
1200 col = cs.findColour(ResidueProperties.aa[index].charAt(0));
1201 // TODO: need colour string function and res selection here
1202 command.append("select " + res + ";color[" + col.getRed() + ","
1203 + col.getGreen() + "," + col.getBlue() + "];");
1206 evalStateCommand(command.toString(),false);
1207 viewerCommandHistory(true);
1210 public void showHelp()
1213 showUrl("http://jmol.sourceforge.net/docs/JmolUserGuide/", "jmolHelp");
1217 * open the URL somehow
1221 public abstract void showUrl(String url, String target);
1224 * called when the binding thinks the UI needs to be refreshed after a Jmol
1225 * state change. this could be because structures were loaded, or because an
1226 * error has occured.
1228 public abstract void refreshGUI();
1230 public void componentResized(ComponentEvent e)
1235 public void componentMoved(ComponentEvent e)
1240 public void componentShown(ComponentEvent e)
1244 public void componentHidden(ComponentEvent e)
1248 public void setLoadingFromArchive(boolean loadingFromArchive)
1250 this.loadingFromArchive = loadingFromArchive;
1255 * @return true if Jmol is still restoring state or loading is still going on
1256 * (see setFinsihedLoadingFromArchive)
1258 public boolean isLoadingFromArchive()
1260 return loadingFromArchive && !loadingFinished;
1264 * modify flag which controls if sequence colouring events are honoured by the
1265 * binding. Should be true for normal operation
1267 * @param finishedLoading
1269 public void setFinishedLoadingFromArchive(boolean finishedLoading)
1271 loadingFinished = finishedLoading;
1274 public void setBackgroundColour(java.awt.Color col)
1276 viewerCommandHistory(false);
1277 // todo set background colour
1278 viewer.sendChimeraCommand(
1279 "background [" + col.getRed() + "," + col.getGreen() + ","
1280 + col.getBlue() + "];", false);
1281 viewerCommandHistory(true);
1285 * add structures and any known sequence associations
1287 * @returns the pdb entries added to the current set.
1289 public synchronized PDBEntry[] addSequenceAndChain(PDBEntry[] pdbe,
1290 SequenceI[][] seq, String[][] chns)
1293 Vector v = new Vector();
1294 Vector rtn = new Vector();
1295 for (int i = 0; i < pdbentry.length; i++)
1297 v.addElement(pdbentry[i]);
1299 for (int i = 0; i < pdbe.length; i++)
1301 int r = v.indexOf(pdbe[i]);
1302 if (r == -1 || r >= pdbentry.length)
1304 rtn.addElement(new int[]
1306 v.addElement(pdbe[i]);
1310 // just make sure the sequence/chain entries are all up to date
1311 addSequenceAndChain(r, seq[i], chns[i]);
1314 pdbe = new PDBEntry[v.size()];
1319 // expand the tied seuqence[] and string[] arrays
1320 SequenceI[][] sqs = new SequenceI[pdbentry.length][];
1321 String[][] sch = new String[pdbentry.length][];
1322 System.arraycopy(sequence, 0, sqs, 0, sequence.length);
1323 System.arraycopy(chains, 0, sch, 0, this.chains.length);
1326 pdbe = new PDBEntry[rtn.size()];
1327 for (int r = 0; r < pdbe.length; r++)
1329 int[] stri = ((int[]) rtn.elementAt(r));
1330 // record the pdb file as a new addition
1331 pdbe[r] = pdbentry[stri[0]];
1332 // and add the new sequence/chain entries
1333 addSequenceAndChain(stri[0], seq[stri[1]], chns[stri[1]]);
1343 public void addSequence(int pe, SequenceI[] seq)
1345 // add sequences to the pe'th pdbentry's seuqence set.
1346 addSequenceAndChain(pe, seq, null);
1349 private void addSequenceAndChain(int pe, SequenceI[] seq, String[] tchain)
1351 if (pe < 0 || pe >= pdbentry.length)
1354 "Implementation error - no corresponding pdbentry (for index "
1355 + pe + ") to add sequences mappings to");
1357 final String nullChain = "TheNullChain";
1358 Vector s = new Vector();
1359 Vector c = new Vector();
1362 chains = new String[pdbentry.length][];
1364 if (sequence[pe] != null)
1366 for (int i = 0; i < sequence[pe].length; i++)
1368 s.addElement(sequence[pe][i]);
1369 if (chains[pe] != null)
1371 if (i < chains[pe].length)
1373 c.addElement(chains[pe][i]);
1377 c.addElement(nullChain);
1382 if (tchain != null && tchain.length > 0)
1384 c.addElement(nullChain);
1389 for (int i = 0; i < seq.length; i++)
1391 if (!s.contains(seq[i]))
1393 s.addElement(seq[i]);
1394 if (tchain != null && i < tchain.length)
1396 c.addElement(tchain[i] == null ? nullChain : tchain[i]);
1400 SequenceI[] tmp = new SequenceI[s.size()];
1405 String[] tch = new String[c.size()];
1407 for (int i = 0; i < tch.length; i++)
1409 if (tch[i] == nullChain)
1425 * @return text report of alignment between pdbfile and any associated
1426 * alignment sequences
1428 public String printMapping(String pdbfile)
1430 return ssm.printMapping(pdbfile);