Skip to content
Merged
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@
that PEtab condition changes are applied before its assignments.
Previously, their order was undefined
(by @dweindl in https://github.com/PEtab-dev/libpetab-python/pull/562)
* Several fixes to `assignments_to_experiments`: keep a switch at the start
of a later period, keep the condition changes of symbols that the model
still uses elsewhere, evaluate a condition change once at the start of its
period, leave time-dependent initial assignments in the model, reject
assignments to species or compartments, leave problems without
time-dependent assignments unchanged, give a ramp's slope parameter an
unused ID, and accept switching times that conditions set from parameters
fixed by the parameter table
(by @FFroehlich in https://github.com/PEtab-dev/libpetab-python/pull/574)

**Features**
* `petab1to2` and `petab_files_1to2` can skip validation via `validate=False`
Expand Down
1 change: 1 addition & 0 deletions doc/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ API Reference
petab.v1.yaml
petab.v2
petab.v2.C
petab.v2.assignments_to_experiments
petab.v2.converters
petab.v2.core
petab.v2.experiments
Expand Down
31 changes: 31 additions & 0 deletions petab/v1/models/sbml_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,37 @@ def get_valid_ids_for_condition_table(self) -> Iterable[str]:
def symbol_allowed_in_observable_formula(self, id_: str) -> bool:
return self.sbml_model.getElementBySId(id_) or id_ == "time"

def get_referenced_ids(self) -> set[str]:
"""Get the IDs that the model refers to.

These are the IDs in the math of any model element (e.g., kinetic
laws, rules, initial assignments, events), and those referred to as
conversion factors. IDs that are only defined, but not referred to,
are not included.
"""
ids = set()
for element in self.sbml_model.getListOfAllElements():
if not (hasattr(element, "isSetMath") and element.isSetMath()):
continue
nodes = [element.getMath()]
while nodes:
node = nodes.pop()
if node.getType() == libsbml.AST_NAME:
ids.add(node.getName())
nodes += [
node.getChild(i) for i in range(node.getNumChildren())
]
# conversion factors refer to parameters by attribute, not in math
ids |= {
element.getConversionFactor()
for element in [
self.sbml_model,
*self.sbml_model.getListOfSpecies(),
]
if element.isSetConversionFactor()
}
return ids

def is_valid(self) -> bool:
return is_sbml_consistent(self.sbml_model.getSBMLDocument())

Expand Down
Loading
Loading