Spaces:
Sleeping
Sleeping
File size: 2,240 Bytes
4e16dd3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | from __future__ import annotations
import math
from typing import Optional, TYPE_CHECKING
import numpy as np
from mesa import Agent, Model
if TYPE_CHECKING: # ONLY for the type checker
from AntibodyAgent import AntibodyAgent
class ReceptorAgent(Agent):
"""
A single membrane receptor diffusing along x (1-D).
Parameters
----------
uid : unique ID for Mesa
model : the HybridAvidityModel instance
rec_type : 'A' or 'B'
"""
def __init__(self, uid: int, model: Model, rec_type: str):
super().__init__(model)
self.rec_type = rec_type # 'A' or 'B'
self.bound_ab: Optional["AntibodyAgent"] = None
# self.legacy_id = uid
# Fast local refs to model-wide constants
self.space_size = model.space_size
self.membrane_y = model.membrane_y
self.d_rec = model.d_rec # receptor diffusion coefficient
self.dt = model.dt # integration timestep
# --------------------------------------------------------------------- #
# Agent behaviour #
# --------------------------------------------------------------------- #
def step(self):
"""
One Monte-Carlo step.
• If the receptor is bivalently bound, it performs a coupled random
walk with its partner receptor (distance held constant).
• Otherwise it diffuses freely along x (toroidal), fixed y.
"""
if self.bound_ab and self.bound_ab.n_bound == 2:
mate = next(r for r in self.bound_ab.arm_state.values() if r is not self)
# Joint Brownian step along x, keep inter-receptor distance
dx = np.random.normal(0.0, math.sqrt(2 * self.d_rec * self.dt))
for rec in (self, mate):
x_new = (rec.pos[0] + dx) % self.space_size
self.model.space.move_agent(rec, (x_new, self.membrane_y))
else:
dx = np.random.normal(0.0, math.sqrt(2 * self.d_rec * self.dt))
x_new = (self.pos[0] + dx) % self.space_size
self.model.space.move_agent(self, (x_new, self.membrane_y))
|