JAL-4307 some models return null for hetatm list
[jalview.git] / src / jalview / ext / jmol / JalviewJmolBinding.java
index 870db65..5b931e1 100644 (file)
@@ -26,6 +26,8 @@ import java.awt.event.ComponentListener;
 import java.io.File;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.StringTokenizer;
@@ -184,7 +186,28 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
 
   // End StructureListener
   // //////////////////////////
-
+  
+  ////////////////////////////
+  // HETATM get
+  //
+  
+  @Override
+  public List<String> getHetatmNames()
+  {
+    HashMap<String,String> hetlist=new HashMap();
+    for (int mc=0;mc<jmolViewer.ms.mc; mc++)
+    {
+      Map<String,String> hets = jmolViewer.ms.getHeteroList(mc);
+      if (hets!=null)
+      {
+        hetlist.putAll(hets);
+      }
+    }
+    return Arrays.asList(hetlist.keySet().toArray(new String[0]));
+  }
+  //
+  ////////////////////////////
+  
   @Override
   public float[][] functionXY(String functionName, int x, int y)
   {
@@ -267,16 +290,30 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
   {
     if (atoms != null)
     {
-      boolean useScriptWait = atoms.size() > 1;
       if (resetLastRes.length() > 0)
       {
-        jmolScript(resetLastRes.toString(), useScriptWait);
+        jmolScript(resetLastRes.toString());
         resetLastRes.setLength(0);
       }
+      StringBuilder highlightCommands=null;
       for (AtomSpec atom : atoms)
       {
-        highlightAtom(atom.getAtomIndex(), atom.getPdbResNum(),
-                atom.getChain(), atom.getPdbFile(), useScriptWait);
+        StringBuilder thisAtom = highlightAtom(atom.getAtomIndex(), atom.getPdbResNum(),
+                atom.getChain(), atom.getPdbFile());
+        if (thisAtom!=null) {
+          if (highlightCommands==null)
+          {
+            highlightCommands=thisAtom;                  
+          } else {
+            highlightCommands.append(thisAtom);
+          }
+        }
+      }
+      if (highlightCommands!=null)
+      {
+        jmolHistory(false);
+        jmolScript(highlightCommands.toString());
+        jmolHistory(true);
       }
       // Highlight distances between atoms with a 'measure' command - not yet
       // working
@@ -306,17 +343,15 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
   }
 
   // jmol/ssm only
-  public void highlightAtom(int atomIndex, int pdbResNum, String chain,
-          String pdbfile, boolean useScriptWait)
+  private StringBuilder highlightAtom(int atomIndex, int pdbResNum, String chain,
+          String pdbfile)
   {
     String modelId = getModelIdForFile(pdbfile);
     if (modelId.isEmpty())
     {
-      return;
+      return null;
     }
 
-    jmolHistory(false, useScriptWait);
-
     StringBuilder selection = new StringBuilder(32);
     StringBuilder cmd = new StringBuilder(64);
     selection.append("select ").append(String.valueOf(pdbResNum));
@@ -333,8 +368,7 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
     resetLastRes.append(selection).append(";wireframe 0;").append(selection)
             .append(" and not hetero; spacefill 0;");
 
-    jmolScript(cmd.toString(), useScriptWait);
-    jmolHistory(true, useScriptWait);
+    return cmd;
   }
 
   private boolean debug = true;