Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 29 additions & 33 deletions rmgpy/data/kinetics/family.py
Original file line number Diff line number Diff line change
Expand Up @@ -3648,7 +3648,7 @@ def make_bm_rules_from_template_rxn_map(self, template_rxn_map, nprocs=1, Tref=1

index += 1

def cross_validate(self, folds=5, template_rxn_map=None, test_rxn_inds=None, T=1000.0, iters=0, random_state=1, ascend=False):
def cross_validate(self, folds=5, template_rxn_map=None, test_rxn_inds=None, T=1000.0, iters=0, random_state=1):
"""
Perform K-fold cross validation on an automatically generated tree at temperature T
after finding an appropriate node for kinetics estimation it will move up the tree
Expand Down Expand Up @@ -3704,47 +3704,43 @@ def cross_validate(self, folds=5, template_rxn_map=None, test_rxn_inds=None, T=1
if entry.parent:
entry = entry.parent

boo = True
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why boo? A more informative name would help. ANd I don't see where boo is ever set to anything but True? So what's this infinite loop about?
Does it mean while entry.parent: ?


while boo:
if entry.parent is None:
break
kin = self.rules.entries[entry.label][0].data
kinparent = self.rules.entries[entry.parent.label][0].data
err_parent = abs(kinparent.uncertainty.data_mean + kinparent.uncertainty.mu - kin.uncertainty.data_mean) + np.sqrt(2.0*kinparent.uncertainty.var/np.pi)
err_entry = abs(kin.uncertainty.mu) + np.sqrt(2.0*kin.uncertainty.var/np.pi)
if err_entry <= err_parent:
break
else:
entry = entry.parent

uncertainties[rxn] = self.rules.entries[entry.label][0].data.uncertainty

if not ascend:
L = list(set(template_rxn_map[entry.label]) - set(rxns_test))

if L != []:
if isinstance(L[0].kinetics,Arrhenius):
kinetics = ArrheniusBM().fit_to_reactions(L, recipe=self.forward_recipe.actions)
kinetics = kinetics.to_arrhenius(rxn.get_enthalpy_of_reaction(T))
L = list(set(template_rxn_map[entry.label]) - set(rxns_test))

if L != []:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a more Pythonic way to check empty list is by if not L?

if isinstance(L[0].kinetics, Arrhenius):
kinetics = ArrheniusBM().fit_to_reactions(L, recipe=self.forward_recipe.actions)
if kinetics.E0.value_si < 0.0 or len(L) == 1:
kinetics = average_kinetics([r.kinetics for r in L])
else:
kinetics = ArrheniusChargeTransferBM().fit_to_reactions(L, recipe=self.forward_recipe.actions)
kinetics = kinetics.to_arrhenius_charge_transfer(rxn.get_enthalpy_of_reaction(T))
k = kinetics.get_rate_coefficient(T)
errors[rxn] = np.log(k / krxn)
kinetics = kinetics.to_arrhenius(rxn.get_enthalpy_of_reaction(298.0))
else:
raise ValueError('only one piece of kinetics information in the tree?')
else:
boo = True
rlist = list(set(template_rxn_map[entry.label]) - set(rxns_test))
kinetics = _make_rule((self.forward_recipe.actions,rlist,T,1.0e3,"",[rxn.rank for rxn in rlist]))
logging.error("determining fold rate")
c = 1
while boo:
parent = entry.parent
if parent is None:
break
rlistparent = list(set(template_rxn_map[parent.label]) - set(rxns_test))
kineticsparent = _make_rule((self.forward_recipe.actions,rlistparent,T,1.0e3,"",[rxn.rank for rxn in rlistparent]))
err_parent = abs(kineticsparent.uncertainty.data_mean + kineticsparent.uncertainty.mu - kinetics.uncertainty.data_mean) + np.sqrt(2.0*kineticsparent.uncertainty.var/np.pi)
err_entry = abs(kinetics.uncertainty.mu) + np.sqrt(2.0*kinetics.uncertainty.var/np.pi)
if err_entry > err_parent:
entry = entry.parent
kinetics = kineticsparent
logging.error("recursing {}".format(c))
c += 1
kinetics = ArrheniusChargeTransferBM().fit_to_reactions(L, recipe=self.forward_recipe.actions)
if kinetics.E0.value_si < 0.0 or len(L) == 1:
kinetics = average_kinetics([r.kinetics for r in L])
else:
boo = False
kinetics = kinetics.to_arrhenius_charge_transfer(rxn.get_enthalpy_of_reaction(298.0))

kinetics = kinetics.to_arrhenius(rxn.get_enthalpy_of_reaction(T))
k = kinetics.get_rate_coefficient(T)
errors[rxn] = np.log(k / krxn)
else:
raise ValueError('only one piece of kinetics information in the tree?')

return errors, uncertainties

Expand Down