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.datamodel.AlignmentI;
27 import jalview.datamodel.ColumnSelection;
28 import jalview.datamodel.PDBEntry;
29 import jalview.datamodel.SequenceI;
30 import jalview.io.AppletFormatAdapter;
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;
42 import java.util.ArrayList;
43 import java.util.Enumeration;
44 import java.util.HashMap;
45 import java.util.LinkedHashMap;
46 import java.util.List;
49 import ext.edu.ucsf.rbvi.strucviz2.ChimeraManager;
50 import ext.edu.ucsf.rbvi.strucviz2.ChimeraModel;
51 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
52 import ext.edu.ucsf.rbvi.strucviz2.StructureManager.ModelType;
54 public abstract class JalviewChimeraBinding extends AAStructureBindingModel
57 private static final boolean debug = false;
59 private static final String PHOSPHORUS = "P";
61 private static final String ALPHACARBON = "CA";
63 private StructureManager csm;
65 private ChimeraManager viewer;
68 * set if chimera state is being restored from some source - instructs binding
69 * not to apply default display style when structure set is updated for first
72 private boolean loadingFromArchive = false;
75 * second flag to indicate if the Chimera viewer should ignore sequence
76 * colouring events from the structure manager because the GUI is still
79 private boolean loadingFinished = true;
82 * state flag used to check if the Chimera viewer's paint method can be called
84 private boolean finishedInit = false;
86 public boolean isFinishedInit()
91 public void setFinishedInit(boolean finishedInit)
93 this.finishedInit = finishedInit;
96 boolean allChainsSelected = false;
99 * when true, try to search the associated datamodel for sequences that are
100 * associated with any unknown structures in the Chimera view.
102 private boolean associateNewStructs = false;
104 List<String> atomsPicked = new ArrayList<String>();
106 public List<String> chainNames;
108 private Map<String, String> chainFile;
110 StringBuffer eval = new StringBuffer();
112 public String fileLoadingError;
114 private Map<String, List<ChimeraModel>> chimmaps = new LinkedHashMap<String, List<ChimeraModel>>();
116 private List<String> mdlToFile = new ArrayList<String>();
119 * the default or current model displayed if the model cannot be identified
120 * from the selection message
128 boolean loadedInline;
130 public boolean openFile(PDBEntry pe)
132 String file = pe.getFile();
135 List<ChimeraModel> oldList = viewer.getModelList();
136 viewer.openModel(file, pe.getId(), ModelType.PDB_MODEL);
137 List<ChimeraModel> newList = viewer.getModelList();
138 if (oldList.size() < newList.size())
140 while (oldList.size() > 0)
145 chimmaps.put(file, newList);
146 for (ChimeraModel cm : newList)
148 while (mdlToFile.size() < 1 + cm.getModelNumber())
150 mdlToFile.add(new String(""));
152 mdlToFile.set(cm.getModelNumber(), file);
155 File fl = new File(file);
156 String protocol = AppletFormatAdapter.URL;
161 protocol = AppletFormatAdapter.FILE;
163 } catch (Exception e)
168 // Explicitly map to the filename used by Chimera ;
169 // pdbentry[pe].getFile(), protocol);
171 if (getSsm() != null)
173 getSsm().addStructureViewerListener(this);
174 // ssm.addSelectionListener(this);
175 FeatureRenderer fr = getFeatureRenderer(null);
184 } catch (Exception q)
186 log("Exception when trying to open model " + file + "\n"
194 * current set of model filenames loaded
196 String[] modelFileNames = null;
199 StringBuffer resetLastRes = new StringBuffer();
201 private List<String> lastReply;
212 public JalviewChimeraBinding(StructureSelectionManager ssm,
213 PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains,
216 super(ssm, pdbentry, sequenceIs, chains, protocol);
217 viewer = new ChimeraManager(
218 csm = new ext.edu.ucsf.rbvi.strucviz2.StructureManager(true));
227 public JalviewChimeraBinding(StructureSelectionManager ssm,
228 ChimeraManager theViewer)
232 csm = viewer.getStructureManager();
236 * Construct a title string for the viewer window based on the data Jalview
242 public String getViewerTitle(boolean verbose)
244 return getViewerTitle("Chimera", verbose);
248 * prepare the view for a given set of models/chains. chainList contains
249 * strings of the form 'pdbfilename:Chaincode'
252 * list of chains to make visible
254 public void centerViewer(List<String> toshow)
256 StringBuilder cmd = new StringBuilder(64);
258 for (String lbl : toshow)
264 mlength = lbl.indexOf(":", p);
265 } while (p < mlength && mlength < (lbl.length() - 2));
266 // TODO: lookup each pdb id and recover proper model number for it.
267 cmd.append("#" + getModelNum(chainFile.get(lbl)) + "."
268 + lbl.substring(mlength + 1) + " or ");
270 if (cmd.length() > 0)
272 cmd.setLength(cmd.length() - 4);
274 String cmdstring = cmd.toString();
275 evalStateCommand("~display #*; ~ribbon #*; ribbon " + cmdstring
276 + ";focus " + cmdstring, false);
280 * Close down the Jalview viewer, and (optionally) the associated Chimera
283 public void closeViewer(boolean closeChimera)
285 getSsm().removeStructureViewerListener(this, this.getPdbFile());
288 viewer.exitChimera();
292 releaseUIResources();
295 public void colourByChain()
297 colourBySequence = false;
298 evalStateCommand("rainbow chain", false);
301 public void colourByCharge()
303 colourBySequence = false;
305 "color white;color red ::ASP;color red ::GLU;color blue ::LYS;color blue ::ARG;color yellow ::CYS",
310 * superpose the structures associated with sequences in the alignment
311 * according to their corresponding positions.
313 public void superposeStructures(AlignmentI alignment)
315 superposeStructures(alignment, -1, null);
319 * superpose the structures associated with sequences in the alignment
320 * according to their corresponding positions. ded)
322 * @param refStructure
323 * - select which pdb file to use as reference (default is -1 - the
324 * first structure in the alignment)
326 public void superposeStructures(AlignmentI alignment, int refStructure)
328 superposeStructures(alignment, refStructure, null);
332 * superpose the structures associated with sequences in the alignment
333 * according to their corresponding positions. ded)
335 * @param refStructure
336 * - select which pdb file to use as reference (default is -1 - the
337 * first structure in the alignment)
341 public void superposeStructures(AlignmentI alignment, int refStructure,
342 ColumnSelection hiddenCols)
344 superposeStructures(new AlignmentI[]
345 { alignment }, new int[]
346 { refStructure }, new ColumnSelection[]
350 public void superposeStructures(AlignmentI[] _alignment,
351 int[] _refStructure, ColumnSelection[] _hiddenCols)
353 assert (_alignment.length == _refStructure.length && _alignment.length != _hiddenCols.length);
354 StringBuilder allComs = new StringBuilder(128); // Chimera superposition cmd
355 String[] files = getPdbFile();
356 // check to see if we are still waiting for Chimera files
357 long starttime = System.currentTimeMillis();
358 boolean waiting = true;
362 for (String file : files)
366 // HACK - in Jalview 2.8 this call may not be threadsafe so we catch
367 // every possible exception
368 StructureMapping[] sm = getSsm().getMapping(file);
369 if (sm == null || sm.length == 0)
373 } catch (Exception x)
381 // we wait around for a reasonable time before we give up
383 && System.currentTimeMillis() < (10000 + 1000 * files.length + starttime));
387 .println("RUNTIME PROBLEM: Chimera seems to be taking a long time to process all the structures.");
391 StringBuffer selectioncom = new StringBuffer();
392 for (int a = 0; a < _alignment.length; a++)
394 int refStructure = _refStructure[a];
395 AlignmentI alignment = _alignment[a];
396 ColumnSelection hiddenCols = _hiddenCols[a];
398 && selectioncom.length() > 0
399 && !selectioncom.substring(selectioncom.length() - 1).equals(
402 selectioncom.append(" ");
404 // process this alignment
405 if (refStructure >= files.length)
407 System.err.println("Invalid reference structure value "
411 if (refStructure < -1)
416 boolean matched[] = new boolean[alignment.getWidth()];
417 for (int m = 0; m < matched.length; m++)
420 matched[m] = (hiddenCols != null) ? hiddenCols.isVisible(m) : true;
423 int commonrpositions[][] = new int[files.length][alignment.getWidth()];
424 String isel[] = new String[files.length];
425 String[] targetC = new String[files.length];
426 String[] chainNames = new String[files.length];
427 String[] atomSpec = new String[files.length];
428 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
430 StructureMapping[] mapping = getSsm().getMapping(files[pdbfnum]);
431 // RACE CONDITION - getMapping only returns Jmol loaded filenames once
432 // Jmol callback has completed.
433 if (mapping == null || mapping.length < 1)
435 throw new Error(MessageManager.getString("error.implementation_error_chimera_getting_data"));
438 final int seqCountForPdbFile = getSequence()[pdbfnum].length;
439 for (int s = 0; s < seqCountForPdbFile; s++)
441 for (int sp, m = 0; m < mapping.length; m++)
443 final SequenceI theSequence = getSequence()[pdbfnum][s];
444 if (mapping[m].getSequence() == theSequence
445 && (sp = alignment.findIndex(theSequence)) > -1)
447 if (refStructure == -1)
449 refStructure = pdbfnum;
451 SequenceI asp = alignment.getSequenceAt(sp);
452 for (int r = 0; r < matched.length; r++)
458 matched[r] = false; // assume this is not a good site
459 if (r >= asp.getLength())
464 if (Comparison.isGap(asp.getCharAt(r)))
466 // no mapping to gaps in sequence
469 int t = asp.findPosition(r); // sequence position
470 int apos = mapping[m].getAtomNum(t);
471 int pos = mapping[m].getPDBResNum(t);
473 if (pos < 1 || pos == lastPos)
475 // can't align unmapped sequence
478 matched[r] = true; // this is a good ite
480 // just record this residue position
481 commonrpositions[pdbfnum][r] = pos;
483 // create model selection suffix
484 isel[pdbfnum] = "#" + pdbfnum;
485 if (mapping[m].getChain() == null
486 || mapping[m].getChain().trim().length() == 0)
488 targetC[pdbfnum] = "";
492 targetC[pdbfnum] = "." + mapping[m].getChain();
494 chainNames[pdbfnum] = mapping[m].getPdbId()
496 atomSpec[pdbfnum] = asp.getRNA() != null ? PHOSPHORUS : ALPHACARBON;
497 // move on to next pdb file
498 s = seqCountForPdbFile;
505 // TODO: consider bailing if nmatched less than 4 because superposition
508 // TODO: refactor superposable position search (above) from jmol selection
509 // construction (below)
511 String[] selcom = new String[files.length];
514 // generate select statements to select regions to superimpose structures
516 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
518 String chainCd = targetC[pdbfnum];
521 StringBuffer molsel = new StringBuffer();
522 for (int r = 0; r < matched.length; r++)
530 if (lpos != commonrpositions[pdbfnum][r] - 1)
535 molsel.append((run ? "" : ":") + lpos);
536 molsel.append(chainCd);
542 // continuous run - and lpos >-1
545 // at the beginning, so add dash
546 molsel.append(":" + lpos);
551 lpos = commonrpositions[pdbfnum][r];
552 // molsel.append(lpos);
555 // add final selection phrase
558 molsel.append((run ? "" : ":") + lpos);
559 molsel.append(chainCd);
560 // molsel.append("");
562 if (molsel.length() > 1)
564 selcom[pdbfnum] = molsel.toString();
565 selectioncom.append("#" + pdbfnum);
566 selectioncom.append(selcom[pdbfnum]);
567 selectioncom.append(" ");
568 if (pdbfnum < files.length - 1)
570 selectioncom.append("| ");
575 selcom[pdbfnum] = null;
579 StringBuilder command = new StringBuilder(256);
580 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
582 if (pdbfnum == refStructure || selcom[pdbfnum] == null
583 || selcom[refStructure] == null)
587 if (command.length() > 0)
593 * Form Chimera match command, from the 'new' structure to the
594 * 'reference' structure e.g. (residues 1-91, chain B/A, alphacarbons):
596 * match #1:1-91.B@CA #0:1-91.A@CA
599 * https://www.cgl.ucsf.edu/chimera/docs/UsersGuide/midas/match.html
601 command.append("match #" + pdbfnum /* +".1" */);
602 // TODO: handle sub-models
603 command.append(selcom[pdbfnum]);
604 command.append("@" + atomSpec[pdbfnum]);
605 command.append(" #" + refStructure /* +".1" */);
606 command.append(selcom[refStructure]);
607 command.append("@" + atomSpec[refStructure]);
609 if (selectioncom.length() > 0)
613 System.out.println("Select regions:\n" + selectioncom.toString());
614 System.out.println("Superimpose command(s):\n"
615 + command.toString());
617 allComs.append("~display all; chain @CA|P; ribbon "
618 + selectioncom.toString() + ";"+command.toString());
619 // selcom.append("; ribbons; ");
622 if (selectioncom.length() > 0)
623 {// finally, mark all regions that were superposed.
624 if (selectioncom.substring(selectioncom.length() - 1).equals("|"))
626 selectioncom.setLength(selectioncom.length() - 1);
630 System.out.println("Select regions:\n" + selectioncom.toString());
632 allComs.append("; ~display all; chain @CA|P; ribbon "
633 + selectioncom.toString() + "; focus");
634 // evalStateCommand("select *; backbone; select "+selcom.toString()+"; cartoons; center "+selcom.toString());
635 evalStateCommand(allComs.toString(), true /* false */);
640 private void checkLaunched()
642 if (!viewer.isChimeraLaunched())
644 viewer.launchChimera(csm.getChimeraPaths());
646 if (!viewer.isChimeraLaunched())
648 log("Failed to launch Chimera!");
653 * Answers true if the Chimera process is still running, false if ended or not
658 public boolean isChimeraRunning()
660 return viewer.isChimeraLaunched();
664 * Send a command to Chimera, and optionally log any responses.
669 public void evalStateCommand(final String command, boolean logResponse)
671 viewerCommandHistory(false);
673 if (lastCommand == null || !lastCommand.equals(command))
675 // Thread t = new Thread(new Runnable()
680 // trim command or it may never find a match in the replyLog!!
681 lastReply = viewer.sendChimeraCommand(command.trim(), logResponse);
682 if (debug && logResponse)
684 log("Response from command ('" + command + "') was:\n"
689 // TODO - use j7/8 thread management
693 // } catch (InterruptedException foo)
698 viewerCommandHistory(true);
699 lastCommand = command;
703 * colour any structures associated with sequences in the given alignment
704 * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
705 * if colourBySequence is enabled.
707 public void colourBySequence(boolean showFeatures,
708 jalview.api.AlignmentViewPanel alignmentv)
710 if (!colourBySequence || !loadingFinished)
714 if (getSsm() == null)
718 String[] files = getPdbFile();
720 SequenceRenderer sr = getSequenceRenderer(alignmentv);
722 FeatureRenderer fr = null;
725 fr = getFeatureRenderer(alignmentv);
727 AlignmentI alignment = alignmentv.getAlignment();
729 for (jalview.structure.StructureMappingcommandSet cpdbbyseq : getColourBySequenceCommands(files, sr, fr, alignment))
731 for (String command : cpdbbyseq.commands)
733 executeWhenReady(command);
745 protected StructureMappingcommandSet[] getColourBySequenceCommands(
746 String[] files, SequenceRenderer sr, FeatureRenderer fr,
747 AlignmentI alignment)
749 return ChimeraCommands
750 .getColourBySequenceCommand(getSsm(), files, getSequence(), sr,
758 protected void executeWhenReady(String command)
761 evalStateCommand(command, false);
765 private void waitForChimera()
767 while (viewer != null && viewer.isBusy())
771 } catch (InterruptedException q)
778 // End StructureListener
779 // //////////////////////////
781 public Color getColour(int atomIndex, int pdbResNum, String chain,
784 if (getModelNum(pdbfile) < 0)
788 log("get model / residue colour attribute unimplemented");
793 * returns the current featureRenderer that should be used to colour the
800 public abstract FeatureRenderer getFeatureRenderer(
801 AlignmentViewPanel alignment);
804 * instruct the Jalview binding to update the pdbentries vector if necessary
805 * prior to matching the jmol view's contents to the list of structure files
806 * Jalview knows about.
808 public abstract void refreshPdbEntries();
810 private int getModelNum(String modelFileName)
812 String[] mfn = getPdbFile();
817 for (int i = 0; i < mfn.length; i++)
819 if (mfn[i].equalsIgnoreCase(modelFileName))
828 * map between index of model filename returned from getPdbFile and the first
829 * index of models from this file in the viewer. Note - this is not trimmed -
830 * use getPdbFile to get number of unique models.
832 private int _modelFileNameMap[];
834 // ////////////////////////////////
835 // /StructureListener
836 public synchronized String[] getPdbFile()
840 return new String[0];
842 // if (modelFileNames == null)
844 // Collection<ChimeraModel> chimodels = viewer.getChimeraModels();
845 // _modelFileNameMap = new int[chimodels.size()];
847 // for (ChimeraModel chimodel : chimodels)
849 // String mdlName = chimodel.getModelName();
851 // modelFileNames = new String[j];
852 // // System.arraycopy(mset, 0, modelFileNames, 0, j);
855 return chimmaps.keySet().toArray(
856 modelFileNames = new String[chimmaps.size()]);
860 * map from string to applet
862 public Map getRegistryInfo()
864 // TODO Auto-generated method stub
869 * returns the current sequenceRenderer that should be used to colour the
876 public abstract SequenceRenderer getSequenceRenderer(
877 AlignmentViewPanel alignment);
880 public void highlightAtom(int atomIndex, int pdbResNum, String chain,
883 List<ChimeraModel> cms = chimmaps.get(pdbfile);
886 int mdlNum = cms.get(0).getModelNumber();
888 viewerCommandHistory(false);
889 // viewer.stopListening();
890 if (resetLastRes.length() > 0)
893 eval.append(resetLastRes.toString() + ";");
896 eval.append("display "); // +modelNum
898 resetLastRes.setLength(0);
899 resetLastRes.append("~display ");
901 eval.append(" #" + (mdlNum));
902 resetLastRes.append(" #" + (mdlNum));
904 // complete select string
906 eval.append(":" + pdbResNum);
907 resetLastRes.append(":" + pdbResNum);
908 if (!chain.equals(" "))
910 eval.append("." + chain);
911 resetLastRes.append("." + chain);
914 viewer.sendChimeraCommand(eval.toString(), false);
915 viewerCommandHistory(true);
916 // viewer.startListening();
920 private void log(String message)
922 System.err.println("## Chimera log: " + message);
925 private void viewerCommandHistory(boolean enable)
927 // log("(Not yet implemented) History "
928 // + ((debug || enable) ? "on" : "off"));
931 public void loadInline(String string)
935 // viewer.loadInline(strModel, isAppend);
937 // construct fake fullPathName and fileName so we can identify the file
939 // Then, construct pass a reader for the string to Jmol.
940 // ((org.jmol.Viewer.Viewer) viewer).loadModelFromFile(fullPathName,
941 // fileName, null, reader, false, null, null, 0);
942 // viewer.openStringInline(string);
943 log("cannot load inline in Chimera, yet");
946 public void mouseOverStructure(int atomIndex, String strInfo)
948 // function to parse a mouseOver event from Chimera
951 int alocsep = strInfo.indexOf("^");
952 int mdlSep = strInfo.indexOf("/");
953 int chainSeparator = strInfo.indexOf(":"), chainSeparator1 = -1;
955 if (chainSeparator == -1)
957 chainSeparator = strInfo.indexOf(".");
958 if (mdlSep > -1 && mdlSep < chainSeparator)
960 chainSeparator1 = chainSeparator;
961 chainSeparator = mdlSep;
964 // handle insertion codes
967 pdbResNum = Integer.parseInt(strInfo.substring(
968 strInfo.indexOf("]") + 1, alocsep));
973 pdbResNum = Integer.parseInt(strInfo.substring(
974 strInfo.indexOf("]") + 1, chainSeparator));
978 if (strInfo.indexOf(":") > -1)
980 chainId = strInfo.substring(strInfo.indexOf(":") + 1,
981 strInfo.indexOf("."));
988 String pdbfilename = modelFileNames[frameNo]; // default is first or current
992 if (chainSeparator1 == -1)
994 chainSeparator1 = strInfo.indexOf(".", mdlSep);
996 String mdlId = (chainSeparator1 > -1) ? strInfo.substring(mdlSep + 1,
997 chainSeparator1) : strInfo.substring(mdlSep + 1);
1000 // recover PDB filename for the model hovered over.
1001 int _mp = _modelFileNameMap.length - 1, mnumber = new Integer(mdlId)
1003 while (mnumber < _modelFileNameMap[_mp])
1007 pdbfilename = modelFileNames[_mp];
1008 if (pdbfilename == null)
1010 // pdbfilename = new File(viewer.getModelFileName(mnumber))
1011 // .getAbsolutePath();
1014 } catch (Exception e)
1019 if (lastMessage == null || !lastMessage.equals(strInfo))
1021 getSsm().mouseOverStructure(pdbResNum, chainId, pdbfilename);
1024 lastMessage = strInfo;
1027 public void notifyAtomPicked(int atomIndex, String strInfo, String strData)
1030 * this implements the toggle label behaviour copied from the original
1031 * structure viewer, MCView
1033 if (strData != null)
1035 System.err.println("Ignoring additional pick data string " + strData);
1037 // rewrite these selections for chimera (DNA, RNA and protein)
1038 int chainSeparator = strInfo.indexOf(":");
1040 if (chainSeparator == -1)
1042 chainSeparator = strInfo.indexOf(".");
1045 String picked = strInfo.substring(strInfo.indexOf("]") + 1,
1047 String mdlString = "";
1048 if ((p = strInfo.indexOf(":")) > -1)
1050 picked += strInfo.substring(p + 1, strInfo.indexOf("."));
1053 if ((p = strInfo.indexOf("/")) > -1)
1055 mdlString += strInfo.substring(p, strInfo.indexOf(" #"));
1057 picked = "((" + picked + ".CA" + mdlString + ")|(" + picked + ".P"
1059 viewerCommandHistory(false);
1061 if (!atomsPicked.contains(picked))
1063 viewer.select(picked);
1064 atomsPicked.add(picked);
1068 viewer.select("not " + picked);
1069 atomsPicked.remove(picked);
1071 viewerCommandHistory(true);
1072 // TODO: in application this happens
1074 // if (scriptWindow != null)
1076 // scriptWindow.sendConsoleMessage(strInfo);
1077 // scriptWindow.sendConsoleMessage("\n");
1082 // incremented every time a load notification is successfully handled -
1083 // lightweight mechanism for other threads to detect when they can start
1084 // referring to new structures.
1085 private long loadNotifiesHandled = 0;
1087 public long getLoadNotifiesHandled()
1089 return loadNotifiesHandled;
1092 public void notifyFileLoaded(String fullPathName, String fileName2,
1093 String modelName, String errorMsg, int modelParts)
1095 if (errorMsg != null)
1097 fileLoadingError = errorMsg;
1101 // TODO: deal sensibly with models loaded inLine:
1102 // modelName will be null, as will fullPathName.
1104 // the rest of this routine ignores the arguments, and simply interrogates
1105 // the Jmol view to find out what structures it contains, and adds them to
1106 // the structure selection manager.
1107 fileLoadingError = null;
1108 String[] oldmodels = modelFileNames;
1109 modelFileNames = null;
1110 chainNames = new ArrayList<String>();
1111 chainFile = new HashMap<String, String>();
1112 boolean notifyLoaded = false;
1113 String[] modelfilenames = getPdbFile();
1114 // first check if we've lost any structures
1115 if (oldmodels != null && oldmodels.length > 0)
1118 for (int i = 0; i < oldmodels.length; i++)
1120 for (int n = 0; n < modelfilenames.length; n++)
1122 if (modelfilenames[n] == oldmodels[i])
1124 oldmodels[i] = null;
1128 if (oldmodels[i] != null)
1135 String[] oldmfn = new String[oldm];
1137 for (int i = 0; i < oldmodels.length; i++)
1139 if (oldmodels[i] != null)
1141 oldmfn[oldm++] = oldmodels[i];
1144 // deregister the Jmol instance for these structures - we'll add
1145 // ourselves again at the end for the current structure set.
1146 getSsm().removeStructureViewerListener(this, oldmfn);
1150 // register ourselves as a listener and notify the gui that it needs to
1152 getSsm().addStructureViewerListener(this);
1156 FeatureRenderer fr = getFeatureRenderer(null);
1162 loadNotifiesHandled++;
1164 setLoadingFromArchive(false);
1167 public void setJalviewColourScheme(ColourSchemeI cs)
1169 colourBySequence = false;
1179 // Chimera expects RBG values in the range 0-1
1180 final double normalise = 255D;
1181 viewerCommandHistory(false);
1182 // TODO: Switch between nucleotide or aa selection expressions
1183 Enumeration en = ResidueProperties.aa3Hash.keys();
1184 StringBuilder command = new StringBuilder(128);
1185 command.append("color white;");
1186 while (en.hasMoreElements())
1188 res = en.nextElement().toString();
1189 index = ((Integer) ResidueProperties.aa3Hash.get(res)).intValue();
1195 col = cs.findColour(ResidueProperties.aa[index].charAt(0));
1196 command.append("color " + col.getRed() / normalise + ","
1197 + col.getGreen() / normalise + "," + col.getBlue()
1198 / normalise + " ::" + res + ";");
1201 evalStateCommand(command.toString(),false);
1202 viewerCommandHistory(true);
1206 * called when the binding thinks the UI needs to be refreshed after a Chimera
1207 * state change. this could be because structures were loaded, or because an
1208 * error has occurred.
1210 public abstract void refreshGUI();
1212 public void setLoadingFromArchive(boolean loadingFromArchive)
1214 this.loadingFromArchive = loadingFromArchive;
1219 * @return true if Chimeral is still restoring state or loading is still going
1220 * on (see setFinsihedLoadingFromArchive)
1222 public boolean isLoadingFromArchive()
1224 return loadingFromArchive && !loadingFinished;
1228 * modify flag which controls if sequence colouring events are honoured by the
1229 * binding. Should be true for normal operation
1231 * @param finishedLoading
1233 public void setFinishedLoadingFromArchive(boolean finishedLoading)
1235 loadingFinished = finishedLoading;
1239 * Send the Chimera 'background solid <color>" command.
1242 * ://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/background
1246 public void setBackgroundColour(Color col)
1248 viewerCommandHistory(false);
1249 double normalise = 255D;
1250 final String command = "background solid " + col.getRed() / normalise + ","
1251 + col.getGreen() / normalise + "," + col.getBlue()
1253 viewer.sendChimeraCommand(command, false);
1254 viewerCommandHistory(true);
1260 * @return text report of alignment between pdbfile and any associated
1261 * alignment sequences
1263 public String printMapping(String pdbfile)
1265 return getSsm().printMapping(pdbfile);
1269 * Ask Chimera to save its session to the given file. Returns true if
1270 * successful, else false.
1275 public boolean saveSession(String filepath)
1277 if (isChimeraRunning())
1279 List<String> reply = viewer.sendChimeraCommand("save " + filepath,
1281 return true; // todo: check for error in reply?
1282 // System.out.println(reply);