biocrnpyler.core.compartment

Classes

Compartment(name[, size, ...])

Spatial compartment for organizing species in a CRN model.

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

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:
namestr

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.

sizefloat or int, default=1e-6

Size of the compartment in the units specified by unit. Default is 1 microliter (1e-6 liters).

spatial_dimensionsint, default=3

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

unitstr, 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:
namestr

str: Name of the compartment.

sizefloat

float: Size of compartment in units specified by unit attribute.

spatial_dimensionsint

int: Number of spatial dimensions.

unitstr or None

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

Raises:
TypeError

If name is None.

ValueError

If name is not a string, contains invalid characters, or if size or spatial_dimensions are invalid.

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
__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:
otherCompartment

Another compartment to compare with.

Returns:
bool

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

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

str: Name of the compartment.

property size

float: Size of compartment in units specified by unit attribute.

property spatial_dimensions

int: Number of spatial dimensions.

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

property unit

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