def run_irc(zma, irc_job, coord_name, run_fs, ini_scn_save_fs, ts_info, mod_ini_thy_info, overwrite, opt_script_str, **opt_kwargs): """ Run the irc job """ # Maybe check for positive coords if not _irc_ran(ini_scn_save_fs, coord_name, irc_job): print('No IRC calculation in save filesystem') opt_success, _ = es_runner.read_job( job=irc_job, run_fs=run_fs, ) need_irc = bool(not opt_success) else: print('Found IRC directory at {}'.format(ini_scn_save_fs[1].path( [coord_name]))) need_irc = False if need_irc: print('Running IRC calculation') es_runner.run_job( job=irc_job, script_str=opt_script_str, run_fs=run_fs, geo=zma, spc_info=ts_info, thy_info=mod_ini_thy_info, overwrite=overwrite, **opt_kwargs, ) else: print('Skipping IRC calculation')
def execute_irc(zma, ts_info, mod_ini_thy_info, ini_method_dct, ini_scn_run_fs, ini_scn_save_fs, es_keyword_dct, directions=(elstruct.Job.IRCF, elstruct.Job.IRCR)): """ Run and save the IRC """ coord_name = 'IRC' overwrite = es_keyword_dct['overwrite'] retryfail = es_keyword_dct['retryfail'] # Set up run filesys run_fs = autofile.fs.run(ini_scn_run_fs[1].path([coord_name])) # Run and Read the IRC in the forward and reverse direction for direction in directions: script_str, kwargs = qchem_params(ini_method_dct, job=direction) run_irc(zma, direction, coord_name, run_fs, ini_scn_save_fs, ts_info, mod_ini_thy_info, overwrite, retryfail, script_str, **kwargs) success, _ = es_runner.read_job( job=direction, run_fs=run_fs, ) if success: save_irc(direction, coord_name, run_fs, ini_scn_save_fs, mod_ini_thy_info) return success
def save_irc(irc_job, coord_name, run_fs, ini_scn_save_fs, mod_ini_thy_info): """ Read IRC output and store data in filesystem """ opt_success, opt_ret = es_runner.read_job( job=irc_job, run_fs=run_fs, ) if opt_success is not None: # Read the IRC output file inf_obj, inp_str, out_str = opt_ret prog = inf_obj.prog geos, gras, hessians = elstruct.reader.irc_points(prog, out_str) coord_vals, enes = elstruct.reader.irc_path(prog, out_str) # Write the data for each geom along IRC to the filesystem save_path = ini_scn_save_fs[1].path([coord_name]) print(" - Saving...") print(" - Save path: {}".format(save_path)) locs_lst = [] for idx, val in enumerate(coord_vals): # Set locs idx; for reverse, ignore SadPt and flip idx to negative locs_idx = idx if irc_job == elstruct.Job.IRCR: if locs_idx == 0: continue # val *= -1 coord vals negative from elstruct fxn for g09 # Scale the coordinates so rounding to .2f number is non-zero locs = [coord_name, [val * 100.0]] locs_lst.append(locs) # Save files ini_scn_save_fs[-1].create(locs) ini_scn_save_fs[-1].file.energy.write(enes[idx], locs) ini_scn_save_fs[-1].file.geometry.write(geos[idx], locs) ini_scn_save_fs[-1].file.geometry_input.write(inp_str, locs) ini_scn_save_fs[-1].file.geometry_info.write(inf_obj, locs) if gras: ini_scn_save_fs[-1].file.gradient.write(gras[idx], locs) ini_scn_save_fs[-1].file.gradient_info.write(inf_obj, locs) if hessians: ini_scn_save_fs[-1].file.hessian.write(hessians[idx], locs) ini_scn_save_fs[-1].file.hessian_info.write(inf_obj, locs) scn_save_path = ini_scn_save_fs[-1].path(locs) sp_save_fs = autofile.fs.single_point(scn_save_path) sp_save_fs[-1].create(mod_ini_thy_info[1:4]) sp_save_fs[-1].file.input.write(inp_str, mod_ini_thy_info[1:4]) sp_save_fs[-1].file.info.write(inf_obj, mod_ini_thy_info[1:4]) sp_save_fs[-1].file.energy.write(enes[idx], mod_ini_thy_info[1:4]) # Build the trajectory file if locs_lst: es_runner.write_traj(coord_name, ini_scn_save_fs, mod_ini_thy_info, locs_lst)
def structure(run_fs, save_fs, locs, job, mod_thy_info, zma_locs=(0, ), in_zma_fs=False, cart_to_zma=False): """ Save a geometry and associated information from some electronic structure routine into the filesystem. """ success, ret = es_runner.read_job(job=job, run_fs=run_fs) if success: # Get the geo, zma, and ene based on job type ene, zma, geo = _read(run_fs, job, cart_to_zma=cart_to_zma) # Obtain inf obj and inp str to write in filesys inf_obj, inp_str, _ = ret # Set and print the save path information save_path = save_fs[-1].path(locs) print(" - Saving...") print(" - Save path: {}".format(save_path)) # Save the geometry information save_fs[-1].create(locs) save_fs[-1].file.geometry_info.write(inf_obj, locs) save_fs[-1].file.geometry_input.write(inp_str, locs) save_fs[-1].file.geometry.write(geo, locs) save_fs[-1].file.energy.write(ene, locs) # Save zma information seperately, if required if not in_zma_fs: zma_save_fs = autofile.fs.zmatrix(save_path) zma_save_fs[-1].create(zma_locs) zma_save_fs[-1].file.geometry_info.write(inf_obj, zma_locs) zma_save_fs[-1].file.geometry_input.write(inp_str, zma_locs) zma_save_fs[-1].file.zmatrix.write(zma, zma_locs) elif zma: save_fs[-1].file.zmatrix.write(zma, locs) # Saving the energy to an SP filesys print(" - Saving energy...") sp_save_fs = autofile.fs.single_point(save_path) sp_save_fs[-1].create(mod_thy_info[1:4]) sp_save_fs[-1].file.input.write(inp_str, mod_thy_info[1:4]) sp_save_fs[-1].file.info.write(inf_obj, mod_thy_info[1:4]) sp_save_fs[-1].file.energy.write(ene, mod_thy_info[1:4]) saved = True else: saved = False return saved
def _read(run_fs, job, cart_to_zma=False): """ Read the output """ assert job in (elstruct.Job.OPTIMIZATION, elstruct.Job.ENERGY), ('Job not opt or energy') success, ret = es_runner.read_job(job=job, run_fs=run_fs) if ret and success: inf_obj, _, out_str = ret prog = inf_obj.prog method = inf_obj.method try: ene = elstruct.reader.energy(prog, method, out_str) except TypeError: ene = None print('No ENE') except AttributeError: ene = None print('No ENE') if job == elstruct.Job.OPTIMIZATION: # Read the optimized structs from the output file try: geo = elstruct.reader.opt_geometry(prog, out_str) except TypeError: geo = None print('No GEOM') # Read the optimized zma if cart_to_zma: zma = automol.geom.zmatrix(geo) elif 'psi' not in prog: try: zma = elstruct.reader.opt_zmatrix(prog, out_str) except TypeError: zma = None print('No ZMA') else: zma = None print('No ZMA') elif job == elstruct.Job.ENERGY: # Read the initial structs stored in the run filesys zma = run_fs[-1].file.zmatrix.read([job]) geo = run_fs[-1].file.geometry.read([job]) else: ene, zma, geo = None, None, None return ene, zma, geo
def _presamp_save(spc_info, cnf_run_fs, cnf_save_fs, thy_info, zrxn=None, rid=None): """ Loop over the RUN filesys and save conformers """ job = elstruct.Job.OPTIMIZATION if not cnf_run_fs[0].exists(): print(" - No conformers in RUN filesys to save.") else: print(" - Found conformers in RUN filesys to save.\n") for locs in cnf_run_fs[-1].existing(): cnf_run_path = cnf_run_fs[-1].path(locs) run_fs = autofile.fs.run(cnf_run_path) if run_fs[-1].file.info.exists([job]): inf_obj = run_fs[-1].file.info.read([job]) if inf_obj.status == autofile.schema.RunStatus.SUCCESS: print(f"\nReading from conformer run at {cnf_run_path}") # Read the electronic structure optimization job success, ret = es_runner.read_job(job=job, run_fs=run_fs) if success: if run_fs[-1].file.zmatrix.exists([job]): init_zma = run_fs[-1].file.zmatrix.read([job]) else: init_zma = None save_conformer(ret, cnf_run_fs, cnf_save_fs, locs, thy_info, zrxn=zrxn, orig_ich=spc_info[0], init_zma=init_zma) # Update the conformer trajectory file print('') filesys.mincnf.traj_sort(cnf_save_fs, thy_info, rid=rid)
def run_irc(zma, irc_job, coord_name, run_fs, ini_scn_save_fs, ts_info, mod_ini_thy_info, overwrite, retryfail, opt_script_str, **opt_kwargs): """ Run the irc job """ def _irc_ran(ini_scn_save_fs, coord_name, irc_job): """ See if coords are available """ coords = ini_scn_save_fs[-1].existing([coord_name]) if irc_job == elstruct.Job.IRCF: ran_coords = [coord[1][0] for coord in coords if coord[1][0] > 0.0] else: ran_coords = [coord[1][0] for coord in coords if coord[1][0] < 0.0] return bool(ran_coords) # Maybe check for positive coords if not _irc_ran(ini_scn_save_fs, coord_name, irc_job): print('No IRC calculation in save filesystem') opt_success, _ = es_runner.read_job( job=irc_job, run_fs=run_fs, ) need_irc = not opt_success else: print('Found IRC directory at ' f'{ini_scn_save_fs[1].path([coord_name])}') need_irc = False if need_irc: print('Running IRC calculation...') es_runner.run_job(job=irc_job, script_str=opt_script_str, run_fs=run_fs, geo=zma, spc_info=ts_info, thy_info=mod_ini_thy_info, overwrite=overwrite, retryfail=retryfail, **opt_kwargs)
def save_tau(tau_run_fs, tau_save_fs, mod_thy_info): """ save the tau dependent geometries that have been found so far """ # db_style = 'jsondb' db_style = 'directory' if db_style == 'jsondb': saved_locs = tau_save_fs[-1].json_existing() saved_geos = tau_save_fs[-1].json.geometry.read_all(saved_locs) elif db_style == 'directory': saved_geos = [tau_save_fs[-1].file.geometry.read(locs) for locs in tau_save_fs[-1].existing()] if not tau_run_fs[0].exists(): ioprinter.info_message("No tau geometries to save. Skipping...") else: if db_style == 'jsondb': save_info = [[], [], [], [], []] sp_save_info = [[], [], [], [], []] for locs in tau_run_fs[-1].existing(): run_path = tau_run_fs[-1].path(locs) run_fs = autofile.fs.run(run_path) save_path = tau_save_fs[-1].root.path() ioprinter.reading("tau run", run_path) success, ret = es_runner.read_job( job=elstruct.Job.OPTIMIZATION, run_fs=run_fs) if success: inf_obj, inp_str, out_str = ret prog = inf_obj.prog method = inf_obj.method ene = elstruct.reader.energy(prog, method, out_str) geo = elstruct.reader.opt_geometry(prog, out_str) if db_style == 'directory': ioprinter.save_geo(save_path) tau_save_fs[-1].create(locs) tau_save_fs[-1].file.geometry_info.write(inf_obj, locs) tau_save_fs[-1].file.geometry_input.write(inp_str, locs) tau_save_fs[-1].file.energy.write(ene, locs) tau_save_fs[-1].file.geometry.write(geo, locs) # Saving the energy to a SP filesystem save_path = tau_save_fs[-1].path(locs) ioprinter.save_energy(save_path) sp_save_fs = autofile.fs.single_point(save_path) sp_save_fs[-1].create(mod_thy_info[1:4]) sp_save_fs[-1].file.input.write(inp_str, mod_thy_info[1:4]) sp_save_fs[-1].file.info.write(inf_obj, mod_thy_info[1:4]) sp_save_fs[-1].file.energy.write(ene, mod_thy_info[1:4]) elif db_style == 'jsondb': # tau_save_fs[-1].json.geometry_info.write(inf_obj, locs) # tau_save_fs[-1].json.geometry_input.write(inp_str, locs) # tau_save_fs[-1].json.energy.write(ene, locs) # tau_save_fs[-1].json.geometry.write(geo, locs) ioprinter.info_message( " - Saving energy and geo of unique geometry...") save_info[0].append(locs) save_info[1].append(inf_obj) save_info[2].append(inp_str) save_info[3].append(ene) save_info[4].append(geo) sp_save_fs = autofile.fs.single_point( save_path, json_layer=locs) sp_save_info[0].append(sp_save_fs) sp_save_info[1].append(mod_thy_info[1:4]) sp_save_info[2].append(inp_str) sp_save_info[3].append(inf_obj) sp_save_info[4].append(ene) sp_save_fs[-1].json.input.write(inp_str, mod_thy_info[1:4]) sp_save_fs[-1].json.info.write(inf_obj, mod_thy_info[1:4]) sp_save_fs[-1].json.energy.write(ene, mod_thy_info[1:4]) saved_geos.append(geo) if db_style == 'jsondb': tau_save_fs[-1].json_create() tau_save_fs[-1].json.geometry_info.write_all( save_info[1], save_info[0]) tau_save_fs[-1].json.geometry_input.write_all( save_info[2], save_info[0]) tau_save_fs[-1].json.energy.write_all( save_info[3], save_info[0]) tau_save_fs[-1].json.geometry.write_all( save_info[4], save_info[0]) for i, sp_save_fs_i in enumerate(sp_save_info[0]): sp_save_fs_i[-1].json.input.write( sp_save_info[2][i], sp_save_info[1][i]) sp_save_fs_i[-1].json.info.write( sp_save_info[3][i], sp_save_info[1][i]) sp_save_fs_i[-1].json.energy.write( sp_save_info[4][i], sp_save_info[1][i]) # update the tau trajectory file filesys.mincnf.traj_sort(tau_save_fs, mod_thy_info)
def find_vdw(ts_name, spc_dct, thy_info, ini_thy_info, vdw_params, nsamp_par, run_prefix, save_prefix, kickoff_size, kickoff_backward, overwrite): """ Find van der Waals structures for all the pairs of species in a reaction list. Fxn takes two species, performs a (random?) rotation, sticks them together and optimizes the combined geometry. Supposed to use the wells filesystem? """ new_vdws = [] _, opt_script_str, _, opt_kwargs = qchem_params(*thy_info[:2]) mul = spc_dct[ts_name]['low_mul'] vdw_names_lst = [] if vdw_params[0]: vdw_names_lst.append([sorted(spc_dct[ts_name]['reacs']), mul, 'r']) if vdw_params[1]: vdw_names_lst.append([sorted(spc_dct[ts_name]['prods']), mul, 'p']) for names, ts_mul, label in vdw_names_lst: if len(names) < 2: ioprinter.info_message( 'Cannot find van der Waals well for unimolecular', 'reactant or product') ichs = list(map(lambda name: spc_dct[name]['inchi'], names)) chgs = list(map(lambda name: spc_dct[name]['chg'], names)) muls = list(map(lambda name: spc_dct[name]['mul'], names)) # theory prog = thy_info[0] method = thy_info[1] _, opt_script_str, _, opt_kwargs = es_runner.qchem_params(prog, method) geos = [(), ()] ntaudof = 0. for i, (nam, ich, chg, mul) in enumerate(zip(names, ichs, chgs, muls)): spc_info = [ich, chg, mul] orb_restr = filesys.inf.orbital_restriction(spc_info, ini_thy_info) ini_g = ini_thy_info[0:3] ini_g.append(orb_restr) orb_restr = filesys.inf.orbital_restriction(spc_info, thy_info) thy_info = thy_info[0:3] thy_info.append(orb_restr) spc_run_fs = autofile.fs.species(run_prefix) spc_run_fs[-1].create(spc_info) spc_run_path = spc_run_fs[-1].path(spc_info) spc_save_fs = autofile.fs.species(save_prefix) spc_save_fs[-1].create(spc_info) spc_save_path = spc_save_fs[-1].path(spc_info) thy_run_fs = autofile.fs.theory(spc_run_path) thy_run_fs[-1].create(thy_info[1:4]) thy_run_path = thy_run_fs[-1].path(thy_info[1:4]) thy_save_fs = autofile.fs.theory(spc_save_path) thy_save_fs[-1].create(thy_info[1:4]) thy_save_path = thy_save_fs[-1].path(thy_info[1:4]) run_fs = autofile.fs.run(thy_run_path) ini_thy_save_fs = autofile.fs.theory(spc_save_path) ini_thy_save_fs[-1].create(ini_thy_info[1:4]) cnf_run_fs = autofile.fs.conformer(thy_run_path) cnf_save_fs = autofile.fs.conformer(thy_save_path) geo = geom.reference_geometry(spc_dct[nam], thy_info, ini_thy_info, thy_run_fs, thy_save_fs, ini_thy_save_fs, cnf_run_fs, cnf_save_fs, run_fs, kickoff_size=kickoff_size, kickoff_backward=kickoff_backward, overwrite=overwrite) geos[i] = geo gra = automol.geom.graph(geo) ntaudof += len( automol.graph.rotational_bond_keys(gra, with_h_rotors=False)) nsamp = util.nsamp_init(nsamp_par, ntaudof) geo1, geo2 = geos geo1 = automol.geom.mass_centered(geo1) geo2 = automol.geom.mass_centered(geo2) min_ene = 0. for idx in range(int(nsamp)): ioprinter.info_message('Optimizing vdw geometry {}/{}'.format( idx + 1, nsamp)) angs1 = numpy.multiply(numpy.random.rand(3), [1 * numpy.pi, 2 * numpy.pi, 2 * numpy.pi]) angs2 = numpy.multiply(numpy.random.rand(3), [1 * numpy.pi, 2 * numpy.pi, 2 * numpy.pi]) angs12 = numpy.multiply(numpy.random.rand(2), [1 * numpy.pi, 2 * numpy.pi]) geo1 = automol.geom.euler_rotate(geo1, *angs1) geo2 = automol.geom.euler_rotate(geo2, *angs2) dist_cutoff = 3.0 * phycon.ANG2BOHR geo = automol.geom.join(geo1, geo2, dist_cutoff, *angs12) ioprinter.info_message("Species: {}".format('+'.join(names))) ioprinter.geometry(geo) # Set up the filesystem ich = automol.inchi.recalculate(automol.inchi.join(ichs)) chg = sum(chgs) mul = ts_mul spc_info = (ich, chg, mul) spc_run_fs = autofile.fs.species(run_prefix) spc_run_fs[-1].create(spc_info) spc_run_path = spc_run_fs[-1].path(spc_info) spc_save_fs = autofile.fs.species(save_prefix) spc_save_fs[-1].create(spc_info) spc_save_path = spc_save_fs[-1].path(spc_info) orb_restr = filesys.inf.orbital_restriction(spc_info, thy_info) thy_info = thy_info[0:3] thy_info.append(orb_restr) thy_run_fs = autofile.fs.theory(spc_run_path) thy_run_fs[-1].create(thy_info[1:4]) thy_run_path = thy_run_fs[-1].path(thy_info[1:4]) thy_save_fs = autofile.fs.theory(spc_save_path) thy_save_fs[-1].create(thy_info[1:4]) thy_save_path = thy_save_fs[-1].path(thy_info[1:4]) run_fs = autofile.fs.run(thy_run_path) # Generate reference geometry # Generate the z-matrix and sampling ranges es_runner.run_job( job=elstruct.Job.OPTIMIZATION, geo=geo, spc_info=spc_info, th_info=thy_info, run_fs=run_fs, script_str=opt_script_str, overwrite=overwrite, **opt_kwargs, ) # Save info for the initial geometry (from ichi or fsave dir) success, ret = es_runner.read_job(job=elstruct.Job.OPTIMIZATION, run_fs=run_fs) if success: ioprinter.save_reference(thy_save_path) inf_obj, inp_str, out_str = ret prog = inf_obj.prog method = inf_obj.method geo = elstruct.reader.opt_geometry(prog, out_str) ioprinter.geometry(geo) thy_save_fs[-1].file.geometry.write(geo, thy_info[1:4]) ene = elstruct.reader.energy(prog, method, out_str) if ene < min_ene: min_ene = ene ioprinter.debug_message('ene test in vdw', ene) thy_save_fs[-1].file.energy.write(ene, thy_info[1:4]) ioprinter.save_reference(thy_save_path) vdw_name = label + ts_name.replace('ts', 'vdw') spc_dct[vdw_name] = spc_dct[ts_name].copy() spc_dct[vdw_name]['inchi'] = ich spc_dct[vdw_name]['mul'] = mul spc_dct[vdw_name]['chg'] = chg spc_dct[vdw_name]['dist_info'][1] = dist_cutoff # Make a fake conformer cnf_save_fs = autofile.fs.conformer(thy_save_path) cnf_run_fs = autofile.fs.conformer(thy_run_path) cnf_save_fs[0].create() cnf_run_fs[0].create() tors_range_dct = {} cinf_obj = autofile.schema.info_objects.conformer[0]( 0, tors_range_dct) cinf_obj.nsamp = 1 cnf_save_fs[0].file.info.write(cinf_obj) locs_lst = cnf_save_fs[-1].existing() if not locs_lst: cid = autofile.schema.generate_new_conformer_id() locs = [cid] else: locs = locs_lst[0] cnf_save_fs[-1].create(locs) cnf_run_fs[-1].create(locs) cnf_save_fs[-1].file.geometry_info.write(inf_obj, locs) cnf_save_fs[-1].file.geometry_input.write(inp_str, locs) cnf_save_fs[-1].file.energy.write(ene, locs) cnf_save_fs[-1].file.geometry.write(geo, locs) if min_ene: new_vdws.append(vdw_name) return new_vdws