X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fext%2Frbvi%2Fchimera%2FJalviewChimeraBinding.java;h=2534421761f6f4a08889019e945a8225c4557b07;hb=23e1ca45f5adac64d191f1e3e7d4d64ae52eaa03;hp=e5934bfd865bc0273963975c891306ee5dcb7205;hpb=c19d2a91ca05e052e3408bf5852d88eb5d0608f1;p=jalview.git diff --git a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java index e5934bf..2534421 100644 --- a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java +++ b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2) - * Copyright (C) 2015 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -27,14 +27,17 @@ import jalview.bin.Cache; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.PDBEntry; +import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.httpserver.AbstractRequestHandler; import jalview.schemes.ColourSchemeI; import jalview.schemes.ResidueProperties; import jalview.structure.AtomSpec; +import jalview.structure.StructureMapping; import jalview.structure.StructureMappingcommandSet; import jalview.structure.StructureSelectionManager; import jalview.structures.models.AAStructureBindingModel; +import jalview.util.Comparison; import jalview.util.MessageManager; import java.awt.Color; @@ -101,16 +104,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel private String lastCommand; - private boolean loadedInline; - - /** - * current set of model filenames loaded - */ - String[] modelFileNames = null; - - String lastMousedOverAtomSpec; - - private List lastReply; + String lastHighlightCommand; /* * incremented every time a load notification is successfully handled - @@ -617,7 +611,8 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel if (lastCommand == null || !lastCommand.equals(command)) { // trim command or it may never find a match in the replyLog!! - lastReply = viewer.sendChimeraCommand(command.trim(), logResponse); + List lastReply = viewer.sendChimeraCommand(command.trim(), + logResponse); if (logResponse && debug) { log("Response from command ('" + command + "') was:\n" + lastReply); @@ -715,17 +710,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel // End StructureListener // ////////////////////////// - public Color getColour(int atomIndex, int pdbResNum, String chain, - String pdbfile) - { - if (getModelNum(pdbfile) < 0) - { - return null; - } - log("get model / residue colour attribute unimplemented"); - return null; - } - /** * returns the current featureRenderer that should be used to colour the * structures @@ -795,15 +779,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel } /** - * map from string to applet - */ - public Map getRegistryInfo() - { - // TODO Auto-generated method stub - return null; - } - - /** * returns the current sequenceRenderer that should be used to colour the * structures * @@ -815,22 +790,22 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel AlignmentViewPanel alignment); /** - * Construct and send a command to highlight zero, one or more atoms. - * - *
-   * Done by generating a command like (to 'highlight' position 44)
-   *   show #0:44.C
-   * 
+ * Construct and send a command to highlight zero, one or more atoms. We do + * this by sending an "rlabel" command to show the residue label at that + * position. */ @Override public void highlightAtoms(List atoms) { - if (atoms == null) + if (atoms == null || atoms.size() == 0) { return; } - StringBuilder atomSpecs = new StringBuilder(); + + StringBuilder cmd = new StringBuilder(128); boolean first = true; + boolean found = false; + for (AtomSpec atom : atoms) { int pdbResNum = atom.getPdbResNum(); @@ -839,39 +814,46 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel List cms = chimeraMaps.get(pdbfile); if (cms != null && !cms.isEmpty()) { - /* - * Formatting as #0:34.A,#1:33.A doesn't work as desired, so instead we - * concatenate multiple 'show' commands - */ - atomSpecs.append(first ? "" : ";show "); + if (first) + { + cmd.append("rlabel #").append(cms.get(0).getModelNumber()) + .append(":"); + } + else + { + cmd.append(","); + } first = false; - atomSpecs.append("#" + cms.get(0).getModelNumber()); - atomSpecs.append(":" + pdbResNum); + cmd.append(pdbResNum); if (!chain.equals(" ")) { - atomSpecs.append("." + chain); + cmd.append(".").append(chain); } + found = true; } } - String atomSpec = atomSpecs.toString(); + String command = cmd.toString(); /* - * Avoid repeated commands for the same residue + * avoid repeated commands for the same residue */ - if (atomSpec.equals(lastMousedOverAtomSpec)) + if (command.equals(lastHighlightCommand)) { return; } - StringBuilder command = new StringBuilder(32); - viewerCommandHistory(false); - if (atomSpec.length() > 0) + /* + * unshow the label for the previous residue + */ + if (lastHighlightCommand != null) { - command.append("show ").append(atomSpec); - viewer.sendChimeraCommand(command.toString(), false); + viewer.sendChimeraCommand("~" + lastHighlightCommand, false); } - viewerCommandHistory(true); - this.lastMousedOverAtomSpec = atomSpec; + if (found) + { + viewer.sendChimeraCommand(command, false); + } + this.lastHighlightCommand = command; } /** @@ -994,6 +976,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel */ public abstract void refreshGUI(); + @Override public void setLoadingFromArchive(boolean loadingFromArchive) { this.loadingFromArchive = loadingFromArchive; @@ -1004,6 +987,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel * @return true if Chimeral is still restoring state or loading is still going * on (see setFinsihedLoadingFromArchive) */ + @Override public boolean isLoadingFromArchive() { return loadingFromArchive && !loadingFinished; @@ -1015,6 +999,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel * * @param finishedLoading */ + @Override public void setFinishedLoadingFromArchive(boolean finishedLoading) { loadingFinished = finishedLoading; @@ -1115,4 +1100,115 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel { sendChimeraCommand("focus", false); } + + /** + * Send a 'show' command for all atoms in the currently selected columns + * + * TODO: pull up to abstract structure viewer interface + * + * @param vp + */ + public void highlightSelection(AlignmentViewPanel vp) + { + List cols = vp.getAlignViewport().getColumnSelection() + .getSelected(); + AlignmentI alignment = vp.getAlignment(); + StructureSelectionManager sm = getSsm(); + for (SequenceI seq : alignment.getSequences()) + { + /* + * convert selected columns into sequence positions + */ + int[] positions = new int[cols.size()]; + int i = 0; + for (Integer col : cols) + { + positions[i++] = seq.findPosition(col); + } + sm.highlightStructure(this, seq, positions); + } + } + + /** + * Constructs and send commands to Chimera to set attributes on residues for + * features visible in Jalview + * + * @param avp + */ + public void sendFeaturesToChimera(AlignmentViewPanel avp) + { + // TODO send a command per feature with the range of residues it applies to + AlignmentI alignment = avp.getAlignment(); + FeatureRenderer fr = getFeatureRenderer(avp); + + /* + * fr is null if feature display is turned off + */ + if (fr == null) + { + return; + } + + String[] files = getPdbFile(); + if (files == null) + { + return; + } + for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) + { + StructureMapping[] mapping = getSsm().getMapping(files[pdbfnum]); + + if (mapping == null || mapping.length < 1) + { + continue; + } + + int lastPos = -1; + for (int seqNo = 0; seqNo < getSequence()[pdbfnum].length; seqNo++) + { + for (int m = 0; m < mapping.length; m++) + { + final SequenceI seq = getSequence()[pdbfnum][seqNo]; + int sp = alignment.findIndex(seq); + if (mapping[m].getSequence() == seq && sp > -1) + { + SequenceI asp = alignment.getSequenceAt(sp); + for (int r = 0; r < asp.getLength(); r++) + { + // no mapping to gaps in sequence + if (Comparison.isGap(asp.getCharAt(r))) + { + continue; + } + int residuePos = asp.findPosition(r); + int pos = mapping[m].getPDBResNum(residuePos); + + if (pos < 1 || pos == lastPos) + { + continue; + } + final String chain = mapping[m].getChain(); + List features = fr.findFeaturesAtRes(asp, + residuePos); + for (SequenceFeature feature : features) + { + String desc = feature.getDescription(); + float score = feature.getScore(); + if (score != 0 && score != Float.NaN) + { + desc = Float.toString(score); + } + String attName = "jv:" + + feature.getType().replace(" ", "_"); + String cmd = "setattr r " + attName + " \"" + + desc + "\" #" + pdbfnum + ":" + pos + "." + chain; + System.out.println(cmd); + sendAsynchronousCommand(cmd, null); + } + } + } + } + } + } + } }