pypharm 1.3.6__py3-none-any.whl → 1.4.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- PyPharm/__init__.py +3 -1
- PyPharm/algorithms/__init__.py +0 -0
- PyPharm/algorithms/country_optimization.py +469 -0
- PyPharm/algorithms/country_optimization_v2.py +330 -0
- PyPharm/algorithms/country_optimization_v3.py +428 -0
- PyPharm/algorithms/genetic_optimization.py +130 -0
- PyPharm/algorithms/gold_digger_optimization.py +127 -0
- PyPharm/constants.py +56 -0
- PyPharm/models/__init__.py +2 -0
- PyPharm/models/compartment_models.py +638 -0
- PyPharm/models/pbpk.py +404 -0
- {pypharm-1.3.6.dist-info → pypharm-1.4.1.dist-info}/METADATA +135 -5
- pypharm-1.4.1.dist-info/RECORD +21 -0
- pypharm-1.3.6.dist-info/RECORD +0 -11
- {pypharm-1.3.6.dist-info → pypharm-1.4.1.dist-info}/WHEEL +0 -0
- {pypharm-1.3.6.dist-info → pypharm-1.4.1.dist-info}/top_level.txt +0 -0
PyPharm/models/pbpk.py
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
from multiprocessing import shared_memory
|
|
2
|
+
import datetime
|
|
3
|
+
import numpy as np
|
|
4
|
+
from scipy.integrate import solve_ivp, RK45, odeint
|
|
5
|
+
from scipy.integrate import simps
|
|
6
|
+
from scipy.optimize import minimize
|
|
7
|
+
from PyPharm.algorithms.country_optimization import CountriesAlgorithm
|
|
8
|
+
from PyPharm.algorithms.country_optimization_v2 import CountriesAlgorithm_v2
|
|
9
|
+
from PyPharm.algorithms.genetic_optimization import GeneticAlgorithm
|
|
10
|
+
from PyPharm.constants import MODEL_CONST, ORGAN_NAMES
|
|
11
|
+
from numba import njit, types
|
|
12
|
+
from numba.typed import Dict
|
|
13
|
+
import matplotlib.pyplot as plt
|
|
14
|
+
|
|
15
|
+
cnst_rat = MODEL_CONST['rat']
|
|
16
|
+
cnst_human = MODEL_CONST['human']
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class PBPKmod:
|
|
20
|
+
|
|
21
|
+
_organs = ['lung', 'heart', 'brain', 'muscle', 'adipose', 'skin', 'bone', 'kidney',
|
|
22
|
+
'liver', 'gut', 'spleen', 'stomach', 'pancreas', 'venous_blood', 'arterial_blood']
|
|
23
|
+
_cl_organs = ['kidney', 'liver']
|
|
24
|
+
|
|
25
|
+
def __init__(self, know_k={}, know_cl={}, numba_option=False):
|
|
26
|
+
self.know_k = know_k
|
|
27
|
+
self.know_cl = know_cl
|
|
28
|
+
self._optim = False
|
|
29
|
+
self.numba_option = numba_option
|
|
30
|
+
if numba_option:
|
|
31
|
+
self.cnst_v_rat = Dict.empty(
|
|
32
|
+
key_type=types.unicode_type,
|
|
33
|
+
value_type=types.float64
|
|
34
|
+
)
|
|
35
|
+
for k, v in cnst_rat.items():
|
|
36
|
+
self.cnst_v_rat[k] = v['V']
|
|
37
|
+
self.cnst_v_human = Dict.empty(
|
|
38
|
+
key_type=types.unicode_type,
|
|
39
|
+
value_type=types.float64
|
|
40
|
+
)
|
|
41
|
+
for k, v in cnst_human.items():
|
|
42
|
+
self.cnst_v_human[k] = v['V']
|
|
43
|
+
self.cnst_q_rat = Dict.empty(
|
|
44
|
+
key_type=types.unicode_type,
|
|
45
|
+
value_type=types.float64
|
|
46
|
+
)
|
|
47
|
+
for k, v in cnst_rat.items():
|
|
48
|
+
if v.get('Q'):
|
|
49
|
+
self.cnst_q_rat[k] = v['Q']
|
|
50
|
+
self.cnst_q_human = Dict.empty(
|
|
51
|
+
key_type=types.unicode_type,
|
|
52
|
+
value_type=types.float64
|
|
53
|
+
)
|
|
54
|
+
for k, v in cnst_human.items():
|
|
55
|
+
if v.get('Q'):
|
|
56
|
+
self.cnst_q_human[k] = v['Q']
|
|
57
|
+
|
|
58
|
+
def load_optimization_data(self, time_exp, dict_c_exp, start_c_in_venous, is_human=False):
|
|
59
|
+
self.time_exp = time_exp
|
|
60
|
+
self.dict_c_exp = dict_c_exp
|
|
61
|
+
self.start_c_in_venous = start_c_in_venous
|
|
62
|
+
self.is_human = is_human
|
|
63
|
+
|
|
64
|
+
def fitness(self, k_cl):
|
|
65
|
+
|
|
66
|
+
self.k_cl = k_cl
|
|
67
|
+
|
|
68
|
+
sol_difurs = self(max(self.time_exp), self.start_c_in_venous, self.is_human)
|
|
69
|
+
# Список для хранения результатов
|
|
70
|
+
present_organs_indices = []
|
|
71
|
+
|
|
72
|
+
# Проверяем, какие ключи из 'organs' есть в 'dict_n'
|
|
73
|
+
for organ in self._organs:
|
|
74
|
+
if organ in self.dict_c_exp:
|
|
75
|
+
index = self._organs.index(organ) # Получаем индекс органа в списке organs
|
|
76
|
+
present_organs_indices.append((organ, index))
|
|
77
|
+
|
|
78
|
+
rez_err = 0
|
|
79
|
+
for organ, index in present_organs_indices:
|
|
80
|
+
mean_y = sum(sol_difurs[:, index]) / len(sol_difurs[:, index])
|
|
81
|
+
a = [(sol_difurs[:, index][self.time_exp[i]] - self.dict_c_exp[organ][i]) ** 2 for i in range(len(self.dict_c_exp[organ]))]
|
|
82
|
+
a = sum(a)
|
|
83
|
+
b = [(mean_y - self.dict_c_exp[organ][i]) ** 2 for i in
|
|
84
|
+
range(len(self.dict_c_exp[organ]))]
|
|
85
|
+
b = sum(b)
|
|
86
|
+
rez_err += a / b
|
|
87
|
+
# rez_err += sum([abs(sol_difurs[:, index][self.time_exp[i]] - self.dict_c_exp[organ][i]) for i in
|
|
88
|
+
# range(len(self.dict_c_exp[organ]))])
|
|
89
|
+
|
|
90
|
+
return rez_err
|
|
91
|
+
|
|
92
|
+
def __call__(self, max_time, start_c_in_venous, is_human=False, step=1):
|
|
93
|
+
self.y0 = [0 for _ in range(15)] # всего в модели 15 органов
|
|
94
|
+
self.y0[-2] = start_c_in_venous
|
|
95
|
+
t = np.linspace(0, max_time, max_time + 1 if self._optim else int(1 / step * max_time) + 1)
|
|
96
|
+
|
|
97
|
+
if not hasattr(self, 'k_cl'):
|
|
98
|
+
self.k_cl = []
|
|
99
|
+
|
|
100
|
+
full_k = []
|
|
101
|
+
i = 0
|
|
102
|
+
for name in self._organs:
|
|
103
|
+
know_k = self.know_k.get(name)
|
|
104
|
+
if know_k is not None:
|
|
105
|
+
full_k.append(know_k)
|
|
106
|
+
else:
|
|
107
|
+
full_k.append(self.k_cl[i])
|
|
108
|
+
i += 1
|
|
109
|
+
full_cl = []
|
|
110
|
+
|
|
111
|
+
for name in self._cl_organs:
|
|
112
|
+
know_k = self.know_cl.get(name)
|
|
113
|
+
if know_k is not None:
|
|
114
|
+
full_cl.append(know_k)
|
|
115
|
+
else:
|
|
116
|
+
full_cl.append(self.k_cl[i])
|
|
117
|
+
i += 1
|
|
118
|
+
if not self.numba_option:
|
|
119
|
+
sol_difurs = odeint(
|
|
120
|
+
self.fullPBPKmodel,
|
|
121
|
+
self.y0,
|
|
122
|
+
t,
|
|
123
|
+
args=([*full_k, *full_cl], is_human)
|
|
124
|
+
)
|
|
125
|
+
else:
|
|
126
|
+
k_cl = np.array([*full_k, *full_cl])
|
|
127
|
+
if is_human:
|
|
128
|
+
cnst_v = self.cnst_v_human
|
|
129
|
+
cnst_q = self.cnst_q_human
|
|
130
|
+
else:
|
|
131
|
+
cnst_v = self.cnst_v_rat
|
|
132
|
+
cnst_q = self.cnst_q_rat
|
|
133
|
+
function = lambda c, t: self.numba_fullPBPK_for_optimization(
|
|
134
|
+
y=c,
|
|
135
|
+
t=t,
|
|
136
|
+
K_CL=k_cl.astype(np.float64),
|
|
137
|
+
cnst_q=cnst_q,
|
|
138
|
+
cnst_v=cnst_v
|
|
139
|
+
)
|
|
140
|
+
sol_difurs = odeint(
|
|
141
|
+
function,
|
|
142
|
+
self.y0,
|
|
143
|
+
t
|
|
144
|
+
)
|
|
145
|
+
if self._optim:
|
|
146
|
+
return sol_difurs
|
|
147
|
+
|
|
148
|
+
self.last_result = {
|
|
149
|
+
't': t
|
|
150
|
+
}
|
|
151
|
+
for organ in self._organs:
|
|
152
|
+
index = self._organs.index(organ)
|
|
153
|
+
self.last_result[organ] = np.array([sol_difurs[i][index] for i in range(t.size)])
|
|
154
|
+
return self.last_result
|
|
155
|
+
|
|
156
|
+
def plot_last_result(self, organ_names=[], left=None, right=None, user_names={}, theoretic_data={}, y_lims={}):
|
|
157
|
+
if hasattr(self, 'last_result'):
|
|
158
|
+
for name in organ_names:
|
|
159
|
+
if theoretic_data.get(name):
|
|
160
|
+
plt.plot(theoretic_data[name]['x'], theoretic_data[name]['y'], '*r')
|
|
161
|
+
plt.plot(
|
|
162
|
+
self.last_result['t'],
|
|
163
|
+
self.last_result.get(name),
|
|
164
|
+
)
|
|
165
|
+
plt.title(user_names.get(name, name))
|
|
166
|
+
plt.xlim(left=left, right=right)
|
|
167
|
+
if y_lims.get(name):
|
|
168
|
+
plt.ylim(y_lims.get(name))
|
|
169
|
+
plt.grid()
|
|
170
|
+
plt.show()
|
|
171
|
+
|
|
172
|
+
def optimize(self, method=None, user_method=None, method_is_func=True,
|
|
173
|
+
optimization_func_name='__call__', **kwargs):
|
|
174
|
+
"""
|
|
175
|
+
Функция оптимизации модели
|
|
176
|
+
|
|
177
|
+
Args:
|
|
178
|
+
method: Метод оптимизации, любой доступный minimize + 'country_optimization' и 'country_optimization_v2'
|
|
179
|
+
max_step: Максимальный шаг при решении СДУ
|
|
180
|
+
**kwargs: Дополнительные именованные аргументы
|
|
181
|
+
|
|
182
|
+
Returns:
|
|
183
|
+
None
|
|
184
|
+
"""
|
|
185
|
+
self._optim = True
|
|
186
|
+
f = lambda x: self.fitness(x)
|
|
187
|
+
if user_method is not None:
|
|
188
|
+
if method_is_func:
|
|
189
|
+
x = user_method(f, **kwargs)
|
|
190
|
+
else:
|
|
191
|
+
optimization_obj = user_method(f, **kwargs)
|
|
192
|
+
x = getattr(optimization_obj, optimization_func_name)()
|
|
193
|
+
else:
|
|
194
|
+
if method == 'country_optimization':
|
|
195
|
+
CA = CountriesAlgorithm(
|
|
196
|
+
f=f,
|
|
197
|
+
memory_list=getattr(self, 'memory', None),
|
|
198
|
+
**kwargs
|
|
199
|
+
)
|
|
200
|
+
CA.start()
|
|
201
|
+
x = CA.countries[0].population[0].x
|
|
202
|
+
elif method == 'country_optimization_v2':
|
|
203
|
+
CA = CountriesAlgorithm_v2(
|
|
204
|
+
f=f,
|
|
205
|
+
**kwargs
|
|
206
|
+
)
|
|
207
|
+
CA.start()
|
|
208
|
+
x = CA.countries[0].population[0].x
|
|
209
|
+
elif method == 'GA':
|
|
210
|
+
CA = GeneticAlgorithm(
|
|
211
|
+
f=f,
|
|
212
|
+
**kwargs
|
|
213
|
+
)
|
|
214
|
+
x = CA.start()
|
|
215
|
+
else:
|
|
216
|
+
res = minimize(
|
|
217
|
+
fun=f,
|
|
218
|
+
method=method,
|
|
219
|
+
**kwargs
|
|
220
|
+
)
|
|
221
|
+
x = res.x
|
|
222
|
+
self._optim = False
|
|
223
|
+
return x
|
|
224
|
+
|
|
225
|
+
def update_know_params(self, k_cl):
|
|
226
|
+
i = 0
|
|
227
|
+
for name in self._organs:
|
|
228
|
+
know_k = self.know_k.get(name)
|
|
229
|
+
if know_k is None:
|
|
230
|
+
self.know_k[name] = k_cl[i]
|
|
231
|
+
i += 1
|
|
232
|
+
for name in self._cl_organs:
|
|
233
|
+
know_cl = self.know_cl.get(name)
|
|
234
|
+
if know_cl is None:
|
|
235
|
+
self.know_cl[name] = k_cl[i]
|
|
236
|
+
i += 1
|
|
237
|
+
|
|
238
|
+
def get_unknown_params(self):
|
|
239
|
+
result = []
|
|
240
|
+
for name in self._organs:
|
|
241
|
+
know_k = self.know_k.get(name)
|
|
242
|
+
if know_k is None:
|
|
243
|
+
result.append(f"k_{name}")
|
|
244
|
+
for name in self._cl_organs:
|
|
245
|
+
know_cl = self.know_cl.get(name)
|
|
246
|
+
if know_cl is None:
|
|
247
|
+
result.append(f"cl_{name}")
|
|
248
|
+
return result
|
|
249
|
+
|
|
250
|
+
def fullPBPKmodel(self, y, t, K_CL, is_human=False): # V, Q, K, CL):
|
|
251
|
+
# 15 органов
|
|
252
|
+
if is_human:
|
|
253
|
+
cnst = cnst_human
|
|
254
|
+
else:
|
|
255
|
+
cnst = cnst_rat
|
|
256
|
+
C_lung, C_heart, C_brain, C_muscle, C_fat, C_skin, C_bone, \
|
|
257
|
+
C_kidney, C_liver, C_gut, C_spleen, C_stomach, C_pancreas, C_V, C_A = y
|
|
258
|
+
|
|
259
|
+
K_lung, K_heart, K_brain, K_muscle, K_fat, K_skin, K_bone, \
|
|
260
|
+
K_kidney, K_liver, K_gut, K_spleen, K_stomach, K_pancreas, K_liver_cl, K_kidney_cl = K_CL[:15]
|
|
261
|
+
CL_kidney, CL_liver = K_CL[15:]
|
|
262
|
+
|
|
263
|
+
dC_lung_dt = cnst['lung']['Q'] * (C_V - C_lung / K_lung) / cnst['lung']['V']
|
|
264
|
+
dC_heart_dt = cnst['heart']['Q'] * (C_A - C_heart / K_heart) / cnst['heart']['V']
|
|
265
|
+
dC_brain_dt = cnst['brain']['Q'] * (C_A - C_brain / K_brain) / cnst['brain']['V']
|
|
266
|
+
dC_muscle_dt = cnst['muscle']['Q'] * (C_A - C_muscle / K_muscle) / cnst['muscle']['V']
|
|
267
|
+
dC_fat_dt = cnst['adipose']['Q'] * (C_A - C_fat / K_fat) / cnst['adipose']['V']
|
|
268
|
+
dC_skin_dt = cnst['skin']['Q'] * (C_A - C_skin / K_skin) / cnst['skin']['V']
|
|
269
|
+
dC_bone_dt = cnst['bone']['Q'] * (C_A - C_bone / K_bone) / cnst['bone']['V']
|
|
270
|
+
# Kidney V(Kidney)*dC(Kidney)/dt = Q(Kidney)*C(A)-Q(Kidney)*CV(Kidney)-CL(Kidney,int)*CV(Kidney,int)?
|
|
271
|
+
dC_kidney_dt = (cnst['kidney']['Q'] * (C_A - C_kidney / K_kidney) - CL_kidney * C_kidney / K_kidney_cl) / \
|
|
272
|
+
cnst['kidney']['V'] # ???
|
|
273
|
+
|
|
274
|
+
# Liver V(Liver)*dC(Liver)/dt = (Q(Liver)-Q(Spleen)-Q(Gut)-Q(Pancreas)-Q(Stomach))*C(A) + Q(Spleen)*CV(Spleen) +
|
|
275
|
+
# + Q(Gut)*CV(Gut) + Q(Pancreas)*CV(Pancreas) + Q(Stomach)*CV(Stomach) -
|
|
276
|
+
# - Q(Liver)*CV(Liver) - CL(Liver,int)*CV(Liver,int)? # тут скорее всего нужно вычитать потоки из друг друга дополнительно по крови что бы сохранить массовый баланс
|
|
277
|
+
Q_liver_in_from_art = cnst['liver']['Q'] - cnst['gut']['Q'] - cnst['spleen']['Q'] - \
|
|
278
|
+
cnst['pancreas']['Q'] - cnst['stomach']['Q']
|
|
279
|
+
dC_liver_dt = (
|
|
280
|
+
Q_liver_in_from_art * C_A + cnst['gut']['Q'] * C_gut / K_gut
|
|
281
|
+
+ cnst['spleen']['Q'] * C_spleen / K_spleen
|
|
282
|
+
+ cnst['stomach']['Q'] * C_stomach / K_stomach
|
|
283
|
+
+ cnst['pancreas']['Q'] * C_pancreas / K_pancreas
|
|
284
|
+
- cnst['liver']['Q'] * C_liver / K_liver
|
|
285
|
+
- CL_liver * C_liver / K_liver_cl # ???
|
|
286
|
+
) / cnst['liver']['V']
|
|
287
|
+
|
|
288
|
+
dC_gut_dt = cnst['gut']['Q'] * (C_A - C_gut / K_gut) / cnst['gut']['V']
|
|
289
|
+
dC_spleen_dt = cnst['spleen']['Q'] * (C_A - C_spleen / K_spleen) / cnst['spleen']['V']
|
|
290
|
+
dC_stomach_dt = cnst['stomach']['Q'] * (C_A - C_stomach / K_stomach) / cnst['stomach']['V']
|
|
291
|
+
dC_pancreas_dt = cnst['pancreas']['Q'] * (C_A - C_pancreas / K_pancreas) / cnst['pancreas']['V']
|
|
292
|
+
|
|
293
|
+
dC_venouse_dt = (
|
|
294
|
+
cnst['heart']['Q'] * C_heart / K_heart
|
|
295
|
+
+ cnst['brain']['Q'] * C_brain / K_brain
|
|
296
|
+
+ cnst['muscle']['Q'] * C_muscle / K_muscle
|
|
297
|
+
+ cnst['skin']['Q'] * C_skin / K_skin
|
|
298
|
+
+ cnst['adipose']['Q'] * C_fat / K_fat
|
|
299
|
+
+ cnst['bone']['Q'] * C_bone / K_bone
|
|
300
|
+
+ cnst['kidney']['Q'] * C_kidney / K_kidney
|
|
301
|
+
+ cnst['liver']['Q'] * C_liver / K_liver
|
|
302
|
+
- cnst['lung']['Q'] * C_V
|
|
303
|
+
) / cnst['venous_blood']['V']
|
|
304
|
+
|
|
305
|
+
dC_arterial_dt = cnst['lung']['Q'] * (C_lung / K_lung - C_A) / cnst['arterial_blood']['V']
|
|
306
|
+
|
|
307
|
+
y_new = [dC_lung_dt, dC_heart_dt, dC_brain_dt, dC_muscle_dt, dC_fat_dt, dC_skin_dt, dC_bone_dt, \
|
|
308
|
+
dC_kidney_dt, dC_liver_dt, dC_gut_dt, dC_spleen_dt, dC_stomach_dt, dC_pancreas_dt, dC_venouse_dt,
|
|
309
|
+
dC_arterial_dt]
|
|
310
|
+
return y_new
|
|
311
|
+
|
|
312
|
+
@staticmethod
|
|
313
|
+
@njit
|
|
314
|
+
def numba_fullPBPK_for_optimization(y, t, K_CL, cnst_q, cnst_v):
|
|
315
|
+
C_lung, C_heart, C_brain, C_muscle, C_fat, C_skin, C_bone, \
|
|
316
|
+
C_kidney, C_liver, C_gut, C_spleen, C_stomach, C_pancreas, C_V, C_A = y
|
|
317
|
+
|
|
318
|
+
K_lung, K_heart, K_brain, K_muscle, K_fat, K_skin, K_bone, \
|
|
319
|
+
K_kidney, K_liver, K_gut, K_spleen, K_stomach, K_pancreas, K_liver_cl, K_kidney_cl = K_CL[:15]
|
|
320
|
+
CL_kidney, CL_liver = K_CL[15:]
|
|
321
|
+
|
|
322
|
+
dC_lung_dt = cnst_q['lung'] * (C_V - C_lung / K_lung) / cnst_v['lung']
|
|
323
|
+
dC_heart_dt = cnst_q['heart'] * (C_A - C_heart / K_heart) / cnst_v['heart']
|
|
324
|
+
dC_brain_dt = cnst_q['brain'] * (C_A - C_brain / K_brain) / cnst_v['brain']
|
|
325
|
+
dC_muscle_dt = cnst_q['muscle'] * (C_A - C_muscle / K_muscle) / cnst_v['muscle']
|
|
326
|
+
dC_fat_dt = cnst_q['adipose'] * (C_A - C_fat / K_fat) / cnst_v['adipose']
|
|
327
|
+
dC_skin_dt = cnst_q['skin'] * (C_A - C_skin / K_skin) / cnst_v['skin']
|
|
328
|
+
dC_bone_dt = cnst_q['bone'] * (C_A - C_bone / K_bone) / cnst_v['bone']
|
|
329
|
+
# Kidney V(Kidney)*dC(Kidney)/dt = Q(Kidney)*C(A)-Q(Kidney)*CV(Kidney)-CL(Kidney,int)*CV(Kidney,int)?
|
|
330
|
+
dC_kidney_dt = (cnst_q['kidney'] * (C_A - C_kidney / K_kidney) - CL_kidney * C_kidney / K_kidney_cl) / \
|
|
331
|
+
cnst_v['kidney'] # ???
|
|
332
|
+
|
|
333
|
+
# Liver V(Liver)*dC(Liver)/dt = (Q(Liver)-Q(Spleen)-Q(Gut)-Q(Pancreas)-Q(Stomach))*C(A) + Q(Spleen)*CV(Spleen) +
|
|
334
|
+
# + Q(Gut)*CV(Gut) + Q(Pancreas)*CV(Pancreas) + Q(Stomach)*CV(Stomach) -
|
|
335
|
+
# - Q(Liver)*CV(Liver) - CL(Liver,int)*CV(Liver,int)? # тут скорее всего нужно вычитать потоки из друг друга дополнительно по крови что бы сохранить массовый баланс
|
|
336
|
+
Q_liver_in_from_art = cnst_q['liver'] - cnst_q['gut'] - cnst_q['spleen'] - \
|
|
337
|
+
cnst_q['pancreas'] - cnst_q['stomach']
|
|
338
|
+
dC_liver_dt = (
|
|
339
|
+
Q_liver_in_from_art * C_A + cnst_q['gut'] * C_gut / K_gut
|
|
340
|
+
+ cnst_q['spleen'] * C_spleen / K_spleen
|
|
341
|
+
+ cnst_q['stomach'] * C_stomach / K_stomach
|
|
342
|
+
+ cnst_q['pancreas'] * C_pancreas / K_pancreas
|
|
343
|
+
- cnst_q['liver'] * C_liver / K_liver
|
|
344
|
+
- CL_liver * C_liver / K_liver_cl # ???
|
|
345
|
+
) / cnst_v['liver']
|
|
346
|
+
|
|
347
|
+
dC_gut_dt = cnst_q['gut'] * (C_A - C_gut / K_gut) / cnst_v['gut']
|
|
348
|
+
dC_spleen_dt = cnst_q['spleen'] * (C_A - C_spleen / K_spleen) / cnst_v['spleen']
|
|
349
|
+
dC_stomach_dt = cnst_q['stomach'] * (C_A - C_stomach / K_stomach) / cnst_v['stomach']
|
|
350
|
+
dC_pancreas_dt = cnst_q['pancreas'] * (C_A - C_pancreas / K_pancreas) / cnst_v['pancreas']
|
|
351
|
+
|
|
352
|
+
dC_venouse_dt = (
|
|
353
|
+
cnst_q['heart'] * C_heart / K_heart
|
|
354
|
+
+ cnst_q['brain'] * C_brain / K_brain
|
|
355
|
+
+ cnst_q['muscle'] * C_muscle / K_muscle
|
|
356
|
+
+ cnst_q['skin'] * C_skin / K_skin
|
|
357
|
+
+ cnst_q['adipose'] * C_fat / K_fat
|
|
358
|
+
+ cnst_q['bone'] * C_bone / K_bone
|
|
359
|
+
+ cnst_q['kidney'] * C_kidney / K_kidney
|
|
360
|
+
+ cnst_q['liver'] * C_liver / K_liver
|
|
361
|
+
- cnst_q['lung'] * C_V
|
|
362
|
+
) / cnst_v['venous_blood']
|
|
363
|
+
|
|
364
|
+
dC_arterial_dt = cnst_q['lung'] * (C_lung / K_lung - C_A) / cnst_v['arterial_blood']
|
|
365
|
+
|
|
366
|
+
y_new = np.array([dC_lung_dt, dC_heart_dt, dC_brain_dt, dC_muscle_dt, dC_fat_dt, dC_skin_dt, dC_bone_dt, \
|
|
367
|
+
dC_kidney_dt, dC_liver_dt, dC_gut_dt, dC_spleen_dt, dC_stomach_dt, dC_pancreas_dt, dC_venouse_dt,
|
|
368
|
+
dC_arterial_dt]).astype(np.float64)
|
|
369
|
+
return y_new
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
model = PBPKmod(numba_option=True)
|
|
373
|
+
print(model.get_unknown_params())
|
|
374
|
+
model.load_optimization_data(
|
|
375
|
+
time_exp=[12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
376
|
+
dict_c_exp = {ORGAN_NAMES.LIVER: [103.2 * 1e-6, 134.54 * 1e-6, 87.89 * 1e-6, 81.87 * 1e-6, 45.83 * 1e-6, 28.48 * 1e-6],
|
|
377
|
+
ORGAN_NAMES.LUNG: [26.96 * 1e-6, 22.67 * 1e-6, 15.51 * 1e-6, 12.07 * 1e-6, 4.53 * 1e-6, 0 * 1e-6],
|
|
378
|
+
ORGAN_NAMES.SPLEEN: [11.84 * 1e-6, 12.22 * 1e-6, 8.52 * 1e-6, 7.01 * 1e-6, 3.65 * 1e-6, 2.16 * 1e-6]
|
|
379
|
+
},
|
|
380
|
+
start_c_in_venous=150 * 1e-3 / MODEL_CONST['rat']['venous_blood']['V']
|
|
381
|
+
)
|
|
382
|
+
|
|
383
|
+
result = model.optimize(
|
|
384
|
+
method='country_optimization',
|
|
385
|
+
Xmin=17 * [0.0001],
|
|
386
|
+
Xmax=17 * [5],
|
|
387
|
+
M=20,
|
|
388
|
+
N=25,
|
|
389
|
+
n=[1, 10],
|
|
390
|
+
p=[0.00001, 2],
|
|
391
|
+
m=[1, 8],
|
|
392
|
+
k=8,
|
|
393
|
+
l=3,
|
|
394
|
+
ep=[0.2, 0.4],
|
|
395
|
+
tmax=3,
|
|
396
|
+
printing=True,
|
|
397
|
+
)
|
|
398
|
+
model.update_know_params(result)
|
|
399
|
+
|
|
400
|
+
result = model(max_time=24 * 60, start_c_in_venous=150 * 1e-3 / MODEL_CONST['rat']['venous_blood']['V'], step=0.1)
|
|
401
|
+
|
|
402
|
+
model_furs = PBPKmod(numba_option=True)
|
|
403
|
+
|
|
404
|
+
print()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pypharm
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.4.1
|
|
4
4
|
Summary: Module for solving pharmacokinetic problems
|
|
5
5
|
Home-page: https://github.com/Krash13/PyPharm
|
|
6
6
|
Author: Krash13
|
|
@@ -240,7 +240,7 @@ res = model(90, d=5700, compartment_number=0)
|
|
|
240
240
|
Если оба параметра не заданы, то модель выраздается
|
|
241
241
|
в простую BaseCompartmentModel.
|
|
242
242
|
|
|
243
|
-
**5) Модель
|
|
243
|
+
**5) Модель ReleaseCompartmentModel**
|
|
244
244
|
|
|
245
245
|
Данная модель учитывает поправку на высвобождение
|
|
246
246
|
ЛВ в модель вводятся дополнительные параметры:
|
|
@@ -277,8 +277,72 @@ plt.show()
|
|
|
277
277
|
в таком случае, искомое нужно просто задать как None. Тогда вектор неизвестных это
|
|
278
278
|
x = [configuration_matrix (неизвестные), outputs(неизвестные), volumes(неизвестные), release_parameters(неизвестные), v_release]
|
|
279
279
|
|
|
280
|
+
**6) Использование PBPK модели**
|
|
280
281
|
|
|
281
|
-
|
|
282
|
+
Вы можете использовать PBPK модель как для рассчёта по известным
|
|
283
|
+
данным так и для поиска параметров, исходя из ваших экспериментальных данных.
|
|
284
|
+
|
|
285
|
+
Чтобы задать исзвестные вам константы, при инициализации объекта следует использовать
|
|
286
|
+
параметры know_k и know_cl, которые содержат словари с известными параметрами, имена органов следует брать
|
|
287
|
+
из класса ORGAN_NAMES.
|
|
288
|
+
|
|
289
|
+
Ниже приведен пример поиска параметров и построение кривых распределения вещества
|
|
290
|
+
в органах с использованием генетического алгоритма.
|
|
291
|
+
|
|
292
|
+
```python
|
|
293
|
+
from PyPharm import PBPKmod
|
|
294
|
+
from PyPharm.constants import ORGAN_NAMES, MODEL_CONST
|
|
295
|
+
|
|
296
|
+
model = PBPKmod()
|
|
297
|
+
print(model.get_unknown_params())
|
|
298
|
+
model.load_optimization_data(
|
|
299
|
+
time_exp=[12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
300
|
+
dict_c_exp = {ORGAN_NAMES.LIVER: [103.2 * 1e-6, 134.54 * 1e-6, 87.89 * 1e-6, 81.87 * 1e-6, 45.83 * 1e-6, 28.48 * 1e-6],
|
|
301
|
+
ORGAN_NAMES.LUNG: [26.96 * 1e-6, 22.67 * 1e-6, 15.51 * 1e-6, 12.07 * 1e-6, 4.53 * 1e-6, 0 * 1e-6],
|
|
302
|
+
ORGAN_NAMES.SPLEEN: [11.84 * 1e-6, 12.22 * 1e-6, 8.52 * 1e-6, 7.01 * 1e-6, 3.65 * 1e-6, 2.16 * 1e-6]
|
|
303
|
+
},
|
|
304
|
+
start_c_in_venous=150 * 1e-3 / MODEL_CONST['rat']['venous_blood']['V']
|
|
305
|
+
)
|
|
306
|
+
result = model.optimize(
|
|
307
|
+
method='GA',
|
|
308
|
+
x_min=17 * [0.0001],
|
|
309
|
+
x_max=17 * [5],
|
|
310
|
+
genes=17 * [16],
|
|
311
|
+
n=300,
|
|
312
|
+
child_percent=0.3,
|
|
313
|
+
mutation_chance=0.5,
|
|
314
|
+
max_mutation=5,
|
|
315
|
+
t_max=300,
|
|
316
|
+
printing=True,
|
|
317
|
+
)
|
|
318
|
+
model.update_know_params(result)
|
|
319
|
+
|
|
320
|
+
result = model(max_time=24 * 60, start_c_in_venous=150 * 1e-3 / MODEL_CONST['rat']['venous_blood']['V'], step=0.1)
|
|
321
|
+
model.plot_last_result(
|
|
322
|
+
organ_names=[ORGAN_NAMES.LUNG, ORGAN_NAMES.LIVER, ORGAN_NAMES.SPLEEN],
|
|
323
|
+
user_names={
|
|
324
|
+
ORGAN_NAMES.LUNG: 'Лёгкие',
|
|
325
|
+
ORGAN_NAMES.LIVER: 'Печень',
|
|
326
|
+
ORGAN_NAMES.SPLEEN: 'Селезёнка',
|
|
327
|
+
},
|
|
328
|
+
theoretic_data={
|
|
329
|
+
ORGAN_NAMES.LIVER: {
|
|
330
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
331
|
+
'y': [103.2 * 1e-6, 134.54 * 1e-6, 87.89 * 1e-6, 81.87 * 1e-6, 45.83 * 1e-6, 28.48 * 1e-6],
|
|
332
|
+
},
|
|
333
|
+
ORGAN_NAMES.LUNG: {
|
|
334
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
335
|
+
'y': [26.96 * 1e-6, 22.67 * 1e-6, 15.51 * 1e-6, 12.07 * 1e-6, 4.53 * 1e-6, 0 * 1e-6],
|
|
336
|
+
},
|
|
337
|
+
ORGAN_NAMES.SPLEEN: {
|
|
338
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
339
|
+
'y': [11.84 * 1e-6, 12.22 * 1e-6, 8.52 * 1e-6, 7.01 * 1e-6, 3.65 * 1e-6, 2.16 * 1e-6]
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
)
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
**7) Использование shared_memory**
|
|
282
346
|
|
|
283
347
|
Начиная с версии 1.3.0, вы можете использовать **shared_memory** для получения текущих данных
|
|
284
348
|
оптимизации. Имя нужного вам участка памяти хранится в поле **memory_name**.
|
|
@@ -517,7 +581,7 @@ of variables.
|
|
|
517
581
|
If both parameters are not set, then the model is deleted
|
|
518
582
|
into a simple BaseCompartmentModel.
|
|
519
583
|
|
|
520
|
-
**5) The
|
|
584
|
+
**5) The ReleaseCompartmentModel model**
|
|
521
585
|
|
|
522
586
|
This model takes into account the release adjustment
|
|
523
587
|
medicinal substance additional parameters are introduced into the model:
|
|
@@ -554,7 +618,72 @@ The release_parameters and v_release parameters can be optimized
|
|
|
554
618
|
in this case, you just need to set the desired value as None. Then the vector of unknowns is
|
|
555
619
|
x = [configuration_matrix (unknown), outputs(unknown), volumes(unknown), release_parameters(unknown), v_release]
|
|
556
620
|
|
|
557
|
-
**6) Using
|
|
621
|
+
**6) Using the PBPK model**
|
|
622
|
+
|
|
623
|
+
You can use the PBPK model both for calculations based on known
|
|
624
|
+
data and for searching for parameters based on your experimental data.
|
|
625
|
+
|
|
626
|
+
To set constants known to you, when initializing an object, you should use the
|
|
627
|
+
parameters know_k and know_cl, which contain dictionaries with known parameters, the names of organs should be taken
|
|
628
|
+
from the ORGAN_NAMES class.
|
|
629
|
+
|
|
630
|
+
Below is an example of searching for parameters and constructing distribution curves of a substance
|
|
631
|
+
in organs using a genetic algorithm.
|
|
632
|
+
|
|
633
|
+
```python
|
|
634
|
+
from PyPharm import PBPKmod
|
|
635
|
+
from PyPharm.constants import ORGAN_NAMES, MODEL_CONST
|
|
636
|
+
|
|
637
|
+
model = PBPKmod()
|
|
638
|
+
print(model.get_unknown_params())
|
|
639
|
+
model.load_optimization_data(
|
|
640
|
+
time_exp=[12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
641
|
+
dict_c_exp = {ORGAN_NAMES.LIVER: [103.2 * 1e-6, 134.54 * 1e-6, 87.89 * 1e-6, 81.87 * 1e-6, 45.83 * 1e-6, 28.48 * 1e-6],
|
|
642
|
+
ORGAN_NAMES.LUNG: [26.96 * 1e-6, 22.67 * 1e-6, 15.51 * 1e-6, 12.07 * 1e-6, 4.53 * 1e-6, 0 * 1e-6],
|
|
643
|
+
ORGAN_NAMES.SPLEEN: [11.84 * 1e-6, 12.22 * 1e-6, 8.52 * 1e-6, 7.01 * 1e-6, 3.65 * 1e-6, 2.16 * 1e-6]
|
|
644
|
+
},
|
|
645
|
+
start_c_in_venous=150 * 1e-3 / MODEL_CONST['rat']['venous_blood']['V']
|
|
646
|
+
)
|
|
647
|
+
result = model.optimize(
|
|
648
|
+
method='GA',
|
|
649
|
+
x_min=17 * [0.0001],
|
|
650
|
+
x_max=17 * [5],
|
|
651
|
+
genes=17 * [16],
|
|
652
|
+
n=300,
|
|
653
|
+
child_percent=0.3,
|
|
654
|
+
mutation_chance=0.5,
|
|
655
|
+
max_mutation=5,
|
|
656
|
+
t_max=300,
|
|
657
|
+
printing=True,
|
|
658
|
+
)
|
|
659
|
+
model.update_know_params(result)
|
|
660
|
+
|
|
661
|
+
result = model(max_time=24 * 60, start_c_in_venous=150 * 1e-3 / MODEL_CONST['rat']['venous_blood']['V'], step=0.1)
|
|
662
|
+
model.plot_last_result(
|
|
663
|
+
organ_names=[ORGAN_NAMES.LUNG, ORGAN_NAMES.LIVER, ORGAN_NAMES.SPLEEN],
|
|
664
|
+
user_names={
|
|
665
|
+
ORGAN_NAMES.LUNG: 'Лёгкие',
|
|
666
|
+
ORGAN_NAMES.LIVER: 'Печень',
|
|
667
|
+
ORGAN_NAMES.SPLEEN: 'Селезёнка',
|
|
668
|
+
},
|
|
669
|
+
theoretic_data={
|
|
670
|
+
ORGAN_NAMES.LIVER: {
|
|
671
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
672
|
+
'y': [103.2 * 1e-6, 134.54 * 1e-6, 87.89 * 1e-6, 81.87 * 1e-6, 45.83 * 1e-6, 28.48 * 1e-6],
|
|
673
|
+
},
|
|
674
|
+
ORGAN_NAMES.LUNG: {
|
|
675
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
676
|
+
'y': [26.96 * 1e-6, 22.67 * 1e-6, 15.51 * 1e-6, 12.07 * 1e-6, 4.53 * 1e-6, 0 * 1e-6],
|
|
677
|
+
},
|
|
678
|
+
ORGAN_NAMES.SPLEEN: {
|
|
679
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
680
|
+
'y': [11.84 * 1e-6, 12.22 * 1e-6, 8.52 * 1e-6, 7.01 * 1e-6, 3.65 * 1e-6, 2.16 * 1e-6]
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
)
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
**7) Using shared_memory**
|
|
558
687
|
|
|
559
688
|
Since version 1.3.0, you can use **shared_memory** to get current data
|
|
560
689
|
optimization. The name of the memory location you need is stored in the **memory_name** field.
|
|
@@ -568,3 +697,4 @@ print(c)
|
|
|
568
697
|
|
|
569
698
|
The data is stored in list format [current_iteration, x0, ... , xn, f], works only for the country_optimization algorithm.
|
|
570
699
|
|
|
700
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
PyPharm/__init__.py,sha256=W3NIi--fjBbpS9ODzq8lZ4L0trgqvXda7GO2dxpscXg,103
|
|
2
|
+
PyPharm/constants.py,sha256=dW_qHteF4PwHYCLuqbp-8yU6MUpDun38DdDr7-SlfmE,2082
|
|
3
|
+
PyPharm/country_optimization.py,sha256=3fnnAJfdLgD0RP8qyJzHBuPDHcPljcLPQM9oqNip1r8,19664
|
|
4
|
+
PyPharm/country_optimization_v2.py,sha256=3d2mt15DXdr1V3soIJS51xuCv6uzH8pirah1RnI5--8,13156
|
|
5
|
+
PyPharm/country_optimization_v3.py,sha256=-3slM5MwSmiG6rD7p9ycbUQPdt4hd5bcEwpSxjb3A7U,17034
|
|
6
|
+
PyPharm/genetic_optimization.py,sha256=EC_pEWwL-ufCQd71zBhCeAB6-Sh1fijv7F3L0bWCz3I,5036
|
|
7
|
+
PyPharm/gold_digger_optimization.py,sha256=mln67sAYxkwzFqZ9Ylild1F25VuaruXRPaUMOGT5gIM,4449
|
|
8
|
+
PyPharm/models.py,sha256=VQlSLGzV3k7mNKiLAIKV29mc6ka6IakmUtEt10cBcq8,33066
|
|
9
|
+
PyPharm/algorithms/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
PyPharm/algorithms/country_optimization.py,sha256=kfRksJoAOI33yavo73mcLL5RvVe68A-TfSJ7b_N-4-0,19662
|
|
11
|
+
PyPharm/algorithms/country_optimization_v2.py,sha256=3d2mt15DXdr1V3soIJS51xuCv6uzH8pirah1RnI5--8,13156
|
|
12
|
+
PyPharm/algorithms/country_optimization_v3.py,sha256=btPF1_aNfk9TNWf9oi-POGTU_2vfOJSp4EsyisGvDzc,17127
|
|
13
|
+
PyPharm/algorithms/genetic_optimization.py,sha256=EC_pEWwL-ufCQd71zBhCeAB6-Sh1fijv7F3L0bWCz3I,5036
|
|
14
|
+
PyPharm/algorithms/gold_digger_optimization.py,sha256=mln67sAYxkwzFqZ9Ylild1F25VuaruXRPaUMOGT5gIM,4449
|
|
15
|
+
PyPharm/models/__init__.py,sha256=NMJcXMq0gCXgGLyB62j3qIzz3tbxqe6AOLPsJnfcjM0,129
|
|
16
|
+
PyPharm/models/compartment_models.py,sha256=aEa4RQ9SedbIwVm95K7QnPMin0-nLADrzcBuIeDBVhc,33102
|
|
17
|
+
PyPharm/models/pbpk.py,sha256=IJINwQkzFRygA1wd1sKYuGx4_ecJRRWmC3J2DKoAqlw,18708
|
|
18
|
+
pypharm-1.4.1.dist-info/METADATA,sha256=WVE1U3R4oT29V2ZhurpIebySSieAEyaPUKgf0dr4414,22939
|
|
19
|
+
pypharm-1.4.1.dist-info/WHEEL,sha256=OqRkF0eY5GHssMorFjlbTIq072vpHpF60fIQA6lS9xA,92
|
|
20
|
+
pypharm-1.4.1.dist-info/top_level.txt,sha256=yybfSkKw8q1G3aEcnlfVL7_L9ufGFSAYZnpc7q6oYJk,8
|
|
21
|
+
pypharm-1.4.1.dist-info/RECORD,,
|
pypharm-1.3.6.dist-info/RECORD
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
PyPharm/__init__.py,sha256=hxhMRlWpLMARQV-ZNYkmvhQ9gCYI18an75vlySWjA6s,90
|
|
2
|
-
PyPharm/country_optimization.py,sha256=3fnnAJfdLgD0RP8qyJzHBuPDHcPljcLPQM9oqNip1r8,19664
|
|
3
|
-
PyPharm/country_optimization_v2.py,sha256=3d2mt15DXdr1V3soIJS51xuCv6uzH8pirah1RnI5--8,13156
|
|
4
|
-
PyPharm/country_optimization_v3.py,sha256=-3slM5MwSmiG6rD7p9ycbUQPdt4hd5bcEwpSxjb3A7U,17034
|
|
5
|
-
PyPharm/genetic_optimization.py,sha256=EC_pEWwL-ufCQd71zBhCeAB6-Sh1fijv7F3L0bWCz3I,5036
|
|
6
|
-
PyPharm/gold_digger_optimization.py,sha256=mln67sAYxkwzFqZ9Ylild1F25VuaruXRPaUMOGT5gIM,4449
|
|
7
|
-
PyPharm/models.py,sha256=VQlSLGzV3k7mNKiLAIKV29mc6ka6IakmUtEt10cBcq8,33066
|
|
8
|
-
pypharm-1.3.6.dist-info/METADATA,sha256=wSroVP5fAWGzIeIks6Q9KrehcgRQA4NGsudovNA7AsQ,17608
|
|
9
|
-
pypharm-1.3.6.dist-info/WHEEL,sha256=OqRkF0eY5GHssMorFjlbTIq072vpHpF60fIQA6lS9xA,92
|
|
10
|
-
pypharm-1.3.6.dist-info/top_level.txt,sha256=yybfSkKw8q1G3aEcnlfVL7_L9ufGFSAYZnpc7q6oYJk,8
|
|
11
|
-
pypharm-1.3.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|