Skip to content

Commit d1fc2f9

Browse files
rwestclaude
andcommitted
Improve diagnostics for "Family had N reactants?" kinetics test failure
The dispatch else-branch in kinetics_check_sample_can_react raised a terse ValueError ("Family had N reactants?: ...") that named neither the family nor the underlying cause, making CI failures hard to diagnose. This branch is reached whenever the number of reactant roots that produced at least one usable sample molecule does not match the family template, and it raised before the logging loop ran, discarding any per-sample errors already queued. Add an explicit check comparing the number of reactant roots that yielded samples against the family template's reactant count. On a mismatch, append a descriptive, per-root message logged together with the queued per-sample errors (and then raises the standard "Error Occurred. See log for details."), naming the family and the specific reactant root(s) with no usable sample. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ea19324 commit d1fc2f9

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

test/database/databaseTest.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,7 +1577,22 @@ def make_error_message(reactants, message=""):
15771577
output += "\n" + s.to_adjacency_list(label=s.to_smiles())
15781578
return output
15791579

1580-
if len(sample_reactants) == 1 == len(family.forward_template.reactants):
1580+
expected_reactants = [str(r) for r in family.forward_template.reactants]
1581+
roots_with_samples = [str(k) for k in sample_reactants.keys()]
1582+
roots_without_samples = [r for r in expected_reactants if r not in roots_with_samples]
1583+
if len(sample_reactants) != len(family.forward_template.reactants):
1584+
# One or more reactant roots produced no usable sample molecule (every candidate was
1585+
# forbidden by is_molecule_forbidden, or raised UnexpectedChargeError/
1586+
# ImplicitBenzeneError during make_sample_molecule). Record a descriptive error so it
1587+
# is logged below alongside any per-sample errors, instead of raising opaquely here.
1588+
test1.append(
1589+
f"In family {family_name}, {len(roots_without_samples)} reactant root(s) produced "
1590+
f"no usable sample molecule: {roots_without_samples}. The family template expects "
1591+
f"{len(expected_reactants)} reactant(s) {expected_reactants}; only these root(s) "
1592+
f"yielded samples: {roots_with_samples}. Check the group definitions for the "
1593+
f"missing reactant root(s)."
1594+
)
1595+
elif len(sample_reactants) == 1:
15811596
reactants = list(sample_reactants.values())[0]
15821597
for reactant in reactants:
15831598
try:
@@ -1670,7 +1685,13 @@ def make_error_message(reactants, message=""):
16701685
species = rmgpy.species.Species(index=1, molecule=[molecule])
16711686
species.generate_resonance_structures()
16721687
else:
1673-
raise ValueError(f"Family had {len(sample_reactants)} reactants?: " f"{', '.join(map(str,sample_reactants.keys())) }")
1688+
# Reactant count matches the template but is not 1, 2, or 3 (RMG only supports up to
1689+
# trimolecular). This is not expected for any well-formed family.
1690+
raise ValueError(
1691+
f"In family {family_name}, the number of sampled reactant roots "
1692+
f"({len(sample_reactants)}) matches the template reactant count but is not 1, 2, "
1693+
f"or 3, which is unexpected: {roots_with_samples}."
1694+
)
16741695

16751696
# print out entries skipped from exception we can't currently handle
16761697
if skipped:

0 commit comments

Comments
 (0)