JAL-2295 JAL-1596 method to pass a command script file to Chimera
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 8 Nov 2016 16:29:22 +0000 (16:29 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 8 Nov 2016 16:29:22 +0000 (16:29 +0000)
src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java

index 40b6059..d94a3c2 100644 (file)
@@ -38,6 +38,10 @@ import jalview.structures.models.AAStructureBindingModel;
 import jalview.util.MessageManager;
 
 import java.awt.Color;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
 import java.net.BindException;
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
@@ -1143,6 +1147,35 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
     {
       sendAsynchronousCommand(command, null);
     }
+  }
 
+  /**
+   * Write commands to a temporary file, and send a command to Chimera to open
+   * the file as a commands script. For use when sending a large number of
+   * separate commands would overload the REST interface mechanism.
+   * 
+   * @param commands
+   */
+  protected void sendCommandsByFile(String[] commands)
+  {
+    try
+    {
+      File tmp = File.createTempFile("chim", ".com");
+      tmp.deleteOnExit();
+      PrintWriter out = new PrintWriter(new FileOutputStream(tmp));
+      for (String command : commands)
+      {
+        out.println(command);
+      }
+      out.flush();
+      out.close();
+      String path = tmp.getAbsolutePath();
+      sendAsynchronousCommand("open cmd:" + path, null);
+    } catch (IOException e)
+    {
+      System.err
+              .println("Sending commands to Chimera via file failed with "
+                      + e.getMessage());
+    }
   }
 }