ABM-IR

The shared model description. Field by field documentation is in the ABM-IR reference.

abmfact.ir

ABM-IR: a versioned description of a biological agent-based model that any engine can run.

Load a model with load_model(), change parameters by dotted path with apply_params(), and identify it with model_hash(). The JSON Schema is exported with export_schema().

abmfact.ir.model

ABM-IR v0.1: one description of a biological agent-based model that every engine can read.

The vocabulary follows PhysiCell, so a declarative PhysiCell project maps onto it closely, but nothing here is specific to one engine. Units are those named in units (micron and minute by default, as in PhysiCell). Engine-specific code that cannot be described declaratively is listed under native_extensions and is never translated.

class abmfact.ir.model.Units(*, space: str = 'micron', time: str = 'min')[source]

Bases: _Base

The units of length and time that the model’s quantities are given in.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.Bounds(*, x_min: float, x_max: float, y_min: float, y_max: float, z_min: float = -10.0, z_max: float = 10.0)[source]

Bases: _Base

The extent of the domain along each axis. Each minimum must be below its maximum.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.Voxel(*, dx: Annotated[float, Gt(gt=0)], dy: Annotated[float, Gt(gt=0)], dz: Annotated[float, Gt(gt=0)] = 20.0)[source]

Bases: _Base

The size of one voxel of the substrate grid. In a 2D model dz still sets the voxel volume.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.Space(*, dimensions: Literal[2, 3] = 2, bounds: Bounds, voxel: Voxel, boundary: Literal['closed', 'periodic'] = 'closed')[source]

Bases: _Base

The simulation domain: its dimension, bounds, substrate grid, and whether it is closed or periodic.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.SubstrateBoundary(*, kind: ~typing.Literal['no_flux', 'dirichlet'] = 'no_flux', value: ~typing.Annotated[float, ~annotated_types.Ge(ge=0)] = 0.0, sides: dict[~typing.Literal['x_min', 'x_max', 'y_min', 'y_max', 'z_min', 'z_max'], ~typing.Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=0)])] | None] = <factory>)[source]

Bases: _Base

dirichlet holds every side at value; sides overrides one side, None makes it no-flux.

value_at(side: str) → float | None[source]

The Dirichlet value on one side, or None for no flux.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.Substrate(*, name: ~typing.Annotated[str, ~annotated_types.MinLen(min_length=1), _PydanticGeneralMetadata(pattern='^[^,\\n]+$')], units: str = 'dimensionless', diffusion_coefficient: ~typing.Annotated[float, ~annotated_types.Ge(ge=0)], decay_rate: ~typing.Annotated[float, ~annotated_types.Ge(ge=0)] = 0.0, initial_value: ~typing.Annotated[float, ~annotated_types.Ge(ge=0)] = 0.0, boundary: ~abmfact.ir.model.SubstrateBoundary = <factory>)[source]

Bases: _Base

A diffusing substance, with its diffusion coefficient, decay rate, initial value and boundary.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.Cycle(*, model: Literal['live', 'flow_cytometry', 'flow_cytometry_separated', 'ki67_basic', 'ki67_advanced', 'cycling_quiescent', 'custom'] = 'live', rates: list[Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=0)])]] | None = None, durations: list[Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Gt(gt=0)])]] | None = None)[source]

Bases: _Base

A cell cycle. live has one phase whose exit rate is the division rate.

Give either rates (phase exit rates, per time unit, in phase order) or durations (fixed phase durations), as PhysiCell does.

property division_rate: float

Total rate of completing the cycle, for a cycle read as phases in series.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.Death(*, apoptosis_rate: Annotated[float, Ge(ge=0)] = 0.0, necrosis_rate: Annotated[float, Ge(ge=0)] = 0.0, apoptosis_duration: Annotated[float, Gt(gt=0)] = 516.0, necrosis_duration: Annotated[float, Gt(gt=0)] = 86400.0)[source]

Bases: _Base

Apoptosis and necrosis rates, and how long a dead cell remains before it is removed.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.Integrity(*, damage_rate: Annotated[float, Ge(ge=0)] = 0.0, damage_repair_rate: Annotated[float, Ge(ge=0)] = 0.0)[source]

Bases: _Base

Damage a cell carries, as in PhysiCell’s cell integrity: it grows at damage_rate and is repaired at damage_repair_rate, both per unit time. Attacks add to it, and rules can read it as the damage signal.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.Mechanics(*, adhesion_strength: Annotated[float, ~annotated_types.Ge(ge=0)] = 0.4, repulsion_strength: Annotated[float, ~annotated_types.Ge(ge=0)] = 10.0, max_adhesion_distance: Annotated[float, ~annotated_types.Ge(ge=1.0)] = 1.25, adhesion_affinities: dict[str, ~typing.Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=0)])]] = <factory>)[source]

Bases: _Base

Centre-based mechanics. max_adhesion_distance is relative to the cell radius, as in PhysiCell.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.Chemotaxis(*, substrate: Annotated[str, MinLen(min_length=1), _PydanticGeneralMetadata(pattern='^[^,\\n]+$')], direction: Literal[1, -1] = 1)[source]

Bases: _Base

Migration bias along one substrate’s gradient: direction 1 moves up the gradient, -1 down it.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.Motility(*, speed: Annotated[float, Ge(ge=0)] = 0.0, persistence_time: Annotated[float, Gt(gt=0)] = 1.0, migration_bias: Annotated[float, Ge(ge=0), Le(le=1)] = 0.0, chemotaxis: Chemotaxis | None = None)[source]

Bases: _Base

Cell migration, as in PhysiCell: speed, persistence time and migration bias.

migration_bias runs from 0 (a random direction) to 1 (the chemotaxis direction only).

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.Secretion(*, substrate: Annotated[str, MinLen(min_length=1), _PydanticGeneralMetadata(pattern='^[^,\\n]+$')], secretion_rate: Annotated[float, Ge(ge=0)] = 0.0, target: Annotated[float, Ge(ge=0)] = 1.0, uptake_rate: Annotated[float, Ge(ge=0)] = 0.0, net_export_rate: float = 0.0)[source]

Bases: _Base

Exchange of one substrate between a cell and its voxel, as in PhysiCell.

The cell secretes towards the target density at secretion_rate, takes up at uptake_rate, and adds net_export_rate of substrate per time unit.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.Interactions(*, attack_rates: dict[str, ~typing.Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=0)])]] = <factory>, damage_rate: Annotated[float, ~annotated_types.Ge(ge=0)] = 0.0, attack_duration: Annotated[float, ~annotated_types.Gt(gt=0)] = 0.1, immunogenicities: dict[str, ~typing.Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=0)])]] = <factory>, phagocytosis_rates: dict[str, ~typing.Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=0)])]] = <factory>, dead_phagocytosis_rate: Annotated[float, ~annotated_types.Ge(ge=0)] = 0.0, fusion_rates: dict[str, ~typing.Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=0)])]] = <factory>)[source]

Bases: _Base

Contact interactions with other cells, as in PhysiCell.

Attack, phagocytosis and fusion rates are keyed by the name of the target cell type. damage_rate is the attack damage rate, and dead_phagocytosis_rate applies to dead cells of any type. An attack lasts attack_duration on average. immunogenicities scales how readily each attacker type starts an attack on this cell type, keyed by the attacker’s name; a missing type counts as 1.

property active: bool

Whether any attack, phagocytosis, fusion or dead phagocytosis rate is above zero.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.CellType(*, name: ~typing.Annotated[str, ~annotated_types.MinLen(min_length=1), _PydanticGeneralMetadata(pattern='^[^,\\n]+$')], volume: ~typing.Annotated[float, ~annotated_types.Gt(gt=0)] = 2494.0, cycle: ~abmfact.ir.model.Cycle = <factory>, death: ~abmfact.ir.model.Death = <factory>, integrity: ~abmfact.ir.model.Integrity = <factory>, mechanics: ~abmfact.ir.model.Mechanics = <factory>, motility: ~abmfact.ir.model.Motility = <factory>, secretion: list[~abmfact.ir.model.Secretion] = <factory>, interactions: ~abmfact.ir.model.Interactions = <factory>, transformations: dict[str, ~typing.Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=0)])]] = <factory>, custom: dict[str, float] = <factory>)[source]

Bases: _Base

One cell type: its volume, cycle, death, mechanics, motility, secretion and interactions.

transformations maps other cell type names to the rate of turning into that type. custom holds named numeric custom data.

property radius: float

Radius of a sphere with this volume.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.Rule(*, cell_type: Annotated[str, MinLen(min_length=1), _PydanticGeneralMetadata(pattern='^[^,\\n]+$')], signal: Annotated[str, MinLen(min_length=1), _PydanticGeneralMetadata(pattern='^[^,\\n]+$')], direction: Literal['increases', 'decreases'], behaviour: Annotated[str, MinLen(min_length=1), _PydanticGeneralMetadata(pattern='^[^,\\n]+$')], saturation_value: Annotated[float, Ge(ge=0)], half_max: Annotated[float, Gt(gt=0)], hill_power: Annotated[float, Gt(gt=0)], apply_to_dead: bool = False)[source]

Bases: _Base

One signal-to-behaviour rule in PhysiCell’s cell behaviour grammar (CBHG, rules CSV version 3).

saturation_value is the behaviour value when the signal saturates: the maximum for an increases rule and the minimum for a decreases rule. The base value comes from the cell type.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.IntracellularModel(*, cell_type: ~typing.Annotated[str, ~annotated_types.MinLen(min_length=1), _PydanticGeneralMetadata(pattern='^[^,\\n]+$')], format: ~typing.Literal['maboss', 'sbml', 'sbml-qual'], files: dict[str, str], inputs: dict[str, str] = <factory>, outputs: dict[str, str] = <factory>, time_step: ~typing.Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Gt(gt=0)])] | None = None, settings: dict[str, ~typing.Any] = <factory>)[source]

Bases: _Base

A reference to an intracellular model file. Paths are relative to the IR file.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.Placement(*, kind: Literal['disc', 'rectangle', 'random', 'positions', 'positions_csv'], cell_type: Annotated[str, FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1), _PydanticGeneralMetadata(pattern='^[^,\\n]+$')])] | None = None, count: Annotated[int, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=0)])] | None = None, density: Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=0)])] | None = None, centre: tuple[float, float] = (0.0, 0.0), radius: Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Gt(gt=0)])] | None = None, size: tuple[Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Gt(gt=0)])], Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Gt(gt=0)])]] | None = None, positions: list[tuple[float, float]] | None = None, path: str | None = None)[source]

Bases: _Base

Initial cells. density is cells per unit area (2D) or volume (3D); positions are explicit.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.InitialConditions(*, placements: list[Placement] = <factory>)[source]

Bases: _Base

The cells present at the start of a run, as a list of placements.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.TimedEvent(*, time: Annotated[float, Ge(ge=0)], action: Literal['set_substrate_boundary', 'set_substrate', 'add_cells', 'set_parameter'], target: Annotated[str, MinLen(min_length=1), _PydanticGeneralMetadata(pattern='^[^,\\n]+$')], value: float | None = None, until: Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=0)])] | None = None)[source]

Bases: _Base

A change at a set time, held until until when given (then reverted), for example a drug pulse.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.Observable(*, name: Annotated[str, _PydanticGeneralMetadata(pattern='^[A-Za-z_][A-Za-z0-9_]*$')], kind: Literal['cell_count', 'live_count', 'dead_count', 'type_fraction', 'mean_position', 'radius_of_gyration', 'substrate_mean', 'substrate_min', 'substrate_max'], cell_type: Annotated[str, FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1), _PydanticGeneralMetadata(pattern='^[^,\\n]+$')])] | None = None, substrate: Annotated[str, FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1), _PydanticGeneralMetadata(pattern='^[^,\\n]+$')])] | None = None, axis: Literal['x', 'y', 'z'] = 'x')[source]

Bases: _Base

A named quantity measured at every saved time, such as a cell count or a substrate mean.

cell_type restricts a count or position to one type. The substrate_ kinds need substrate, and type_fraction needs cell_type.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.Experiment(*, max_time: Annotated[float, Gt(gt=0)], dt_diffusion: Annotated[float, Gt(gt=0)] = 0.01, dt_mechanics: Annotated[float, Gt(gt=0)] = 0.1, dt_phenotype: Annotated[float, Gt(gt=0)] = 6.0, save_interval: Annotated[float, Gt(gt=0)] = 60.0, threads: Annotated[int, Ge(ge=1)] = 1)[source]

Bases: _Base

The run length, the time steps and the save interval, in the model’s time unit, as in PhysiCell.

dt_diffusion, dt_mechanics and dt_phenotype are the steps of each process. threads is the number of threads an engine may use.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.DerivedFrom(*, engine: str, path: str, sha256: str | None = None)[source]

Bases: _Base

The engine project a model was imported from, with an optional SHA-256 digest of its source.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.Provenance(*, source: str | None = None, doi: str | None = None, authors: list[str] = <factory>, licence: str | None = None, derived_from: DerivedFrom | None = None, created_with: str | None = None, notes: str = '')[source]

Bases: _Base

Where a model came from: its source, DOI, authors, licence, origin project and the tool that made it.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.NativeExtension(*, engine: str, kind: ~typing.Literal['custom_cpp', 'custom_function', 'other'], files: list[str] = <factory>, description: str = '', affects: list[str] = <factory>)[source]

Bases: _Base

Engine-specific code that the IR does not describe and never translates. affects names what it may change.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class abmfact.ir.model.IRModel(*, schema_version: ~typing.Literal['0.1'] = '0.1', name: ~typing.Annotated[str, ~annotated_types.MinLen(min_length=1), _PydanticGeneralMetadata(pattern='^[^,\\n]+$')], description: str = '', units: ~abmfact.ir.model.Units = <factory>, space: ~abmfact.ir.model.Space, substrates: list[~abmfact.ir.model.Substrate] = <factory>, cell_types: ~typing.Annotated[list[~abmfact.ir.model.CellType], ~annotated_types.MinLen(min_length=1)], rules: list[~abmfact.ir.model.Rule] = <factory>, intracellular: list[~abmfact.ir.model.IntracellularModel] = <factory>, initial_conditions: ~abmfact.ir.model.InitialConditions = <factory>, events: list[~abmfact.ir.model.TimedEvent] = <factory>, observables: list[~abmfact.ir.model.Observable] = <factory>, experiment: ~abmfact.ir.model.Experiment, provenance: ~abmfact.ir.model.Provenance = <factory>, native_extensions: list[~abmfact.ir.model.NativeExtension] = <factory>)[source]

Bases: _Base

An ABM-IR document.

property source_dir: Path | None

The folder relative file paths are resolved against (the IR file’s folder), or None.

resolve(path: str) → Path[source]

A file path from the model, made absolute against the IR file’s folder.

cell_type(name: str) → CellType[source]

The cell type called name. Raises KeyError when the model has none.

substrate(name: str) → Substrate[source]

The substrate called name. Raises KeyError when the model has none.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_post_init(context: Any, /) → None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • context – The context.

abmfact.ir.model.reference_problems(m: IRModel) → list[tuple[str, str]][source]

Every cross-reference that names something the model does not define, as (path, message).

abmfact.ir.io

Load, save, hash and parameterise ABM-IR documents, and export the JSON Schema.

abmfact.ir.io.UNHASHED = ('description', 'provenance')

Fields that describe a model without changing what it computes; they are left out of the hash.

abmfact.ir.io.model_from_dict(doc: Any, source: str | None = None, source_dir: Path | None = None) → IRModel[source]

Validate a mapping as an ABM-IR model, raising IRError with dotted paths.

abmfact.ir.io.load_model(path: str | Path) → IRModel[source]

Read an ABM-IR model from a YAML or JSON file.

abmfact.ir.io.model_to_dict(model: IRModel, full: bool = False) → dict[str, Any][source]

A plain mapping. Defaults are left out unless full; schema_version always comes first.

abmfact.ir.io.save_model(model: IRModel, path: str | Path) → Path[source]

Write a model as YAML, or JSON when the suffix is .json.

abmfact.ir.io.model_hash(model: IRModel) → str[source]

SHA-256 of what the model computes: every field except description and provenance, plus the contents of the files it references (initial positions and intracellular models). Text files are hashed with LF line endings, so a Windows checkout gives the same hash.

abmfact.ir.io.read_cells_csv(path: str | Path, type_names: list[str]) → tuple[list[tuple[float, float, float]], list[str]][source]

Initial cells from a PhysiCell-style cells.csv: x,y,z,type with or without a header.

type is a cell type name or an index into type_names; extra columns are ignored.

abmfact.ir.io.apply_params(model: IRModel, params: Mapping[str, Any]) → IRModel[source]

A copy of model with values replaced at dotted paths.

cell_types[tumour].cycle.rates[0] addresses a list item by name and then by index. A path to a mapping key that does not exist yet adds it (useful for custom values and affinities). Every change is validated, so a bad value fails with the same messages as a bad file.

abmfact.ir.io.schema_dict() → dict[str, Any][source]

The JSON Schema of ABM-IR, as exported to schemas/abm-ir-<version>.json.

abmfact.ir.io.export_schema(path: str | Path) → Path[source]

Write the ABM-IR JSON Schema to path and return the path.

abmfact.ir.errors

Validation errors that name the exact place in the document.

exception abmfact.ir.errors.IRError(errors: Sequence[tuple[str, str]], source: str | None = None)[source]

Bases: ValueError

An ABM-IR document is not valid. errors lists (dotted path, message) pairs.

abmfact.ir.errors.dotted_path(loc: Sequence[Any], doc: Any) → str[source]

Turn a pydantic error location into cell_types[tumour].cycle.rates[1].

List items that have a name are addressed by name, so the path stays readable and matches the syntax of abmfact.ir.apply_params().

abmfact.ir.errors.from_validation_error(exc: Any, doc: Any, source: str | None = None) → IRError[source]

Convert a pydantic ValidationError. Cross-reference problems arrive as path: message lines.

abmfact.ir.vocabulary

Signal and behaviour names for rules, as PhysiCell 1.14.2 defines them.

The lists follow setup_signal_behavior_dictionaries in core/PhysiCell_signal_behavior.cpp of PhysiCell 1.14.2. Names that contain a substrate or cell type are matched as patterns, so a rule can only name substrates and cell types that the model defines.

abmfact.ir.vocabulary.is_signal(name: str, substrates: Iterable[str], cell_types: Iterable[str]) → bool[source]

True when name is a PhysiCell signal for a model with these substrates and cell types.

abmfact.ir.vocabulary.is_behaviour(name: str, substrates: Iterable[str], cell_types: Iterable[str]) → bool[source]

True when name is a PhysiCell behaviour for a model with these substrates and cell types.