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;
39 import jalview.util.MessageManager;
41 import java.awt.Color;
42 import java.awt.event.ComponentEvent;
44 import java.util.ArrayList;
45 import java.util.Enumeration;
46 import java.util.HashMap;
47 import java.util.Hashtable;
48 import java.util.List;
50 import java.util.Vector;
52 import ext.edu.ucsf.rbvi.strucviz2.ChimeraManager;
53 import ext.edu.ucsf.rbvi.strucviz2.ChimeraModel;
54 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
55 import ext.edu.ucsf.rbvi.strucviz2.StructureManager.ModelType;
57 public abstract class JalviewChimeraBinding extends
58 SequenceStructureBindingModel implements StructureListener,
59 SequenceStructureBinding, StructureSelectionManagerProvider
62 private StructureManager csm;
64 private ChimeraManager viewer;
67 * set if chimera state is being restored from some source - instructs binding
68 * not to apply default display style when structure set is updated for first
71 private boolean loadingFromArchive = false;
74 * second flag to indicate if the jmol viewer should ignore sequence colouring
75 * events from the structure manager because the GUI is still setting up
77 private boolean loadingFinished = true;
80 * state flag used to check if the Jmol viewer's paint method can be called
82 private boolean finishedInit = false;
84 public boolean isFinishedInit()
89 public void setFinishedInit(boolean finishedInit)
91 this.finishedInit = finishedInit;
94 boolean allChainsSelected = false;
97 * when true, try to search the associated datamodel for sequences that are
98 * associated with any unknown structures in the Jmol view.
100 private boolean associateNewStructs = false;
102 Vector atomsPicked = new Vector();
104 public Vector chainNames;
109 * array of target chains for seuqences - tied to pdbentry and sequence[]
111 protected String[][] chains;
113 boolean colourBySequence = true;
115 StringBuffer eval = new StringBuffer();
117 public String fileLoadingError;
119 private Map<String, List<ChimeraModel>> chimmaps = new HashMap<String, List<ChimeraModel>>();
121 private List<String> mdlToFile = new ArrayList<String>();
124 * the default or current model displayed if the model cannot be identified
125 * from the selection message
133 boolean loadedInline;
135 public boolean openFile(PDBEntry pe)
137 String file = pe.getFile();
140 List<ChimeraModel> oldList = viewer.getModelList();
141 viewer.openModel(file, ModelType.PDB_MODEL);
142 List<ChimeraModel> newList = viewer.getModelList();
143 if (oldList.size() < newList.size())
145 while (oldList.size() > 0)
150 chimmaps.put(file, newList);
151 for (ChimeraModel cm : newList)
153 while (mdlToFile.size() < 1 + cm.getModelNumber())
155 mdlToFile.add(new String(""));
157 mdlToFile.set(cm.getModelNumber(), file);
160 File fl = new File(file);
161 String protocol = AppletFormatAdapter.URL;
166 protocol = AppletFormatAdapter.FILE;
168 } catch (Exception e)
173 // Explicitly map to the filename used by Jmol ;
174 // pdbentry[pe].getFile(), protocol);
178 ssm.addStructureViewerListener(this);
179 // ssm.addSelectionListener(this);
180 FeatureRenderer fr = getFeatureRenderer(null);
189 } catch (Exception q)
191 log("Exception when trying to open model " + file + "\n"
199 * current set of model filenames loaded
201 String[] modelFileNames = null;
203 public PDBEntry[] pdbentry;
206 * datasource protocol for access to PDBEntrylatest
208 String protocol = null;
210 StringBuffer resetLastRes = new StringBuffer();
213 * sequences mapped to each pdbentry
215 public SequenceI[][] sequence;
217 public StructureSelectionManager ssm;
219 private List<String> lastReply;
221 public JalviewChimeraBinding(StructureSelectionManager ssm,
222 PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains,
226 this.sequence = sequenceIs;
227 this.chains = chains;
228 this.pdbentry = pdbentry;
229 this.protocol = protocol;
232 this.chains = new String[pdbentry.length][];
234 viewer = new ChimeraManager(
235 csm = new ext.edu.ucsf.rbvi.strucviz2.StructureManager(true));
237 * viewer = JmolViewer.allocateViewer(renderPanel, new SmarterJmolAdapter(),
238 * "jalviewJmol", ap.av.applet .getDocumentBase(),
239 * ap.av.applet.getCodeBase(), "", this);
241 * jmolpopup = JmolPopup.newJmolPopup(viewer, true, "Jmol", true);
245 public JalviewChimeraBinding(StructureSelectionManager ssm,
246 ChimeraManager viewer2)
250 csm = viewer.getStructureManager();
254 * construct a title string for the viewer window based on the data jalview
259 public String getViewerTitle()
261 if (sequence == null || pdbentry == null || sequence.length < 1
262 || pdbentry.length < 1 || sequence[0].length < 1)
264 return ("Jalview Chimera Window");
266 // TODO: give a more informative title when multiple structures are
268 StringBuffer title = new StringBuffer("Chimera view for "
269 + sequence[0][0].getName() + ":" + pdbentry[0].getId());
271 if (pdbentry[0].getProperty() != null)
273 if (pdbentry[0].getProperty().get("method") != null)
275 title.append(" Method: ");
276 title.append(pdbentry[0].getProperty().get("method"));
278 if (pdbentry[0].getProperty().get("chains") != null)
280 title.append(" Chain:");
281 title.append(pdbentry[0].getProperty().get("chains"));
284 return title.toString();
288 * prepare the view for a given set of models/chains. chainList contains
289 * strings of the form 'pdbfilename:Chaincode'
292 * list of chains to make visible
294 public void centerViewer(Vector chainList)
296 StringBuffer cmd = new StringBuffer();
299 for (int i = 0, iSize = chainList.size(); i < iSize; i++)
302 lbl = (String) chainList.elementAt(i);
306 mlength = lbl.indexOf(":", p);
307 } while (p < mlength && mlength < (lbl.length() - 2));
308 // TODO: lookup each pdb id and recover proper model number for it.
309 cmd.append("#" + getModelNum((String) chainFile.get(lbl)) + "."
310 + lbl.substring(mlength + 1) + " or ");
312 if (cmd.length() > 0)
313 cmd.setLength(cmd.length() - 4);
314 evalStateCommand("~display #*; ~ribbon #*; ribbon " + cmd + ";focus "
318 public void closeViewer()
320 ssm.removeStructureViewerListener(this, this.getPdbFile());
321 // and shut down Chimera
322 viewer.exitChimera();
323 // viewer.evalStringQuiet("zap");
324 // viewer.setJmolStatusListener(null);
327 releaseUIResources();
331 * called by JalviewJmolbinding after closeViewer is called - release any
332 * resources and references so they can be garbage collected.
334 protected abstract void releaseUIResources();
336 public void colourByChain()
338 colourBySequence = false;
339 // TODO: colour by chain should colour each chain distinctly across all
341 // TODO: http://issues.jalview.org/browse/JAL-628
342 evalStateCommand("select *;color chain",false);
345 public void colourByCharge()
347 colourBySequence = false;
348 evalStateCommand("colour *;color white;select ASP,GLU;color red;"
349 + "select LYS,ARG;color blue;select CYS;color yellow", false);
353 * superpose the structures associated with sequences in the alignment
354 * according to their corresponding positions.
356 public void superposeStructures(AlignmentI alignment)
358 superposeStructures(alignment, -1, null);
362 * superpose the structures associated with sequences in the alignment
363 * according to their corresponding positions. ded)
365 * @param refStructure
366 * - select which pdb file to use as reference (default is -1 - the
367 * first structure in the alignment)
369 public void superposeStructures(AlignmentI alignment, int refStructure)
371 superposeStructures(alignment, refStructure, null);
375 * superpose the structures associated with sequences in the alignment
376 * according to their corresponding positions. ded)
378 * @param refStructure
379 * - select which pdb file to use as reference (default is -1 - the
380 * first structure in the alignment)
384 public void superposeStructures(AlignmentI alignment, int refStructure,
385 ColumnSelection hiddenCols)
387 superposeStructures(new AlignmentI[]
388 { alignment }, new int[]
389 { refStructure }, new ColumnSelection[]
393 public void superposeStructures(AlignmentI[] _alignment,
394 int[] _refStructure, ColumnSelection[] _hiddenCols)
396 assert (_alignment.length == _refStructure.length && _alignment.length != _hiddenCols.length);
397 StringBuffer allComs = new StringBuffer(); // whole shebang for superposition
398 String[] files = getPdbFile();
399 // check to see if we are still waiting for Jmol files
400 long starttime = System.currentTimeMillis();
401 boolean waiting = true;
405 for (String file : files)
409 // HACK - in Jalview 2.8 this call may not be threadsafe so we catch
410 // every possible exception
411 StructureMapping[] sm = ssm.getMapping(file);
412 if (sm == null || sm.length == 0)
416 } catch (Exception x)
424 // we wait around for a reasonable time before we give up
426 && System.currentTimeMillis() < (10000 + 1000 * files.length + starttime));
430 .println("RUNTIME PROBLEM: Jmol seems to be taking a long time to process all the structures.");
434 StringBuffer selectioncom = new StringBuffer();
435 for (int a = 0; a < _alignment.length; a++)
437 int refStructure = _refStructure[a];
438 AlignmentI alignment = _alignment[a];
439 ColumnSelection hiddenCols = _hiddenCols[a];
441 && selectioncom.length() > 0
442 && !selectioncom.substring(selectioncom.length() - 1).equals(
445 selectioncom.append(" ");
447 // process this alignment
448 if (refStructure >= files.length)
450 System.err.println("Invalid reference structure value "
454 if (refStructure < -1)
458 StringBuffer command = new StringBuffer();
460 boolean matched[] = new boolean[alignment.getWidth()];
461 for (int m = 0; m < matched.length; m++)
464 matched[m] = (hiddenCols != null) ? hiddenCols.isVisible(m) : true;
467 int commonrpositions[][] = new int[files.length][alignment.getWidth()];
468 String isel[] = new String[files.length];
469 // reference structure - all others are superposed in it
470 String[] targetC = new String[files.length];
471 String[] chainNames = new String[files.length];
472 String[] atomS = new String[files.length];
473 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
475 StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
476 // RACE CONDITION - getMapping only returns Jmol loaded filenames once
477 // Jmol callback has completed.
478 if (mapping == null || mapping.length < 1)
480 throw new Error(MessageManager.getString("error.implementation_error_chimera_getting_data"));
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)
1353 throw new Error(MessageManager.formatMessage("error.implementation_error_no_pdbentry_from_index", new String[]{Integer.valueOf(pe).toString()}));
1355 final String nullChain = "TheNullChain";
1356 Vector s = new Vector();
1357 Vector c = new Vector();
1360 chains = new String[pdbentry.length][];
1362 if (sequence[pe] != null)
1364 for (int i = 0; i < sequence[pe].length; i++)
1366 s.addElement(sequence[pe][i]);
1367 if (chains[pe] != null)
1369 if (i < chains[pe].length)
1371 c.addElement(chains[pe][i]);
1375 c.addElement(nullChain);
1380 if (tchain != null && tchain.length > 0)
1382 c.addElement(nullChain);
1387 for (int i = 0; i < seq.length; i++)
1389 if (!s.contains(seq[i]))
1391 s.addElement(seq[i]);
1392 if (tchain != null && i < tchain.length)
1394 c.addElement(tchain[i] == null ? nullChain : tchain[i]);
1398 SequenceI[] tmp = new SequenceI[s.size()];
1403 String[] tch = new String[c.size()];
1405 for (int i = 0; i < tch.length; i++)
1407 if (tch[i] == nullChain)
1423 * @return text report of alignment between pdbfile and any associated
1424 * alignment sequences
1426 public String printMapping(String pdbfile)
1428 return ssm.printMapping(pdbfile);