Skip to content

Commit f8c2840

Browse files
authored
Test case simultaneous PEtab and SBML event (#107)
Test case where both a PEtab condition and SBML event (via trigger `time >= 10`) fire at the exact same time-point. Following the spec, the SBML event should be fired after the PEtab condition. This is the same test case as `0016`, with the only modification that the SBML event trigger is `time >= 10` (such that the events arguably trigger at the exact same time).
1 parent 2742279 commit f8c2840

File tree

14 files changed

+296
-0
lines changed

14 files changed

+296
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
from inspect import cleandoc
2+
3+
from petab.v2.C import *
4+
from petab.v2 import Problem
5+
from petabtests import (
6+
PetabV2TestCase,
7+
antimony_to_sbml_str,
8+
)
9+
from pathlib import Path
10+
11+
DESCRIPTION = cleandoc("""
12+
## Objective
13+
14+
This case tests simultaneous re-initialization of compartment size and
15+
contained species when an SBML event triggers at the exact same
16+
time-point as a PEtab condition.
17+
18+
## Model
19+
20+
A species `S`, defined in terms of concentrations, with `dS/dt = p = 1`,
21+
in a compartment `C`. `S` and `C` are changed via the condition table.
22+
23+
There is a PEtab condition triggered at `t=10`, which is triggered
24+
at the exact time as an SBML event that re-initializes the compartment
25+
volume after the condition table is applied.
26+
""")
27+
28+
# problem --------------------------------------------------------------------
29+
30+
sbml_file = Path(__file__).parent / "model.xml"
31+
32+
vol0 = 4
33+
conc0 = 2
34+
conc10 = 8
35+
dSdt = 1
36+
vol10 = (conc0 + 10 * dSdt) + vol0 # = 16
37+
38+
ant_model = f"""
39+
model petab_test_0030
40+
compartment C = {vol0}
41+
42+
species S in C = 3 # this is overwritten by the condition table
43+
44+
p = {dSdt}
45+
S' = p
46+
47+
at time >= 10, fromTrigger=false: C = C * 2 # this is executed after PEtab condition
48+
end
49+
"""
50+
sbml_file.write_text(antimony_to_sbml_str(ant_model))
51+
52+
problem = Problem()
53+
problem.add_observable("obs_C", "C", noise_formula="1")
54+
problem.add_observable("obs_amount_S", "S * C", noise_formula="1")
55+
problem.add_observable("obs_conc_S", "S", noise_formula="1")
56+
57+
problem.add_parameter("p", lb=0, ub=10, nominal_value=1)
58+
59+
problem.add_experiment("experiment1", 0, "condition1", 10, "condition2")
60+
# at t=0
61+
problem.add_condition(
62+
"condition1",
63+
"condition1",
64+
S=conc0,
65+
)
66+
# t=10
67+
problem.add_condition(
68+
"condition2",
69+
"condition2",
70+
S="S + C",
71+
C=conc10,
72+
)
73+
74+
ts = [0, 5, 10, 15]
75+
for t in ts:
76+
for obs in ["obs_C", "obs_amount_S", "obs_conc_S"]:
77+
problem.add_measurement(
78+
obs, experiment_id="experiment1", time=t, measurement=t
79+
)
80+
81+
# solutions ------------------------------------------------------------------
82+
83+
simulation_df = problem.measurement_df.copy(deep=True).rename(
84+
columns={MEASUREMENT: SIMULATION}
85+
)
86+
simulation_df[SIMULATION] = [
87+
# vol, amount, conc
88+
# --- t=0 ---
89+
vol0,
90+
conc0 * vol0,
91+
conc0,
92+
# --- t=5 ---
93+
vol0,
94+
(conc0 + 5 * dSdt) * vol0,
95+
(conc0 + 5 * dSdt),
96+
# --- t=10 ---
97+
# condition table:
98+
# 8, 16 * 8 = 128 , 12 + 4 = 16
99+
# event (triggered at same time as PEtab condition)
100+
# volume is changed by event, amount is preserved, conc changes
101+
# C = 8 * 2 = 16, 128, 8
102+
vol10,
103+
conc10 * vol10,
104+
conc10,
105+
# --- t=15 ---
106+
vol10,
107+
(conc10 + 5 * dSdt) * vol10,
108+
(conc10 + 5 * dSdt)
109+
]
110+
111+
case = PetabV2TestCase.from_problem(
112+
id=30,
113+
brief="Simultaneous trigger of PEtab condition and SBML event.",
114+
description=DESCRIPTION,
115+
model=sbml_file,
116+
problem=problem,
117+
simulation_df=simulation_df,
118+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# PEtab test case 0030
2+
3+
## Objective
4+
5+
This case tests simultaneous re-initialization of compartment size and
6+
contained species when an SBML event triggers at the exact same
7+
time-point as a PEtab condition.
8+
9+
## Model
10+
11+
A species `S`, defined in terms of concentrations, with `dS/dt = p = 1`,
12+
in a compartment `C`. `S` and `C` are changed via the condition table.
13+
14+
There is a PEtab condition triggered at `t=10`, which is triggered
15+
at the exact time as an SBML event that re-initializes the compartment
16+
volume after the condition table is applied.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
condition_files:
2+
- _conditions.tsv
3+
experiment_files:
4+
- _experiments.tsv
5+
format_version: 2.0.0
6+
mapping_files:
7+
- _mapping.tsv
8+
measurement_files:
9+
- _measurements.tsv
10+
model_files:
11+
model_0:
12+
language: sbml
13+
location: _model.xml
14+
observable_files:
15+
- _observables.tsv
16+
parameter_files:
17+
- _parameters.tsv
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
chi2: 51836.0
2+
llh: -25929.027262398453
3+
simulation_files:
4+
- _simulations.tsv
5+
tol_chi2: 0.001
6+
tol_llh: 0.001
7+
tol_simulations: 0.001
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
conditionId targetId targetValue
2+
condition1 S 2.0
3+
condition2 S C + S
4+
condition2 C 8.0
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
experimentId time conditionId
2+
experiment1 0.0 condition1
3+
experiment1 10.0 condition2
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
petabEntityId modelEntityId name
2+
condition1 condition1
3+
condition2 condition2
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
modelId observableId experimentId time measurement observableParameters noiseParameters
2+
obs_C experiment1 0.0 0.0
3+
obs_amount_S experiment1 0.0 0.0
4+
obs_conc_S experiment1 0.0 0.0
5+
obs_C experiment1 5.0 5.0
6+
obs_amount_S experiment1 5.0 5.0
7+
obs_conc_S experiment1 5.0 5.0
8+
obs_C experiment1 10.0 10.0
9+
obs_amount_S experiment1 10.0 10.0
10+
obs_conc_S experiment1 10.0 10.0
11+
obs_C experiment1 15.0 15.0
12+
obs_amount_S experiment1 15.0 15.0
13+
obs_conc_S experiment1 15.0 15.0
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Created by libAntimony version v3.1.1 with libSBML version 5.20.5. -->
3+
<sbml xmlns="http://www.sbml.org/sbml/level3/version2/core" level="3" version="2">
4+
<model metaid="petab_test_0030" id="petab_test_0030">
5+
<listOfCompartments>
6+
<compartment id="C" spatialDimensions="3" size="4" constant="false"/>
7+
</listOfCompartments>
8+
<listOfSpecies>
9+
<species id="S" compartment="C" initialConcentration="3" hasOnlySubstanceUnits="false" boundaryCondition="false" constant="false"/>
10+
</listOfSpecies>
11+
<listOfParameters>
12+
<parameter id="p" value="1" constant="true"/>
13+
</listOfParameters>
14+
<listOfRules>
15+
<rateRule variable="S">
16+
<math xmlns="http://www.w3.org/1998/Math/MathML">
17+
<ci> p </ci>
18+
</math>
19+
</rateRule>
20+
</listOfRules>
21+
<listOfEvents>
22+
<event id="_E0" useValuesFromTriggerTime="false">
23+
<trigger initialValue="true" persistent="true">
24+
<math xmlns="http://www.w3.org/1998/Math/MathML">
25+
<apply>
26+
<geq/>
27+
<csymbol encoding="text" definitionURL="http://www.sbml.org/sbml/symbols/time"> time </csymbol>
28+
<cn type="integer"> 10 </cn>
29+
</apply>
30+
</math>
31+
</trigger>
32+
<listOfEventAssignments>
33+
<eventAssignment variable="C">
34+
<math xmlns="http://www.w3.org/1998/Math/MathML">
35+
<apply>
36+
<times/>
37+
<ci> C </ci>
38+
<cn type="integer"> 2 </cn>
39+
</apply>
40+
</math>
41+
</eventAssignment>
42+
</listOfEventAssignments>
43+
</event>
44+
</listOfEvents>
45+
</model>
46+
</sbml>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
observableId observableName observableFormula noiseFormula noiseDistribution observablePlaceholders noisePlaceholders
2+
obs_C C 1.00000000000000 normal
3+
obs_amount_S C*S 1.00000000000000 normal
4+
obs_conc_S S 1.00000000000000 normal

0 commit comments

Comments
 (0)