Obtaining Odesystem equations in code format from SBML file

Hi,
I am new to Julia and have a question regarding ModelingToolkit and SBML.
I imported an SBML file and converted the model into an ODESystem:

mdl = readSBML("Kok2020.xml", doc -> begin
    set_level_and_version(3, 2)(doc)
    convert_promotelocals_expandfuns(doc)
end)
odesys = ODESystem(mdl)  
structural_simplify(odesys)

However, I am wondering if there is a function to obtain the equations,
parameters, variables and their values into a code format.
Namely, I want to add and change the equations for my own adjusted model.
Currently, the output is in Latex format and prevents me from easily
changing the equations.
So I want to obtain this, but than for the SBML model:

function SIRModel!(du, u, p, t)
  
  # unpack p
  β, γ = p

  # unpack u
  S, I, R = u

  # define equations
  dSdt = -β*I*S
  dIdt = β*I*S - γ*I
  dRdt = γ*I

  du[1:3] = [dSdt, dIdt, dRdt]

  nothing # return nothing
end

u0 = [0.9999, 0.0001, 0.]
p = [0.09, 0.008]

Can anyone help me with this?

ODEProblemExpr(sys) gives the ODEProblem as a Julia expression instead of as the object itself. That’s one tool here.

You can check equations(odesys) and then create a new equation array that you then create a new system from.

2 Likes