-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrc_driver.py
More file actions
executable file
·441 lines (422 loc) · 22.4 KB
/
rc_driver.py
File metadata and controls
executable file
·441 lines (422 loc) · 22.4 KB
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
#!/usr/bin/env python
import os
import sys
import numpy as np
import argparse
import logging
from rcd import config
from rcd import rmg_reader as rg
from rcd import estoktp as es
from qtc import iotools as io
from qtc import obtools as ob
from qtc import tctools as tc
log = logging.getLogger(__name__)
def random_cute_animal():
import random
msg = random.choice(["""\n\t\t TORSSCAN
_,--._
,' `.
|\ / \ /|
)o),/ ( ,--, ,--, ) \.(o(
/o/// /| |\ \\ \\o\\
/ / |\ \( .----, )/ /| \ \\
| | \o`-/ `--' \-'o/ | |
\ \ `,' `.' / /
\. \ `-' ,'| /\ |`. `-' / ,/
\`. `.__,' / / \ \ `.__,' ,'/
\o\ ,' ,' `. `. /o/
\o`---' ,' `. `---'o/
`.____,' `.____,' """,
"""\n
,,, ,,,
;" ^; ;' ",
; s$$$$$$$s ;
, ss$$$$$$$$$$s ,'
;s$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$
$$$$P""Y$$$Y""W$$$$$
$$$$ 0"$$$"0 $$$$$
$$$$ .$$$$$. $$$$
$$$$$$$$$$$$$$$$$
TORS "Y$$$"'*'"$$$Y" SCAN
"$$b.d$$" """,
"""\n
_.---~-~-~~-..
.. __. .-~ ~-.
((\ / `}.~ Try `.
\\\\\ { } Sarah / \ \\
(\ \\\\~~ } opts | } \\
\`.-~-^~ } ,-,. and | ) \\
(___, ) _} ( : scans | / / `.
`----._-~. _\ \ |_ \ / /- _ -.
~~----~~ \ \| ~~--~~~( + / ~-. '--~.
/ / \ \ `~-..__ `~__
__/ / _\ ) `~~---'
.<___.' .<___/
"""])
return msg
def main(inputfile, outputfile, configfile = ''):
torspath = os.path.dirname(os.path.realpath(sys.argv[0]))
if configfile == '':
configfile = torspath + os.path.sep + 'rcd/configfile.txt'
Config = config.CONFIG(configfile,outputfile)
args = config.ARGS( inputfile)
paths = {}
paths['g09'] = args.g09
paths['torsscan'] = torspath
sys.path.insert(0, es.get_paths(paths,'torsscan'))
log.info(random_cute_animal())
##### Build and Run EStokTP ######
####################################
import shutil
symnums = []
samps = None
if args.restart < 8:
index = 0
if "Opt" in args.jobs and args.restart < 1:
alljobs = args.jobs
args.jobs = ["Opt"]
es.run_level0(args, paths)
args.restart = 1
args.jobs = alljobs
if "1dTau" in args.jobs and args.restart < 4:
logging.info("========\nBEGIN LEVEL 1 and 1DHR\n========\n")
alljobs = args.jobs
negvals = True
attempt = 0
while (negvals and attempt < 3):
attempt += 1
args.jobs = ["Opt_1", "1dTau"]
negvals = False
if attempt == 1 and args.restart == 3:
pass
else:
stoichs, symnums = es.build_files(args, paths)
es.execute(paths, args.nodes[0])
if io.check_file('output/estoktp.out'):
shutil.copy('output/estoktp.out','output/estoktp_l1.out')
args.restart = 3
for i in range(len(args.reacs)):
lowene = 0.0
lowenefile = None
if io.check_file('me_files/reac' + str(i+1) + '_hr.me'):
hr = io.read_file('me_files/reac' + str(i+1) + '_hr.me')
hr = hr.split('Rotor')
startkey = 'Potential'
for j, rotor in enumerate(hr[1:]):
pot = rotor.split(startkey)[1]
pot = pot.splitlines()[1]
for k, ene in enumerate(pot.split()):
if float(ene) - lowene < -0.1:
lowene = float(ene)
lowenefile = 'hr_geoms/geom_isp' + str(i+1).zfill(2) + '_hr' + str(j+1).zfill(2) + '_hpt' + str(k+1).zfill(2) + '.xyz'
if lowenefile:
xyz = io.read_file(lowenefile)
logging.info(xyz)
slabel = ob.get_slabel(ob.get_mol(xyz))
if slabel.split('_m')[0] == ob.get_slabel(args.reacs[i]).split('_m')[0]:
negvals = True
if io.check_file('data/ts.dat') and i == 0:
if 'isomerization' in args.reactype.lower():
tsfile = io.read_file('data/ts.dat')
ijk = tsfile.split('ji ki')[1].split()[:3]
ijk.append(tsfile.split('ireact2')[1].split('\n')[1].split()[-1])
xyz = xyz.splitlines()
xyz[int(ijk[0])+1] = '2 ' + xyz[int(ijk[0])+1]
xyz[int(ijk[1])+1] = '3 ' + xyz[int(ijk[1])+1]
xyz[int(ijk[2])+1] = '4 ' + xyz[int(ijk[2])+1]
xyz[int(ijk[3])+1] = '1 ' + xyz[int(ijk[3])+1]
xyz = '\n'.join(xyz)
else:
ijk = io.read_file('data/ts.dat').split('ksite')[1].split()[:3]
xyz = xyz.splitlines()
xyz[int(ijk[0])+1] = '2 ' + xyz[int(ijk[0])+1]
xyz[int(ijk[1])+1] = '1 ' + xyz[int(ijk[1])+1]
xyz[int(ijk[2])+1] = '3 ' + xyz[int(ijk[2])+1]
xyz = '\n'.join(xyz)
slabel = ob.get_smiles_filename(ob.get_slabel(args.reacs[i]))
io.mkdir('geomdir')
io.write_file(xyz,'geomdir/' + slabel + '.xyz')
args.restart = 1
args.XYZ = 'geomdir'
args.xyzstart = '0'
log.warning( 'Lower configuration found in 1dTau. Restarting at Level1. Saved geometry to {}'.format(slabel + '.xyz'))
else:
log.warning( 'Lower configuration found in 1dTau. But has different smiles: {} vs. {}'.format(slabel, ob.get_slabel(args.reacs[i])))
for l in range(len(args.prods)):
lowene = 0.
lowenefile = None
if io.check_file('me_files/prod' + str(l+1) + '_hr.me'):
hr = io.read_file('me_files/prod' + str(l+1) + '_hr.me')
hr = hr.split('Rotor')
startkey = 'Potential'
for j, rotor in enumerate(hr[1:]):
pot = rotor.split(startkey)[1]
pot = pot.splitlines()[1]
for k, ene in enumerate(pot.split()):
if float(ene) - lowene < -0.1:
lowene = float(ene)
lowenefile = 'hr_geoms/geom_isp' + str(i+l+2).zfill(2) + '_hr' + str(j+1).zfill(2) + '_hpt' + str(k+1).zfill(2) + '.xyz'
if lowenefile:
xyz = io.read_file(lowenefile)
slabel = ob.get_slabel(ob.get_mol(xyz))
if slabel.split('_m')[0] == ob.get_slabel(args.prods[l]).split('_m')[0]:
negvals = True
slabel = ob.get_smiles_filename(ob.get_slabel(args.prods[l]))
io.mkdir('geomdir')
io.write_file(xyz, 'geomdir/' + slabel + '.xyz')
args.restart = 1
args.XYZ = 'geomdir'
args.xyzstart = '0'
log.warning( 'Lower configuration found in 1dTau. Restarting at Level1. Saved geometry to {}'.format(slabel + '.xyz'))
else:
log.warning( 'Lower configuration found in 1dTau. But has different smiles: {} vs. {}'.format(slabel, ob.get_slabel(args.prods[l])))
if args.reactype.lower() in ['addition', 'abstraction', 'isomerization', 'addition_well','isomerization_well']:
lowene = 0.
lowenefile = None
if io.check_file('me_files/ts_hr.me'):
hr = io.read_file('me_files/ts_hr.me')
hr = hr.split('Rotor')
startkey = 'Potential'
for j, rotor in enumerate(hr[1:]):
pot = rotor.split(startkey)[1]
pot = pot.splitlines()[1]
for k, ene in enumerate(pot.split()):
if float(ene) - lowene < -0.1:
lowene = float(ene)
lowenefile = 'hr_geoms/geom_isp00_hr' + str(j+1).zfill(2) + '_hpt' + str(k+1).zfill(2) + '.xyz'
if lowenefile:
xyz = io.read_file(lowenefile)
negvals = True
io.mkdir('geomdir')
io.write_file(xyz, 'geomdir/ts.xyz')
args.restart = 1
args.XYZ = 'geomdir'
args.xyzstart = '0'
log.warning( 'Lower configuration found in 1dTau. Restarting at Level1. Saved geometry to ts.xyz')
if args.wellp and args.wellp.lower() != 'false':
lowene = 0.
lowenefile = None
if io.check_file('me_files/wellp_hr.me'):
hr = io.read_file('me_files/wellp_hr.me')
hr = hr.split('Rotor')
startkey = 'Potential'
for j, rotor in enumerate(hr[1:]):
pot = rotor.split(startkey)[1]
pot = pot.splitlines()[1]
for k, ene in enumerate(pot.split()):
if float(ene) - lowene < -0.1:
lowene = float(ene)
lowenefile = 'hr_geoms/geom_isp06_hr' + str(j+1).zfill(2) + '_hpt' + str(k+1).zfill(2) + '.xyz'
if lowenefile:
xyz = io.read_file(lowenefile)
negvals = True
io.mkdir('geomdir')
io.write_file(xyz, 'geomdir/wellp.xyz')
args.restart = 1
args.XYZ = 'geomdir'
args.xyzstart = '0'
log.warning( 'Lower configuration found in 1dTau. Restarting at Level1. Saved geometry to wellp.xyz')
if args.wellr and args.wellr.lower() != 'false':
lowene = 0.
lowenefile = None
if io.check_file('me_files/wellr_hr.me'):
hr = io.read_file('me_files/wellr_hr.me')
hr = hr.split('Rotor')
startkey = 'Potential'
for j, rotor in enumerate(hr[1:]):
pot = rotor.split(startkey)[1]
pot = pot.splitlines()[1]
for k, ene in enumerate(pot.split()):
if float(ene) - lowene < -0.1:
lowene = float( ene)
lowenefile = 'hr_geoms/geom_isp05_hr' + str(j+1).zfill(2) + '_hpt' + str(k+1).zfill(2) + '.xyz'
if lowenefile:
xyz = io.read_file(lowenefile)
negvals = True
io.mkdir('geomdir')
io.write_file(xyz, 'geomdir/wellr.xyz')
args.restart = 1
args.XYZ = 'geomdir'
args.xyzstart = '0'
log.warning( 'Lower configuration found in 1dTau. Restarting at Level1. Saved geometry to wellr.xyz')
args.jobs = alljobs
elif "Opt_1" in args.jobs and args.restart < 2:
log.info("========\nBEGIN LEVEL 1\n========\n")
alljobs = args.jobs
args.jobs = ["Opt_1"]
stoichs, symnums = es.build_files(args, paths)
es.execute(paths, args.nodes[0])
if io.check_file('output/estoktp.out'):
shutil.copy('output/estoktp.out','output/estoktp_l1.out')
args.jobs = alljobs
args.restart = 2
if args.anharm.lower() != 'false' and 'd' not in args.nodes[0]:
from rcd import thermo
log.info("========\nBEGIN VPT2\n========\n")
optlevel, anlevel = thermo.get_anlevel(args.anharm, args.meths)
for n, reac in enumerate(args.reacs):
typ = 'reac'
natom = ob.get_natom(reac)
if natom > 1:
mult = ob.get_mult( reac)
if io.check_file('me_files/' + typ + str(n+1) + '_fr.me'):
mefreqs = io.read_file('me_files/' + typ + str(n+1) + '_fr.me')
if not 'Anh' in mefreqs:
anfr,fr1, anx,fr2,fr3,_ = thermo.get_anharm(typ, str(n+1), natom, args.nodes[0], anlevel, args.anovrwrt, reac, optlevel.split('/'),paths)
io.write_file(mefreqs, 'me_files/' + typ + str(n+1) + '_harm.me')
lines, mefreqs = mefreqs.split('ZeroEnergy')
lines = fr1 + fr2.split('End')[0] + '\n ZeroEnergy' + mefreqs
io.write_file(lines, 'me_files/' + typ + str(n+1) + '_fr.me')
for n, prod in enumerate(args.prods):
typ = 'prod'
natom = ob.get_natom(prod)
if natom > 1:
mult = ob.get_mult( prod)
if io.check_file('me_files/' + typ + str(n+1) + '_fr.me'):
mefreqs = io.read_file('me_files/' + typ + str(n+1) + '_fr.me')
if not 'Anh' in mefreqs:
anfr,fr1, anx,fr2,fr3,_ = thermo.get_anharm(typ, str(n+1), natom, args.nodes[0], anlevel, args.anovrwrt, prod, optlevel.split('/'),paths)
io.write_file(mefreqs, 'me_files/' + typ + str(n+1) + '_harm.me')
lines, mefreqs = mefreqs.split('ZeroEnergy')
lines = fr1 + fr2.split('End')[0] + '\n ZeroEnergy' + mefreqs
io.write_file(lines, 'me_files/' + typ + str(n+1) + '_fr.me')
if args.reactype and io.check_file('geoms/tsgta_l1.xyz'):
typ = 'ts'
mol = io.read_file('geoms/tsgta_l1.xyz')
ts = ob.get_mol(mol)
natom = ob.get_natom(ts)
mult = ob.get_mult( ts)
if io.check_file('me_files/ts_fr.me'):
mefreqs = io.read_file('me_files/ts_fr.me')
if not 'Anh' in mefreqs:
anfr,fr1, anx,fr2,fr3,_ = thermo.get_anharm(typ, str(n+1), natom, args.nodes[0], anlevel, args.anovrwrt, 'ts', optlevel.split('/'),paths)
io.write_file(mefreqs, 'me_files/' + typ + '_harm.me')
lines, mefreqs = mefreqs.split('ZeroEnergy')
imag = fr3.split('WellDepth')[0].split('ImaginaryFrequency[1/cm]')[1].replace('\t','').strip()
mefreqs = mefreqs.splitlines()
for i, line in enumerate(mefreqs):
if 'Imaginary' in line:
mefreqs[i] = ' ImaginaryFrequency[1/cm] {}'.format(imag)
mefreqs = '\n'.join(mefreqs)
lines = fr1 + fr2.split('End')[0] + '\n ZeroEnergy' + mefreqs
io.write_file(lines, 'me_files/' + typ + '_fr.me')
log.info("========\nBEGIN MDHR, HL\n========\n")
if 'kTP' in args.jobs:
alljobs = args.jobs
args.jobs = []
for job in alljobs:
if job != 'kTP':
args.jobs.append(job)
stoichs, symnums = es.build_files(args, paths)
es.execute(paths, args.nodes[0])
if io.check_file('me_files/ts_en.me'):
tsen = float(io.read_file('me_files/ts_en.me'))
tsen += float(io.read_file('me_files/ts_zpe.me'))
reacen = 0
proden = 0
for i, reac in enumerate(args.reacs):
if io.check_file('me_files/reac{}_en.me'.format(i+1)):
reacen += float(io.read_file('me_files/reac{}_en.me'.format(i+1)))
reacen += float(io.read_file('me_files/reac{}_zpe.me'.format(i+1)))
if args.reactype.lower() == 'addition_well' or args.reactype.lower()== 'isomerization_well':
if io.check_file('me_files/wellp_en.me'):
proden += float(io.read_file('me_files/wellp_en.me'))
proden += float(io.read_file('me_files/wellp_zpe.me'))
else:
for i, prod in enumerate(args.prods):
if io.check_file('me_files/prod{}_en.me'.format(i+1)):
proden += float(io.read_file('me_files/prod{}_en.me'.format(i+1)))
proden += float(io.read_file('me_files/prod{}_zpe.me'.format(i+1)))
if tsen <= reacen or tsen <= proden:
log.info('Well Depth is negative. NoTunnel is turned on')
if args.esoptions:
args.esoptions += ',NoTunnel'
else:
args.esoptions = 'NoTunnel'
log.info("========\nBEGIN kTP\n========\n")
args.jobs = alljobs
restart = 7
stoichs, symnums = es.build_files(args, paths)
es.execute(paths, args.nodes[0])
else:
stoichs, symnums = es.build_files(args, paths)
es.execute(paths, args.nodes[0])
if ("1dTau" in args.jobs or 'MdTau' in args.jobs):
for i in range(len(args.reacs)):
es.check_hrs(i+1,'reac')
for i in range(len(args.prods)):
es.check_hrs(i+1,'prod')
es.me_file_abs_path()
if args.restart == 10:
io.execute(['mess', 'me_ktp.inp'])
if args.reactype and io.check_file('rate.out'):
import me_parser
#initialize the class in which to store the results
data = me_parser.paper()
data.reactions = []
# set some constants, depending upon whether the rate coefficients are to be used for CHEMKIN or something else.
data.T0 = 1.0
data.R = 1.987 # cal/mol-K. Note that PLOG formalism requires Ea in cal/mol-K!
data.N_avo = 6.0221415E23 #convert bimolecular rate coefficients from cm^3/sec to cm^3/mol/s
# set the minimum and maximum temperature
#data.Tmin = 600.0
#data.Tmax = 1200.0
# read me.out file from the command line
me_dot_out = 'rate.out'
if io.check_file(me_dot_out):
lines = io.read_file(me_dot_out, True)
if len(lines) < 2:
log.info('rate.out is empty')
## copy new plog executable to the path of the source file
#path = os.path.abspath(os.path.dirname(me_dot_out))
#
#command = 'cp /home/elliott/bin/dsarrfit.x_cfg ' + path
#log.info( command)
#os.system(command)
# parse results for the temperature, pressure, and names of channels
me_parser.get_temp_pres(data,lines)
# parse results for the pdep rate constants
me_parser.get_pdep_k(data,lines)
# fit the results to PLOG expressions
me_parser.fit_pdep(data,nonlin_fit=False) #replace <True> with <False> if you don't want to use the nonlinear solver (not recommended)
# print the resulting PLOG expressions to file
me_parser.print_plog(data, me_dot_out)
# plot the results: dashed line = single PLOG, solid line = double PLOG
#me_parser.plot_reactant(data, me_dot_out, show_plot=False, save_plot=True)
####### Parse results #########
########################################
from rcd import results
rs = results.RESULTS(args, paths)
args.hlen = rs.get_hlen()
args.optlevel = rs.optlevel
args.enlevel = rs.enlevel
args.taulevel = rs.taulevel
if args.parseall.lower() == 'true' or args.alltherm.lower() == 'true':
rs.get_results()
####### Build and run thermo #########
########################################
from rcd import thermo
rs.thermo = False
if args.alltherm.lower() == 'true':
rs.thermo = True
args.symnums = symnums
rs.dH0, rs.dH298, rs.hfbases, rs.anfreqs, rs.anxmat = thermo.run(args, paths, rs.d)
if args.parseall.lower() == 'true':
rs.get_thermo_results()
return
if __name__ == "__main__":
torspath = os.path.dirname(os.path.realpath(sys.argv[0]))
configfile = torspath + os.path.sep + 'configfile.txt'
##### Get arguments ##########
################################
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
description="RCDriver")
parser.add_argument('-i','--inputfile', type=str, default='input.dat')
parser.add_argument('-o','--outputfile', type=str, default='')
parser.add_argument('-c','--configfile', type=str, default=configfile)
inputs = parser.parse_args()
inputfile = inputs.inputfile
configfile = inputs.configfile
outputfile = inputs.outputfile
main(inputfile, outputfile, configfile)