-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
executable file
·202 lines (154 loc) · 7.27 KB
/
models.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import numpy as np
from scipy import integrate
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from copy import deepcopy
def calcium_periodic_boundary(c, number_of_cells, cell_idx):
cell_idx_plus_one = (cell_idx + 1) % number_of_cells
cell_idx_minus_one = (cell_idx - 1) % number_of_cells
c_bar = 0.5 * (c[cell_idx_plus_one] + c[cell_idx_minus_one])
return c_bar
def calcium_no_flux_boundary(c, number_of_cells, cell_idx):
if cell_idx in range(1, number_of_cells - 1):
c_bar = (c[cell_idx - 1] + c[cell_idx + 1]) / 2
elif cell_idx == 0:
c_bar = (c[0] + c[1]) / 2
elif cell_idx == (number_of_cells - 1):
c_bar = (c[number_of_cells - 2] + c[number_of_cells - 1]) / 2
else:
print('whoops')
# print(c_bar.shape)
# if len(c_bar) is not 1:
# print(cell_idx)
return c_bar
def solve_ivp_odes(number_of_cells, number_of_timepoints, dt, dx, a0, b0, c0, v0, calcium_boundary_condition, params, sample_rate):
# unpack params
c_threshold = params["c_threshold"]
c_b_threshold = params["c_b_threshold"]
v_b_threshold = params["v_b_threshold"]
rho = params["rho"]
gamma_0 = params["gamma_0"]
gamma_c = params["gamma_c"]
gamma_v = params["gamma_v"]
k = params["k"]
k_v = params["k_v"]
mu = params["mu"]
lambda_const = params["lambda_const"]
lambda_const_v_0 = params["lambda_const_v_0"]
lambda_const_v_b = params["lambda_const_v_b"]
store_timepoints = int(((number_of_timepoints - 1) / sample_rate) + 1)
t = range(number_of_timepoints)
store_t = t[::sample_rate]
# Preallocate
a_store = np.ndarray((number_of_cells, store_timepoints), dtype=float)
b_store = np.ndarray((number_of_cells, store_timepoints), dtype=float)
c_store = np.ndarray((number_of_cells, store_timepoints), dtype=float)
v_store = np.ndarray((number_of_cells, store_timepoints), dtype=float)
H_c = np.ndarray((number_of_cells), dtype=int)
H_c_b = np.ndarray((number_of_cells), dtype=int)
H_v_b = np.ndarray((number_of_cells), dtype=int)
# Initialize
a_store[:,0] = a0
b_store[:,0] = b0
c_store[:,0] = c0
v_store[:,0] = v0
a_current = a0
b_current = b0
c_current = c0
v_current = v0
a_new = a0
b_new = b0
c_new = c0
v_new = v0
store_idx = 1
for t_idx in range(1, number_of_timepoints):
for cell_idx in range(number_of_cells):
c_bar = calcium_boundary_condition(c_current, number_of_cells, cell_idx)
H_c[cell_idx] = np.heaviside(c_current[cell_idx] - c_threshold,1)
H_v_b[cell_idx] = np.heaviside(v_b_threshold - b_current[cell_idx], 1)
b_new[cell_idx] = b_current[cell_idx] + dt * ((rho * H_c[cell_idx]) - (b_current[cell_idx] * (gamma_0 + (gamma_c * c_current[cell_idx]) + (gamma_v * v_current[cell_idx]))))
c_new[cell_idx] = c_current[cell_idx] + dt * ((k * a_current[cell_idx]) + (mu * np.power(1/dx,2) * (c_bar - c_current[cell_idx])) - (lambda_const * c_current[cell_idx]))
v_new[cell_idx] = v_current[cell_idx] + dt * ((k_v * H_v_b[cell_idx]) - (v_current[cell_idx] * (lambda_const_v_0 + (lambda_const_v_b * b_current[cell_idx]))))
H_c_b[cell_idx] = np.heaviside(c_b_threshold - b_new[cell_idx], 1)
a_new[cell_idx] = max(a_current[cell_idx], H_c_b[cell_idx])
if t_idx in store_t:
a_store[:,store_idx] = a_new
b_store[:,store_idx] = b_new
c_store[:,store_idx] = c_new
v_store[:,store_idx] = v_new
store_idx = store_idx + 1
a_current = a_new
b_current = b_new
c_current = c_new
v_current = v_new
return a_store, b_store, c_store, v_store
def solve_ivp_odes_Hill(number_of_cells, number_of_timepoints, dt, dx, a0, b0, c0, v0, calcium_boundary_condition, params, sample_rate):
# unpack params
c_threshold = params["c_threshold"]
c_b_threshold = params["c_b_threshold"]
v_b_threshold = params["v_b_threshold"]
rho = params["rho"]
gamma_0 = params["gamma_0"]
gamma_c = params["gamma_c"]
gamma_v = params["gamma_v"]
k = params["k"]
k_v = params["k_v"]
mu = params["mu"]
lambda_const = params["lambda_const"]
lambda_const_v_0 = params["lambda_const_v_0"]
lambda_const_v_b = params["lambda_const_v_b"]
store_timepoints = int(((number_of_timepoints - 1) / sample_rate) + 1)
t = range(number_of_timepoints)
store_t = t[::sample_rate]
# Preallocate
a_store = np.ndarray((number_of_cells, store_timepoints), dtype=float)
b_store = np.ndarray((number_of_cells, store_timepoints), dtype=float)
c_store = np.ndarray((number_of_cells, store_timepoints), dtype=float)
v_store = np.ndarray((number_of_cells, store_timepoints), dtype=float)
Hill_c = np.ndarray((number_of_cells))
Hill_c_b = np.ndarray((number_of_cells))
H_c_b = np.ndarray((number_of_cells), dtype=int)
Hill_v_b = np.ndarray((number_of_cells))
Hill_n = 4
# Initialize
a_store[:,0] = a0
b_store[:,0] = b0
c_store[:,0] = c0
v_store[:,0] = v0
a_current = a0
b_current = b0
c_current = c0
v_current = v0
a_new = a0
b_new = b0
c_new = c0
v_new = v0
store_idx = 1
for t_idx in range(1, number_of_timepoints):
for cell_idx in range(number_of_cells):
c_bar = calcium_boundary_condition(c_current, number_of_cells, cell_idx)
if c_current[cell_idx] == 0:
Hill_c[cell_idx] = 0
else:
Hill_c[cell_idx] = 1 / (1 + (c_threshold / c_current[cell_idx]) ** Hill_n)
Hill_v_b[cell_idx] = 1 / (1 + (b_current[cell_idx] / v_b_threshold) ** Hill_n)
b_new[cell_idx] = b_current[cell_idx] + dt * ((rho * Hill_c[cell_idx]) - (b_current[cell_idx] * (gamma_0 + (gamma_c * c_current[cell_idx]) + (gamma_v * v_current[cell_idx]))))
c_new[cell_idx] = c_current[cell_idx] + dt * ((k * a_current[cell_idx]) + (mu * np.power(1/dx,2) * (c_bar - c_current[cell_idx])) - (lambda_const * c_current[cell_idx]))
v_new[cell_idx] = v_current[cell_idx] + dt * ((k_v * Hill_v_b[cell_idx]) - (v_current[cell_idx] * (lambda_const_v_0 + (lambda_const_v_b * b_current[cell_idx]))))
# HILL function for streak identity / calcium activity production
# Hill_c_b[cell_idx] = 1 / (1 + (b_new[cell_idx] / c_b_threshold) ** Hill_n)
# a_new[cell_idx] = max(a_current[cell_idx], Hill_c_b[cell_idx])
# HEAVISIDE function for streak identity / calcium activity production
H_c_b[cell_idx] = np.heaviside(c_b_threshold - b_new[cell_idx], 1)
a_new[cell_idx] = max(a_current[cell_idx], H_c_b[cell_idx])
if t_idx in store_t:
a_store[:,store_idx] = a_new
b_store[:,store_idx] = b_new
c_store[:,store_idx] = c_new
v_store[:,store_idx] = v_new
store_idx = store_idx + 1
a_current = a_new
b_current = b_new
c_current = c_new
v_current = v_new
return a_store, b_store, c_store, v_store