JAL-2035 improvement to add binding to multiple model
[jalview.git] / src / ext / edu / ucsf / rbvi / strucviz2 / ChimeraManager.java
index 2e5dbeb..4201f43 100644 (file)
@@ -178,6 +178,7 @@ public class ChimeraManager
   {
     logger.info("chimera open " + modelPath);
     // stopListening();
+    List<ChimeraModel> modelList = getModelList();
     List<String> response = null;
     // TODO: [Optional] Handle modbase models
     if (type == ModelType.MODBASE_MODEL)
@@ -197,16 +198,26 @@ public class ChimeraManager
       logger.warn("Could not open " + modelPath);
       return null;
     }
-    List<ChimeraModel> chimeraModels = getModelList();
+
+    List<ChimeraModel> newModelList = getModelList();
+    for (ChimeraModel newModel : newModelList)
+    {
+      if (!modelList.contains(newModel))
+      {
+        newModel.setModelName(modelName);
+        sendChimeraCommand(
+                "setattr M name " + modelName + " #"
+                        + newModel.getModelNumber(), false);
+        modelList.add(newModel);
+
+      }
+    }
+
     // assign color and residues to open models
-    for (ChimeraModel chimeraModel : chimeraModels)
+    for (ChimeraModel chimeraModel : modelList)
     {
       // // patch for Jalview - set model name in Chimera
       // // TODO: find a variant that works for sub-models
-      chimeraModel.setModelName(modelName);
-      sendChimeraCommand(
-              "setattr M name " + modelName + " #"
-                      + chimeraModel.getModelNumber(), false);
       // get model color
       Color modelColor = getModelColor(chimeraModel);
       if (modelColor != null)
@@ -227,7 +238,7 @@ public class ChimeraManager
 
     sendChimeraCommand("focus", false);
     // startListening(); // see ChimeraListener
-    return chimeraModels;
+    return modelList;
   }
 
   /**