Skip to content

Chiral active particles

Chiral active particles.

  • Class: ChiralActiveParticlesSystem
  • Import: from skcomplex.systems.physics.active_matter import ChiralActiveParticlesSystem
  • Field: physics/active_matter
  • Topics: active matter, sde, self-propulsion, chirality
  • References:
    • Bechinger et al. 2016
    • van Teeffelen and Löwen 2008

Use this system

The block imports the class and simulates the system with its default parameters and its tuned run settings.

from skcomplex.systems.physics.active_matter import ChiralActiveParticlesSystem

trajectory = ChiralActiveParticlesSystem().prepare().simulate()

Parameters

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

Parameter Default
n_particles 200
speed 3.0
omega 2.0
D_t 0.1
D_r 0.1
size 50.0
random_state 0
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 continuous
Laws noise, rate
Randomness stochastic
Domains real, vector
Structure fixed

Class

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

class ChiralActiveParticlesSystem(BaseSystem):
    """Chiral active particles.

    The particles swim along circles of radius `v / omega` that drift by diffusion.

    Their effective diffusion coefficient at long times is `D_t + v^2 D_r / (2 (D_r^2 + omega^2))`. The system has the
    positions `swimmers.x` and orientations `swimmers.theta`.

    Args:
        n_particles:
            The number of particles.

        speed:
            The self-propulsion speed.

        omega:
            The angular velocity.

        D_t:
            The translational diffusion coefficient.

        D_r:
            The rotational diffusion coefficient.

        size:
            The side of the square in which the particles start.

        random_state:
            The seed or generator of the initial positions and orientations.

        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.physics.active_matter import ChiralActiveParticlesSystem
        >>> ChiralActiveParticlesSystem(10, omega=1.0).prepare().system_.interactions[0].omega
        1.0
    """

    field = 'physics/active_matter'
    topics = ('active matter', 'sde', 'self-propulsion', 'chirality')
    references = ('Bechinger et al. 2016', 'van Teeffelen and Löwen 2008')
    until = 20.0
    dt = 0.5

    def __init__(
        self,
        n_particles: int = 200,
        *,
        speed: float = 3.0,
        omega: float = 2.0,
        D_t: float = 0.1,
        D_r: float = 0.1,
        size: float = 50.0,
        random_state: int | np.random.Generator | None = 0,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.n_particles = n_particles
        self.speed = speed
        self.omega = omega
        self.D_t = D_t
        self.D_r = D_r
        self.size = size
        self.random_state = random_state

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the system of chiral active particles.

        Args:
            context:
                The observables to compile with the problem, or `None` for none.
        """
        super()._prepare(context)
        positions, angles = ActiveBrownianParticlesSystem._get_swimmers(self.n_particles, self.size, self.random_state)
        swimmers = ActiveParticleElement(
            'swimmers',
            x=positions,
            theta=angles,
            size=self.n_particles,
            space=ContinuousSpace(n_dim=2),
        )
        diffusion = ActiveDiffusionInteraction(
            'diffusion',
            target='swimmers',
            D_t=self.D_t,
            D_r=self.D_r,
            omega=self.omega,
        )
        self.system_ = System(
            self.label,
            elements=[swimmers],
            interactions=[diffusion, SelfPropulsionInteraction('propulsion', target='swimmers', speed=self.speed)],
            solver=EulerMaruyamaSolver(dt=0.01),
        )

Components

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

Elements:

  • ActiveParticleElement, from Element

Interactions:

  • ActiveDiffusionInteraction, from Interaction
  • SelfPropulsionInteraction, from Interaction
class ActiveParticleElement(Element):
    """Active particle in the plane with the position `x` and the orientation `theta`.

    A `SelfPropulsionInteraction` moves the position along the orientation, and an `ActiveDiffusionInteraction` makes
    both diffuse and the orientation turn.

    Args:
        label:
            The label of the particle or the group.

        x:
            The initial position, one row per particle or shared.

        theta:
            The initial orientation, one per particle or shared.

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

        space:
            The continuous space of the particles, or `None` for none.

    Examples:
        >>> from skcomplex.systems.physics.common.particles import ActiveParticleElement
        >>> ActiveParticleElement('swimmer', theta=1.0).theta
        1.0
    """

    visual = POINTS

    def __init__(
        self,
        label: str,
        *,
        x: object = (0.0, 0.0),
        theta: Annotated[object, Period(2 * math.pi)] = 0.0,
        size: int | None = None,
        space: BaseSpace | None = None,
    ) -> None:
        super().__init__(label, size=size, space=space)
        self.x = x
        self.theta = theta

class ActiveDiffusionInteraction(Interaction):
    """Diffusion of the position and the orientation of active particles.

    The position follows `dx = sqrt(2 D_t) dW` and the orientation `dtheta = omega dt + sqrt(2 D_r) dW`. With `omega =
    0` it is an active Brownian particle, and otherwise a chiral one. It is a bacterium, a Janus colloid, or a robot
    that loses its heading.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the particles, whose position is `x` and orientation `theta`.

        D_t:
            The translational diffusion coefficient.

        D_r:
            The rotational diffusion coefficient.

        omega:
            The angular velocity of a chiral particle.

    Examples:
        >>> import numpy as np
        >>> from skcomplex.core.components.spaces import ContinuousSpace
        >>> from skcomplex.core.engine.solvers import EulerMaruyamaSolver
        >>> from skcomplex.core.systems import System
        >>> from skcomplex.systems.physics.common.particles import ActiveDiffusionInteraction, ActiveParticleElement
        >>> plane = ContinuousSpace(n_dim=2)
        >>> swimmers = ActiveParticleElement('swimmers', x=np.zeros((4000, 2)), size=4000, space=plane)
        >>> diffusion = ActiveDiffusionInteraction('diffusion', target='swimmers', D_r=0.5)
        >>> system = System(elements=[swimmers], interactions=[diffusion], solver=EulerMaruyamaSolver(dt=0.1))
        >>> angles = system.prepare().simulate(until=2.0, dt=2.0, random_state=0).get_values('swimmers.theta')[-1]
        >>> round(float((angles**2).mean()), 1)
        2.0
    """

    law_classes = (NoiseLaw, RateLaw)

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

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the noise of the position, and the turning and the noise of the orientation of the target.

        Args:
            context:
                The namespace of the target, the time `t`, and the parameters.
        """
        super()._prepare(context)
        s = context
        theta = s.target.theta
        self.laws_ = [
            NoiseLaw(s.target.x, sqrt(2 * s.D_t)),
            RateLaw(theta.diff(s.t), s.omega),
            NoiseLaw(theta, sqrt(2 * s.D_r)),
        ]

class SelfPropulsionInteraction(Interaction):
    """Self-propulsion `x' += speed (cos theta, sin theta)` of a position in the plane.

    The position drifts along a heading `theta`, which other laws turn and diffuse. It is a swimming bacterium, a
    Janus colloid, or a walking robot.

    Args:
        label:
            The label of the interaction.

        target:
            The path of the particle or the group whose positions move.

        speed:
            The self-propulsion speed.

        state:
            The name of the vector value that holds the position.

        heading:
            The name of the value that holds the heading.

    Examples:
        >>> import math
        >>> from skcomplex.core.components.spaces import ContinuousSpace
        >>> from skcomplex.core.systems import System
        >>> from skcomplex.systems.physics.common.particles import ActiveParticleElement, SelfPropulsionInteraction
        >>> swimmer = ActiveParticleElement('swimmer', theta=math.pi / 2)
        >>> propulsion = SelfPropulsionInteraction('propulsion', target='swimmer', speed=2.0)
        >>> system = System(elements=[swimmer], interactions=[propulsion], space=ContinuousSpace(n_dim=2))
        >>> trajectory = system.prepare().simulate(until=1.0, dt=1.0)
        >>> trajectory.get_values('swimmer.x')[-1].round(6).tolist()
        [0.0, 2.0]
    """

    law_classes = (RateLaw,)

    def __init__(
        self,
        label: str,
        *,
        target: Role,
        speed: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
        state: str = 'x',
        heading: str = 'theta',
    ) -> None:
        super().__init__(label)
        self.target = target
        self.speed = speed
        self.state = state
        self.heading = heading

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the drift of the position of the target along its heading.

        Args:
            context:
                The namespace of the target, the time `t`, and the parameters.
        """
        super()._prepare(context)
        heading = getattr(context.target, self.heading)
        velocity = context.speed * vector(SR, [cos(heading), sin(heading)])
        self.laws_ = [RateLaw(getattr(context.target, self.state), velocity)]