JAL-3404 explicit getModelForPdbFile lookup
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Sat, 10 Aug 2019 04:20:02 +0000 (05:20 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Sat, 10 Aug 2019 04:20:02 +0000 (05:20 +0100)
src/jalview/ext/jmol/JalviewJmolBinding.java
src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java
src/jalview/structures/models/AAStructureBindingModel.java
src/jalview/util/StructureCommands.java

index 5243b40..2645980 100644 (file)
@@ -59,7 +59,6 @@ import org.jmol.api.JmolSelectionListener;
 import org.jmol.api.JmolStatusListener;
 import org.jmol.api.JmolViewer;
 import org.jmol.c.CBK;
-import org.jmol.script.T;
 import org.jmol.viewer.Viewer;
 
 public abstract class JalviewJmolBinding extends AAStructureBindingModel
@@ -558,19 +557,6 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
     return null;
   }
 
-  public Color getColour(int atomIndex, int pdbResNum, String chain,
-          String pdbfile)
-  {
-    if (getModelNum(pdbfile) < 0)
-    {
-      return null;
-    }
-    // TODO: verify atomIndex is selecting correct model.
-    // return new Color(viewer.getAtomArgb(atomIndex)); Jmol 12.2.4
-    int colour = viewer.ms.at[atomIndex].atomPropertyInt(T.color);
-    return new Color(colour);
-  }
-
   /**
    * instruct the Jalview binding to update the pdbentries vector if necessary
    * prior to matching the jmol view's contents to the list of structure files
@@ -605,7 +591,6 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
   @Override
   public synchronized String[] getStructureFiles()
   {
-    List<String> mset = new ArrayList<>();
     if (viewer == null)
     {
       return new String[0];
@@ -613,6 +598,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
 
     if (modelFileNames == null)
     {
+      List<String> mset = new ArrayList<>();
       int modelCount = viewer.ms.mc;
       String filePath = null;
       for (int i = 0; i < modelCount; ++i)
@@ -1464,4 +1450,10 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
      */
     viewer.evalString("zoom 0");
   }
+
+  @Override
+  public int getModelForPdbFile(String fileName, int fileIndex)
+  {
+    return fileIndex;
+  }
 }
index f7d5c6a..3498f23 100644 (file)
@@ -1283,4 +1283,18 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
     }
     sendChimeraCommand(cmd.toString(), false);
   }
+
+  @Override
+  public int getModelForPdbFile(String fileName, int fileIndex)
+  {
+    if (chimeraMaps.containsKey(fileName))
+    {
+      List<ChimeraModel> models = chimeraMaps.get(fileName);
+      if (!models.isEmpty())
+      {
+        return models.get(0).getModelNumber();
+      }
+    }
+    return -1;
+  }
 }
index 448ed24..05c09e9 100644 (file)
@@ -979,7 +979,9 @@ public abstract class AAStructureBindingModel
   
     for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
     {
-      StructureMapping[] mappings = getSsm().getMapping(files[pdbfnum]);
+      String fileName = files[pdbfnum];
+      final int modelNumber = getModelForPdbFile(fileName, pdbfnum);
+      StructureMapping[] mappings = getSsm().getMapping(fileName);
   
       /*
        * Find the first mapped sequence (if any) for this PDB entry which is in
@@ -1021,7 +1023,7 @@ public abstract class AAStructureBindingModel
               {
                 for (int[] range : residueRanges)
                 {
-                  model.addRange(pdbfnum, range[0], range[1], chainCd);
+                  model.addRange(modelNumber, range[0], range[1], chainCd);
                 }
               }
             }
@@ -1034,6 +1036,17 @@ public abstract class AAStructureBindingModel
   }
 
   /**
+   * Answers the structure viewer's model number for the given PDB file, or -1 if
+   * not found
+   * 
+   * @param fileName
+   * @param fileIndex
+   *                    index of the file in the stored array of file names
+   * @return
+   */
+  public abstract int getModelForPdbFile(String fileName, int fileIndex);
+
+  /**
    * Answers a default structure model specification which is simply the string
    * form of the model number. Override if needed to specify submodels.
    * 
index 8e66da8..fb52340 100644 (file)
@@ -95,8 +95,10 @@ public abstract class StructureCommands
   
     for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
     {
+      String fileName = files[pdbfnum];
+      final int modelNumber = binding.getModelForPdbFile(fileName, pdbfnum);
       StructureMapping[] mapping = binding.getSsm()
-              .getMapping(files[pdbfnum]);
+              .getMapping(fileName);
   
       if (mapping == null || mapping.length < 1)
       {
@@ -160,8 +162,7 @@ public abstract class StructureCommands
                 if (startPos != -1)
                 {
                   StructureCommands.addAtomSpecRange(colourMap, lastColour,
-                          pdbfnum, startPos,
-                          lastPos, lastChain);
+                          modelNumber, startPos, lastPos, lastChain);
                 }
                 startPos = pos;
               }
@@ -173,8 +174,7 @@ public abstract class StructureCommands
             if (lastColour != null)
             {
               StructureCommands.addAtomSpecRange(colourMap, lastColour,
-                      pdbfnum,
-                      startPos, lastPos, lastChain);
+                      modelNumber, startPos, lastPos, lastChain);
             }
           }
         }