JAL-3551 the correct PyMOL colour by chain command
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 16 Mar 2020 10:11:38 +0000 (10:11 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 16 Mar 2020 10:11:38 +0000 (10:11 +0000)
src/jalview/ext/pymol/PymolCommands.java
test/jalview/ext/pymol/PymolCommandsTest.java

index 1638644..910aae1 100644 (file)
@@ -10,19 +10,19 @@ import java.util.ArrayList;
 import java.util.List;
 
 /**
 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/Category:Commands
+ * @see https://pymolwiki.org/index.php/RPC
  */
 public class PymolCommands extends StructureCommandsBase
 {
  */
 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<>();
   private static final List<StructureCommandI> COLOR_BY_CHARGE = new ArrayList<>();
 
   private static final List<StructureCommandI> SHOW_BACKBONE = new ArrayList<>();
@@ -33,7 +33,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"));
             .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"));
   }
     SHOW_BACKBONE.add(new StructureCommand("hide", "everything"));
     SHOW_BACKBONE.add(new StructureCommand("show", "ribbon"));
   }
@@ -41,8 +42,6 @@ public class PymolCommands extends StructureCommandsBase
   @Override
   public StructureCommandI colourByChain()
   {
   @Override
   public StructureCommandI colourByChain()
   {
-    // https://pymolwiki.org/index.php/CBC
-    // TODO this doesn't execute as an xml-rpc command
     return COLOUR_BY_CHAIN;
   }
 
     return COLOUR_BY_CHAIN;
   }
 
index a66f809..9dc107e 100644 (file)
@@ -186,6 +186,18 @@ public class PymolCommandsTest
   }
 
   @Test(groups = "Functional")
   }
 
   @Test(groups = "Functional")
+  public void testColourByCharge()
+  {
+    PymolCommands testee = new PymolCommands();
+    List<StructureCommandI> cmds = testee.colourByCharge();
+    assertEquals(cmds.size(), 4);
+    assertEquals(cmds.get(0).toString(), "color(white,*)");
+    assertEquals(cmds.get(1).toString(), "color(red,resn ASP resn GLU)");
+    assertEquals(cmds.get(2).toString(), "color(blue,resn LYS resn ARG)");
+    assertEquals(cmds.get(3).toString(), "color(yellow,resn CYS)");
+  }
+
+  @Test(groups = "Functional")
   public void testOpenCommandFile()
   {
     PymolCommands testee = new PymolCommands();
   public void testOpenCommandFile()
   {
     PymolCommands testee = new PymolCommands();
@@ -202,6 +214,13 @@ public class PymolCommandsTest
   }
 
   @Test(groups = "Functional")
   }
 
   @Test(groups = "Functional")
+  public void testColourByChain()
+  {
+    PymolCommands testee = new PymolCommands();
+    assertEquals(testee.colourByChain().toString(), "spectrum(chain)");
+  }
+
+  @Test(groups = "Functional")
   public void testGetColourCommand()
   {
     PymolCommands testee = new PymolCommands();
   public void testGetColourCommand()
   {
     PymolCommands testee = new PymolCommands();