Skip to content

filter check_mass_balance zeros with a floating point comparison #1436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from

Conversation

jedforrest
Copy link

@jedforrest jedforrest commented Apr 15, 2025

Fixes #1435 by filtering out zeros in the reaction element dictionary using math.isclose.

@@ -1451,7 +1451,7 @@ def check_mass_balance(self) -> Dict[str, float]:
for element, amount in metabolite.elements.items():
reaction_element_dict[element] += coefficient * amount
# filter out 0 values
return {k: v for k, v in reaction_element_dict.items() if v != 0}
return {k: v for k, v in reaction_element_dict.items() if not isclose(v, 0.0, abs_tol=1e-12)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. Maybe the tolerance could be taken from Configuration().tolerance instead like the other tolerances?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] check_mass_balance fails for floating point coefficients
2 participants