Skip to content

Commit bf9ff08

Browse files
committed
Change the way in which libraryOrder is handled for kinetics database.
Prior to this, libraryOrder listed all the libraries used in order of priority, but did not indicate whether they are Seed mechs or reaction libraries. Now, indicate this by setting libraryOrder as a list of tuples in the format ('library_label', LibraryType), where LibraryType is set to either 'Reaction Library' or 'Seed'. That way we can avoid trying to double generating reactions for the 'Seed' library type (since they have already been added to the core). This also gives us more flexibility for treating the seeds and reaction libraries differently.
1 parent a896980 commit bf9ff08

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

rmgpy/data/kinetics/__init__.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def __init__(self):
6262
self.recommendedFamilies = {}
6363
self.families = {}
6464
self.libraries = {}
65-
self.libraryOrder = []
65+
self.libraryOrder = [] # a list of tuples in the format ('library_label', LibraryType),
66+
# where LibraryType is set to either 'Reaction Library' or 'Seed'.
6667
self.local_context = {
6768
'KineticsData': KineticsData,
6869
'Arrhenius': Arrhenius,
@@ -201,7 +202,7 @@ def loadLibraries(self, path, libraries=None):
201202
The `path` points to the folder of kinetics libraries in the database,
202203
and the libraries should be in files like :file:`<path>/<library>.py`.
203204
"""
204-
self.libraries = {}; self.libraryOrder = []
205+
self.libraries = {}
205206

206207
if libraries is not None:
207208
for library_name in libraries:
@@ -211,11 +212,12 @@ def loadLibraries(self, path, libraries=None):
211212
library = KineticsLibrary(label=library_name)
212213
library.load(library_file, self.local_context, self.global_context)
213214
self.libraries[library.label] = library
214-
self.libraryOrder.append(library.label)
215215
else:
216216
raise IOError("Couldn't find kinetics library {0}".format(library_file))
217-
assert (self.libraryOrder == libraries)
218-
else:# load all the libraries you can find
217+
# library order should've been set prior to this, with the given seed mechs and reaction libraries
218+
assert (len(self.libraryOrder) == len(libraries))
219+
else:# load all the libraries you can find (this cannot be activated in a normal RMG job. Only activated when loading the database for other purposes)
220+
self.libraryOrder = []
219221
for (root, dirs, files) in os.walk(os.path.join(path)):
220222
for f in files:
221223
name, ext = os.path.splitext(f)
@@ -226,7 +228,7 @@ def loadLibraries(self, path, libraries=None):
226228
library = KineticsLibrary(label=label)
227229
library.load(library_file, self.local_context, self.global_context)
228230
self.libraries[library.label] = library
229-
self.libraryOrder.append(library.label)
231+
self.libraryOrder.append((library.label,'Reaction Library'))
230232

231233
def save(self, path):
232234
"""
@@ -348,8 +350,11 @@ def generateReactionsFromLibraries(self, reactants, products, **options):
348350
searches the depository.
349351
"""
350352
reactionList = []
351-
for label in self.libraryOrder:
352-
reactionList.extend(self.generateReactionsFromLibrary(reactants, products, self.libraries[label], **options))
353+
for label, libraryType in self.libraryOrder:
354+
# Generate reactions from reaction libraries (no need to generate them from seeds)
355+
if libraryType == "Reaction Library":
356+
print 'generating reactions from library {0}'.format(label)
357+
reactionList.extend(self.generateReactionsFromLibrary(reactants, products, self.libraries[label], **options))
353358
return reactionList
354359

355360
def generateReactionsFromLibrary(self, reactants, products, library, **options):

rmgpy/data/rmg.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,20 @@ def loadKinetics(self,
139139
`path` points to the top-level folder of the RMG kinetics database.
140140
"""
141141
kineticsLibraries = []
142-
if reactionLibraries is not None and seedMechanisms is not None:
143-
kineticsLibraries.extend(seedMechanisms)
144-
kineticsLibraries.extend(reactionLibraries)
145-
elif reactionLibraries is not None and seedMechanisms is None:
146-
kineticsLibraries.extend(reactionLibraries)
147-
elif reactionLibraries is None and seedMechanisms is not None:
148-
kineticsLibraries.extend(seedMechanisms)
149-
else:
142+
libraryOrder = []
143+
if seedMechanisms is None and reactionLibraries is None:
150144
kineticsLibraries = None
151-
145+
if seedMechanisms is not None:
146+
for library in seedMechanisms:
147+
kineticsLibraries.append(library)
148+
libraryOrder.append((library,'Seed'))
149+
if reactionLibraries is not None:
150+
for library in reactionLibraries:
151+
kineticsLibraries.append(library)
152+
libraryOrder.append((library,'Reaction Library'))
153+
152154
self.kinetics = KineticsDatabase()
155+
self.kinetics.libraryOrder = libraryOrder
153156
self.kinetics.load(path,
154157
families=kineticsFamilies,
155158
libraries=kineticsLibraries,

0 commit comments

Comments
 (0)