+ private static final StructureCommand SHOW_BACKBONE = new StructureCommand(
+ "select *; cartoons off; backbone");
+
+ private static final StructureCommand FOCUS_VIEW = new StructureCommand(
+ "zoom 0");
+
+ private static final StructureCommand COLOUR_ALL_WHITE = new StructureCommand(
+ "select *;color white;");
+
+ private static final StructureCommandI COLOUR_BY_CHARGE = new StructureCommand(
+ "select *;color white;select ASP,GLU;color red;"
+ + "select LYS,ARG;color blue;select CYS;color yellow");
+
+ private static final StructureCommandI COLOUR_BY_CHAIN = new StructureCommand(
+ "select *;color chain");
+
+ private static final String PIPE = "|";
+
+ private static final String HYPHEN = "-";
+
+ private static final String COLON = ":";
+
+ private static final String SLASH = "/";
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return
+ */
+ @Override
+ public int getModelStartNo()
+ {
+ return 1;
+ }
+
+ /**
+ * Returns a string representation of the given colour suitable for inclusion
+ * in Jmol commands
+ *
+ * @param c
+ * @return
+ */
+ protected String getColourString(Color c)
+ {
+ return c == null ? null
+ : String.format("[%d,%d,%d]", c.getRed(), c.getGreen(),
+ c.getBlue());
+ }
+
+ @Override
+ public StructureCommandI colourByChain()
+ {
+ return COLOUR_BY_CHAIN;
+ }
+
+ @Override
+ public List<StructureCommandI> colourByCharge()
+ {
+ return Arrays.asList(COLOUR_BY_CHARGE);
+ }
+
+ @Override
+ public List<StructureCommandI> colourByResidues(
+ Map<String, Color> colours)
+ {
+ List<StructureCommandI> cmds = super.colourByResidues(colours);
+ cmds.add(0, COLOUR_ALL_WHITE);
+ return cmds;
+ }
+
+ @Override
+ public StructureCommandI setBackgroundColour(Color col)
+ {
+ return new StructureCommand("background " + getColourString(col));
+ }
+
+ @Override
+ public StructureCommandI focusView()
+ {
+ return FOCUS_VIEW;
+ }
+
+ @Override
+ public List<StructureCommandI> showChains(List<String> toShow)
+ {
+ StringBuilder atomSpec = new StringBuilder(128);
+ boolean first = true;
+ for (String chain : toShow)
+ {
+ String[] tokens = chain.split(":");
+ if (tokens.length == 2)
+ {
+ if (!first)
+ {
+ atomSpec.append(" or ");
+ }
+ first = false;
+ atomSpec.append(":").append(tokens[1]).append(" /")
+ .append(tokens[0]);
+ }
+ }
+
+ String spec = atomSpec.toString();
+ String command = "select *;restrict " + spec + ";cartoon;center "
+ + spec;
+ return Arrays.asList(new StructureCommand(command));
+ }
+
+ /**
+ * Returns a command to superpose atoms in {@code atomSpec} to those in
+ * {@code refAtoms}, restricted to alpha carbons only (Phosphorous for rna).
+ * For example
+ *
+ * <pre>
+ * compare {2.1} {1.1} SUBSET {(*.CA | *.P) and conformation=1}
+ * ATOMS {1-87:A}{2-54:A|61-94:A} ROTATE TRANSLATE 1.0;
+ * </pre>
+ *
+ * where {@code conformation=1} excludes ALTLOC atom locations, and 1.0 is the
+ * time in seconds to animate the action. For this example, atoms in model 2
+ * are moved towards atoms in model 1.
+ * <p>
+ * The two atomspecs should each be for one model only, but may have more than
+ * one chain. The number of atoms specified should be the same for both
+ * models, though if not, Jmol may make a 'best effort' at superposition.
+ *
+ * @see https://chemapps.stolaf.edu/jmol/docs/#compare
+ */
+ @Override
+ public List<StructureCommandI> superposeStructures(AtomSpecModel refAtoms,
+ AtomSpecModel atomSpec, AtomSpecType backbone)
+ {
+ StringBuilder sb = new StringBuilder(64);
+ String refModel = refAtoms.getModels().iterator().next();
+ String model2 = atomSpec.getModels().iterator().next();
+ sb.append(String.format("compare {%s.1} {%s.1}", model2, refModel));
+ sb.append(" SUBSET {(*.CA | *.P) and conformation=1} ATOMS {");
+
+ /*
+ * command examples don't include modelspec with atoms, getAtomSpec does;
+ * it works, so leave it as it is for simplicity
+ */
+ sb.append(getAtomSpec(atomSpec, backbone)).append("}{");
+ sb.append(getAtomSpec(refAtoms, backbone)).append("}");
+ sb.append(" ROTATE TRANSLATE ");
+ sb.append(getCommandSeparator());
+
+ /*
+ * show residues used for superposition as ribbon
+ */
+ sb.append("select ")
+ .append(getAtomSpec(atomSpec, AtomSpecType.RESIDUE_ONLY))
+ .append("|");
+ sb.append(getAtomSpec(refAtoms, AtomSpecType.RESIDUE_ONLY))
+ .append(getCommandSeparator()).append("cartoons");
+ return Arrays.asList(new StructureCommand(sb.toString()));
+ }
+
+ @Override
+ public List<StructureCommandI> centerViewOn(List<AtomSpecModel> residues)
+ {
+ StringBuilder sb = new StringBuilder(64);
+ sb.append("center ");
+ for (AtomSpecModel ranges : residues)
+ {
+ if (sb.length() > 9)
+ {
+ sb.append(" or ");
+ }
+ sb.append(getAtomSpec(ranges, AtomSpecType.RESIDUE_ONLY));
+ }
+ return Arrays.asList(new StructureCommand(sb.toString()));
+ }
+
+ @Override
+ public StructureCommandI openCommandFile(String path)
+ {
+ /*
+ * https://chemapps.stolaf.edu/jmol/docs/#script
+ * not currently used in Jalview
+ */
+ return new StructureCommand("script " + path);
+ }
+
+ @Override
+ public StructureCommandI saveSession(String filepath)
+ {
+ /*
+ * https://chemapps.stolaf.edu/jmol/docs/#writemodel
+ */
+ StructureCommand sc = new StructureCommand(
+ "write STATE \"" + filepath + "\"");
+ sc.setWaitNeeded(true);
+ return sc;
+ }
+
+ @Override
+ protected StructureCommandI colourResidues(String atomSpec, Color colour)
+ {
+ StringBuilder sb = new StringBuilder(atomSpec.length() + 20);
+ sb.append("select ").append(atomSpec).append(getCommandSeparator())
+ .append("color").append(getColourString(colour));
+ return new StructureCommand(sb.toString());
+ }
+
+ @Override
+ protected String getResidueSpec(String residue)
+ {
+ return residue;
+ }