In [1]:
%matplotlib notebook
from libsignetsim import Model, TimeseriesSimulation, Experiment, ModelVsTimeseriesOptimization
from libsignetsim.figure.SigNetSimFigure import SigNetSimFigure
In [2]:
m = Model()
m.setName("Enzymatic Reaction")
e = m.listOfSpecies.new("E")
s = m.listOfSpecies.new("S")
p = m.listOfSpecies.new("P")
m.listOfParameters.new("vmax", 1)
m.listOfParameters.new("km", 1)
r = m.listOfReactions.new("Enzymatic reaction")
r.listOfReactants.add(s)
r.listOfModifiers.add(e)
r.listOfProducts.add(p)
r.kineticLaw.setPrettyPrintMathFormula("vmax*E*S/(km+S)")
e.setValue(10)
s.setValue(12)
p.setValue(0)
In [3]:
sim = TimeseriesSimulation([m], time_min=0, time_ech=0.1, time_max=20)
sim.run()
In [4]:
reference_times = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 20]
reference_data = [0.0, 2, 3.5, 5.5, 7, 9, 10, 11.5, 12, 12, 12, 12, 12, 12, 12, 12, 12]
# Building the experiment
experiment = Experiment()
condition = experiment.createCondition()
for i, data in enumerate(reference_data):
condition.addObservation(reference_times[i], 'P', data)
In [5]:
figure = SigNetSimFigure()
plots = experiment.plot(figure=figure, suffix=" (data)", marker='.')
sim.plot(figure=figure, plot=plots[0], variables=['P'], suffix=" (model)")
Out[5]:
In [6]:
selected_parameters = []
for parameter in m.listOfParameters:
selected_parameters.append((parameter, 1, 1e-6, 1e+6, 4))
fit = ModelVsTimeseriesOptimization(
workingModel=m,
list_of_experiments=[experiment],
parameters_to_fit=selected_parameters,
nb_procs=2
)
score = fit.runOptimization(2)
parameters = fit.readOptimizationOutput()
In [7]:
for parameter, value in parameters.items():
parameter.setValue(value)
In [8]:
sim2 = TimeseriesSimulation([m], time_min=0, time_ech=0.1, time_max=20)
sim2.run()
In [9]:
figure = SigNetSimFigure()
plots = experiment.plot(figure=figure, suffix=" (data)", marker='.')
sim2.plot(figure=figure, plot=plots[0], variables=['P'], suffix=" (model)")
Out[9]:
In [ ]: