pygamessはもともと、gamessのインプット作るのめんどくさいっていうのがモジュール作成のモチベーションだったので、gamess実行環境(rungms)が既にあるという前提だったが、最近pybelに対応したことにより、分子設計的な側面が強くなってしまったので、gamess実行環境もまとめて面倒みたほうがいいかなぁと。
rungmsは単なるシェルスクリプトなんだけど、ファイルを直接編集しないといけないので、動くようにするのがめんどくさい(色々なOSに対応するようにしているのでごちゃごちゃしている)。普通に動かせる最小のスクリプトはどんな感じかなぁと1000行超えのスクリプトを削って行ったら200行くらいになったが、残ったコードのほとんどがsetenvだった。どんだけ環境変数好きやねん?と。
import os
import sys
import socket
from shutil import copyfile, rmtree
from tempfile import mkstemp, mkdtemp
scr = mkdtemp()
job = sys.argv[1]
gamess_path = "/usr/local/gamess"
ddikick = os.path.join(gamess_path, "ddikick.x")
gamess = os.path.join(gamess_path, "gamess.Jan122009R1.x")
hostname = socket.gethostname()
setenv_data = [
(" MAKEFP", "efp"), ("GAMMA", "gamma"), ("TRAJECT", "trj"),
("RESTART", "rst"), (" PUNCH", "dat"), (" INPUT", "F05"),
(" AOINTS", "F08"), (" MOINTS", "F09"), ("DICTNRY", "F10"),
("DRTFILE", "F11"), ("CIVECTR", "F12"), ("CASINTS", "F13"),
(" CIINTS", "F14"), (" WORK15", "F15"), (" WORK16", "F16"),
("CSFSAVE", "F17"), ("FOCKDER", "F18"), (" WORK19", "F19"),
(" DASORT", "F20"), ("DFTINTS", "F21"), ("DFTGRID", "F22"),
(" JKFILE", "F23"), (" ORDINT", "F24"), (" EFPIND", "F25"),
("SVPWRK1", "F26"), ("SVPWRK2", "F27"), (" MLTPL", "F28"),
(" MLTPLT", "F29"), (" DAFL30", "F30"), (" SOINTX", "F31"),
(" SOINTY", "F32"), (" SOINTZ", "F33"), (" SORESC", "F34"),
("GCILIST", "F37"), ("HESSIAN", "F38"), ("QMMMTEI", "F39"),
("SOCCDAT", "F40"), (" AABB41", "F41"), (" BBAA42", "F42"),
(" BBBB43", "F43"), (" MCQD50", "F50"), (" MCQD51", "F51"),
(" MCQD52", "F52"), (" MCQD53", "F53"), (" MCQD54", "F54"),
(" MCQD55", "F55"), (" MCQD56", "F56"), (" MCQD57", "F57"),
(" MCQD58", "F58"), (" MCQD59", "F59"), (" MCQD60", "F60"),
("NMRINT1", "F61"), ("NMRINT2", "F62"), ("NMRINT3", "F63"),
("NMRINT4", "F64"), ("NMRINT5", "F65"), ("NMRINT6", "F66"),
("ELNUINT", "F67"), ("NUNUINT", "F68"), (" NUMOIN", "F69"),
(" GMCREF", "F70"), (" GMCO2R", "F71"), (" GMCROC", "F72"),
(" GMCOOC", "F73"), (" GMCCC0", "F74"), (" GMCHMA", "F75"),
(" GMCEI1", "F76"), (" GMCEI2", "F77"), (" GMCEOB", "F78"),
(" GMCEDT", "F79"), (" GMCERF", "F80"), (" GMCHCR", "F81"),
(" GMCGJK", "F82"), (" GMCGAI", "F83"), (" GMCGEO", "F84"),
(" GMCTE1", "F85"), (" GMCTE2", "F86"), (" GMCHEF", "F87"),
(" GMCMOL", "F88"), (" GMCMOS", "F89"), (" GMCWGT", "F90"),
(" GMCRM2", "F91"), (" GMCRM1", "F92"), (" GMCR00", "F93"),
(" GMCRP1", "F94"), (" GMCRP2", "F95"), (" GMCVEF", "F96"),
(" GMCDIN", "F97"), (" GMC2SZ", "F98"), (" GMCCCS", "F99")
]
for e in setenv_data:
os.environ[e[0].strip()] = "%s/%s.%s" %(scr, job, e[1])
os.environ["ERICFMT"] = os.path.join(gamess_path, "ericfmt.dat")
os.environ["MCPPATH"] = os.path.join(gamess_path, "mcpdata")
os.environ["EXTBAS"] = "/dev/null"
os.environ["NUCBAS"] = "/dev/null"
src = job + ".inp"
dest = os.path.join(scr,job) + ".F05"
copyfile(src,dest)
exec_string = "%s %s %s -ddi 1 1 %s -scr %s > t.out" % (ddikick, gamess, job, hostname, scr)
os.system(exec_string)
rmtree(scr)