OSDN Git Service

Start implementing 'additional exponent' for JANPA output
[molby/Molby.git] / Scripts / gamess.rb
index 92458a0..94c74fe 100755 (executable)
@@ -653,8 +653,8 @@ class Molecule
                                  ncomps = mol.sub_load_gamess_log_basis_set(bs_lines, lineno + i)
                                end
                          rescue
-                           puts $!.to_s
-                           puts $!.backtrace.inspect
+          $stderr.write($!.to_s + "\n")
+          $stderr.write($!.backtrace.inspect + "\n")
                          end
                          last_i = j
                        else
@@ -706,8 +706,8 @@ class Molecule
                            mol.sub_load_gamess_log_mo_coefficients(mo_lines, lineno + i, ncomps)
                          end
                        rescue
-                         puts $!.to_s
-                         puts $!.backtrace.inspect
+                         $stderr.write($!.to_s + "\n")
+                         $stderr.write($!.backtrace.inspect + "\n")
                        end
                        last_i = j
           elsif line =~ /NSERCH: *([0-9]+)/
@@ -1552,6 +1552,7 @@ class Molecule
       fp.print "#  Generated by Molby at #{now}\n"
       fp.print "import sys\n"
       fp.print "import re\n"
+      fp.print "base = re.sub('\\.\\w*$', '', sys.argv[1])  #  Basename of the input file\n"
       fp.print "molecule mol {\n"
       charge = Integer(hash["charge"])
       mult = Integer(hash["mult"])
@@ -1559,21 +1560,41 @@ class Molecule
         fp.printf " %d %d\n", charge, mult
       end
       atoms.each { |ap|
-        fp.printf "%-8s %10.6f %10.6f %10.6f\n", ap.element, ap.x, ap.y, ap.z
+        fp.printf "%-8s %16.12f %16.12f %16.12f\n", ap.element, ap.x, ap.y, ap.z
       }
+      use_symmetry = Integer(hash["use_symmetry"])
+      move_to_com = Integer(hash["move_to_com"])
+      do_reorient = Integer(hash["do_reorient"])
+      if move_to_com == 0
+        fp.print "nocom\n"
+      end
+      if do_reorient == 0
+        fp.print "noreorient\n"
+      end
+      if use_symmetry == 0
+        fp.print "symmetry c1\n"
+      end
       fp.print "units angstrom\n"
       fp.print "}\n"
       fp.print "set basis #{hash['basis']}\n"
-      if hash['scftype'] != "RHF"
-        fp.print "set reference #{hash['scftype']}\n"
-      end
+      fp.print "set reference #{hash['scftype']}\n"
       options = "return_wfn=True"
       if hash['dft'] != 0
         options += ", dft_functional='#{hash['dfttype']}'"
       end
       runtype = hash['runtype'].downcase
       fp.print "energy, wfn = #{runtype}('scf', #{options})\n"
-      fp.print "wfn.write_molden(re.sub('\\.\\w*$', '.molden', sys.argv[1]))\n"
+      fp.print "wfn.write_molden(f'{base}.molden')\n"
+      if hash['run_junpa'] != 0
+        fp.print "\n"
+        fp.print "#  Interface for JANPA\n"
+        fp.print "#  cf. https://sourceforge.net/p/janpa/wiki/psi4Examples/\n"
+        fp.print "d = wfn.Da().to_array()\n"
+        fp.print "s = wfn.S().to_array()\n"
+        fp.print "c = wfn.Ca().to_array()\n"
+        fp.print "occs = c.T.dot(s.dot(d).dot(s).dot(c))\n"
+        fp.print "molden(wfn, f'{base}.da.molden', density_a = psi4.core.Matrix.from_array(occs))\n"
+      end
     end
     if fname == nil
       s = fp.buffer
@@ -1585,7 +1606,94 @@ class Molecule
     end
   end
 
-  #  Execute Psi4 (inferior copy of rungms script)
+  def Molecule.is_java_available
+    if $platform == "win"
+      f = get_global_settings("java_home")
+      if f
+        ENV["JAVA_HOME"] = f
+        if !ENV["PATH"].split(";").find { |e| e == "#{f}\\bin" }
+          ENV["PATH"] = "#{f}\\bin;" + ENV["PATH"]
+        end
+      end
+    end
+    return (call_subprocess("java -version", nil) == 0)
+  end
+  
+  def Molecule.make_java_available
+    if $platform == "win"
+      fname = Dialog.open_panel("Locate JDK Folder (if you have one):", "c:\\", nil, true)
+      return false if fname == nil
+      fname.sub!(/\//, "\\")
+      if File.exists?("#{fname}\\bin\\java.exe")
+        set_global_settings("java_home", fname)
+        if Molecule.is_java_available()
+          return true
+        end
+      end
+      error_message_box("Cannot run Java. Please examine your installation again.")
+      return false
+    elsif $platform == "mac"
+      message_box("Please download OpenJDK, and move it into /Library/Java/JavaVirtualMachines folder.", "Install Java", :ok)
+      return false
+    else
+      message_box("Please install Java virtual machine.", "Install Java", :ok)
+      return false
+    end
+  end
+  
+  #  Execute JANPA
+  #  inppath is the input file minus extention
+  #  mol is the molecule (may be nil)
+  def Molecule.execute_janpa(inppath, mol, spherical)
+    #    nbo_desc =   #  JANPA
+    janpa_dir = "#{ResourcePath}/JANPA"
+    status = 0
+    outfile = "#{inppath}.janpa.log"
+    if spherical
+      cmd1 = ["java", "-jar", "#{janpa_dir}/molden2molden.jar", "-NormalizeBF", "-i", "#{inppath}.da.molden", "-o", "#{inppath}.in.molden"]
+      cmd2 = nil
+    else
+      cmd1 = ["java", "-jar", "#{janpa_dir}/molden2molden.jar", "-frompsi4v1mo", "-NormalizeBF", "-cart2pure", "-i", "#{inppath}.da.molden", "-o", "#{inppath}.in.molden"]
+      cmd2 = ["java", "-jar", "#{janpa_dir}/molden2molden.jar", "-frompsi4v1mo", "-NormalizeBF", "-cart2pure", "-i", "#{inppath}.molden", "-o", "#{inppath}.spherical.molden"]
+    end
+    cmd3 = ["java", "-jar", "#{janpa_dir}/janpa.jar", "-i", "#{inppath}.in.molden"]
+    ["nao", "pnao", "aho", "lho", "lpo", "clpo"].each { |type|
+      generate = (get_global_settings("psi4.#{type}").to_i != 0)
+      if type == "pnao" || type == "nao" || type == "lho"
+        #  PLHO is generated within Molby from JANPA NAO/PNAO/LHO
+        generate ||= (get_global_settings("psi4.plho").to_i != 0)
+      end
+      if generate
+        cmd3.push("-#{type.upcase}_Molden_File", "#{inppath}.#{type.upcase}.molden")
+      end
+    }
+    # show_progress_panel("Executing JANPA...")
+    procname = "molden2molden"
+    flag = call_subprocess(cmd1, procname, nil, outfile)
+    if flag && cmd2 != nil
+      procname = "molden2molden"
+      flag = call_subprocess(cmd2, procname, nil, ">>#{outfile}")
+    end
+    if flag
+      procname = "janpa"
+      flag = call_subprocess(cmd3, procname, nil, ">>#{outfile}")
+    end
+    if flag
+      if mol
+        #  import JANPA log and molden output
+        #  Files: inppath.janpa.log, inppath.{NAO,PNAO,AHO,LHO,LPO,CLPO,spherical}.molden
+        mol.sub_load_janpa_log(inppath)
+      end
+      hide_progress_panel
+    else
+      status = $?.exitstatus
+      hide_progress_panel
+      message_box("Execution of #{procname} failed with status #{status}.", "JANPA Failed")
+    end
+    return status
+  end
+  
+  #  Execute Psi4
   #  inpname is the input file
   #  mol (optional) is the molecule from which the Psi4 input was built.
   def Molecule.execute_psi4(inpname, mol = nil)
@@ -1596,6 +1704,7 @@ class Molecule
 
     #  Set PATH for psi4conda
     psi4folder = get_global_settings("psi4.psi4conda_folder")
+    ncpus = get_global_settings("psi4.ncpus").to_i
     orgpath = ENV["PATH"]
     orgdir = Dir.pwd
     if $platform == "win"
@@ -1604,56 +1713,29 @@ class Molecule
       ENV["PATH"] = "#{psi4folder}/bin:#{psi4folder}/condabin:" + ENV["PATH"]
     end
     Dir.chdir(inpdir)
-    cmdline = "psi4 #{inpbase}"
+    cmdargv = ["psi4", "#{inpbase}"]
+    if ncpus > 0
+      cmdargv.push("-n", "#{ncpus}")
+    end
     hf_type = nil
     nalpha = nil
     nbeta = nil
+    spherical = false
 
-    term_callback = lambda { |m, n|
-    begin
-      msg = "Psi4 execution of #{inpbase}"
-      hmsg = "Psi4 "
-      if n == 0
-        msg += "succeeded."
-        hmsg += "Completed"
-        icon = :info
-      else
-        msg += "failed with status #{n}."
-        hmsg += "Failed"
-        icon = :error
-      end
-      msg += "\n(In directory #{inpdir})"
-      ENV["PATH"] = orgpath
-      Dir.chdir(orgdir)
-      if mol != nil
-        message_box(msg, hmsg, :ok, icon)
-      end
-      if n == 0
-        #  Try to load molden file if available
-        mol.clear_basis_set
-        mol.clear_mo_coefficients
-        mol.set_mo_info(:type => hf_type, :alpha => nalpha, :beta => nbeta)
-        molden = inpdir + "/" + inpbody +".molden"
-        if File.exists?(molden)
-          fp = Kernel.open(molden, "rt")
-          mol.instance_eval { @lineno = 0 }
-          begin
-            #  mol.@hf_type should be set before calling sub_load_molden
-            mol.sub_load_molden(fp)
-            fp.close
-          rescue => e
-            print(e.message + "\n")
-            print(e.backtrace.inspect + "\n")
-          end
-        end
-      end
-      rescue => e
-        print("#{e.message}\n")
-        print("#{e.backtrace.to_s}\n")
+    outfile = inpdir + "/" + inpbody + ".out"
+    if File.exists?(outfile)
+      n = 1
+      while true
+        outbackfile = inpdir + "/" + inpbody + "~" + (n == 1 ? "" : "#{n}") + ".out"
+        break if !File.exists?(outbackfile)
+        n += 1
       end
-      true
-    }
-    
+      File.rename(outfile, outbackfile)
+    else
+      outbackfile = nil
+    end
+
+    #  Timer callback
     timer_count = 0
     fplog = nil
     last_size = 0
@@ -1668,11 +1750,15 @@ class Molecule
         end
         timer_count = 0
         if fplog == nil
-          fplog = Kernel.open(inpdir + "/" + inpbody + ".out", "rt")
-          if fplog == nil
-            return true
+          if File.exists?(outfile)
+            fplog = Kernel.open(outfile, "rt")
+            if fplog == nil
+              return true
+            end
+            last_size = 0
+          else
+            return true  #  Skip until outfile is available
           end
-          last_size = 0
         end
         fplog.seek(0, IO::SEEK_END)
         current_size = fplog.tell
@@ -1714,7 +1800,7 @@ class Molecule
             end
             #  Does this geometry differ from the last one?
             vecs.length.times { |i|
-              if (mol.atoms[i].r - vecs[i]).length2 > 1.0e-14
+              if (mol.atoms[i].r - vecs[i]).length2 > 1.0e-20
                 #  Create a new frame and break
                 mol.create_frame
                 vecs.length.times { |j|
@@ -1730,6 +1816,7 @@ class Molecule
             energy = Float($1)
             mol.set_property("energy", energy)
             mol.show_text("Frame: #{mol.nframes - 1}\nEnergy: #{energy}")
+            print("Frame: #{mol.nframes - 1} Energy: #{energy}\n")
             if line =~ /RHF/
               hf_type = "RHF"
             elsif line =~ /UHF/
@@ -1742,29 +1829,102 @@ class Molecule
             nalpha = Integer($1)
           elsif line =~ /^ *Nbeta *= *(\d+)/
             nbeta = Integer($1)
+          elsif line =~ /^ *Spherical Harmonics\?: *(\w+)/
+            spherical = ($1 == "true")
           end
         end
         if next_index > 0
-          lines.slice!(next_index, lines.length - next_index)
+          lines.slice!(0, next_index)
           next_index = 0
         end
         return true
       rescue => e
         #  Some error occurred during callback. Show the message in the console and abort.
-        p e.message
-        p e.backtrace
+        $stderr.write("#{e.message}\n")
+        $stderr.write("#{e.backtrace.inspect}\n")
         return false
       end
     }
+
+    #  Terminate callback
+    term_callback = lambda { |m, n|
+      do_janpa = false
+      begin
+        msg = "Psi4 execution of #{inpbase} "
+        hmsg = "Psi4 "
+        if n == -1
+          msg += "cannot be started. Please examine Psi4 installation."
+          hmsg += "Error"
+          icon = :error
+        else
+          if n == 0
+            msg += "succeeded."
+            hmsg += "Completed"
+            icon = :info
+          else
+            msg += "failed with status #{n}."
+            hmsg += "Failed"
+            icon = :error
+          end
+          msg += "\n(In directory #{inpdir})"
+        end
+        if n == 0
+          #  Try to load final lines of the logfile
+          timer_count = 100
+          timer_callback.call(m, n)
+          #  Try to load molden file if available
+          mol.clear_basis_set
+          mol.clear_mo_coefficients
+          mol.set_mo_info(:type => hf_type, :alpha => nalpha, :beta => nbeta)
+          molden = inpdir + "/" + inpbody +".molden"
+          if File.exists?(molden)
+            fp = Kernel.open(molden, "rt")
+            mol.instance_eval { @lineno = 0 }
+            begin
+              #  mol.@hf_type should be set before calling sub_load_molden
+              mol.sub_load_molden(fp)
+              fp.close
+            rescue => e
+              $stderr.write("#{e.message}\n")
+              $stderr.write("#{e.backtrace.inspect}\n")
+            end
+          end
+          if (get_global_settings("psi4.run_janpa").to_i == 1)
+            do_janpa = true
+            Molecule.execute_janpa(inpdir + "/" + inpbody, mol, spherical)
+          end
+        elsif n == -1
+          #  The child process actually did not start
+          #  Restore the old file if outbackfile is not nil
+          if outbackfile && !File.exists?(outfile)
+            File.rename(outbackfile, outfile)
+          end
+        end
+        if outbackfile && File.exists?(outbackfile)
+          File.delete(outbackfile)
+        end
+        ENV["PATH"] = orgpath
+        Dir.chdir(orgdir)
+        if mol != nil
+          message_box(msg, hmsg, :ok, icon)
+        end
+      rescue => e
+        $stderr.write("#{e.message}\n")
+        $stderr.write("#{e.backtrace.inspect}\n")
+      end
+      print("% ")
+      true
+    }
     
     if mol
-      pid = mol.call_subprocess_async(cmdline, term_callback, timer_callback)
+      pid = mol.call_subprocess_async(cmdargv, term_callback, timer_callback)
       if pid < 0
+        #  This may not happen on OSX or Linux (don't know for MSW)
         error_message_box("Psi4 failed to start. Please examine Psi4 installation.")
         return -1
       end
     else
-      status = call_subprocess(cmdline, "Running Psi4")
+      status = call_subprocess(cmdargv, "Running Psi4")
       term_callback.call(nil, status)
       return status
     end
@@ -1798,9 +1958,10 @@ class Molecule
     dfttype_desc = ["B3LYP"]
     runtype_desc = ["Energy", "Optimize"]
     scftype_desc = ["RHF", "ROHF", "UHF"]
-#   nbo_desc = ["nao", "nbo", "nho", "nlmo", "pnao", "pnbo", "pnho", "pnlmo"]
+    nbo_desc = ["nao", "pnao", "aho", "lho", "lpo", "clpo"]  #  JANPA
     user_input = Hash.new
-    defaults = {"scftype"=>0, "runtype"=>0, "use_internal"=>1, "eliminate_freedom"=>1, "charge"=>"0", "mult"=>"1",
+    defaults = {"scftype"=>0, "runtype"=>0, "move_to_com"=>0, "do_reorient"=>0,
+      "use_symmetry"=>0,  "charge"=>"0", "mult"=>"1",
       "basis"=>1, "use_secondary_basis"=>0, "secondary_elements"=>"",
       "secondary_basis"=>8, "esp"=>0, "ncpus"=>"1"}
     psi4_input_direct = nil
@@ -1841,108 +2002,113 @@ class Molecule
         set_attr("psi4conda_folder", :value=>fname)
       end
       layout(4,
-        #  Line 1
+        #  ------
         item(:text, :title=>"SCF type"),
         item(:popup, :subitems=>scftype_desc, :tag=>"scftype"),
         item(:text, :title=>"Run type"),
-        item(:popup, :subitems=>runtype_desc, :tag=>"runtype",
-          :action=>lambda { |it| set_attr("use_internal", :enabled=>(it[:value] >= 2)) } ),
-        #  Line 2
-        item(:checkbox, :title=>"Use internal coordinates for structure optimization", :tag=>"use_internal"),
+        item(:popup, :subitems=>runtype_desc, :tag=>"runtype"),
+        #  ------
+        item(:checkbox, :title=>"Detect symmetry", :tag=>"use_symmetry"),
+        -1, -1, -1,
+        #  ------
+        item(:checkbox, :title=>"Move the molecule to the center of mass", :tag=>"move_to_com"),
         -1, -1, -1,
-        #  Line 3
-        item(:checkbox, :title=>"Eliminate translation and rotational degrees of freedom", :tag=>"eliminate_freedom"),
+        #  ------
+        item(:checkbox, :title=>"Rotate the molecule to the symmetry principle axes", :tag=>"do_reorient"),
         -1, -1, -1,
-        #  Line 4
+        #  ------
         item(:text, :title=>"Charge"),
         item(:textfield, :width=>80, :tag=>"charge"),
         item(:text, :title=>"Multiplicity"),
         item(:textfield, :width=>80, :tag=>"mult"),
-        #  Line 5
+        #  ------
         item(:checkbox, :title=>"Use DFT", :tag=>"dft",
           :action=>lambda { |it| set_attr("dfttype", :enabled=>(it[:value] != 0)) } ),
         -1,
         item(:text, :title=>"DFT type"),
         item(:popup, :subitems=>dfttype_desc, :tag=>"dfttype"),
-        #  Line 6
+        #  ------
         item(:line),
         -1, -1, -1,
-        #  Line 7
+        #  ------
         item(:text, :title=>"Basis set"),
         item(:popup, :subitems=>bset_desc, :tag=>"basis"),
         -1,
         -1,
-        #  Line 8
+        #  ------
         #item(:button, :title=>"Load Basis Set...", :action=>:load_basis_set_sub),
         #-1, -1, -1,
-        #  Line 9
-        item(:checkbox, :title=>"Use secondary basis set", :tag=>"use_secondary_basis",
-          :action=>lambda { |it|
-            flag = (it[:value] != 0)
-            set_attr("secondary_elements", :enabled=>flag)
-            set_attr("secondary_basis", :enabled=>flag)
-          }),
-        -1, -1, -1,
-        #  Line 10
-        item(:text, :title=>"   Elements"),
-        item(:textfield, :width=>80, :tag=>"secondary_elements"),
-        item(:text, :title=>"Basis set"),
-        item(:popup, :subitems=>bset_desc, :tag=>"secondary_basis"),
-        #  Line 11
+        #  ------
+        #item(:checkbox, :title=>"Use secondary basis set", :tag=>"use_secondary_basis",
+        #  :action=>lambda { |it|
+        #    flag = (it[:value] != 0)
+        #    set_attr("secondary_elements", :enabled=>flag)
+        #    set_attr("secondary_basis", :enabled=>flag)
+        #  }),
+        #-1, -1, -1,
+        #  ------
+        #item(:text, :title=>"   Elements"),
+        #item(:textfield, :width=>80, :tag=>"secondary_elements"),
+        #item(:text, :title=>"Basis set"),
+        #item(:popup, :subitems=>bset_desc, :tag=>"secondary_basis"),
+        #  ------
         item(:line),
         -1, -1, -1,
-        #  Line 12
+        #  ------
         #item(:checkbox, :title=>"Calculate electrostatic potential (ESP)", :tag=>"esp"),
         #-1, -1, -1,
-        #  Line 13
+        #  ------
         #item(:line),
         #-1, -1, -1,
-        #  Line 14
-        #item(:checkbox, :title=>"Include NBO instructions", :tag=>"include_nbo",
-        #    :action=>lambda { |it|
-        #      flag = (it[:value] != 0)
-        #      nbos.each { |nbo| set_attr(nbo, :enabled=>flag) }
-        #    }),
-        #-1, -1, -1,
-        #  Line 15
-        #item(:checkbox, :title=>"NAO", :tag=>"nao"),
-        #item(:checkbox, :title=>"NBO", :tag=>"nbo"),
-        #item(:checkbox, :title=>"NHO", :tag=>"nho"),
-        #item(:checkbox, :title=>"NLMO", :tag=>"nlmo"),
-        #  Line 16
-        #item(:checkbox, :title=>"PNAO", :tag=>"pnao"),
-        #item(:checkbox, :title=>"PNBO", :tag=>"pnbo"),
-        #item(:checkbox, :title=>"PNHO", :tag=>"pnho"),
-        #item(:checkbox, :title=>"PNLMO", :tag=>"pnlmo"),
-        #  Line 17
+        #  ------
+        item(:checkbox, :title=>"Run JANPA after Psi4", :tag=>"run_janpa",
+            :action=>lambda { |it|
+              flag = (it[:value] != 0)
+              nbo_desc.each { |nbo| set_attr(nbo, :enabled=>flag) }
+            }),
+        -1, -1, -1,
+        #  ------
+        item(:checkbox, :title=>"NAO", :tag=>"nao"),
+        item(:checkbox, :title=>"PNAO", :tag=>"pnao"),
+        item(:checkbox, :title=>"AHO", :tag=>"aho"),
+        item(:checkbox, :title=>"LHO", :tag=>"lho"),
+        #  ------
+        item(:checkbox, :title=>"PLHO*", :tag=>"plho"),
+        item(:checkbox, :title=>"LPO", :tag=>"lpo"),
+        item(:checkbox, :title=>"CLPO", :tag=>"clpo"),
+        -1,
+        #  ------
+        item(:text, :title=>"* Not JANPA original; Molby extension", :font=>[9]),
+        -1, -1, -1,
+        #  ------
         item(:line),
         -1, -1, -1,
-        #  Line 18
+        #  ------
         item(:checkbox, :title=>"Execute Psi4 on this machine", :tag=>"execute_local",
           :action=>lambda { |it|
             flag = (it[:value] != 0)
             set_attr("psi4conda_folder", :enabled=>flag)
-            set_attr("select_path", :enabled=>flag)
+            set_attr("select_folder", :enabled=>flag)
             set_attr("ncpus", :enabled=>flag)
           }),
         -1, -1, -1,
-        #  Line 19
-        item(:text, :title=>"   Folder"),
+        #  ------
+        item(:text, :title=>" Psi4 Folder"),
         item(:textfield, :width=>300, :tag=>"psi4conda_folder"),
         -1, -1,
-        #  Line 20
+        #  ------
         -1,
-        item(:button, :title=>"Select Path...", :tag=>"select_path", :action=>:select_psi4_folder),
+        item(:button, :title=>"Select Folder...", :tag=>"select_folder", :action=>:select_psi4_folder),
         -1, -1,
         # item(:button, :title=>"Optional Scripts...", :action=>:set_optional_scripts),
-        #  Line 21
+        #  ------
         item(:text, :title=>"   N of CPUs"),
         item(:textfield, :width=>80, :tag=>"ncpus"),
         -1, -1,
-        #  Line 22
+        #  ------
         item(:line),
         -1, -1, -1,
-        #  Line 23
+        #  ------
         item(:button, :title=>"Edit Psi4 Input and Go", :action=>lambda { |it|
           h = Hash.new
           each_item { |it2|
@@ -1950,11 +2116,11 @@ class Molecule
               h[tag] = it2[:value]
             end
           }
-          h["basis"] = bset_desc[h["basis"]]
-          h["secondary_basis"] = bset_desc[h["secondary_basis"]]
-          h["dfttype"] = dfttype_desc[h["dfttype"]]
-          h["runtype"] = runtype_desc[h["runtype"]]
-          h["scftype"] = scftype_desc[h["scftype"]]
+          h["basis"] = bset_desc[h["basis"] || 0]
+          h["secondary_basis"] = bset_desc[h["secondary_basis"] || 0]
+          h["dfttype"] = dfttype_desc[h["dfttype"] || 0]
+          h["runtype"] = runtype_desc[h["runtype"] || 0]
+          h["scftype"] = scftype_desc[h["scftype"] || 0]
           psi4_input_direct = mol.cmd_edit_psi4_input(mol.export_psi4(nil, h))
           if psi4_input_direct
             end_modal(0)
@@ -1972,11 +2138,11 @@ class Molecule
           end
         end
       }
-      set_attr("secondary_elements", :enabled=>(values["use_secondary_basis"] == 1))
-      set_attr("secondary_basis", :enabled=>(values["use_secondary_basis"] == 1))
+      #set_attr("secondary_elements", :enabled=>(values["use_secondary_basis"] == 1))
+      #set_attr("secondary_basis", :enabled=>(values["use_secondary_basis"] == 1))
       set_attr("dfttype", :enabled=>(values["dft"] == 1))
-      set_attr("use_internal", :enabled=>((values["runtype"] || 0) >= 2))
       set_attr("psi4conda_folder", :enabled=>(values["execute_local"] == 1))
+      set_attr("select_folder", :enabled=>(values["execute_local"] == 1))
       set_attr("ncpus", :enabled=>(values["execute_local"] == 1))
       #nbos.each { |nao|
       #  set_attr(nao, :enabled=>(values["include_nbo"] == 1))
@@ -1989,11 +2155,11 @@ class Molecule
     }
     if hash[:status] == 0
       #  Specify basis by internal keys
-      hash["basis"] = bset_desc[hash["basis"]]
-      hash["secondary_basis"] = bset_desc[hash["secondary_basis"]]
-      hash["dfttype"] = dfttype_desc[hash["dfttype"]]
-      hash["runtype"] = runtype_desc[hash["runtype"]]
-      hash["scftype"] = scftype_desc[hash["scftype"]]
+      hash["basis"] = bset_desc[hash["basis"] || 0]
+      hash["secondary_basis"] = bset_desc[hash["secondary_basis"] || 0]
+      hash["dfttype"] = dfttype_desc[hash["dfttype"] || 0]
+      hash["runtype"] = runtype_desc[hash["runtype"] || 0]
+      hash["scftype"] = scftype_desc[hash["scftype"] || 0]
       basename = (self.path ? File.basename(self.path, ".*") : self.name)
       fname = Dialog.save_panel("Export Psi4 input file:", self.dir, basename + ".in", "Psi4 input file (*.in)|*.in|All files|*.*")
       return nil if !fname
@@ -2003,6 +2169,14 @@ class Molecule
         export_psi4(fname, hash)
       end
       if hash["execute_local"] == 1
+        if hash["run_janpa"] == 1
+          #  Check if Java is available
+          if !Molecule.is_java_available()
+            if !Molecule.make_java_available()
+              return nil
+            end
+          end
+        end
         @hf_type = hash["scftype"]
         Molecule.execute_psi4(fname, self)
       end