JAL-2422 temporary hacks removed; use hex colours for Chimera[X]
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 31 Jan 2020 16:11:21 +0000 (16:11 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 31 Jan 2020 16:11:21 +0000 (16:11 +0000)
src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java
src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java
src/jalview/gui/AppJmol.java
src/jalview/gui/ChimeraViewFrame.java

index 216c06c..710ca95 100644 (file)
@@ -348,14 +348,22 @@ public class ChimeraManager
    */
   public void startListening(String uri)
   {
+    /*
+     * listen for model changes
+     */
     String command = isChimeraX
             ? ("info notify start models prefix ModelChanged jalview url "
-                    + uri
-                    + "; info notify start selection jalview prefix SelectionChanged url "
                     + uri)
-            : ("listen start models url " + uri
-                    + ";listen start select prefix SelectionChanged url "
-                    + uri);
+            : ("listen start models url " + uri);
+    sendChimeraCommand(command, false);
+
+    /*
+     * listen for selection changes
+     */
+    command = isChimeraX
+            ? ("info notify start selection jalview prefix SelectionChanged url "
+                    + uri)
+            : ("listen start select prefix SelectionChanged url " + uri);
     sendChimeraCommand(command, false);
   }
 
@@ -436,12 +444,13 @@ public class ChimeraManager
      */
     if (isChimeraX)
     {
-      return selectedResidues;
+      // return selectedResidues;
     }
 
     // in fact 'listinfo' (undocumented) works in ChimeraX
-    String command = (isChimeraX ? "info" : "list")
-            + " selection level residue";
+    String command = (isChimeraX
+            ? "view" /*"info selection level residue" */
+            : "list selection level residue");
     List<String> chimeraReply = sendChimeraCommand(command, true);
     if (chimeraReply != null)
     {
@@ -497,19 +506,24 @@ public class ChimeraManager
   public List<ChimeraModel> getModelList()
   {
     List<ChimeraModel> modelList = new ArrayList<>();
-    modelList.add(new ChimeraModel("4zhp", ModelType.PDB_MODEL, 1, 0));
-    return modelList; // ChimeraX doesn't have 'list models' command
-    // List<String> list = sendChimeraCommand("list models type molecule",
-    // true);
-    // if (list != null)
-    // {
-    // for (String modelLine : list)
-    // {
-    // ChimeraModel chimeraModel = new ChimeraModel(modelLine);
-    // modelList.add(chimeraModel);
-    // }
-    // }
-    // return modelList;
+    String command = "list models type "
+            + (isChimeraX ? "AtomicStructure" : "molecule");
+    List<String> list = sendChimeraCommand(command, true);
+    if (list != null)
+    {
+      for (String modelLine : list)
+      {
+        try
+        {
+          ChimeraModel chimeraModel = new ChimeraModel(modelLine);
+          modelList.add(chimeraModel);
+        } catch (NullPointerException e)
+        {
+          // hack for now
+        }
+      }
+    }
+    return modelList;
   }
 
   /**
@@ -868,24 +882,23 @@ public class ChimeraManager
   {
     String restUrl = "http://127.0.0.1:" + this.chimeraRestPort + "/run";
     List<NameValuePair> commands = new ArrayList<>(1);
-    String encoded = command.replace(" ", "+").replace("#", "%23")
-            .replace("|", "%7C").replace(";", "%3B");
-    commands.add(new BasicNameValuePair("command", encoded));
+    String method = isChimeraX() ? "GET" : "POST";
+    if ("GET".equals(method))
+    {
+      command = command.replace(" ", "+").replace("#", "%23")
+              .replace("|", "%7C").replace(";", "%3B");
+    }
+    commands.add(new BasicNameValuePair("command", command));
 
     List<String> reply = new ArrayList<>();
     BufferedReader response = null;
     try
     {
-      if (isChimeraX())
-      {
-        response = HttpClientUtils.doHttpGet(restUrl, commands,
-                CONNECTION_TIMEOUT_MS, REST_REPLY_TIMEOUT_MS);
-      }
-      else
-      {
-        response = HttpClientUtils.doHttpUrlPost(restUrl, commands,
-                CONNECTION_TIMEOUT_MS, REST_REPLY_TIMEOUT_MS);
-      }
+      response = "GET".equals(method)
+              ? HttpClientUtils.doHttpGet(restUrl, commands,
+                      CONNECTION_TIMEOUT_MS, REST_REPLY_TIMEOUT_MS)
+              : HttpClientUtils.doHttpUrlPost(restUrl, commands,
+                      CONNECTION_TIMEOUT_MS, REST_REPLY_TIMEOUT_MS);
       String line = "";
       while ((line = response.readLine()) != null)
       {
index 786fc6c..d0fa5ef 100644 (file)
@@ -41,6 +41,7 @@ import jalview.structure.AtomSpec;
 import jalview.structure.StructureMappingcommandSet;
 import jalview.structure.StructureSelectionManager;
 import jalview.structures.models.AAStructureBindingModel;
+import jalview.util.ColorUtils;
 import jalview.util.MessageManager;
 
 import java.awt.Color;
@@ -137,8 +138,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
     try
     {
       List<ChimeraModel> modelsToMap = new ArrayList<>();
-      List<ChimeraModel> oldList = viewer.isChimeraX() ? new ArrayList<>()
-              : viewer.getModelList();
+      List<ChimeraModel> oldList = viewer.getModelList();
       boolean alreadyOpen = false;
 
       /*
@@ -1025,8 +1025,8 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
 
     /*
      * concatenate colour commands, one per residue symbol
-     * Chimera format:  color 0.000000,0.372549,0.627451 ::VAL
-     * ChimeraX format: color :VAL rgb(73,73,182)
+     * Chimera format:  color colorCode ::VAL
+     * ChimeraX format: color :VAL colourCode
      */
     boolean chimeraX = viewer.isChimeraX();
     for (String resName : residueSet)
@@ -1036,7 +1036,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
               : resName.charAt(0);
       Color col = cs.findColour(res, 0, null, null, 0f);
       command.append("color ");
-      String colorSpec = getRgbDescriptor(col, chimeraX);
+      String colorSpec = ColorUtils.toTkCode(col);
       if (chimeraX)
       {
         command.append(":").append(resName).append(" ").append(colorSpec);
@@ -1100,40 +1100,12 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
   public void setBackgroundColour(Color col)
   {
     viewerCommandHistory(false);
-    String command = "set bgColor "
-            + getRgbDescriptor(col, viewer.isChimeraX());
+    String command = "set bgColor " + ColorUtils.toTkCode(col);
     viewer.sendChimeraCommand(command, false);
     viewerCommandHistory(true);
   }
 
   /**
-   * Answers the Chimera/X format for RGB values of the given colour.
-   * 
-   * <pre>
-   * Chimera: r,g,b with values scaled [0=1]
-   * ChimeraX: rgb(r,g,b) with values scaled 0-255
-   * </pre>
-   * 
-   * @param col
-   * @param chimeraX
-   * @return
-   */
-  private static String getRgbDescriptor(Color col, boolean chimeraX)
-  {
-    if (chimeraX)
-    {
-      return String.format("rgb(%d,%d,%d)", col.getRed(), col.getGreen(),
-              col.getBlue());
-    }
-    else
-    {
-      double scale = 255D;
-      return String.format("%f,%f,%f", col.getRed() / scale,
-              col.getGreen() / scale, col.getBlue() / scale);
-    }
-  }
-
-  /**
    * Ask Chimera to save its session to the given file. Returns true if
    * successful, else false.
    * 
index ea7fb6b..e9c5416 100644 (file)
@@ -604,6 +604,7 @@ public class AppJmol extends StructureViewerBase
               .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
     } catch (Exception ex)
     {
+      System.err.println("Show Jmol help failed with: " + ex.getMessage());
     }
   }
 
index 520b74d..183b475 100644 (file)
@@ -710,10 +710,14 @@ public class ChimeraViewFrame extends StructureViewerBase
   {
     try
     {
-      BrowserLauncher
-              .openURL("https://www.cgl.ucsf.edu/chimera/docs/UsersGuide");
+      String url = jmb.isChimeraX()
+              ? "http://www.rbvi.ucsf.edu/chimerax/docs/user/index.html"
+              : "https://www.cgl.ucsf.edu/chimera/docs/UsersGuide";
+      BrowserLauncher.openURL(url);
     } catch (IOException ex)
     {
+      System.err
+              .println("Show Chimera help failed with: " + ex.getMessage());
     }
   }