From d81a2c8849c017bfe95f0678b03a8a1ffa1c89e9 Mon Sep 17 00:00:00 2001 From: Jackson Burns Date: Tue, 3 Dec 2024 13:07:30 -0500 Subject: [PATCH] squash as well --- rmgpy/molecule/resonance.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rmgpy/molecule/resonance.py b/rmgpy/molecule/resonance.py index d3ef2d0a7b..3cb0bad9b8 100644 --- a/rmgpy/molecule/resonance.py +++ b/rmgpy/molecule/resonance.py @@ -1101,7 +1101,7 @@ def _clar_optimization(mol, recursion_constraints=None, clar_number=-1, save_ord if status == 2: # infeasible raise RuntimeError("All valid Clar formulae have been enumerated!") else: - raise RuntimeError(f"Clar optimization failed (Exit Code {status}) for an unexpected reason: {result.message}") + raise RuntimeError(f"Optimization failed (Exit Code {status}) for an unexpected reason '{result.message}'") _clar_number, solution = -result.fun, result.x @@ -1109,6 +1109,11 @@ def _clar_optimization(mol, recursion_constraints=None, clar_number=-1, save_ord if _clar_number == 0: return [] + # on later runs, non-integer solutions occur - branching might be able to find actual solutions, + # but we just call it good enough here + if any([x != 1 and x != 0 for x in solution]): + raise RuntimeError("Optimization obtained a non-integer solution - no more formulae will be enumerated.") + # first solution, so the result should be an upper limit if clar_number == -1: clar_number = _clar_number