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
+ *
+ *
+ * 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;
+ *
+ *
+ * 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.
+ *
+ * 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 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 centerViewOn(List 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
+ */
+ return new StructureCommand("write STATE \"" + filepath + "\"");
+ }
+
+ @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;
+ }
/**
- * Jmol utility which constructs the commands to colour chains by the given
- * alignment
+ * Generates a Jmol atomspec string like
*
- * @returns Object[] { Object[] { ,
+ *
+ * 2-5:A/1.1,8:A/1.1,5-10:B/2.1
+ *
+ *
+ * Parameter {@code alphaOnly} is not used here - this restriction is made by
+ * a separate clause in the {@code compare} (superposition) command.
+ */
+ @Override
+ public String getAtomSpec(AtomSpecModel model, AtomSpecType specType)
+ {
+ StringBuilder sb = new StringBuilder(128);
+
+ boolean first = true;
+ for (String modelNo : model.getModels())
+ {
+ for (String chain : model.getChains(modelNo))
+ {
+ for (int[] range : model.getRanges(modelNo, chain))
+ {
+ if (!first)
+ {
+ sb.append(PIPE);
+ }
+ first = false;
+ if (range[0] == range[1])
+ {
+ sb.append(range[0]);
+ }
+ else
+ {
+ sb.append(range[0]).append(HYPHEN).append(range[1]);
+ }
+ sb.append(COLON).append(chain.trim()).append(SLASH);
+ sb.append(String.valueOf(modelNo)).append(".1");
+ }
+ }
+ }
+
+ return sb.toString();
+ }
+
+ @Override
+ public List showBackbone()
+ {
+ return Arrays.asList(SHOW_BACKBONE);
+ }
+
+ @Override
+ public StructureCommandI loadFile(String file)
+ {
+ // https://chemapps.stolaf.edu/jmol/docs/#loadfiles
+ return new StructureCommand(
+ "load FILES \"" + Platform.escapeBackslashes(file) + "\"");
+ }
+
+ /**
+ * Obsolete method, only referenced from
+ * jalview.javascript.MouseOverStructureListener
*
+ * @param ssm
+ * @param files
+ * @param sequence
+ * @param sr
+ * @param viewPanel
+ * @return
*/
- public static StructureMappingcommandSet[] getColourBySequenceCommand(
- StructureSelectionManager ssm, String[] files,
- SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr,
- AlignmentI alignment)
+ @Deprecated
+ public String[] colourBySequence(StructureSelectionManager ssm,
+ String[] files, SequenceI[][] sequence, SequenceRenderer sr,
+ AlignmentViewPanel viewPanel)
{
+ // TODO delete method
- ArrayList cset = new ArrayList();
+ FeatureRenderer fr = viewPanel.getFeatureRenderer();
+ FeatureColourFinder finder = new FeatureColourFinder(fr);
+ AlignViewportI viewport = viewPanel.getAlignViewport();
+ HiddenColumns cs = viewport.getAlignment().getHiddenColumns();
+ AlignmentI al = viewport.getAlignment();
+ List cset = new ArrayList<>();
for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
{
StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
- StringBuffer command = new StringBuffer();
- StructureMappingcommandSet smc;
- ArrayList str = new ArrayList();
+ StringBuilder command = new StringBuilder(128);
+ List str = new ArrayList<>();
if (mapping == null || mapping.length < 1)
+ {
continue;
+ }
- int lastPos = -1;
for (int s = 0; s < sequence[pdbfnum].length; s++)
{
for (int sp, m = 0; m < mapping.length; m++)
{
if (mapping[m].getSequence() == sequence[pdbfnum][s]
- && (sp = alignment.findIndex(sequence[pdbfnum][s])) > -1)
+ && (sp = al.findIndex(sequence[pdbfnum][s])) > -1)
{
- SequenceI asp = alignment.getSequenceAt(sp);
+ int lastPos = StructureMapping.UNASSIGNED_VALUE;
+ SequenceI asp = al.getSequenceAt(sp);
for (int r = 0; r < asp.getLength(); r++)
{
// no mapping to gaps in sequence
- if (jalview.util.Comparison.isGap(asp.getCharAt(r)))
+ if (Comparison.isGap(asp.getCharAt(r)))
{
continue;
}
int pos = mapping[m].getPDBResNum(asp.findPosition(r));
- if (pos < 1 || pos == lastPos)
+ if (pos == lastPos)
+ {
+ continue;
+ }
+ if (pos == StructureMapping.UNASSIGNED_VALUE)
+ {
+ // terminate current colour op
+ if (command.length() > 0
+ && command.charAt(command.length() - 1) != ';')
+ {
+ command.append(";");
+ }
+ // reset lastPos
+ lastPos = StructureMapping.UNASSIGNED_VALUE;
continue;
+ }
lastPos = pos;
- Color col = sr.getResidueBoxColour(sequence[pdbfnum][s], r);
-
- if (fr != null)
- col = fr.findFeatureColour(col, sequence[pdbfnum][s], r);
- String newSelcom = (mapping[m].getChain() != " " ? ":"
- + mapping[m].getChain() : "")
- + "/"
- + (pdbfnum + 1)
- + ".1"
- + ";color["
- + col.getRed()
- + ","
- + col.getGreen()
- + ","
- + col.getBlue() + "]";
- if (command.length() > newSelcom.length()
- && command.substring(
- command.length() - newSelcom.length())
- .equals(newSelcom))
+ Color col = sr.getResidueColour(sequence[pdbfnum][s], r,
+ finder);
+
+ /*
+ * shade hidden regions darker
+ */
+ if (!cs.isVisible(r))
+ {
+ col = Color.GRAY;
+ }
+
+ String newSelcom = (mapping[m].getChain() != " "
+ ? ":" + mapping[m].getChain()
+ : "") + "/" + (pdbfnum + 1) + ".1" + ";color"
+ + getColourString(col);
+ if (command.length() > newSelcom.length() && command
+ .substring(command.length() - newSelcom.length())
+ .equals(newSelcom))
{
command = JmolCommands.condenseCommand(command, pos);
continue;
@@ -113,7 +415,12 @@ public class JmolCommands
// TODO: deal with case when buffer is too large for Jmol to parse
// - execute command and flush
- command.append(";");
+ if (command.length() > 0
+ && command.charAt(command.length() - 1) != ';')
+ {
+ command.append(";");
+ }
+
if (command.length() > 51200)
{
// add another chunk
@@ -123,7 +430,7 @@ public class JmolCommands
command.append("select " + pos);
command.append(newSelcom);
}
- break;
+ // break;
}
}
}
@@ -132,15 +439,22 @@ public class JmolCommands
str.add(command.toString());
command.setLength(0);
}
- // Finally, add the command set ready to be returned.
- cset.add(new StructureMappingcommandSet(JmolCommands.class,
- files[pdbfnum], str.toArray(new String[str.size()])));
+ cset.addAll(str);
}
- return cset.toArray(new StructureMappingcommandSet[cset.size()]);
+ return cset.toArray(new String[cset.size()]);
}
- public static StringBuffer condenseCommand(StringBuffer command, int pos)
+ /**
+ * Helper method
+ *
+ * @param command
+ * @param pos
+ * @return
+ */
+ @Deprecated
+ private static StringBuilder condenseCommand(StringBuilder command,
+ int pos)
{
// work back to last 'select'
@@ -155,7 +469,7 @@ public class JmolCommands
;
} while ((q = command.indexOf("select", p)) == -1 && p > 0);
- StringBuffer sb = new StringBuffer(command.substring(0, q + 7));
+ StringBuilder sb = new StringBuilder(command.substring(0, q + 7));
command = command.delete(0, q + 7);
@@ -175,4 +489,15 @@ public class JmolCommands
return sb;
}
+ @Override
+ public StructureCommandI openSession(String filepath)
+ {
+ return loadFile(filepath);
+ }
+
+ @Override
+ public StructureCommandI closeViewer()
+ {
+ return null; // not an external viewer
+ }
}