Module nlisim.modules.mcp1
Expand source code
from typing import Any, Dict
import attr
import numpy as np
from nlisim.coordinates import Voxel
from nlisim.diffusion import apply_diffusion
from nlisim.grid import RectangularGrid
from nlisim.module import ModuleModel, ModuleState
from nlisim.modules.molecules import MoleculesState
from nlisim.state import State
from nlisim.util import turnover_rate
def molecule_grid_factory(self: 'MCP1State') -> np.ndarray:
return np.zeros(shape=self.global_state.grid.shape, dtype=float)
@attr.s(kw_only=True, repr=False)
class MCP1State(ModuleState):
grid: np.ndarray = attr.ib(
default=attr.Factory(molecule_grid_factory, takes_self=True)
) # units: atto-mols
half_life: float # units: min
half_life_multiplier: float # units: proportion
macrophage_secretion_rate: float # units: atto-mol * cell^-1 * h^-1
pneumocyte_secretion_rate: float # units: atto-mol * cell^-1 * h^-1
macrophage_secretion_rate_unit_t: float # units: atto-mol * cell^-1 * step^-1
pneumocyte_secretion_rate_unit_t: float # units: atto-mol * cell^-1 * step^-1
k_d: float # units: aM
class MCP1(ModuleModel):
"""MCP1"""
name = 'mcp1'
StateClass = MCP1State
def initialize(self, state: State) -> State:
mcp1: MCP1State = state.mcp1
# config file values
mcp1.half_life = self.config.getfloat('half_life') # units: min
mcp1.macrophage_secretion_rate = self.config.getfloat(
'macrophage_secretion_rate'
) # units: atto-mol * cell^-1 * h^-1
mcp1.pneumocyte_secretion_rate = self.config.getfloat(
'pneumocyte_secretion_rate'
) # units: atto-mol * cell^-1 * h^-1
mcp1.k_d = self.config.getfloat('k_d') # units: aM
# computed values
mcp1.half_life_multiplier = 0.5 ** (
self.time_step / mcp1.half_life
) # units in exponent: (min/step) / min -> 1/step
# time unit conversions
# units: (atto-mol * cell^-1 * h^-1 * (min * step^-1) / (min * hour^-1)
# = atto-mol * cell^-1 * step^-1
mcp1.macrophage_secretion_rate_unit_t = mcp1.macrophage_secretion_rate * (
self.time_step / 60
)
mcp1.pneumocyte_secretion_rate_unit_t = mcp1.pneumocyte_secretion_rate * (
self.time_step / 60
)
return state
def advance(self, state: State, previous_time: float) -> State:
"""Advance the state by a single time step."""
from nlisim.modules.macrophage import MacrophageCellData, MacrophageState
from nlisim.modules.pneumocyte import PneumocyteCellData, PneumocyteState
mcp1: MCP1State = state.mcp1
molecules: MoleculesState = state.molecules
pneumocyte: PneumocyteState = state.pneumocyte
macrophage: MacrophageState = state.macrophage
grid: RectangularGrid = state.grid
# interact with pneumocytes
for pneumocyte_cell_index in pneumocyte.cells.alive():
pneumocyte_cell: PneumocyteCellData = pneumocyte.cells[pneumocyte_cell_index]
if pneumocyte_cell['tnfa']:
pneumocyte_cell_voxel: Voxel = grid.get_voxel(pneumocyte_cell['point'])
mcp1.grid[tuple(pneumocyte_cell_voxel)] += mcp1.pneumocyte_secretion_rate_unit_t
# interact with macrophages
for macrophage_cell_index in macrophage.cells.alive():
macrophage_cell: MacrophageCellData = macrophage.cells[macrophage_cell_index]
if macrophage_cell['tnfa']:
macrophage_cell_voxel: Voxel = grid.get_voxel(macrophage_cell['point'])
mcp1.grid[tuple(macrophage_cell_voxel)] += mcp1.macrophage_secretion_rate_unit_t
# Degrade MCP1
mcp1.grid *= mcp1.half_life_multiplier
mcp1.grid *= turnover_rate(
x=np.array(1.0, dtype=np.float64),
x_system=0.0,
base_turnover_rate=molecules.turnover_rate,
rel_cyt_bind_unit_t=molecules.rel_cyt_bind_unit_t,
)
# Diffusion of MCP1
mcp1.grid[:] = apply_diffusion(
variable=mcp1.grid,
laplacian=molecules.laplacian,
diffusivity=molecules.diffusion_constant,
dt=self.time_step,
)
return state
def summary_stats(self, state: State) -> Dict[str, Any]:
from nlisim.util import TissueType
mcp1: MCP1State = state.mcp1
voxel_volume = state.voxel_volume
mask = state.lung_tissue != TissueType.AIR
return {
'concentration (nM)': float(np.mean(mcp1.grid[mask]) / voxel_volume / 1e9),
}
def visualization_data(self, state: State):
mcp1: MCP1State = state.mcp1
return 'molecule', mcp1.grid
Functions
def molecule_grid_factory(self: MCP1State) ‑> numpy.ndarray
-
Expand source code
def molecule_grid_factory(self: 'MCP1State') -> np.ndarray: return np.zeros(shape=self.global_state.grid.shape, dtype=float)
Classes
class MCP1 (config: SimulationConfig)
-
MCP1
Expand source code
class MCP1(ModuleModel): """MCP1""" name = 'mcp1' StateClass = MCP1State def initialize(self, state: State) -> State: mcp1: MCP1State = state.mcp1 # config file values mcp1.half_life = self.config.getfloat('half_life') # units: min mcp1.macrophage_secretion_rate = self.config.getfloat( 'macrophage_secretion_rate' ) # units: atto-mol * cell^-1 * h^-1 mcp1.pneumocyte_secretion_rate = self.config.getfloat( 'pneumocyte_secretion_rate' ) # units: atto-mol * cell^-1 * h^-1 mcp1.k_d = self.config.getfloat('k_d') # units: aM # computed values mcp1.half_life_multiplier = 0.5 ** ( self.time_step / mcp1.half_life ) # units in exponent: (min/step) / min -> 1/step # time unit conversions # units: (atto-mol * cell^-1 * h^-1 * (min * step^-1) / (min * hour^-1) # = atto-mol * cell^-1 * step^-1 mcp1.macrophage_secretion_rate_unit_t = mcp1.macrophage_secretion_rate * ( self.time_step / 60 ) mcp1.pneumocyte_secretion_rate_unit_t = mcp1.pneumocyte_secretion_rate * ( self.time_step / 60 ) return state def advance(self, state: State, previous_time: float) -> State: """Advance the state by a single time step.""" from nlisim.modules.macrophage import MacrophageCellData, MacrophageState from nlisim.modules.pneumocyte import PneumocyteCellData, PneumocyteState mcp1: MCP1State = state.mcp1 molecules: MoleculesState = state.molecules pneumocyte: PneumocyteState = state.pneumocyte macrophage: MacrophageState = state.macrophage grid: RectangularGrid = state.grid # interact with pneumocytes for pneumocyte_cell_index in pneumocyte.cells.alive(): pneumocyte_cell: PneumocyteCellData = pneumocyte.cells[pneumocyte_cell_index] if pneumocyte_cell['tnfa']: pneumocyte_cell_voxel: Voxel = grid.get_voxel(pneumocyte_cell['point']) mcp1.grid[tuple(pneumocyte_cell_voxel)] += mcp1.pneumocyte_secretion_rate_unit_t # interact with macrophages for macrophage_cell_index in macrophage.cells.alive(): macrophage_cell: MacrophageCellData = macrophage.cells[macrophage_cell_index] if macrophage_cell['tnfa']: macrophage_cell_voxel: Voxel = grid.get_voxel(macrophage_cell['point']) mcp1.grid[tuple(macrophage_cell_voxel)] += mcp1.macrophage_secretion_rate_unit_t # Degrade MCP1 mcp1.grid *= mcp1.half_life_multiplier mcp1.grid *= turnover_rate( x=np.array(1.0, dtype=np.float64), x_system=0.0, base_turnover_rate=molecules.turnover_rate, rel_cyt_bind_unit_t=molecules.rel_cyt_bind_unit_t, ) # Diffusion of MCP1 mcp1.grid[:] = apply_diffusion( variable=mcp1.grid, laplacian=molecules.laplacian, diffusivity=molecules.diffusion_constant, dt=self.time_step, ) return state def summary_stats(self, state: State) -> Dict[str, Any]: from nlisim.util import TissueType mcp1: MCP1State = state.mcp1 voxel_volume = state.voxel_volume mask = state.lung_tissue != TissueType.AIR return { 'concentration (nM)': float(np.mean(mcp1.grid[mask]) / voxel_volume / 1e9), } def visualization_data(self, state: State): mcp1: MCP1State = state.mcp1 return 'molecule', mcp1.grid
Ancestors
Methods
def advance(self, state: State, previous_time: float) ‑> State
-
Advance the state by a single time step.
Expand source code
def advance(self, state: State, previous_time: float) -> State: """Advance the state by a single time step.""" from nlisim.modules.macrophage import MacrophageCellData, MacrophageState from nlisim.modules.pneumocyte import PneumocyteCellData, PneumocyteState mcp1: MCP1State = state.mcp1 molecules: MoleculesState = state.molecules pneumocyte: PneumocyteState = state.pneumocyte macrophage: MacrophageState = state.macrophage grid: RectangularGrid = state.grid # interact with pneumocytes for pneumocyte_cell_index in pneumocyte.cells.alive(): pneumocyte_cell: PneumocyteCellData = pneumocyte.cells[pneumocyte_cell_index] if pneumocyte_cell['tnfa']: pneumocyte_cell_voxel: Voxel = grid.get_voxel(pneumocyte_cell['point']) mcp1.grid[tuple(pneumocyte_cell_voxel)] += mcp1.pneumocyte_secretion_rate_unit_t # interact with macrophages for macrophage_cell_index in macrophage.cells.alive(): macrophage_cell: MacrophageCellData = macrophage.cells[macrophage_cell_index] if macrophage_cell['tnfa']: macrophage_cell_voxel: Voxel = grid.get_voxel(macrophage_cell['point']) mcp1.grid[tuple(macrophage_cell_voxel)] += mcp1.macrophage_secretion_rate_unit_t # Degrade MCP1 mcp1.grid *= mcp1.half_life_multiplier mcp1.grid *= turnover_rate( x=np.array(1.0, dtype=np.float64), x_system=0.0, base_turnover_rate=molecules.turnover_rate, rel_cyt_bind_unit_t=molecules.rel_cyt_bind_unit_t, ) # Diffusion of MCP1 mcp1.grid[:] = apply_diffusion( variable=mcp1.grid, laplacian=molecules.laplacian, diffusivity=molecules.diffusion_constant, dt=self.time_step, ) return state
Inherited members
class MCP1State (*, global_state: State, grid: numpy.ndarray = NOTHING)
-
Base type intended to store the state for simulation modules.
This class contains serialization support for basic types (float, int, str, bool) and numpy arrays of those types. Modules containing more complicated state must override the serialization mechanism with custom behavior.
Method generated by attrs for class MCP1State.
Expand source code
class MCP1State(ModuleState): grid: np.ndarray = attr.ib( default=attr.Factory(molecule_grid_factory, takes_self=True) ) # units: atto-mols half_life: float # units: min half_life_multiplier: float # units: proportion macrophage_secretion_rate: float # units: atto-mol * cell^-1 * h^-1 pneumocyte_secretion_rate: float # units: atto-mol * cell^-1 * h^-1 macrophage_secretion_rate_unit_t: float # units: atto-mol * cell^-1 * step^-1 pneumocyte_secretion_rate_unit_t: float # units: atto-mol * cell^-1 * step^-1 k_d: float # units: aM
Ancestors
Class variables
var grid : numpy.ndarray
var half_life : float
var half_life_multiplier : float
var k_d : float
var macrophage_secretion_rate : float
var macrophage_secretion_rate_unit_t : float
var pneumocyte_secretion_rate : float
var pneumocyte_secretion_rate_unit_t : float
Inherited members