Revision: 20616
          http://sourceforge.net/p/jmol/code/20616
Author:   hansonr
Date:     2015-07-02 17:18:02 +0000 (Thu, 02 Jul 2015)
Log Message:
-----------
load NBO CH3CH3 working, but still have a run-away NBOServe.exe

Modified Paths:
--------------
    branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialog.java
    branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogConfig.java
    branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogRun.java
    branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogSearch.java
    branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBOService.java

Modified: branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialog.java
===================================================================
--- branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialog.java   
2015-07-01 19:31:54 UTC (rev 20615)
+++ branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialog.java   
2015-07-02 17:18:02 UTC (rev 20616)
@@ -104,13 +104,8 @@
       modules.addActionListener(new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
-          if (nboService != null) {
-            nboService.closeProcess();
-            nboService.startProcess(false);
-            while (!nboService.restartIfNecessary()) {
-              // continue forever?
-            }
-          }
+          if (nboService != null)
+            nboService.restart();
           switch (modules.getSelectedIndex()) {
           case 0:
             openPanel('m');

Modified: 
branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogConfig.java
===================================================================
--- branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogConfig.java     
2015-07-01 19:31:54 UTC (rev 20615)
+++ branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogConfig.java     
2015-07-02 17:18:02 UTC (rev 20616)
@@ -235,9 +235,8 @@
   }
   
   protected void connectPressed() {
-    nboService.closeProcess();
+    String err = nboService.restart();
     nboReport(null);
-    String err = nboService.startProcess(false);
     if (err == null) {
       nboReport("NBOServe successfully connected");
     } else {
@@ -372,11 +371,6 @@
     sb.append(s);
   }
 
-  String getFileData(String fileName) {
-    return vwr.getFileAsString4(fileName, Integer.MAX_VALUE,
-        false, false, false, "nbo");
-  }
-
   protected JTextField tfFolder, tfName, tfExt;
   protected int jmolAtomCount;
   protected File inputFile;

Modified: branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogRun.java
===================================================================
--- branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogRun.java        
2015-07-01 19:31:54 UTC (rev 20615)
+++ branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogRun.java        
2015-07-02 17:18:02 UTC (rev 20616)
@@ -175,7 +175,7 @@
 
   protected void getParams(File inputFile) {
     newParams = params = "";
-    String data = getFileData(inputFile.toString());
+    String data = nboService.getFileData(inputFile.toString());
     int n = data.length();
     String sep = (data.indexOf("\r") >= 0 ? "\n\r" : "\n");
     String[] tokens = PT.split(data, "$END");

Modified: 
branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogSearch.java
===================================================================
--- branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogSearch.java     
2015-07-01 19:31:54 UTC (rev 20615)
+++ branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBODialogSearch.java     
2015-07-02 17:18:02 UTC (rev 20616)
@@ -925,11 +925,7 @@
     private void done() {
       try {
         labelAt();
-        nboService.closeProcess();
-        nboService.startProcess(false);
-        while (!nboService.restartIfNecessary()) {
-          // continue forever?
-        }
+        nboService.restart();
         rawCmd("");
       } catch (Exception e) {
         e.printStackTrace();

Modified: branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBOService.java
===================================================================
--- branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBOService.java  
2015-07-01 19:31:54 UTC (rev 20615)
+++ branches/nbo/Jmol/src/org/openscience/jmol/app/nbo/NBOService.java  
2015-07-02 17:18:02 UTC (rev 20616)
@@ -46,9 +46,90 @@
  * 
  * TODO: figure out how to manage time-consuming asynchronous requests
  * 
+ * 
  */
 public class NBOService {
 
+  /// BH: observations: 
+  // 
+  // 1) NBOServe creates jmol_infile.txt, jmol_molfile.txt, and 
jmol_outfile.txt. 
+  // 
+  // 2) Of these three, jmol_outfile is locked for writing during NBOServe 
sessions 
+  //    and stays locked until the program finishes. 
+  //    
+  //    
+  // 3) When View starts up, a new jmol_outfile is created, and it can be 
deleted.
+  // 
+  // 4) The process of View...Browse... leads to the following:
+  // 
+  //    07/02/2015  09:04 AM                20 jmol_infile.txt
+  //    07/02/2015  09:04 AM               429 jmol_outfile.txt 
+  //    07/02/2015  09:05 AM                95 v_test1435845900375.txt
+  //    07/02/2015  09:05 AM                11 fort.106
+  //    07/02/2015  09:05 AM                 0 v_test1435845900375.txtDONE
+  // 
+  // v_test... is 
+  //
+  //  GLOBAL C_PATH C:\temp
+  //  GLOBAL I_KEYWORD 6
+  //  GLOBAL C_JOBSTEM ch3nh2
+  //  GLOBAL I_BAS_1 6
+  //  CMD LABEL
+  //
+  // jmol_infile.txt is:
+  //
+  //          1    1    2
+  //  
+  // jmol_outfile.txt is:
+  
+  //    DATA " "
+  //    1    1    2
+  //  NBOServe: NATURAL BOND ORBITAL PROGRAM SUITE
+  //  _______________________________________________
+  //  (1) NBOModel:
+  //    Create & edit molecular model and input files
+  //  (2) NBORun:
+  //    Launch NBO analysis for chosen archive (.47) file
+  //  (3) NBOView:
+  //    Display NBO orbitals in 1D/2D/3D imagery
+  //  (4) NBOSearch:
+  //    Search NBO output interactively
+  //  Your choice (1-4), (H)elp, e(X)it, or (D)ir reset?
+  //  END ""
+  //
+  // fort.106 is 
+  //
+  //    END ""
+  //
+  // note that the actual label information came back only over sysout.
+  //
+  // requesting a 3D view (raytrace) produces the following files:
+  //
+  //  07/02/2015  09:13 AM                97 v_test1435846433040.txt
+  //  07/02/2015  09:13 AM                 0 v_test1435846433040.txtDONE
+  //  07/02/2015  09:14 AM                59 v_test1435846446147.txt
+  //  07/02/2015  09:14 AM           480,029 ch3nh2.bmp (in c:\temp)
+  //  07/02/2015  09:14 AM                 0 v_test1435846446147.txtDONE
+  //  07/02/2015  09:14 AM                 2 jmol_outfile.txt
+  //  07/02/2015  09:14 AM               121 jmol_molfile.txt
+  //  07/02/2015  09:14 AM             5,552 raytrace.rt
+
+  // the first v_test is: 
+  //
+  //  GLOBAL C_PATH C:\temp
+  //  GLOBAL C_JOBSTEM ch3nh2
+  //  GLOBAL I_BAS_1 6
+  //  GLOBAL SIGN +1 
+  //  CMD PROFILE 10  
+  // 
+  // and the second is:
+  //
+  //  GLOBAL C_PATH C:\temp
+  //  GLOBAL C_JOBSTEM ch3nh2
+  //  CMD VIEW 1 
+  
+  
+  
   // modes of operation
   
   // NOTE: There was a problem in that View and Raw were both 4 here
@@ -81,6 +162,7 @@
   private boolean inData;
   protected boolean inRequest, isWorking;
   String serverPath;
+  String serverDir;
   String workingPath;
 
   private boolean nboSync;
@@ -110,6 +192,7 @@
    */
   private void setServerPath(String path) {
     serverPath = path;
+    serverDir = new File(serverPath).getParent() + "/";
   }
 
   /**
@@ -152,8 +235,6 @@
       serverMode = MODE_ERR;
     }
     String nboAction = (String) info.get("action");
-    if (nboAction == null)
-      System.out.println("HOH");
     String s;
     switch (serverMode) {
     case MODE_MODEL:
@@ -176,13 +257,13 @@
       break;
     }
     if (s != null) {
+      if (nboSync) {
+        clearServerFile("fort.106");
+        clearServerFile("jmol_molfile.txt");
+      }
       sendToNBO(serverMode, s);
       if (nboSync) {
-        try {
-          nboServer.waitFor();
-        } catch (InterruptedException e) {
-          return false;
-        }
+        waitFor(serverMode);
       }
       ok = true;
     }
@@ -193,12 +274,54 @@
     return ok;
   }
 
+  private boolean waitFor(int mode) {
+    String fname = serverDir + (mode == MODE_MODEL ? "jmol_molfile.txt" : 
"fort.106");
+    File f = new File(fname);
+    for (int i = 0; i < 200; i++) { // 2 seconds allowed
+      if (f.exists()) {
+        switch (mode) {
+        case MODE_MODEL:
+          String dataCmd = fixNBOModel(getFileData(fname));
+          Logger.info(dataCmd);
+          sbRet.append(dataCmd + ";rotate best;");     
+          break;
+        case MODE_RAW:
+          // sbRet already created?
+          break;
+        }
+        break;
+      }
+      try {
+        Thread.sleep(10);
+      } catch (InterruptedException e) {
+        return false;
+      }
+    }
+    return true;
+//    try {
+//      nboServer.waitFor();
+//      return true;
+//    } catch (InterruptedException e) {
+//      return false;
+//    }
+  }
+
+  private boolean clearServerFile(String fname) {
+    File f = new File(serverDir + fname);
+    try {
+      f.delete();
+    } catch (Exception e) {
+      return false;
+    }
+    return true;
+  }
+
   /**
    * @param mode
    * @param s
    */
   private void sendToNBO(int mode, String s) {
-    s = (mode == MODE_RAW ? s : mode + "\r\n" + s + "\r\n"
+    s = (mode == MODE_RAW ? s : "\r\n" + mode + "\r\n" + s + "\r\nexit\r\n"
         + (nboSync ? "x\r\n" : ""));
     sendCmd(s);
   }
@@ -222,8 +345,7 @@
       } else if (line.startsWith("DATA ")) {
         if (line.startsWith("DATA \"model")) {
           sbRet.setLength(0);
-          nboModel = PT.getQuotedStringAt(line, 0);
-          line += " NBO " + nboModel;
+          line = fixNBOModel(line);
         }
         inData = (line.indexOf("exit") < 0);
         if (inData)
@@ -251,6 +373,19 @@
       nboDialog.nboReport(line);
   }
 
+  /**
+   * fixes DATA line to include a title
+   * 
+   * @param line
+   * @return line or full data block
+   */
+  private String fixNBOModel(String line) {
+    nboModel = PT.getQuotedStringAt(line, 0);
+    String s = " NBO " + nboModel;
+    int pt = line.indexOf("\n");
+    return (pt < 0 ? line + s : line.substring(0, pt) + s + 
line.substring(pt));
+  }
+
   String startProcess(boolean sync) {
     try {
       System.out.println("starting NBO process sync=" + sync);
@@ -372,6 +507,12 @@
     nboServer = null;
   }
 
+  String restart() {
+    closeProcess();
+    return startProcess(false);
+  }
+
+
   public boolean restartIfNecessary() {
     if (nboServer == null)
       startProcess(false);
@@ -383,7 +524,7 @@
     vwr.script(script);
   }
   
-  private Object lock = "";
+  private Object lock = "jmol_lock";
 
   synchronized String runScriptNow(String script) {
     synchronized (lock) {
@@ -410,9 +551,16 @@
     }
   }
 
-  private Object nbo = "";
+  private Object nbo = "nbo_lock";
   
   
+  /**
+   * The interface for ALL communication with NBOServe from NBODialog.
+   * 
+   * @param cmd
+   * @param data
+   * @param doWait
+   */
   protected void rawCmdNew(String cmd, SB data, boolean doWait) {
     synchronized (nbo) {
       String fname = null;
@@ -422,7 +570,7 @@
           Logger.info("issuing\n" + cmd);
         } else {
           fname = cmd + "_test" + System.currentTimeMillis() + ".txt";
-          cmdFile = new File(new File(serverPath).getParent() + "/" + fname);
+          cmdFile = new File(serverDir + fname);
           Logger.info("issuing " + fname + "\n" + data);
           writeToFile(data.toString(), cmdFile);
           cmd = "<" + fname + ">";
@@ -445,7 +593,7 @@
           }
         }
         if (cmdFile != null) {
-          cmdFile = new File(new File(serverPath).getParent() + "/" + fname + 
"DONE");
+          cmdFile = new File(serverDir + fname + "DONE");
           writeToFile("", cmdFile);
         }
           
@@ -466,5 +614,10 @@
     Logger.info(s.length() + " bytes written to " + file);
   }
 
+  String getFileData(String fileName) {
+    return vwr.getFileAsString4(fileName, Integer.MAX_VALUE,
+        false, false, false, "nbo");
+  }
 
+
 }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Jmol-commits mailing list
Jmol-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-commits

Reply via email to