Spaces:
Sleeping
Sleeping
Download ReceptorAgent.py from Daniel-Promatix/AvidityLab: direct link, hf CLI and curl.
- Browser
- Download file 2.24 kB
-
https://huggingface.co/spaces/Daniel-Promatix/AvidityLab/resolve/main/ReceptorAgent.py
- Command line
-
hf download hf://spaces/Daniel-Promatix/AvidityLab/ReceptorAgent.py
-
curl -L -o ReceptorAgent.py https://huggingface.co/spaces/Daniel-Promatix/AvidityLab/resolve/main/ReceptorAgent.py
2.24 kB
| 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)) | |