I am testing ways to code Matlab/Simbiology concepts (e.g. compartments, repeated assignments) in Julia/Catalyst and I would appreciate both general pointers on where to find more information as well as figuring out one piece of this puzzle in the code below. (error pasted as comment)
# test example to create a simple model with two compartments
using Catalyst
using DifferentialEquations
using Plots
@variables t
@parameters p = 1
# define compartment c1 having the volume c1
@parameters c1 = 10
c1rn = @reaction_network c1
# define compartment c1 having the volume c1
@parameters c2 = 2
c2rn = @reaction_network c2
# define species D in compartment c1
@species c1₊D(t) = 300
# define species D in compartment c2
@species c2₊D(t) = 100
# define species Dc in compartments c1 and c2 to represent concentrations
@variables c1₊Dc(t)
@variables c2₊Dc(t)
# define the reactions
# This does not works as it uses the c1₊Dc and c2₊Dc variables in the rates
rxn = [
@reaction p*c1₊Dc, c1₊D => c2₊D
@reaction p*c2₊Dc, c2₊D => c1₊D
]
#= This works but it defeats the purpose of creating variables to make the definition of the reaction more readable
rxn = [
@reaction p*c1₊D/c1, c1₊D => c2₊D
@reaction p*c2₊D/c2, c2₊D => c1₊D
]
=#
# define the equations defining c1₊Dc and c2₊Dc used in the rates above
ra = [
c1₊Dc ~ c1₊D / c1
c2₊Dc ~ c2₊D / c2
]
# build the reaction system with component systems c1rn and c2rn corresponding to the two compartments
@named rs = ReactionSystem([rxn; ra], t, [c1₊D, c2₊D, c1₊Dc, c2₊Dc], [p, c1, c2]; systems=[c1rn,c2rn])
meq0 = convert(ODESystem, rs)
meq = structural_simplify(meq0)
tspan = (0.0,250.0)
ode = ODEProblem(meq, [], tspan, [])
# all works up to this point
# but fails on the following line with
# LoadError: UndefVarError: `c1₊Dc` not defined
sol = solve(ode, Tsit5())
plot(sol)