package jalview.ext.pymol;
+import java.awt.Color;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
import jalview.structure.AtomSpecModel;
import jalview.structure.StructureCommand;
import jalview.structure.StructureCommandI;
import jalview.structure.StructureCommandsBase;
-import java.awt.Color;
-import java.util.ArrayList;
-import java.util.List;
-
/**
- * A class that generates commands to send to PyMol
+ * A class that generates commands to send to PyMol over its XML-RPC interface.
+ * <p>
+ * Note that because the xml-rpc interface can only accept one command at a
+ * time, we can't concatenate commands, and must instead form and send them
+ * individually.
*
* @see https://pymolwiki.org/index.php/Category:Commands
+ * @see https://pymolwiki.org/index.php/RPC
*/
public class PymolCommands extends StructureCommandsBase
{
- private static final StructureCommandI COLOUR_BY_CHAIN = new StructureCommand(
- "util.cbc");
+ private static final StructureCommand COLOUR_BY_CHAIN = new StructureCommand("spectrum", "chain");
- /*
- * because the xml-rpc interface can only accept one command at a time, we can't
- * concatenate commands and must instead form and send them individually
- */
private static final List<StructureCommandI> COLOR_BY_CHARGE = new ArrayList<>();
private static final List<StructureCommandI> SHOW_BACKBONE = new ArrayList<>();
.add(new StructureCommand("color", "red", "resn ASP resn GLU"));
COLOR_BY_CHARGE.add(
new StructureCommand("color", "blue", "resn LYS resn ARG"));
- COLOR_BY_CHARGE.add(new StructureCommand("color"));
+ COLOR_BY_CHARGE
+ .add(new StructureCommand("color", "yellow", "resn CYS"));
SHOW_BACKBONE.add(new StructureCommand("hide", "everything"));
SHOW_BACKBONE.add(new StructureCommand("show", "ribbon"));
}
@Override
public StructureCommandI colourByChain()
{
- // https://pymolwiki.org/index.php/CBC
- // TODO this doesn't execute as an xml-rpc command
return COLOUR_BY_CHAIN;
}
@Override
public StructureCommandI openCommandFile(String path)
{
- // where is this documented by PyMol?
- // todo : xml-rpc answers 'method "@" is not supported'
- return new StructureCommand("@" + path); // should be .pml
+ // https://pymolwiki.org/index.php/Run
+ return new StructureCommand("run", path); // should be .pml
}
@Override
return new StructureCommand("load", file);
}
+ /**
+ * Overrides the default implementation (which generates concatenated
+ * commands) to generate one per colour (because the XML-RPC interface to
+ * PyMOL only accepts one command at a time)
+ *
+ * @param colourMap
+ * @return
+ */
+ @Override
+ public List<StructureCommandI> colourBySequence(
+ Map<Object, AtomSpecModel> colourMap)
+ {
+ List<StructureCommandI> commands = new ArrayList<>();
+ for (Object key : colourMap.keySet())
+ {
+ Color colour = (Color) key;
+ final AtomSpecModel colourData = colourMap.get(colour);
+ commands.add(getColourCommand(colourData, colour));
+ }
+
+ return commands;
+ }
+
}