From 645578c3cea49f5efb27cc1b8f2d5098bbd4d4bf Mon Sep 17 00:00:00 2001 From: "Felipe S. S. Schneider" Date: Mon, 28 Feb 2022 19:49:11 -0300 Subject: [PATCH] Don't normalize equilibria if one rate is zero This is to avoid a (rare but possible) division-by-zero error. --- overreact/api.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/overreact/api.py b/overreact/api.py index 3942c445..9ea8d646 100644 --- a/overreact/api.py +++ b/overreact/api.py @@ -570,7 +570,15 @@ def get_k( pair = k[i : i + 2] _K = pair[0] / pair[1] - k[i : i + 2] = pair / pair.min() + denom = pair.min() + if denom == 0.0: + logger.warning( + "found half-equilibrium reaction with zero rate constant: " + "skipping equilibrium normalization" + ) + denom = 1.0 + + k[i : i + 2] = pair / denom assert np.isclose(_K, k[i] / k[i + 1]), ( f"reaction rate constants {k[i]} and {k[i + 1]} for " "equilibria could not be made to match the expected "