JAL-2422 write Jalview features to ChimeraX via command file
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 13 Dec 2019 16:12:31 +0000 (16:12 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 13 Dec 2019 16:12:31 +0000 (16:12 +0000)
src/jalview/ext/rbvi/chimera/ChimeraCommands.java
src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java

index 01458a8..b35faa8 100644 (file)
@@ -350,7 +350,7 @@ public class ChimeraCommands
           AlignmentViewPanel viewPanel, boolean isChimeraX)
   {
     Map<String, Map<Object, AtomSpecModel>> featureMap = buildFeaturesMap(
-            ssm, files, seqs, viewPanel);
+            ssm, files, seqs, viewPanel, isChimeraX);
 
     List<String> commands = buildSetAttributeCommands(featureMap,
             isChimeraX);
@@ -372,11 +372,12 @@ public class ChimeraCommands
    * @param files
    * @param seqs
    * @param viewPanel
+   * @param isChimeraX
    * @return
    */
   protected static Map<String, Map<Object, AtomSpecModel>> buildFeaturesMap(
           StructureSelectionManager ssm, String[] files, SequenceI[][] seqs,
-          AlignmentViewPanel viewPanel)
+          AlignmentViewPanel viewPanel, boolean isChimeraX)
   {
     Map<String, Map<Object, AtomSpecModel>> theMap = new LinkedHashMap<>();
 
@@ -414,6 +415,7 @@ public class ChimeraCommands
     AlignmentI alignment = viewPanel.getAlignment();
     for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
     {
+      final int modelNumber = pdbfnum + (isChimeraX ? 1 : 0);
       StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
 
       if (mapping == null || mapping.length < 1)
@@ -437,12 +439,12 @@ public class ChimeraCommands
             if (!visibleFeatures.isEmpty())
             {
               scanSequenceFeatures(visibleFeatures, structureMapping, seq,
-                      theMap, pdbfnum);
+                      theMap, modelNumber);
             }
             if (showLinkedFeatures)
             {
               scanComplementFeatures(complementRenderer, structureMapping,
-                      seq, theMap, pdbfnum);
+                      seq, theMap, modelNumber);
             }
           }
         }
@@ -626,14 +628,25 @@ public class ChimeraCommands
          * add a command to set the attribute on the mapped residues
          * Put values in single quotes, encoding any embedded single quotes
          */
+        AtomSpecModel atomSpecModel = values.get(value);
         StringBuilder sb = new StringBuilder(128);
+        sb.append("setattr ");
+        if (isChimeraX)
+        {
+          sb.append(atomSpecModel.getAtomSpecX());
+        }
         String featureValue = value.toString();
         featureValue = featureValue.replaceAll("\\'", "&#39;");
-        sb.append("setattr r ").append(attributeName).append(" '")
+        sb.append(" res ").append(attributeName).append(" '")
                 .append(featureValue).append("' ");
-        AtomSpecModel atomSpecModel = values.get(value);
-        sb.append(isChimeraX ? atomSpecModel.getAtomSpecX()
-                : atomSpecModel.getAtomSpec());
+        if (isChimeraX)
+        {
+          sb.append(" create true");
+        }
+        else
+        {
+          sb.append(atomSpecModel.getAtomSpec());
+        }
         commands.add(sb.toString());
       }
     }
index 47ada53..c16ce13 100644 (file)
@@ -1154,9 +1154,10 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
    */
   protected void sendCommandsByFile(String[] commands)
   {
+    boolean toChimeraX = viewer.isChimeraX();
     try
     {
-      File tmp = File.createTempFile("chim", ".com");
+      File tmp = File.createTempFile("chim", toChimeraX ? ".cxc" : ".com");
       tmp.deleteOnExit();
       PrintWriter out = new PrintWriter(new FileOutputStream(tmp));
       for (String command : commands)
@@ -1166,7 +1167,8 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
       out.flush();
       out.close();
       String path = tmp.getAbsolutePath();
-      sendAsynchronousCommand("open cmd:" + path, null);
+      String command = "open " + (toChimeraX ? "" : "cmd:") + path;
+      sendAsynchronousCommand(command, null);
     } catch (IOException e)
     {
       System.err.println("Sending commands to Chimera via file failed with "