Пример #1
0
def read_spc_dict_from_path(dict_path):
    """
    Read species dictionary given the dictionary file path
    
    Args:
        dict_path (str): the absolute path to species dictionary
    
    Returns:
        spc_dict (OrderedDict): an ordered dictionary has all species information
    """
    lib = KineticsLibrary()
    spc_dict = lib.get_species(dict_path)
    return spc_dict
Пример #2
0
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
Пример #3
0
def read_kinetic_lib_from_path(lib_path,
                               kinetic_db,
                               overwrite=False,
                               create=False):
    """
    Read RMG kinetic library given its file path. The species dictionary should
    be included under the same directory.

    Args:
        lib_path (str): Path to thermo library file
        kinetic_db (RMG KineticsDatabase): RMG  database object
    """
    if not os.path.exists(lib_path) and create:
        create_kinetic_lib(os.path.dirname(lib_path))
        lib = KineticsLibrary()
        kinetic_db.libraries[lib_path] = lib
        kinetic_db.library_order.append(lib_path)
        logging.info(
            'Created kinetics library {1} at {0} ...'.format(
                os.path.split(lib_path)[0],
                os.path.split(lib_path)[1]), )
    elif lib_path not in kinetic_db.library_order or overwrite:
        lib = KineticsLibrary()
        try:
            lib.load(lib_path,
                     KineticsDatabase().local_context,
                     KineticsDatabase().global_context)
        except:
            logging.error('The library file %s is not vaild.' % (lib_path))
        else:
            lib.label = lib_path
            kinetic_db.libraries[lib.label] = lib
            kinetic_db.library_order.append(lib.label)
            logging.info(
                'Loading kinetics library {1} from {0} ...'.format(
                    os.path.split(lib_path)[0],
                    os.path.split(lib_path)[1]), )
    else:
        logging.warning('The library %s has already been loaded' % (lib_path))
Пример #4
0
     species = speciesList[i]
     rdkitmol = species.molecule[0].toRDKitMol(removeHs=False)
     species.molecule = [Molecule().fromRDKitMol(rdkitmol)]#[0].toAdjacencyList(removeH=False)
     print species.molecule[0].toAdjacencyList(removeH = removeH)
     if species.thermo:
         thermoLibrary.loadEntry(index = i + 1,
                                 label = species.label,
                                 molecule = species.molecule[0].toAdjacencyList(removeH = removeH),
                                 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                    
 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
Пример #5
0
"""

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'))
Пример #6
0
    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),
            item=reaction,
            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
Пример #7
0
    # load thermo library entries
    thermoLibrary = ThermoLibrary()
    for i in range(len(speciesList)): 
        species = speciesList[i]
        if species.thermo:
            thermoLibrary.loadEntry(index = i + 1,
                                    label = species.label,
                                    molecule = species.molecule[0].toAdjacencyList(),
                                    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                    
    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()
        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)
positional arguments:
INPUT       the input path of the RMG-Java kinetics library directory
LIBRARYNAME      the libraryname for the RMG-Py format kinetics library

"""

import argparse
import os
from rmgpy.data.kinetics import KineticsLibrary
          
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)
    
        
    # Save in Py format    
    library.save(os.path.join('input/kinetics/libraries/', libraryName, 'reactions.py'))
    library.saveDictionary(os.path.join('input/kinetics/libraries/', libraryName, 'dictionary.txt'))
Пример #10
0
    # load thermo library entries
    thermoLibrary = ThermoLibrary(name=name)
    for i in range(len(speciesList)): 
        species = speciesList[i]
        if species.thermo:
            thermoLibrary.loadEntry(index = i + 1,
                                    label = species.label,
                                    molecule = species.molecule[0].toAdjacencyList(),
                                    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                    
    kineticsLibrary = KineticsLibrary(name=name)
    kineticsLibrary.entries = {}
    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
    
Пример #11
0
"""
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)
Пример #12
0
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'))
Пример #13
0
                            ]  #[0].toAdjacencyList(removeH=False)
        print species.molecule[0].toAdjacencyList(removeH=removeH)
        if species.thermo:
            thermoLibrary.loadEntry(
                index=i + 1,
                label=species.label,
                molecule=species.molecule[0].toAdjacencyList(removeH=removeH),
                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
    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