-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf1e20d
commit 47c48a1
Showing
4 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#= | ||
This code was generated by heta-compiler | ||
=# | ||
function get_MTKmodel() | ||
|
||
### Define independent and dependent variables | ||
|
||
@variables t | ||
__ruleVariables__ = @variables S(t) P(t) r1(t) | ||
__dynamicVariables__ = @variables _S_(t) _P_(t) | ||
|
||
### Define potential algebraic variables | ||
|
||
### Define parameters (constants and statics) | ||
__constParameters__ = @parameters Vmax Km | ||
__staticParameters__ = @parameters default_comp | ||
|
||
### Define an operator for the differentiation w.r.t. time | ||
__D__ = Differential(t) | ||
|
||
### ODE Equations ### | ||
__eqs__ = [ | ||
# extended rules | ||
S ~ _S_/ default_comp, | ||
P ~ _P_/ default_comp, | ||
r1 ~ Vmax * S / (Km + S) * default_comp, | ||
|
||
# ODEs | ||
__D__(_S_) ~ -r1, # dS/dt | ||
__D__(_P_) ~ r1, # dP/dt | ||
] | ||
|
||
### Continious events ### | ||
|
||
### Discrete events ### | ||
|
||
### Initialization ### | ||
|
||
__constValues__ = [ | ||
Vmax => 0.1, | ||
Km => 2.5, | ||
] | ||
|
||
__init__ = [ | ||
default_comp => 1e+0, | ||
S => 1e+1, | ||
P => 0e+0, | ||
r1 => Vmax * S / (Km + S) * default_comp, | ||
] | ||
|
||
__amountsInit__ = [ | ||
_S_ => S * default_comp, | ||
_P_ => P * default_comp, | ||
] | ||
|
||
### ODESystem definition ### | ||
__sys__ = ODESystem(__eqs__, t, [__dynamicVariables__; __ruleVariables__], [__constParameters__; __staticParameters__], | ||
name = :mm, | ||
discrete_events = [], | ||
defaults = [__constValues__; __init__; __amountsInit__] | ||
) | ||
|
||
return structural_simplify(__sys__), __amountsInit__, __constValues__ | ||
end | ||
|
||
__model__ = get_MTKmodel() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#= | ||
This code was generated by heta-compiler | ||
=# | ||
function get_MTKmodel() | ||
### Define independent and dependent variables | ||
|
||
@variables t | ||
__ruleVariables__ = @variables comp4(t) s1(t) s2(t) s3(t) s4(t) s5(t) r1(t) r2(t) r3(t) p1(t) s6(t) s7(t) s8(t) s9(t) s10(t) r4(t) r5(t) | ||
__dynamicVariables__ = @variables comp3(t) _s1_(t) _s2_(t) _s6_(t) _s7_(t) _s8_(t) | ||
|
||
### Define potential algebraic variables | ||
|
||
### Define parameters (constants and statics) | ||
__constParameters__ = @parameters k1 k2 k3 k4 k5 k6 | ||
__staticParameters__ = @parameters comp1 comp2 _s3_ _s4_ _s9_ | ||
|
||
### Define an operator for the differentiation w.r.t. time | ||
__D__ = Differential(t) | ||
|
||
### ODE Equations ### | ||
__eqs__ = [ | ||
# extended rules | ||
comp4 ~ 4e+0, | ||
s1 ~ _s1_/ comp1, | ||
s2 ~ _s2_/ comp1, | ||
s3 ~ _s3_/ comp2, | ||
s4 ~ _s4_/ comp2, | ||
s5 ~ 0e+0, | ||
r1 ~ k1 * s1 * comp1, | ||
r2 ~ k2 * s3 * comp2, | ||
r3 ~ k3 * s2 * comp1, | ||
p1 ~ k4 * comp3, | ||
s6 ~ _s6_, | ||
s7 ~ _s7_/ comp1, | ||
s8 ~ _s8_, | ||
s9 ~ _s9_, | ||
s10 ~ 0e+0, | ||
r4 ~ k5 * s6, | ||
r5 ~ k6 * s9, | ||
|
||
# ODEs | ||
__D__(comp3) ~ -p1, # dcomp3_/dt | ||
__D__(_s1_) ~ -r1, # ds1_/dt | ||
__D__(_s2_) ~ 2*r1-r3, # ds2_/dt | ||
__D__(_s6_) ~ -r4, # ds6_/dt | ||
__D__(_s7_) ~ r4, # ds7_/dt | ||
__D__(_s8_) ~ r4, # ds8_/dt | ||
] | ||
|
||
### Continious events ### | ||
|
||
### Discrete events ### | ||
|
||
### Initialization ### | ||
|
||
__constValues__ = [ | ||
k1 => 0.1, | ||
k2 => 0.2, | ||
k3 => 0.3, | ||
k4 => 0.4, | ||
k5 => 0.5, | ||
k6 => 0.6, | ||
] | ||
|
||
__init__ = [ | ||
comp1 => 1e+0, | ||
comp2 => 2.1, | ||
comp3 => 3e+0, | ||
comp4 => 4e+0, | ||
s1 => 1e+1, | ||
s2 => 0e+0, | ||
s3 => 1e+1, | ||
s4 => 1.1, | ||
s5 => 0e+0, | ||
r1 => k1 * s1 * comp1, | ||
r2 => k2 * s3 * comp2, | ||
r3 => k3 * s2 * comp1, | ||
p1 => k4 * comp3, | ||
s6 => 1e+1, | ||
s7 => 0e+0, | ||
s8 => 0e+0, | ||
s9 => 1e+0, | ||
s10 => 0e+0, | ||
r4 => k5 * s6, | ||
r5 => k6 * s9, | ||
] | ||
|
||
__amountsInit__ = [ | ||
_s1_ => s1 * comp1, | ||
_s2_ => s2 * comp1, | ||
_s3_ => s3 * comp2, | ||
_s4_ => s4 * comp2, | ||
_s6_ => s6, | ||
_s7_ => s7 * comp1, | ||
_s8_ => s8, | ||
_s9_ => s9, | ||
] | ||
|
||
### ODESystem definition ### | ||
__sys__ = ODESystem(__eqs__, t, [__dynamicVariables__; __ruleVariables__], [__constParameters__; __staticParameters__], | ||
name = :nameless, | ||
discrete_events = [], | ||
defaults = [__constValues__; __init__; __amountsInit__] | ||
) | ||
|
||
return structural_simplify(__sys__), __amountsInit__, __constValues__ | ||
end | ||
|
||
__model__ = get_MTKmodel() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using HetaSimulator, Plots | ||
using DiffEqCallbacks | ||
|
||
m = load_mtkmodel("$HetaSimulatorDir/cases/mtk/mm.jl") | ||
observed(m.sys) | ||
equations(m.sys) | ||
|
||
prob = ODEProblem(m.sys, m.u0map, (0.,250.), m.parammap) | ||
|
||
obs = [:r1, :_S_, :Km] | ||
# check if obs are present in sys | ||
saved_values = SavedValues(Float64, Vector{Float64}) | ||
saved_fun = (u,t,integrator) -> prob.f.observed(getproperty.((m.sys,), obs))(u, integrator.p, t) | ||
scb = SavingCallback(saved_fun, saved_values) | ||
|
||
s = solve(prob, Tsit5(), callback=scb, save_everystep=false, save_start=false, save_end = false) | ||
saved_values | ||
|
||
plot(HetaSimulator.DiffEqArray(saved_values.saveval, saved_values.t)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using HetaSimulator, Plots | ||
using DiffEqCallbacks | ||
|
||
m = load_mtkmodel("$HetaSimulatorDir/cases/mtk/nameless.jl") | ||
observed(m.sys) | ||
equations(m.sys) | ||
|
||
prob = ODEProblem(m.sys, m.u0map, (0.,60.), m.parammap) | ||
|
||
obs = [:r4, :_s1_, :comp1] | ||
# check if obs are present in sys | ||
saved_values = SavedValues(Float64, Vector{Float64}) | ||
saved_fun = (u,t,integrator) -> prob.f.observed(getproperty.((m.sys,), obs))(u, integrator.p, t) | ||
scb = SavingCallback(saved_fun, saved_values) | ||
|
||
s = solve(prob, Tsit5(), callback=scb, save_everystep=false, save_start=false, save_end = false) | ||
saved_values | ||
|
||
plot(HetaSimulator.DiffEqArray(saved_values.saveval, saved_values.t)) |