JAL-2422 write Jalview features to ChimeraX via command file
[jalview.git] / src / jalview / ext / rbvi / chimera / ChimeraCommands.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());
       }
     }