X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fext%2Frbvi%2Fchimera%2FJalviewChimeraBinding.java;h=b345c5ea428e833f63049b8853a71dd752922ed9;hb=31f1b88951cc5ff3aea7ae0bc1a9d8fbdd264ea3;hp=6e6f5ee469bffcfcce7bfc8b3194f50e03ba9395;hpb=95e0cdd0a7da15cad5d1d3adbb621419d84e135a;p=jalview.git diff --git a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java index 6e6f5ee..b345c5e 100644 --- a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java +++ b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java @@ -28,7 +28,6 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; -import jalview.io.AppletFormatAdapter; import jalview.schemes.ColourSchemeI; import jalview.schemes.ResidueProperties; import jalview.structure.StructureMapping; @@ -39,7 +38,6 @@ import jalview.util.Comparison; import jalview.util.MessageManager; import java.awt.Color; -import java.io.File; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; @@ -65,123 +63,106 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel private ChimeraManager viewer; - /** + /* * set if chimera state is being restored from some source - instructs binding * not to apply default display style when structure set is updated for first * time. */ private boolean loadingFromArchive = false; - /** - * second flag to indicate if the Chimera viewer should ignore sequence - * colouring events from the structure manager because the GUI is still - * setting up + /* + * flag to indicate if the Chimera viewer should ignore sequence colouring + * events from the structure manager because the GUI is still setting up */ private boolean loadingFinished = true; - /** + /* * state flag used to check if the Chimera viewer's paint method can be called */ private boolean finishedInit = false; - public boolean isFinishedInit() - { - return finishedInit; - } - - public void setFinishedInit(boolean finishedInit) - { - this.finishedInit = finishedInit; - } - - boolean allChainsSelected = false; - - /** - * when true, try to search the associated datamodel for sequences that are - * associated with any unknown structures in the Chimera view. - */ - private boolean associateNewStructs = false; + private List atomsPicked = new ArrayList(); - List atomsPicked = new ArrayList(); - - public List chainNames; + private List chainNames; private Map chainFile; - StringBuffer eval = new StringBuffer(); + private StringBuffer eval = new StringBuffer(); public String fileLoadingError; - private Map> chimmaps = new LinkedHashMap>(); - - private List mdlToFile = new ArrayList(); + /* + * Map of ChimeraModel objects keyed by PDB full local file name + */ + private Map> chimeraMaps = new LinkedHashMap>(); - /** + /* * the default or current model displayed if the model cannot be identified * from the selection message */ - int frameNo = 0; + private int frameNo = 0; - String lastCommand; + private String lastCommand; - String lastMessage; + private String lastMessage; - boolean loadedInline; + private boolean loadedInline; + /** + * Open a PDB structure file in Chimera and set up mappings from Jalview. + * + * We check if the PDB model id is already loaded in Chimera, if so don't + * reopen it. This is the case if Chimera has opened a saved session file. + * + * @param pe + * @return + */ public boolean openFile(PDBEntry pe) { String file = pe.getFile(); try { + List modelsToMap = new ArrayList(); List oldList = viewer.getModelList(); - viewer.openModel(file, pe.getId(), ModelType.PDB_MODEL); - List newList = viewer.getModelList(); - if (oldList.size() < newList.size()) + boolean alreadyOpen = false; + + /* + * If Chimera already has this model, don't reopen it, but do remap it. + */ + for (ChimeraModel open : oldList) { - while (oldList.size() > 0) + if (open.getModelName().equals(pe.getId())) { - oldList.remove(0); - newList.remove(0); - } - chimmaps.put(file, newList); - for (ChimeraModel cm : newList) - { - while (mdlToFile.size() < 1 + cm.getModelNumber()) - { - mdlToFile.add(new String("")); - } - mdlToFile.set(cm.getModelNumber(), file); + alreadyOpen = true; + modelsToMap.add(open); } + } - File fl = new File(file); - String protocol = AppletFormatAdapter.URL; - try - { - if (fl.exists()) - { - protocol = AppletFormatAdapter.FILE; - } - } catch (Exception e) - { - } catch (Error e) - { - } - // Explicitly map to the filename used by Chimera ; - // pdbentry[pe].getFile(), protocol); + /* + * If Chimera doesn't yet have this model, ask it to open it, and retrieve + * the model names added by Chimera. + */ + if (!alreadyOpen) + { + viewer.openModel(file, pe.getId(), ModelType.PDB_MODEL); + modelsToMap = viewer.getModelList(); + modelsToMap.removeAll(oldList); + } + + chimeraMaps.put(file, modelsToMap); - if (getSsm() != null) + if (getSsm() != null) + { + getSsm().addStructureViewerListener(this); + // ssm.addSelectionListener(this); + FeatureRenderer fr = getFeatureRenderer(null); + if (fr != null) { - getSsm().addStructureViewerListener(this); - // ssm.addSelectionListener(this); - FeatureRenderer fr = getFeatureRenderer(null); - if (fr != null) - { - fr.featuresAdded(); - } - refreshGUI(); + fr.featuresAdded(); } - return true; + refreshGUI(); } + return true; } catch (Exception q) { log("Exception when trying to open model " + file + "\n" @@ -642,7 +623,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel { if (!viewer.isChimeraLaunched()) { - viewer.launchChimera(csm.getChimeraPaths()); + viewer.launchChimera(StructureManager.getChimeraPaths()); } if (!viewer.isChimeraLaunched()) { @@ -662,7 +643,8 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel } /** - * Send a command to Chimera, and optionally log any responses. + * Send a command to Chimera, launching it first if necessary, and optionally + * log any responses. * * @param command * @param logResponse @@ -673,28 +655,12 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel checkLaunched(); if (lastCommand == null || !lastCommand.equals(command)) { -// Thread t = new Thread(new Runnable() -// { -// @Override -// public void run() -// { // trim command or it may never find a match in the replyLog!! lastReply = viewer.sendChimeraCommand(command.trim(), logResponse); if (debug && logResponse) - { - log("Response from command ('" + command + "') was:\n" - + lastReply); - } -// } -// }); - // TODO - use j7/8 thread management -// try -// { -// t.join(); -// } catch (InterruptedException foo) -// { -// } -// ; + { + log("Response from command ('" + command + "') was:\n" + lastReply); + } } viewerCommandHistory(true); lastCommand = command; @@ -853,8 +819,8 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel // // System.arraycopy(mset, 0, modelFileNames, 0, j); // } - return chimmaps.keySet().toArray( - modelFileNames = new String[chimmaps.size()]); + return chimeraMaps.keySet().toArray( + modelFileNames = new String[chimeraMaps.size()]); } /** @@ -881,7 +847,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel public void highlightAtom(int atomIndex, int pdbResNum, String chain, String pdbfile) { - List cms = chimmaps.get(pdbfile); + List cms = chimeraMaps.get(pdbfile); if (cms != null) { int mdlNum = cms.get(0).getModelNumber(); @@ -1306,4 +1272,19 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel return true; } + public boolean isFinishedInit() + { + return finishedInit; + } + + public void setFinishedInit(boolean finishedInit) + { + this.finishedInit = finishedInit; + } + + public List getChainNames() + { + return chainNames; + } + }