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'))
def loadOld(self, path): """ Load an old-style RMG kinetics library from the location `path`. """ path = os.path.abspath(path) self.loadOldDictionary(os.path.join(path, 'species.txt'), pattern=False) species = dict([(label, Species(label=label, molecule=[entry.item])) for label, entry in self.entries.iteritems()]) # Add common bath gases (Ar, Ne, He, N2) if not already present for label, smiles in [('AR', '[Ar]'), ('HE', '[He]'), ('NE', '[Ne]'), ('N2', 'N#N')]: if label not in species: molecule = Molecule().fromSMILES(smiles) spec = Species(label=label, molecule=[molecule]) species[label] = spec reactions = [] reactions.extend( self.__loadOldReactions(os.path.join(path, 'reactions.txt'), species)) if os.path.exists(os.path.join(path, 'pdepreactions.txt')): pdep_reactions = self.__loadOldReactions( os.path.join(path, 'pdepreactions.txt'), species) # RMG-Py likes otherwise equivalent PDep and non-pdep reactions to be marked as duplicates self.markValidDuplicates(reactions, pdep_reactions) reactions.extend(pdep_reactions) self.entries = {} for index, reaction in enumerate(reactions): entry = Entry( index=index + 1, item=reaction, data=reaction.kinetics, ) entry.longDesc = reaction.kinetics.comment reaction.kinetics.comment = '' self.entries[index + 1] = entry reaction.kinetics = None self.checkForDuplicates() self.convertDuplicatesToMulti()
def loadOld(self, path): """ Load an old-style RMG kinetics library from the location `path`. """ path = os.path.abspath(path) self.loadOldDictionary( os.path.join(path, 'species.txt'), pattern=False) species = dict([(label, Species(label=label, molecule=[entry.item])) for label, entry in self.entries.iteritems()]) # Add common bath gases (Ar, Ne, He, N2) if not already present for label, smiles in [('Ar', '[Ar]'), ('He', '[He]'), ('Ne', '[Ne]'), ('N2', 'N#N')]: if label not in species: molecule = Molecule().fromSMILES(smiles) spec = Species(label=label, molecule=[molecule]) species[label] = spec reactions = [] reactions.extend( self.__loadOldReactions( os.path.join(path, 'reactions.txt'), species)) if os.path.exists(os.path.join(path, 'pdepreactions.txt')): pdep_reactions = self.__loadOldReactions( os.path.join(path, 'pdepreactions.txt'), species) # RMG-Py likes otherwise equivalent PDep and non-pdep reactions to be marked as duplicates self.markValidDuplicates(reactions, pdep_reactions) reactions.extend(pdep_reactions) self.entries = {} for index, reaction in enumerate(reactions): entry = Entry( index=index + 1, item=reaction, data=reaction.kinetics, ) entry.longDesc = reaction.kinetics.comment reaction.kinetics.comment = '' self.entries[index + 1] = entry reaction.kinetics = None self.checkForDuplicates() self.convertDuplicatesToMulti()
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 #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
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
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
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 # 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:
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 #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():