X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fext%2Frbvi%2Fchimera%2FChimeraXCommands.java;h=66ecaeafb653deb1c0dea064d959d217c9082686;hb=57738a1f3c19b1c3a00bd3ac5108f8cd0af32f99;hp=d0c5671eba9745da99c9ecb9f5858a0835469a1f;hpb=15684417a64007046f10d193d5c9363be8f88ea7;p=jalview.git diff --git a/src/jalview/ext/rbvi/chimera/ChimeraXCommands.java b/src/jalview/ext/rbvi/chimera/ChimeraXCommands.java index d0c5671..66ecaea 100644 --- a/src/jalview/ext/rbvi/chimera/ChimeraXCommands.java +++ b/src/jalview/ext/rbvi/chimera/ChimeraXCommands.java @@ -21,22 +21,43 @@ package jalview.ext.rbvi.chimera; import java.awt.Color; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import jalview.structure.AtomSpecModel; import jalview.structure.StructureCommand; import jalview.structure.StructureCommandI; -import jalview.util.ColorUtils; +import jalview.structure.StructureCommandsI.AtomSpecType; /** * Routines for generating ChimeraX commands for Jalview/ChimeraX binding */ public class ChimeraXCommands extends ChimeraCommands { + // https://www.cgl.ucsf.edu/chimerax/docs/user/commands/info.html#resattr + private static final StructureCommand LIST_RESIDUE_ATTRIBUTES = new StructureCommand( + "info resattr"); + + // https://www.cgl.ucsf.edu/chimerax/docs/user/commands/exit.html + private static final StructureCommand CLOSE_CHIMERAX = new StructureCommand( + "exit"); + + // https://www.cgl.ucsf.edu/chimerax/docs/user/commands/info.html#notify + private static final StructureCommand STOP_NOTIFY_SELECTION = new StructureCommand( + "info notify stop selection jalview"); + + private static final StructureCommand STOP_NOTIFY_MODELS = new StructureCommand( + "info notify stop models jalview"); + + // https://www.cgl.ucsf.edu/chimerax/docs/user/commands/info.html#selection + private static final StructureCommand GET_SELECTION = new StructureCommand( + "info selection level residue"); + private static final StructureCommand SHOW_BACKBONE = new StructureCommand( "~display all;~ribbon;show @CA|P atoms"); + // https://www.cgl.ucsf.edu/chimerax/docs/user/commands/view.html private static final StructureCommand FOCUS_VIEW = new StructureCommand( "view"); @@ -56,13 +77,6 @@ public class ChimeraXCommands extends ChimeraCommands } @Override - public StructureCommandI setBackgroundColour(Color col) - { - // https://www.cgl.ucsf.edu/chimerax/docs/user/commands/set.html - return new StructureCommand("set bgColor " + ColorUtils.toTkCode(col)); - } - - @Override public StructureCommandI colourResidues(String atomSpec, Color colour) { // https://www.cgl.ucsf.edu/chimerax/docs/user/commands/color.html @@ -74,7 +88,6 @@ public class ChimeraXCommands extends ChimeraCommands @Override public StructureCommandI focusView() { - // https://www.cgl.ucsf.edu/chimerax/docs/user/commands/view.html return FOCUS_VIEW; } @@ -107,7 +120,8 @@ public class ChimeraXCommands extends ChimeraCommands String attributeValue, AtomSpecModel atomSpecModel) { StringBuilder sb = new StringBuilder(128); - sb.append("setattr ").append(getAtomSpec(atomSpecModel, false)); + sb.append("setattr ") + .append(getAtomSpec(atomSpecModel, AtomSpecType.RESIDUE_ONLY)); sb.append(" res ").append(attributeName).append(" '") .append(attributeValue).append("'"); sb.append(" create true"); @@ -125,7 +139,8 @@ public class ChimeraXCommands extends ChimeraCommands public StructureCommandI saveSession(String filepath) { // https://www.cgl.ucsf.edu/chimerax/docs/user/commands/save.html - return new StructureCommand("save session " + filepath); + // note ChimeraX will append ".cxs" to the filepath! + return new StructureCommand("save " + filepath + " format session"); } /** @@ -140,7 +155,7 @@ public class ChimeraXCommands extends ChimeraCommands * @return */ @Override - public String getAtomSpec(AtomSpecModel atomSpec, boolean alphaOnly) + public String getAtomSpec(AtomSpecModel atomSpec, AtomSpecType specType) { StringBuilder sb = new StringBuilder(128); boolean firstModel = true; @@ -152,11 +167,14 @@ public class ChimeraXCommands extends ChimeraCommands } firstModel = false; appendModel(sb, model, atomSpec); - if (alphaOnly) + if (specType == AtomSpecType.ALPHA) { - // TODO @P if RNA - add nucleotide flag to AtomSpecModel? sb.append("@CA"); } + if (specType == AtomSpecType.PHOSPHATE) + { + sb.append("@P"); + } } return sb.toString(); } @@ -200,7 +218,7 @@ public class ChimeraXCommands extends ChimeraCommands @Override public List superposeStructures(AtomSpecModel ref, - AtomSpecModel spec) + AtomSpecModel spec, AtomSpecType backbone) { /* * Form ChimeraX match command to match spec to ref @@ -210,8 +228,8 @@ public class ChimeraXCommands extends ChimeraCommands * @see https://www.cgl.ucsf.edu/chimerax/docs/user/commands/align.html */ StringBuilder cmd = new StringBuilder(); - String atomSpec = getAtomSpec(spec, true); - String refSpec = getAtomSpec(ref, true); + String atomSpec = getAtomSpec(spec, backbone); + String refSpec = getAtomSpec(ref, backbone); cmd.append("align ").append(atomSpec).append(" toAtoms ") .append(refSpec); @@ -219,10 +237,58 @@ public class ChimeraXCommands extends ChimeraCommands * show superposed residues as ribbon, others as chain */ cmd.append("; ribbon "); - cmd.append(getAtomSpec(spec, false)).append("|"); - cmd.append(getAtomSpec(ref, false)).append("; view"); + cmd.append(getAtomSpec(spec, AtomSpecType.RESIDUE_ONLY)).append("|"); + cmd.append(getAtomSpec(ref, AtomSpecType.RESIDUE_ONLY)) + .append("; view"); return Arrays.asList(new StructureCommand(cmd.toString())); } + @Override + public StructureCommandI openSession(String filepath) + { + // https://www.cgl.ucsf.edu/chimerax/docs/user/commands/open.html#composite + // this version of the command has no dependency on file extension + return new StructureCommand("open " + filepath + " format session"); + } + + @Override + public StructureCommandI closeViewer() + { + return CLOSE_CHIMERAX; + } + + @Override + public List startNotifications(String uri) + { + List cmds = new ArrayList<>(); + cmds.add(new StructureCommand( + "info notify start models jalview prefix ModelChanged url " + + uri)); + cmds.add(new StructureCommand( + "info notify start selection jalview prefix SelectionChanged url " + + uri)); + return cmds; + } + + @Override + public List stopNotifications() + { + List cmds = new ArrayList<>(); + cmds.add(STOP_NOTIFY_MODELS); + cmds.add(STOP_NOTIFY_SELECTION); + return cmds; + } + + @Override + public StructureCommandI getSelectedResidues() + { + return GET_SELECTION; + } + + @Override + public StructureCommandI listResidueAttributes() + { + return LIST_RESIDUE_ATTRIBUTES; + } }