X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fext%2Frbvi%2Fchimera%2FChimeraXCommands.java;h=9636a6a2a089fb9c8e4f7b24e1625217ccd59637;hb=42f4227ed213d422a87d3b22fc9e85d14ffaf53f;hp=5eba203fd64cf7b2ccaf5463fb8147d85797b49e;hpb=09ec96d9ac0fd717d6cf32417d9916cca781d92c;p=jalview.git diff --git a/src/jalview/ext/rbvi/chimera/ChimeraXCommands.java b/src/jalview/ext/rbvi/chimera/ChimeraXCommands.java index 5eba203..9636a6a 100644 --- a/src/jalview/ext/rbvi/chimera/ChimeraXCommands.java +++ b/src/jalview/ext/rbvi/chimera/ChimeraXCommands.java @@ -21,12 +21,12 @@ package jalview.ext.rbvi.chimera; import jalview.structure.AtomSpecModel; +import jalview.structure.StructureCommand; +import jalview.structure.StructureCommandI; import jalview.util.ColorUtils; -import jalview.util.IntRangeComparator; import java.awt.Color; -import java.util.Collections; -import java.util.Iterator; +import java.util.Arrays; import java.util.List; /** @@ -34,12 +34,19 @@ import java.util.List; */ public class ChimeraXCommands extends ChimeraCommands { - private static final String CMD_COLOUR_BY_CHARGE = "color white;color :ASP,GLU red;color :LYS,ARG blue;color :CYS yellow"; + private static final StructureCommand SHOW_BACKBONE = new StructureCommand( + "~display all;show @CA|P pbonds"); + + private static final StructureCommand FOCUS_VIEW = new StructureCommand( + "view"); + + private static final StructureCommandI COLOUR_BY_CHARGE = new StructureCommand( + "color white;color :ASP,GLU red;color :LYS,ARG blue;color :CYS yellow"); @Override - public String colourByCharge() + public List colourByCharge() { - return CMD_COLOUR_BY_CHARGE; + return Arrays.asList(COLOUR_BY_CHARGE); } @Override @@ -49,26 +56,26 @@ public class ChimeraXCommands extends ChimeraCommands } @Override - public String setBackgroundColour(Color col) + public StructureCommandI setBackgroundColour(Color col) { // https://www.cgl.ucsf.edu/chimerax/docs/user/commands/set.html - return "set bgColor " + ColorUtils.toTkCode(col); + return new StructureCommand("set bgColor " + ColorUtils.toTkCode(col)); } @Override - public String getColourCommand(String atomSpec, Color colour) + public StructureCommandI getColourCommand(String atomSpec, Color colour) { // https://www.cgl.ucsf.edu/chimerax/docs/user/commands/color.html String colourCode = getColourString(colour); - return "color " + atomSpec + " " + colourCode; + return new StructureCommand("color " + atomSpec + " " + colourCode); } @Override - public String focusView() + public StructureCommandI focusView() { // https://www.cgl.ucsf.edu/chimerax/docs/user/commands/view.html - return "view"; + return FOCUS_VIEW; } /** @@ -96,7 +103,7 @@ public class ChimeraXCommands extends ChimeraCommands * @return */ @Override - protected String setAttribute(String attributeName, + protected StructureCommandI setAttribute(String attributeName, String attributeValue, AtomSpecModel atomSpecModel) { StringBuilder sb = new StringBuilder(128); @@ -104,21 +111,21 @@ public class ChimeraXCommands extends ChimeraCommands sb.append(" res ").append(attributeName).append(" '") .append(attributeValue).append("'"); sb.append(" create true"); - return sb.toString(); + return new StructureCommand(sb.toString()); } @Override - public String openCommandFile(String path) + public StructureCommandI openCommandFile(String path) { // https://www.cgl.ucsf.edu/chimerax/docs/user/commands/open.html - return "open " + path; + return new StructureCommand("open " + path); } @Override - public String saveSession(String filepath) + public StructureCommandI saveSession(String filepath) { // https://www.cgl.ucsf.edu/chimerax/docs/user/commands/save.html - return "save session " + filepath; + return new StructureCommand("save session " + filepath); } /** @@ -133,7 +140,7 @@ public class ChimeraXCommands extends ChimeraCommands { StringBuilder sb = new StringBuilder(128); boolean firstModel = true; - for (Integer model : atomSpec.getModels()) + for (String model : atomSpec.getModels()) { if (!firstModel) { @@ -157,7 +164,7 @@ public class ChimeraXCommands extends ChimeraCommands * @param model * @param atomSpec */ - protected void appendModel(StringBuilder sb, Integer model, + protected void appendModel(StringBuilder sb, String model, AtomSpecModel atomSpec) { sb.append("#").append(model); @@ -167,59 +174,29 @@ public class ChimeraXCommands extends ChimeraCommands boolean firstPositionForChain = true; sb.append("/").append(chain.trim()).append(":"); List rangeList = atomSpec.getRanges(model, chain); - - /* - * sort ranges into ascending start position order - */ - Collections.sort(rangeList, IntRangeComparator.ASCENDING); - - int start = rangeList.isEmpty() ? 0 : rangeList.get(0)[0]; - int end = rangeList.isEmpty() ? 0 : rangeList.get(0)[1]; - - Iterator iterator = rangeList.iterator(); - while (iterator.hasNext()) + boolean first = true; + for (int[] range : rangeList) { - int[] range = iterator.next(); - if (range[0] <= end + 1) + if (!first) { - /* - * range overlaps or is contiguous with the last one - * - so just extend the end position, and carry on - * (unless this is the last in the list) - */ - end = Math.max(end, range[1]); + sb.append(","); } - else - { - /* - * we have a break so append the last range - */ - appendRange(sb, start, end, chain, firstPositionForChain, true); - start = range[0]; - end = range[1]; - firstPositionForChain = false; - } - } - - /* - * and append the last range - */ - if (!rangeList.isEmpty()) - { - appendRange(sb, start, end, chain, firstPositionForChain, true); + first = false; + appendRange(sb, range[0], range[1], chain, firstPositionForChain, + true); } - firstPositionForChain = false; } } @Override - public String showBackbone() + public List showBackbone() { - return "~display all;show @CA|P pbonds"; + return Arrays.asList(SHOW_BACKBONE); } @Override - public String superposeStructures(AtomSpecModel spec, AtomSpecModel ref) + public List superposeStructures(AtomSpecModel spec, + AtomSpecModel ref) { /* * Form ChimeraX match command to match spec to ref @@ -242,7 +219,7 @@ public class ChimeraXCommands extends ChimeraCommands cmd.append(getAtomSpec(spec, false)).append("|"); cmd.append(getAtomSpec(ref, false)).append("; view"); - return cmd.toString(); + return Arrays.asList(new StructureCommand(cmd.toString())); } }