def chemkin_to_kinetic_lib(chem_path, dict_path, name, save_path='', use_chemkin_names=True): """ Convert a CHEMKIN file into a RMG kinetic library given species dictionary and the library name. Args: chem_path (str): The path to the CHEMKIN file dict_path (str): The path to a species dictionary name (str): The name of the new library save_path (str): The path to the saving directory. By default, the library will be saved to RMG-database repository use_chemkin_names (bool): Use the original CHEMKIN species name """ # Load the reactions from the CHEMKIN FILE logging.info('Loading CHEMKIN file %s with species dictionary %s' % (chem_path, dict_path)) _, rxns = load_chemkin_file(chem_path, dict_path, use_chemkin_names=use_chemkin_names) kinetic_lib = KineticsLibrary(name=name) kinetic_lib.entries = {} # Create new entries for i in range(len(rxns)): rxn = rxns[i] entry = Entry( index=i + 1, label=str(rxn), item=rxn, data=rxn.kinetics, ) try: entry.long_desc = 'Originally from reaction library: ' + \ rxn.library + "\n" + rxn.kinetics.comment except AttributeError: entry.long_desc = rxn.kinetics.comment kinetic_lib.entries[i + 1] = entry logging.info('Adding reaction %s in to the kinetic library %s' % (entry.label, name)) # Check for duplicates and convert them to multiArrhenius / multiPdepArrehenius kinetic_lib.check_for_duplicates(mark_duplicates=True) kinetic_lib.convert_duplicates_to_multi() # Save the library if not save_path: save_path = os.path.join(settings['database.directory'], 'kinetics', 'libraries') try: os.makedirs(os.path.join(save_path, name)) except: pass logging.info('Saving the kinetic library to %s' % (os.path.join(save_path, name))) kinetic_lib.save(os.path.join(save_path, name, 'reactions.py')) kinetic_lib.save_dictionary(os.path.join(save_path, name, 'dictionary.txt'))
def create_kinetic_lib(path): """ Create an empty kinetic library and an empty species dictionary according to the path Args: path (str): The non-existing file path to create kinetic libraries and species dictionary """ lib_path = os.path.join(path, 'reactions.py') if os.path.isfile(lib_path): logging.warn('File %s is already existed, not overwriting.' % (lib_path)) # Create an empty kinetics library file lib = KineticsLibrary() lib.save(lib_path) dict_path = os.path.join(path, 'dictionary.txt') with open(dict_path, 'w+'): pass
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.kinetics import KineticsLibrary 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 kinetics library directory') parser.add_argument('libraryName', metavar='OUTPUT', type=str, nargs=1, help='the libraryName for the RMG-Py format kinetics library') args = parser.parse_args() inputPath = args.inputPath[0] libraryName = args.libraryName[0] library = KineticsLibrary() library.loadOld(inputPath) try: os.makedirs(os.path.join(settings['database.directory'], 'kinetics', 'libraries', libraryName)) except: pass # Save in Py format library.save(os.path.join(settings['database.directory'], 'kinetics', 'libraries', libraryName, 'reactions.py')) library.saveDictionary(os.path.join(settings['database.directory'], 'kinetics', 'libraries', libraryName,'dictionary.txt'))
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'))
nargs=1, help='the input path of the RMG-Java kinetics library directory') parser.add_argument( 'outputPath', metavar='OUTPUT', type=str, nargs=1, help= 'the libraryname.py output file for the RMG-Py format kinetics library' ) args = parser.parse_args() inputPath = args.inputPath[0] outputPath = args.outputPath[0] library = KineticsLibrary() library.loadOld(inputPath) # Assign history to 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 library.entries.iteritems(): entry.history.append(event) # Save in Py format library.save(outputPath)
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'))
""" This script imports an individual RMG-Java kinetics library from a local directory and saves the output kinetics library py file into a path of the user's choosing. This py file can be added to the input/kinetics/libraries folder to be used as an RMG-Py kinetics library. """ import argparse import time from rmgpy.data.kinetics import KineticsLibrary from importOldDatabase import getUsername if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('inputPath', metavar='INPUT', type=str, nargs=1, help='the input path of the RMG-Java kinetics library directory') parser.add_argument('outputPath', metavar='OUTPUT', type=str, nargs=1, help='the libraryname.py output file for the RMG-Py format kinetics library') args = parser.parse_args() inputPath = args.inputPath[0] outputPath = args.outputPath[0] library = KineticsLibrary() library.loadOld(inputPath) # Save in Py format library.save(outputPath)
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)