Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0030/0030.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
from inspect import cleandoc

from petab.v2.C import *
from petab.v2 import Problem
from petabtests import (
PetabV2TestCase,
antimony_to_sbml_str,
)
from pathlib import Path

DESCRIPTION = cleandoc("""
## Objective

This case tests simultaneous re-initialization of compartment size and
contained species when an SBML event triggers at the exact same
time-point as a PEtab condition.

## Model

A species `S`, defined in terms of concentrations, with `dS/dt = p = 1`,
in a compartment `C`. `S` and `C` are changed via the condition table.

There is a PEtab condition triggered at `t=10`, which is triggered
at the exact time as an SBML event that re-initializes the compartment
volume after the condition table is applied.
""")

# problem --------------------------------------------------------------------

sbml_file = Path(__file__).parent / "model.xml"

vol0 = 4
conc0 = 2
conc10 = 8
dSdt = 1
vol10 = (conc0 + 10 * dSdt) + vol0 # = 16

ant_model = f"""
model petab_test_0030
compartment C = {vol0}

species S in C = 3 # this is overwritten by the condition table

p = {dSdt}
S' = p

at time >= 10, fromTrigger=false: C = C * 2 # this is executed after PEtab condition
end
"""
sbml_file.write_text(antimony_to_sbml_str(ant_model))

problem = Problem()
problem.add_observable("obs_C", "C", noise_formula="1")
problem.add_observable("obs_amount_S", "S * C", noise_formula="1")
problem.add_observable("obs_conc_S", "S", noise_formula="1")

problem.add_parameter("p", lb=0, ub=10, nominal_value=1)

problem.add_experiment("experiment1", 0, "condition1", 10, "condition2")
# at t=0
problem.add_condition(
"condition1",
"condition1",
S=conc0,
)
# t=10
problem.add_condition(
"condition2",
"condition2",
S="S + C",
C=conc10,
)

ts = [0, 5, 10, 15]
for t in ts:
for obs in ["obs_C", "obs_amount_S", "obs_conc_S"]:
problem.add_measurement(
obs, experiment_id="experiment1", time=t, measurement=t
)

# solutions ------------------------------------------------------------------

simulation_df = problem.measurement_df.copy(deep=True).rename(
columns={MEASUREMENT: SIMULATION}
)
simulation_df[SIMULATION] = [
# vol, amount, conc
# --- t=0 ---
vol0,
conc0 * vol0,
conc0,
# --- t=5 ---
vol0,
(conc0 + 5 * dSdt) * vol0,
(conc0 + 5 * dSdt),
# --- t=10 ---
# condition table:
# 8, 16 * 8 = 128 , 12 + 4 = 16
# event (triggered at same time as PEtab condition)
# volume is changed by event, amount is preserved, conc changes
# C = 8 * 2 = 16, 128, 8
vol10,
conc10 * vol10,
conc10,
# --- t=15 ---
vol10,
(conc10 + 5 * dSdt) * vol10,
(conc10 + 5 * dSdt)
]

case = PetabV2TestCase.from_problem(
id=30,
brief="Simultaneous trigger of PEtab condition and SBML event.",
description=DESCRIPTION,
model=sbml_file,
problem=problem,
simulation_df=simulation_df,
)
16 changes: 16 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0030/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# PEtab test case 0030

## Objective

This case tests simultaneous re-initialization of compartment size and
contained species when an SBML event triggers at the exact same
time-point as a PEtab condition.

## Model

A species `S`, defined in terms of concentrations, with `dS/dt = p = 1`,
in a compartment `C`. `S` and `C` are changed via the condition table.

There is a PEtab condition triggered at `t=10`, which is triggered
at the exact time as an SBML event that re-initializes the compartment
volume after the condition table is applied.
17 changes: 17 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0030/_0030.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
condition_files:
- _conditions.tsv
experiment_files:
- _experiments.tsv
format_version: 2.0.0
mapping_files:
- _mapping.tsv
measurement_files:
- _measurements.tsv
model_files:
model_0:
language: sbml
location: _model.xml
observable_files:
- _observables.tsv
parameter_files:
- _parameters.tsv
7 changes: 7 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0030/_0030_solution.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
chi2: 51836.0
llh: -25929.027262398453
simulation_files:
- _simulations.tsv
tol_chi2: 0.001
tol_llh: 0.001
tol_simulations: 0.001
4 changes: 4 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0030/_conditions.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
conditionId targetId targetValue
condition1 S 2.0
condition2 S C + S
condition2 C 8.0
3 changes: 3 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0030/_experiments.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
experimentId time conditionId
experiment1 0.0 condition1
experiment1 10.0 condition2
3 changes: 3 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0030/_mapping.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
petabEntityId modelEntityId name
condition1 condition1
condition2 condition2
13 changes: 13 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0030/_measurements.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
modelId observableId experimentId time measurement observableParameters noiseParameters
obs_C experiment1 0.0 0.0
obs_amount_S experiment1 0.0 0.0
obs_conc_S experiment1 0.0 0.0
obs_C experiment1 5.0 5.0
obs_amount_S experiment1 5.0 5.0
obs_conc_S experiment1 5.0 5.0
obs_C experiment1 10.0 10.0
obs_amount_S experiment1 10.0 10.0
obs_conc_S experiment1 10.0 10.0
obs_C experiment1 15.0 15.0
obs_amount_S experiment1 15.0 15.0
obs_conc_S experiment1 15.0 15.0
46 changes: 46 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0030/_model.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created by libAntimony version v3.1.1 with libSBML version 5.20.5. -->
<sbml xmlns="http://www.sbml.org/sbml/level3/version2/core" level="3" version="2">
<model metaid="petab_test_0030" id="petab_test_0030">
<listOfCompartments>
<compartment id="C" spatialDimensions="3" size="4" constant="false"/>
</listOfCompartments>
<listOfSpecies>
<species id="S" compartment="C" initialConcentration="3" hasOnlySubstanceUnits="false" boundaryCondition="false" constant="false"/>
</listOfSpecies>
<listOfParameters>
<parameter id="p" value="1" constant="true"/>
</listOfParameters>
<listOfRules>
<rateRule variable="S">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<ci> p </ci>
</math>
</rateRule>
</listOfRules>
<listOfEvents>
<event id="_E0" useValuesFromTriggerTime="false">
<trigger initialValue="true" persistent="true">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply>
<geq/>
<csymbol encoding="text" definitionURL="http://www.sbml.org/sbml/symbols/time"> time </csymbol>
<cn type="integer"> 10 </cn>
</apply>
</math>
</trigger>
<listOfEventAssignments>
<eventAssignment variable="C">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply>
<times/>
<ci> C </ci>
<cn type="integer"> 2 </cn>
</apply>
</math>
</eventAssignment>
</listOfEventAssignments>
</event>
</listOfEvents>
</model>
</sbml>
4 changes: 4 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0030/_observables.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
observableId observableName observableFormula noiseFormula noiseDistribution observablePlaceholders noisePlaceholders
obs_C C 1.00000000000000 normal
obs_amount_S C*S 1.00000000000000 normal
obs_conc_S S 1.00000000000000 normal
2 changes: 2 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0030/_parameters.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parameterId lowerBound upperBound nominalValue estimate priorDistribution priorParameters
p 0.0 10.0 1.0 true
13 changes: 13 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0030/_simulations.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
modelId observableId experimentId time simulation observableParameters noiseParameters
obs_C experiment1 0.0 4
obs_amount_S experiment1 0.0 8
obs_conc_S experiment1 0.0 2
obs_C experiment1 5.0 4
obs_amount_S experiment1 5.0 28
obs_conc_S experiment1 5.0 7
obs_C experiment1 10.0 16
obs_amount_S experiment1 10.0 128
obs_conc_S experiment1 10.0 8
obs_C experiment1 15.0 16
obs_amount_S experiment1 15.0 208
obs_conc_S experiment1 15.0 13
46 changes: 46 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0030/model.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created by libAntimony version v3.1.1 with libSBML version 5.20.5. -->
<sbml xmlns="http://www.sbml.org/sbml/level3/version2/core" level="3" version="2">
<model metaid="petab_test_0030" id="petab_test_0030">
<listOfCompartments>
<compartment id="C" spatialDimensions="3" size="4" constant="false"/>
</listOfCompartments>
<listOfSpecies>
<species id="S" compartment="C" initialConcentration="3" hasOnlySubstanceUnits="false" boundaryCondition="false" constant="false"/>
</listOfSpecies>
<listOfParameters>
<parameter id="p" value="1" constant="true"/>
</listOfParameters>
<listOfRules>
<rateRule variable="S">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<ci> p </ci>
</math>
</rateRule>
</listOfRules>
<listOfEvents>
<event id="_E0" useValuesFromTriggerTime="false">
<trigger initialValue="true" persistent="true">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply>
<geq/>
<csymbol encoding="text" definitionURL="http://www.sbml.org/sbml/symbols/time"> time </csymbol>
<cn type="integer"> 10 </cn>
</apply>
</math>
</trigger>
<listOfEventAssignments>
<eventAssignment variable="C">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply>
<times/>
<ci> C </ci>
<cn type="integer"> 2 </cn>
</apply>
</math>
</eventAssignment>
</listOfEventAssignments>
</event>
</listOfEvents>
</model>
</sbml>
4 changes: 4 additions & 0 deletions petabtests/cases/v2.0.0/sbml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,7 @@ Simulation. None t0 condition applied at time-point without measurements.

Simulation. Non-zero simulation start time

# [0030](0030/)

Simultaneous trigger of PEtab condition and SBML event.