def save_thermo_lib(species_list, path, name, lib_long_desc): """ Save an RMG thermo library of all species in `species_list` in the supplied `path` `name` is the library's name (or project's name) `long_desc` is a multiline string with level of theory description """ if species_list: lib_path = os.path.join(path, 'thermo', '{0}.py'.format(name)) thermo_library = ThermoLibrary(name=name, longDesc=lib_long_desc) for i, spc in enumerate(species_list): if spc.thermo is not None: spc.long_thermo_description += '\nExternal symmetry: {0}, optical isomers: {1}\n'.format( spc.external_symmetry, spc.optical_isomers) spc.long_thermo_description += '\nGeometry:\n{0}'.format( spc.final_xyz) thermo_library.loadEntry( index=i + 1, label=spc.label, molecule=spc.mol_list[0].toAdjacencyList(), thermo=spc.thermo, shortDesc=spc.thermo.comment, longDesc=spc.long_thermo_description) else: logging.warning( 'Species {0} did not contain any thermo data and was omitted from the thermo' ' library.'.format(str(spc))) thermo_library.save(lib_path)
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 runThermoEstimator(inputFile): """ Estimate thermo for a list of species using RMG and the settings chosen inside a thermo input file. """ rmg = RMG() rmg.loadThermoInput(inputFile) # initialize and load the database as well as any QM settings rmg.loadDatabase() if rmg.quantumMechanics: rmg.quantumMechanics.initialize() # Generate the thermo for all the species and write them to chemkin format as well as # ThermoLibrary format with values for H, S, and Cp's. output = open(os.path.join(rmg.outputDirectory, 'output.txt'),'wb') library = ThermoLibrary(name='Thermo Estimation Library') for species in rmg.initialSpecies: species.generateThermoData(rmg.database, quantumMechanics=rmg.reactionModel.quantumMechanics) library.loadEntry( index = len(library.entries) + 1, label = species.label, molecule = species.molecule[0].toAdjacencyList(), thermo = species.thermo.toThermoData(), shortDesc = species.thermo.comment, ) output.write(writeThermoEntry(species)) output.write('\n') output.close() library.save(os.path.join(rmg.outputDirectory,'ThermoLibrary.py'))
def runThermoEstimator(inputFile): """ Estimate thermo for a list of species using RMG and the settings chosen inside a thermo input file. """ rmg = RMG() rmg.loadThermoInput(inputFile) # initialize and load the database as well as any QM settings rmg.loadDatabase() if rmg.quantumMechanics: rmg.quantumMechanics.initialize() # Generate the thermo for all the species and write them to chemkin format as well as # ThermoLibrary format with values for H, S, and Cp's. output = open(os.path.join(rmg.outputDirectory, 'output.txt'), 'wb') library = ThermoLibrary(name='Thermo Estimation Library') for species in rmg.initialSpecies: species.generateThermoData( rmg.database, quantumMechanics=rmg.reactionModel.quantumMechanics) library.loadEntry( index=len(library.entries) + 1, label=species.label, molecule=species.molecule[0].toAdjacencyList(), thermo=species.thermo.toThermoData(), shortDesc=species.thermo.comment, ) output.write(writeThermoEntry(species)) output.write('\n') output.close() library.save(os.path.join(rmg.outputDirectory, 'ThermoLibrary.py'))
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 runThermoEstimator(inputFile): """ Estimate thermo for a list of species using RMG and the settings chosen inside a thermo input file. """ rmg = RMG() rmg.loadThermoInput(inputFile) rmg.database = RMGDatabase() path = os.path.join(settings['database.directory']) # forbidden structure loading rmg.database.loadThermo(os.path.join(path, 'thermo'), rmg.thermoLibraries, depository=False) if rmg.solvent: rmg.database.loadSolvation(os.path.join(path, 'solvation')) Species.solventData = rmg.database.solvation.getSolventData(rmg.solvent) Species.solventName = rmg.solvent # Generate the thermo for all the species and write them to chemkin format as well as # ThermoLibrary format with values for H, S, and Cp's. output = open(os.path.join(rmg.outputDirectory, 'output.txt'),'wb') library = ThermoLibrary(name='Thermo Estimation Library') for species in rmg.initialSpecies: species.getThermoData(rmg.database) library.loadEntry( index = len(library.entries) + 1, label = species.label, molecule = species.molecule[0].toAdjacencyList(), thermo = species.thermo.toThermoData(), shortDesc = species.thermo.comment, ) output.write(writeThermoEntry(species)) output.write('\n') output.close() library.save(os.path.join(rmg.outputDirectory,'ThermoLibrary.py'))
kineticsLibrary = KineticsLibrary() kineticsLibrary.entries = {} for i in range(len(reactionList)): reaction = reactionList[i] entry = Entry( index = i+1, item = reaction, data = reaction.kinetics, ) entry.longDesc = reaction.kinetics.comment kineticsLibrary.entries[i+1] = entry kineticsLibrary.checkForDuplicates() kineticsLibrary.convertDuplicatesToMulti() # Assign history to all entries user = getUsername() # Pulls username from current git repository #user = '******'.format(name, email) # If not in git repository, then enter user information manually event = [time.asctime(),user,'action','{0} imported this entry from the old RMG database.'.format(user)] for label, entry in thermoLibrary.entries.iteritems(): entry.history.append(event) for label, entry in kineticsLibrary.entries.iteritems(): entry.history.append(event) # Save in Py format if not os.path.exists(outputDir): os.makedirs(os.path.join(self.path)) thermoLibrary.save(os.path.join(outputDir, 'chemkinThermoLibrary.py'), removeH=removeH) kineticsLibrary.save(os.path.join(outputDir, 'chemkinKineticsLibrary.py'), removeH=removeH)
import argparse import os from rmgpy.data.thermo import ThermoLibrary if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('inputPath', metavar='INPUT', type=str, nargs=1, help='the input path of the RMG-Java thermo library directory') parser.add_argument('libraryName', metavar='OUTPUT', type=str, nargs=1, help='the libraryName for the RMG-Py format thermo library') args = parser.parse_args() inputPath = args.inputPath[0] libraryName = args.libraryName[0] library = ThermoLibrary() library.loadOld( dictstr = os.path.join(inputPath, 'Dictionary.txt'), treestr = '', libstr = os.path.join(inputPath, 'Library.txt'), numParameters = 12, numLabels = 1, pattern = False, ) library.name = libraryName # Save in Py format library.save(os.path.join('input/thermo/libraries/', libraryName+'.py'))
data=reaction.kinetics, ) try: entry.long_desc = 'Originally from reaction library: ' + reaction.library + "\n" + reaction.kinetics.comment except AttributeError: entry.long_desc = reaction.kinetics.comment kinetics_library.entries[i + 1] = entry # Mark as duplicates where there are mixed pressure dependent and non-pressure dependent duplicate kinetics # Even though CHEMKIN does not require a duplicate flag, RMG needs it. # Using flag mark_duplicates = True kinetics_library.check_for_duplicates(mark_duplicates=True) kinetics_library.convert_duplicates_to_multi() # Save in Py format database_directory = settings['database.directory'] try: os.makedirs( os.path.join(database_directory, 'kinetics', 'libraries', name)) except: pass thermo_library.save( os.path.join(database_directory, 'thermo', 'libraries', name + '.py')) kinetics_library.save( os.path.join(database_directory, 'kinetics', 'libraries', name, 'reactions.py')) kinetics_library.save_dictionary( os.path.join(database_directory, 'kinetics', 'libraries', name, 'dictionary.txt'))
) 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 kineticsLibrary = KineticsLibrary() kineticsLibrary.entries = {} for i in range(len(reactionList)): reaction = reactionList[i] entry = Entry( index = i+1, label = str(reaction), item = reaction, data = reaction.kinetics, ) entry.longDesc = reaction.kinetics.comment kineticsLibrary.entries[i+1] = entry kineticsLibrary.checkForDuplicates() kineticsLibrary.convertDuplicatesToMulti() # Save in Py format try: os.makedirs(os.join('input/kinetics/libraries/',name)) except: pass thermoLibrary.save(os.path.join('input/thermo/libraries', name + '.py')) kineticsLibrary.save(os.path.join('input/kinetics/libraries/', name, 'reactions.py')) kineticsLibrary.saveDictionary(os.path.join('input/kinetics/libraries/', name, 'dictionary.txt'))
for i in range(len(reactionList)): reaction = reactionList[i] entry = Entry( index = i+1, label = str(reaction), item = reaction, data = reaction.kinetics, ) try: entry.longDesc = 'Originally from reaction library: ' + reaction.library + "\n" + reaction.kinetics.comment except AttributeError: entry.longDesc = reaction.kinetics.comment kineticsLibrary.entries[i+1] = entry # Mark as duplicates where there are mixed pressure dependent and non-pressure dependent duplicate kinetics # Even though CHEMKIN does not require a duplicate flag, RMG needs it. # Using flag markDuplicates = True kineticsLibrary.checkForDuplicates(markDuplicates=True) kineticsLibrary.convertDuplicatesToMulti() # Save in Py format databaseDirectory = settings['database.directory'] try: os.makedirs(os.path.join(databaseDirectory, 'kinetics', 'libraries',name)) except: pass thermoLibrary.save(os.path.join(databaseDirectory, 'thermo' ,'libraries', name + '.py')) kineticsLibrary.save(os.path.join(databaseDirectory, 'kinetics', 'libraries', name, 'reactions.py')) kineticsLibrary.saveDictionary(os.path.join(databaseDirectory, 'kinetics', 'libraries', name, 'dictionary.txt'))
import argparse import os from rmgpy.data.thermo import ThermoLibrary from rmgpy import settings if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('inputPath', metavar='INPUT', type=str, nargs=1, help='the input path of the RMG-Java thermo library directory') parser.add_argument('libraryName', metavar='OUTPUT', type=str, nargs=1, help='the libraryName for the RMG-Py format thermo library') args = parser.parse_args() inputPath = args.inputPath[0] libraryName = args.libraryName[0] library = ThermoLibrary() library.loadOld( dictstr = os.path.join(inputPath, 'Dictionary.txt'), treestr = '', libstr = os.path.join(inputPath, 'Library.txt'), numParameters = 12, numLabels = 1, pattern = False, ) library.name = libraryName # Save in Py format library.save(os.path.join(settings['database.directory'], 'thermo', 'libraries', libraryName+'.py'))
metavar='INPUT', type=str, nargs=1, help='the input path of the RMG-Java thermo library directory') parser.add_argument( 'libraryName', metavar='OUTPUT', type=str, nargs=1, help='the libraryName for the RMG-Py format thermo library') args = parser.parse_args() inputPath = args.inputPath[0] libraryName = args.libraryName[0] library = ThermoLibrary() library.loadOld( dictstr=os.path.join(inputPath, 'Dictionary.txt'), treestr='', libstr=os.path.join(inputPath, 'Library.txt'), numParameters=12, numLabels=1, pattern=False, ) library.name = libraryName # Save in Py format library.save( os.path.join(settings['database.directory'], 'thermo', 'libraries', libraryName + '.py'))
index=i + 1, item=reaction, data=reaction.kinetics, ) entry.longDesc = reaction.kinetics.comment kineticsLibrary.entries[i + 1] = entry kineticsLibrary.checkForDuplicates() kineticsLibrary.convertDuplicatesToMulti() # Assign history to all entries user = getUsername() # Pulls username from current git repository #user = '******'.format(name, email) # If not in git repository, then enter user information manually event = [ time.asctime(), user, 'action', '{0} imported this entry from the old RMG database.'.format(user) ] for label, entry in thermoLibrary.entries.iteritems(): entry.history.append(event) for label, entry in kineticsLibrary.entries.iteritems(): entry.history.append(event) # Save in Py format if not os.path.exists(outputDir): os.makedirs(os.path.join(self.path)) thermoLibrary.save(os.path.join(outputDir, 'chemkinThermoLibrary.py'), removeH=removeH) kineticsLibrary.save(os.path.join(outputDir, 'chemkinKineticsLibrary.py'), removeH=removeH)