JAL-3518 pull up [get|list]ResidueAttributes to StructureCommandsI
[jalview.git] / src / jalview / ext / rbvi / chimera / JalviewChimeraBinding.java
index b20f135..c8875b4 100644 (file)
@@ -224,10 +224,11 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
     }
     
     /*
-     * the following call should not be needed but is temporarily included,
-     * to avoid a stack trace error in Chimera after "stop really" is sent
+     * the following call is added to avoid a stack trace error in Chimera
+     * after "stop really" is sent; Chimera > 1.14 will not need it; see also 
+     * http://plato.cgl.ucsf.edu/trac/chimera/ticket/17597
      */
-    if (closeChimera)
+    if (closeChimera && (getViewerType() == ViewerType.CHIMERA))
     {
       chimeraManager.getChimeraProcess().destroy();
     }
@@ -636,36 +637,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
   }
 
   /**
-   * Get Chimera residues which have the named attribute, find the mapped
-   * positions in the Jalview sequence(s), and set as sequence features
-   * 
-   * @param attName
-   * @param alignmentPanel
-   */
-  public void copyStructureAttributesToFeatures(String attName,
-          AlignmentViewPanel alignmentPanel)
-  {
-    // todo pull up to AAStructureBindingModel (and interface?)
-
-    /*
-     * ask Chimera to list residues with the attribute, reporting its value
-     */
-    // this alternative command
-    // list residues spec ':*/attName' attr attName
-    // doesn't report 'None' values (which is good), but
-    // fails for 'average.bfactor' (which is bad):
-
-    String cmd = "list residues attr '" + attName + "'";
-    List<String> residues = executeCommand(new StructureCommand(cmd), true);
-
-    boolean featureAdded = createFeaturesForAttributes(attName, residues);
-    if (featureAdded)
-    {
-      alignmentPanel.getFeatureRenderer().featuresAdded();
-    }
-  }
-
-  /**
    * Create features in Jalview for the given attribute name and structure
    * residues.
    * 
@@ -678,12 +649,12 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
    * 
    * @param attName
    * @param residues
-   * @return
+   * @return the number of features added
    */
-  protected boolean createFeaturesForAttributes(String attName,
+  protected int createFeaturesForAttributes(String attName,
           List<String> residues)
   {
-    boolean featureAdded = false;
+    int featuresAdded = 0;
     String featureGroup = getViewerFeatureGroup();
 
     for (String residue : residues)
@@ -711,7 +682,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
         spec = parseAtomSpec(atomSpec);
       } catch (IllegalArgumentException e)
       {
-        System.err.println("Problem parsing atomspec " + atomSpec);
+        Cache.log.error("Problem parsing atomspec " + atomSpec);
         continue;
       }
 
@@ -751,10 +722,13 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
                 start, end, score, featureGroup);
         // todo: should SequenceFeature have an explicit property for chain?
         // note: repeating the action shouldn't duplicate features
-        featureAdded |= seq.addSequenceFeature(sf);
+        if (seq.addSequenceFeature(sf))
+        {
+          featuresAdded++;
+        }
       }
     }
-    return featureAdded;
+    return featuresAdded;
   }
 
   /**
@@ -788,19 +762,28 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
    */
   public List<String> getChimeraAttributes()
   {
-    List<String> atts = chimeraManager.getAttrList();
-    Iterator<String> it = atts.iterator();
-    while (it.hasNext())
+    List<String> attributes = new ArrayList<>();
+    StructureCommandI command = getCommandGenerator().listResidueAttributes();
+    final List<String> reply = executeCommand(command, true);
+    if (reply != null)
     {
-      if (it.next().startsWith(ChimeraCommands.NAMESPACE_PREFIX))
+      for (String inputLine : reply)
       {
-        /*
-         * attribute added from Jalview - exclude it
-         */
-        it.remove();
+        String[] lineParts = inputLine.split("\\s");
+        if (lineParts.length == 2 && lineParts[0].equals("resattr"))
+        {
+          String attName = lineParts[1];
+          /*
+           * exclude attributes added from Jalview
+           */
+          if (!attName.startsWith(ChimeraCommands.NAMESPACE_PREFIX))
+          {
+            attributes.add(attName);
+          }
+        }
       }
     }
-    return atts;
+    return attributes;
   }
 
   /**