Motility-induced phase separation
Repulsive active Brownian disks of unit diameter.
- Class:
MotilityInducedPhaseSeparationSystem - Import:
from skcomplex.systems.physics.active_matter import MotilityInducedPhaseSeparationSystem - Field:
physics/active_matter - Topics:
active matter,sde,phase separation,pair interaction - References:
- Cates and Tailleur 2015
- Bechinger et al. 2016
- Fily and Marchetti 2012
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 MotilityInducedPhaseSeparationSystem
trajectory = MotilityInducedPhaseSeparationSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
n_particles |
400 |
packing_fraction |
0.5 |
speed |
1.0 |
D_r |
0.01 |
k |
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 MotilityInducedPhaseSeparationSystem(BaseSystem):
"""Repulsive active Brownian disks of unit diameter.
The disks phase separate into clusters at high speed.
Disks that collide head on block each other until their orientations diffuse away, so fast swimmers with slow
rotational diffusion, a large Péclet number `v / D_r`, accumulate where they are slow and form dense clusters in a
dilute gas. The system has the positions `swimmers.x` and orientations `swimmers.theta`.
Args:
n_particles:
The number of disks.
packing_fraction:
The fraction of the periodic box the disks cover.
speed:
The self-propulsion speed.
D_r:
The rotational diffusion coefficient.
k:
The stiffness of the repulsion times the mobility.
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 MotilityInducedPhaseSeparationSystem
>>> MotilityInducedPhaseSeparationSystem(16).prepare().system_.interactions[2].k
50.0
"""
field = 'physics/active_matter'
topics = ('active matter', 'sde', 'phase separation', 'pair interaction')
references = ('Cates and Tailleur 2015', 'Bechinger et al. 2016', 'Fily and Marchetti 2012')
until = 20.0
dt = 0.1
@staticmethod
def _get_disks(
n_particles: int,
size: float,
random_state: int | np.random.Generator | None,
) -> tuple[Array, Array]:
"""Return positions on a jittered square grid over a box, and uniform orientations."""
rng = np.random.default_rng(random_state)
side = math.ceil(math.sqrt(n_particles))
spacing = size / side
grid = np.stack(np.meshgrid(np.arange(side), np.arange(side)), axis=-1).reshape(-1, 2)[:n_particles]
positions = np.mod((grid + 0.5) * spacing + rng.normal(0.0, 0.05 * spacing, (n_particles, 2)), size)
return positions, rng.uniform(0.0, 2 * math.pi, n_particles)
@staticmethod
def _get_active_disks(
n_particles: int,
size: float,
speed: float,
D_r: float,
random_state: int | np.random.Generator | None,
) -> tuple[ActiveParticleElement, list[BaseInteraction]]:
"""Return active Brownian disks in a periodic box, and their diffusion and propulsion."""
positions, angles = MotilityInducedPhaseSeparationSystem._get_disks(n_particles, size, random_state)
swimmers = ActiveParticleElement(
'swimmers',
x=positions,
theta=angles,
size=n_particles,
space=ContinuousSpace(extent=(size, size), boundary='periodic'),
)
interactions: list[BaseInteraction] = [
ActiveDiffusionInteraction('diffusion', target='swimmers', D_t=0.0, D_r=D_r),
SelfPropulsionInteraction('propulsion', target='swimmers', speed=speed),
]
return swimmers, interactions
def __init__(
self,
n_particles: int = 400,
*,
packing_fraction: float = 0.5,
speed: float = 1.0,
D_r: float = 0.01,
k: 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.packing_fraction = packing_fraction
self.speed = speed
self.D_r = D_r
self.k = k
self.random_state = random_state
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of repulsive active Brownian disks of unit diameter.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
size = math.sqrt(self.n_particles * math.pi / 4 / self.packing_fraction)
swimmers, interactions = MotilityInducedPhaseSeparationSystem._get_active_disks(
self.n_particles,
size,
self.speed,
self.D_r,
self.random_state,
)
repulsion = SoftSphereInteraction('contact', target='swimmers', cutoff=1.0, k=self.k)
self.system_ = System(
self.label,
elements=[swimmers],
interactions=[*interactions, repulsion],
solver=EulerMaruyamaSolver(dt=0.005),
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
ActiveParticleElement, fromElement
Interactions:
ActiveDiffusionInteraction, fromInteractionSelfPropulsionInteraction, fromInteractionSoftSphereInteraction, fromInteraction
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)]
class SoftSphereInteraction(Interaction):
"""Soft repulsion between overlapping spheres.
The energy is `k (cutoff - r)^2 / 2` closer than the cutoff, so every member is pushed by `k (cutoff - r)` along the
line of centres from each member that overlaps it, `x_i' += sum_j k (cutoff - r_ij) (x_i - x_j) / r_ij`. In a
periodic box the separations are minimum images. The push moves an overdamped sphere, and with `inertia` it moves
the acceleration instead, `RateLaw(x.diff(t, 2), push / m)`, divided by the mass `m` of a sphere that has one. It is
the contact of disks in a granular layer, of cells in a tissue, or of swimmers that bump into each other.
Args:
label:
The label of the interaction.
target:
The path of the group of spheres.
cutoff:
The contact distance, the sum of the two radii.
k:
The stiffness.
inertia:
Whether the push moves the acceleration of a sphere, divided by its mass `m` when it has one.
Examples:
>>> from skcomplex.systems.physics.active_matter._collective import SoftSphereInteraction
>>> SoftSphereInteraction('contact', target='gas', cutoff=0.1, k=50.0).k
50.0
"""
def __init__(
self,
label: str,
*,
target: Role,
cutoff: Annotated[float, RealSet.open(0, oo)] = 1.0,
k: Annotated[float, RealSet.open(0, oo)] = 100.0,
inertia: bool = False,
) -> None:
super().__init__(label)
self.target = target
self.cutoff = cutoff
self.k = k
self.inertia = inertia
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the push of the overlapping neighbours on every sphere.
Args:
context:
The namespace of the target, the time `t`, and the parameters.
"""
super()._prepare(context)
s, x = context, context.target.x
separation = x - s.target.other.x
r = sqrt(separation.dot_product(separation))
distance = SR.var('r', domain='positive')
slope = (s.k * (s.cutoff - distance) ** 2 / 2).diff(distance).subs({distance: r})
push = neighbors(-slope * separation / r, RadiusNeighborhood(self.cutoff))
if self.inertia:
mass = getattr(s.target, 'm', None)
self.laws_ = [RateLaw(x.diff(s.t, 2), push if mass is None else push / mass)]
else:
self.laws_ = [RateLaw(x.diff(s.t), push)]