From 5318813a237d805b0abca4cb390c12b0dc80fefe Mon Sep 17 00:00:00 2001 From: Hao-Wei Pang Date: Mon, 14 Jun 2021 12:16:41 -0400 Subject: [PATCH 1/2] fix spc doesn't have metal attribute error --- rmgpy/data/kinetics/family.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rmgpy/data/kinetics/family.py b/rmgpy/data/kinetics/family.py index 0bbcc79ec5..64e4236422 100644 --- a/rmgpy/data/kinetics/family.py +++ b/rmgpy/data/kinetics/family.py @@ -4241,14 +4241,14 @@ def fix_labels_mol(mol, root_labels): rrev.is_forward = False if estimate_thermo: - for r in rrev.reactants: - if r.thermo is None: - therm_spc = deepcopy(r) + for rev_react in rrev.reactants: + if rev_react.thermo is None: + therm_spc = deepcopy(rev_react) therm_spc.generate_resonance_structures() - if r.metal: - r.thermo = tdb.get_thermo_data(therm_spc, metal_to_scale_to=r.metal) + if metal: + rev_react.thermo = tdb.get_thermo_data(therm_spc, metal_to_scale_to=metal) else: - r.thermo = tdb.get_thermo_data(therm_spc) + rev_react.thermo = tdb.get_thermo_data(therm_spc) rxns[i] = rrev if self.own_reverse and get_reverse: From 1c12a9a869c3579792753012f369cf22d7be0086 Mon Sep 17 00:00:00 2001 From: Hao-Wei Pang Date: Mon, 14 Jun 2021 12:58:18 -0400 Subject: [PATCH 2/2] add function get_reactant_thermo to avoid deepcopy --- rmgpy/data/kinetics/family.py | 63 +++++++++++++++-------------------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/rmgpy/data/kinetics/family.py b/rmgpy/data/kinetics/family.py index 64e4236422..3f61aba750 100644 --- a/rmgpy/data/kinetics/family.py +++ b/rmgpy/data/kinetics/family.py @@ -4051,6 +4051,28 @@ def fix_labels_mol(mol, root_labels): if atm.label not in root_labels: atm.label = '' + def get_reactant_thermo(reactant,metal): + """ + Save the label of reactant and reapply them after thermo estimation to avoid deepcopying + """ + label_dict = reactant.molecule[0].get_all_labeled_atoms() + mol = reactant.molecule[0] + reactant.molecule[0].clear_labeled_atoms() + reactant.generate_resonance_structures() + if metal: + thermo = tdb.get_thermo_data(reactant, metal_to_scale_to=metal) + else: + thermo = tdb.get_thermo_data(reactant) + reactant.molecule = [mol] + + for key,atm in label_dict.items(): + if isinstance(atm,list): + for a in atm: + a.label = key + else: + atm.label = key + return thermo + if self.own_reverse and get_reverse: rev_rxns = [] rkeys = list(self.reverse_map.keys()) @@ -4093,34 +4115,11 @@ def fix_labels_mol(mol, root_labels): metal = entry.metal + entry.facet for j, react in enumerate(entry.item.reactants): if rxns[i].reactants[j].thermo is None: - label_dict = react.molecule[0].get_all_labeled_atoms() - mol = react.molecule[0] - react.molecule[0].clear_labeled_atoms() - react.generate_resonance_structures() - rxns[i].reactants[j].thermo = tdb.get_thermo_data(react, metal_to_scale_to=metal) - react.molecule = [mol] - for key,atm in label_dict.items(): - if isinstance(atm,list): - for a in atm: - a.label = key - else: - atm.label = key + rxns[i].reactants[j].thermo = get_reactant_thermo(react,metal) for j, react in enumerate(entry.item.products): if rxns[i].products[j].thermo is None: - label_dict = react.molecule[0].get_all_labeled_atoms() - mol = react.molecule[0] - react.molecule[0].clear_labeled_atoms() - react.generate_resonance_structures() - rxns[i].products[j].thermo = tdb.get_thermo_data(react, metal_to_scale_to=metal) - react.molecule = [mol] - for key,atm in label_dict.items(): - if isinstance(atm,list): - for a in atm: - a.label = key - else: - atm.label = key - + rxns[i].products[j].thermo = get_reactant_thermo(react,metal) rxns[i].kinetics = entry.data rxns[i].rank = entry.rank @@ -4199,12 +4198,7 @@ def fix_labels_mol(mol, root_labels): if estimate_thermo: for rev_react in rrev.reactants: if rev_react.thermo is None: - therm_spc = deepcopy(rev_react) - therm_spc.generate_resonance_structures() - if metal: - rev_react.thermo = tdb.get_thermo_data(therm_spc, metal_to_scale_to=metal) - else: - rev_react.thermo = tdb.get_thermo_data(therm_spc) + rev_react.thermo = get_reactant_thermo(rev_react,metal) rev_rxns.append(rrev) @@ -4243,12 +4237,7 @@ def fix_labels_mol(mol, root_labels): if estimate_thermo: for rev_react in rrev.reactants: if rev_react.thermo is None: - therm_spc = deepcopy(rev_react) - therm_spc.generate_resonance_structures() - if metal: - rev_react.thermo = tdb.get_thermo_data(therm_spc, metal_to_scale_to=metal) - else: - rev_react.thermo = tdb.get_thermo_data(therm_spc) + rev_react.thermo = get_reactant_thermo(rev_react,metal) rxns[i] = rrev if self.own_reverse and get_reverse: