Example #1
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'))
     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
 user = getUsername()    # Pulls username from current git repository
        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

    # Mark as duplicates where there are mixed pressure dependent and non-pressure dependent duplicate kinetics
Example #4
0
    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
    
    # Mark as duplicates where there are mixed pressure dependent and non-pressure dependent duplicate kinetics