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
7 changes: 7 additions & 0 deletions python/amici/petab_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,13 @@ def import_model_sbml(
if assignment is None:
assignment = sbml_model.createInitialAssignment()
assignment.setSymbol(assignee_id)
else:
logger.debug('The SBML model has an initial assignment defined '
f'for model entity {assignee_id}, but this entity '
'also has an initial value defined in the PEtab '
'condition table. The SBML initial assignment will '
'be overwritten to handle preequilibration and '
'initial values specified by the PEtab problem.')
formula = f'{PREEQ_INDICATOR_ID} * {init_par_id_preeq} ' \
f'+ (1 - {PREEQ_INDICATOR_ID}) * {init_par_id_sim}'
math_ast = libsbml.parseL3Formula(formula)
Expand Down
12 changes: 12 additions & 0 deletions python/amici/petab_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Collection, Iterator)

import amici
from amici.sbml_import import get_species_initial
import libsbml
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -343,6 +344,17 @@ def _set_initial_concentration(condition_id, species_id, init_par_id,
par_map, scale_map):
value = petab.to_float_if_float(
petab_problem.condition_df.loc[condition_id, species_id])
if pd.isna(value):
value = float(
get_species_initial(
petab_problem.sbml_model.getSpecies(species_id)
)
)
logger.debug(f'The species {species_id} has no initial value '
f'defined for the condition {condition_id} in '
'the PEtab conditions table. The initial value is '
f'now set to {value}, which is the initial value '
'defined in the SBML model.')
par_map[init_par_id] = value
if isinstance(value, float):
# numeric initial state
Expand Down
4 changes: 2 additions & 2 deletions python/amici/sbml_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ def _process_species_initial(self):
Extract initial values and initial assignments from species
"""
for species_variable in self.sbml.getListOfSpecies():
initial = _get_species_initial(species_variable)
initial = get_species_initial(species_variable)

species_id = _get_identifier_symbol(species_variable)
# If species_id is a target of an AssignmentRule, species will be
Expand Down Expand Up @@ -1798,7 +1798,7 @@ def _get_identifier_symbol(var: sbml.SBase) -> sp.Symbol:
return symbol_with_assumptions(var.getId())


def _get_species_initial(species: sbml.Species) -> sp.Expr:
def get_species_initial(species: sbml.Species) -> sp.Expr:
"""
Extract the initial concentration from a given species

Expand Down