Skip to content

Commit

Permalink
Don't normalize equilibria if one rate is zero
Browse files Browse the repository at this point in the history
This is to avoid a (rare but possible) division-by-zero error.
  • Loading branch information
schneiderfelipe committed Feb 28, 2022
1 parent 92c7cb0 commit 645578c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion overreact/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down

0 comments on commit 645578c

Please sign in to comment.