2929from rmgpy .data .kinetics .common import UndeterminableKineticsError
3030
3131
32- def getKineticsDepository (family , depositoryLabel , missingGroups ):
32+ def getKineticsDepository (family , depositoryLabel ):
3333
3434 depository = None
3535 for tempDepository in family .depositories :
@@ -42,14 +42,18 @@ def getKineticsDepository(family, depositoryLabel, missingGroups):
4242 approxKinetics = {}
4343
4444 for key , entry in depository .entries .iteritems ():
45- reaction = entry .item
46- template = family .getReactionTemplate (reaction )
47- exactKinetics [key ]= entry .data
48- approxKinetics [key ]= family .rules .estimateKinetics (template )[0 ]
45+ try :
46+ reaction = entry .item
47+ template = family .getReactionTemplate (reaction )
48+ exactKinetics [key ]= entry .data
49+ approxKinetics [key ]= family .rules .estimateKinetics (template )[0 ]
50+ except Exception as e :
51+ print entry .item
52+ print e
4953
5054 return exactKinetics , approxKinetics
5155
52- def getKineticsLeaveOneOut (family , missingGroups ):
56+ def getKineticsLeaveOneOut (family ):
5357 """
5458 Performs the leave one out test on a family. It returns a dictionary of
5559 the original exact nodes and a dictionary of the new averaged nodes.
@@ -63,9 +67,9 @@ def getKineticsLeaveOneOut(family, missingGroups):
6367 index = 0
6468 for entryKey in entryKeys :
6569 index += 1
66- template = family . getReactionTemplate ( family . rules . entries [ entryKey ][ 0 ]. item )
67-
68- print entryKey , [ templateEntry . label for templateEntry in template ], index
70+
71+ nodes = entryKey . split ( ';' )
72+ template = [ family . groups . entries [ node ] for node in nodes ]
6973 exactKinetics [entryKey ], exactKineticsEntry = family .rules .estimateKinetics (template )
7074
7175 familyCopy = copy .deepcopy (family )
@@ -77,15 +81,18 @@ def getKineticsLeaveOneOut(family, missingGroups):
7781 return exactKinetics , approxKinetics
7882
7983
80- #calculates the parity values for each
84+
8185def calculateParity (exactKineticModel , approxKineticModel , T ):
86+ '''
87+ Calculates the parity values between two sets of kinetics evaluated at temperature T
88+ '''
8289 exact = exactKineticModel .getRateCoefficient (T )
8390 approx = approxKineticModel .getRateCoefficient (T )
8491
8592 return float (approx )/ float (exact )
8693
8794
88- def analyzeForParity (exactKinetics , approxKinetics , T = 1000 , cutoff = 0 ):
95+ def analyzeForParity (exactKinetics , approxKinetics , T = 1000.0 , cutoff = 0. 0 ):
8996 """
9097 Creates a parity plot from the exactKinetics and approxKinetics (dictionarys with
9198 kineticModels are entries). Uses the median temperature of the exactKinetics to
@@ -109,7 +116,7 @@ def calculateQ(parityData):
109116 """
110117 Calculates the predicted root mean square error
111118 """
112- Q = 0
119+ Q = 0.0
113120 for key , value in parityData .iteritems ():
114121 Q += (math .log10 (value [0 ]/ value [1 ]))** 2
115122 return (Q / len (parityData ))** 0.5
@@ -201,17 +208,15 @@ def NISTExact(FullDatabase, trialDir):
201208# familyName='Disproportionation'
202209# allFamilyNames=[familyName]
203210
204- missingGroups = []
205211 QDict = {}
206- familiesWithErrors = []
212+
207213 for familyName in allFamilyNames :
208214 family = FullDatabase .kinetics .families [familyName ]
209215 print "Processing" , familyName + '...' , '(' + str (len (family .rules .entries )) + ' nodes)'
210216 if len (family .rules .entries ) < 2 :
211217 print ' Skipping' , familyName , ': only has one node...'
212218 else :
213- ##getKineticsDepository
214- exactKinetics , approxKinetics , missingGroups = getKineticsDepository (family , 'NIST' , missingGroups )
219+ exactKinetics , approxKinetics = getKineticsDepository (family , 'NIST' )
215220
216221 #prune for exact matches only
217222 keysToRemove = []
@@ -222,7 +227,7 @@ def NISTExact(FullDatabase, trialDir):
222227 for key in keysToRemove :
223228 del approxKinetics [key ]
224229
225- parityData = analyzeForParity (exactKinetics , approxKinetics , None , 8 )
230+ parityData = analyzeForParity (exactKinetics , approxKinetics , cutoff = 8.0 )
226231
227232 if len (parityData )< 2 :
228233 print ' Skipping' , familyName , ': only one node was calculated...'
@@ -246,12 +251,7 @@ def NISTExact(FullDatabase, trialDir):
246251 for key , value in QDict .iteritems ():
247252 csvwriter .writerow ([key , value ])
248253
249- with open (os .path .join (trialDir , 'missingNodes.csv' ), 'wb' ) as csvfile :
250- csvwriter = csv .writer (csvfile )
251- for missingNode in missingGroups :
252- csvwriter .writerow (missingNode )
253254
254- print 'These families had errors:' , familiesWithErrors
255255
256256
257257
@@ -271,17 +271,16 @@ def leaveOneOut(FullDatabase, trialDir):
271271# allFamilyNames=[familyName]
272272 allFamilyNames = FullDatabase .kinetics .families .keys ()
273273
274- missingGroups = []
275274 QDict = {}
276- familiesWithErrors = []
275+
277276 for familyName in allFamilyNames :
278277 family = FullDatabase .kinetics .families [familyName ]
279278 print "Processing" , familyName + '...' , '(' + str (len (family .rules .entries )) + ' nodes)'
280279 if len (family .rules .entries ) < 2 :
281280 print ' Skipping' , familyName , ': only has one node...'
282281 else :
283- exactKinetics , approxKinetics , missingGroups = getKineticsLeaveOneOut (family , missingGroups )
284- parityData = analyzeForParity (exactKinetics , approxKinetics , None , 8 )
282+ exactKinetics , approxKinetics = getKineticsLeaveOneOut (family )
283+ parityData = analyzeForParity (exactKinetics , approxKinetics , cutoff = 8.0 )
285284
286285 if len (parityData )< 2 :
287286 print ' Skipping' , familyName , ': only one node was calculated...'
@@ -304,13 +303,7 @@ def leaveOneOut(FullDatabase, trialDir):
304303 csvwriter = csv .writer (csvfile )
305304 for key , value in QDict .iteritems ():
306305 csvwriter .writerow ([key , value ])
307-
308- with open (os .path .join (trialDir , 'missingNodes.csv' ), 'wb' ) as csvfile :
309- csvwriter = csv .writer (csvfile )
310- for missingNode in missingGroups :
311- csvwriter .writerow (missingNode )
312306
313- print 'These families had errors:' , familiesWithErrors
314307 return
315308
316309
@@ -328,8 +321,12 @@ def leaveOneOut(FullDatabase, trialDir):
328321 trialDir = os .path .join (settings ['database.directory' ],'..' ,'testing' ,'eval' )
329322 if not os .path .exists (trialDir ):
330323 os .makedirs (trialDir )
331-
324+ print 'Evaluating the NIST Kinetics against the RMG estimates...'
332325 NISTExact (FullDatabase , trialDir )
326+
327+ print 'Counting the rate rules in the families...'
333328 countNodesAll (FullDatabase , trialDir )
329+
330+ print 'Performing the leave on out test on the kinetics families...'
334331 leaveOneOut (FullDatabase , trialDir )
335332
0 commit comments