From a232e46dab42e8d4209aa4919e8a4e55eecfc4bd Mon Sep 17 00:00:00 2001 From: toshinagata1964 Date: Thu, 20 Dec 2012 08:45:04 +0000 Subject: [PATCH] export_gamess is modified so that arbitrary keyword/value pairs can be given. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/molby/trunk@349 a2be9bc6-48de-4e38-9406-05402d4bc13c --- Scripts/gamess.rb | 145 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 116 insertions(+), 29 deletions(-) diff --git a/Scripts/gamess.rb b/Scripts/gamess.rb index 1e31fc2..aede574 100755 --- a/Scripts/gamess.rb +++ b/Scripts/gamess.rb @@ -100,6 +100,10 @@ class Molecule def export_gamess(fname, hash) + def reorder_array(ary, ordered_sub_ary) + return ordered_sub_ary + (ary - ordered_sub_ary) + end + now = Time.now.to_s basename = File.basename(fname, ".*") @@ -157,38 +161,121 @@ class Molecule natoms += 1 if ap.atomic_number != 0 } + # Fill hash with default values + h = (hash["CONTRL"] ||= Hash.new) + h["COORD"] ||= "UNIQUE" + h["EXETYP"] ||= "RUN" + h["ICHARG"] ||= icharg.to_s + h["ICUT"] ||= "20" + h["INTTYP"] ||= "HONDO" + h["ITOL"] ||= "30" + h["MAXIT"] ||= "200" + h["MOLPLT"] ||= ".T." + h["MPLEVL"] ||= "0" + h["MULT"] ||= mult.to_s + h["QMTTOL"] ||= "1e-08" + h["RUNTYP"] ||= runtyp + if hash["dft"] != 0 + h["DFTTYP"] ||= hash["dfttype"] + end + if hash["use_internal"] != 0 && (hash["runtype"] == 2 || h["RUNTYP"] == "OPTIMIZE") + nzvar = natoms * 3 - 6 # TODO: 3N-5 for linear molecules + h["NZVAR"] = nzvar.to_s + else + nzvar = 0 + end + h["SCFTYP"] ||= scftyp + if ecp_read != "" + h["ECP"] ||= "READ" + end + h["UNITS"] = "ANGS" + + h = (hash["SCF"] ||= Hash.new) + h["CONV"] ||= "1.0E-06" + h["DIRSCF"] ||= ".T." + h["FDIFF"] ||= ".T." + h["DAMP"] ||= ".T." + + h = (hash["STATPT"] ||= Hash.new) + h["NSTEP"] ||= "400" + h["OPTTOL"] ||= "1.0E-06" + + h = (hash["SYSTEM"] ||= Hash.new) + h["MEMDDI"] ||= "0" + h["MWORDS"] ||= "16" + h["TIMLIM"] ||= "50000" + + h = (hash["GUESS"] ||= Hash.new) + h["GUESS"] ||= "HUCKEL" + + if gbasis + h = (hash["BASIS"] ||= Hash.new) + h["GBASIS"] ||= gbasis + end + + if nzvar > 0 + h = (hash["ZMAT"] ||= Hash.new) + h["DLC"] ||= ".T." + h["AUTO"] ||= ".T." + end + + if hash["esp"] != 0 + h = (hash["ELPOT"] ||= Hash.new) + h["IEPOT"] ||= "1" + h["OUTPUT"] ||= "PUNCH" + h["WHERE"] ||= "PDC" + h = (hash["PDC"] ||= Hash.new) + h["CONSTR"] ||= "NONE" + h["PTSEL"] ||= "CONNOLLY" + end + File.open(fname, "wb") { |fp| fp.print "! GAMESS input\n" fp.print "! Generated by Molby at #{now}\n" - fp.print " $CONTRL COORD=UNIQUE EXETYP=RUN ICHARG=#{icharg}\n" - fp.print " ICUT=20 INTTYP=HONDO ITOL=30\n" - fp.print " MAXIT=200 MOLPLT=.T. MPLEVL=0\n" - fp.print " MULT=#{mult} QMTTOL=1e-08 RUNTYP=#{runtyp}\n" - if hash["dft"] != 0 - dfttyp = hash["dfttype"] - fp.print " DFTTYP=#{dfttyp}\n" - end - if hash["use_internal"] != 0 && hash["runtype"] == 2 - nzvar = natoms * 3 - 6 # TODO: 3N-5 for linear molecules - fp.print " NZVAR=#{nzvar}\n" - else - nzvar = 0 - end - fp.print " SCFTYP=#{scftyp} #{ecp_read}UNITS=ANGS $END\n" - fp.print " $SCF CONV=1.0E-06 DIRSCF=.T. FDIFF=.T. DAMP=.T. $END\n" - fp.print " $STATPT NSTEP=400 OPTTOL=1.0E-06 $END\n" - fp.print " $SYSTEM MEMDDI=0 MWORDS=16 TIMLIM=50000 $END\n" - fp.print " $GUESS GUESS=HUCKEL $END\n" - if gbasis - fp.print " $BASIS GBASIS=#{gbasis} $END\n" - end - if nzvar > 0 - fp.print " $ZMAT DLC=.T. AUTO=.T. $END\n" - end - if hash["esp"] != 0 - fp.print " $ELPOT IEPOT=1 OUTPUT=PUNCH WHERE=PDC $END\n" - fp.print " $PDC CONSTR=NONE PTSEL=CONNOLLY $END\n" - end + controls = reorder_array(hash.keys.select { |k| hash[k].is_a?(Hash) }, + ["CONTRL", "SCF", "STATPT", "SYSTEM", "GUESS", "BASIS", "ZMAT", "ELPOT", "PDC"]) + controls.each { |k| + h = hash[k] + next if h == nil || h.size == 0 + if k == "CONTRL" + ordered = ["COORD", "EXETYP", "ICHARG", "ICUT", "INTTYP", "ITOL", "MAXIT", "MOLPLT", "MPLEVL", + "MULT", "QMTTOL", "RUNTYP", "SCFTYP", "ECP", "UNITS", "DFTTYP", "NZVAR"] + elsif k == "SCF" + ordered = ["CONV", "DIRSCF", "FDIFF", "DAMP"] + elsif k == "STATPT" + ordered = ["NSTEP", "OPTTOL"] + elsif k == "SYSTEM" + ordered = ["MEMDDI", "MWORDS", "TIMLIM"] + elsif k == "GUESS" + ordered = ["GUESS"] + elsif k == "BASIS" + ordered = ["GBASIS"] + elsif k == "ZMAT" + ordered = ["DLC", "AUTO"] + elsif k == "ELPOT" + ordered = ["IEPOT", "OUTPUT", "WHERE"] + elsif k == "PDC" + ordered = ["CONSTR", "PTSEL"] + else + ordered = [] + end + keys = reorder_array(h.keys, ordered) + n = 0 + keys.each_with_index { |kk, i| + v = h[kk] + next if v == nil || v == "" + if n == 0 + fp.printf " $%-6s", k + elsif n % 3 == 0 + fp.print "\n " + end + fp.printf " %s=%s", kk, h[kk].to_s + n += 1 + } + if n > 0 + fp.print " $END\n" + end + } fp.print " $DATA\n#{basename}\nC1 0\n" secondary = [] each_atom { |ap| -- 2.11.0