Skip to content

Commit e660f60

Browse files
committed
preeq
1 parent 0deb432 commit e660f60

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

petab/v2/converters.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ class ExperimentsToEventsConverter:
3434
will be removed from the condition table.
3535
Each experiment will have at most one period with a start time of ``-inf``
3636
and one period with a finite start time. The associated changes with
37-
these periods are only the steady-state pre-simulation indicator
37+
these periods are only the pre-equilibration indicator
3838
(if necessary), and the experiment indicator parameter.
3939
"""
4040

4141
#: ID of the parameter that indicates whether the model is in
42-
# the steady-state pre-simulation phase (1) or not (0).
43-
PRE_SIM_INDICATOR = "_petab_pre_simulation_indicator"
42+
# the pre-equilibration phase (1) or not (0).
43+
PREEQ_INDICATOR = "_petab_preequilibration_indicator"
4444

4545
def __init__(self, problem: Problem):
4646
"""Initialize the converter.
@@ -55,7 +55,7 @@ def __init__(self, problem: Problem):
5555
self._new_problem = deepcopy(self._original_problem)
5656

5757
self._model = self._new_problem.model.sbml_model
58-
self._presim_indicator = self.PRE_SIM_INDICATOR
58+
self._preeq_indicator = self.PREEQ_INDICATOR
5959

6060
# The maximum event priority that was found in the unprocessed model.
6161
self._max_event_priority = None
@@ -137,7 +137,7 @@ def convert(self) -> Problem:
137137
:return: The converted PEtab problem.
138138
"""
139139

140-
self._add_presimulation_indicator()
140+
self._add_preequilibration_indicator()
141141

142142
problem = self._new_problem
143143
for experiment in problem.experiment_table.experiments:
@@ -154,7 +154,7 @@ def _convert_experiment(self, problem: Problem, experiment: Experiment):
154154
"""Convert a single experiment to SBML events."""
155155
model = self._model
156156
experiment.sort_periods()
157-
has_presimulation = (
157+
has_preequilibration = (
158158
len(experiment.periods) and experiment.periods[0].time == -inf
159159
)
160160

@@ -168,7 +168,7 @@ def _convert_experiment(self, problem: Problem, experiment: Experiment):
168168
kept_periods = []
169169
for i_period, period in enumerate(experiment.periods):
170170
# check for non-zero initial times of the first period
171-
if (i_period == int(has_presimulation)) and period.time != 0:
171+
if (i_period == int(has_preequilibration)) and period.time != 0:
172172
# TODO: we could address that by offsetting all occurrences of
173173
# the SBML time in the model (except for the newly added
174174
# events triggers). Or we better just leave it to the
@@ -179,18 +179,17 @@ def _convert_experiment(self, problem: Problem, experiment: Experiment):
179179
)
180180

181181
if period.time == -inf:
182-
# steady-state pre-simulation cannot be represented in SBML,
182+
# pre-equilibration cannot be represented in SBML,
183183
# so we need to keep this period in the Problem.
184184
kept_periods.append(period)
185-
elif i_period == int(has_presimulation):
186-
# we always keep the first non-presimulation period
185+
elif i_period == int(has_preequilibration):
186+
# we always keep the first non-pre-equilibration period
187187
# to set the indicator parameters
188188
kept_periods.append(period)
189189
elif not period.changes:
190190
# no condition, no changes, no need for an event,
191-
# no need to keep the period unless it's the initial
192-
# steady-state simulation or the only non-presimulation
193-
# period (handled above)
191+
# no need to keep the period unless it's the pre-equilibration
192+
# or the only non-equilibration period (handled above)
194193
continue
195194

196195
ev = self._create_period_begin_event(
@@ -213,9 +212,9 @@ def _convert_experiment(self, problem: Problem, experiment: Experiment):
213212
for period in kept_periods:
214213
period.condition_ids = [
215214
f"_petab_experiment_condition_{experiment.id}",
216-
"_petab_steady_state_pre_simulation"
215+
"_petab_preequilibration"
217216
if period.time == -inf
218-
else "_petab_no_steady_state_pre_simulation",
217+
else "_petab_no_preequilibration",
219218
]
220219

221220
experiment.periods = kept_periods
@@ -242,23 +241,23 @@ def _create_period_begin_event(
242241

243242
if period.time == -inf:
244243
trig_math = libsbml.parseL3Formula(
245-
f"({exp_ind_id} == 1) && ({self._presim_indicator} == 1)"
244+
f"({exp_ind_id} == 1) && ({self._preeq_indicator} == 1)"
246245
)
247246
else:
248247
trig_math = libsbml.parseL3Formula(
249-
f"({exp_ind_id} == 1) && ({self._presim_indicator} != 1) "
248+
f"({exp_ind_id} == 1) && ({self._preeq_indicator} != 1) "
250249
f"&& (time >= {period.time})"
251250
)
252251
check(trigger.setMath(trig_math))
253252

254253
return ev
255254

256-
def _add_presimulation_indicator(
255+
def _add_preequilibration_indicator(
257256
self,
258257
) -> None:
259-
"""Add an indicator parameter for the steady-state presimulation to
260-
the SBML model."""
261-
par_id = self._presim_indicator
258+
"""Add an indicator parameter for the pre-equilibration to the SBML
259+
model."""
260+
par_id = self._preeq_indicator
262261
if self._model.getElementBySId(par_id) is not None:
263262
raise ValueError(
264263
f"Entity with ID {par_id} already exists in the SBML model."
@@ -325,24 +324,24 @@ def _change_to_event_assignment(change: Change, event: libsbml.Event):
325324

326325
def _add_indicators_to_conditions(self, problem: Problem) -> None:
327326
"""After converting the experiments to events, add the indicator
328-
parameters for the presimulation period and for the different
327+
parameters for the pre-equilibration period and for the different
329328
experiments to the remaining conditions.
330329
Then remove all other conditions."""
331330

332331
# create conditions for indicator parameters
333332
problem.condition_table.conditions.append(
334333
Condition(
335-
id="_petab_steady_state_pre_simulation",
334+
id="_petab_preequilibration",
336335
changes=[
337-
Change(target_id=self._presim_indicator, target_value=1)
336+
Change(target_id=self._preeq_indicator, target_value=1)
338337
],
339338
)
340339
)
341340
problem.condition_table.conditions.append(
342341
Condition(
343-
id="_petab_no_steady_state_pre_simulation",
342+
id="_petab_no_preequilibration",
344343
changes=[
345-
Change(target_id=self._presim_indicator, target_value=0)
344+
Change(target_id=self._preeq_indicator, target_value=0)
346345
],
347346
)
348347
)

0 commit comments

Comments
 (0)