def check_hrs(n, typ): """ Checks MC geoms to make sure they are the same inchii as the starting species """ import sys msg = 'Checking me_files/{1}{0}_hr.me'.format(str(n), typ) filename = 'data/' + typ + str(n) + '.dat' nrotors = 0 md = False if io.check_file(filename): data = io.read_file(filename) tmp = data.split('nhind') if len(tmp) > 2: nrotors = tmp[1].split('\n')[1] if len(tmp) > 3: md = True data = '' filename = 'me_files/' + typ + str(n) + '_hr.me' if io.check_file(filename): data = io.read_file(filename) else: msg = '\nNo hr me_file found' log.error(msg) return if md: if 'MultiRotor' in data: msg = '\nMDTau successfully completed' log.info(msg) else: msg = '\nMD scan incomplete' log.error(msg) filename = 'me_files/' + typ + str(n) + '_1dhr.me' if io.check_file(filename): data = io.read_file(filename) else: msg += '\nNo 1dhr me_file found' log.error(msg) return data = data.split('Rotor') ncomplete = len(data) - 1 msg = '\n{0} out of {1} rotors successfully scanned'.format( str(ncomplete), nrotors) if int(nrotors) == ncomplete: msg = '\n1DTau has completed successfully' else: msg = '\nScan incomplete' log.error(msg) log.info(msg) return
def parse_thermo(self, n, species, d): printstr = '\n=====================\n '+species+'\n=====================\n' optprog, optmethod, optbasis = self.optlevel.split('/') if self.enlevel == 'optlevel': prog = optprog method = optmethod basis = optbasis else: prog, method, basis = self.enlevel.split('/') d[ 'prog'] = prog d['method'] = method d[ 'basis'] = basis if self.args.anharm != 'false': anpfr = ', '.join('%4.4f' % freq for freq in self.anfreqs[n-1]) pxmat =('\n\t'.join(['\t'.join(['%3.3f'%item for item in row]) for row in self.anxmat[n-1]])) printstr += '\nAnharmonic Frequencies (cm-1):\t' + anpfr printstr += '\nX matrix:\n\t' + pxmat #+ anxmat[i-1] d['panharm'] = anpfr d[ 'pxmat'] = pxmat printstr += '\nHeat of formation( 0K): {0:.2f} kcal / {1:.2f} kJ\n'.format(self.dH0[n-1], self.dH0[n-1]/.00038088/ 627.503) printstr += 'Heat of formation(298K): {0:.2f} kcal / {1:.2f} kJ\n'.format(float(self.dH298[n-1]), float(self.dH298[n-1])/.00038088/ 627.503) d[ 'dH0K'] = self.dH0 d[ 'dH298K'] = self.dH298 if self.args.store: database = self.args.database if self.args.anharm != 'false': anprog, anmethod, anbasis = anlevel.split('/') io.db_store_sp_prop(anpfr, species, 'panhrm', database, anprog, anmethod, anbasis, optprog, optmethod, optbasis) io.db_store_sp_prop(pxmat, species, 'pxmat', database, anprog, anmethod, anbasis, optprog, optmethod, optbasis) if not io.check_file(io.db_sp_path(prog, method, basis, database, species, optprog, optmethod, optbasis) + '/' + species + '.hf298k'): io.db_store_sp_prop('Energy (kcal)\tBasis\n----------------------------------\n',species,'hf298k',database, prog,method,basis, optprog, optmethod, optbasis) if len(self.hfbases) >= n+1: io.db_append_sp_prop(str(self.dH298[n-1]) + '\t' + ', '.join(self.hfbases[n]) + '\n', species, 'hf298k',database, prog,method,basis, optprog, optmethod, optbasis) return printstr, d
def extract_mess(filename): """ Extracts necessary EStokTP output for MESS """ lines = '' if io.check_file(filename): lines = io.read_file(filename) if lines == '': log.error(filename + ' is empty, check estoktp.log') return lines
def get_results(self): msg = printheader() d = {} for i,reac in enumerate(self.args.reacs, start=1): lines = '' if io.check_file('geoms/reac' + str(i) + '_l1.log'): lines = io.read_file('geoms/reac' + str(i) + '_l1.log') lines2 = '' if io.check_file('me_files/reac' + str(i) + '_fr.me'): lines2 = io.read_file('me_files/reac' + str(i) + '_fr.me') if lines: printstr, d[reac] = self.parse(i, reac, lines, lines2) msg += printstr else: log.warning('No geom for ' + reac + ' in geoms/reac' + str(i) + '_l1.log') for j,prod in enumerate(self.args.prods, start=1): lines = '' if io.check_file('geoms/prod' + str(i) + '_l1.log'): lines = io.read_file('geoms/prod' + str(j) + '_l1.log') lines2 = '' if io.check_file('me_files/reac' + str(j) + '_fr.me'): lines2 = io.read_file('me_files/prod' + str(j) + '_fr.me') if lines: printstr, d[prod] = self.parse(i+j-1, prod, lines, lines2) msg += printstr else: log.warning('No geom for ' + prod + ' in geoms/prod' + str(j) + '_l1.log') #if args.nTS > 0: # lines = io.read_file('geoms/tsgta_l1.log') # printstr += ts_parse(0,lines) # if args.nTS > 1: # lines = io.read_file('geoms/wellr_l1.log') # printstr += ts_parse(1,lines) # if args.nTS > 2: # lines = io.read_file('geoms/wellp_l1.log') # printstr += ts_parse(2,lines) log.info(msg) self.d = d return
def me_file_abs_path(): """ Replaces relative path in mdhr file with absolute path """ if io.check_file('me_files/reac1_hr.me'): lines = io.read_file('me_files/reac1_hr.me') if "PotentialEnergySurface[kcal/mol]" in lines: before, after = lines.split("PotentialEnergySurface[kcal/mol]") after = after.split('\n') after[0] = after[0].replace('./', io.pwd() + '/') lines = before + "PotentialEnergySurface[kcal/mol]" + '\n'.join( after) io.write_file(lines, 'me_files/reac1_hr.me') return
def get_hlen(self): hlen = [] msg = '' for i in range(len(self.args.reacs)): if io.check_file('me_files/reac'+str(i+1) + '_en.me'): hlen.append(float(io.read_file('me_files/reac'+str(i+1) + '_en.me'))) for meth in self.args.meths: if 'hlevel' in meth: self.enlevel = '{}/{}'.format(meth[1],meth[2]) else: msg += 'No energy found for reac{:g}\n'.format(i+1) for i in range(len(self.args.prods)): if io.check_file('me_files/prod'+str(i+1) + '_en.me'): hlen.append(float(io.read_file('me_files/prod'+str(i+1) + '_en.me'))) else: msg += 'No energy found for prod{:g}\n'.format(i+1) if self.args.reactype: if io.check_file('me_files/ts_en.me'): hlen.append(float(io.read_file('me_files/ts_en.me'))) else: msg += 'No energy found for ts\n' if self.args.wellr and self.args.wellr.lower() != 'false': if io.check_file('me_files/wellr_en.me'): hlen.append(float(io.read_file('me_files/wellr_en.me'))) else: msg += 'No energy found for wellr\n' if self.args.wellp and self.args.wellp.lower() != 'false': if io.check_file('me_files/wellp_en.me'): hlen.append(float(io.read_file('me_files/wellp_en.me'))) else: msg += 'No energy found for wellp\n' log.warning(msg) self.hlen = hlen return hlen
def get_anharm(rorp, i, natom, node, anlevel, anovrwrt, species, optlevel, paths=''): """ Runs the anharm module to project out torsional modes from xmatrix and find the updated vpt2 frequencies """ opts = {} species = species.split('_m')[0] opts['smiles'] = species opts['node'] = node opts['theory'] = anlevel opts['optlevel'] = optlevel opts['anlevel'] = anlevel opts['natoms'] = natom if 'ts' in rorp: opts['logfile'] = 'geoms/' + 'tsgta_l1.log' opts['freqfile'] = 'me_files/ts_fr.me' opts['unprojfreq'] = 'me_files/ts_unpfr.me' else: opts['logfile'] = 'geoms/' + rorp + i + '_l1.log' opts['freqfile'] = 'me_files/' + rorp + i + '_fr.me' opts['unprojfreq'] = 'me_files/' + rorp + i + '_unpfr.me' if io.check_file(ob.get_smiles_filename(species) + 'anharm.log') and not anovrwrt.lower() == 'true': opts['anharmlog'] = ob.get_smiles_filename(species) + 'anharm' opts['writegauss'] = 'false' opts['rungauss'] = 'false' else: opts['writegauss'] = 'true' opts['rungauss'] = 'true' opts['anharmlog'] = ob.get_smiles_filename(species) + 'anharm' return anharm.main(opts)
def check_geoms(name, nsamps): """ Checks MC geoms to make sure they are the same inchii as the starting species """ import sys msg = 'Checking level0 geometries' log.debug(msg) n = 2 filename = 'geoms/' + name + '_' + '1'.zfill(n) + '.xyz' lowfilename = filename coords = io.read_file(filename) lowcoords = coords mol = ob.get_mol(coords) inchi = ob.get_inchi_key(mol) energy = float(coords.split('\n')[1]) for i in range(2, int(nsamps) + 1): filename = 'geoms/' + name + '_' + '{}'.format(i).zfill(n) + '.xyz' log.info(filename) if io.check_file(filename): coords = io.read_file(filename) mol = ob.get_mol(coords) if inchi == ob.get_inchi_key(mol): if float(coords.split('\n')[1]) < energy: energy = float(coords.split('\n')[1]) log.info('Lower energy of {:.2f} found in {}'.format( energy, filename)) lowcoords = coords lowfilename = filename else: log.info( 'Connectivity change after torsional optimization. (InChI mismatch) in {}.' .format(filename)) io.cp(lowfilename, 'torsopt.xyz') #io.write_file("\n".join(lowcoords.split("\n")),'geom.xyz') io.write_file("\n".join(lowcoords.split("\n")[2:]), 'geom.xyz') msg = '\nMonte Carlo sampling successfully found geom.xyz!\n' log.info(msg) return lowfilename
def run(args, paths, d={}): """ Runs heatform, partition_function, thermp, pac99, and write chemkin file """ import shutil import re reacs = args.reacs prods = args.prods anharm = args.anharm anovrwrt = args.anovrwrt node = args.nodes[0] meths = args.meths hfbasis = args.hfbasis qtchf = args.qtchf enlevel = args.enlevel hlen = args.hlen hfbases = [] speciess, speclist, anfreqs, anxmat = build_pfinput(args, d) dH0 = [] dH298 = [] anharmbool = False deltaH = 0 if anharm.lower() != 'false': anharmbool = True for i, species in enumerate(speciess): if len(species.split('_m')) > 1: species, mult = species.split('_m')[0], species.split('_m')[1] if qtchf[0].lower() not in ['false', 'auto']: if len(qtchf) >= i: deltaH = float(qtchf[i]) hfbasis = ['N/A'] hfbases.append(hfbasis) else: logfile = 'geoms/' + speclist[i] + '_l1.log' if speclist[i] == 'ts': logfile = 'geoms/' + speclist[i] + 'gta_l1.log' if io.check_file(logfile): lines = io.read_file(logfile) energy = pa.energy(lines)[1] zpve = pa.zpve(lines) printE = '{}- E: {:5g} pulled from: {}'.format( species, energy, logfile) printzpve = '{}- zpve: {:5g} pulled from: {}'.format( species, zpve, logfile) if enlevel != 'optlevel': energy = hlen[i] printE = '{}- E: {:5g} pulled from: {}'.format( species, energy, 'me_files/' + speclist[i] + '_en.me') if io.check_file('me_files/' + speclist[i] + '_zpe.me'): zpve = float( io.read_file('me_files/' + speclist[i] + '_zpe.me')) printzpve = '{}- ZPVE: {:5g} pulled from: {}'.format( species, zpve, 'me_files/' + speclist[i] + '_zpe.me') if zpve: energy = energy + zpve log.info(printE + '\n' + printzpve) deltaH, hfbasis = hf.main(species, logfile, E=energy, basis=hfbasis, anharm=anharmbool, enlevel=enlevel) hfbases.append(hfbasis) else: deltaH = 0.00 dH0.append(deltaH) if not speclist[i] == 'ts': log.debug('Running mess') tc.run_pf('messpf', species + '.pf') log.info('Completed') log.debug('Generating thermp input.\n') log.info('Completed') stoich = ob.get_formula(ob.get_mol(species)) inp = tc.get_thermp_input(stoich, deltaH) log.debug('Running thermp.\n') if io.check_file(species + '.pf.dat'): os.rename(species + '.pf.dat', 'pf.dat') else: log.error('No pf.dat produced, Restart at: 7!') return [], [], [], [], [] tc.run_thermp(inp, 'thermp.dat', 'pf.dat', 'thermp') lines = io.read_file('thermp.out') log.info('Completed') deltaH298 = ' h298 final\s*([\d,\-,\.]*)' deltaH298 = re.findall(deltaH298, lines)[-1] dH298.append(deltaH298) log.debug('Running pac99.\n') shutil.copyfile('/home/elliott/Packages/therm/new.groups', './new.groups') shutil.copyfile(stoich + '.i97', species + '.i97') tc.run_pac99(species, 'pac99') c97file = species + '.c97' if io.check_file(c97file): c97text = io.read_file(c97file) las, has, msg = tc.get_coefficients(c97text) log.info('Completed') else: log.error('No {} produced'.format(c97file)) chemkinfile = stoich + '.ckin' log.debug('Writing chemkin file {0}.\n'.format(chemkinfile)) method = meths[-1][2] chemininput = tc.write_chemkin_file(species, method, deltaH, float(deltaH298), stoich, 0, las, has, chemkinfile) log.info('Completed') return dH0, dH298, hfbases, anfreqs, anxmat
def run_zero(args, paths, ists=False, restartts=False): stoichs, symnums = build_files(args, paths, ists, len(args.nodes), restartts) successful = True if not 'd' in args.nodes[0]: if len(args.nodes) > 1: import time for i, node in enumerate(args.nodes): if not ists: io.rmrf(node) io.mkdir(node) io.cd(node) shutil.copytree('../data', 'data') else: io.cd(node) shutil.copy('../data/estoktp.dat', 'data/estoktp.dat') for i in range(len(args.reacs)): filename = 'output/reac' + str(i + 1) + '_opt.out' if io.check_file('../' + filename): shutil.copy('../' + filename, filename) time.sleep(5) execute(paths, node, '&') io.cd('..') running = True outlength = {} for node in args.nodes: outlength[node] = 0 while (running): running = False for node in args.nodes: filename = node + '/geom.log' if not io.check_file(filename): running = True #log.debug( 'waiting on node {}'.format(node)) else: lines = io.read_file(filename) newlength = len(lines) if 'termination' in lines and newlength == outlength[ node]: pass else: running = True outlength[node] = newlength #log.debug( 'waiting on node {}'.format(node)) time.sleep(30) log.info('Jobs Completed') io.mkdir('geoms') else: execute(paths, args.nodes[0]) j, k = gather_mcgeoms(args.nodes) for i in range(len(args.reacs)): filename = check_geoms('reac' + str(i + 1), j[i]) filename = filename.split('/')[1].split( '_')[0] + '_opt_' + filename.split('_')[1] filename = 'output/' + filename.replace('.xyz', '.out') shutil.copy(filename, 'output/reac' + str(i + 1) + '_opt.out') for i in range(len(args.prods)): filename = check_geoms('prod' + str(i + 1), j[i + 2]) filename = filename.split('/')[1].split( '_')[0] + '_opt_' + filename.split('_')[1] filename = 'output/' + filename.replace('.xyz', '.out') shutil.copy(filename, 'output/prod' + str(i + 1) + '_opt.out') if ists: if not io.check_file('geoms/ts_01.xyz'): successful = False if io.check_file('output/ts_opt_01.out'): shutil.copy('output/ts_opt_01.out', 'output/ts_opt.out') # filename = filename.split('/')[1].split('_')[0] + '_opt_' + filename.split('_')[1] # filename = 'output/' + filename.replace('.xyz','.out') # shutil.copy(filename, 'output/ts_opt.out') # if args.wellp and args.wellp.lower() != 'false' and 'find' not in args.wellp.lower(): # filename = check_geoms(paths['qtc'], 'wellp', j[6]) # filename = filename.split('/')[1].split('_')[0] + '_opt_' + filename.split('_')[1] # filename = 'output/' + filename.replace('.xyz','.out') # shutil.copy(filename, 'output/wellp_opt.out') # if args.wellr and args.wellr.lower() != 'false' and 'find' not in args.wellr.lower(): # filename = check_geoms(paths['qtc'], 'wellr', j[5]) # filename = filename.split('/')[1].split('_')[0] + '_opt_' + filename.split('_')[1] # filename = 'output/' + filename.replace('.xyz','.out') # shutil.copy(filename, 'output/wellr_opt.out') return successful
def build_files(args, paths, ists=False, nodes=1, restartts=False): """ Runs the build functions for reacn.dat, prodn.dat, theory.dat, and estoktp.dat Requirements: QTC, Openbabel, Pybel (OR prepared cartesian coordinate files) and x2z """ import sys build_subdirs() os.chdir('./data') stoichs = [] symnums = [] mdtype = args.mdtype if not 'MdTau' in args.jobs: mdtype = '' #Create Read, Prod, and TS objects from parameters params = (args.nsamps, args.abcd, nodes, args.interval, args.nsteps, args.XYZ, args.xyzstart, mdtype) Reac = build.MOL(params, 'reac', args.reactype) Prod = build.MOL(params, 'prod') params = (args.nsamps, args.abcd, nodes, args.interval, args.nsteps, args.XYZ, args.xyzstart, mdtype) TS = build.MOL(params, 'ts', args.reactype) reacs = args.reacs prods = args.prods key = set_keys(args.reactype) i, j, k = 0, 0, 0 TSprops = [0, 0, [], [], [], '', 0] #charge, spin, angles, atoms, sort, bond, babs foundlist = [] #Build reacn.dat for i, reac in enumerate(reacs, start=1): msg = 'Building reac{:g}.dat'.format(i) log.debug(msg) args.reacs, angles, atoms, args.jobs, foundlist, stoichs, symnums = build_mol_dat( Reac, reacs, i, stoichs, symnums, args.jobs, foundlist, args.select[i - 1], mdtype) TSprops = prep_reacs4TS(Reac, reac, i, key, angles, atoms, Reac.sort, TSprops, args.reactype, paths) nsamps = Reac.nsamps msg = 'Completed' log.info(msg) #Build prodn.dat for j, prod in enumerate(prods, start=1): msg = 'Building prod{:g}.dat'.format(j) log.debug(msg) args.prods, angles, atoms, args.jobs, foundlist, stoichs, symnums = build_mol_dat( Prod, prods, j, stoichs, symnums, args.jobs, foundlist, args.select[i + j - 1], mdtype) msg = 'Completed' log.info(msg) #Build TS, wellr, and wellp.dat tstype = ['ts', 'wellr', 'wellp'] tss = ['false', args.wellr.lower(), args.wellp.lower()] if args.reactype: tss[0] = 'true' TS.ijk = Reac.ijk TS.sort = TSprops[4] TS.bond = TSprops[5] TS.babs = TSprops[6] for k in range(3): if tss[k] and tss[k] != 'false': if k == 1 and 'true' in args.wellr.lower(): if len(args.reacs) > 1: spin = 0 reac1 = args.reacs[0].split('_m') if len(reac1) > 1: spin += (float(reac1[1]) - 1) / 2 reac2 = args.reacs[1].split('_m') if len(reac2) > 1: spin += (float(reac2[1]) - 1) / 2 else: spin = 0 reac3 = reac1[0] + '.' + reac2[0] if spin: reac3 += '_m' + str(int(2 * spin + 1)) log.info('Building {} '.format(reac3)) angles, atoms = build_well_dat(Reac, reac3, 3, args.jobs, restartts) else: log.info( 'Two reactants are required when finding a reactant well' ) elif k == 2 and (args.reactype.lower() == 'addition_well' or args.reactype.lower() == 'isomerization_well'): if io.check_file('prod1.dat'): msg = 'moving prod1.dat to wellp.dat for {} reaction'.format( args.reactype.lower()) log.info(msg) io.mv('prod1.dat', 'wellp.dat') j = 0 args.prods = [] msg = 'Completed' log.info(msg) elif k == 2 and 'true' in args.wellp.lower(): if len(args.prods) > 1: spin = 0 prod1 = args.prods[0].split('_m') if len(prod1) > 1: spin += (float(prod1[1]) - 1) / 2 prod2 = args.prods[1].split('_m') if len(prod2) > 1: spin += (float(prod2[1]) - 1) / 2 else: spin = 0 prod3 = prod1[0] + '.' + prod2[0] if spin: prod3 += '_m' + str(int(2 * spin + 1)) log.info('Building {} '.format(prod3)) angles, atoms = build_well_dat(Prod, prod3, 4, args.jobs, restartts) else: log.info( 'Two products are required when finding a product well' ) else: msg = 'Building ' + tstype[k] + '.dat' log.debug(msg) TS.charge = TSprops[0] TS.mult = int(2. * TSprops[1] + 1) TS.symnum = ' 1' if k == 0: if 'geomdir' in args.XYZ and io.check_file( '../geomdir/ts.xyz'): angles, atoms = build_well_dat(TS, args.reactype, 'ts', args.jobs, restartts) else: zmatstring = TS.build(tstype[k], args.reactype, args.jobs, False, TSprops[2], TSprops[3], restartts) zmat = tstype[k] + '.dat' io.write_file(zmatstring, zmat) else: params = ('1', args.abcd, nodes, args.interval, args.nsteps, 'False', 'start', 'MdTau' in args.jobs) TS = build.MOL(params, 'ts') TS.charge = TSprops[0] TS.mult = int(2. * TSprops[1] + 1) TS.symnum = ' 1' zmatstring = TS.build(tstype[k], args.reactype, args.jobs, False, TSprops[2]) zmat = tstype[k] + '.dat' io.write_file(zmatstring, zmat) msg = 'Completed' log.info(msg) mol = reac[0] #Builds me_head.dat if args.reactype: msg = 'Building me_head.dat' log.debug(msg) if args.mehead: if io.check_file('../' + args.mehead): headstring = io.read_file('../' + args.mehead) elif io.check_file(args.me_head): headstring = io.read_file(args.mehead) else: headstring = build.build_mehead() else: headstring = build.build_mehead() io.write_file(headstring, 'me_head.dat') msg = 'Completed' log.info(msg) #Builds theory.dat msg = 'Building theory.dat' log.debug(msg) theostring = build.build_theory(args.meths, tss, args.zedoptions, args.oneoptions, args.adiabatic) io.write_file(theostring, 'theory.dat') msg = 'Completed' log.info(msg) #Builds estoktp.dat to restart at any step msg = 'Building estoktp.dat' log.debug(msg) jobs = update_jobs(args.jobs, args.restart) params = (stoichs, args.reactype, args.coresh, args.coresl, args.meml, args.memh, args.esoptions) eststring = build.build_estoktp(params, jobs, i, j, tss, args.xyzstart, foundlist, ists) io.write_file(eststring, 'estoktp.dat') msg = 'Completed' log.info(msg) os.chdir('..') return stoichs, symnums
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