Commit b5fa524f authored by Samuel Tan's avatar Samuel Tan
Browse files

update: recently no pushing, couple of changes can't quite remember, psi4mp2 and stuff

parent 5c92ed94
......@@ -31,7 +31,7 @@ Note that the optional arguments given override the values
in the task file. Lines beginning with '#' are treated as comments.
ppqc allows for more options to be specified in the task file.
For example, with GAMESS input files, any keyword can in the
For example, with GAMESS input files, any keyword in the
$ groups can be replaced simply by specifying it in the task file.
E.g.
runtyp=optimize
......
......@@ -62,7 +62,7 @@ def genPsi4(curr_sys, tsk_d):
if "memory" in tsk_d:
out_f = [re.sub("memory.+", "memory " + tsk_d["memory"], x) for x in out_f]
if "basis" in tsk_d:
out_f = [re.sub("basis.+", "basis " + tsk_d["basis"], x) for x in out_f]
out_f = [re.sub("basis .+", "basis " + tsk_d["basis"], x) for x in out_f]
if "title" in tsk_d:
out_f[0] = '# ' + tsk_d["title"]
......@@ -106,22 +106,37 @@ def mp2Psi4(curr_sys, tsk_d):
out_f = [re.sub("basis.+", "basis " + tsk_d["basis"], x) for x in out_f]
if "title" in tsk_d:
out_f[0] = '# ' + tsk_d["title"]
# better looking indentation
pos1 = pos_uniq(out_f, "set globals {")
if "guess" in tsk_d:
out_f = [re.sub("guess.+", "guess " + tsk_d["guess"], x) for x in out_f]
if "scf_type" in tsk_d:
out_f = [re.sub("scf_type.+", "scf_type " + tsk_d["scf_type"], x) for x in out_f]
#*# commented out for Gaussian opt hack #*#
# better looking indentation (for Psi4 globals)
pos1 = pos_uniq(out_f, "set globals {")
# fancy stuff to look for next closing brace (assuming only one)
# and then get correct position by adding pos1 back in
pos2 = pos_uniq(out_f[pos1:], "^}$") + pos1
# start at pos1 +1 because not indenting set globals
#*# commented out for Gaussian opt hack #*#
## start at pos1 +1 because not indenting set globals
for i in range(pos1 + 1, pos2):
out_f[i] = " " + out_f[i]
out_f_d = {}
for i,mol in enumerate(curr_sys.molDict.values()):
ins = mol.printMol("psi4")
out_f_d[i+1] = insert_List(out_f, tag = "xyz_data", insertThis = ins)
allmol = curr_sys.molDict.keys()
for l, k in enumerate(allmol):
cp1 = curr_sys.molDict[k].printMol("psi4")
cp1 = [ " @" + i.lstrip() for i in cp1]
for m,n in curr_sys.molDict.items():
if m != k:
cp1 += n.printMol("psi4")
out_f_d[l+3] = insert_List(out_f, tag = "xyz_data", insertThis = cp1)
# write complex
out_f_d["complex"] = insert_List(out_f, tag = "xyz_data", insertThis = curr_sys.printSys("psi4"))
......
......@@ -76,7 +76,6 @@ def main():
p.add_argument("-t", "--template", help = "path to template file")
args = p.parse_args()
# if no taskfile specified
try:
readTaskFile(args.taskfile)
......@@ -94,7 +93,6 @@ def main():
taskDict["out_filename"] = args.out_filename
if args.template:
taskDict["template"] = args.template
if taskDict["task"] == "interactefp":
essentials = ["task", "inp_1", "inp_2", "efp_1", "efp_2"]
else:
......@@ -150,11 +148,24 @@ def main():
prettyPrint(mol, out_filename = taskDict["out_filename"] + "_" + str(i) + ".inp")
#prettyPrint(a["complex"], out_filename = taskDict["out_filename"] + "_complex")
else:
#for i, mol in a.items():
# if i is not "complex":
# prettyPrint(mol)
prettyPrint(a["complex"])
elif taskDict["task"] == "psi4":
print(args)
a = psi4(curr_sys = curr_sys, tsk_d = taskDict)
if "out_filename" in taskDict:
for i, mol in a.items():
if i is not "complex":
prettyPrint(mol)
prettyPrint(mol, out_filename = taskDict["out_filename"] + "_" + str(i) + ".inp")
#prettyPrint(a["complex"], out_filename = taskDict["out_filename"] + "_complex")
else:
#for i, mol in a.items():
# if i is not "complex":
# prettyPrint(mol)
prettyPrint(a["complex"])
# GAMESS optimisation
elif taskDict["task"] == "opt_gam":
key_list = [str(a).lower() for a in taskDict.keys()]
......
#!/usr/bin/env python3
from chemF import *
import molDB as mDB # for checking mol is in molDB, if now, warn
from inp_formats import *
import re, os
import sys, getopt, argparse
import collections as col
taskDict = {}
def readTaskFile(tsk_f):
""" reads in task file and puts variables
in a global dictionary, for all to see
ignores comment lines, which start with '#'
"""
f = read_file(tsk_f)
global taskDict
for line in f:
if not line.strip().startswith("#"):
try:
l = line.split("=")
taskDict[l[0]] = l[1]
except IndexError:
print("Line without equal symbol (=) found in task file--do you have a blank line?")
sys.exit(2)
# ensure correct types
if "nfrag" in taskDict:
taskDict["nfrag"] = int(taskDict["nfrag"])
if "guess_charges" in taskDict:
taskDict["guess_charges"] = taskDict["guess_charges"].lower()
def prettyPrint(contentsList, out_filename = None):
""" contentsList is the contents we want to output in list form
out_filename is the file we are writing to
"""
if out_filename:
f = open(out_filename, 'w+')
f.write("\n".join(contentsList))
elif not contentsList:
print(" empty list")
elif isinstance(contentsList[0], int):
print("\n".join(str(contentsList)))
elif isinstance(contentsList[0], str):
print("\n".join(contentsList))
else:
print("TypeError: prettyPrint() arg must be a list")
def usage():
usage_str = """
Usage:
qcpp <task_file> -x <xyz_file> -o <out_filename> -t <template>
See the "templates" directory for examples of templates
"""
warning(usage_str)
def main():
""" main execution happens here """
# returns 2 things:
# list of (option,value) pairs
# arguments after optional arguments removed
# optional parameters that take an arg must be followed by a ":"
# Wed 17 Feb 2016: getopt made redundant, and argparse used
# parser
p = argparse.ArgumentParser(description = "Python Preprocessor for Quantum Chemistry")
p.add_argument("taskfile", help = "path to the task file")
p.add_argument("-o", "--out_filename", help = "path/name of the file to write to")
p.add_argument("-x", "--xyz_file", help = "path to xyz file")
p.add_argument("-t", "--template", help = "path to template file")
args = p.parse_args()
# if no taskfile specified
try:
readTaskFile(args.taskfile)
except FileNotFoundError:
readTaskFile(scriptPath("taskfiles/intEgamess.gen"))
print("task file cannot be found ", args.taskfile)
usage()
#sys.exit(2)
# override task file defaults with optional arguments
if args.xyz_file:
taskDict["using"] = args.xyz_file
if args.out_filename:
taskDict["out_filename"] = args.out_filename
if args.template:
taskDict["template"] = args.template
if taskDict["task"] == "interactefp":
essentials = ["task", "inp_1", "inp_2", "efp_1", "efp_2"]
else:
essentials = ["task", "using"]
# check that taskDict contains all the information we need
i = [x for x in essentials if x not in taskDict]
if i: # i not an empty list
warning("Error: not specified in either task file or command line arguments: ", ", ".join(i))
print(taskDict)
usage()
return 1
#sys.exit(5)
# System class from chemF: read in xyz coordinates
if taskDict["task"] != "interactefp":
try:
curr_sys = System(read_xyz = taskDict["using"])
except FileNotFoundError:
print("FileNotFoundError: specified xyz file can't be found")
print("cant find ", taskDict["using"])
sys.exit(2)
# collect atoms into molecules
if "nfrag" in taskDict:
warning("nfrag detected: ", taskDict["nfrag"])
curr_sys.aggregateMol(nfrag = taskDict["nfrag"])
for mol in curr_sys.molDict.values():
if not mDB.isAnion(mol, q = True) and not mDB.isCation(mol, q = True):
warning("WARNING! ",
col.Counter(mol.atomListAsElem_Sym()),
" is not found in the database")
# printing using functions in formats.py
a = 1
# Psi4 SAPT
if taskDict["task"] == "psi4sapt":
a = genPsi4(curr_sys = curr_sys, tsk_d = taskDict)
try:
prettyPrint(a, taskDict["out_filename"])
except KeyError:
prettyPrint(a)
return 0
# Psi4 MP2
elif taskDict["task"] == "psi4mp2":
a = mp2Psi4(curr_sys = curr_sys, tsk_d = taskDict)
if "out_filename" in taskDict:
for i, mol in a.items():
prettyPrint(mol, out_filename = taskDict["out_filename"] + "_" + str(i) + ".inp")
#prettyPrint(a["complex"], out_filename = taskDict["out_filename"] + "_complex")
else:
#for i, mol in a.items():
# if i is not "complex":
# prettyPrint(mol)
prettyPrint(a["complex"])
elif taskDict["task"] == "psi4":
print(args)
a = psi4(curr_sys = curr_sys, tsk_d = taskDict)
if "out_filename" in taskDict:
for i, mol in a.items():
prettyPrint(mol, out_filename = taskDict["out_filename"] + "_" + str(i) + ".inp")
#prettyPrint(a["complex"], out_filename = taskDict["out_filename"] + "_complex")
else:
#for i, mol in a.items():
# if i is not "complex":
# prettyPrint(mol)
prettyPrint(a["complex"])
# GAMESS optimisation
elif taskDict["task"] == "opt_gam":
key_list = [str(a).lower() for a in taskDict.keys()]
if [b for b in key_list if b in ["basis", "gbasis"]]:
print("No support for Basis group in GAMESS at the moment")
print("Please remove line from task file and use a template file instead")
return 0
a = optGamess(curr_sys = curr_sys, tsk_d = taskDict)
try:
prettyPrint(a, out_filename = taskDict["out_filename"])
except KeyError:
prettyPrint(a)
return 0
# GAMESS EFP
elif taskDict["task"] == "genefpinput":
key_list = [str(a).lower() for a in taskDict.keys()]
if [b for b in key_list if b in ["basis", "gbasis"]]:
print("No support for Basis group in GAMESS at the moment")
print("Please remove line from task file and use a template file instead")
return 0
a = efpGamess(curr_sys = curr_sys, tsk_d = taskDict)
if taskDict.get("out_filename"):
prettyPrint(a[0], taskDict["out_filename"] + "1" + ".inp")
prettyPrint(a[1], taskDict["out_filename"] + "2" + ".inp")
else:
#prettyPrint(a[0], "efp_frag_0.inp")
#prettyPrint(a[1], "efp_frag_1.inp")
prettyPrint(a[0])
prettyPrint(a[1])
return 0
# GAMESS EFP interaction
elif taskDict["task"] == "interactefp":
a = efpIntGamess(tsk_d = taskDict)
if "out_filename" in taskDict:
prettyPrint(a, out_filename = taskDict["out_filename"])
else:
prettyPrint(a)
return 0
# GAMESS interaction energy (FMO version)
elif taskDict["task"] == "gen_cluster_intE":
# generates multiple input files, one for the whole cluster
# and individual files for each cation and anion
a = FMOintEnGamess(curr_sys = curr_sys, tsk_d = taskDict)
#for j,f in a.items():
# print("this is ", j)
# prettyPrint(f)
#print(a)
# these print nicely now
# ironing out the last bits of the cluster input file
# can use enumerate to get sequential cation/anion input files
#print(a)
for cation in a["cations"]:
prettyPrint(a[cation], "cation_" + str(cation) + ".ok")
for anion in a["anions"]:
prettyPrint(a[anion], "anion_" + str(anion) + ".ok")
# print cluster
try:
prettyPrint(a["cluster"], taskDict["out_filename"])
except KeyError:
prettyPrint(a["cluster"])
return 0
# geodesic GAMESS
elif taskDict["task"] == "gen-geod-inp":
key_list = [str(a).lower() for a in taskDict.keys()]
if [b for b in key_list if b in ["basis", "gbasis"]]:
print("No support for Basis group in GAMESS at the moment")
print("Please remove line from task file and use a template file instead")
return 0
if "template" in taskDict:
pass
else:
taskDict["template"] = scriptPath("templates/geodesic.template")
# note using same function as optimise, since
# basically just replacing xyz_data
a = optGamess(curr_sys = curr_sys, tsk_d = taskDict)
try:
prettyPrint(a, out_filename = taskDict["out_filename"])
except KeyError:
prettyPrint(a)
return 0
else:
print("Task not recognized", taskDict["task"])
return 1
#return a
# because we're still testing
# todo
# remove -s taskfile and change -t to template
main()
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
# DF-MP2 CALCULATION: c1mim-bf4-p1_aDZ_Mp2
memory 32 Gb
molecule complex {
0 1
xyz_data
units angstrom
no_reorient
symmetry c1
}
set globals {
basis aug-cc-pVDZ
scf_type DF
freeze_core True
guess sad
basis_guess 3-21G
S_ORTHOGONALIZATION canonical
}
energy('mp2')
# SAPT CALCULATION: c1mim-bf4-p1_aDZ_Mp2
# DF-MP2 CALCULATION: c1mim-bf4-p1_aDZ_Mp2
memory 32 Gb
......
test 100644 → 100755
File mode changed from 100644 to 100755
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment