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

PR to sync with latest breaking SBML change to Reaction #26

Closed
wants to merge 4 commits into from

Conversation

anandijain
Copy link
Contributor

@anandijain anandijain commented Aug 6, 2021

There is something going on with negative stoichs.

The tests will fail since a new release of SBML hasn't happened.

I also probably messed up the boundary condition handling and something in reversible reactions.

Everything passes locally but 7 failures that all either look like one of the following:

Test Failed at /Users/anand/.julia/dev/SBMLToolkit/test/reactionsystem.jl:24
  Expression: isequal(Catalyst.get_eqs(rs), ModelingToolkit.Reaction[ModelingToolkit.Reaction(k1, nothing, [s1], nothing, [1.0])])
   Evaluated: isequal(Reaction[Reaction{Any, Float64}(k1, Term{Real, Nothing}[s1(t)], Any[], [1.0], Float64[], Pair{Any, Float64}[s1(t) => -1.0], true, nothing)], Reaction[Reaction{Any, Float64}(k1, Any[], Term{Real, Nothing}[s1(t)], Float64[], [1.0], Pair{Any, Float64}[s1(t) => 1.0], false, nothing)])

Test Failed at /Users/anand/.julia/dev/SBMLToolkit/test/reactionsystem.jl:129
  Expression: isequal((nothing, [s1], nothing, [1.0]), SBMLToolkit.getreagents(REACTION1.reactants, REACTION1.products, MODEL1))
   Evaluated: isequal((nothing, Num[s1(t)], nothing, [1.0]), (Num[s1(t)], nothing, [1.0], nothing))

@paulflang understandable if you don't have time to review but if you get the chance

src/reactionsystem.jl Outdated Show resolved Hide resolved
@anandijain
Copy link
Contributor Author

Now there are two test failures, but I'm not sure what wen't wrong here.

Model to MTK conversions: Test Failed at /Users/anand/.julia/dev/SBMLToolkit/test/reactionsystem.jl:140
  Expression: isequal(([ncs], [ncs], [1.0], [1.0]), SBMLToolkit.getreagents(constreac.reactants, constreac.products, constmod))
   Evaluated: isequal((Term{Real, Nothing}[constspec(t)], Term{Real, Nothing}[constspec(t)], [1.0], [1.0]), (nothing, Num[constspec(t)], nothing, [1.0]))

Model to MTK conversions: Test Failed at /Users/anand/.julia/dev/SBMLToolkit/test/reactionsystem.jl:141
  Expression: isequal((nothing, nothing, nothing, nothing), SBMLToolkit.getreagents(constreac.reactants, constreac.products, constmod))
   Evaluated: isequal((nothing, nothing, nothing, nothing), (nothing, Num[constspec(t)], nothing, [1.0]))

See the tests where I updated reactions, I'd appreciate a double check that I converted the netstoich to reactants and products correctly.

I'm also wondering what I need to do for the boundary condition stuff, since I effectively removed that logic

@paulflang
Copy link
Member

I'm also wondering what I need to do for the boundary condition stuff, since I effectively removed that logic

This is the reason why the tests are failing iiuc. If boundary_condition=true the species does not change in concentration when the reaction happens. I discussed with Sam how to best implement this without messing up auto-detection from mass action kinetics. The solution is very simple: wherever boundary_condition=true for a reactant, we add the reactant and its stoichiometry to the products and vice versa. You'll have to restructure your code a little to implement this correctly.

Comment on lines -154 to -156
if model.species[k].boundary_condition != true
push!(products, create_var(k,Catalyst.DEFAULT_IV))
push!(pstoich, v)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@paulflang okay yeah I think i see. what is the reason we don't push to reactants if bc is true here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i guess because that would double things up right

Copy link
Member

Choose a reason for hiding this comment

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

if bc is true we need to make sure that the stoichiometry of the species in question is the same on the right and left side of the reaction equation. however, we never want to modify the left hand side. this is because the left hand side can be used to determine if a reaction is mass action kinetics (i.e. A + B -> C gives mass action kinetic kAB, A -> B gives mass action kinetic k*A, etc.). This leaves us with the option to modify the product side. But this is already taken care of in line 149. In line 154 we only need to take care of the default case of bc = false, which is that reaction products are actually produced.

@anandijain
Copy link
Contributor Author

this latest commit only fails on

Model to MTK conversions: Test Failed at /Users/anand/.julia/dev/SBMLToolkit/test/reactionsystem.jl:141
  Expression: isequal((nothing, nothing, nothing, nothing), SBMLToolkit.getreagents(constreac.reactants, constreac.products, constmod))
   Evaluated: isequal((nothing, nothing, nothing, nothing), (Num[constspec(t)], Num[constspec(t)], [1.0], [1.0]))

I don't see why thouhg

@paulflang
Copy link
Member

This is because you call SBMLToolkit.getreagents(constreac.reactants, constreac.products, constmod when you should call SBMLToolkit.getreagents(constreac.reactants, constreac.products, constmod; rev=true. The rev=true just swaps reagents and products.

The reaction is X -> nothing, k*X. Then the reversible reaction is nothing -> X, k. But since species is constant we modify to X -> X, k*X and nothing -> nothing, k for fw and rv reaction, respectively. Note that we are never allowed to modify the substrates of a reaction, as we need to be able to determine whether the kineticLaw of a reaction follows mass action kinetics.

@anandijain
Copy link
Contributor Author

thanks for the help paul #28 is a much cleaner copy of this

@anandijain anandijain closed this Aug 9, 2021
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