Merge branch 'develop' into patch/JAL-3921_jmol_session_save
authorJames Procter <j.procter@dundee.ac.uk>
Thu, 2 Nov 2023 21:01:22 +0000 (21:01 +0000)
committerJames Procter <j.procter@dundee.ac.uk>
Thu, 2 Nov 2023 21:01:22 +0000 (21:01 +0000)
1  2 
src/jalview/ext/jmol/JalviewJmolBinding.java
src/jalview/ext/jmol/JmolCommands.java

@@@ -26,6 -26,8 +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;
@@@ -154,7 -156,7 +156,7 @@@ public abstract class JalviewJmolBindin
      jmolHistory(false);
      if (lastCommand == null || !lastCommand.equals(cmd))
      {
 -      jmolScript(cmd + "\n");
 +      jmolScript(cmd + "\n",command.isWaitNeeded());
      }
      jmolHistory(true);
      lastCommand = cmd;
  
    public void createImage(String file, String type, int quality)
    {
-     System.out.println("JMOL CREATE IMAGE");
+     jalview.bin.Console.outPrintln("JMOL CREATE IMAGE");
    }
  
    @Override
    public String createImage(String fileName, String type,
            Object textOrBytes, int quality)
    {
-     System.out.println("JMOL CREATE IMAGE");
+     jalview.bin.Console.outPrintln("JMOL CREATE IMAGE");
      return null;
    }
  
    @Override
    public String eval(String strEval)
    {
-     // System.out.println(strEval);
+     // jalview.bin.Console.outPrintln(strEval);
      // "# 'eval' is implemented only for the applet.";
      return null;
    }
  
    // End StructureListener
    // //////////////////////////
+   
+   ////////////////////////////
+   // HETATM get
+   //
+   
+   @Override
+   public Map<String,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 hetlist;
+   }
+   //
+   ////////////////////////////
+   
    @Override
    public float[][] functionXY(String functionName, int x, int y)
    {
    {
      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
    }
  
    // 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));
      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;
      lastMessage = strInfo;
      if (data != null)
      {
-       System.err.println("Ignoring additional hover info: " + data
+       jalview.bin.Console.errPrintln("Ignoring additional hover info: " + data
                + " (other info: '" + strInfo + "' pos " + atomIndex + ")");
      }
      mouseOverStructure(atomIndex, strInfo);
       */
      if (strData != null)
      {
-       System.err.println("Ignoring additional pick data string " + strData);
+       jalview.bin.Console.errPrintln("Ignoring additional pick data string " + strData);
      }
      int chainSeparator = strInfo.indexOf(":");
      int p = 0;
                  (data == null) ? ((String) null) : (String) data[1]);
          break;
        case ERROR:
-         // System.err.println("Ignoring error callback.");
+         // jalview.bin.Console.errPrintln("Ignoring error callback.");
          break;
        case SYNC:
        case RESIZE:
  
        case CLICK:
        default:
-         System.err.println(
+         jalview.bin.Console.errPrintln(
                  "Unhandled callback " + type + " " + data[1].toString());
          break;
        }
      } catch (Exception e)
      {
-       System.err.println("Squashed Jmol callback handler error:");
+       jalview.bin.Console.errPrintln("Squashed Jmol callback handler error:");
        e.printStackTrace();
      }
    }
    public void setCallbackFunction(String callbackType,
            String callbackFunction)
    {
-     System.err.println("Ignoring set-callback request to associate "
+     jalview.bin.Console.errPrintln("Ignoring set-callback request to associate "
              + callbackType + " with function " + callbackFunction);
  
    }
            String buttonsToShow)
    {
  
-     System.err.println("Allocating Jmol Viewer: " + commandOptions);
+     jalview.bin.Console.errPrintln("Allocating Jmol Viewer: " + commandOptions);
  
      if (commandOptions == null)
      {
        console = createJmolConsole(consolePanel, buttonsToShow);
      } catch (Throwable e)
      {
-       System.err.println("Could not create Jmol application console. "
+       jalview.bin.Console.errPrintln("Could not create Jmol application console. "
                + e.getMessage());
        e.printStackTrace();
      }
@@@ -241,9 -241,7 +241,9 @@@ public class JmolCommands extends Struc
      /*
       * https://chemapps.stolaf.edu/jmol/docs/#writemodel
       */
 -    return new StructureCommand("write STATE \"" + filepath + "\"");
 +    StructureCommand sc = new StructureCommand("write STATE \"" + filepath + "\"");
 +    sc.setWaitNeeded(true);
 +    return sc;
    }
  
    @Override
      return new StructureCommand(
              "load FILES \"" + Platform.escapeBackslashes(file) + "\"");
    }
+   @Override
+   public StructureCommandI restoreSession(String filePath)
+   {
+     return new StructureCommand(
+             "restore STATE \"" + Platform.escapeBackslashes(filePath) + "\"");
+   }
  
+   @Override
+   public List<StructureCommandI> showHetatms(List<String> toShow)
+   {
+     // always clear the current hetero cpk display
+     
+     StringBuilder sb = new StringBuilder();
+     sb.append("select hetero; cpk off;");
+     
+     if (toShow != null && !toShow.isEmpty())
+     {
+       // select what was requested
+       sb.append("select ");
+       boolean or = false;
+       for (String k : toShow)
+       {
+         sb.append(or ? " or " : " ");
+         sb.append(k);
+         or = true;
+       }
+       // and show as
+       sb.append("; cpk;");
+     }
+     
+     return Arrays.asList(new StructureCommand(sb.toString()));
+   }
    /**
     * Obsolete method, only referenced from
     * jalview.javascript.MouseOverStructureListener