Skip to content

Hypercycles

A hypercycle of self-replicating molecules.

  • Class: HypercyclesSystem
  • Import: from skcomplex.systems.biology.evolution import HypercyclesSystem
  • Field: biology/evolution
  • Topics: hypercycle, autocatalysis, prebiotic, ode
  • References:
    • Eigen and Schuster 1977
    • Gros 2015

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 HypercyclesSystem

trajectory = HypercyclesSystem().prepare().simulate()

Parameters

The model parameters take these defaults, and set_params changes them.

Parameter Default
molecules 4
alpha 0.1
omega 1.0
topology 'cycle'
solver 'auto'
backend 'auto'

Tags

The system with its default parameters has these capability tags, which solvers and analyses check.

Tag Values
Time continuous
Space none
Laws rate
Randomness deterministic
Domains real
Structure fixed

Class

The source of the class shows how it builds its components from its model parameters.

class HypercyclesSystem(BaseSystem):
    """A hypercycle of self-replicating molecules.

    The catalysis of the network keeps a set of them alive.

    The growth rates rise as `lambda_i = alpha i`. In a `'cycle'`, every molecule catalyses the next one. Up to four
    molecules the hypercycle keeps all of them at a fixed point, and from five some members die out and the others
    settle at a fixed point. In a `'complete'` network every molecule catalyses every other, and about `sqrt(2 omega /
    alpha)` of the fastest replicators survive while the others die out. The system has the concentrations `soup.x` of
    the molecules, members of the group `soup`.

    Args:
        molecules:
            The number of molecules.

        alpha:
            The step of the autocatalytic growth rates.

        omega:
            The catalytic rate of a link.

        topology:
            `'cycle'` or `'complete'`.

        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.

    Raises:
        ValidationError:
            The topology is unknown.

    Examples:
        >>> from skcomplex.systems.biology.evolution import HypercyclesSystem
        >>> HypercyclesSystem(3).prepare().system_.interactions[0].topology
        ((0.0, 0.0, 1.0), (1.0, 0.0, 0.0), (0.0, 1.0, 0.0))
    """

    field = 'biology/evolution'
    topics = ('hypercycle', 'autocatalysis', 'prebiotic', 'ode')
    references = ('Eigen and Schuster 1977', 'Gros 2015')
    until = 50.0
    dt = 0.5

    def __init__(
        self,
        molecules: int = 4,
        *,
        alpha: float = 0.1,
        omega: float = 1.0,
        topology: str = 'cycle',
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.molecules = molecules
        self.alpha = alpha
        self.omega = omega
        self.topology = topology

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the system of a hypercycle of self-replicating molecules.

        Args:
            context:
                The observables to compile with the problem, or `None` for none.
        """
        super()._prepare(context)
        if self.topology == 'cycle':
            links = np.roll(np.eye(self.molecules), 1, axis=0)
        elif self.topology == 'complete':
            links = 1 - np.eye(self.molecules)
        else:
            error_msg = f'Unknown topology {self.topology!r}. Use cycle or complete.'
            raise ValidationError(error_msg)
        soup = MoleculeElement(
            'soup',
            x=[1 / self.molecules] * self.molecules,
            growth=[float(self.alpha * index) for index in range(1, self.molecules + 1)],
            size=self.molecules,
        )
        catalysis = CatalysisInteraction(
            'catalysis',
            target='soup',
            omega=self.omega,
            topology=tuple(tuple(float(value) for value in row) for row in links),
        )
        self.system_ = System(self.label, elements=[soup], interactions=[catalysis])

Components

The system uses these element and interaction classes, each with its nearest class of the core.

Elements:

Interactions:

  • CatalysisInteraction, from Interaction
class MoleculeElement(Element):
    """Self-replicating molecule of a prebiotic soup.

    It has its concentration `x` and its own growth rate.

    Args:
        label:
            The label of the molecule or of the group of molecules.

        x:
            The initial concentration.

        growth:
            The rate of replication without catalysis.

        size:
            The number of molecules, or `None` for one.

    Examples:
        >>> from skcomplex.systems.biology.evolution import MoleculeElement
        >>> MoleculeElement('molecule', growth=0.1).growth
        0.1
    """

    def __init__(
        self,
        label: str,
        *,
        x: Annotated[object, RealSet.closed_open(0, oo)] = 0.5,
        growth: object = 0.0,
        size: int | None = None,
    ) -> None:
        super().__init__(label, size=size)
        self.x = x
        self.growth = growth

class CatalysisInteraction(ReplicatorInteraction):
    """Catalysed replication of the molecules of a group.

    A common outflow keeps the total at 1.

    Molecule `i` replicates at the rate `f_i = lambda_i + omega sum_j T_ij x_j`, with its own growth `lambda_i` and the
    0 or 1 topology `T` of the catalytic links read as the weights of a total over the molecules. The outflow is the
    total replication, so the concentrations follow the replicator equation `dx_i/dt = x_i (f_i - sum_j x_j f_j)`.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the group of molecules.

        omega:
            The catalytic rate of a link.

        topology:
            The catalytic links, 1 where molecule `j` catalyses molecule `i`.

    Examples:
        >>> from skcomplex.systems.biology.evolution import CatalysisInteraction
        >>> CatalysisInteraction('catalysis', target='soup', topology=((0, 1), (1, 0))).topology
        ((0, 1), (1, 0))
    """

    def __init__(
        self,
        label: str,
        *,
        target: Role,
        omega: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
        topology: Sequence[Sequence[float]] = ((0.0, 1.0), (1.0, 0.0)),
    ) -> None:
        super().__init__(label, target=target)
        self.omega = omega
        self.topology = topology

    def _check_fitness(self) -> None:
        """Leave the fitness unchecked, since the catalysis derives it from its topology."""

    def _get_fitness(self, namespace: SimpleNamespace) -> Expression:
        """Return the catalysed growth `lambda_i + omega sum_j T_ij x_j` of a molecule.

        Args:
            namespace:
                The namespace of the symbols the fitness can use, with the namespace of the target.

        Returns:
            fitness:
                The fitness of the molecule.
        """
        molecule = namespace.target
        fitness: Expression = molecule.growth + namespace.omega * total(
            molecule.x,
            weights=np.asarray(self.topology, dtype=float),
        )
        return fitness

Equations

The equations are those that symbolic returns for the system with its default parameters.

soup.x[i]: diff(x_soup(t), t) == (_reduced_0*omega_catalysis - _reduced_1 + growth_soup)*x_soup(t)