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.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.io.AppletFormatAdapter;
32 import jalview.schemes.ColourSchemeI;
33 import jalview.schemes.ResidueProperties;
34 import jalview.structure.StructureMapping;
35 import jalview.structure.StructureMappingcommandSet;
36 import jalview.structure.StructureSelectionManager;
37 import jalview.structures.models.AAStructureBindingModel;
38 import jalview.util.Comparison;
39 import jalview.util.MessageManager;
41 import java.awt.Color;
43 import java.util.ArrayList;
44 import java.util.Enumeration;
45 import java.util.HashMap;
46 import java.util.LinkedHashMap;
47 import java.util.List;
50 import ext.edu.ucsf.rbvi.strucviz2.ChimeraManager;
51 import ext.edu.ucsf.rbvi.strucviz2.ChimeraModel;
52 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
53 import ext.edu.ucsf.rbvi.strucviz2.StructureManager.ModelType;
55 public abstract class JalviewChimeraBinding extends AAStructureBindingModel
58 private static final boolean debug = false;
60 private static final String PHOSPHORUS = "P";
62 private static final String ALPHACARBON = "CA";
64 private StructureManager csm;
66 private ChimeraManager viewer;
69 * set if chimera state is being restored from some source - instructs binding
70 * not to apply default display style when structure set is updated for first
73 private boolean loadingFromArchive = false;
76 * second flag to indicate if the Chimera viewer should ignore sequence
77 * colouring events from the structure manager because the GUI is still
80 private boolean loadingFinished = true;
83 * state flag used to check if the Chimera 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;
111 StringBuffer eval = new StringBuffer();
113 public String fileLoadingError;
115 private Map<String, List<ChimeraModel>> chimmaps = new LinkedHashMap<String, List<ChimeraModel>>();
117 private List<String> mdlToFile = new ArrayList<String>();
120 * the default or current model displayed if the model cannot be identified
121 * from the selection message
129 boolean loadedInline;
131 public boolean openFile(PDBEntry pe)
133 String file = pe.getFile();
136 List<ChimeraModel> oldList = viewer.getModelList();
137 viewer.openModel(file, pe.getId(), ModelType.PDB_MODEL);
138 List<ChimeraModel> newList = viewer.getModelList();
139 if (oldList.size() < newList.size())
141 while (oldList.size() > 0)
146 chimmaps.put(file, newList);
147 for (ChimeraModel cm : newList)
149 while (mdlToFile.size() < 1 + cm.getModelNumber())
151 mdlToFile.add(new String(""));
153 mdlToFile.set(cm.getModelNumber(), file);
156 File fl = new File(file);
157 String protocol = AppletFormatAdapter.URL;
162 protocol = AppletFormatAdapter.FILE;
164 } catch (Exception e)
169 // Explicitly map to the filename used by Chimera ;
170 // pdbentry[pe].getFile(), protocol);
172 if (getSsm() != null)
174 getSsm().addStructureViewerListener(this);
175 // ssm.addSelectionListener(this);
176 FeatureRenderer fr = getFeatureRenderer(null);
185 } catch (Exception q)
187 log("Exception when trying to open model " + file + "\n"
195 * current set of model filenames loaded
197 String[] modelFileNames = null;
200 StringBuffer resetLastRes = new StringBuffer();
202 private List<String> lastReply;
213 public JalviewChimeraBinding(StructureSelectionManager ssm,
214 PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains,
217 super(ssm, pdbentry, sequenceIs, chains, protocol);
218 viewer = new ChimeraManager(
219 csm = new ext.edu.ucsf.rbvi.strucviz2.StructureManager(true));
228 public JalviewChimeraBinding(StructureSelectionManager ssm,
229 ChimeraManager theViewer)
233 csm = viewer.getStructureManager();
237 * Construct a title string for the viewer window based on the data Jalview
243 public String getViewerTitle(boolean verbose)
245 return getViewerTitle("Chimera", verbose);
249 * prepare the view for a given set of models/chains. chainList contains
250 * strings of the form 'pdbfilename:Chaincode'
253 * list of chains to make visible
255 public void centerViewer(List<String> toshow)
257 StringBuilder cmd = new StringBuilder(64);
259 for (String lbl : toshow)
265 mlength = lbl.indexOf(":", p);
266 } while (p < mlength && mlength < (lbl.length() - 2));
267 // TODO: lookup each pdb id and recover proper model number for it.
268 cmd.append("#" + getModelNum(chainFile.get(lbl)) + "."
269 + lbl.substring(mlength + 1) + " or ");
271 if (cmd.length() > 0)
273 cmd.setLength(cmd.length() - 4);
275 String cmdstring = cmd.toString();
276 evalStateCommand("~display #*; ~ribbon #*; ribbon " + cmdstring
277 + ";focus " + cmdstring, false);
281 * Close down the Jalview viewer, and (optionally) the associated Chimera
284 public void closeViewer(boolean closeChimera)
286 getSsm().removeStructureViewerListener(this, this.getPdbFile());
289 viewer.exitChimera();
293 releaseUIResources();
296 public void colourByChain()
298 colourBySequence = false;
299 evalStateCommand("rainbow chain", false);
302 public void colourByCharge()
304 colourBySequence = false;
306 "color white;color red ::ASP;color red ::GLU;color blue ::LYS;color blue ::ARG;color yellow ::CYS",
311 * superpose the structures associated with sequences in the alignment
312 * according to their corresponding positions.
314 public void superposeStructures(AlignmentI alignment)
316 superposeStructures(alignment, -1, null);
320 * superpose the structures associated with sequences in the alignment
321 * according to their corresponding positions. ded)
323 * @param refStructure
324 * - select which pdb file to use as reference (default is -1 - the
325 * first structure in the alignment)
327 public void superposeStructures(AlignmentI alignment, int refStructure)
329 superposeStructures(alignment, refStructure, null);
333 * superpose the structures associated with sequences in the alignment
334 * according to their corresponding positions. ded)
336 * @param refStructure
337 * - select which pdb file to use as reference (default is -1 - the
338 * first structure in the alignment)
342 public void superposeStructures(AlignmentI alignment, int refStructure,
343 ColumnSelection hiddenCols)
345 superposeStructures(new AlignmentI[]
346 { alignment }, new int[]
347 { refStructure }, new ColumnSelection[]
351 public void superposeStructures(AlignmentI[] _alignment,
352 int[] _refStructure, ColumnSelection[] _hiddenCols)
354 assert (_alignment.length == _refStructure.length && _alignment.length != _hiddenCols.length);
355 StringBuilder allComs = new StringBuilder(128); // Chimera superposition cmd
356 String[] files = getPdbFile();
357 // check to see if we are still waiting for Chimera files
358 long starttime = System.currentTimeMillis();
359 boolean waiting = true;
363 for (String file : files)
367 // HACK - in Jalview 2.8 this call may not be threadsafe so we catch
368 // every possible exception
369 StructureMapping[] sm = getSsm().getMapping(file);
370 if (sm == null || sm.length == 0)
374 } catch (Exception x)
382 // we wait around for a reasonable time before we give up
384 && System.currentTimeMillis() < (10000 + 1000 * files.length + starttime));
388 .println("RUNTIME PROBLEM: Chimera seems to be taking a long time to process all the structures.");
392 StringBuffer selectioncom = new StringBuffer();
393 for (int a = 0; a < _alignment.length; a++)
395 int refStructure = _refStructure[a];
396 AlignmentI alignment = _alignment[a];
397 ColumnSelection hiddenCols = _hiddenCols[a];
399 && selectioncom.length() > 0
400 && !selectioncom.substring(selectioncom.length() - 1).equals(
403 selectioncom.append(" ");
405 // process this alignment
406 if (refStructure >= files.length)
408 System.err.println("Invalid reference structure value "
412 if (refStructure < -1)
417 boolean matched[] = new boolean[alignment.getWidth()];
418 for (int m = 0; m < matched.length; m++)
421 matched[m] = (hiddenCols != null) ? hiddenCols.isVisible(m) : true;
424 int commonrpositions[][] = new int[files.length][alignment.getWidth()];
425 String isel[] = new String[files.length];
426 String[] targetC = new String[files.length];
427 String[] chainNames = new String[files.length];
428 String[] atomSpec = new String[files.length];
429 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
431 StructureMapping[] mapping = getSsm().getMapping(files[pdbfnum]);
432 // RACE CONDITION - getMapping only returns Jmol loaded filenames once
433 // Jmol callback has completed.
434 if (mapping == null || mapping.length < 1)
436 throw new Error(MessageManager.getString("error.implementation_error_chimera_getting_data"));
439 final int seqCountForPdbFile = getSequence()[pdbfnum].length;
440 for (int s = 0; s < seqCountForPdbFile; s++)
442 for (int sp, m = 0; m < mapping.length; m++)
444 final SequenceI theSequence = getSequence()[pdbfnum][s];
445 if (mapping[m].getSequence() == theSequence
446 && (sp = alignment.findIndex(theSequence)) > -1)
448 if (refStructure == -1)
450 refStructure = pdbfnum;
452 SequenceI asp = alignment.getSequenceAt(sp);
453 for (int r = 0; r < matched.length; r++)
459 matched[r] = false; // assume this is not a good site
460 if (r >= asp.getLength())
465 if (Comparison.isGap(asp.getCharAt(r)))
467 // no mapping to gaps in sequence
470 int t = asp.findPosition(r); // sequence position
471 int apos = mapping[m].getAtomNum(t);
472 int pos = mapping[m].getPDBResNum(t);
474 if (pos < 1 || pos == lastPos)
476 // can't align unmapped sequence
479 matched[r] = true; // this is a good ite
481 // just record this residue position
482 commonrpositions[pdbfnum][r] = pos;
484 // create model selection suffix
485 isel[pdbfnum] = "#" + pdbfnum;
486 if (mapping[m].getChain() == null
487 || mapping[m].getChain().trim().length() == 0)
489 targetC[pdbfnum] = "";
493 targetC[pdbfnum] = "." + mapping[m].getChain();
495 chainNames[pdbfnum] = mapping[m].getPdbId()
497 atomSpec[pdbfnum] = asp.getRNA() != null ? PHOSPHORUS : ALPHACARBON;
498 // move on to next pdb file
499 s = seqCountForPdbFile;
506 // TODO: consider bailing if nmatched less than 4 because superposition
509 // TODO: refactor superposable position search (above) from jmol selection
510 // construction (below)
512 String[] selcom = new String[files.length];
515 // generate select statements to select regions to superimpose structures
517 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
519 String chainCd = targetC[pdbfnum];
522 StringBuffer molsel = new StringBuffer();
523 for (int r = 0; r < matched.length; r++)
531 if (lpos != commonrpositions[pdbfnum][r] - 1)
536 molsel.append((run ? "" : ":") + lpos);
537 molsel.append(chainCd);
543 // continuous run - and lpos >-1
546 // at the beginning, so add dash
547 molsel.append(":" + lpos);
552 lpos = commonrpositions[pdbfnum][r];
553 // molsel.append(lpos);
556 // add final selection phrase
559 molsel.append((run ? "" : ":") + lpos);
560 molsel.append(chainCd);
561 // molsel.append("");
563 if (molsel.length() > 1)
565 selcom[pdbfnum] = molsel.toString();
566 selectioncom.append("#" + pdbfnum);
567 selectioncom.append(selcom[pdbfnum]);
568 selectioncom.append(" ");
569 if (pdbfnum < files.length - 1)
571 selectioncom.append("| ");
576 selcom[pdbfnum] = null;
580 StringBuilder command = new StringBuilder(256);
581 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
583 if (pdbfnum == refStructure || selcom[pdbfnum] == null
584 || selcom[refStructure] == null)
588 if (command.length() > 0)
594 * Form Chimera match command, from the 'new' structure to the
595 * 'reference' structure e.g. (residues 1-91, chain B/A, alphacarbons):
597 * match #1:1-91.B@CA #0:1-91.A@CA
600 * https://www.cgl.ucsf.edu/chimera/docs/UsersGuide/midas/match.html
602 command.append("match #" + pdbfnum /* +".1" */);
603 // TODO: handle sub-models
604 command.append(selcom[pdbfnum]);
605 command.append("@" + atomSpec[pdbfnum]);
606 command.append(" #" + refStructure /* +".1" */);
607 command.append(selcom[refStructure]);
608 command.append("@" + atomSpec[refStructure]);
610 if (selectioncom.length() > 0)
614 System.out.println("Select regions:\n" + selectioncom.toString());
615 System.out.println("Superimpose command(s):\n"
616 + command.toString());
618 allComs.append("~display all; chain @CA|P; ribbon "
619 + selectioncom.toString() + ";"+command.toString());
620 // selcom.append("; ribbons; ");
623 if (selectioncom.length() > 0)
624 {// finally, mark all regions that were superposed.
625 if (selectioncom.substring(selectioncom.length() - 1).equals("|"))
627 selectioncom.setLength(selectioncom.length() - 1);
631 System.out.println("Select regions:\n" + selectioncom.toString());
633 allComs.append("; ~display all; chain @CA|P; ribbon "
634 + selectioncom.toString() + "; focus");
635 // evalStateCommand("select *; backbone; select "+selcom.toString()+"; cartoons; center "+selcom.toString());
636 evalStateCommand(allComs.toString(), true /* false */);
641 private void checkLaunched()
643 if (!viewer.isChimeraLaunched())
645 viewer.launchChimera(csm.getChimeraPaths());
647 if (!viewer.isChimeraLaunched())
649 log("Failed to launch Chimera!");
654 * Answers true if the Chimera process is still running, false if ended or not
659 public boolean isChimeraRunning()
661 return viewer.isChimeraLaunched();
665 * Send a command to Chimera, and optionally log any responses.
670 public void evalStateCommand(final String command, boolean logResponse)
672 viewerCommandHistory(false);
674 if (lastCommand == null || !lastCommand.equals(command))
676 // Thread t = new Thread(new Runnable()
681 // trim command or it may never find a match in the replyLog!!
682 lastReply = viewer.sendChimeraCommand(command.trim(), logResponse);
683 if (debug && logResponse)
685 log("Response from command ('" + command + "') was:\n"
690 // TODO - use j7/8 thread management
694 // } catch (InterruptedException foo)
699 viewerCommandHistory(true);
700 lastCommand = command;
704 * colour any structures associated with sequences in the given alignment
705 * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
706 * if colourBySequence is enabled.
708 public void colourBySequence(boolean showFeatures,
709 jalview.api.AlignmentViewPanel alignmentv)
711 if (!colourBySequence || !loadingFinished)
715 if (getSsm() == null)
719 String[] files = getPdbFile();
721 SequenceRenderer sr = getSequenceRenderer(alignmentv);
723 FeatureRenderer fr = null;
726 fr = getFeatureRenderer(alignmentv);
728 AlignmentI alignment = alignmentv.getAlignment();
730 for (jalview.structure.StructureMappingcommandSet cpdbbyseq : getColourBySequenceCommands(files, sr, fr, alignment))
732 for (String command : cpdbbyseq.commands)
734 executeWhenReady(command);
746 protected StructureMappingcommandSet[] getColourBySequenceCommands(
747 String[] files, SequenceRenderer sr, FeatureRenderer fr,
748 AlignmentI alignment)
750 return ChimeraCommands
751 .getColourBySequenceCommand(getSsm(), files, getSequence(), sr,
759 protected void executeWhenReady(String command)
762 evalStateCommand(command, false);
766 private void waitForChimera()
768 while (viewer != null && viewer.isBusy())
772 } catch (InterruptedException q)
779 // End StructureListener
780 // //////////////////////////
782 public Color getColour(int atomIndex, int pdbResNum, String chain,
785 if (getModelNum(pdbfile) < 0)
789 log("get model / residue colour attribute unimplemented");
794 * returns the current featureRenderer that should be used to colour the
801 public abstract FeatureRenderer getFeatureRenderer(
802 AlignmentViewPanel alignment);
805 * instruct the Jalview binding to update the pdbentries vector if necessary
806 * prior to matching the jmol view's contents to the list of structure files
807 * Jalview knows about.
809 public abstract void refreshPdbEntries();
811 private int getModelNum(String modelFileName)
813 String[] mfn = getPdbFile();
818 for (int i = 0; i < mfn.length; i++)
820 if (mfn[i].equalsIgnoreCase(modelFileName))
829 * map between index of model filename returned from getPdbFile and the first
830 * index of models from this file in the viewer. Note - this is not trimmed -
831 * use getPdbFile to get number of unique models.
833 private int _modelFileNameMap[];
835 // ////////////////////////////////
836 // /StructureListener
837 public synchronized String[] getPdbFile()
841 return new String[0];
843 // if (modelFileNames == null)
845 // Collection<ChimeraModel> chimodels = viewer.getChimeraModels();
846 // _modelFileNameMap = new int[chimodels.size()];
848 // for (ChimeraModel chimodel : chimodels)
850 // String mdlName = chimodel.getModelName();
852 // modelFileNames = new String[j];
853 // // System.arraycopy(mset, 0, modelFileNames, 0, j);
856 return chimmaps.keySet().toArray(
857 modelFileNames = new String[chimmaps.size()]);
861 * map from string to applet
863 public Map getRegistryInfo()
865 // TODO Auto-generated method stub
870 * returns the current sequenceRenderer that should be used to colour the
877 public abstract SequenceRenderer getSequenceRenderer(
878 AlignmentViewPanel alignment);
881 public void highlightAtom(int atomIndex, int pdbResNum, String chain,
884 List<ChimeraModel> cms = chimmaps.get(pdbfile);
887 int mdlNum = cms.get(0).getModelNumber();
889 viewerCommandHistory(false);
890 // viewer.stopListening();
891 if (resetLastRes.length() > 0)
894 eval.append(resetLastRes.toString() + ";");
897 eval.append("display "); // +modelNum
899 resetLastRes.setLength(0);
900 resetLastRes.append("~display ");
902 eval.append(" #" + (mdlNum));
903 resetLastRes.append(" #" + (mdlNum));
905 // complete select string
907 eval.append(":" + pdbResNum);
908 resetLastRes.append(":" + pdbResNum);
909 if (!chain.equals(" "))
911 eval.append("." + chain);
912 resetLastRes.append("." + chain);
915 viewer.sendChimeraCommand(eval.toString(), false);
916 viewerCommandHistory(true);
917 // viewer.startListening();
921 private void log(String message)
923 System.err.println("## Chimera log: " + message);
926 private void viewerCommandHistory(boolean enable)
928 // log("(Not yet implemented) History "
929 // + ((debug || enable) ? "on" : "off"));
932 public void loadInline(String string)
936 // viewer.loadInline(strModel, isAppend);
938 // construct fake fullPathName and fileName so we can identify the file
940 // Then, construct pass a reader for the string to Jmol.
941 // ((org.jmol.Viewer.Viewer) viewer).loadModelFromFile(fullPathName,
942 // fileName, null, reader, false, null, null, 0);
943 // viewer.openStringInline(string);
944 log("cannot load inline in Chimera, yet");
947 public void mouseOverStructure(int atomIndex, String strInfo)
949 // function to parse a mouseOver event from Chimera
952 int alocsep = strInfo.indexOf("^");
953 int mdlSep = strInfo.indexOf("/");
954 int chainSeparator = strInfo.indexOf(":"), chainSeparator1 = -1;
956 if (chainSeparator == -1)
958 chainSeparator = strInfo.indexOf(".");
959 if (mdlSep > -1 && mdlSep < chainSeparator)
961 chainSeparator1 = chainSeparator;
962 chainSeparator = mdlSep;
965 // handle insertion codes
968 pdbResNum = Integer.parseInt(strInfo.substring(
969 strInfo.indexOf("]") + 1, alocsep));
974 pdbResNum = Integer.parseInt(strInfo.substring(
975 strInfo.indexOf("]") + 1, chainSeparator));
979 if (strInfo.indexOf(":") > -1)
981 chainId = strInfo.substring(strInfo.indexOf(":") + 1,
982 strInfo.indexOf("."));
989 String pdbfilename = modelFileNames[frameNo]; // default is first or current
993 if (chainSeparator1 == -1)
995 chainSeparator1 = strInfo.indexOf(".", mdlSep);
997 String mdlId = (chainSeparator1 > -1) ? strInfo.substring(mdlSep + 1,
998 chainSeparator1) : strInfo.substring(mdlSep + 1);
1001 // recover PDB filename for the model hovered over.
1002 int _mp = _modelFileNameMap.length - 1, mnumber = new Integer(mdlId)
1004 while (mnumber < _modelFileNameMap[_mp])
1008 pdbfilename = modelFileNames[_mp];
1009 if (pdbfilename == null)
1011 // pdbfilename = new File(viewer.getModelFileName(mnumber))
1012 // .getAbsolutePath();
1015 } catch (Exception e)
1020 if (lastMessage == null || !lastMessage.equals(strInfo))
1022 getSsm().mouseOverStructure(pdbResNum, chainId, pdbfilename);
1025 lastMessage = strInfo;
1028 public void notifyAtomPicked(int atomIndex, String strInfo, String strData)
1031 * this implements the toggle label behaviour copied from the original
1032 * structure viewer, MCView
1034 if (strData != null)
1036 System.err.println("Ignoring additional pick data string " + strData);
1038 // rewrite these selections for chimera (DNA, RNA and protein)
1039 int chainSeparator = strInfo.indexOf(":");
1041 if (chainSeparator == -1)
1043 chainSeparator = strInfo.indexOf(".");
1046 String picked = strInfo.substring(strInfo.indexOf("]") + 1,
1048 String mdlString = "";
1049 if ((p = strInfo.indexOf(":")) > -1)
1051 picked += strInfo.substring(p + 1, strInfo.indexOf("."));
1054 if ((p = strInfo.indexOf("/")) > -1)
1056 mdlString += strInfo.substring(p, strInfo.indexOf(" #"));
1058 picked = "((" + picked + ".CA" + mdlString + ")|(" + picked + ".P"
1060 viewerCommandHistory(false);
1062 if (!atomsPicked.contains(picked))
1064 viewer.select(picked);
1065 atomsPicked.add(picked);
1069 viewer.select("not " + picked);
1070 atomsPicked.remove(picked);
1072 viewerCommandHistory(true);
1073 // TODO: in application this happens
1075 // if (scriptWindow != null)
1077 // scriptWindow.sendConsoleMessage(strInfo);
1078 // scriptWindow.sendConsoleMessage("\n");
1083 // incremented every time a load notification is successfully handled -
1084 // lightweight mechanism for other threads to detect when they can start
1085 // referring to new structures.
1086 private long loadNotifiesHandled = 0;
1088 public long getLoadNotifiesHandled()
1090 return loadNotifiesHandled;
1093 public void notifyFileLoaded(String fullPathName, String fileName2,
1094 String modelName, String errorMsg, int modelParts)
1096 if (errorMsg != null)
1098 fileLoadingError = errorMsg;
1102 // TODO: deal sensibly with models loaded inLine:
1103 // modelName will be null, as will fullPathName.
1105 // the rest of this routine ignores the arguments, and simply interrogates
1106 // the Jmol view to find out what structures it contains, and adds them to
1107 // the structure selection manager.
1108 fileLoadingError = null;
1109 String[] oldmodels = modelFileNames;
1110 modelFileNames = null;
1111 chainNames = new ArrayList<String>();
1112 chainFile = new HashMap<String, String>();
1113 boolean notifyLoaded = false;
1114 String[] modelfilenames = getPdbFile();
1115 // first check if we've lost any structures
1116 if (oldmodels != null && oldmodels.length > 0)
1119 for (int i = 0; i < oldmodels.length; i++)
1121 for (int n = 0; n < modelfilenames.length; n++)
1123 if (modelfilenames[n] == oldmodels[i])
1125 oldmodels[i] = null;
1129 if (oldmodels[i] != null)
1136 String[] oldmfn = new String[oldm];
1138 for (int i = 0; i < oldmodels.length; i++)
1140 if (oldmodels[i] != null)
1142 oldmfn[oldm++] = oldmodels[i];
1145 // deregister the Jmol instance for these structures - we'll add
1146 // ourselves again at the end for the current structure set.
1147 getSsm().removeStructureViewerListener(this, oldmfn);
1151 // register ourselves as a listener and notify the gui that it needs to
1153 getSsm().addStructureViewerListener(this);
1157 FeatureRenderer fr = getFeatureRenderer(null);
1163 loadNotifiesHandled++;
1165 setLoadingFromArchive(false);
1168 public void setJalviewColourScheme(ColourSchemeI cs)
1170 colourBySequence = false;
1180 // Chimera expects RBG values in the range 0-1
1181 final double normalise = 255D;
1182 viewerCommandHistory(false);
1183 // TODO: Switch between nucleotide or aa selection expressions
1184 Enumeration en = ResidueProperties.aa3Hash.keys();
1185 StringBuilder command = new StringBuilder(128);
1186 command.append("color white;");
1187 while (en.hasMoreElements())
1189 res = en.nextElement().toString();
1190 index = ((Integer) ResidueProperties.aa3Hash.get(res)).intValue();
1196 col = cs.findColour(ResidueProperties.aa[index].charAt(0));
1197 command.append("color " + col.getRed() / normalise + ","
1198 + col.getGreen() / normalise + "," + col.getBlue()
1199 / normalise + " ::" + res + ";");
1202 evalStateCommand(command.toString(),false);
1203 viewerCommandHistory(true);
1207 * called when the binding thinks the UI needs to be refreshed after a Chimera
1208 * state change. this could be because structures were loaded, or because an
1209 * error has occurred.
1211 public abstract void refreshGUI();
1213 public void setLoadingFromArchive(boolean loadingFromArchive)
1215 this.loadingFromArchive = loadingFromArchive;
1220 * @return true if Chimeral is still restoring state or loading is still going
1221 * on (see setFinsihedLoadingFromArchive)
1223 public boolean isLoadingFromArchive()
1225 return loadingFromArchive && !loadingFinished;
1229 * modify flag which controls if sequence colouring events are honoured by the
1230 * binding. Should be true for normal operation
1232 * @param finishedLoading
1234 public void setFinishedLoadingFromArchive(boolean finishedLoading)
1236 loadingFinished = finishedLoading;
1240 * Send the Chimera 'background solid <color>" command.
1243 * ://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/background
1247 public void setBackgroundColour(Color col)
1249 viewerCommandHistory(false);
1250 double normalise = 255D;
1251 final String command = "background solid " + col.getRed() / normalise + ","
1252 + col.getGreen() / normalise + "," + col.getBlue()
1254 viewer.sendChimeraCommand(command, false);
1255 viewerCommandHistory(true);
1261 * @return text report of alignment between pdbfile and any associated
1262 * alignment sequences
1264 public String printMapping(String pdbfile)
1266 return getSsm().printMapping(pdbfile);
1270 * Ask Chimera to save its session to the given file. Returns true if
1271 * successful, else false.
1276 public boolean saveSession(String filepath)
1278 if (isChimeraRunning())
1280 List<String> reply = viewer.sendChimeraCommand("save " + filepath,
1282 if (reply.contains("Session written"))
1289 .error("Error saving Chimera session: " + reply.toString());
1296 * Ask Chimera to open a session file. Returns true if successful, else false.
1297 * The filename must have a .py extension for this command to work.
1302 public boolean openSession(String filepath)
1304 evalStateCommand("open " + filepath, true);
1305 // todo: test for failure - how?