Skip to content

Get variable stoichiometries fully working - #1342

Merged
luciansmith merged 18 commits into
developfrom
support-variable-stoich
Jul 31, 2026
Merged

Get variable stoichiometries fully working#1342
luciansmith merged 18 commits into
developfrom
support-variable-stoich

Conversation

@luciansmith

Copy link
Copy Markdown

They sort of half-work now; add new tests to more fully check everything.

Also comment out 'we don't support this' error message, and claim we support those tags in the SBML Test Suite.
* Include a new stoichiometryMap
* New resetRateRuleStoichPtr
* resetAll (in Python) includes stoichiometries.
All new tests now pass: the reset functions properly reset stoichiometries, and setting them also works.
We need a new minor version number for rr, since we now write out stoichiometryMap to the save/load state.
A reaction like J0: A + A -> B has one stoichiometry for A in the reaction J0 (-2), but it comes from two different values (1 and 1).  If one or more of those stoichiometries have IDs, things get very complicated very quickly.  Hopefully, we can figure out a way to handle this.

First, a design thing:  Get/SetValue("stoich(A, J0)") will now always *get* the stoichiometry of the species in the reaction.  This might be negative of GetValue("n"), even if 'n' is the stoichiometry value of A, if it's a reactant.  This also will hold true for reactions with multiple speciesReferences to the same species.

Also, do better throwing LLVM exceptions (we were getting a lot of 'invalid file' errors that had nothing to do with invalid files).
Need storage for initial stoichiometries, and all the 'multiReactantProduct' stoichiometries before we can start using them.

Also set up some new test cases for the whole thing.

Went back and forth with Claude for ages before finally getting clarity on setting/getting stoichiometries by name ('n') vs. by position ('stoich(S1, J0)').  The upshot is that name will always give you the literal value of that stoichiometry, and by position will always give you the stoichiometry matrix value for the species/reaction combination.  So it can be opposite signs for the same root value!
Also, don't throw when getting stoichiometries when conserved moieties have been turned on, only when setting them.
Better name than multiReactantAndOrProduct, also.  (And just before doing a ton more with the elements.)
Stores and retrieves and sets the value of stoichiometries that must be combined with other stoichiometries to get the final stoichiometry of a species in a particular reaction (i.e. A + A -> B + 2 B).  In particular, when they're named, they get to be manipulated elsewhere in the SBML model, such as with a rate rule or assignment rule, or even with an event assignment or initial assignment.
…with events.

This fixes all the SBML Test Suite tests that were failing.
In addition, some other tests were deliberately checking to make sure they threw, since we didn't support it.  But now we do!
The previous version must have had some sort of slight change?  Anyway.
It's now by reaction instead of by species.
@luciansmith
luciansmith merged commit 717573e into develop Jul 31, 2026
9 checks passed
@luciansmith
luciansmith deleted the support-variable-stoich branch July 31, 2026 18:45
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.

1 participant