-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup_BH6_orca.py
209 lines (164 loc) · 6.08 KB
/
setup_BH6_orca.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import yaml
from os import path, system, sys
from subprocess import run as subrun
eH_to_eV = 27.211386245988
eV_to_kcalmol = 23.06054783061903
eH_to_kcalmol = eH_to_eV*eV_to_kcalmol
bh6_rxs = [45,46,61,62,63,64]
rdir = path.dirname(path.realpath(__file__)) + '/'
accept_opts = ['method', 'basis', '*xyz', '*xyzfile', '%scf', 'charge', '2S+1',
'tol', 'grid', 'rest', '%pal']
def get_BH6_sys_list():
rxd = yaml.load(open(rdir + 'BH76_ref_energies.yaml','r'),\
Loader=yaml.Loader)
sysl = []
for irx in bh6_rxs:
td = rxd[irx]['Stoich']
for asys in td:
if asys not in sysl:
sysl.append(asys)
return sysl
def job_script(file_name='./runjob.sh'):
tstr = '#!/bin/bash\n'
tstr += '#PBS -l walltime=1:00:00:00\n'
tstr += '#PBS -q normal\n'
tstr += '#PBS -l nodes=1:ppn=20\n'
tstr += '#PBS -N BH6\n'
tstr += '#PBS -j oe\n'
tstr += '#PBS -o oe.txt\n'
tstr += '#PBS -m a\n\n'
tstr += 'cd "$PBS_O_WORKDIR"\n'
tstr += 'export PATH=/home/tuf53878/orca/openmpi-4.1.1/bin:$PATH\n'
tstr += 'export LD_LIBRARY_PATH=/home/tuf53878/orca/openmpi-4.1.1/lib:$LD_LIBRARY_PATH\n'
tstr += 'orca_exec=/home/tuf53878/orca/orca\n\n'
tstr += 'for u in ./*/ ; do\n'
tstr += ' cd $u\n'
tstr += ' $orca_exec inp.txt >> out.txt\n'
tstr += ' cd ..\n'
tstr += 'done'
with open(file_name,'w+') as tfl:
tfl.write(tstr)
return
def orca_inp_writer(opts={},file_name='./inp.txt'):
def_opts = {
'method': 'PBE', 'basis': 'def2-qzvp', '*xyzfile': 'struc.xyz',
'%scf': {'MaxIter': 500}, 'charge': 0, '2S+1': 1, 'tol': 'StrongSCF',
'grid': 'defgrid2', 'rest': 'RKS', '%pal': {'nprocs': 20}
}
for anopt in opts:
def_opts[anopt] = opts[anopt]
with open(file_name,'w+') as tfl:
for anopt in def_opts:
if anopt[0] == '%':
tfl.write('{:}\n'.format(anopt))
for bopt in def_opts[anopt]:
tfl.write('{:} {:}\n'.format(bopt,def_opts[anopt][bopt]))
tfl.write('end\n')
elif anopt[0] == '*':
if anopt == '*xyz':
tfl.write('{:} {:} {:}\n'.format(anopt,def_opts['charge'],def_opts['2S+1']))
for anat in def_opts[anopt]:
tfl.write('{:} {:} {:} {:}\n'.format(anat,*def_opts[anopt][anat]))
tfl.write('*\n')
elif anopt == '*xyzfile':
tfl.write('{:} {:} {:} {:}\n'.format(anopt, def_opts['charge'], \
def_opts['2S+1'], def_opts['*xyzfile']))
elif anopt in ['charge','2S+1']:
continue
else:
tfl.write('! {:}\n'.format(def_opts[anopt]))
return
def setup_BH6(uopts,makeclean=True):
cmd = yaml.load(open(rdir + 'BH76_chg_2s.yaml','r'),\
Loader=yaml.Loader)
sys_l = get_BH6_sys_list()
thstr = 'KS'
if uopts['method'] == 'HF':
thstr = 'HF'
wdir = 'BH6_{:}/'.format(uopts['method'])
geodir = rdir + 'BH76_geometries/'
if makeclean:
system('rm -rf ' + wdir)
system('mkdir ' + wdir)
job_script(file_name=wdir+'runjob.sh')
for asys in sys_l:
system('cp -r {:}/{:} {:}/'.format(geodir,asys,wdir))
topts = { }
for anopt in uopts:
topts[anopt] = uopts[anopt]
topts['charge'] = cmd[asys]['Charge']
topts['2S+1'] = cmd[asys]['2S']+1
if cmd[asys]['R']:
topts['rest'] = 'R'+thstr
else:
topts['rest'] = 'U'+thstr
orca_inp_writer(opts=topts,file_name=wdir + asys +'/inp.txt')
return
def analysis(dir='./'):
rxd = yaml.load(open(rdir + 'BH76_ref_energies.yaml','r'),\
Loader=yaml.Loader)
sysl = get_BH6_sys_list()
en_d = {
'units': 'kcal/mol',
'SP': {},
'RX': {},
'Stats': {'MD': 0.0, 'MAD': 0.0, 'VAR': 0.0, 'STD DEV': 0.0, 'RMSD': 0.0}
}
for asys in sysl:
tmp_byte = subrun(['grep','FINAL SINGLE POINT ENERGY',asys+'/out.txt'], \
capture_output=True)
vals = tmp_byte.stdout.decode('utf-8').split()
etot = float(vals[-1])
tmp_byte = subrun(['grep','SCF CONVERGED',asys+'/out.txt'], \
capture_output=True)
tmpstr = tmp_byte.stdout.decode('utf-8').split()
if len(tmpstr) == 0:
print('WARNING, {:} not converged'.format(asys))
en_d['SP'][asys] = etot*eH_to_kcalmol
for jrx,irx in enumerate(bh6_rxs):
en_d['RX'][jrx] = 0.0
td = rxd[irx]['Stoich']
for asys in td:
en_d['RX'][jrx] += td[asys]*en_d['SP'][asys]
terr = en_d['RX'][jrx] - rxd[irx]['Ref']
en_d['Stats']['MD'] += terr
en_d['Stats']['MAD'] += abs(terr)
en_d['Stats']['VAR'] += terr**2
fnsys = 1.*len(bh6_rxs)
en_d['Stats']['MD'] /= fnsys
en_d['Stats']['MAD'] /= fnsys
en_d['Stats']['VAR'] /= fnsys
en_d['Stats']['STD DEV'] = max(0.0, en_d['Stats']['VAR'] - en_d['Stats']['MD']**2)**(0.5)
en_d['Stats']['RMSD'] = en_d['Stats']['VAR']**(0.5)
with open('./BH6_total.yaml','w+') as tfl:
yaml.dump(en_d,tfl,Dumper=yaml.Dumper)
return
def parse_into_setup():
method = None
makeclean = True
dfa_dir = None
ioptd = {}
if len(sys.argv) < 2:
raise SystemExit('Need to specify at least the density functional!')
elif sys.argv[1] == 'analysis':
analysis()
exit()
else:
for astr in sys.argv[1:]:
key,val = astr.split('=')
lkey = key.lower()
if lkey == 'clean':
if val.lower()[0] == 't':
makeclean = True
elif val.lower()[0] == 'f':
makeclean = False
else:
print('Keyword "clean" must be t/f!')
elif key in accept_opts:
ioptd[key] = val
else:
print('Skipping unknown keyword {:}'.format(key))
setup_BH6(ioptd,makeclean=makeclean)
return
if __name__ == "__main__":
parse_into_setup()