def save_thermo_lib(species_list, path, name, lib_long_desc): """ Save an RMG thermo library. Args: species_list (list): Entries are Species object instances for which thermo will be saved. path (str): The base folder in which the thermo library will be saved. name (str): The library name. lib_long_desc (str): A multiline string with relevant description. """ if species_list: lib_path = os.path.join(path, f'{name}.py') thermo_library = ThermoLibrary(name=name, long_desc=lib_long_desc) for i, spc in enumerate(species_list): if spc.thermo is not None: long_thermo_description = f'\nSpin multiplicity: {spc.conformer.spin_multiplicity}' \ f'\nExternal symmetry: {spc.molecule[0].symmetry_number}' \ f'\nOptical isomers: {spc.conformer.optical_isomers}\n' xyz = get_str_xyz(spc) if xyz is not None: long_thermo_description += f'\nGeometry:\n{xyz}' thermo_library.load_entry( index=i, label=spc.label, molecule=spc.molecule[0].to_adjacency_list(), thermo=spc.thermo, shortDesc=spc.thermo.comment, longDesc=long_thermo_description) else: logging.warning( f'Species {spc.label} did not contain any thermo data and was omitted from the thermo ' f'library {name}.') thermo_library.save(lib_path)
def run_thermo_estimator(input_file, library_flag): """ Estimate thermo for a list of species using RMG and the settings chosen inside a thermo input file. """ rmg = RMG() rmg.load_thermo_input(input_file) rmg.database = RMGDatabase() path = os.path.join(settings['database.directory']) # forbidden structure loading rmg.database.load_thermo(os.path.join(path, 'thermo'), rmg.thermo_libraries, depository=False) if rmg.solvent: rmg.database.load_solvation(os.path.join(path, 'solvation')) Species.solvent_data = rmg.database.solvation.get_solvent_data( rmg.solvent) Species.solvent_name = rmg.solvent for species in rmg.initial_species: submit(species) if library_flag: library = ThermoLibrary(name='Thermo Estimation Library') for species in rmg.initial_species: library.load_entry( index=len(library.entries) + 1, label=species.label, molecule=species.molecule[0].to_adjacency_list(), thermo=species.get_thermo_data().to_thermo_data(), shortDesc=species.get_thermo_data().comment, ) library.save(os.path.join(rmg.output_directory, 'ThermoLibrary.py')) # Save the thermo data to chemkin format output files and dictionary, with no reactions save_chemkin_file(os.path.join(rmg.output_directory, 'chem_annotated.inp'), species=rmg.initial_species, reactions=[]) save_species_dictionary(os.path.join(rmg.output_directory, 'species_dictionary.txt'), species=rmg.initial_species)
def get_libraries(self): """Get RMG kinetics and thermo libraries""" name = 'kineticsjobs' species_list = list(self.species_dict.values()) reaction_list = list(self.reaction_dict.values()) # remove duplicate species for rxn in reaction_list: for i, rspc in enumerate(rxn.reactants): for spc in species_list: if spc.is_isomorphic(rspc): rxn.reactants[i] = spc break for i, rspc in enumerate(rxn.products): for spc in species_list: if spc.is_isomorphic(rspc): rxn.products[i] = spc break del_inds = [] for i, spc1 in enumerate(species_list): for j, spc2 in enumerate(species_list): if j > i and spc1.is_isomorphic(spc2): del_inds.append(j) for j in sorted(del_inds)[::-1]: del species_list[j] thermo_library = ThermoLibrary(name=name) for i, species in enumerate(species_list): if species.thermo: thermo_library.load_entry( index=i + 1, label=species.label, molecule=species.molecule[0].to_adjacency_list(), thermo=species.thermo, shortDesc=species.thermo.comment) else: logging.warning( 'Species {0} did not contain any thermo data and was omitted from the thermo library.' .format(str(species))) # load kinetics library entries kinetics_library = KineticsLibrary(name=name, auto_generated=True) kinetics_library.entries = {} for i, reaction in enumerate(reaction_list): entry = Entry(index=i + 1, label=reaction.to_labeled_str(), item=reaction, data=reaction.kinetics) if reaction.kinetics is not None: if hasattr(reaction, 'library') and reaction.library: entry.long_desc = 'Originally from reaction library: ' + \ reaction.library + "\n" + reaction.kinetics.comment else: entry.long_desc = reaction.kinetics.comment kinetics_library.entries[i + 1] = entry kinetics_library.label = name return thermo_library, kinetics_library, species_list
args = parser.parse_args() chemkin_path = args.chemkin_path[0] dictionary_path = args.dictionary_path[0] name = args.name[0] species_list, reaction_list = load_chemkin_file(chemkin_path, dictionary_path) thermo_library = ThermoLibrary(name=name) for i in range(len(species_list)): species = species_list[i] if species.thermo: thermo_library.load_entry( index=i + 1, label=species.label, molecule=species.molecule[0].to_adjacency_list(), thermo=species.thermo, ) else: logging.warning( """Species {0} did not contain any thermo data and was omitted from the thermo library.""".format(str(species))) # load kinetics library entries kinetics_library = KineticsLibrary(name=name) kinetics_library.entries = {} for i in range(len(reaction_list)): reaction = reaction_list[i] entry = Entry( index=i + 1, label=str(reaction),