def add_zma_inp(): """ Add the zma input files using geo inputs """ cnf_managers = fs.iterate_managers(PFX, ['REACTION', 'THEORY', 'TRANSITION STATE'], 'CONFORMER') for cnf_fs in cnf_managers: if cnf_fs is not None: print() for locs in cnf_fs[-1].existing(): cnf_path = cnf_fs[-1].path(locs) # zma_fs = fs.manager(cnf_path, 'ZMATRIX') if cnf_fs[-1].file.geometry_input.exists(locs): inp_str = cnf_fs[-1].file.geometry_input.read(locs) print('FOUND INPUT') print(cnf_fs[-1].path(locs)) break for locs in cnf_fs[-1].existing(): cnf_path = cnf_fs[-1].path(locs) zma_fs = fs.manager(cnf_path, 'ZMATRIX') zma_path = zma_fs[-1].path([0]) if not zma_fs[-1].file.geometry_input.exists([0]): print('WRITING INPUT') print(zma_path) # zma_fs = fs.manager(cnf_path, 'ZMATRIX') zma_fs[-1].file.geometry_input.write(inp_str, [0]) else: print('INPUT GOOD') print(zma_path)
def add_ene_to_sp(): """ Add the energy files """ ini = ['SPECIES', 'THEORY'] # saddle = bool('REACTION' in ini) # managers = fs.iterate_managers( # PFX, ini, 'CONFORMER' # ) managers = fs.iterate_managers( PFX, ['SPECIES'], 'THEORY' ) for thy_fs in managers: if thy_fs is not None: for thy_locs in thy_fs[-1].existing(): thy_path = thy_fs[-1].path(thy_locs) print('thy', thy_path) cnf_fs = fs.conformer(thy_path) for cnf_locs in cnf_fs[-1].existing(): cnf_path = cnf_fs[-1].path(cnf_locs) print('cnf', cnf_path) sp_locs = fs.iterate_locators(cnf_path, ['SINGLE POINT']) sp_lst = list(sp_locs) print('thy_locs', thy_locs) print('sp_locs', sp_lst) if sp_lst: if (thy_locs,) not in sp_lst: if cnf_fs[-1].file.energy.exists(cnf_locs): print('ADD SP FILES') sp_fs = fs.single_point(cnf_path) sp_fs[-1].create(thy_locs) inp_str = cnf_fs[-1].file.geometry_input.read(cnf_locs) ene = cnf_fs[-1].file.energy.read(cnf_locs) sp_fs[-1].file.input.write(inp_str, thy_locs) sp_fs[-1].file.energy.write(ene, thy_locs) else: print('NEED SP FILE') else: print('ADD SP DIR AND FILES') sp_fs = fs.single_point(cnf_path) sp_fs[-1].create(thy_locs) inp_str = cnf_fs[-1].file.geometry_input.read(cnf_locs) ene = cnf_fs[-1].file.energy.read(cnf_locs) sp_fs[-1].file.input.write(inp_str, thy_locs) sp_fs[-1].file.energy.write(ene, thy_locs)
def example6(): """ Example 6: Iterate over CSCANS managers """ for scn_fs in fs.iterate_managers( PFX, ['REACTION', 'THEORY', 'TRANSITION STATE', 'CONFORMER', 'ZMATRIX'], 'CSCAN'): if scn_fs[0].exists(): print(scn_fs[0].path()) # Note that the following loops all do the same thing # Combined loop over scan coordinates, coordinate values, and # constraints for locs in scn_fs[-1].existing(): print(locs) print() # Loop over all directories for a given set of scan coordinates for root_locs in scn_fs[1].existing(): print('root: {}'.format(root_locs)) for locs in scn_fs[3].existing(root_locs): print(locs) print() # Loop over all directories for a given set of scan coordinates and # values for root_locs in scn_fs[2].existing(): print('root: {}'.format(root_locs)) for locs in scn_fs[3].existing(root_locs): print(locs) print() # Completely split out the loop for root_locs1 in scn_fs[1].existing(): print('root1: {}'.format(root_locs1)) for root_locs2 in scn_fs[2].existing(root_locs1): print('root2: {}'.format(root_locs2)) for locs in scn_fs[3].existing(root_locs2): print(locs) print()
def example5(): """ Example 5: Iterate over CONFORMER managers under SPECIES/THEORY paths """ for cnf_fs in fs.iterate_managers(PFX, ['SPECIES', 'THEORY'], 'CONFORMER'): print(cnf_fs[0].path()) # If it has an energy file, print the value for locs in cnf_fs[-1].existing(): path = cnf_fs[-1].path(locs) print(path) # ene = cnf_fs[-1].file.energy.read(locs) # print(ene) print()
def check_zma_for_trans(): """ Check zma for trans files """ zma_managers = fs.iterate_managers(PFX, ['REACTION', 'THEORY', 'TRANSITION STATE', 'CONFORMER'], 'ZMATRIX') BAD = 0 for zma_fs in zma_managers: zma_path = zma_fs[-1].path([0]) print(zma_path) if zma_fs is not None: if zma_fs[-1].file.transformation.exists([0]): print('GOOD') else: print('NO TRANS') BAD += 1 else: print('zma none') print() print('\nBAD CNT', BAD)
def add_ene_yaml(): """ Add the energy files """ ini = ['SPECIES', 'THEORY'] # saddle = bool('REACTION' in ini) # managers = fs.iterate_managers( # PFX, ini, 'CONFORMER' # ) managers = fs.iterate_managers( PFX, ['SPECIES', 'THEORY'], 'CONFORMER') for cnf_fs in managers: for cnf_locs in cnf_fs[-1].existing(): cnf_path = cnf_fs[-1].path(cnf_locs) sp_fs = fs.single_point(cnf_path) sp_locs = fs.iterate_locators(cnf_path, ['SINGLE POINT']) for locs in sp_locs: sp_fs = fs.single_point(cnf_path) if not sp_fs[-1].file.info.exists(locs): print('BAD')
def add_zma_trans(): """ Add the zma input files using geo inputs """ cnf_managers = fs.iterate_managers(PFX, ['REACTION', 'THEORY', 'TRANSITION STATE'], 'CONFORMER') for cnf_fs in cnf_managers: if cnf_fs is not None: print() gra = None for locs in cnf_fs[-1].existing(): cnf_path = cnf_fs[-1].path(locs) zma_fs = fs.manager(cnf_path, 'ZMATRIX') zma_path = zma_fs[-1].path([0]) # if zma_fs[-1].file.transformation.exists([0]): # tra = zma_fs[-1].file.transformation.read([0]) # print('FOUND TRA') # print(zma_path) # break if zma_fs[-1].file.reactant_graph.exists([0]): gra = zma_fs[-1].file.reactant_graph.read([0]) print('FOUND GRAPH') print(zma_fs[-1].path([0])) break print('---') print() for locs in cnf_fs[-1].existing(): cnf_path = cnf_fs[-1].path(locs) zma_fs = fs.manager(cnf_path, 'ZMATRIX') zma_path = zma_fs[-1].path([0]) # if not zma_fs[-1].file.transformation.exists([0]): if not zma_fs[-1].file.reactant_graph.exists([0]): print('WRITING GRA AT CONF') print(zma_path) zma_fs = fs.manager(cnf_path, 'ZMATRIX') # zma_fs[-1].file.transformation.write(tra, [0]) zma_fs[-1].file.reactant_graph.write(gra, [0]) else: print('GRA GOOD') print(zma_path)
if locs_lst: geos = [fs_[-1].file.geometry.read(locs) for locs in locs_lst] traj = [] for geo, locs in zip(geos, locs_lst): comment = '{}'.format(locs[0]) traj.append((comment, geo)) traj_path = fs_[0].file.trajectory.path() print("Updating trajectory file at {}".format(traj_path)) fs_[0].file.trajectory.write(traj) # First, write them in the CONFORMER layer for cnf_fs in itertools.chain( fs.iterate_managers(SAVE_PFX, ['SPECIES', 'THEORY'], 'CONFORMER'), fs.iterate_managers(SAVE_PFX, ['REACTION', 'THEORY', 'TRANSITION STATE'], 'CONFORMER')): write_sorted_trajectory_file(cnf_fs) # Then write them in the SYMMETRY layer for sym_fs in itertools.chain( fs.iterate_managers(SAVE_PFX, ['SPECIES', 'THEORY', 'CONFORMER'], 'SYMMETRY'), fs.iterate_managers( SAVE_PFX, ['REACTION', 'THEORY', 'TRANSITION STATE', 'CONFORMER'], 'SYMMETRY')): write_trajectory_file(sym_fs)
# zma = zma_df.read(cnf_locs) # # zma_fs = fs.manager(cnf_path, 'ZMATRIX') # # zma_fs[-1].file.zmatrix.write(zma, [0]) # # zma_path = zma_fs[-1].path([0]) # # # # Now that we've written the z-matrix to the new location, we can # # # remove the old one # # zma_df.removable = True # # zma_df.remove(cnf_locs) # Lastly, write the zmatrix files for the z-matrix guess for zma_fs in itertools.chain( fs.iterate_managers(SAVE_PFX, ['REACTION', 'THEORY'], 'ZMATRIX')): if zma_fs[-1].exists([0]): path = zma_fs[-1].path([0]) print(path) scan_fs = fs.manager(path, 'SCAN') scan_locs_lst = sorted(scan_fs[-1].existing()) if scan_locs_lst: scan_locs = scan_locs_lst[0] scan_path = scan_fs[-1].path(scan_locs) print(scan_locs) zma = scan_fs[-1].file.zmatrix.read(scan_locs)
def write_freqs(): """ write the harm freqs using ProjRot """ # Build tmp dir to run ProjRot prefix = tempfile.mkdtemp() print(prefix) start_path = os.getcwd() # ini = ['REACTION', 'THEORY', 'TRANSITION STATE'] ini = ['SPECIES', 'THEORY'] saddle = bool('REACTION' in ini) managers = fs.iterate_managers( PFX, ini, 'CONFORMER' ) bad_path = [] for cnf_fs in managers: # print(cnf_fs[-1].existing()) for locs in cnf_fs[-1].existing(): cnf_path = cnf_fs[-1].path(locs) print(cnf_path) if cnf_fs[-1].file.hessian.exists(locs): print('RUNNING HESS') # Read the info geom = cnf_fs[-1].file.geometry.read(locs) # grad = cnf_fs[-1].file.gradient.read(locs) grad = [] hess = cnf_fs[-1].file.hessian.read(locs) # Write the ProjRot input file inp_str = projrot_io.writer.rpht_input( [geom], [grad], [hess], rotors_str='') in_path = os.path.join(prefix, 'RPHt_input_data.dat') with open(in_path, 'w') as proj_file: proj_file.write(inp_str) os.chdir(prefix) subprocess.check_call(['RPHt.exe']) os.chdir(start_path) # Read the harmonic frequencies out_path = os.path.join(prefix, 'RTproj_freq.dat') with open(out_path, 'r') as proj_file: out_str = proj_file.read() freqs, imag = projrot_io.reader.rpht_output( out_str) # Combine freqs if saddle: if len(imag) == 1: wfreqs = freqs + [-1.0*x for x in imag] else: wfreqs = [] bad_path.append(cnf_path) print('bad_freqs') print(freqs) print(imag) else: if len(imag) == 0: wfreqs = freqs else: wfreqs = [] bad_path.append(cnf_path) print('bad_freqs') print(freqs) print(imag) # Write the freqs if wfreqs: print('FREQS GOOD') print(wfreqs) cnf_fs[-1].file.harmonic_frequencies.write(sorted(wfreqs), locs)
""" demonstrates use of the safemode setting """ import autofile from autofile import fs autofile.turn_off_safemode() PFX = '/lcrc/project/PACC/AutoMech/data/save/' print(autofile.safemode_is_on()) for zma_fs in fs.iterate_managers( PFX, ['REACTION', 'THEORY', 'TRANSITION STATE', 'CONFORMER'], 'ZMATRIX'): print(zma_fs[0].path())
rct_smis = list((automol.inchi.smiles(ich) for ich in rct_ichs)) prd_smis = list((automol.inchi.smiles(ich) for ich in prd_ichs)) # print('ichs') # print(rct_ichs) # print(prd_ichs) # print('smi') # print(list((automol.inchi.smiles(ich) for ich in rct_ichs))) # print(list((automol.inchi.smiles(ich) for ich in prd_ichs))) # Get one z-matrix for this reaction, if there is one rxn_path = RXN_FS[-1].path(rxn_locs) zma_fs = next( fs.iterate_managers(rxn_path, ['THEORY', 'TRANSITION STATE', 'CONFORMER'], 'ZMATRIX'), None) if zma_fs is not None: zma_path = zma_fs[-1].path([0]) # print([rct_ichs, prd_ichs]) print(zma_path) if zma_fs[-1].file.zmatrix.exists([0]): # Read out the z-matrix ts_zma = zma_fs[-1].file.zmatrix.read([0]) # Note that the keys in rct_gras and prd_gras at this point are # arbitrary. The following work determines the transformation and # the reactant graph *in terms of the z-matrix keys*. # Attempt to determine the transformation in the forward direction
""" A script to wipe out all cscan directories """ import itertools from autofile import fs RUN_PFX = '/lcrc/project/PACC/AutoMech/data/run/' SAVE_PFX = '/lcrc/project/PACC/AutoMech/data/save/' for sca_fs in itertools.chain( fs.iterate_managers(RUN_PFX, ['SPECIES', 'THEORY', 'CONFORMER', 'ZMATRIX'], 'CSCAN'), fs.iterate_managers(SAVE_PFX, ['SPECIES', 'THEORY', 'CONFORMER', 'ZMATRIX'], 'CSCAN'), fs.iterate_managers( RUN_PFX, ['REACTION', 'THEORY', 'TRANSITION STATE', 'CONFORMER', 'ZMATRIX'], 'CSCAN'), fs.iterate_managers( SAVE_PFX, ['REACTION', 'THEORY', 'TRANSITION STATE', 'CONFORMER', 'ZMATRIX'], 'CSCAN')): if sca_fs[0].exists(): print(sca_fs[0].path()) sca_fs[0].removable = True sca_fs[0].remove() print('removing...')