def run(pes_rlst, spc_rlst, trans_tsk_lst, spc_mod_dct, spc_dct, thy_dct, run_prefix, save_prefix): """ main driver for etransfer run """ # Print Header ioprinter.info_message('Calculating Transport:') ioprinter.runlst(('SPC', 0, 0), spc_rlst) # ---------------------------------------------------- # # PREPARE INFORMATION TO PASS TO TRANSPORTDRIVER TASKS # # ---------------------------------------------------- # spc_mods = list(spc_mod_dct.keys()) # hack spc_mod_dct_i = spc_mod_dct[spc_mods[0]] split_rlst = split_unstable_full(pes_rlst, spc_rlst, spc_dct, spc_mod_dct_i, save_prefix) spc_queue = parser.rlst.spc_queue(tuple(split_rlst.values())[0], 'SPC') # --------------------------------------- # # RUN THE REQUESTED TRANSPORTDRIVER TASKS # # --------------------------------------- # for tsk_lst in trans_tsk_lst: [_, tsk, etrans_keyword_dct] = tsk_lst run_tsk(tsk, spc_queue, spc_dct, thy_dct, etrans_keyword_dct, run_prefix, save_prefix)
def run(pes_rlst, spc_rlst, proc_tsk_lst, spc_dct, pes_mod_dct, spc_mod_dct, thy_dct, run_prefix, save_prefix): """ Central driver for all output tasks. :param pes_idx: index for the PES where the channel/spc belong to :type pes_idx: int :param rxn_lst: species and models for all reactions being run :type rxn_lst: list[dict[species, reacs, prods, model]] :param spc_dct: species information :type spc_dct: dict[spc_name: spc_information] :param es_tsk_lst: list of the electronic structure tasks :type es_tsk_lst: list[[obj, tsk, keyword_dict]] :param thy_dct: all of the theory information :type thy_dct: dict[] :param run_inp_dct: information from input section of run.dat :type run_inp_dct: dict[] """ # -------------------------------- # # RUN THE REQUESTED ESDRIVER TASKS # # -------------------------------- # run_rlst = parser.rlst.combine(pes_rlst, spc_rlst) for (fml, pes_idx, subpes_idx), run_lst in run_rlst.items(): # Print what is being run PESs that are being run ioprinter.runlst((fml, pes_idx, subpes_idx), run_lst) # Loop over Tasks for tsk_lst in proc_tsk_lst: # Unpack the options [obj, tsk, prnt_keyword_dct] = tsk_lst # Get the model from the task spc_mods, pes_mod = parser.models.extract_models(tsk) spc_mod_dct_i = spc_mod_dct[spc_mods[0]] pes_mod_dct_i = pes_mod_dct[pes_mod] # Build the queue of species based on user request if obj == 'spc': obj_queue = parser.rlst.spc_queue(run_lst, fml) for spc_name in obj_queue: run_tsk( tsk, spc_dct, spc_name, thy_dct, prnt_keyword_dct, pes_mod_dct_i, spc_mod_dct_i, run_prefix, save_prefix)
def run(pes_rlst, pes_grp_dct, ktp_tsk_lst, spc_dct, glob_dct, thy_dct, pes_mod_dct, spc_mod_dct, run_prefix, save_prefix, mdriver_path): """ Executes all kinetics tasks. :param pes_rlst: species from PESs to run :type pes_rlst: tuple(dict[str: dict]) :param spc_rlst: lst of species to run :type spc_rlst: tuple(dict[str: dict]) :param es_tsk_lst: list of the electronic structure tasks :type es_tsk_lst: tuple(tuple(str, str, dict)) :param spc_dct: species information :type spc_dct: dict[str:dict] :param glob_dct: global information for all species :type glob_dct: dict[str: dict] :param thy_dct: all of the theory information :type thy_dct: dict[str:dict] :param run_prefix: root-path to the run-filesystem :type run_prefix: str :param save_prefix: root-path to the save-filesystem :type save_prefix: str :param mdriver_path: path where mechdriver is running :type mdriver_path: str """ # ------------------------------------------------------------------ # # PREPARE GENERAL INFORMATION FOR ALL PES TO PASS TO KTPDRIVER TASKS # # ------------------------------------------------------------------ # write_rate_tsk = parser.run.extract_task('write_mess', ktp_tsk_lst) run_rate_tsk = parser.run.extract_task('run_mess', ktp_tsk_lst) run_fit_tsk = parser.run.extract_task('run_fits', ktp_tsk_lst) # Group the PESs into lists pes_grps_rlst = parser.rlst.pes_groups(pes_rlst, pes_grp_dct) # --------------------------------------- # # LOOP OVER ALL OF THE SUBPES in PES_RLST # # --------------------------------------- # for (pes_grp_rlst, pes_param_dct) in pes_grps_rlst: # print('WORKING ON PES GROUP NUM') # print(pes_grp_rlst) # Generate the paths needed for MESSRATE calculations rate_paths_dct = rate_paths(pes_grp_rlst, run_prefix) # Process info required ro run all of the PESs if write_rate_tsk is not None: proc_tsk = write_rate_tsk else: proc_tsk = run_fit_tsk spc_dct, all_rxn_lst, all_instab_chnls, label_dct = _process( proc_tsk, ktp_tsk_lst, pes_grp_rlst, spc_mod_dct, spc_dct, glob_dct, run_prefix, save_prefix) # ---------------------------------------- # # WRITE AND RUN TASK FOR EACH PES IN GROUP # # ---------------------------------------- # for pesgrp_num, (pes_inf, rxn_lst) in enumerate(pes_grp_rlst.items()): # Print PES Channels that are being run ioprinter.runlst(pes_inf, rxn_lst) # Write the MESS file if write_rate_tsk is not None: tsk_key_dct = write_rate_tsk[-1] ktp_tasks.write_messrate_task( pesgrp_num, pes_inf, all_rxn_lst[pesgrp_num], tsk_key_dct, pes_param_dct, spc_dct, thy_dct, pes_mod_dct, spc_mod_dct, all_instab_chnls[pesgrp_num], label_dct, rate_paths_dct, run_prefix, save_prefix) # Run mess to produce rates (urrently nothing from tsk lst used) if run_rate_tsk is not None: ktp_tasks.run_messrate_task(rate_paths_dct, pes_inf) # ---------------------------------------- # # FIT THE COMBINES RATES FOR ENTIRE GROUP # # ---------------------------------------- # # Fit rates to functional forms; write parameters to ChemKin file if run_fit_tsk is not None: tsk_key_dct = run_fit_tsk[-1] ktp_tasks.run_fits_task(pes_grp_rlst, pes_param_dct, rate_paths_dct, mdriver_path, label_dct, pes_mod_dct, spc_mod_dct, thy_dct, tsk_key_dct)
def run(pes_rlst, ktp_tsk_lst, spc_dct, glob_dct, thy_dct, pes_mod_dct, spc_mod_dct, run_prefix, save_prefix): """ main driver for generation of full set of rate constants on a single PES """ # --------------------------------------- # # LOOP OVER ALL OF THE SUBPES in PES_RLST # # --------------------------------------- # for pes_inf, rxn_lst in pes_rlst.items(): # ---------------------------------------------- # # PREPARE INFORMATION TO PASS TO KTPDRIVER TASKS # # ---------------------------------------------- # # Set objects pes_formula, pes_idx, subpes_idx = pes_inf label_dct = None # Print PES Channels that are being run ioprinter.runlst(pes_inf, rxn_lst) # Set paths where files will be written and read mess_path = job_path(run_prefix, 'MESS', 'RATE', pes_formula, locs_idx=subpes_idx) # --------------------------------- # # RUN THE REQUESTED KTPDRIVER TASKS # # --------------------------------- # # Write the MESS file write_rate_tsk = parser.run.extract_task('write_mess', ktp_tsk_lst) if write_rate_tsk is not None: # Get all the info for the task tsk_key_dct = write_rate_tsk[-1] pes_mod = tsk_key_dct['kin_model'] spc_mod = tsk_key_dct['spc_model'] spc_dct, rxn_lst, label_dct = _process(pes_idx, rxn_lst, ktp_tsk_lst, spc_mod_dct, spc_mod, thy_dct, spc_dct, glob_dct, run_prefix, save_prefix) ioprinter.messpf('write_header') mess_inp_str, dats = ktproutines.rates.make_messrate_str( pes_idx, rxn_lst, pes_mod, spc_mod, spc_dct, thy_dct, pes_mod_dct, spc_mod_dct, label_dct, mess_path, run_prefix, save_prefix) autorun.write_input(mess_path, mess_inp_str, aux_dct=dats, input_name='mess.inp') # Run mess to produce rates (currently nothing from tsk lst keys used) run_rate_tsk = parser.run.extract_task('run_mess', ktp_tsk_lst) if run_rate_tsk is not None: ioprinter.obj('vspace') ioprinter.obj('line_dash') ioprinter.running('MESS for the input file', mess_path) autorun.run_script(autorun.SCRIPT_DCT['messrate'], mess_path) # Fit rate output to modified Arrhenius forms, print in ChemKin format run_fit_tsk = parser.run.extract_task('run_fits', ktp_tsk_lst) if run_fit_tsk is not None: # Get all the info for the task tsk_key_dct = run_fit_tsk[-1] spc_mod = tsk_key_dct['spc_model'] pes_mod = tsk_key_dct['kin_model'] ratefit_dct = pes_mod_dct[pes_mod]['rate_fit'] if label_dct is None: spc_dct, rxn_lst, label_dct = _process(pes_idx, rxn_lst, ktp_tsk_lst, spc_mod_dct, spc_mod, thy_dct, spc_dct, run_prefix, save_prefix) ioprinter.obj('vspace') ioprinter.obj('line_dash') ioprinter.info_message( 'Fitting Rate Constants for PES to Functional Forms', newline=1) # Read and fit rates; write to ckin string ratefit_dct = pes_mod_dct[pes_mod]['rate_fit'] ckin_dct = ratefit.fit.fit_ktp_dct( mess_path=mess_path, inp_fit_method=ratefit_dct['fit_method'], pdep_dct=ratefit_dct['pdep_fit'], arrfit_dct=ratefit_dct['arrfit_fit'], chebfit_dct=ratefit_dct['chebfit_fit'], troefit_dct=ratefit_dct['troefit_fit'], label_dct=label_dct, fit_temps=pes_mod_dct[pes_mod]['rate_temps'], fit_pressures=pes_mod_dct[pes_mod]['pressures'], fit_tunit=pes_mod_dct[pes_mod]['temp_unit'], fit_punit=pes_mod_dct[pes_mod]['pressure_unit']) # Write the header part ckin_dct.update( {'header': writer.ckin.model_header((spc_mod, ), spc_mod_dct)}) ckin_path = output_path('CKIN') writer.ckin.write_rxn_file(ckin_dct, pes_formula, ckin_path)
def run(spc_rlst, therm_tsk_lst, pes_mod_dct, spc_mod_dct, spc_dct, run_prefix, save_prefix): """ main driver for thermo run """ # Print Header fo ioprinter.info_message('Calculating Thermochem:') ioprinter.runlst(('SPC', 0, 0), spc_rlst) # ------------------------------------------------ # # PREPARE INFORMATION TO PASS TO THERMDRIVER TASKS # # ------------------------------------------------ # # Build a list of the species to calculate thermochem for loops below spc_mods = list(spc_mod_dct.keys()) # hack split_spc_lst = split_unstable_spc(spc_rlst, spc_dct, spc_mod_dct[spc_mods[0]], save_prefix) spc_queue = parser.rlst.spc_queue('spc', tuple(split_spc_lst.values())[0]) # Build the paths [(messpf, nasa)], models and levels for each spc thm_paths = thermo_paths(spc_dct, spc_queue, spc_mods, run_prefix) # ----------------------------------- # # RUN THE REQUESTED THERMDRIVER TASKS # # ----------------------------------- # # Write and Run MESSPF inputs to generate the partition functions write_messpf_tsk = parser.run.extract_task('write_mess', therm_tsk_lst) if write_messpf_tsk is not None: ioprinter.messpf('write_header') spc_mods, pes_mod = parser.models.extract_models(write_messpf_tsk) for idx, spc_name in enumerate(spc_queue): print('write test {}'.format(spc_name)) for spc_mod in spc_mods: messpf_inp_str = thmroutines.qt.make_messpf_str( pes_mod_dct[pes_mod]['therm_temps'], spc_dct, spc_name, pes_mod_dct[pes_mod], spc_mod_dct[spc_mod], run_prefix, save_prefix) ioprinter.messpf('input_string') ioprinter.info_message(messpf_inp_str) autorun.write_input(thm_paths[idx][spc_mod][0], messpf_inp_str, input_name='pf.inp') # Run the MESSPF files that have been written run_messpf_tsk = parser.run.extract_task('run_mess', therm_tsk_lst) if run_messpf_tsk is not None: spc_mod, pes_mod = parser.models.extract_models(run_messpf_tsk) spc_mods = parser.models.split_model(spc_mod[0]) ioprinter.messpf('run_header') for idx, spc_name in enumerate(spc_queue): _spc_mods, coeffs, operators = spc_mods # Run MESSPF for all requested models, combine the PFS at the end ioprinter.message('Run MESSPF: {}'.format(spc_name), newline=1) _pfs = [] for spc_mod in _spc_mods: autorun.run_script(autorun.SCRIPT_DCT['messpf'], thm_paths[idx][spc_mod][0]) _pfs.append( pfrunner.mess.read_messpf(thm_paths[idx][spc_mod][0])) final_pf = pfrunner.mess.combine_pfs(_pfs, coeffs, operators) # need to clean thm path build tot_idx = len(spc_mods) spc_info = sinfo.from_dct(spc_dct[spc_name]) spc_fml = automol.inchi.formula_string(spc_info[0]) thm_prefix = [spc_fml, automol.inchi.inchi_key(spc_info[0])] thm_paths[idx]['final'] = (job_path(run_prefix, 'MESS', 'PF', thm_prefix, locs_idx=tot_idx), job_path(run_prefix, 'THERM', 'NASA', thm_prefix, locs_idx=tot_idx)) pfrunner.mess.write_mess_output(fstring( spc_dct[spc_name]['inchi']), final_pf, thm_paths[idx]['final'][0], filename='pf.dat') # Use MESS partition functions to compute thermo quantities run_fit_tsk = parser.run.extract_task('run_fits', therm_tsk_lst) if run_fit_tsk is not None: spc_mods, pes_mod = parser.models.extract_models(run_fit_tsk) pes_mod_dct_i = pes_mod_dct[pes_mod] ioprinter.nasa('header') chn_basis_ene_dct = {} for idx, spc_name in enumerate(spc_queue): # Take species model and add it to the chn_basis_ene dct spc_mod = spc_mods[0] spc_mod_dct_i = spc_mod_dct[spc_mod] if spc_mod not in chn_basis_ene_dct: chn_basis_ene_dct[spc_mod] = {} # Get the reference scheme and energies (ref in different place) ref_scheme = pes_mod_dct_i['therm_fit']['ref_scheme'] ref_enes = pes_mod_dct_i['therm_fit']['ref_enes'] # Determine info about the basis species used in thermochem calcs basis_dct, uniref_dct = thmroutines.basis.prepare_refs( ref_scheme, spc_dct, [[spc_name, None]], run_prefix, save_prefix) # Get the basis info for the spc of interest spc_basis, coeff_basis = basis_dct[spc_name] # Get the energies for the spc and its basis ene_basis = [] energy_missing = False for spc_basis_i in spc_basis: if spc_basis_i in chn_basis_ene_dct[spc_mod]: ioprinter.message( 'Energy already found for basis species: ' + spc_basis_i) ene_basis.append(chn_basis_ene_dct[spc_mod][spc_basis_i]) else: ioprinter.message( 'Energy will be determined for basis species: ' + spc_basis_i) energy_missing = True if not energy_missing: pf_filesystems = filesys.models.pf_filesys(spc_dct[spc_name], spc_mod_dct_i, run_prefix, save_prefix, saddle=False) ene_spc = ene.read_energy(spc_dct[spc_name], pf_filesystems, spc_mod_dct_i, run_prefix, read_ene=True, read_zpe=True, saddle=False) else: ene_spc, ene_basis = thmroutines.basis.basis_energy( spc_name, spc_basis, uniref_dct, spc_dct, spc_mod_dct_i, run_prefix, save_prefix) for spc_basis_i, ene_basis_i in zip(spc_basis, ene_basis): chn_basis_ene_dct[spc_mod][spc_basis_i] = ene_basis_i # Calculate and store the 0 K Enthalpy hf0k = thmroutines.heatform.calc_hform_0k(ene_spc, ene_basis, spc_basis, coeff_basis, ref_set=ref_enes) spc_dct[spc_name]['Hfs'] = [hf0k] # Write the NASA polynomials in CHEMKIN format ckin_nasa_str = '' ckin_path = output_path('CKIN') for idx, spc_name in enumerate(spc_queue): ioprinter.nasa('calculate', spc_name) # Write the header describing the models used in thermo calcs ckin_nasa_str += writer.ckin.model_header(spc_mods, spc_mod_dct) # Build and write the NASA polynomial in CHEMKIN-format string # Call dies if you haven't run "write mess" task ckin_nasa_str += thmroutines.nasapoly.build_polynomial( spc_name, spc_dct, thm_paths[idx]['final'][0], thm_paths[idx]['final'][1]) ckin_nasa_str += '\n\n' print(ckin_nasa_str) nasa7_params_all = chemkin_io.parser.thermo.create_spc_nasa7_dct( ckin_nasa_str) # print('ckin_nasa_str test', ckin_nasa_str) ioprinter.info_message( 'SPECIES H(0 K) H(298 K) S(298 K) Cp(300 K) Cp(500 K) Cp(1000 K) Cp(1500 K)\n' ) ioprinter.info_message( ' kcal/mol kcal/mol cal/(mol K) ... \n') for spc_name in nasa7_params_all: nasa7_params = nasa7_params_all[spc_name] whitespace = 18 - len(spc_name) h0 = spc_dct[spc_name]['Hfs'][0] h298 = mechanalyzer.calculator.thermo.enthalpy( nasa7_params, 298.15) / 1000. s298 = mechanalyzer.calculator.thermo.entropy(nasa7_params, 298.15) cp300 = mechanalyzer.calculator.thermo.heat_capacity( nasa7_params, 300) cp500 = mechanalyzer.calculator.thermo.heat_capacity( nasa7_params, 500) cp1000 = mechanalyzer.calculator.thermo.heat_capacity( nasa7_params, 1000) cp1500 = mechanalyzer.calculator.thermo.heat_capacity( nasa7_params, 1500) whitespace = whitespace * ' ' ioprinter.info_message( '{}{}{:>7.2f}{:>9.2f}{:>9.2f}{:>9.2f}{:>9.2f}{:>9.2f}{:>9.2f}'. format(spc_name, whitespace, h0, h298, s298, cp300, cp500, cp1000, cp1500)) # Write all of the NASA polynomial strings writer.ckin.write_nasa_file(ckin_nasa_str, ckin_path)
def run(pes_rlst, spc_rlst, therm_tsk_lst, pes_mod_dct, spc_mod_dct, spc_dct, thy_dct, run_prefix, save_prefix, mdriver_path): """ Executes all thermochemistry tasks. :param pes_rlst: species from PESs to run [(PES formula, PES idx, SUP-PES idx) (CHANNEL idx, (REACS, PRODS)) :type pes_rlst: tuple(dict[str: dict]) :param spc_rlst: lst of species to run :type spc_rlst: tuple(dict[str: dict]) :param es_tsk_lst: list of the electronic structure tasks :type es_tsk_lst: tuple(tuple(str, str, dict)) :param spc_dct: species information :type spc_dct: dict[str:dict] :param glob_dct: global information for all species :type glob_dct: dict[str: dict] :param thy_dct: all of the theory information :type thy_dct: dict[str:dict] :param run_prefix: root-path to the run-filesystem :type run_prefix: str :param save_prefix: root-path to the save-filesystem :type save_prefix: str :param mdriver_path: path where mechdriver is running :type mdriver_path: str """ # Print Header ioprinter.info_message('Calculating Thermochem:') ioprinter.runlst(list(spc_rlst.keys())[0], list(spc_rlst.values())[0]) # ------------------------------------------------ # # PREPARE INFORMATION TO PASS TO THERMDRIVER TASKS # # ------------------------------------------------ # # Parse Tasks write_messpf_tsk = parser.run.extract_task('write_mess', therm_tsk_lst) run_messpf_tsk = parser.run.extract_task('run_mess', therm_tsk_lst) run_fit_tsk = parser.run.extract_task('run_fits', therm_tsk_lst) # Build a list of the species to calculate thermochem for loops below # and build the paths [(messpf, nasa)], models and levels for each spc cnf_range = write_messpf_tsk[-1]['cnf_range'] sort_str = write_messpf_tsk[-1]['sort'] spc_locs_dct, thm_paths_dct, sort_info_lst = _set_spc_queue( spc_mod_dct, pes_rlst, spc_rlst, spc_dct, thy_dct, save_prefix, run_prefix, cnf_range, sort_str) # ----------------------------------- # # RUN THE REQUESTED THERMDRIVER TASKS # # ----------------------------------- # # Write and Run MESSPF inputs to generate the partition functions if write_messpf_tsk is not None: thermo_tasks.write_messpf_task(write_messpf_tsk, spc_locs_dct, spc_dct, pes_mod_dct, spc_mod_dct, run_prefix, save_prefix, thm_paths_dct) # Run the MESSPF files that have been written if run_messpf_tsk is not None: thermo_tasks.run_messpf_task(run_messpf_tsk, spc_locs_dct, spc_dct, thm_paths_dct) # Use MESS partition functions to compute thermo quantities if run_fit_tsk is not None: ioprinter.nasa('header') spc_mods, pes_mod = parser.models.extract_models(run_fit_tsk) pes_mod_dct_i = pes_mod_dct[pes_mod] # Get the reference scheme and energies (ref in different place) ref_scheme = pes_mod_dct_i['therm_fit']['ref_scheme'] ref_enes = pes_mod_dct_i['therm_fit']['ref_enes'] spc_dct = thermo_tasks.get_heats_of_formation(spc_locs_dct, spc_dct, spc_mods, spc_mod_dct, ref_scheme, ref_enes, run_prefix, save_prefix) # This has to happen down here because the weights rely on # The heats of formation print('in run_fit_tsk for thermo_driver boltzmann') spc_dct = thermo_tasks.produce_boltzmann_weighted_conformers_pf( run_messpf_tsk, spc_locs_dct, spc_dct, thm_paths_dct) # Write the NASA polynomials in CHEMKIN format ckin_nasa_str_dct, ckin_path = thermo_tasks.nasa_polynomial_task( mdriver_path, spc_locs_dct, thm_paths_dct, spc_dct, spc_mod_dct, spc_mods, sort_info_lst, ref_scheme) for idx, nasa_str in ckin_nasa_str_dct.items(): ioprinter.print_thermo(spc_dct, nasa_str, spc_locs_dct, idx, spc_mods[0]) # Write all of the NASA polynomial strings writer.ckin.write_nasa_file(nasa_str, ckin_path, idx=idx)
def run(pes_rlst, spc_rlst, proc_tsk_lst, spc_dct, thy_dct, pes_mod_dct, spc_mod_dct, run_prefix, save_prefix, mdriver_path): """ Central driver for all output tasks. :param spc_dct: species information :type spc_dct: dict[spc_name: spc_information] :param es_tsk_lst: list of the electronic structure tasks :type es_tsk_lst: list[[obj, tsk, keyword_dict]] :param thy_dct: all of the theory information :type thy_dct: dict[] :param run_inp_dct: information from input section of run.dat :type run_inp_dct: dict[] """ # Build the spc and ts queues spc_queue, ts_queue = (), () run_rlst = parser.rlst.combine(pes_rlst, spc_rlst) ts_queue = () for (fml, pes_idx, subpes_idx), run_lst_i in run_rlst.items(): ioprinter.runlst((fml, pes_idx, subpes_idx), run_lst_i) if fml != 'SPC': if any(tsk_lst[0] in ('all', 'ts') for tsk_lst in proc_tsk_lst): ts_dct, _queue = parser.spc.ts_dct_from_proctsks( pes_idx, proc_tsk_lst, run_lst_i, spc_mod_dct['global'], thy_dct, spc_dct, run_prefix, save_prefix) # doesnt allow for info from .dat file or internal defaults spc_dct.update(ts_dct) # Doesnt work it ts species from earlier part of for loop lost # spc_dct = parser.spc.combine_sadpt_spc_dcts( # ts_dct, spc_dct, glob_dct) ts_queue += _queue spc_queue += parser.rlst.spc_queue(run_lst_i, fml) else: spc_queue += run_lst_i # Remove species from queue spc_queue = tuple(i for n, i in enumerate(spc_queue) if i not in spc_queue[:n]) # Set master missing data list to write out at the end of run missing_data = () # Loop over Tasks for tsk_lst in proc_tsk_lst: [obj, tsk, prnt_keyword_dct] = tsk_lst # Build the queue of species based on user request if obj == 'spc': obj_queue = spc_queue elif obj == 'ts': obj_queue = ts_queue elif obj == 'all': obj_queue = spc_queue + ts_queue # Set up model dictionaries for the code to use spc_mod_dct_i = spc_mod_dct['global'] pes_mod_dct_i = pes_mod_dct['global'] # Run task and collate info about missing data missing_data += run_tsk(tsk, obj_queue, prnt_keyword_dct, spc_dct, thy_dct, spc_mod_dct_i, pes_mod_dct_i, run_prefix, save_prefix, mdriver_path) # Write a report that details what data is missing write_missing_data_report(missing_data)
def run(pes_rlst, spc_rlst, es_tsk_lst, spc_dct, glob_dct, thy_dct, run_prefix, save_prefix): """ Central driver for all electronic structure tasks. :param pes_rlst: lst of PES-SUBPES-CHNLS ro tun :type pes_rlst: [dict[species, reacs, prods, model]] :param spc_rlst: lst of species to run :type spc_rlst: [dict[species, reacs, prods, model]] :param es_tsk_lst: list of the electronic structure tasks :type es_tsk_lst: list[[obj, tsk, keyword_dict]] :param spc_dct: species information :type spc_dct: dict[spc_name: spc_information] :param thy_dct: all of the theory information :type thy_dct: dict[] """ # --------------------------------------------- # # PREPARE INFORMATION TO PASS TO ESDRIVER TASKS # # --------------------------------------------- # # Set the appropriate run lst; default to PES if any if pes_rlst: run_rlst, run_typ = pes_rlst, 'pes' else: run_rlst, run_typ = spc_rlst, 'spc' # -------------------------------- # # RUN THE REQUESTED ESDRIVER TASKS # # -------------------------------- # for (pes_form, pes_idx, subpes_idx), run_lst in run_rlst.items(): # Print what is being run PESs that are being run ioprinter.runlst((pes_form, pes_idx, subpes_idx), run_lst) # Build a TS dictionary and add it to the spc dct if needed if any(tsk_lst[0] == 'ts' for tsk_lst in es_tsk_lst): ts_dct, ts_queue = parser.spc.ts_dct_from_estsks( pes_idx, es_tsk_lst, run_lst, thy_dct, spc_dct, run_prefix, save_prefix) spc_dct = parser.spc.combine_sadpt_spc_dcts( ts_dct, spc_dct, glob_dct) else: ts_queue = () # Loop over the tasks for tsk_lst in es_tsk_lst: # Unpack the options [obj, tsk, es_keyword_dct] = tsk_lst # Build the queue of species based on user request if obj == 'all': obj_queue = parser.rlst.spc_queue(run_typ, run_lst) + ts_queue if obj == 'spc': obj_queue = parser.rlst.spc_queue(run_typ, run_lst) elif obj == 'ts': obj_queue = ts_queue elif obj == 'vdw': obj_queue = () # Run the electronic structure task for all spc in queue for spc_name in obj_queue: run_tsk(tsk, spc_dct, spc_name, thy_dct, es_keyword_dct, run_prefix, save_prefix)
def run(pes_rlst, spc_rlst, es_tsk_lst, spc_dct, glob_dct, thy_dct, run_prefix, save_prefix, print_debug=False): """ Executes all electronic structure tasks. :param pes_rlst: species from PESs to run [(PES formula, PES idx, SUP-PES idx) (CHANNEL idx, (REACS, PRODS)) :type pes_rlst: tuple(dict[str: dict]) :param spc_rlst: lst of species to run :type spc_rlst: tuple(dict[str: dict]) :param es_tsk_lst: list of the electronic structure tasks tuple(tuple(obj, tsk, keyword_dict)) :type es_tsk_lst: tuple(tuple(str, str, dict)) :param spc_dct: species information dict[spc_name: spc_information] :type spc_dct: dict[str:dict] :param glob_dct: global information for all species dict[spc_name: spc_information] :type glob_dct: dict[str: dict] :param thy_dct: all of the theory information dict[thy name: inf] :type thy_dct: dict[str:dict] :param run_prefix: root-path to the run-filesystem :type run_prefix: str :param save_prefix: root-path to the save-filesystem :type save_prefix: str """ # -------------------------------- # # RUN THE REQUESTED ESDRIVER TASKS # # -------------------------------- # # Set the appropriate run lst; default to PES if any # Runs through PESs, then SPC run_rlst = parser.rlst.combine(pes_rlst, spc_rlst) for (fml, pes_idx, subpes_idx), run_lst in run_rlst.items(): # Print what is being run PESs that are being run ioprinter.runlst((fml, pes_idx, subpes_idx), run_lst) # Initialize an empty ts_dct for the PES ts_dct = None # Loop over the tasks for tsk_lst in es_tsk_lst: # Build a TS dictionary and add it to the spc dct if needed # will only build a ts dct for 1st ts task on the PES if (fml != 'SPC' and tsk_lst[0] in ('ts', 'all')): if ts_dct is None: ts_dct = parser.spc.ts_dct_from_estsks( pes_idx, es_tsk_lst, run_lst, thy_dct, spc_dct, run_prefix, save_prefix) spc_dct = parser.spc.combine_sadpt_spc_dcts( ts_dct, spc_dct, glob_dct) ts_queue = tuple(x for x in ts_dct) if ts_dct is not None else () # Unpack the options [obj, tsk, es_keyword_dct] = tsk_lst # Build the queue of species based on user request if obj == 'all': obj_queue = parser.rlst.spc_queue(run_lst, fml) + ts_queue elif obj == 'spc': obj_queue = parser.rlst.spc_queue(run_lst, fml) elif obj == 'ts': obj_queue = ts_queue elif obj == 'vdw': obj_queue = () # Run the electronic structure task for all spc in queue for spc_name in obj_queue: run_tsk(tsk, spc_dct, spc_name, thy_dct, es_keyword_dct, run_prefix, save_prefix, print_debug=print_debug)
def run(pes_rlst, spc_rlst, therm_tsk_lst, pes_mod_dct, spc_mod_dct, spc_dct, run_prefix, save_prefix): """ Executes all thermochemistry tasks. :param pes_rlst: species from PESs to run [(PES formula, PES idx, SUP-PES idx) (CHANNEL idx, (REACS, PRODS)) :type pes_rlst: tuple(dict[str: dict]) :param spc_rlst: lst of species to run :type spc_rlst: tuple(dict[str: dict]) :param es_tsk_lst: list of the electronic structure tasks tuple(tuple(obj, tsk, keyword_dict)) :type es_tsk_lst: tuple(tuple(str, str, dict)) :param spc_dct: species information dict[spc_name: spc_information] :type spc_dct: dict[str:dict] :param glob_dct: global information for all species dict[spc_name: spc_information] :type glob_dct: dict[str: dict] :param thy_dct: all of the theory information dict[thy name: inf] :type thy_dct: dict[str:dict] :param run_prefix: root-path to the run-filesystem :type run_prefix: str :param save_prefix: root-path to the save-filesystem :type save_prefix: str """ # Print Header ioprinter.info_message('Calculating Thermochem:') ioprinter.runlst(('SPC', 0, 0), spc_rlst) # ------------------------------------------------ # # PREPARE INFORMATION TO PASS TO THERMDRIVER TASKS # # ------------------------------------------------ # # Build a list of the species to calculate thermochem for loops below spc_mods = list(spc_mod_dct.keys()) # hack spc_mod_dct_i = spc_mod_dct[spc_mods[0]] split_rlst = split_unstable_full( pes_rlst, spc_rlst, spc_dct, spc_mod_dct_i, save_prefix) spc_queue = parser.rlst.spc_queue( tuple(split_rlst.values())[0], 'SPC') # Build the paths [(messpf, nasa)], models and levels for each spc thm_paths = thermo_paths(spc_dct, spc_queue, spc_mods, run_prefix) # ----------------------------------- # # RUN THE REQUESTED THERMDRIVER TASKS # # ----------------------------------- # # Write and Run MESSPF inputs to generate the partition functions write_messpf_tsk = parser.run.extract_task('write_mess', therm_tsk_lst) if write_messpf_tsk is not None: ioprinter.messpf('write_header') spc_mods, pes_mod = parser.models.extract_models(write_messpf_tsk) for idx, spc_name in enumerate(spc_queue): print('write test {}'.format(spc_name)) for spc_mod in spc_mods: messpf_inp_str = thmroutines.qt.make_messpf_str( pes_mod_dct[pes_mod]['therm_temps'], spc_dct, spc_name, pes_mod_dct[pes_mod], spc_mod_dct[spc_mod], run_prefix, save_prefix) ioprinter.messpf('input_string') ioprinter.info_message(messpf_inp_str) autorun.write_input( thm_paths[idx][spc_mod][0], messpf_inp_str, input_name='pf.inp') # Run the MESSPF files that have been written run_messpf_tsk = parser.run.extract_task('run_mess', therm_tsk_lst) if run_messpf_tsk is not None: spc_mod, pes_mod = parser.models.extract_models(run_messpf_tsk) spc_mods = parser.models.split_model(spc_mod[0]) ioprinter.messpf('run_header') for idx, spc_name in enumerate(spc_queue): _spc_mods, coeffs, operators = spc_mods # Run MESSPF for all requested models, combine the PFS at the end ioprinter.message('Run MESSPF: {}'.format(spc_name), newline=1) _pfs = [] for spc_mod in _spc_mods: autorun.run_script( autorun.SCRIPT_DCT['messpf'], thm_paths[idx][spc_mod][0]) _pfs.append( reader.mess.messpf(thm_paths[idx][spc_mod][0])) final_pf = thermfit.pf.combine(_pfs, coeffs, operators) # need to clean thm path build tdx = len(spc_mods) spc_info = sinfo.from_dct(spc_dct[spc_name]) spc_fml = automol.inchi.formula_string(spc_info[0]) thm_prefix = [spc_fml, automol.inchi.inchi_key(spc_info[0])] thm_paths[idx]['final'] = ( job_path(run_prefix, 'MESS', 'PF', thm_prefix, locs_idx=tdx), job_path(run_prefix, 'THERM', 'NASA', thm_prefix, locs_idx=tdx) ) writer.mess.output( fstring(spc_dct[spc_name]['inchi']), final_pf, thm_paths[idx]['final'][0], filename='pf.dat') # Use MESS partition functions to compute thermo quantities run_fit_tsk = parser.run.extract_task('run_fits', therm_tsk_lst) if run_fit_tsk is not None: spc_mods, pes_mod = parser.models.extract_models(run_fit_tsk) pes_mod_dct_i = pes_mod_dct[pes_mod] ioprinter.nasa('header') chn_basis_ene_dct = {} for idx, spc_name in enumerate(spc_queue): # Take species model and add it to the chn_basis_ene dct spc_mod = spc_mods[0] spc_mod_dct_i = spc_mod_dct[spc_mod] if spc_mod not in chn_basis_ene_dct: chn_basis_ene_dct[spc_mod] = {} # Get the reference scheme and energies (ref in different place) ref_scheme = pes_mod_dct_i['therm_fit']['ref_scheme'] ref_enes = pes_mod_dct_i['therm_fit']['ref_enes'] # Determine info about the basis species used in thermochem calcs basis_dct, uniref_dct = thermfit.prepare_refs( ref_scheme, spc_dct, (spc_name,)) # Get the basis info for the spc of interest spc_basis, coeff_basis = basis_dct[spc_name] # Get the energies for the spc and its basis ene_basis = [] energy_missing = False for spc_basis_i in spc_basis: if spc_basis_i in chn_basis_ene_dct[spc_mod]: ioprinter.message( 'Energy already found for basis species: ' + spc_basis_i) ene_basis.append(chn_basis_ene_dct[spc_mod][spc_basis_i]) else: ioprinter.message( 'Energy will be determined for basis species: ' + spc_basis_i) energy_missing = True if not energy_missing: pf_filesystems = filesys.models.pf_filesys( spc_dct[spc_name], spc_mod_dct_i, run_prefix, save_prefix, saddle=False) ene_spc = ene.read_energy( spc_dct[spc_name], pf_filesystems, spc_mod_dct_i, run_prefix, read_ene=True, read_zpe=True, saddle=False) else: ene_spc, ene_basis = thmroutines.basis.basis_energy( spc_name, spc_basis, uniref_dct, spc_dct, spc_mod_dct_i, run_prefix, save_prefix) for spc_basis_i, ene_basis_i in zip(spc_basis, ene_basis): chn_basis_ene_dct[spc_mod][spc_basis_i] = ene_basis_i # Calculate and store the 0 K Enthalpy hf0k = thermfit.heatform.calc_hform_0k( ene_spc, ene_basis, spc_basis, coeff_basis, ref_set=ref_enes) spc_dct[spc_name]['Hfs'] = [hf0k] # Write the NASA polynomials in CHEMKIN format ckin_nasa_str = '' ckin_path = output_path('CKIN') for idx, spc_name in enumerate(spc_queue): ioprinter.nasa('calculate', spc_name) # Write the header describing the models used in thermo calcs ckin_nasa_str += writer.ckin.model_header(spc_mods, spc_mod_dct) # Build and write the NASA polynomial in CHEMKIN-format string # Call dies if you haven't run "write mess" task ckin_nasa_str += thmroutines.nasapoly.build_polynomial( spc_name, spc_dct, thm_paths[idx]['final'][0], thm_paths[idx]['final'][1]) ckin_nasa_str += '\n\n' print('CKIN NASA STR\n') print(ckin_nasa_str) nasa7_params_all = chemkin_io.parser.thermo.create_spc_nasa7_dct( ckin_nasa_str) ioprinter.info_message( 'SPECIES\t\tH(0 K)[kcal/mol]\tH(298 K)[kcal/mol]\t' + 'S(298 K)[cal/mol K]\n') for spc_name in nasa7_params_all: nasa7_params = nasa7_params_all[spc_name] ht0 = spc_dct[spc_name]['Hfs'][0] ht298 = mechanalyzer.calculator.thermo.enthalpy( nasa7_params, 298.15) st298 = mechanalyzer.calculator.thermo.entropy( nasa7_params, 298.15) ioprinter.info_message( '{}\t{:3.2f}\t{:3.2f}\t{:3.2f}'.format( spc_name, ht0, ht298/1000., st298)) # Write all of the NASA polynomial strings writer.ckin.write_nasa_file(ckin_nasa_str, ckin_path)
def run(pes_rlst, ktp_tsk_lst, spc_dct, glob_dct, pes_mod_dct, spc_mod_dct, run_prefix, save_prefix): """ Executes all kinetics tasks. :param pes_rlst: species from PESs to run [(PES formula, PES idx, SUP-PES idx) (CHANNEL idx, (REACS, PRODS)) :type pes_rlst: tuple(dict[str: dict]) :param spc_rlst: lst of species to run :type spc_rlst: tuple(dict[str: dict]) :param es_tsk_lst: list of the electronic structure tasks tuple(tuple(obj, tsk, keyword_dict)) :type es_tsk_lst: tuple(tuple(str, str, dict)) :param spc_dct: species information dict[spc_name: spc_information] :type spc_dct: dict[str:dict] :param glob_dct: global information for all species dict[spc_name: spc_information] :type glob_dct: dict[str: dict] :param thy_dct: all of the theory information dict[thy name: inf] :type thy_dct: dict[str:dict] :param run_prefix: root-path to the run-filesystem :type run_prefix: str :param save_prefix: root-path to the save-filesystem :type save_prefix: str """ # --------------------------------------- # # LOOP OVER ALL OF THE SUBPES in PES_RLST # # --------------------------------------- # for pes_inf, rxn_lst in pes_rlst.items(): # ---------------------------------------------- # # PREPARE INFORMATION TO PASS TO KTPDRIVER TASKS # # ---------------------------------------------- # # Set objects pes_formula, pes_idx, subpes_idx = pes_inf label_dct = None # Print PES Channels that are being run ioprinter.runlst(pes_inf, rxn_lst) # Set paths where files will be written and read mess_path = job_path(run_prefix, 'MESS', 'RATE', pes_formula, locs_idx=subpes_idx) # --------------------------------- # # RUN THE REQUESTED KTPDRIVER TASKS # # --------------------------------- # # Write the MESS file write_rate_tsk = parser.run.extract_task('write_mess', ktp_tsk_lst) if write_rate_tsk is not None: # Get all the info for the task tsk_key_dct = write_rate_tsk[-1] pes_mod = tsk_key_dct['kin_model'] spc_mod = tsk_key_dct['spc_model'] spc_dct, rxn_lst, instab_chnls, label_dct = _process( pes_idx, rxn_lst, ktp_tsk_lst, spc_mod_dct, spc_mod, spc_dct, glob_dct, run_prefix, save_prefix) ioprinter.messpf('write_header') # Doesn't give full string mess_inp_str, dats = ktproutines.rates.make_messrate_str( pes_idx, rxn_lst, pes_mod, spc_mod, spc_dct, pes_mod_dct, spc_mod_dct, instab_chnls, label_dct, mess_path, run_prefix, save_prefix, make_lump_well_inp=tsk_key_dct['lump_wells']) autorun.write_input(mess_path, mess_inp_str, aux_dct=dats, input_name='mess.inp') # Run mess to produce rates (currently nothing from tsk lst keys used) run_rate_tsk = parser.run.extract_task('run_mess', ktp_tsk_lst) if run_rate_tsk is not None: ioprinter.obj('vspace') ioprinter.obj('line_dash') ioprinter.running('MESS for the input file', mess_path) autorun.run_script(autorun.SCRIPT_DCT['messrate'], mess_path) # Fit rate output to modified Arrhenius forms, print in ChemKin format run_fit_tsk = parser.run.extract_task('run_fits', ktp_tsk_lst) if run_fit_tsk is not None: # Get all the info for the task tsk_key_dct = run_fit_tsk[-1] spc_mod = tsk_key_dct['spc_model'] pes_mod = tsk_key_dct['kin_model'] ratefit_dct = pes_mod_dct[pes_mod]['rate_fit'] if label_dct is None: spc_dct, rxn_lst, _, label_dct = _process( pes_idx, rxn_lst, ktp_tsk_lst, spc_mod_dct, spc_mod, spc_dct, glob_dct, run_prefix, save_prefix) ioprinter.obj('vspace') ioprinter.obj('line_dash') ioprinter.info_message( 'Fitting Rate Constants for PES to Functional Forms', newline=1) # Read and fit rates; write to ckin string ratefit_dct = pes_mod_dct[pes_mod]['rate_fit'] ckin_dct = ratefit.fit.fit_ktp_dct( mess_path=mess_path, inp_fit_method=ratefit_dct['fit_method'], pdep_dct=ratefit_dct['pdep_fit'], arrfit_dct=ratefit_dct['arrfit_fit'], chebfit_dct=ratefit_dct['chebfit_fit'], troefit_dct=ratefit_dct['troefit_fit'], label_dct=label_dct, fit_temps=pes_mod_dct[pes_mod]['rate_temps'], fit_pressures=pes_mod_dct[pes_mod]['pressures'], fit_tunit=pes_mod_dct[pes_mod]['temp_unit'], fit_punit=pes_mod_dct[pes_mod]['pressure_unit']) # Write the header part ckin_dct.update( {'header': writer.ckin.model_header((spc_mod, ), spc_mod_dct)}) ckin_path = output_path('CKIN') writer.ckin.write_rxn_file(ckin_dct, pes_formula, ckin_path)