Skip to content

Commit

Permalink
Merge pull request #2 from paulflang/aj/extra_dispatches_piracy
Browse files Browse the repository at this point in the history
remove String dispatches for MTK constructors
  • Loading branch information
paulflang authored Jun 17, 2021
2 parents dfa7d1c + f05324a commit a5a2324
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ SBML = "e5567a89-2604-4b09-9718-f5f78e97c3bb"
julia = "1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "OrdinaryDiffEq"]
24 changes: 0 additions & 24 deletions src/reactionsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ function ModelingToolkit.ReactionSystem(model::SBML.Model; kwargs...) # Todo: r
ReactionSystem(rxs,Catalyst.DEFAULT_IV,species,params; kwargs...)
end

""" ReactionSystem constructor """
function ModelingToolkit.ReactionSystem(sbmlfile::String; kwargs...)
model = readSBML(sbmlfile,SBML.convert_simplify_math)
ReactionSystem(model; kwargs...)
end

""" ODESystem constructor """
function ModelingToolkit.ODESystem(model::SBML.Model; kwargs...)
rs = ReactionSystem(model; kwargs...)
Expand All @@ -27,24 +21,6 @@ function ModelingToolkit.ODESystem(model::SBML.Model; kwargs...)
convert(ODESystem, rs, defaults=defaults)
end

""" ODESystem constructor """
function ModelingToolkit.ODESystem(sbmlfile::String; kwargs...)
model = readSBML(sbmlfile)
ODESystem(model; kwargs...)
end

""" ODEProblem constructor """
function ModelingToolkit.ODEProblem(model::SBML.Model,tspan;kwargs...) # PL: Todo: add u0 and parameters argument
odesys = ODESystem(model)
ODEProblem(odesys, [], tspan; kwargs...)
end

""" ODEProblem constructor """
function ModelingToolkit.ODEProblem(sbmlfile::String,tspan;kwargs...) # PL: Todo: add u0 and parameters argument
odesys = ODESystem(sbmlfile)
ODEProblem(odesys, [], tspan; kwargs...)
end

""" Check if conversion to ReactionSystem is possible """
function checksupport(model::SBML.Model)
for s in values(model.species)
Expand Down
10 changes: 5 additions & 5 deletions test/reactionsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@named rs = ReactionSystem(MODEL1)
isequal(nameof(rs), :rs)

rs = ReactionSystem(sbmlfile)
rs = ReactionSystem(readSBML(sbmlfile))
# println(Catalyst.get_eqs(rs))
# println(ModelingToolkit.Reaction[ModelingToolkit.Reaction(c1*k1*2.0*s1*2.0*s2, [s1, s2], [s1s2], [1., 1.], [1.]; use_only_rate=true)])
@test isequal(Catalyst.get_eqs(rs), ModelingToolkit.Reaction[ModelingToolkit.Reaction(0.25c1*k1*s1*s2, [s1, s2], [s1s2], [1., 1.], [1.]; use_only_rate=true)])
Expand All @@ -34,7 +34,7 @@
@named rs = ReactionSystem(MODEL1)
isequal(nameof(rs), :rs)

rs = ReactionSystem(joinpath("data","reactionsystem_05.xml")) # Contains reversible reaction
rs = ReactionSystem(readSBML(joinpath("data","reactionsystem_05.xml"))) # Contains reversible reaction
@test isequal(Catalyst.get_eqs(rs),
ModelingToolkit.Reaction[
ModelingToolkit.Reaction(c1*k1*s1*s2, [s1,s2], [s1s2],
Expand Down Expand Up @@ -62,7 +62,7 @@
isequal(nameof(odesys), :odesys)
@test_nowarn structural_simplify(odesys)

odesys = ODESystem(sbmlfile)
odesys = ODESystem(readSBML(sbmlfile))
trueeqs = Equation[Differential(t)(s1) ~ -0.25c1 * k1 * s1 * s2,
Differential(t)(s1s2) ~ 0.25c1 * k1 * s1 * s2,
Differential(t)(s2) ~ -0.25c1 * k1 * s1 * s2]
Expand All @@ -79,11 +79,11 @@
@test_nowarn ODEProblem(odesys, [], [0., 1.], [])

# Test ODEProblem
oprob = ODEProblem(MODEL1, [0., 1.])
oprob = ODEProblem(ODESystem(MODEL1), [0., 1.])
sol = solve(oprob, Tsit5())
@test isapprox(sol.u, [[1.], [2.]])

@test_nowarn ODEProblem(sbmlfile, [0., 1.])
@test_nowarn ODEProblem(ODESystem(readSBML(sbmlfile)), [0., 1.])

# Test checksupport
@test_nowarn SBML.checksupport(MODEL1)
Expand Down

0 comments on commit a5a2324

Please sign in to comment.