def save_kinetics_lib(rxn_list, path, name, lib_long_desc): """ Save an RMG kinetics library. Args: rxn_list (list): Entries are Reaction object instances for which kinetics will be saved. path (str): The base folder in which the kinetic library will be saved. name (str): The library name. lib_long_desc (str): A multiline string with relevant description. """ entries = dict() if rxn_list: for i, rxn in enumerate(rxn_list): if rxn.kinetics is not None: entry = Entry(index=i, item=rxn, data=rxn.kinetics, label=rxn.label) entries[i + 1] = entry else: logging.warning( f'Reaction {rxn.label} did not contain any kinetic data and was omitted from the ' f'kinetics library.') kinetics_library = KineticsLibrary(name=name, long_desc=lib_long_desc, auto_generated=True) kinetics_library.entries = entries if os.path.exists(path): shutil.rmtree(path) try: os.makedirs(path) except OSError: pass kinetics_library.save(os.path.join(path, 'reactions.py')) kinetics_library.save_dictionary(os.path.join(path, 'dictionary.txt'))
def save_kinetics_lib(rxn_list, path, name, lib_long_desc): """ Save an RMG kinetics library of all reactions in `rxn_list` in the supplied `path` `rxn_list` is a list of ARCReaction objects `name` is the library's name (or project's name) `long_desc` is a multiline string with level of theory description """ entries = dict() if rxn_list: for i, rxn in enumerate(rxn_list): if rxn.kinetics is not None: if len(rxn.rmg_reaction.reactants): reactants = rxn.rmg_reaction.reactants products = rxn.rmg_reaction.products elif rxn.r_species.mol_list is not None: reactants = [Species(molecule=arc_spc.mol_list) for arc_spc in rxn.r_species] products = [Species(molecule=arc_spc.mol_list) for arc_spc in rxn.p_species] elif rxn.r_species.mol is not None: reactants = [Species(molecule=[arc_spc.mol]) for arc_spc in rxn.r_species] products = [Species(molecule=[arc_spc.mol]) for arc_spc in rxn.p_species] else: reactants = [Species(molecule=[arc_spc.xyz_mol]) for arc_spc in rxn.r_species] products = [Species(molecule=[arc_spc.xyz_mol]) for arc_spc in rxn.p_species] rxn.rmg_reaction.reactants = reactants rxn.rmg_reaction.products = products entry = Entry( index=i, item=rxn.rmg_reaction, data=rxn.kinetics, label=rxn.label) rxn.ts_species.make_ts_report() entry.longDesc = rxn.ts_species.ts_report + '\n\nOptimized TS geometry:\n' + rxn.ts_species.final_xyz rxn.rmg_reaction.kinetics = rxn.kinetics rxn.rmg_reaction.kinetics.comment = str('') entries[i+1] = entry else: logging.warning('Reaction {0} did not contain any kinetic data and was omitted from the kinetics' ' library.'.format(rxn.label)) kinetics_library = KineticsLibrary(name=name, longDesc=lib_long_desc, autoGenerated=True) kinetics_library.entries = entries lib_path = os.path.join(path, 'kinetics', '') if os.path.exists(lib_path): shutil.rmtree(lib_path) try: os.makedirs(lib_path) except OSError: pass kinetics_library.save(os.path.join(lib_path, 'reactions.py')) kinetics_library.saveDictionary(os.path.join(lib_path, 'dictionary.txt'))