Skip to content

Commit 6589177

Browse files
Merge pull request #163 from SciML/pl/support_catalystv14
Support Catalyst v14
2 parents 18ebab7 + 5b38d0d commit 6589177

File tree

12 files changed

+36
-33
lines changed

12 files changed

+36
-33
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"
1111
[compat]
1212
Aqua = "0.8"
1313
CSV = "0.10.5"
14-
Catalyst = "13"
14+
Catalyst = "14"
1515
DataFrames = "1"
1616
Downloads = "1"
17-
ModelingToolkit = "8.51"
17+
ModelingToolkit = "9"
1818
OrdinaryDiffEq = "6.42"
1919
Plots = "1.11"
2020
SBML = "1.4.4"
21-
SBMLToolkitTestSuite = "0.0.3"
21+
SBMLToolkitTestSuite = "0.0.4"
2222
SafeTestsets = "0.1"
2323
Sundials = "4.14"
2424
SymbolicUtils = "1, 2"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
SBMLToolkit.jl is a lightweight tool to import models specified in the Systems Biology Markup Language (SBML) into the Julia SciML ecosystem. There are multiple ways to specify the same model in SBML. Please help us improving SBMLToolkit.jl by creating a GitHub issue if you experience errors when converting your SBML model.
1313

14-
SBMLToolkit uses the [SBML.jl](https://github.com/LCSB-BioCore/SBML.jl) wrapper of the [libSBML](https://model.caltech.edu/software/libsbml/) library to lower dynamical SBML models into dynamical systems. If you would like to import BioNetGen models use the `writeSBML()` export function or import the `.net` file with [ReactionNetworkImporters.jl](https://github.com/SciML/ReactionNetworkImporters.jl). For constrained-based modeling, please have a look at [COBREXA.jl](https://github.com/LCSB-BioCore/COBREXA.jl). We also recommend trying [SBMLImporter.jl](https://github.com/sebapersson/SBMLImporter.jl) (Pros: respects directionality of events, outputs concentrations instead of amounts. Cons: imports ODESystems, i.e. does not interface with Catalyst).
14+
SBMLToolkit uses the [SBML.jl](https://github.com/LCSB-BioCore/SBML.jl) wrapper of the [libSBML](https://model.caltech.edu/software/libsbml/) library to lower dynamical SBML models into completed dynamical systems. If you would like to import BioNetGen models use the `writeSBML()` export function or import the `.net` file with [ReactionNetworkImporters.jl](https://github.com/SciML/ReactionNetworkImporters.jl). For constrained-based modeling, please have a look at [COBREXA.jl](https://github.com/LCSB-BioCore/COBREXA.jl). We also recommend trying [SBMLImporter.jl](https://github.com/sebapersson/SBMLImporter.jl). While SBMLToolkit.jl has a slightly cleaner interface, SBMLImporter.jl respects directionality of events, can output concentrations or amounts, and provides better simulation performance for models including time-triggered events and SBML `piecewise` expressions.
1515

1616
## Installation
1717

@@ -46,7 +46,7 @@ rs = readSBML("my_model.xml", ReactionSystemImporter())
4646

4747
One common case where this is useful is if you want to run stochastic instead of ODE simulations.
4848

49-
In the very unlikely case that you need fine-grained control over the SBML import, you can create an SBML.jl `Model` (we strongly recommend manually running `SBMLToolkit.checksupport_file("my_model.xml")` before)
49+
In the very unlikely case that you need fine-grained control over the SBML import, you can create an SBML.jl `Model` (we strongly recommend manually running `checksupport_file("my_model.xml")` before)
5050

5151
```julia
5252
using SBML

src/SBMLToolkit.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ include("utils.jl")
1515

1616
export ReactionSystem, ODESystem
1717
export readSBML, readSBMLFromString, set_level_and_version, convert_simplify_math,
18-
convert_promotelocals_expandfuns
18+
convert_promotelocals_expandfuns, checksupport_file
1919
export DefaultImporter, ReactionSystemImporter, ODESystemImporter
2020

2121
end

src/reactions.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Infer forward and reverse components of bidirectional kineticLaw
3030
"""
3131
function get_unidirectional_components(bidirectional_math)
3232
bm = ModelingToolkit.value(bidirectional_math) # Symbolics.tosymbol(bidirectional_math)
33-
bm = simplify(bm; expand = true)
33+
bm = expand(simplify(bm))
3434
if !SymbolicUtils.isadd(bm)
3535
@warn "Cannot separate bidirectional kineticLaw `$bidirectional_math` to forward and reverse part. Setting forward to `$bidirectional_math` and reverse to `0`. Stochastic simulations will be inexact."
3636
return (bidirectional_math, Num(0))
@@ -168,7 +168,7 @@ function get_massaction(kl::Num, reactants::Union{Vector{Num}, Nothing},
168168

169169
function check_args(::Val{true}, x::SymbolicUtils.BasicSymbolic{Real})
170170
for arg in SymbolicUtils.arguments(x)
171-
if isnan(check_args(arg)) || isequal(arg, Catalyst.DEFAULT_IV)
171+
if isnan(check_args(arg)) || isequal(arg, default_t())
172172
return NaN
173173
end
174174
end

src/systems.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ See also [`Model`](@ref) and [`ODESystemImporter`](@ref).
3939
"""
4040
function SBML.readSBML(sbmlfile::String, ::ODESystemImporter;
4141
include_zero_odes::Bool = true, kwargs...) # Returns an MTK.ODESystem
42-
convert(ODESystem, readSBML(sbmlfile, ReactionSystemImporter(), kwargs...),
42+
odesys = convert(ODESystem, readSBML(sbmlfile, ReactionSystemImporter(), kwargs...),
4343
include_zero_odes = include_zero_odes)
44+
complete(odesys)
4445
end
4546

4647
"""
@@ -90,11 +91,12 @@ function Catalyst.ReactionSystem(model::SBML.Model; kwargs...) # Todo: requires
9091
defs = ModelingToolkit._merge(defs, kwargs[:defaults])
9192
kwargs = filter(x -> !isequal(first(x), :defaults), kwargs)
9293
end
93-
ReactionSystem([rxs..., algrules..., raterules_subs..., obsrules_rearranged...],
94+
rs = ReactionSystem([rxs..., algrules..., raterules_subs..., obsrules_rearranged...],
9495
IV, first.(u0map), first.(parammap);
9596
defaults = defs, name = gensym(:SBML),
9697
continuous_events = get_events(model),
9798
combinatoric_ratelaws = false, kwargs...)
99+
return complete(rs) # Todo: maybe add a `complete=True` kwarg
98100
end
99101

100102
"""
@@ -107,7 +109,8 @@ See also [`ReactionSystem`](@ref).
107109
function ModelingToolkit.ODESystem(model::SBML.Model; include_zero_odes::Bool = true,
108110
kwargs...)
109111
rs = ReactionSystem(model; kwargs...)
110-
convert(ODESystem, rs; include_zero_odes = include_zero_odes)
112+
odesys = convert(ODESystem, rs; include_zero_odes = include_zero_odes)
113+
complete(odesys)
111114
end
112115

113116
function get_mappings(model::SBML.Model)

src/utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Conversion to symbolics
2-
const IV = Catalyst.DEFAULT_IV
3-
const D = Differential(IV)
2+
const IV = default_t()
3+
const D = default_time_deriv()
44
symbolicsRateOf(x) = D(x)
55
const symbolics_mapping = Dict(SBML.default_function_mapping...,
66
"rateOf" => symbolicsRateOf)

test/events.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using SBMLToolkit
22
using Catalyst, SBMLToolkitTestSuite
33
using Test
44

5-
const IV = Catalyst.DEFAULT_IV
5+
const IV = default_t()
66
@parameters compartment
77
@species S1(IV) S2(IV)
88

test/reactions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using Test
44

55
cd(@__DIR__)
66
sbmlfile = joinpath("data", "reactionsystem_01.xml")
7-
const IV = Catalyst.DEFAULT_IV
7+
const IV = default_t()
88
@parameters k1, c1
99
@species s1(IV), s2(IV), s1s2(IV)
1010

test/rules.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using SBML, SBMLToolkitTestSuite
33
using Catalyst, ModelingToolkit, OrdinaryDiffEq
44
using Test
55

6-
const IV = Catalyst.DEFAULT_IV
6+
const IV = default_t()
77
@parameters k1, compartment
88
@species S1(IV), S2(IV)
99

@@ -24,7 +24,7 @@ o_true = [S1 ~ 7 * compartment]
2424
sbml, _, _ = SBMLToolkitTestSuite.read_case("00031") # rateRule
2525
m = readmodel(sbml)
2626
a, o, r = SBMLToolkit.get_rules(m)
27-
r_true = [Differential(IV)(S1) ~ 7 * compartment]
27+
r_true = [default_time_deriv()(S1) ~ 7 * compartment]
2828
@test isequal(r, r_true)
2929

3030
sbml, _, _ = SBMLToolkitTestSuite.read_case("00039") # algebraicRule
@@ -59,16 +59,16 @@ m = readmodel(sbml)
5959
vc = SBMLToolkit.get_volume_correction(m, "S1")
6060
@test isnothing(vc)
6161

62-
# tests that non-constant parameters become states
62+
# tests that non-constant parameters become variables
6363
sbml, _, _ = SBMLToolkitTestSuite.read_case("00033")
6464
m = readmodel(sbml)
6565
@named sys = ODESystem(m)
6666
@species k1(IV)
67-
@test isequal(k1, states(sys)[end])
67+
@test isequal(k1, unknowns(sys)[end])
6868

69-
# tests that non-constant compartments become states
69+
# tests that non-constant compartments become variables
7070
sbml, _, _ = SBMLToolkitTestSuite.read_case("00051") # hOSU="true" species
7171
m = readmodel(sbml)
7272
@named sys = ODESystem(m)
7373
@species C(IV)
74-
@test isequal(C, states(sys)[end])
74+
@test isequal(C, unknowns(sys)[end])

test/systems.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using Test
44

55
cd(@__DIR__)
66
sbmlfile = joinpath("data", "reactionsystem_01.xml")
7-
const IV = Catalyst.DEFAULT_IV
7+
const IV = default_t()
88
@parameters k1, c1
99
@species s1(IV), s2(IV), s1s2(IV)
1010

@@ -49,7 +49,7 @@ rs = ReactionSystem(MODEL1)
4949
@test isequal(Catalyst.get_eqs(rs),
5050
Catalyst.Reaction[Catalyst.Reaction(k1, nothing, [s1], nothing, [1.0])])
5151
@test isequal(Catalyst.get_iv(rs), IV)
52-
@test isequal(Catalyst.get_states(rs), [s1])
52+
@test isequal(Catalyst.get_species(rs), [s1])
5353
@test isequal(Catalyst.get_ps(rs), [k1, c1])
5454
@named rs = ReactionSystem(MODEL1)
5555
isequal(nameof(rs), :rs)
@@ -59,7 +59,7 @@ rs = ReactionSystem(readSBML(sbmlfile))
5959
Catalyst.Reaction[Catalyst.Reaction(k1 / c1, [s1, s2], [s1s2], [1.0, 1.0],
6060
[1.0])])
6161
@test isequal(Catalyst.get_iv(rs), IV)
62-
@test isequal(Catalyst.get_states(rs), [s1, s1s2, s2])
62+
@test isequal(Catalyst.get_species(rs), [s1, s1s2, s2])
6363
@test isequal(Catalyst.get_ps(rs), [k1, c1])
6464
@named rs = ReactionSystem(MODEL1)
6565
isequal(nameof(rs), :rs)
@@ -71,18 +71,18 @@ rs = ReactionSystem(MODEL2) # Contains reversible reaction
7171
Catalyst.Reaction(k1, nothing, [s1],
7272
nothing, [1])])
7373
@test isequal(Catalyst.get_iv(rs), IV)
74-
@test isequal(Catalyst.get_states(rs), [s1])
74+
@test isequal(Catalyst.get_species(rs), [s1])
7575
@test isequal(Catalyst.get_ps(rs), [k1, c1])
7676

7777
@test convert(ModelingToolkit.ODESystem, rs) isa ODESystem
7878
@test structural_simplify(convert(ModelingToolkit.ODESystem, rs)) isa ODESystem
7979

8080
# Test ODESystem constructor
8181
odesys = ODESystem(MODEL1)
82-
trueeqs = Equation[Differential(IV)(s1) ~ k1]
82+
trueeqs = Equation[default_time_deriv()(s1) ~ k1]
8383
@test isequal(Catalyst.get_eqs(odesys), trueeqs)
8484
@test isequal(Catalyst.get_iv(odesys), IV)
85-
@test isequal(Catalyst.get_states(odesys), [s1])
85+
@test isequal(Catalyst.get_unknowns(odesys), [s1])
8686
@test isequal(Catalyst.get_ps(odesys), [k1, c1])
8787
u0 = [s1 => 1.0]
8888
par = [k1 => 1.0, c1 => 2.0]
@@ -93,12 +93,12 @@ isequal(nameof(odesys), :odesys)
9393

9494
odesys = ODESystem(readSBML(sbmlfile))
9595
m = readSBML(sbmlfile)
96-
trueeqs = Equation[Differential(IV)(s1) ~ -(k1 * s1 * s2) / c1,
97-
Differential(IV)(s1s2) ~ (k1 * s1 * s2) / c1,
98-
Differential(IV)(s2) ~ -(k1 * s1 * s2) / c1]
96+
trueeqs = Equation[default_time_deriv()(s1) ~ -((k1 * s1 * s2) / c1),
97+
default_time_deriv()(s1s2) ~ (k1 * s1 * s2) / c1,
98+
default_time_deriv()(s2) ~ -((k1 * s1 * s2) / c1)]
9999
@test isequal(Catalyst.get_eqs(odesys), trueeqs)
100100
@test isequal(Catalyst.get_iv(odesys), IV)
101-
@test isequal(Catalyst.get_states(odesys), [s1, s1s2, s2])
101+
@test isequal(Catalyst.get_unknowns(odesys), [s1, s1s2, s2])
102102
@test isequal(Catalyst.get_ps(odesys), [k1, c1])
103103
u0 = [s1 => 2 * 1.0, s2 => 2 * 1.0, s1s2 => 2 * 1.0]
104104
par = [k1 => 1.0, c1 => 2.0]

0 commit comments

Comments
 (0)