88import libsbml
99from sbmlmath import sbml_math_to_sympy , set_math
1010
11- from .C import TIME_PREEQUILIBRATION
1211from .core import Change , Condition , Experiment , ExperimentPeriod
1312from .models ._sbml_utils import add_sbml_parameter , check
1413from .models .sbml_model import SbmlModel
@@ -165,16 +164,16 @@ def _convert_experiment(self, experiment: Experiment):
165164 """Convert a single experiment to SBML events."""
166165 model = self ._model
167166 experiment .sort_periods ()
168- has_preequilibration = (
169- len (experiment .periods )
170- and experiment .periods [0 ].time == TIME_PREEQUILIBRATION
171- )
167+ has_preequilibration = experiment .has_preequilibration
172168
173169 # add experiment indicator
174170 exp_ind_id = self .get_experiment_indicator (experiment .id )
175171 if model .getElementBySId (exp_ind_id ) is not None :
176- raise AssertionError (
177- f"Entity with ID { exp_ind_id } exists already."
172+ raise ValueError (
173+ f"The model has entity with ID `{ exp_ind_id } `. "
174+ "IDs starting with `petab_` are reserved for "
175+ f"{ self .__class__ .__name__ } and should not be used in the "
176+ "model."
178177 )
179178 add_sbml_parameter (model , id_ = exp_ind_id , constant = False , value = 0 )
180179 kept_periods = []
@@ -192,7 +191,7 @@ def _convert_experiment(self, experiment: Experiment):
192191 "This cannot be represented in SBML."
193192 )
194193
195- if period .time == TIME_PREEQUILIBRATION :
194+ if period .is_preequilibration :
196195 # pre-equilibration cannot be represented in SBML,
197196 # so we need to keep this period in the Problem.
198197 kept_periods .append (period )
@@ -227,7 +226,7 @@ def _convert_experiment(self, experiment: Experiment):
227226 period .condition_ids = [
228227 self ._get_experiment_indicator_condition_id (experiment .id ),
229228 self .CONDITION_ID_PREEQ_ON
230- if period .time == TIME_PREEQUILIBRATION
229+ if period .is_preequilibration
231230 else self .CONDITION_ID_PREEQ_OFF ,
232231 ]
233232
@@ -253,7 +252,7 @@ def _create_period_start_event(
253252
254253 exp_ind_id = self .get_experiment_indicator (experiment .id )
255254
256- if period .time == TIME_PREEQUILIBRATION :
255+ if period .is_preequilibration :
257256 trig_math = libsbml .parseL3Formula (
258257 f"({ exp_ind_id } == 1) && ({ self ._preeq_indicator } == 1)"
259258 )
@@ -324,7 +323,8 @@ def _change_to_event_assignment(change: Change, event: libsbml.Event):
324323 sbml_model , id_ = change .target_id , constant = False , value = 0
325324 )
326325 else :
327- # TODO: can that break models??
326+ # We can safely change the `constant` attribute of the target.
327+ # "Constant" does not imply "boundary condition" in SBML.
328328 target .setConstant (False )
329329
330330 # the target value may depend on parameters that are only
0 commit comments