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.LinkedHashMap;
48 import java.util.List;
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 static final String PHOSPHORUS = "P";
63 private static final String ALPHACARBON = "CA";
65 private StructureManager csm;
67 private ChimeraManager viewer;
70 * set if chimera state is being restored from some source - instructs binding
71 * not to apply default display style when structure set is updated for first
74 private boolean loadingFromArchive = false;
77 * second flag to indicate if the jmol viewer should ignore sequence colouring
78 * events from the structure manager because the GUI is still setting up
80 private boolean loadingFinished = true;
83 * state flag used to check if the Jmol viewer's paint method can be called
85 private boolean finishedInit = false;
87 public boolean isFinishedInit()
92 public void setFinishedInit(boolean finishedInit)
94 this.finishedInit = finishedInit;
97 boolean allChainsSelected = false;
100 * when true, try to search the associated datamodel for sequences that are
101 * associated with any unknown structures in the Chimera view.
103 private boolean associateNewStructs = false;
105 List<String> atomsPicked = new ArrayList<String>();
107 public List<String> chainNames;
109 private Map<String, String> chainFile;
112 * array of target chains for sequences - tied to pdbentry and sequence[]
114 protected String[][] chains;
116 boolean colourBySequence = true;
118 StringBuffer eval = new StringBuffer();
120 public String fileLoadingError;
122 private Map<String, List<ChimeraModel>> chimmaps = new LinkedHashMap<String, List<ChimeraModel>>();
124 private List<String> mdlToFile = new ArrayList<String>();
127 * the default or current model displayed if the model cannot be identified
128 * from the selection message
136 boolean loadedInline;
138 public boolean openFile(PDBEntry pe)
140 String file = pe.getFile();
143 List<ChimeraModel> oldList = viewer.getModelList();
144 viewer.openModel(file, pe.getId(), ModelType.PDB_MODEL);
145 List<ChimeraModel> newList = viewer.getModelList();
146 if (oldList.size() < newList.size())
148 while (oldList.size() > 0)
153 chimmaps.put(file, newList);
154 for (ChimeraModel cm : newList)
156 while (mdlToFile.size() < 1 + cm.getModelNumber())
158 mdlToFile.add(new String(""));
160 mdlToFile.set(cm.getModelNumber(), file);
163 File fl = new File(file);
164 String protocol = AppletFormatAdapter.URL;
169 protocol = AppletFormatAdapter.FILE;
171 } catch (Exception e)
176 // Explicitly map to the filename used by Jmol ;
177 // pdbentry[pe].getFile(), protocol);
181 ssm.addStructureViewerListener(this);
182 // ssm.addSelectionListener(this);
183 FeatureRenderer fr = getFeatureRenderer(null);
192 } catch (Exception q)
194 log("Exception when trying to open model " + file + "\n"
202 * current set of model filenames loaded
204 String[] modelFileNames = null;
206 public PDBEntry[] pdbentry;
209 * datasource protocol for access to PDBEntrylatest
211 String protocol = null;
213 StringBuffer resetLastRes = new StringBuffer();
216 * sequences mapped to each pdbentry
218 public SequenceI[][] sequence;
220 public StructureSelectionManager ssm;
222 private List<String> lastReply;
224 public JalviewChimeraBinding(StructureSelectionManager ssm,
225 PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains,
229 this.sequence = sequenceIs;
230 this.chains = chains;
231 this.pdbentry = pdbentry;
232 this.protocol = protocol;
235 this.chains = new String[pdbentry.length][];
237 viewer = new ChimeraManager(
238 csm = new ext.edu.ucsf.rbvi.strucviz2.StructureManager(true));
240 * viewer = JmolViewer.allocateViewer(renderPanel, new SmarterJmolAdapter(),
241 * "jalviewJmol", ap.av.applet .getDocumentBase(),
242 * ap.av.applet.getCodeBase(), "", this);
244 * jmolpopup = JmolPopup.newJmolPopup(viewer, true, "Jmol", true);
248 public JalviewChimeraBinding(StructureSelectionManager ssm,
249 ChimeraManager viewer2)
253 csm = viewer.getStructureManager();
257 * construct a title string for the viewer window based on the data jalview
262 public String getViewerTitle()
264 if (sequence == null || pdbentry == null || sequence.length < 1
265 || pdbentry.length < 1 || sequence[0].length < 1)
267 return ("Jalview Chimera Window");
269 // TODO: give a more informative title when multiple structures are
271 StringBuffer title = new StringBuffer("Chimera view for "
272 + sequence[0][0].getName() + ":" + pdbentry[0].getId());
274 if (pdbentry[0].getProperty() != null)
276 if (pdbentry[0].getProperty().get("method") != null)
278 title.append(" Method: ");
279 title.append(pdbentry[0].getProperty().get("method"));
281 if (pdbentry[0].getProperty().get("chains") != null)
283 title.append(" Chain:");
284 title.append(pdbentry[0].getProperty().get("chains"));
287 return title.toString();
291 * prepare the view for a given set of models/chains. chainList contains
292 * strings of the form 'pdbfilename:Chaincode'
295 * list of chains to make visible
297 public void centerViewer(List<String> toshow)
299 StringBuilder cmd = new StringBuilder(64);
301 for (String lbl : toshow)
307 mlength = lbl.indexOf(":", p);
308 } while (p < mlength && mlength < (lbl.length() - 2));
309 // TODO: lookup each pdb id and recover proper model number for it.
310 cmd.append("#" + getModelNum(chainFile.get(lbl)) + "."
311 + lbl.substring(mlength + 1) + " or ");
313 if (cmd.length() > 0)
315 cmd.setLength(cmd.length() - 4);
317 String cmdstring = cmd.toString();
318 evalStateCommand("~display #*; ~ribbon #*; ribbon " + cmdstring
319 + ";focus " + cmdstring, false);
322 public void closeViewer()
324 ssm.removeStructureViewerListener(this, this.getPdbFile());
325 // and shut down Chimera
326 viewer.exitChimera();
327 // viewer.evalStringQuiet("zap");
328 // viewer.setJmolStatusListener(null);
331 releaseUIResources();
335 * called by JalviewJmolbinding after closeViewer is called - release any
336 * resources and references so they can be garbage collected.
338 protected abstract void releaseUIResources();
340 public void colourByChain()
342 colourBySequence = false;
343 // TODO: colour by chain should colour each chain distinctly across all
345 // TODO: http://issues.jalview.org/browse/JAL-628
346 evalStateCommand("select *;color chain",false);
349 public void colourByCharge()
351 colourBySequence = false;
352 evalStateCommand("colour *;color white;select ASP,GLU;color red;"
353 + "select LYS,ARG;color blue;select CYS;color yellow", false);
357 * superpose the structures associated with sequences in the alignment
358 * according to their corresponding positions.
360 public void superposeStructures(AlignmentI alignment)
362 superposeStructures(alignment, -1, null);
366 * superpose the structures associated with sequences in the alignment
367 * according to their corresponding positions. ded)
369 * @param refStructure
370 * - select which pdb file to use as reference (default is -1 - the
371 * first structure in the alignment)
373 public void superposeStructures(AlignmentI alignment, int refStructure)
375 superposeStructures(alignment, refStructure, null);
379 * superpose the structures associated with sequences in the alignment
380 * according to their corresponding positions. ded)
382 * @param refStructure
383 * - select which pdb file to use as reference (default is -1 - the
384 * first structure in the alignment)
388 public void superposeStructures(AlignmentI alignment, int refStructure,
389 ColumnSelection hiddenCols)
391 superposeStructures(new AlignmentI[]
392 { alignment }, new int[]
393 { refStructure }, new ColumnSelection[]
397 public void superposeStructures(AlignmentI[] _alignment,
398 int[] _refStructure, ColumnSelection[] _hiddenCols)
400 assert (_alignment.length == _refStructure.length && _alignment.length != _hiddenCols.length);
401 StringBuilder allComs = new StringBuilder(128); // Chimera superposition cmd
402 String[] files = getPdbFile();
403 // check to see if we are still waiting for Jmol files
404 long starttime = System.currentTimeMillis();
405 boolean waiting = true;
409 for (String file : files)
413 // HACK - in Jalview 2.8 this call may not be threadsafe so we catch
414 // every possible exception
415 StructureMapping[] sm = ssm.getMapping(file);
416 if (sm == null || sm.length == 0)
420 } catch (Exception x)
428 // we wait around for a reasonable time before we give up
430 && System.currentTimeMillis() < (10000 + 1000 * files.length + starttime));
434 .println("RUNTIME PROBLEM: Chimera seems to be taking a long time to process all the structures.");
438 StringBuffer selectioncom = new StringBuffer();
439 for (int a = 0; a < _alignment.length; a++)
441 int refStructure = _refStructure[a];
442 AlignmentI alignment = _alignment[a];
443 ColumnSelection hiddenCols = _hiddenCols[a];
445 && selectioncom.length() > 0
446 && !selectioncom.substring(selectioncom.length() - 1).equals(
449 selectioncom.append(" ");
451 // process this alignment
452 if (refStructure >= files.length)
454 System.err.println("Invalid reference structure value "
458 if (refStructure < -1)
463 boolean matched[] = new boolean[alignment.getWidth()];
464 for (int m = 0; m < matched.length; m++)
467 matched[m] = (hiddenCols != null) ? hiddenCols.isVisible(m) : true;
470 int commonrpositions[][] = new int[files.length][alignment.getWidth()];
471 String isel[] = new String[files.length];
472 String[] targetC = new String[files.length];
473 String[] chainNames = new String[files.length];
474 String[] atomSpec = new String[files.length];
475 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
477 StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
478 // RACE CONDITION - getMapping only returns Jmol loaded filenames once
479 // Jmol callback has completed.
480 if (mapping == null || mapping.length < 1)
482 throw new Error(MessageManager.getString("error.implementation_error_chimera_getting_data"));
485 for (int s = 0; s < sequence[pdbfnum].length; s++)
487 for (int sp, m = 0; m < mapping.length; m++)
489 if (mapping[m].getSequence() == sequence[pdbfnum][s]
490 && (sp = alignment.findIndex(sequence[pdbfnum][s])) > -1)
492 if (refStructure == -1)
494 refStructure = pdbfnum;
496 SequenceI asp = alignment.getSequenceAt(sp);
497 for (int r = 0; r < matched.length; r++)
503 matched[r] = false; // assume this is not a good site
504 if (r >= asp.getLength())
509 if (jalview.util.Comparison.isGap(asp.getCharAt(r)))
511 // no mapping to gaps in sequence
514 int t = asp.findPosition(r); // sequence position
515 int apos = mapping[m].getAtomNum(t);
516 int pos = mapping[m].getPDBResNum(t);
518 if (pos < 1 || pos == lastPos)
520 // can't align unmapped sequence
523 matched[r] = true; // this is a good ite
525 // just record this residue position
526 commonrpositions[pdbfnum][r] = pos;
528 // create model selection suffix
529 isel[pdbfnum] = "#" + pdbfnum;
530 if (mapping[m].getChain() == null
531 || mapping[m].getChain().trim().length() == 0)
533 targetC[pdbfnum] = "";
537 targetC[pdbfnum] = "." + mapping[m].getChain();
539 chainNames[pdbfnum] = mapping[m].getPdbId()
541 atomSpec[pdbfnum] = asp.getRNA() != null ? PHOSPHORUS : ALPHACARBON;
542 // move on to next pdb file
543 s = sequence[pdbfnum].length;
550 // TODO: consider bailing if nmatched less than 4 because superposition
553 // TODO: refactor superposable position search (above) from jmol selection
554 // construction (below)
556 String[] selcom = new String[files.length];
559 // generate select statements to select regions to superimpose structures
561 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
563 String chainCd = targetC[pdbfnum];
566 StringBuffer molsel = new StringBuffer();
567 for (int r = 0; r < matched.length; r++)
575 if (lpos != commonrpositions[pdbfnum][r] - 1)
580 molsel.append((run ? "" : ":") + lpos);
581 molsel.append(chainCd);
587 // continuous run - and lpos >-1
590 // at the beginning, so add dash
591 molsel.append(":" + lpos);
596 lpos = commonrpositions[pdbfnum][r];
597 // molsel.append(lpos);
600 // add final selection phrase
603 molsel.append((run ? "" : ":") + lpos);
604 molsel.append(chainCd);
605 // molsel.append("");
607 if (molsel.length() > 1)
609 selcom[pdbfnum] = molsel.toString();
610 selectioncom.append("#" + pdbfnum);
611 selectioncom.append(selcom[pdbfnum]);
612 selectioncom.append(" ");
613 if (pdbfnum < files.length - 1)
615 selectioncom.append("| ");
620 selcom[pdbfnum] = null;
624 StringBuilder command = new StringBuilder(256);
625 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
627 if (pdbfnum == refStructure || selcom[pdbfnum] == null
628 || selcom[refStructure] == null)
632 if (command.length() > 0)
638 * Form Chimera match command, from the 'new' structure to the
639 * 'reference' structure e.g. (residues 1-91, chain B/A, alphacarbons):
641 * match #1:1-91.B@CA #0:1-91.A@CA
644 * https://www.cgl.ucsf.edu/chimera/docs/UsersGuide/midas/match.html
646 command.append("match #" + pdbfnum /* +".1" */);
647 // TODO: handle sub-models
648 command.append(selcom[pdbfnum]);
649 command.append("@" + atomSpec[pdbfnum]);
650 command.append(" #" + refStructure /* +".1" */);
651 command.append(selcom[refStructure]);
652 command.append("@" + atomSpec[refStructure]);
654 if (selectioncom.length() > 0)
656 // TODO remove debug output
657 System.out.println("Select regions:\n" + selectioncom.toString());
659 .println("Superimpose command(s):\n" + command.toString());
660 allComs.append("~display all; chain @CA|P; ribbon "
661 + selectioncom.toString() + ";"+command.toString());
662 // selcom.append("; ribbons; ");
665 if (selectioncom.length() > 0)
666 {// finally, mark all regions that were superposed.
667 if (selectioncom.substring(selectioncom.length() - 1).equals("|"))
669 selectioncom.setLength(selectioncom.length() - 1);
671 System.out.println("Select regions:\n" + selectioncom.toString());
672 allComs.append("; ~display all; chain @CA|P; ribbon "
673 + selectioncom.toString() + "");
674 // evalStateCommand("select *; backbone; select "+selcom.toString()+"; cartoons; center "+selcom.toString());
675 evalStateCommand(allComs.toString(), true /* false */);
680 private void checkLaunched()
682 if (!viewer.isChimeraLaunched())
684 viewer.launchChimera(csm.getChimeraPaths());
686 if (!viewer.isChimeraLaunched())
688 log("Failed to launch Chimera!");
692 public void evalStateCommand(final String command, boolean resp)
694 viewerCommandHistory(false);
696 if (lastCommand == null || !lastCommand.equals(command))
698 // Thread t = new Thread(new Runnable()
703 // trim command or it may never find a match in the replyLog!!
704 lastReply = viewer.sendChimeraCommand(command.trim(), resp);
707 log("Response from command ('" + command + "') was:\n"
712 // TODO - use j7/8 thread management
716 // } catch (InterruptedException foo)
721 viewerCommandHistory(true);
722 lastCommand = command;
726 * colour any structures associated with sequences in the given alignment
727 * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
728 * if colourBySequence is enabled.
730 public void colourBySequence(boolean showFeatures,
731 jalview.api.AlignmentViewPanel alignmentv)
733 if (!colourBySequence || !loadingFinished)
741 String[] files = getPdbFile();
743 SequenceRenderer sr = getSequenceRenderer(alignmentv);
745 FeatureRenderer fr = null;
748 fr = getFeatureRenderer(alignmentv);
750 AlignmentI alignment = alignmentv.getAlignment();
752 for (jalview.structure.StructureMappingcommandSet cpdbbyseq : ChimeraCommands
753 .getColourBySequenceCommand(ssm, files, sequence, sr, fr,
756 for (String cbyseq : cpdbbyseq.commands)
759 evalStateCommand(cbyseq, false);
765 private void waitForChimera()
767 while (viewer.isBusy())
771 } catch (InterruptedException q)
776 public boolean isColourBySequence()
778 return colourBySequence;
781 public void setColourBySequence(boolean colourBySequence)
783 this.colourBySequence = colourBySequence;
786 // End StructureListener
787 // //////////////////////////
789 public float[][] functionXY(String functionName, int x, int y)
794 public float[][][] functionXYZ(String functionName, int nx, int ny, int nz)
796 // TODO Auto-generated method stub
800 public Color getColour(int atomIndex, int pdbResNum, String chain,
803 if (getModelNum(pdbfile) < 0)
807 log("get model / residue colour attribute unimplemented");
812 * returns the current featureRenderer that should be used to colour the
819 public abstract FeatureRenderer getFeatureRenderer(
820 AlignmentViewPanel alignment);
823 * instruct the Jalview binding to update the pdbentries vector if necessary
824 * prior to matching the jmol view's contents to the list of structure files
825 * Jalview knows about.
827 public abstract void refreshPdbEntries();
829 private int getModelNum(String modelFileName)
831 String[] mfn = getPdbFile();
836 for (int i = 0; i < mfn.length; i++)
838 if (mfn[i].equalsIgnoreCase(modelFileName))
847 * map between index of model filename returned from getPdbFile and the first
848 * index of models from this file in the viewer. Note - this is not trimmed -
849 * use getPdbFile to get number of unique models.
851 private int _modelFileNameMap[];
853 // ////////////////////////////////
854 // /StructureListener
855 public synchronized String[] getPdbFile()
859 return new String[0];
861 // if (modelFileNames == null)
863 // Collection<ChimeraModel> chimodels = viewer.getChimeraModels();
864 // _modelFileNameMap = new int[chimodels.size()];
866 // for (ChimeraModel chimodel : chimodels)
868 // String mdlName = chimodel.getModelName();
870 // modelFileNames = new String[j];
871 // // System.arraycopy(mset, 0, modelFileNames, 0, j);
874 return chimmaps.keySet().toArray(
875 modelFileNames = new String[chimmaps.size()]);
879 * map from string to applet
881 public Map getRegistryInfo()
883 // TODO Auto-generated method stub
888 * returns the current sequenceRenderer that should be used to colour the
895 public abstract SequenceRenderer getSequenceRenderer(
896 AlignmentViewPanel alignment);
899 public void highlightAtom(int atomIndex, int pdbResNum, String chain,
902 List<ChimeraModel> cms = chimmaps.get(pdbfile);
905 int mdlNum = cms.get(0).getModelNumber();
907 viewerCommandHistory(false);
908 // viewer.stopListening();
909 if (resetLastRes.length() > 0)
912 eval.append(resetLastRes.toString() + ";");
915 eval.append("display "); // +modelNum
917 resetLastRes.setLength(0);
918 resetLastRes.append("~display ");
920 eval.append(" #" + (mdlNum));
921 resetLastRes.append(" #" + (mdlNum));
923 // complete select string
925 eval.append(":" + pdbResNum);
926 resetLastRes.append(":" + pdbResNum);
927 if (!chain.equals(" "))
929 eval.append("." + chain);
930 resetLastRes.append("." + chain);
933 viewer.sendChimeraCommand(eval.toString(), false);
934 viewerCommandHistory(true);
935 // viewer.startListening();
939 boolean debug = true;
941 private void log(String message)
943 System.err.println("## Chimera log: " + message);
946 private void viewerCommandHistory(boolean enable)
948 log("(Not yet implemented) History "
949 + ((debug || enable) ? "on" : "off"));
952 public void loadInline(String string)
956 // viewer.loadInline(strModel, isAppend);
958 // construct fake fullPathName and fileName so we can identify the file
960 // Then, construct pass a reader for the string to Jmol.
961 // ((org.jmol.Viewer.Viewer) viewer).loadModelFromFile(fullPathName,
962 // fileName, null, reader, false, null, null, 0);
963 // viewer.openStringInline(string);
964 log("cannot load inline in Chimera, yet");
967 public void mouseOverStructure(int atomIndex, String strInfo)
969 // function to parse a mouseOver event from Chimera
972 int alocsep = strInfo.indexOf("^");
973 int mdlSep = strInfo.indexOf("/");
974 int chainSeparator = strInfo.indexOf(":"), chainSeparator1 = -1;
976 if (chainSeparator == -1)
978 chainSeparator = strInfo.indexOf(".");
979 if (mdlSep > -1 && mdlSep < chainSeparator)
981 chainSeparator1 = chainSeparator;
982 chainSeparator = mdlSep;
985 // handle insertion codes
988 pdbResNum = Integer.parseInt(strInfo.substring(
989 strInfo.indexOf("]") + 1, alocsep));
994 pdbResNum = Integer.parseInt(strInfo.substring(
995 strInfo.indexOf("]") + 1, chainSeparator));
999 if (strInfo.indexOf(":") > -1)
1001 chainId = strInfo.substring(strInfo.indexOf(":") + 1,
1002 strInfo.indexOf("."));
1009 String pdbfilename = modelFileNames[frameNo]; // default is first or current
1013 if (chainSeparator1 == -1)
1015 chainSeparator1 = strInfo.indexOf(".", mdlSep);
1017 String mdlId = (chainSeparator1 > -1) ? strInfo.substring(mdlSep + 1,
1018 chainSeparator1) : strInfo.substring(mdlSep + 1);
1021 // recover PDB filename for the model hovered over.
1022 int _mp = _modelFileNameMap.length - 1, mnumber = new Integer(mdlId)
1024 while (mnumber < _modelFileNameMap[_mp])
1028 pdbfilename = modelFileNames[_mp];
1029 if (pdbfilename == null)
1031 // pdbfilename = new File(viewer.getModelFileName(mnumber))
1032 // .getAbsolutePath();
1035 } catch (Exception e)
1040 if (lastMessage == null || !lastMessage.equals(strInfo))
1042 ssm.mouseOverStructure(pdbResNum, chainId, pdbfilename);
1045 lastMessage = strInfo;
1048 public void notifyAtomPicked(int atomIndex, String strInfo, String strData)
1051 * this implements the toggle label behaviour copied from the original
1052 * structure viewer, MCView
1054 if (strData != null)
1056 System.err.println("Ignoring additional pick data string " + strData);
1058 // rewrite these selections for chimera (DNA, RNA and protein)
1059 int chainSeparator = strInfo.indexOf(":");
1061 if (chainSeparator == -1)
1063 chainSeparator = strInfo.indexOf(".");
1066 String picked = strInfo.substring(strInfo.indexOf("]") + 1,
1068 String mdlString = "";
1069 if ((p = strInfo.indexOf(":")) > -1)
1071 picked += strInfo.substring(p + 1, strInfo.indexOf("."));
1074 if ((p = strInfo.indexOf("/")) > -1)
1076 mdlString += strInfo.substring(p, strInfo.indexOf(" #"));
1078 picked = "((" + picked + ".CA" + mdlString + ")|(" + picked + ".P"
1080 viewerCommandHistory(false);
1082 if (!atomsPicked.contains(picked))
1084 viewer.select(picked);
1085 atomsPicked.add(picked);
1089 viewer.select("not " + picked);
1090 atomsPicked.remove(picked);
1092 viewerCommandHistory(true);
1093 // TODO: in application this happens
1095 // if (scriptWindow != null)
1097 // scriptWindow.sendConsoleMessage(strInfo);
1098 // scriptWindow.sendConsoleMessage("\n");
1103 // incremented every time a load notification is successfully handled -
1104 // lightweight mechanism for other threads to detect when they can start
1105 // referring to new structures.
1106 private long loadNotifiesHandled = 0;
1108 public long getLoadNotifiesHandled()
1110 return loadNotifiesHandled;
1113 public void notifyFileLoaded(String fullPathName, String fileName2,
1114 String modelName, String errorMsg, int modelParts)
1116 if (errorMsg != null)
1118 fileLoadingError = errorMsg;
1122 // TODO: deal sensibly with models loaded inLine:
1123 // modelName will be null, as will fullPathName.
1125 // the rest of this routine ignores the arguments, and simply interrogates
1126 // the Jmol view to find out what structures it contains, and adds them to
1127 // the structure selection manager.
1128 fileLoadingError = null;
1129 String[] oldmodels = modelFileNames;
1130 modelFileNames = null;
1131 chainNames = new ArrayList<String>();
1132 chainFile = new HashMap<String, String>();
1133 boolean notifyLoaded = false;
1134 String[] modelfilenames = getPdbFile();
1135 // first check if we've lost any structures
1136 if (oldmodels != null && oldmodels.length > 0)
1139 for (int i = 0; i < oldmodels.length; i++)
1141 for (int n = 0; n < modelfilenames.length; n++)
1143 if (modelfilenames[n] == oldmodels[i])
1145 oldmodels[i] = null;
1149 if (oldmodels[i] != null)
1156 String[] oldmfn = new String[oldm];
1158 for (int i = 0; i < oldmodels.length; i++)
1160 if (oldmodels[i] != null)
1162 oldmfn[oldm++] = oldmodels[i];
1165 // deregister the Jmol instance for these structures - we'll add
1166 // ourselves again at the end for the current structure set.
1167 ssm.removeStructureViewerListener(this, oldmfn);
1171 // register ourselves as a listener and notify the gui that it needs to
1173 ssm.addStructureViewerListener(this);
1177 FeatureRenderer fr = getFeatureRenderer(null);
1183 loadNotifiesHandled++;
1185 setLoadingFromArchive(false);
1188 public void setJalviewColourScheme(ColourSchemeI cs)
1190 colourBySequence = false;
1200 viewerCommandHistory(false);
1201 // TODO: Switch between nucleotide or aa selection expressions
1202 Enumeration en = ResidueProperties.aa3Hash.keys();
1203 StringBuffer command = new StringBuffer("select *;color white;");
1204 while (en.hasMoreElements())
1206 res = en.nextElement().toString();
1207 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(),false);
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)
1305 List<PDBEntry> v = new ArrayList<PDBEntry>();
1306 List<int[]> rtn = new ArrayList<int[]>();
1307 for (int i = 0; i < pdbentry.length; i++)
1311 for (int i = 0; i < pdbe.length; i++)
1313 int r = v.indexOf(pdbe[i]);
1314 if (r == -1 || r >= pdbentry.length)
1322 // just make sure the sequence/chain entries are all up to date
1323 addSequenceAndChain(r, seq[i], chns[i]);
1326 pdbe = v.toArray(new PDBEntry[v.size()]);
1330 // expand the tied sequence[] and string[] arrays
1331 SequenceI[][] sqs = new SequenceI[pdbentry.length][];
1332 String[][] sch = new String[pdbentry.length][];
1333 System.arraycopy(sequence, 0, sqs, 0, sequence.length);
1334 System.arraycopy(chains, 0, sch, 0, this.chains.length);
1337 pdbe = new PDBEntry[rtn.size()];
1338 for (int r = 0; r < pdbe.length; r++)
1340 int[] stri = (rtn.get(r));
1341 // record the pdb file as a new addition
1342 pdbe[r] = pdbentry[stri[0]];
1343 // and add the new sequence/chain entries
1344 addSequenceAndChain(stri[0], seq[stri[1]], chns[stri[1]]);
1355 * Adds sequences to the pe'th pdbentry's sequence set.
1360 public void addSequence(int pe, SequenceI[] seq)
1362 addSequenceAndChain(pe, seq, null);
1365 private void addSequenceAndChain(int pe, SequenceI[] seq, String[] tchain)
1367 if (pe < 0 || pe >= pdbentry.length)
1369 throw new Error(MessageManager.formatMessage(
1370 "error.implementation_error_no_pdbentry_from_index",
1372 { Integer.valueOf(pe).toString() }));
1374 final String nullChain = "TheNullChain";
1375 List<SequenceI> s = new ArrayList<SequenceI>();
1376 List<String> c = new ArrayList<String>();
1379 chains = new String[pdbentry.length][];
1381 if (sequence[pe] != null)
1383 for (int i = 0; i < sequence[pe].length; i++)
1385 s.add(sequence[pe][i]);
1386 if (chains[pe] != null)
1388 if (i < chains[pe].length)
1390 c.add(chains[pe][i]);
1399 if (tchain != null && tchain.length > 0)
1406 for (int i = 0; i < seq.length; i++)
1408 if (!s.contains(seq[i]))
1411 if (tchain != null && i < tchain.length)
1413 c.add(tchain[i] == null ? nullChain : tchain[i]);
1417 SequenceI[] tmp = s.toArray(new SequenceI[s.size()]);
1421 String[] tch = c.toArray(new String[c.size()]);
1422 for (int i = 0; i < tch.length; i++)
1424 if (tch[i] == nullChain)
1440 * @return text report of alignment between pdbfile and any associated
1441 * alignment sequences
1443 public String printMapping(String pdbfile)
1445 return ssm.printMapping(pdbfile);