ecell / ecell4_base

An integrated software environment for multi-algorithm, multi-timescale, multi-spatial-representation simulation of various cellular phenomena
https://ecell4.e-cell.org/
GNU General Public License v3.0
63 stars 23 forks source link

Enable to get derivatives and a Jacobian matrix for ode #350

Closed kaizu closed 5 years ago

kaizu commented 5 years ago

The above PR enables the followings:

import numpy
from ecell4 import *
from ecell4_base import *
from ecell4_base.core import *

with reaction_rules():
    A + B == C | (0.01, 0.3)
    C > D | 0.1
    2 * D > E | 1.0 * A * D / (D + 10.0)

m = get_model()
print(numpy.array(get_stoichiometry(m.list_species(), m.reaction_rules())))

w = ode.World()
w.bind_to(m)
w.add_molecules(Species('A'), 10)
w.add_molecules(Species('B'), 20)
w.add_molecules(Species('C'), 30)
w.add_molecules(Species('D'), 40)

print(w.evaluate(m.reaction_rules()[0]))
print(numpy.array(w.evaluate(m.reaction_rules())))

sim = ode.Simulator(w, m)
sim.initialize()

print(numpy.array(sim.derivatives()))
print(numpy.array(sim.jacobian()))
print(numpy.array(sim.fluxes()))
print(numpy.array(sim.stoichiometry()))