Skip to content

Commit 9dde345

Browse files
rwestJacksonBurns
andcommitted
Consolidate stoichiometry checks
...and change an error type. Co-Authored-By: Jackson Burns <jwburns@mit.edu> Co-authored-by: Jackson Burns <33505528+JacksonBurns@users.noreply.github.com>
1 parent 85e7e81 commit 9dde345

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

rmgpy/data/kinetics/family.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2708,18 +2708,15 @@ def get_labeled_reactants_and_products(self, reactants, products, relabel_atoms=
27082708
template_reactants = [x.item for x in template.reactants]
27092709
else:
27102710
template_reactants = [x.item for x in template.reactants]
2711-
2711+
if (num_reactants := len(reactants0)) != (num_template := len(template_reactants)):
2712+
raise ValueError(f"Reaction has {num_reactants} reactants but template has {num_template} reactants.")
27122713
if len(reactants0) == 1:
2713-
if len(template_reactants) != 1:
2714-
raise ValueError(f"Reaction has {len(reactants0)} reactants but template has {len(template_reactants)} reactants.")
27152714
molecule = reactants0[0]
27162715
mappings = self._match_reactant_to_template(molecule, template_reactants[0])
27172716
mappings = [[map0] for map0 in mappings]
27182717
num_mappings = len(mappings)
27192718
reactant_structures = [molecule]
27202719
elif len(reactants0) == 2:
2721-
if len(template_reactants) != 2:
2722-
raise ValueError(f"Reaction has {len(reactants0)} reactants but template has {len(template_reactants)} reactants.")
27232720
molecule_a = reactants0[0]
27242721
molecule_b = reactants0[1]
27252722
# get mappings in forward direction
@@ -2734,8 +2731,6 @@ def get_labeled_reactants_and_products(self, reactants, products, relabel_atoms=
27342731
reactant_structures = [molecule_a, molecule_b]
27352732
num_mappings = len(mappings_a) * len(mappings_b)
27362733
elif len(reactants0) == 3:
2737-
if len(template_reactants) != 3:
2738-
raise ValueError(f"Reaction has {len(reactants0)} reactants but template has {len(template_reactants)} reactants.")
27392734
molecule_a = reactants0[0]
27402735
molecule_b = reactants0[1]
27412736
molecule_c = reactants0[2]
@@ -2750,7 +2745,7 @@ def get_labeled_reactants_and_products(self, reactants, products, relabel_atoms=
27502745
reactant_structures = [molecule_a, molecule_b, molecule_c]
27512746
num_mappings = len(mappings_a) * len(mappings_b) * len(mappings_c)
27522747
else:
2753-
raise NotImplementedError('You have {0} reactants, which is unexpected!'.format(len(reactants)))
2748+
raise ValueError('You have {0} reactants, which is unexpected!'.format(len(reactants)))
27542749

27552750
for mapping in mappings:
27562751
try:

0 commit comments

Comments
 (0)