Undirected and directed polymer assembly pool
An assembly pool of linear polymers grown from one monomer.
- Class:
PolymerAssemblyPoolSystem - Import:
from skcomplex.systems.biology.evolution import PolymerAssemblyPoolSystem - Field:
biology/evolution - Topics:
assembly theory,selection,polymers,agents - References:
- Sharma et al. 2023
Use this system
The block imports the class and simulates the system with its default parameters and its tuned run settings.
from skcomplex.systems.biology.evolution import PolymerAssemblyPoolSystem
trajectory = PolymerAssemblyPoolSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
mode |
'undirected' |
solver |
'auto' |
backend |
'auto' |
Tags
The system with its default parameters has these capability tags, which solvers and analyses check.
| Tag | Values |
|---|---|
| Time | discrete |
| Space | none |
| Laws | update |
| Randomness | stochastic |
| Domains | integer |
| Structure | variable membership |
Class
The source of the class shows how it builds its components from its model parameters.
class PolymerAssemblyPoolSystem(BaseSystem):
"""An assembly pool of linear polymers grown from one monomer.
The pool grows by joining pairs of its polymers.
Undirected exploration joins two random polymers of the pool, and directed exploration, a model of selection, joins
the newest polymer with a random one. Undirected joining fills the pool with many short polymers, while directed
joining builds ever longer chains, of a higher assembly index, about the base 2 logarithm of the length. The system
has the lengths `pool.length` of the variable group `pool`.
Args:
mode:
`'undirected'` or `'directed'`.
label:
The label of the system, which names it when it is nested in another one.
solver:
The solver of the problem, or `'auto'` for the one the system chooses.
backend:
The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.
Examples:
>>> from skcomplex.systems.biology.evolution import PolymerAssemblyPoolSystem
>>> PolymerAssemblyPoolSystem('directed').prepare().system_.interactions[0].mode
'directed'
"""
field = 'biology/evolution'
topics = ('assembly theory', 'selection', 'polymers', 'agents')
references = ('Sharma et al. 2023',)
until = 200
def __init__(
self,
mode: str = 'undirected',
*,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.mode = mode
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set an assembly pool of linear polymers grown from one monomer.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
pool = PolymerElement('pool', size=1)
self.system_ = System(
self.label,
elements=[pool],
interactions=[PolymerJoiningInteraction('joining', polymers='pool', mode=self.mode)],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
PolymerElement, fromElement
Interactions:
PolymerJoiningInteraction, fromInteraction
class PolymerElement(Element):
"""Linear polymer of an assembly pool, with its length and the step it was made.
Args:
label:
The label of the polymer or of the group of polymers.
length:
The number of monomers.
born:
The step at which the polymer was made.
size:
The number of polymers, or `None` for one.
Examples:
>>> from skcomplex.systems.biology.evolution import PolymerElement
>>> PolymerElement('polymer', length=3.0).length
3.0
"""
def __init__(
self,
label: str,
*,
length: Annotated[float | Array, NN] = 1.0,
born: Annotated[float | Array, NN] = 0.0,
size: int | None = None,
) -> None:
super().__init__(label, size=size)
self.length = length
self.born = born
class PolymerJoiningInteraction(Interaction):
"""Joining of two polymers of an assembly pool into a new one.
The polymers are joined at random or by reuse of the newest polymer.
At every step, undirected exploration joins two polymers drawn at random from the pool, and directed exploration
joins the polymer made most recently with one drawn at random. The joined polymer, of the summed length, is added
to the pool, and the two polymers it joins stay in it.
Args:
label:
The label of the interaction.
polymers:
The path of the variable group of polymers.
mode:
`'undirected'` or `'directed'`.
Raises:
ValidationError:
The mode is unknown.
Examples:
>>> from skcomplex.systems.biology.evolution import PolymerJoiningInteraction
>>> PolymerJoiningInteraction('joining', polymers='pool', mode='directed').mode
'directed'
"""
draws = True
law_classes = (UpdateLaw,)
def __init__(self, label: str, *, polymers: Role, mode: str = 'undirected') -> None:
super().__init__(label)
self.polymers = polymers
self.mode = mode
def _check_arguments(self) -> None:
"""Raise an error for an argument the interaction cannot take.
Raises:
ValidationError:
The mode is unknown.
"""
super()._check_arguments()
if self.mode not in MODES:
error_msg = f'The mode must be one of {", ".join(MODES)}, not {self.mode!r}.'
raise ValidationError(error_msg)
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the joining, a rule of the whole system.
Args:
context:
The namespace of the system.
"""
super()._prepare(context)
self.laws_: list[BaseLaw] = [UpdateLaw(context, self.join)]
def join(self, system: SystemView) -> None:
"""Join two polymers and add the product to the pool.
Args:
system:
The system.
"""
pool = cast(list[PolymerView], system.get_agents(self.polymers))
partner = pool[int(system.rng.integers(len(pool)))]
if self.mode == 'directed':
first = max(pool, key=lambda polymer: polymer.born)
else:
first = pool[int(system.rng.integers(len(pool)))]
born = max(polymer.born for polymer in pool) + 1
system.create(self.polymers, length=first.length + partner.length, born=born)
Equations
The equations are those that symbolic returns for the system with its default parameters.