srDFT_G2/Ref/Inputs_G1/qp_create_ezfio_from_g09_zmat

92 lines
2.0 KiB
Plaintext
Raw Normal View History

2019-03-26 15:02:24 +01:00
#!/usr/bin/env python2
"""
convert zmatrix and input for spin multiplicity and charge from the SI of
J. Chem. Phys. 131, 154112 (2009); https://doi.org/10.1063/1.3247288
into a zmatrix usable by the QP, and spits the correct command to execute
Usage:
qp_create_ezfio_from_g09_zmat g09_zmat basis
Produces the ezfio folder g09_zmat.ezfio
"""
import sys
import os
import subprocess
try:
import qp_path
except ImportError:
print "source .quantum_package.rc"
raise
try:
QP_ROOT = os.environ["QP_ROOT"]
QP_EZFIO = os.environ["QP_EZFIO"]
except KeyError:
print "Error: QP_ROOT environment variable not found."
sys.exit(1)
else:
sys.path = [QP_EZFIO + "/Python",
QP_ROOT + "/install/resultsFile",
QP_ROOT + "/install",
QP_ROOT + "/scripts"] + sys.path
def findall(sub, string):
"""
>>> text = "Allowed Hello Hollow"
>>> tuple(findall('ll', text))
(1, 10, 16)
"""
index = 0 - len(sub)
try:
while True:
index = string.index(sub, index + len(sub))
yield index
except ValueError:
pass
filepath = sys.argv[1]
basis = sys.argv[2]
icount = 0
zmat = []
with open(filepath, "r") as fp:
cipsi = []
for line in fp:
if (icount == 0 ):
a=line.split(',')
charge = int(a[0])
spin = int(a[1])
else:
a=line.split()
if(len(a)>0):
n=a[0].count(',')
if(n > 6):
listfind=list(findall(',', a[0]))
char=a[0]
a[0]=char[0:listfind[n-1]]
b=a[0].replace(',', ' ')
b=b.replace('=', ' ')
zmat.append(b)
else:
b=" "
zmat.append(b)
icount += 1
c = filepath.split('.')
file_origin = c[0]
ezfio = file_origin+".ezfio"
zmat_file = file_origin+".zmt"
file_zmat = open(zmat_file,"w+")
for l in zmat:
file_zmat.write(l +'\n')
command="qp_create_ezfio -m %s -c %s -b %s -o %s %s" % (spin,charge,basis,ezfio,zmat_file)
print command
#os.system(command)