예제 #1
0
def save_kinetics_lib(rxn_list, path, name, lib_long_desc):
    """
    Save an RMG kinetics library.

    Args:
        rxn_list (list): Entries are Reaction object instances for which kinetics will be saved.
        path (str): The base folder in which the kinetic library will be saved.
        name (str): The library name.
        lib_long_desc (str): A multiline string with relevant description.
    """
    entries = dict()
    if rxn_list:
        for i, rxn in enumerate(rxn_list):
            if rxn.kinetics is not None:
                entry = Entry(index=i,
                              item=rxn,
                              data=rxn.kinetics,
                              label=rxn.label)
                entries[i + 1] = entry
            else:
                logging.warning(
                    f'Reaction {rxn.label} did not contain any kinetic data and was omitted from the '
                    f'kinetics library.')
        kinetics_library = KineticsLibrary(name=name,
                                           long_desc=lib_long_desc,
                                           auto_generated=True)
        kinetics_library.entries = entries
        if os.path.exists(path):
            shutil.rmtree(path)
        try:
            os.makedirs(path)
        except OSError:
            pass
        kinetics_library.save(os.path.join(path, 'reactions.py'))
        kinetics_library.save_dictionary(os.path.join(path, 'dictionary.txt'))
예제 #2
0
def save_kinetics_lib(rxn_list, path, name, lib_long_desc):
    """
    Save an RMG kinetics library of all reactions in `rxn_list` in the supplied `path`
    `rxn_list` is a list of ARCReaction objects
    `name` is the library's name (or project's name)
    `long_desc` is a multiline string with level of theory description
    """
    entries = dict()
    if rxn_list:
        for i, rxn in enumerate(rxn_list):
            if rxn.kinetics is not None:
                if len(rxn.rmg_reaction.reactants):
                    reactants = rxn.rmg_reaction.reactants
                    products = rxn.rmg_reaction.products
                elif rxn.r_species.mol_list is not None:
                    reactants = [Species(molecule=arc_spc.mol_list) for arc_spc in rxn.r_species]
                    products = [Species(molecule=arc_spc.mol_list) for arc_spc in rxn.p_species]
                elif rxn.r_species.mol is not None:
                    reactants = [Species(molecule=[arc_spc.mol]) for arc_spc in rxn.r_species]
                    products = [Species(molecule=[arc_spc.mol]) for arc_spc in rxn.p_species]
                else:
                    reactants = [Species(molecule=[arc_spc.xyz_mol]) for arc_spc in rxn.r_species]
                    products = [Species(molecule=[arc_spc.xyz_mol]) for arc_spc in rxn.p_species]
                rxn.rmg_reaction.reactants = reactants
                rxn.rmg_reaction.products = products
                entry = Entry(
                    index=i,
                    item=rxn.rmg_reaction,
                    data=rxn.kinetics,
                    label=rxn.label)
                rxn.ts_species.make_ts_report()
                entry.longDesc = rxn.ts_species.ts_report + '\n\nOptimized TS geometry:\n' + rxn.ts_species.final_xyz
                rxn.rmg_reaction.kinetics = rxn.kinetics
                rxn.rmg_reaction.kinetics.comment = str('')
                entries[i+1] = entry
            else:
                logging.warning('Reaction {0} did not contain any kinetic data and was omitted from the kinetics'
                                ' library.'.format(rxn.label))
        kinetics_library = KineticsLibrary(name=name, longDesc=lib_long_desc, autoGenerated=True)
        kinetics_library.entries = entries
        lib_path = os.path.join(path, 'kinetics', '')
        if os.path.exists(lib_path):
            shutil.rmtree(lib_path)
        try:
            os.makedirs(lib_path)
        except OSError:
            pass
        kinetics_library.save(os.path.join(lib_path, 'reactions.py'))
        kinetics_library.saveDictionary(os.path.join(lib_path, 'dictionary.txt'))
예제 #3
0
파일: main.py 프로젝트: xiaoruiDong/RMG-Py
    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
예제 #4
0
    def getLibraries(self):

        name = 'kineticsjobs'
                
        speciesList = self.speciesDict.values()
        reactionList = self.reactionDict.values()

        # remove duplicate species
        for rxn in reactionList:
            for i,rspc in enumerate(rxn.reactants):
                for spc in speciesList:
                    if spc.isIsomorphic(rspc):
                        rxn.reactants[i] = spc
                        break
            for i,rspc in enumerate(rxn.products):
                for spc in speciesList:
                    if spc.isIsomorphic(rspc):
                        rxn.products[i] = spc
                        break
        del_inds = []
        for i,spc1 in enumerate(speciesList):
            for j,spc2 in enumerate(speciesList):
                if j>i and spc1.isIsomorphic(spc2):
                    del_inds.append(j)
        
        for j in sorted(del_inds)[::-1]:
            del speciesList[j]
            
        thermoLibrary = ThermoLibrary(name=name)
        for i,species in enumerate(speciesList): 
            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,autoGenerated=True)
        kineticsLibrary.entries = {}
        for i,reaction in enumerate(reactionList):      
            entry = Entry(
                    index = i+1,
                    label = reaction.toLabeledStr(),
                    item = reaction,
                    data = reaction.kinetics,
                )

            if reaction.kinetics is not None:
                if hasattr(reaction,'library') and reaction.library:
                    entry.longDesc = 'Originally from reaction library: ' +\
                                     reaction.library + "\n" + reaction.kinetics.comment
                else:
                    entry.longDesc = reaction.kinetics.comment
            
            kineticsLibrary.entries[i+1] = entry
        
        kineticsLibrary.label = name
        
        return thermoLibrary,kineticsLibrary,speciesList