Skip to content

epymorph.tools.ipm_diagram

EdgeDef

Bases: Protocol

A simplified EdgeDef interface.

rate abstractmethod property

rate: Expr

compartment_from abstractmethod property

compartment_from: Symbol

compartment_to abstractmethod property

compartment_to: Symbol

CompartmentModel

Bases: Protocol

A simplified CompartmentModel interface.

events abstractmethod property

events: Sequence[EdgeDef]

check_dependencies

check_dependencies() -> None

Checks if the external requirements for drawing diagrams are installed. Raises ExternalDependencyError if not.

merge_edges

merge_edges(
    ipm: CompartmentModel,
) -> list[tuple[str, str, Expr]]

Combines (by addition) the rate expressions of all edges with the same source and destination compartment.

construct_digraph

construct_digraph(
    ipm: CompartmentModel,
) -> Iterator[Digraph]

Constructs a Digraph from the given compartment model. The Digraph is only valid as long as the context is open, because we rely on temporary files to render latex expressions.

digraph_png

digraph_png(ipm: CompartmentModel) -> BytesIO

Constructs a Digraph from the given compartment model and renders it to PNG. Returns the PNG file content in a BytesIO.

render_diagram

render_diagram(
    ipm: CompartmentModel,
    *,
    file: str | Path | None = None,
    figsize: tuple[float, float] | None = None,
) -> None

Render a diagram of the given IPM, either by showing it with matplotlib (default) or by saving it to file as a png image.

Parameters:

  • ipm (CompartmentModel) –

    The IPM to render.

  • file (str | Path, default: None ) –

    Provide a file path to save a png image of the diagram to this path. If file is None, we will instead use matplotlib to show the diagram.

  • figsize (tuple[float, float], default: None ) –

    The matplotlib figure size to use when displaying the diagram. Only used if file is not provided.