From: gmungoc Date: Fri, 15 May 2020 06:29:55 +0000 (+0100) Subject: JAL-3551 raise label on ('highlight') structure residue (wip) X-Git-Tag: Release_2_11_2_0~37^2~18 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=b145d2b4a617f452801953c1b49dae6b65521f14 JAL-3551 raise label on ('highlight') structure residue (wip) --- diff --git a/src/jalview/gui/PymolBindingModel.java b/src/jalview/gui/PymolBindingModel.java index 6787c8a..fcf586a 100644 --- a/src/jalview/gui/PymolBindingModel.java +++ b/src/jalview/gui/PymolBindingModel.java @@ -12,12 +12,20 @@ import jalview.ext.pymol.PymolCommands; import jalview.ext.pymol.PymolManager; import jalview.gui.StructureViewer.ViewerType; import jalview.structure.AtomSpec; +import jalview.structure.StructureCommand; import jalview.structure.StructureCommandI; import jalview.structure.StructureSelectionManager; import jalview.structures.models.AAStructureBindingModel; public class PymolBindingModel extends AAStructureBindingModel { + /* + * format for labels shown on structures when mousing over sequence; + * see https://pymolwiki.org/index.php/Label#examples + * left not final so customisable e.g. with a Groovy script + */ + private static String LABEL_FORMAT = "\"%s %s\" % (resn,resi)"; + private PymolManager pymolManager; private Thread pymolMonitor; @@ -32,6 +40,8 @@ public class PymolBindingModel extends AAStructureBindingModel */ Map pymolObjects = new HashMap<>(); + private String lastLabelSpec; + /** * Constructor * @@ -59,6 +69,37 @@ public class PymolBindingModel extends AAStructureBindingModel @Override public void highlightAtoms(List atoms) { + /* + * https://pymolwiki.org/index.php/Label#examples + */ + StringBuilder sb = new StringBuilder(); + for (AtomSpec atom : atoms) + { + // todo promote to StructureCommandsI.showLabel() + // todo handle CA|P correctly + String modelId = getModelIdForFile(atom.getPdbFile()); + sb.append(String.format(" %s//%s/%d/CA", modelId, + atom.getChain(), + atom.getPdbResNum())); + } + String labelSpec = sb.toString(); + if (labelSpec.equals(lastLabelSpec)) + { + return; + } + StructureCommandI command = new StructureCommand("label", labelSpec, LABEL_FORMAT); + executeCommand(command, false); + + /* + * and remove the label(s) previously shown + */ + if (lastLabelSpec != null) + { + command = new StructureCommand("label", lastLabelSpec, ""); + executeCommand(command, false); + } + + lastLabelSpec = labelSpec; } @Override