biocrnpyler.core.Compartment

class biocrnpyler.core.Compartment(name: str, size=1e-06, spatial_dimensions=3, unit=None)[source]

Bases: object

Spatial compartment for organizing species in a CRN model.

Compartments represent physically distinct regions where chemical species can exist, such as the cytoplasm, nucleus, extracellular space, or organelles. Each compartment has a name, size, and spatial dimensionality. Species in different compartments are treated as distinct, even if they have the same molecular identity.

Parameters:
  • name (str) – Name of the compartment. Must consist of letters, numbers, or underscores. Cannot contain double underscores, and cannot begin or end with special characters. Must start with a letter. The name ‘default’ is reserved by BioCRNpyler.

  • size (float or int, default 1e-6) – Size of the compartment in the units specified by unit. Default is 1 microliter (1e-6 liters).

  • spatial_dimensions (int, default 3) – Number of spatial dimensions (0 for point, 1 for line, 2 for surface, 3 for volume). Must be non-negative.

  • unit (str, optional) – Unit identifier for the compartment size (e.g., ‘L’, ‘mL’, ‘µL’). Must be a supported unit in BioCRNpyler. See documentation for supported units or add custom units in ‘core/units.py’.

Attributes:
  • name (str) – Name of the compartment.

  • size (float) – Size of the compartment.

  • spatial_dimensions (int) – Number of spatial dimensions.

  • unit (str or None) – Unit identifier for the compartment size.

Raises:

See also

Species

Chemical species that can be assigned to compartments.

Mixture

Container that can have a default compartment.

Notes

The reserved name ‘default’ is used internally by BioCRNpyler for species that have not been explicitly assigned to a compartment. User-defined compartments should use other names.

Two compartments are considered equal if they have the same name. If two compartments have the same name but different sizes or spatial dimensions, a ValueError is raised to prevent inconsistencies.

Examples

Create a cytoplasm compartment:

>>> cytoplasm = bcp.Compartment(
...     name="cytoplasm",
...     size=1e-15,  # 1 femtoliter (bacterial cell volume)
...     spatial_dimensions=3,
...     unit="L"
... )

Create a membrane compartment (2D):

>>> membrane = bcp.Compartment(
...     name="membrane",
...     size=1e-12,  # 1 square micrometer
...     spatial_dimensions=2,
...     unit="m^2"
... )

Use compartments with species:

>>> species_cyto = bcp.Species("Protein_X", compartment=cytoplasm)
>>> species_mem = bcp.Species("Protein_X", compartment=membrane)
>>> species_cyto == species_mem  # False - different compartments

Methods

__eq__(other)[source]

Check equality of compartments by name.

Two compartments are considered equal if they have the same name. If two compartments have the same name but different sizes or spatial dimensions, a ValueError is raised to prevent inconsistencies.

Parameters:

other (Compartment) – Another compartment to compare with.

Returns:

True if compartments have the same name (and consistent attributes), False otherwise.

Return type:

bool

Raises:

ValueError – If compartments have the same name but different sizes or spatial dimensions.

Notes

This comparison is based solely on the compartment name. If two compartments share a name, they must also share the same physical properties (size and spatial dimensions) to maintain model consistency.

property name

Name of the compartment.

Type:

str

property size

Size of compartment in units specified by unit attribute.

Type:

float

property spatial_dimensions

Number of spatial dimensions.

0 for point, 1 for line, 2 for surface, 3 for volume.

Type:

int

property unit

Unit identifier for compartment size (e.g., ‘mL’, ‘uL’).

Type:

str