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
10 changes: 9 additions & 1 deletion petab/v1/sbml.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,15 @@ def get_param_value(parameter_id: str):
]

def remove_rules(target_id: str):
if sbml_model.removeRuleByVariable(target_id):
"""Remove any assignment rule and initial assignment for
``target_id`` so that its initial value can be set explicitly.
"""
rule = sbml_model.getRuleByVariable(target_id)
if (
rule is not None
and rule.getTypeCode() == libsbml.SBML_ASSIGNMENT_RULE
):
sbml_model.removeRuleByVariable(target_id)
warn(
"An SBML rule was removed to set the component "
f"{target_id} to a constant value.",
Expand Down
10 changes: 9 additions & 1 deletion tests/v1/test_sbml.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ def create_test_data():
"\n".join(
[
"compartment compartment_1 = 1",
*(f"species species_{i} = 10 * {i}" for i in range(1, 5)),
*(f"species species_{i} = 10 * {i}" for i in range(1, 6)),
*(f"parameter_{i} = {i}" for i in range(1, 4)),
"species_2 := 25",
"species_5' = 1",
]
)
)
Expand All @@ -32,6 +33,7 @@ def create_test_data():
"species_2": [25],
"species_3": ["parameter_1"],
"species_4": ["not_a_model_parameter"],
"species_5": [55],
"compartment_1": [2],
}
)
Expand Down Expand Up @@ -85,6 +87,12 @@ def check_model(condition_model):
condition_model.getSpecies("species_4").getInitialConcentration()
== 3.25
)
assert (
condition_model.getSpecies("species_5").getInitialConcentration() == 55
)
assert condition_model.getRuleByVariable("species_5") is not None, (
"RateRule was removed although it should have been kept"
)
assert len(condition_model.getListOfInitialAssignments()) == 0, (
"InitialAssignment not removed"
)
Expand Down
Loading