|
| 1 | +from inspect import cleandoc |
| 2 | + |
| 3 | +from petab.v2.C import * |
| 4 | +from petab.v2 import Problem |
| 5 | +from petabtests import PetabV2TestCase, analytical_a, analytical_b, DEFAULT_SBML_FILE |
| 6 | + |
| 7 | +DESCRIPTION = cleandoc(""" |
| 8 | +## Objective |
| 9 | +
|
| 10 | +This case tests applying two PEtab conditions simultaneously, at a time |
| 11 | +point that also has measurement values. |
| 12 | +
|
| 13 | +## Model |
| 14 | +
|
| 15 | +A simple conversion reaction `A <=> B` in a single compartment, following |
| 16 | +mass action kinetics. |
| 17 | +""") |
| 18 | + |
| 19 | +# problem -------------------------------------------------------------------- |
| 20 | +a0 = 1 |
| 21 | +b0 = 1 |
| 22 | +k1 = 0.8 |
| 23 | +k2 = 0.6 |
| 24 | +problem = Problem() |
| 25 | + |
| 26 | +problem.add_condition( |
| 27 | + "condition1", |
| 28 | + A="A + 5.0", |
| 29 | +) |
| 30 | +problem.add_condition( |
| 31 | + "condition2", |
| 32 | + B="B + 3.0", |
| 33 | +) |
| 34 | +problem.add_experiment("experiment1", |
| 35 | + 0, "", |
| 36 | + 10, "condition1", |
| 37 | + 10, "condition2") |
| 38 | + |
| 39 | +problem.add_observable("obs_a", "A", noise_formula="0.5") |
| 40 | +problem.add_observable("obs_b", "B", noise_formula="0.1") |
| 41 | +problem.add_measurement("obs_a", experiment_id="experiment1", time=0, measurement=0.7) |
| 42 | +problem.add_measurement("obs_b", experiment_id="experiment1", time=0, measurement=1.0) |
| 43 | +problem.add_measurement("obs_a", experiment_id="experiment1", time=10, measurement=0.1) |
| 44 | +problem.add_measurement("obs_b", experiment_id="experiment1", time=10, measurement=0.4) |
| 45 | + |
| 46 | +problem.add_parameter("k1", lb=0, ub=10, nominal_value=k1, estimate=True) |
| 47 | +problem.add_parameter("k2", lb=0, ub=10, nominal_value=k2, estimate=True) |
| 48 | + |
| 49 | + |
| 50 | +# solutions ------------------------------------------------------------------ |
| 51 | + |
| 52 | +simulation_df = problem.measurement_df.copy(deep=True).rename( |
| 53 | + columns={MEASUREMENT: SIMULATION} |
| 54 | +) |
| 55 | +# in the model, concentrations are used, which do not depend on the |
| 56 | +# compartment size, so that the species values should stay the same |
| 57 | +simulation_df[SIMULATION] = [ |
| 58 | + a0, |
| 59 | + b0, |
| 60 | + analytical_a(10.0, a0=a0, b0=b0, k1=k1, k2=k2) + 5.0, |
| 61 | + analytical_b(10.0, a0=a0, b0=b0, k1=k1, k2=k2) + 3.0, |
| 62 | +] |
| 63 | + |
| 64 | +case = PetabV2TestCase.from_problem( |
| 65 | + id=31, |
| 66 | + brief="Simulation. Two PEtab conditions applied at the same " |
| 67 | + "time point.", |
| 68 | + description=DESCRIPTION, |
| 69 | + model=DEFAULT_SBML_FILE, |
| 70 | + problem=problem, |
| 71 | + simulation_df=simulation_df, |
| 72 | +) |
0 commit comments