JAL-3551 concatenate colour by sequence commands for all except PyMOL
[jalview.git] / src / jalview / ext / pymol / PymolCommands.java
index 1638644..e4f9f5f 100644 (file)
@@ -1,28 +1,29 @@
 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<>();
@@ -33,7 +34,8 @@ public class PymolCommands extends StructureCommandsBase
             .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"));
   }
@@ -41,8 +43,6 @@ public class PymolCommands extends StructureCommandsBase
   @Override
   public StructureCommandI colourByChain()
   {
-    // https://pymolwiki.org/index.php/CBC
-    // TODO this doesn't execute as an xml-rpc command
     return COLOUR_BY_CHAIN;
   }
 
@@ -120,9 +120,8 @@ public class PymolCommands extends StructureCommandsBase
   @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
@@ -211,4 +210,27 @@ public class PymolCommands extends StructureCommandsBase
     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;
+  }
+
 }