2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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.bin.Cache;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.ColumnSelection;
29 import jalview.datamodel.PDBEntry;
30 import jalview.datamodel.SequenceI;
31 import jalview.schemes.ColourSchemeI;
32 import jalview.schemes.ResidueProperties;
33 import jalview.structure.StructureMapping;
34 import jalview.structure.StructureMappingcommandSet;
35 import jalview.structure.StructureSelectionManager;
36 import jalview.structures.models.AAStructureBindingModel;
37 import jalview.util.Comparison;
38 import jalview.util.MessageManager;
40 import java.awt.Color;
41 import java.util.ArrayList;
42 import java.util.HashMap;
43 import java.util.LinkedHashMap;
44 import java.util.List;
47 import ext.edu.ucsf.rbvi.strucviz2.ChimeraManager;
48 import ext.edu.ucsf.rbvi.strucviz2.ChimeraModel;
49 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
50 import ext.edu.ucsf.rbvi.strucviz2.StructureManager.ModelType;
52 public abstract class JalviewChimeraBinding extends AAStructureBindingModel
55 private static final boolean debug = false;
57 private static final String PHOSPHORUS = "P";
59 private static final String ALPHACARBON = "CA";
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 * flag to indicate if the Chimera 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 Chimera viewer's paint method can be called
81 private boolean finishedInit = false;
83 private List<String> atomsPicked = new ArrayList<String>();
85 private List<String> chainNames;
87 private Map<String, String> chainFile;
89 public String fileLoadingError;
92 * Map of ChimeraModel objects keyed by PDB full local file name
94 private Map<String, List<ChimeraModel>> chimeraMaps = new LinkedHashMap<String, List<ChimeraModel>>();
97 * the default or current model displayed if the model cannot be identified
98 * from the selection message
100 private int frameNo = 0;
102 private String lastCommand;
104 private String lastMessage;
106 private boolean loadedInline;
109 * current set of model filenames loaded
111 String[] modelFileNames = null;
113 String lastMousedOverAtomSpec;
115 private List<String> lastReply;
118 * Open a PDB structure file in Chimera and set up mappings from Jalview.
120 * We check if the PDB model id is already loaded in Chimera, if so don't
121 * reopen it. This is the case if Chimera has opened a saved session file.
126 public boolean openFile(PDBEntry pe)
128 String file = pe.getFile();
131 List<ChimeraModel> modelsToMap = new ArrayList<ChimeraModel>();
132 List<ChimeraModel> oldList = viewer.getModelList();
133 boolean alreadyOpen = false;
136 * If Chimera already has this model, don't reopen it, but do remap it.
138 for (ChimeraModel open : oldList)
140 if (open.getModelName().equals(pe.getId()))
143 modelsToMap.add(open);
148 * If Chimera doesn't yet have this model, ask it to open it, and retrieve
149 * the model names added by Chimera.
153 viewer.openModel(file, pe.getId(), ModelType.PDB_MODEL);
154 modelsToMap = viewer.getModelList();
155 modelsToMap.removeAll(oldList);
158 chimeraMaps.put(file, modelsToMap);
160 if (getSsm() != null)
162 getSsm().addStructureViewerListener(this);
163 // ssm.addSelectionListener(this);
164 FeatureRenderer fr = getFeatureRenderer(null);
172 } catch (Exception q)
174 log("Exception when trying to open model " + file + "\n"
190 public JalviewChimeraBinding(StructureSelectionManager ssm,
191 PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains,
194 super(ssm, pdbentry, sequenceIs, chains, protocol);
195 viewer = new ChimeraManager(
196 csm = new ext.edu.ucsf.rbvi.strucviz2.StructureManager(true));
205 public JalviewChimeraBinding(StructureSelectionManager ssm,
206 ChimeraManager theViewer)
210 csm = viewer.getStructureManager();
214 * Construct a title string for the viewer window based on the data Jalview
220 public String getViewerTitle(boolean verbose)
222 return getViewerTitle("Chimera", verbose);
226 * prepare the view for a given set of models/chains. chainList contains
227 * strings of the form 'pdbfilename:Chaincode'
230 * list of chains to make visible
232 public void centerViewer(List<String> toshow)
234 StringBuilder cmd = new StringBuilder(64);
236 for (String lbl : toshow)
242 mlength = lbl.indexOf(":", p);
243 } while (p < mlength && mlength < (lbl.length() - 2));
244 // TODO: lookup each pdb id and recover proper model number for it.
245 cmd.append("#" + getModelNum(chainFile.get(lbl)) + "."
246 + lbl.substring(mlength + 1) + " or ");
248 if (cmd.length() > 0)
250 cmd.setLength(cmd.length() - 4);
252 String cmdstring = cmd.toString();
253 evalStateCommand("~display #*; ~ribbon #*; ribbon " + cmdstring
254 + ";focus " + cmdstring, false);
258 * Close down the Jalview viewer, and (optionally) the associated Chimera
261 public void closeViewer(boolean closeChimera)
263 getSsm().removeStructureViewerListener(this, this.getPdbFile());
266 viewer.exitChimera();
270 releaseUIResources();
273 public void colourByChain()
275 colourBySequence = false;
276 evalStateCommand("rainbow chain", false);
279 public void colourByCharge()
281 colourBySequence = false;
283 "color white;color red ::ASP;color red ::GLU;color blue ::LYS;color blue ::ARG;color yellow ::CYS",
288 * superpose the structures associated with sequences in the alignment
289 * according to their corresponding positions.
291 public void superposeStructures(AlignmentI alignment)
293 superposeStructures(alignment, -1, null);
297 * superpose the structures associated with sequences in the alignment
298 * according to their corresponding positions. ded)
300 * @param refStructure
301 * - select which pdb file to use as reference (default is -1 - the
302 * first structure in the alignment)
304 public void superposeStructures(AlignmentI alignment, int refStructure)
306 superposeStructures(alignment, refStructure, null);
310 * superpose the structures associated with sequences in the alignment
311 * according to their corresponding positions. ded)
313 * @param refStructure
314 * - select which pdb file to use as reference (default is -1 - the
315 * first structure in the alignment)
319 public void superposeStructures(AlignmentI alignment, int refStructure,
320 ColumnSelection hiddenCols)
322 superposeStructures(new AlignmentI[]
323 { alignment }, new int[]
324 { refStructure }, new ColumnSelection[]
328 public void superposeStructures(AlignmentI[] _alignment,
329 int[] _refStructure, ColumnSelection[] _hiddenCols)
331 assert (_alignment.length == _refStructure.length && _alignment.length != _hiddenCols.length);
332 StringBuilder allComs = new StringBuilder(128); // Chimera superposition cmd
333 String[] files = getPdbFile();
334 // check to see if we are still waiting for Chimera files
335 long starttime = System.currentTimeMillis();
336 boolean waiting = true;
340 for (String file : files)
344 // HACK - in Jalview 2.8 this call may not be threadsafe so we catch
345 // every possible exception
346 StructureMapping[] sm = getSsm().getMapping(file);
347 if (sm == null || sm.length == 0)
351 } catch (Exception x)
359 // we wait around for a reasonable time before we give up
361 && System.currentTimeMillis() < (10000 + 1000 * files.length + starttime));
365 .println("RUNTIME PROBLEM: Chimera seems to be taking a long time to process all the structures.");
369 StringBuffer selectioncom = new StringBuffer();
370 for (int a = 0; a < _alignment.length; a++)
372 int refStructure = _refStructure[a];
373 AlignmentI alignment = _alignment[a];
374 ColumnSelection hiddenCols = _hiddenCols[a];
376 && selectioncom.length() > 0
377 && !selectioncom.substring(selectioncom.length() - 1).equals(
380 selectioncom.append(" ");
382 // process this alignment
383 if (refStructure >= files.length)
385 System.err.println("Invalid reference structure value "
389 if (refStructure < -1)
394 boolean matched[] = new boolean[alignment.getWidth()];
395 for (int m = 0; m < matched.length; m++)
398 matched[m] = (hiddenCols != null) ? hiddenCols.isVisible(m) : true;
401 int commonrpositions[][] = new int[files.length][alignment.getWidth()];
402 String isel[] = new String[files.length];
403 String[] targetC = new String[files.length];
404 String[] chainNames = new String[files.length];
405 String[] atomSpec = new String[files.length];
406 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
408 StructureMapping[] mapping = getSsm().getMapping(files[pdbfnum]);
409 // RACE CONDITION - getMapping only returns Jmol loaded filenames once
410 // Jmol callback has completed.
411 if (mapping == null || mapping.length < 1)
413 throw new Error(MessageManager.getString("error.implementation_error_chimera_getting_data"));
416 final int seqCountForPdbFile = getSequence()[pdbfnum].length;
417 for (int s = 0; s < seqCountForPdbFile; s++)
419 for (int sp, m = 0; m < mapping.length; m++)
421 final SequenceI theSequence = getSequence()[pdbfnum][s];
422 if (mapping[m].getSequence() == theSequence
423 && (sp = alignment.findIndex(theSequence)) > -1)
425 if (refStructure == -1)
427 refStructure = pdbfnum;
429 SequenceI asp = alignment.getSequenceAt(sp);
430 for (int r = 0; r < matched.length; r++)
436 matched[r] = false; // assume this is not a good site
437 if (r >= asp.getLength())
442 if (Comparison.isGap(asp.getCharAt(r)))
444 // no mapping to gaps in sequence
447 int t = asp.findPosition(r); // sequence position
448 int apos = mapping[m].getAtomNum(t);
449 int pos = mapping[m].getPDBResNum(t);
451 if (pos < 1 || pos == lastPos)
453 // can't align unmapped sequence
456 matched[r] = true; // this is a good ite
458 // just record this residue position
459 commonrpositions[pdbfnum][r] = pos;
461 // create model selection suffix
462 isel[pdbfnum] = "#" + pdbfnum;
463 if (mapping[m].getChain() == null
464 || mapping[m].getChain().trim().length() == 0)
466 targetC[pdbfnum] = "";
470 targetC[pdbfnum] = "." + mapping[m].getChain();
472 chainNames[pdbfnum] = mapping[m].getPdbId()
474 atomSpec[pdbfnum] = asp.getRNA() != null ? PHOSPHORUS : ALPHACARBON;
475 // move on to next pdb file
476 s = seqCountForPdbFile;
483 // TODO: consider bailing if nmatched less than 4 because superposition
486 // TODO: refactor superposable position search (above) from jmol selection
487 // construction (below)
489 String[] selcom = new String[files.length];
492 // generate select statements to select regions to superimpose structures
494 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
496 String chainCd = targetC[pdbfnum];
499 StringBuffer molsel = new StringBuffer();
500 for (int r = 0; r < matched.length; r++)
508 if (lpos != commonrpositions[pdbfnum][r] - 1)
513 molsel.append((run ? "" : ":") + lpos);
514 molsel.append(chainCd);
520 // continuous run - and lpos >-1
523 // at the beginning, so add dash
524 molsel.append(":" + lpos);
529 lpos = commonrpositions[pdbfnum][r];
530 // molsel.append(lpos);
533 // add final selection phrase
536 molsel.append((run ? "" : ":") + lpos);
537 molsel.append(chainCd);
538 // molsel.append("");
540 if (molsel.length() > 1)
542 selcom[pdbfnum] = molsel.toString();
543 selectioncom.append("#" + pdbfnum);
544 selectioncom.append(selcom[pdbfnum]);
545 selectioncom.append(" ");
546 if (pdbfnum < files.length - 1)
548 selectioncom.append("| ");
553 selcom[pdbfnum] = null;
557 StringBuilder command = new StringBuilder(256);
558 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
560 if (pdbfnum == refStructure || selcom[pdbfnum] == null
561 || selcom[refStructure] == null)
565 if (command.length() > 0)
571 * Form Chimera match command, from the 'new' structure to the
572 * 'reference' structure e.g. (residues 1-91, chain B/A, alphacarbons):
574 * match #1:1-91.B@CA #0:1-91.A@CA
577 * https://www.cgl.ucsf.edu/chimera/docs/UsersGuide/midas/match.html
579 command.append("match #" + pdbfnum /* +".1" */);
580 // TODO: handle sub-models
581 command.append(selcom[pdbfnum]);
582 command.append("@" + atomSpec[pdbfnum]);
583 command.append(" #" + refStructure /* +".1" */);
584 command.append(selcom[refStructure]);
585 command.append("@" + atomSpec[refStructure]);
587 if (selectioncom.length() > 0)
591 System.out.println("Select regions:\n" + selectioncom.toString());
592 System.out.println("Superimpose command(s):\n"
593 + command.toString());
595 allComs.append("~display all; chain @CA|P; ribbon "
596 + selectioncom.toString() + ";"+command.toString());
597 // selcom.append("; ribbons; ");
600 if (selectioncom.length() > 0)
601 {// finally, mark all regions that were superposed.
602 if (selectioncom.substring(selectioncom.length() - 1).equals("|"))
604 selectioncom.setLength(selectioncom.length() - 1);
608 System.out.println("Select regions:\n" + selectioncom.toString());
610 allComs.append("; ~display all; chain @CA|P; ribbon "
611 + selectioncom.toString() + "; focus");
612 // evalStateCommand("select *; backbone; select "+selcom.toString()+"; cartoons; center "+selcom.toString());
613 evalStateCommand(allComs.toString(), true /* false */);
618 private void checkLaunched()
620 if (!viewer.isChimeraLaunched())
622 viewer.launchChimera(StructureManager.getChimeraPaths());
624 if (!viewer.isChimeraLaunched())
626 log("Failed to launch Chimera!");
631 * Answers true if the Chimera process is still running, false if ended or not
636 public boolean isChimeraRunning()
638 return viewer.isChimeraLaunched();
642 * Send a command to Chimera, launching it first if necessary, and optionally
648 public void evalStateCommand(final String command, boolean logResponse)
650 viewerCommandHistory(false);
652 if (lastCommand == null || !lastCommand.equals(command))
654 // trim command or it may never find a match in the replyLog!!
655 lastReply = viewer.sendChimeraCommand(command.trim(), logResponse);
656 if (debug && logResponse)
658 log("Response from command ('" + command + "') was:\n" + lastReply);
661 viewerCommandHistory(true);
662 lastCommand = command;
666 * colour any structures associated with sequences in the given alignment
667 * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
668 * if colourBySequence is enabled.
670 public void colourBySequence(boolean showFeatures,
671 jalview.api.AlignmentViewPanel alignmentv)
673 if (!colourBySequence || !loadingFinished)
677 if (getSsm() == null)
681 String[] files = getPdbFile();
683 SequenceRenderer sr = getSequenceRenderer(alignmentv);
685 FeatureRenderer fr = null;
688 fr = getFeatureRenderer(alignmentv);
690 AlignmentI alignment = alignmentv.getAlignment();
692 for (jalview.structure.StructureMappingcommandSet cpdbbyseq : getColourBySequenceCommands(
693 files, sr, fr, alignment))
695 for (String command : cpdbbyseq.commands)
697 executeWhenReady(command);
709 protected StructureMappingcommandSet[] getColourBySequenceCommands(
710 String[] files, SequenceRenderer sr, FeatureRenderer fr,
711 AlignmentI alignment)
713 return ChimeraCommands.getColourBySequenceCommand(getSsm(), files,
714 getSequence(), sr, fr, alignment);
720 protected void executeWhenReady(String command)
723 evalStateCommand(command, false);
727 private void waitForChimera()
729 while (viewer != null && viewer.isBusy())
733 } catch (InterruptedException q)
740 // End StructureListener
741 // //////////////////////////
743 public Color getColour(int atomIndex, int pdbResNum, String chain,
746 if (getModelNum(pdbfile) < 0)
750 log("get model / residue colour attribute unimplemented");
755 * returns the current featureRenderer that should be used to colour the
762 public abstract FeatureRenderer getFeatureRenderer(
763 AlignmentViewPanel alignment);
766 * instruct the Jalview binding to update the pdbentries vector if necessary
767 * prior to matching the jmol view's contents to the list of structure files
768 * Jalview knows about.
770 public abstract void refreshPdbEntries();
772 private int getModelNum(String modelFileName)
774 String[] mfn = getPdbFile();
779 for (int i = 0; i < mfn.length; i++)
781 if (mfn[i].equalsIgnoreCase(modelFileName))
790 * map between index of model filename returned from getPdbFile and the first
791 * index of models from this file in the viewer. Note - this is not trimmed -
792 * use getPdbFile to get number of unique models.
794 private int _modelFileNameMap[];
796 // ////////////////////////////////
797 // /StructureListener
798 public synchronized String[] getPdbFile()
802 return new String[0];
804 // if (modelFileNames == null)
806 // Collection<ChimeraModel> chimodels = viewer.getChimeraModels();
807 // _modelFileNameMap = new int[chimodels.size()];
809 // for (ChimeraModel chimodel : chimodels)
811 // String mdlName = chimodel.getModelName();
813 // modelFileNames = new String[j];
814 // // System.arraycopy(mset, 0, modelFileNames, 0, j);
817 return chimeraMaps.keySet().toArray(
818 modelFileNames = new String[chimeraMaps.size()]);
822 * map from string to applet
824 public Map getRegistryInfo()
826 // TODO Auto-generated method stub
831 * returns the current sequenceRenderer that should be used to colour the
838 public abstract SequenceRenderer getSequenceRenderer(
839 AlignmentViewPanel alignment);
842 * Construct and send a command to highlight an atom.
845 * Done by generating a command like (to 'highlight' position 44)
846 * ~select #0:43.C;select #0:44.C
847 * Note this removes the selection from the previous position.
850 public void highlightAtom(int atomIndex, int pdbResNum, String chain,
853 List<ChimeraModel> cms = chimeraMaps.get(pdbfile);
856 StringBuilder sb = new StringBuilder();
857 sb.append(" #" + cms.get(0).getModelNumber());
858 sb.append(":" + pdbResNum);
859 if (!chain.equals(" "))
861 sb.append("." + chain);
863 String atomSpec = sb.toString();
865 StringBuilder command = new StringBuilder(32);
866 if (lastMousedOverAtomSpec != null)
868 command.append("~show " + lastMousedOverAtomSpec + ";");
870 viewerCommandHistory(false);
871 command.append("show ").append(atomSpec);
872 String cmd = command.toString();
873 if (cmd.length() > 0)
875 viewer.sendChimeraCommand(cmd, false);
877 viewerCommandHistory(true);
878 this.lastMousedOverAtomSpec = atomSpec;
882 private void log(String message)
884 System.err.println("## Chimera log: " + message);
887 private void viewerCommandHistory(boolean enable)
889 // log("(Not yet implemented) History "
890 // + ((debug || enable) ? "on" : "off"));
893 public void loadInline(String string)
897 // viewer.loadInline(strModel, isAppend);
899 // construct fake fullPathName and fileName so we can identify the file
901 // Then, construct pass a reader for the string to Jmol.
902 // ((org.jmol.Viewer.Viewer) viewer).loadModelFromFile(fullPathName,
903 // fileName, null, reader, false, null, null, 0);
904 // viewer.openStringInline(string);
905 log("cannot load inline in Chimera, yet");
908 public void mouseOverStructure(int atomIndex, String strInfo)
910 // function to parse a mouseOver event from Chimera
913 int alocsep = strInfo.indexOf("^");
914 int mdlSep = strInfo.indexOf("/");
915 int chainSeparator = strInfo.indexOf(":"), chainSeparator1 = -1;
917 if (chainSeparator == -1)
919 chainSeparator = strInfo.indexOf(".");
920 if (mdlSep > -1 && mdlSep < chainSeparator)
922 chainSeparator1 = chainSeparator;
923 chainSeparator = mdlSep;
926 // handle insertion codes
929 pdbResNum = Integer.parseInt(strInfo.substring(
930 strInfo.indexOf("]") + 1, alocsep));
935 pdbResNum = Integer.parseInt(strInfo.substring(
936 strInfo.indexOf("]") + 1, chainSeparator));
940 if (strInfo.indexOf(":") > -1)
942 chainId = strInfo.substring(strInfo.indexOf(":") + 1,
943 strInfo.indexOf("."));
950 String pdbfilename = modelFileNames[frameNo]; // default is first or current
954 if (chainSeparator1 == -1)
956 chainSeparator1 = strInfo.indexOf(".", mdlSep);
958 String mdlId = (chainSeparator1 > -1) ? strInfo.substring(mdlSep + 1,
959 chainSeparator1) : strInfo.substring(mdlSep + 1);
962 // recover PDB filename for the model hovered over.
963 int _mp = _modelFileNameMap.length - 1, mnumber = new Integer(mdlId)
965 while (mnumber < _modelFileNameMap[_mp])
969 pdbfilename = modelFileNames[_mp];
970 if (pdbfilename == null)
972 // pdbfilename = new File(viewer.getModelFileName(mnumber))
973 // .getAbsolutePath();
976 } catch (Exception e)
981 if (lastMessage == null || !lastMessage.equals(strInfo))
983 getSsm().mouseOverStructure(pdbResNum, chainId, pdbfilename);
986 lastMessage = strInfo;
989 public void notifyAtomPicked(int atomIndex, String strInfo, String strData)
992 * this implements the toggle label behaviour copied from the original
993 * structure viewer, MCView
997 System.err.println("Ignoring additional pick data string " + strData);
999 // rewrite these selections for chimera (DNA, RNA and protein)
1000 int chainSeparator = strInfo.indexOf(":");
1002 if (chainSeparator == -1)
1004 chainSeparator = strInfo.indexOf(".");
1007 String picked = strInfo.substring(strInfo.indexOf("]") + 1,
1009 String mdlString = "";
1010 if ((p = strInfo.indexOf(":")) > -1)
1012 picked += strInfo.substring(p + 1, strInfo.indexOf("."));
1015 if ((p = strInfo.indexOf("/")) > -1)
1017 mdlString += strInfo.substring(p, strInfo.indexOf(" #"));
1019 picked = "((" + picked + ".CA" + mdlString + ")|(" + picked + ".P"
1021 viewerCommandHistory(false);
1023 if (!atomsPicked.contains(picked))
1025 viewer.select(picked);
1026 atomsPicked.add(picked);
1030 viewer.select("not " + picked);
1031 atomsPicked.remove(picked);
1033 viewerCommandHistory(true);
1034 // TODO: in application this happens
1036 // if (scriptWindow != null)
1038 // scriptWindow.sendConsoleMessage(strInfo);
1039 // scriptWindow.sendConsoleMessage("\n");
1044 // incremented every time a load notification is successfully handled -
1045 // lightweight mechanism for other threads to detect when they can start
1046 // referring to new structures.
1047 private long loadNotifiesHandled = 0;
1049 public long getLoadNotifiesHandled()
1051 return loadNotifiesHandled;
1054 public void notifyFileLoaded(String fullPathName, String fileName2,
1055 String modelName, String errorMsg, int modelParts)
1057 if (errorMsg != null)
1059 fileLoadingError = errorMsg;
1063 // TODO: deal sensibly with models loaded inLine:
1064 // modelName will be null, as will fullPathName.
1066 // the rest of this routine ignores the arguments, and simply interrogates
1067 // the Jmol view to find out what structures it contains, and adds them to
1068 // the structure selection manager.
1069 fileLoadingError = null;
1070 String[] oldmodels = modelFileNames;
1071 modelFileNames = null;
1072 chainNames = new ArrayList<String>();
1073 chainFile = new HashMap<String, String>();
1074 boolean notifyLoaded = false;
1075 String[] modelfilenames = getPdbFile();
1076 // first check if we've lost any structures
1077 if (oldmodels != null && oldmodels.length > 0)
1080 for (int i = 0; i < oldmodels.length; i++)
1082 for (int n = 0; n < modelfilenames.length; n++)
1084 if (modelfilenames[n] == oldmodels[i])
1086 oldmodels[i] = null;
1090 if (oldmodels[i] != null)
1097 String[] oldmfn = new String[oldm];
1099 for (int i = 0; i < oldmodels.length; i++)
1101 if (oldmodels[i] != null)
1103 oldmfn[oldm++] = oldmodels[i];
1106 // deregister the Jmol instance for these structures - we'll add
1107 // ourselves again at the end for the current structure set.
1108 getSsm().removeStructureViewerListener(this, oldmfn);
1112 // register ourselves as a listener and notify the gui that it needs to
1114 getSsm().addStructureViewerListener(this);
1118 FeatureRenderer fr = getFeatureRenderer(null);
1124 loadNotifiesHandled++;
1126 setLoadingFromArchive(false);
1129 public void setJalviewColourScheme(ColourSchemeI cs)
1131 colourBySequence = false;
1140 // Chimera expects RBG values in the range 0-1
1141 final double normalise = 255D;
1142 viewerCommandHistory(false);
1143 // TODO: Switch between nucleotide or aa selection expressions
1144 StringBuilder command = new StringBuilder(128);
1145 command.append("color white;");
1146 for (String res : ResidueProperties.aa3Hash.keySet())
1148 index = ResidueProperties.aa3Hash.get(res).intValue();
1154 col = cs.findColour(ResidueProperties.aa[index].charAt(0));
1155 command.append("color " + col.getRed() / normalise + ","
1156 + col.getGreen() / normalise + "," + col.getBlue()
1157 / normalise + " ::" + res + ";");
1160 evalStateCommand(command.toString(),false);
1161 viewerCommandHistory(true);
1165 * called when the binding thinks the UI needs to be refreshed after a Chimera
1166 * state change. this could be because structures were loaded, or because an
1167 * error has occurred.
1169 public abstract void refreshGUI();
1171 public void setLoadingFromArchive(boolean loadingFromArchive)
1173 this.loadingFromArchive = loadingFromArchive;
1178 * @return true if Chimeral is still restoring state or loading is still going
1179 * on (see setFinsihedLoadingFromArchive)
1181 public boolean isLoadingFromArchive()
1183 return loadingFromArchive && !loadingFinished;
1187 * modify flag which controls if sequence colouring events are honoured by the
1188 * binding. Should be true for normal operation
1190 * @param finishedLoading
1192 public void setFinishedLoadingFromArchive(boolean finishedLoading)
1194 loadingFinished = finishedLoading;
1198 * Send the Chimera 'background solid <color>" command.
1201 * ://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/background
1205 public void setBackgroundColour(Color col)
1207 viewerCommandHistory(false);
1208 double normalise = 255D;
1209 final String command = "background solid " + col.getRed() / normalise + ","
1210 + col.getGreen() / normalise + "," + col.getBlue()
1212 viewer.sendChimeraCommand(command, false);
1213 viewerCommandHistory(true);
1219 * @return text report of alignment between pdbfile and any associated
1220 * alignment sequences
1222 public String printMapping(String pdbfile)
1224 return getSsm().printMapping(pdbfile);
1228 * Ask Chimera to save its session to the given file. Returns true if
1229 * successful, else false.
1234 public boolean saveSession(String filepath)
1236 if (isChimeraRunning())
1238 List<String> reply = viewer.sendChimeraCommand("save " + filepath,
1240 if (reply.contains("Session written"))
1247 .error("Error saving Chimera session: " + reply.toString());
1254 * Ask Chimera to open a session file. Returns true if successful, else false.
1255 * The filename must have a .py extension for this command to work.
1260 public boolean openSession(String filepath)
1262 evalStateCommand("open " + filepath, true);
1263 // todo: test for failure - how?
1267 public boolean isFinishedInit()
1269 return finishedInit;
1272 public void setFinishedInit(boolean finishedInit)
1274 this.finishedInit = finishedInit;
1277 public List<String> getChainNames()