Skip to content

flatten

Helpers for model flattening.

flatten_sbml

flatten_sbml(sbml_path, sbml_flat_path, leave_ports=True)

Flatten given SBML file.

A relative path is relative to the working directory, which is never changed. libsbml resolves the comp:source of an external model definition against the location of the document which names it, i.e. relative to the directory of sbml_path, and of the external files in turn.

libsbml opens the file of an external model definition itself, and on Windows it does so with the narrow (ANSI) file API, which cannot open a path with a non-ASCII character: a model with external model definitions in such a directory cannot be flattened on Windows. sbml_path and sbml_flat_path themselves may be any path, a path libsbml cannot open is read and written by python.

:param sbml_path: input path to SBML file to flatten (should be a comp model) :param sbml_flat_path: output path for flat SBML :param leave_ports: boolean flag to leave ports in flattened model.

:return: flattened SBMLDocument

:raises ValueError: if the file cannot be read, has no model, or libsbml cannot flatten the document, see flatten_sbml_doc

flatten_sbml_doc

flatten_sbml_doc(
    doc, sbml_flat_path=None, leave_ports=True
)

Flatten SBMLDocument.

Validation should be performed before the flattening and is not part of the flattening routine. If an output path is provided the file is written to the output path.

:param doc: SBMLDocument to flatten. :param sbml_flat_path: Path to write flattended SBMLDocument to :param leave_ports: flag to leave ports

:return: SBMLDocument

:raises ValueError: if the document has no model, e.g. a library of comp model definitions, which has nothing to flatten them into