1 package jalview.ext.rbvi.chimera;
3 import jalview.api.AlignmentViewPanel;
4 import jalview.api.FeatureRenderer;
5 import jalview.api.SequenceRenderer;
6 import jalview.bin.Cache;
7 import jalview.datamodel.AlignmentI;
8 import jalview.datamodel.ColumnSelection;
9 import jalview.datamodel.PDBEntry;
10 import jalview.datamodel.SequenceI;
11 import jalview.schemes.ColourSchemeI;
12 import jalview.schemes.ResidueProperties;
13 import jalview.structure.StructureMapping;
14 import jalview.structure.StructureMappingcommandSet;
15 import jalview.structure.StructureSelectionManager;
16 import jalview.structures.models.AAStructureBindingModel;
17 import jalview.util.Comparison;
18 import jalview.util.MessageManager;
20 import java.awt.Color;
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.LinkedHashMap;
24 import java.util.List;
27 import ext.edu.ucsf.rbvi.strucviz2.ChimeraManager;
28 import ext.edu.ucsf.rbvi.strucviz2.ChimeraModel;
29 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
30 import ext.edu.ucsf.rbvi.strucviz2.StructureManager.ModelType;
32 public abstract class JalviewChimeraBinding extends AAStructureBindingModel
35 private static final boolean debug = false;
37 private static final String PHOSPHORUS = "P";
39 private static final String ALPHACARBON = "CA";
41 private StructureManager csm;
43 private ChimeraManager viewer;
46 * set if chimera state is being restored from some source - instructs binding
47 * not to apply default display style when structure set is updated for first
50 private boolean loadingFromArchive = false;
53 * flag to indicate if the Chimera viewer should ignore sequence colouring
54 * events from the structure manager because the GUI is still setting up
56 private boolean loadingFinished = true;
59 * state flag used to check if the Chimera viewer's paint method can be called
61 private boolean finishedInit = false;
63 private List<String> atomsPicked = new ArrayList<String>();
65 private List<String> chainNames;
67 private Map<String, String> chainFile;
69 private StringBuffer eval = new StringBuffer();
71 public String fileLoadingError;
74 * Map of ChimeraModel objects keyed by PDB full local file name
76 private Map<String, List<ChimeraModel>> chimeraMaps = new LinkedHashMap<String, List<ChimeraModel>>();
79 * the default or current model displayed if the model cannot be identified
80 * from the selection message
82 private int frameNo = 0;
84 private String lastCommand;
86 private String lastMessage;
88 private boolean loadedInline;
91 * Open a PDB structure file in Chimera and set up mappings from Jalview.
93 * We check if the PDB model id is already loaded in Chimera, if so don't
94 * reopen it. This is the case if Chimera has opened a saved session file.
99 public boolean openFile(PDBEntry pe)
101 String file = pe.getFile();
104 List<ChimeraModel> modelsToMap = new ArrayList<ChimeraModel>();
105 List<ChimeraModel> oldList = viewer.getModelList();
106 boolean alreadyOpen = false;
109 * If Chimera already has this model, don't reopen it, but do remap it.
111 for (ChimeraModel open : oldList)
113 if (open.getModelName().equals(pe.getId()))
116 modelsToMap.add(open);
121 * If Chimera doesn't yet have this model, ask it to open it, and retrieve
122 * the model names added by Chimera.
126 viewer.openModel(file, pe.getId(), ModelType.PDB_MODEL);
127 modelsToMap = viewer.getModelList();
128 modelsToMap.removeAll(oldList);
131 chimeraMaps.put(file, modelsToMap);
133 if (getSsm() != null)
135 getSsm().addStructureViewerListener(this);
136 // ssm.addSelectionListener(this);
137 FeatureRenderer fr = getFeatureRenderer(null);
145 } catch (Exception q)
147 log("Exception when trying to open model " + file + "\n"
155 * current set of model filenames loaded
157 String[] modelFileNames = null;
160 StringBuffer resetLastRes = new StringBuffer();
162 private List<String> lastReply;
173 public JalviewChimeraBinding(StructureSelectionManager ssm,
174 PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains,
177 super(ssm, pdbentry, sequenceIs, chains, protocol);
178 viewer = new ChimeraManager(
179 csm = new ext.edu.ucsf.rbvi.strucviz2.StructureManager(true));
188 public JalviewChimeraBinding(StructureSelectionManager ssm,
189 ChimeraManager theViewer)
193 csm = viewer.getStructureManager();
197 * Construct a title string for the viewer window based on the data Jalview
203 public String getViewerTitle(boolean verbose)
205 return getViewerTitle("Chimera", verbose);
209 * prepare the view for a given set of models/chains. chainList contains
210 * strings of the form 'pdbfilename:Chaincode'
213 * list of chains to make visible
215 public void centerViewer(List<String> toshow)
217 StringBuilder cmd = new StringBuilder(64);
219 for (String lbl : toshow)
225 mlength = lbl.indexOf(":", p);
226 } while (p < mlength && mlength < (lbl.length() - 2));
227 // TODO: lookup each pdb id and recover proper model number for it.
228 cmd.append("#" + getModelNum(chainFile.get(lbl)) + "."
229 + lbl.substring(mlength + 1) + " or ");
231 if (cmd.length() > 0)
233 cmd.setLength(cmd.length() - 4);
235 String cmdstring = cmd.toString();
236 evalStateCommand("~display #*; ~ribbon #*; ribbon " + cmdstring
237 + ";focus " + cmdstring, false);
241 * Close down the Jalview viewer, and (optionally) the associated Chimera
244 public void closeViewer(boolean closeChimera)
246 getSsm().removeStructureViewerListener(this, this.getPdbFile());
249 viewer.exitChimera();
253 releaseUIResources();
256 public void colourByChain()
258 colourBySequence = false;
259 evalStateCommand("rainbow chain", false);
262 public void colourByCharge()
264 colourBySequence = false;
266 "color white;color red ::ASP;color red ::GLU;color blue ::LYS;color blue ::ARG;color yellow ::CYS",
271 * superpose the structures associated with sequences in the alignment
272 * according to their corresponding positions.
274 public void superposeStructures(AlignmentI alignment)
276 superposeStructures(alignment, -1, null);
280 * superpose the structures associated with sequences in the alignment
281 * according to their corresponding positions. ded)
283 * @param refStructure
284 * - select which pdb file to use as reference (default is -1 - the
285 * first structure in the alignment)
287 public void superposeStructures(AlignmentI alignment, int refStructure)
289 superposeStructures(alignment, refStructure, null);
293 * superpose the structures associated with sequences in the alignment
294 * according to their corresponding positions. ded)
296 * @param refStructure
297 * - select which pdb file to use as reference (default is -1 - the
298 * first structure in the alignment)
302 public void superposeStructures(AlignmentI alignment, int refStructure,
303 ColumnSelection hiddenCols)
305 superposeStructures(new AlignmentI[]
306 { alignment }, new int[]
307 { refStructure }, new ColumnSelection[]
311 public void superposeStructures(AlignmentI[] _alignment,
312 int[] _refStructure, ColumnSelection[] _hiddenCols)
314 assert (_alignment.length == _refStructure.length && _alignment.length != _hiddenCols.length);
315 StringBuilder allComs = new StringBuilder(128); // Chimera superposition cmd
316 String[] files = getPdbFile();
317 // check to see if we are still waiting for Chimera files
318 long starttime = System.currentTimeMillis();
319 boolean waiting = true;
323 for (String file : files)
327 // HACK - in Jalview 2.8 this call may not be threadsafe so we catch
328 // every possible exception
329 StructureMapping[] sm = getSsm().getMapping(file);
330 if (sm == null || sm.length == 0)
334 } catch (Exception x)
342 // we wait around for a reasonable time before we give up
344 && System.currentTimeMillis() < (10000 + 1000 * files.length + starttime));
348 .println("RUNTIME PROBLEM: Chimera seems to be taking a long time to process all the structures.");
352 StringBuffer selectioncom = new StringBuffer();
353 for (int a = 0; a < _alignment.length; a++)
355 int refStructure = _refStructure[a];
356 AlignmentI alignment = _alignment[a];
357 ColumnSelection hiddenCols = _hiddenCols[a];
359 && selectioncom.length() > 0
360 && !selectioncom.substring(selectioncom.length() - 1).equals(
363 selectioncom.append(" ");
365 // process this alignment
366 if (refStructure >= files.length)
368 System.err.println("Invalid reference structure value "
372 if (refStructure < -1)
377 boolean matched[] = new boolean[alignment.getWidth()];
378 for (int m = 0; m < matched.length; m++)
381 matched[m] = (hiddenCols != null) ? hiddenCols.isVisible(m) : true;
384 int commonrpositions[][] = new int[files.length][alignment.getWidth()];
385 String isel[] = new String[files.length];
386 String[] targetC = new String[files.length];
387 String[] chainNames = new String[files.length];
388 String[] atomSpec = new String[files.length];
389 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
391 StructureMapping[] mapping = getSsm().getMapping(files[pdbfnum]);
392 // RACE CONDITION - getMapping only returns Jmol loaded filenames once
393 // Jmol callback has completed.
394 if (mapping == null || mapping.length < 1)
396 throw new Error(MessageManager.getString("error.implementation_error_chimera_getting_data"));
399 final int seqCountForPdbFile = getSequence()[pdbfnum].length;
400 for (int s = 0; s < seqCountForPdbFile; s++)
402 for (int sp, m = 0; m < mapping.length; m++)
404 final SequenceI theSequence = getSequence()[pdbfnum][s];
405 if (mapping[m].getSequence() == theSequence
406 && (sp = alignment.findIndex(theSequence)) > -1)
408 if (refStructure == -1)
410 refStructure = pdbfnum;
412 SequenceI asp = alignment.getSequenceAt(sp);
413 for (int r = 0; r < matched.length; r++)
419 matched[r] = false; // assume this is not a good site
420 if (r >= asp.getLength())
425 if (Comparison.isGap(asp.getCharAt(r)))
427 // no mapping to gaps in sequence
430 int t = asp.findPosition(r); // sequence position
431 int apos = mapping[m].getAtomNum(t);
432 int pos = mapping[m].getPDBResNum(t);
434 if (pos < 1 || pos == lastPos)
436 // can't align unmapped sequence
439 matched[r] = true; // this is a good ite
441 // just record this residue position
442 commonrpositions[pdbfnum][r] = pos;
444 // create model selection suffix
445 isel[pdbfnum] = "#" + pdbfnum;
446 if (mapping[m].getChain() == null
447 || mapping[m].getChain().trim().length() == 0)
449 targetC[pdbfnum] = "";
453 targetC[pdbfnum] = "." + mapping[m].getChain();
455 chainNames[pdbfnum] = mapping[m].getPdbId()
457 atomSpec[pdbfnum] = asp.getRNA() != null ? PHOSPHORUS : ALPHACARBON;
458 // move on to next pdb file
459 s = seqCountForPdbFile;
466 // TODO: consider bailing if nmatched less than 4 because superposition
469 // TODO: refactor superposable position search (above) from jmol selection
470 // construction (below)
472 String[] selcom = new String[files.length];
475 // generate select statements to select regions to superimpose structures
477 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
479 String chainCd = targetC[pdbfnum];
482 StringBuffer molsel = new StringBuffer();
483 for (int r = 0; r < matched.length; r++)
491 if (lpos != commonrpositions[pdbfnum][r] - 1)
496 molsel.append((run ? "" : ":") + lpos);
497 molsel.append(chainCd);
503 // continuous run - and lpos >-1
506 // at the beginning, so add dash
507 molsel.append(":" + lpos);
512 lpos = commonrpositions[pdbfnum][r];
513 // molsel.append(lpos);
516 // add final selection phrase
519 molsel.append((run ? "" : ":") + lpos);
520 molsel.append(chainCd);
521 // molsel.append("");
523 if (molsel.length() > 1)
525 selcom[pdbfnum] = molsel.toString();
526 selectioncom.append("#" + pdbfnum);
527 selectioncom.append(selcom[pdbfnum]);
528 selectioncom.append(" ");
529 if (pdbfnum < files.length - 1)
531 selectioncom.append("| ");
536 selcom[pdbfnum] = null;
540 StringBuilder command = new StringBuilder(256);
541 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
543 if (pdbfnum == refStructure || selcom[pdbfnum] == null
544 || selcom[refStructure] == null)
548 if (command.length() > 0)
554 * Form Chimera match command, from the 'new' structure to the
555 * 'reference' structure e.g. (residues 1-91, chain B/A, alphacarbons):
557 * match #1:1-91.B@CA #0:1-91.A@CA
560 * https://www.cgl.ucsf.edu/chimera/docs/UsersGuide/midas/match.html
562 command.append("match #" + pdbfnum /* +".1" */);
563 // TODO: handle sub-models
564 command.append(selcom[pdbfnum]);
565 command.append("@" + atomSpec[pdbfnum]);
566 command.append(" #" + refStructure /* +".1" */);
567 command.append(selcom[refStructure]);
568 command.append("@" + atomSpec[refStructure]);
570 if (selectioncom.length() > 0)
574 System.out.println("Select regions:\n" + selectioncom.toString());
575 System.out.println("Superimpose command(s):\n"
576 + command.toString());
578 allComs.append("~display all; chain @CA|P; ribbon "
579 + selectioncom.toString() + ";"+command.toString());
580 // selcom.append("; ribbons; ");
583 if (selectioncom.length() > 0)
584 {// finally, mark all regions that were superposed.
585 if (selectioncom.substring(selectioncom.length() - 1).equals("|"))
587 selectioncom.setLength(selectioncom.length() - 1);
591 System.out.println("Select regions:\n" + selectioncom.toString());
593 allComs.append("; ~display all; chain @CA|P; ribbon "
594 + selectioncom.toString() + "; focus");
595 // evalStateCommand("select *; backbone; select "+selcom.toString()+"; cartoons; center "+selcom.toString());
596 evalStateCommand(allComs.toString(), true /* false */);
601 private void checkLaunched()
603 if (!viewer.isChimeraLaunched())
605 viewer.launchChimera(StructureManager.getChimeraPaths());
607 if (!viewer.isChimeraLaunched())
609 log("Failed to launch Chimera!");
614 * Answers true if the Chimera process is still running, false if ended or not
619 public boolean isChimeraRunning()
621 return viewer.isChimeraLaunched();
625 * Send a command to Chimera, launching it first if necessary, and optionally
631 public void evalStateCommand(final String command, boolean logResponse)
633 viewerCommandHistory(false);
635 if (lastCommand == null || !lastCommand.equals(command))
637 // trim command or it may never find a match in the replyLog!!
638 lastReply = viewer.sendChimeraCommand(command.trim(), logResponse);
639 if (debug && logResponse)
641 log("Response from command ('" + command + "') was:\n" + lastReply);
644 viewerCommandHistory(true);
645 lastCommand = command;
649 * colour any structures associated with sequences in the given alignment
650 * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
651 * if colourBySequence is enabled.
653 public void colourBySequence(boolean showFeatures,
654 jalview.api.AlignmentViewPanel alignmentv)
656 if (!colourBySequence || !loadingFinished)
660 if (getSsm() == null)
664 String[] files = getPdbFile();
666 SequenceRenderer sr = getSequenceRenderer(alignmentv);
668 FeatureRenderer fr = null;
671 fr = getFeatureRenderer(alignmentv);
673 AlignmentI alignment = alignmentv.getAlignment();
675 for (jalview.structure.StructureMappingcommandSet cpdbbyseq : getColourBySequenceCommands(
676 files, sr, fr, alignment))
678 for (String command : cpdbbyseq.commands)
680 executeWhenReady(command);
692 protected StructureMappingcommandSet[] getColourBySequenceCommands(
693 String[] files, SequenceRenderer sr, FeatureRenderer fr,
694 AlignmentI alignment)
696 return ChimeraCommands.getColourBySequenceCommand(getSsm(), files,
697 getSequence(), sr, fr, alignment);
703 protected void executeWhenReady(String command)
706 evalStateCommand(command, false);
710 private void waitForChimera()
712 while (viewer != null && viewer.isBusy())
716 } catch (InterruptedException q)
723 // End StructureListener
724 // //////////////////////////
726 public Color getColour(int atomIndex, int pdbResNum, String chain,
729 if (getModelNum(pdbfile) < 0)
733 log("get model / residue colour attribute unimplemented");
738 * returns the current featureRenderer that should be used to colour the
745 public abstract FeatureRenderer getFeatureRenderer(
746 AlignmentViewPanel alignment);
749 * instruct the Jalview binding to update the pdbentries vector if necessary
750 * prior to matching the jmol view's contents to the list of structure files
751 * Jalview knows about.
753 public abstract void refreshPdbEntries();
755 private int getModelNum(String modelFileName)
757 String[] mfn = getPdbFile();
762 for (int i = 0; i < mfn.length; i++)
764 if (mfn[i].equalsIgnoreCase(modelFileName))
773 * map between index of model filename returned from getPdbFile and the first
774 * index of models from this file in the viewer. Note - this is not trimmed -
775 * use getPdbFile to get number of unique models.
777 private int _modelFileNameMap[];
779 // ////////////////////////////////
780 // /StructureListener
781 public synchronized String[] getPdbFile()
785 return new String[0];
787 // if (modelFileNames == null)
789 // Collection<ChimeraModel> chimodels = viewer.getChimeraModels();
790 // _modelFileNameMap = new int[chimodels.size()];
792 // for (ChimeraModel chimodel : chimodels)
794 // String mdlName = chimodel.getModelName();
796 // modelFileNames = new String[j];
797 // // System.arraycopy(mset, 0, modelFileNames, 0, j);
800 return chimeraMaps.keySet().toArray(
801 modelFileNames = new String[chimeraMaps.size()]);
805 * map from string to applet
807 public Map getRegistryInfo()
809 // TODO Auto-generated method stub
814 * returns the current sequenceRenderer that should be used to colour the
821 public abstract SequenceRenderer getSequenceRenderer(
822 AlignmentViewPanel alignment);
825 public void highlightAtom(int atomIndex, int pdbResNum, String chain,
828 List<ChimeraModel> cms = chimeraMaps.get(pdbfile);
831 int mdlNum = cms.get(0).getModelNumber();
833 viewerCommandHistory(false);
834 // viewer.stopListening();
835 if (resetLastRes.length() > 0)
838 eval.append(resetLastRes.toString() + ";");
841 eval.append("display "); // +modelNum
843 resetLastRes.setLength(0);
844 resetLastRes.append("~display ");
846 eval.append(" #" + (mdlNum));
847 resetLastRes.append(" #" + (mdlNum));
849 // complete select string
851 eval.append(":" + pdbResNum);
852 resetLastRes.append(":" + pdbResNum);
853 if (!chain.equals(" "))
855 eval.append("." + chain);
856 resetLastRes.append("." + chain);
859 viewer.sendChimeraCommand(eval.toString(), false);
860 viewerCommandHistory(true);
861 // viewer.startListening();
865 private void log(String message)
867 System.err.println("## Chimera log: " + message);
870 private void viewerCommandHistory(boolean enable)
872 // log("(Not yet implemented) History "
873 // + ((debug || enable) ? "on" : "off"));
876 public void loadInline(String string)
880 // viewer.loadInline(strModel, isAppend);
882 // construct fake fullPathName and fileName so we can identify the file
884 // Then, construct pass a reader for the string to Jmol.
885 // ((org.jmol.Viewer.Viewer) viewer).loadModelFromFile(fullPathName,
886 // fileName, null, reader, false, null, null, 0);
887 // viewer.openStringInline(string);
888 log("cannot load inline in Chimera, yet");
891 public void mouseOverStructure(int atomIndex, String strInfo)
893 // function to parse a mouseOver event from Chimera
896 int alocsep = strInfo.indexOf("^");
897 int mdlSep = strInfo.indexOf("/");
898 int chainSeparator = strInfo.indexOf(":"), chainSeparator1 = -1;
900 if (chainSeparator == -1)
902 chainSeparator = strInfo.indexOf(".");
903 if (mdlSep > -1 && mdlSep < chainSeparator)
905 chainSeparator1 = chainSeparator;
906 chainSeparator = mdlSep;
909 // handle insertion codes
912 pdbResNum = Integer.parseInt(strInfo.substring(
913 strInfo.indexOf("]") + 1, alocsep));
918 pdbResNum = Integer.parseInt(strInfo.substring(
919 strInfo.indexOf("]") + 1, chainSeparator));
923 if (strInfo.indexOf(":") > -1)
925 chainId = strInfo.substring(strInfo.indexOf(":") + 1,
926 strInfo.indexOf("."));
933 String pdbfilename = modelFileNames[frameNo]; // default is first or current
937 if (chainSeparator1 == -1)
939 chainSeparator1 = strInfo.indexOf(".", mdlSep);
941 String mdlId = (chainSeparator1 > -1) ? strInfo.substring(mdlSep + 1,
942 chainSeparator1) : strInfo.substring(mdlSep + 1);
945 // recover PDB filename for the model hovered over.
946 int _mp = _modelFileNameMap.length - 1, mnumber = new Integer(mdlId)
948 while (mnumber < _modelFileNameMap[_mp])
952 pdbfilename = modelFileNames[_mp];
953 if (pdbfilename == null)
955 // pdbfilename = new File(viewer.getModelFileName(mnumber))
956 // .getAbsolutePath();
959 } catch (Exception e)
964 if (lastMessage == null || !lastMessage.equals(strInfo))
966 getSsm().mouseOverStructure(pdbResNum, chainId, pdbfilename);
969 lastMessage = strInfo;
972 public void notifyAtomPicked(int atomIndex, String strInfo, String strData)
975 * this implements the toggle label behaviour copied from the original
976 * structure viewer, MCView
980 System.err.println("Ignoring additional pick data string " + strData);
982 // rewrite these selections for chimera (DNA, RNA and protein)
983 int chainSeparator = strInfo.indexOf(":");
985 if (chainSeparator == -1)
987 chainSeparator = strInfo.indexOf(".");
990 String picked = strInfo.substring(strInfo.indexOf("]") + 1,
992 String mdlString = "";
993 if ((p = strInfo.indexOf(":")) > -1)
995 picked += strInfo.substring(p + 1, strInfo.indexOf("."));
998 if ((p = strInfo.indexOf("/")) > -1)
1000 mdlString += strInfo.substring(p, strInfo.indexOf(" #"));
1002 picked = "((" + picked + ".CA" + mdlString + ")|(" + picked + ".P"
1004 viewerCommandHistory(false);
1006 if (!atomsPicked.contains(picked))
1008 viewer.select(picked);
1009 atomsPicked.add(picked);
1013 viewer.select("not " + picked);
1014 atomsPicked.remove(picked);
1016 viewerCommandHistory(true);
1017 // TODO: in application this happens
1019 // if (scriptWindow != null)
1021 // scriptWindow.sendConsoleMessage(strInfo);
1022 // scriptWindow.sendConsoleMessage("\n");
1027 // incremented every time a load notification is successfully handled -
1028 // lightweight mechanism for other threads to detect when they can start
1029 // referring to new structures.
1030 private long loadNotifiesHandled = 0;
1032 public long getLoadNotifiesHandled()
1034 return loadNotifiesHandled;
1037 public void notifyFileLoaded(String fullPathName, String fileName2,
1038 String modelName, String errorMsg, int modelParts)
1040 if (errorMsg != null)
1042 fileLoadingError = errorMsg;
1046 // TODO: deal sensibly with models loaded inLine:
1047 // modelName will be null, as will fullPathName.
1049 // the rest of this routine ignores the arguments, and simply interrogates
1050 // the Jmol view to find out what structures it contains, and adds them to
1051 // the structure selection manager.
1052 fileLoadingError = null;
1053 String[] oldmodels = modelFileNames;
1054 modelFileNames = null;
1055 chainNames = new ArrayList<String>();
1056 chainFile = new HashMap<String, String>();
1057 boolean notifyLoaded = false;
1058 String[] modelfilenames = getPdbFile();
1059 // first check if we've lost any structures
1060 if (oldmodels != null && oldmodels.length > 0)
1063 for (int i = 0; i < oldmodels.length; i++)
1065 for (int n = 0; n < modelfilenames.length; n++)
1067 if (modelfilenames[n] == oldmodels[i])
1069 oldmodels[i] = null;
1073 if (oldmodels[i] != null)
1080 String[] oldmfn = new String[oldm];
1082 for (int i = 0; i < oldmodels.length; i++)
1084 if (oldmodels[i] != null)
1086 oldmfn[oldm++] = oldmodels[i];
1089 // deregister the Jmol instance for these structures - we'll add
1090 // ourselves again at the end for the current structure set.
1091 getSsm().removeStructureViewerListener(this, oldmfn);
1095 // register ourselves as a listener and notify the gui that it needs to
1097 getSsm().addStructureViewerListener(this);
1101 FeatureRenderer fr = getFeatureRenderer(null);
1107 loadNotifiesHandled++;
1109 setLoadingFromArchive(false);
1112 public void setJalviewColourScheme(ColourSchemeI cs)
1114 colourBySequence = false;
1123 // Chimera expects RBG values in the range 0-1
1124 final double normalise = 255D;
1125 viewerCommandHistory(false);
1126 // TODO: Switch between nucleotide or aa selection expressions
1127 StringBuilder command = new StringBuilder(128);
1128 command.append("color white;");
1129 for (String res : ResidueProperties.aa3Hash.keySet())
1131 index = ResidueProperties.aa3Hash.get(res).intValue();
1137 col = cs.findColour(ResidueProperties.aa[index].charAt(0));
1138 command.append("color " + col.getRed() / normalise + ","
1139 + col.getGreen() / normalise + "," + col.getBlue()
1140 / normalise + " ::" + res + ";");
1143 evalStateCommand(command.toString(),false);
1144 viewerCommandHistory(true);
1148 * called when the binding thinks the UI needs to be refreshed after a Chimera
1149 * state change. this could be because structures were loaded, or because an
1150 * error has occurred.
1152 public abstract void refreshGUI();
1154 public void setLoadingFromArchive(boolean loadingFromArchive)
1156 this.loadingFromArchive = loadingFromArchive;
1161 * @return true if Chimeral is still restoring state or loading is still going
1162 * on (see setFinsihedLoadingFromArchive)
1164 public boolean isLoadingFromArchive()
1166 return loadingFromArchive && !loadingFinished;
1170 * modify flag which controls if sequence colouring events are honoured by the
1171 * binding. Should be true for normal operation
1173 * @param finishedLoading
1175 public void setFinishedLoadingFromArchive(boolean finishedLoading)
1177 loadingFinished = finishedLoading;
1181 * Send the Chimera 'background solid <color>" command.
1184 * ://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/background
1188 public void setBackgroundColour(Color col)
1190 viewerCommandHistory(false);
1191 double normalise = 255D;
1192 final String command = "background solid " + col.getRed() / normalise + ","
1193 + col.getGreen() / normalise + "," + col.getBlue()
1195 viewer.sendChimeraCommand(command, false);
1196 viewerCommandHistory(true);
1202 * @return text report of alignment between pdbfile and any associated
1203 * alignment sequences
1205 public String printMapping(String pdbfile)
1207 return getSsm().printMapping(pdbfile);
1211 * Ask Chimera to save its session to the given file. Returns true if
1212 * successful, else false.
1217 public boolean saveSession(String filepath)
1219 if (isChimeraRunning())
1221 List<String> reply = viewer.sendChimeraCommand("save " + filepath,
1223 if (reply.contains("Session written"))
1230 .error("Error saving Chimera session: " + reply.toString());
1237 * Ask Chimera to open a session file. Returns true if successful, else false.
1238 * The filename must have a .py extension for this command to work.
1243 public boolean openSession(String filepath)
1245 evalStateCommand("open " + filepath, true);
1246 // todo: test for failure - how?
1250 public boolean isFinishedInit()
1252 return finishedInit;
1255 public void setFinishedInit(boolean finishedInit)
1257 this.finishedInit = finishedInit;
1260 public List<String> getChainNames()