Skip to content
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

Full system balancing #851

Merged
merged 7 commits into from
May 23, 2024
Merged

Full system balancing #851

merged 7 commits into from
May 23, 2024

Conversation

TorkelE
Copy link
Member

@TorkelE TorkelE commented May 20, 2024

Creates a function balance_system, which takes a ReactionSystem and returns a version with all its reactions balanced.

rs = @reaction_network begin
    @species C(t) O(t) H(t)
    @compounds begin
        H2(t) = 2H
        CH4(t) = C + 4H
        O2(t) = 2O
        CO2(t) = C + 2O
        H2O(t) = 2H + O
    end
    1.0, C + H2 --> CH4
    2.0, CH4 + O2 --> CO2 + H2O
end
rs_balanced = balance_system(rs)

error("Could not balance reaction `$rx`, unable to create a balanced `ReactionSystem`.")
end
if length(brxs) > 1
error("Infinite number of balanced reactions possible for reaction ($rx) are possible. No method for automatically generating a valid reaction is currently implemented in `balance_system`.")
Copy link
Member Author

Choose a reason for hiding this comment

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

I was unsure how to actually construct a proper reaction from the base. Had a look at some outputs but didn't really understand. At some point we should support it, but not really a priority.

Copy link
Member Author

Choose a reason for hiding this comment

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

Although we probably could raise a issue that it should be fixed

Copy link
Member

Choose a reason for hiding this comment

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

We should probably update these error messages as they are imprecise (the old one too). The issue isn't an infinite number of solutions (there are always an infinite number), it is whether there are multiple independent solution vectors (i.e. the dimension of the solution space is greater than one). So the error messages should probably be updated to reflect this.

Copy link
Member

Choose a reason for hiding this comment

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

Modulo that comment this is fine with me.

Copy link
Member Author

Choose a reason for hiding this comment

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

That make sense, I will update with new error/warning message (new and old ones)

@TorkelE
Copy link
Member Author

TorkelE commented May 21, 2024

New messages:

waring:
"The space of possible balanced versions of the reaction ($reaction) is greater than 1. This prevents the selection of a single appropriate balanced reaction. Instead, a basis for balanced reactions is returned. Note that we do not check if they preserve the set of substrates and products from the original reaction."

error (for system-level balancing)
"The space of possible balanced versions of the reaction ($reaction) is greater than 1. This prevents the selection of a single appropriate balanced reaction. No method to, in this case, automatically generate a valid reaction is currently implemented in balance_system.""

Copy link
Member

@isaacsas isaacsas left a comment

Choose a reason for hiding this comment

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

If tests pass happy for you to merge this.

@TorkelE TorkelE merged commit d7a18c4 into master May 23, 2024
5 of 6 checks passed
@TorkelE TorkelE deleted the full_system_balancing branch May 23, 2024 16:41
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.

2 participants