pypharm 1.3.5__py3-none-any.whl → 1.4.0__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/models/pbpk.py ADDED
@@ -0,0 +1,375 @@
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
+ _optim = False
25
+ know_k = {}
26
+ know_cl = {}
27
+
28
+ def __init__(self, know_k=None, know_cl=None, numba_option=False):
29
+ if know_k is not None:
30
+ self.know_k = know_k
31
+
32
+ if know_cl is not None:
33
+ self.know_cl = know_cl
34
+
35
+ self.numba_option = numba_option
36
+ if numba_option:
37
+ self.cnst_v_rat = Dict.empty(
38
+ key_type=types.unicode_type,
39
+ value_type=types.float64
40
+ )
41
+ for k, v in cnst_rat.items():
42
+ self.cnst_v_rat[k] = v['V']
43
+ self.cnst_v_human = Dict.empty(
44
+ key_type=types.unicode_type,
45
+ value_type=types.float64
46
+ )
47
+ for k, v in cnst_human.items():
48
+ self.cnst_v_human[k] = v['V']
49
+ self.cnst_q_rat = Dict.empty(
50
+ key_type=types.unicode_type,
51
+ value_type=types.float64
52
+ )
53
+ for k, v in cnst_rat.items():
54
+ if v.get('Q'):
55
+ self.cnst_q_rat[k] = v['Q']
56
+ self.cnst_q_human = Dict.empty(
57
+ key_type=types.unicode_type,
58
+ value_type=types.float64
59
+ )
60
+ for k, v in cnst_human.items():
61
+ if v.get('Q'):
62
+ self.cnst_q_human[k] = v['Q']
63
+
64
+ def load_optimization_data(self, time_exp, dict_c_exp, start_c_in_venous, is_human=False):
65
+ self.time_exp = time_exp
66
+ self.dict_c_exp = dict_c_exp
67
+ self.start_c_in_venous = start_c_in_venous
68
+ self.is_human = is_human
69
+
70
+ def fitness(self, k_cl):
71
+
72
+ self.k_cl = k_cl
73
+
74
+ sol_difurs = self(max(self.time_exp), self.start_c_in_venous, self.is_human)
75
+ # Список для хранения результатов
76
+ present_organs_indices = []
77
+
78
+ # Проверяем, какие ключи из 'organs' есть в 'dict_n'
79
+ for organ in self._organs:
80
+ if organ in self.dict_c_exp:
81
+ index = self._organs.index(organ) # Получаем индекс органа в списке organs
82
+ present_organs_indices.append((organ, index))
83
+
84
+ rez_err = 0
85
+ for organ, index in present_organs_indices:
86
+ mean_y = sum(sol_difurs[:, index]) / len(sol_difurs[:, index])
87
+ 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]))]
88
+ a = sum(a)
89
+ b = [(mean_y - self.dict_c_exp[organ][i]) ** 2 for i in
90
+ range(len(self.dict_c_exp[organ]))]
91
+ b = sum(b)
92
+ rez_err += a / b
93
+ # rez_err += sum([abs(sol_difurs[:, index][self.time_exp[i]] - self.dict_c_exp[organ][i]) for i in
94
+ # range(len(self.dict_c_exp[organ]))])
95
+
96
+ return rez_err
97
+
98
+ def __call__(self, max_time, start_c_in_venous, is_human=False, step=1):
99
+ self.y0 = [0 for _ in range(15)] # всего в модели 15 органов
100
+ self.y0[-2] = start_c_in_venous
101
+ t = np.linspace(0, max_time, max_time + 1 if self._optim else int(1 / step * max_time) + 1)
102
+
103
+ if not hasattr(self, 'k_cl'):
104
+ self.k_cl = []
105
+
106
+ full_k = []
107
+ i = 0
108
+ for name in self._organs:
109
+ know_k = self.know_k.get(name)
110
+ if know_k is not None:
111
+ full_k.append(know_k)
112
+ else:
113
+ full_k.append(self.k_cl[i])
114
+ i += 1
115
+ full_cl = []
116
+
117
+ for name in self._cl_organs:
118
+ know_k = self.know_cl.get(name)
119
+ if know_k is not None:
120
+ full_cl.append(know_k)
121
+ else:
122
+ full_cl.append(self.k_cl[i])
123
+ i += 1
124
+ if not self.numba_option:
125
+ sol_difurs = odeint(
126
+ self.fullPBPKmodel,
127
+ self.y0,
128
+ t,
129
+ args=([*full_k, *full_cl], is_human)
130
+ )
131
+ else:
132
+ k_cl = np.array([*full_k, *full_cl])
133
+ if is_human:
134
+ cnst_v = self.cnst_v_human
135
+ cnst_q = self.cnst_q_human
136
+ else:
137
+ cnst_v = self.cnst_v_rat
138
+ cnst_q = self.cnst_q_rat
139
+ function = lambda c, t: self.numba_fullPBPK_for_optimization(
140
+ y=c,
141
+ t=t,
142
+ K_CL=k_cl.astype(np.float64),
143
+ cnst_q=cnst_q,
144
+ cnst_v=cnst_v
145
+ )
146
+ sol_difurs = odeint(
147
+ function,
148
+ self.y0,
149
+ t
150
+ )
151
+ if self._optim:
152
+ return sol_difurs
153
+
154
+ self.last_result = {
155
+ 't': t
156
+ }
157
+ for organ in self._organs:
158
+ index = self._organs.index(organ)
159
+ self.last_result[organ] = np.array([sol_difurs[i][index] for i in range(t.size)])
160
+ return self.last_result
161
+
162
+ def plot_last_result(self, organ_names=[], left=None, right=None, user_names={}, theoretic_data={}, y_lims={}):
163
+ if hasattr(self, 'last_result'):
164
+ for name in organ_names:
165
+ if theoretic_data.get(name):
166
+ plt.plot(theoretic_data[name]['x'], theoretic_data[name]['y'], '*r')
167
+ plt.plot(
168
+ self.last_result['t'],
169
+ self.last_result.get(name),
170
+ )
171
+ plt.title(user_names.get(name, name))
172
+ plt.xlim(left=left, right=right)
173
+ if y_lims.get(name):
174
+ plt.ylim(y_lims.get(name))
175
+ plt.grid()
176
+ plt.show()
177
+
178
+ def optimize(self, method=None, user_method=None, method_is_func=True,
179
+ optimization_func_name='__call__', **kwargs):
180
+ """
181
+ Функция оптимизации модели
182
+
183
+ Args:
184
+ method: Метод оптимизации, любой доступный minimize + 'country_optimization' и 'country_optimization_v2'
185
+ max_step: Максимальный шаг при решении СДУ
186
+ **kwargs: Дополнительные именованные аргументы
187
+
188
+ Returns:
189
+ None
190
+ """
191
+ self._optim = True
192
+ f = lambda x: self.fitness(x)
193
+ if user_method is not None:
194
+ if method_is_func:
195
+ x = user_method(f, **kwargs)
196
+ else:
197
+ optimization_obj = user_method(f, **kwargs)
198
+ x = getattr(optimization_obj, optimization_func_name)()
199
+ else:
200
+ if method == 'country_optimization':
201
+ CA = CountriesAlgorithm(
202
+ f=f,
203
+ memory_list=getattr(self, 'memory', None),
204
+ **kwargs
205
+ )
206
+ CA.start()
207
+ x = CA.countries[0].population[0].x
208
+ elif method == 'country_optimization_v2':
209
+ CA = CountriesAlgorithm_v2(
210
+ f=f,
211
+ **kwargs
212
+ )
213
+ CA.start()
214
+ x = CA.countries[0].population[0].x
215
+ elif method == 'GA':
216
+ CA = GeneticAlgorithm(
217
+ f=f,
218
+ **kwargs
219
+ )
220
+ x = CA.start()
221
+ else:
222
+ res = minimize(
223
+ fun=f,
224
+ method=method,
225
+ **kwargs
226
+ )
227
+ x = res.x
228
+ self._optim = False
229
+ return x
230
+
231
+ def update_know_params(self, k_cl):
232
+ i = 0
233
+ for name in self._organs:
234
+ know_k = self.know_k.get(name)
235
+ if know_k is None:
236
+ self.know_k[name] = k_cl[i]
237
+ i += 1
238
+ for name in self._cl_organs:
239
+ know_cl = self.know_cl.get(name)
240
+ if know_cl is None:
241
+ self.know_cl[name] = k_cl[i]
242
+ i += 1
243
+
244
+ def get_unknown_params(self):
245
+ result = []
246
+ for name in self._organs:
247
+ know_k = self.know_k.get(name)
248
+ if know_k is None:
249
+ result.append(f"k_{name}")
250
+ for name in self._cl_organs:
251
+ know_cl = self.know_cl.get(name)
252
+ if know_cl is None:
253
+ result.append(f"cl_{name}")
254
+ return result
255
+
256
+ def fullPBPKmodel(self, y, t, K_CL, is_human=False): # V, Q, K, CL):
257
+ # 15 органов
258
+ if is_human:
259
+ cnst = cnst_human
260
+ else:
261
+ cnst = cnst_rat
262
+ C_lung, C_heart, C_brain, C_muscle, C_fat, C_skin, C_bone, \
263
+ C_kidney, C_liver, C_gut, C_spleen, C_stomach, C_pancreas, C_V, C_A = y
264
+
265
+ K_lung, K_heart, K_brain, K_muscle, K_fat, K_skin, K_bone, \
266
+ K_kidney, K_liver, K_gut, K_spleen, K_stomach, K_pancreas, K_liver_cl, K_kidney_cl = K_CL[:15]
267
+ CL_kidney, CL_liver = K_CL[15:]
268
+
269
+ dC_lung_dt = cnst['lung']['Q'] * (C_V - C_lung / K_lung) / cnst['lung']['V']
270
+ dC_heart_dt = cnst['heart']['Q'] * (C_A - C_heart / K_heart) / cnst['heart']['V']
271
+ dC_brain_dt = cnst['brain']['Q'] * (C_A - C_brain / K_brain) / cnst['brain']['V']
272
+ dC_muscle_dt = cnst['muscle']['Q'] * (C_A - C_muscle / K_muscle) / cnst['muscle']['V']
273
+ dC_fat_dt = cnst['adipose']['Q'] * (C_A - C_fat / K_fat) / cnst['adipose']['V']
274
+ dC_skin_dt = cnst['skin']['Q'] * (C_A - C_skin / K_skin) / cnst['skin']['V']
275
+ dC_bone_dt = cnst['bone']['Q'] * (C_A - C_bone / K_bone) / cnst['bone']['V']
276
+ # Kidney V(Kidney)*dC(Kidney)/dt = Q(Kidney)*C(A)-Q(Kidney)*CV(Kidney)-CL(Kidney,int)*CV(Kidney,int)?
277
+ dC_kidney_dt = (cnst['kidney']['Q'] * (C_A - C_kidney / K_kidney) - CL_kidney * C_kidney / K_kidney_cl) / \
278
+ cnst['kidney']['V'] # ???
279
+
280
+ # Liver V(Liver)*dC(Liver)/dt = (Q(Liver)-Q(Spleen)-Q(Gut)-Q(Pancreas)-Q(Stomach))*C(A) + Q(Spleen)*CV(Spleen) +
281
+ # + Q(Gut)*CV(Gut) + Q(Pancreas)*CV(Pancreas) + Q(Stomach)*CV(Stomach) -
282
+ # - Q(Liver)*CV(Liver) - CL(Liver,int)*CV(Liver,int)? # тут скорее всего нужно вычитать потоки из друг друга дополнительно по крови что бы сохранить массовый баланс
283
+ Q_liver_in_from_art = cnst['liver']['Q'] - cnst['gut']['Q'] - cnst['spleen']['Q'] - \
284
+ cnst['pancreas']['Q'] - cnst['stomach']['Q']
285
+ dC_liver_dt = (
286
+ Q_liver_in_from_art * C_A + cnst['gut']['Q'] * C_gut / K_gut
287
+ + cnst['spleen']['Q'] * C_spleen / K_spleen
288
+ + cnst['stomach']['Q'] * C_stomach / K_stomach
289
+ + cnst['pancreas']['Q'] * C_pancreas / K_pancreas
290
+ - cnst['liver']['Q'] * C_liver / K_liver
291
+ - CL_liver * C_liver / K_liver_cl # ???
292
+ ) / cnst['liver']['V']
293
+
294
+ dC_gut_dt = cnst['gut']['Q'] * (C_A - C_gut / K_gut) / cnst['gut']['V']
295
+ dC_spleen_dt = cnst['spleen']['Q'] * (C_A - C_spleen / K_spleen) / cnst['spleen']['V']
296
+ dC_stomach_dt = cnst['stomach']['Q'] * (C_A - C_stomach / K_stomach) / cnst['stomach']['V']
297
+ dC_pancreas_dt = cnst['pancreas']['Q'] * (C_A - C_pancreas / K_pancreas) / cnst['pancreas']['V']
298
+
299
+ dC_venouse_dt = (
300
+ cnst['heart']['Q'] * C_heart / K_heart
301
+ + cnst['brain']['Q'] * C_brain / K_brain
302
+ + cnst['muscle']['Q'] * C_muscle / K_muscle
303
+ + cnst['skin']['Q'] * C_skin / K_skin
304
+ + cnst['adipose']['Q'] * C_fat / K_fat
305
+ + cnst['bone']['Q'] * C_bone / K_bone
306
+ + cnst['kidney']['Q'] * C_kidney / K_kidney
307
+ + cnst['liver']['Q'] * C_liver / K_liver
308
+ - cnst['lung']['Q'] * C_V
309
+ ) / cnst['venous_blood']['V']
310
+
311
+ dC_arterial_dt = cnst['lung']['Q'] * (C_lung / K_lung - C_A) / cnst['arterial_blood']['V']
312
+
313
+ y_new = [dC_lung_dt, dC_heart_dt, dC_brain_dt, dC_muscle_dt, dC_fat_dt, dC_skin_dt, dC_bone_dt, \
314
+ dC_kidney_dt, dC_liver_dt, dC_gut_dt, dC_spleen_dt, dC_stomach_dt, dC_pancreas_dt, dC_venouse_dt,
315
+ dC_arterial_dt]
316
+ return y_new
317
+
318
+ @staticmethod
319
+ @njit
320
+ def numba_fullPBPK_for_optimization(y, t, K_CL, cnst_q, cnst_v):
321
+ C_lung, C_heart, C_brain, C_muscle, C_fat, C_skin, C_bone, \
322
+ C_kidney, C_liver, C_gut, C_spleen, C_stomach, C_pancreas, C_V, C_A = y
323
+
324
+ K_lung, K_heart, K_brain, K_muscle, K_fat, K_skin, K_bone, \
325
+ K_kidney, K_liver, K_gut, K_spleen, K_stomach, K_pancreas, K_liver_cl, K_kidney_cl = K_CL[:15]
326
+ CL_kidney, CL_liver = K_CL[15:]
327
+
328
+ dC_lung_dt = cnst_q['lung'] * (C_V - C_lung / K_lung) / cnst_v['lung']
329
+ dC_heart_dt = cnst_q['heart'] * (C_A - C_heart / K_heart) / cnst_v['heart']
330
+ dC_brain_dt = cnst_q['brain'] * (C_A - C_brain / K_brain) / cnst_v['brain']
331
+ dC_muscle_dt = cnst_q['muscle'] * (C_A - C_muscle / K_muscle) / cnst_v['muscle']
332
+ dC_fat_dt = cnst_q['adipose'] * (C_A - C_fat / K_fat) / cnst_v['adipose']
333
+ dC_skin_dt = cnst_q['skin'] * (C_A - C_skin / K_skin) / cnst_v['skin']
334
+ dC_bone_dt = cnst_q['bone'] * (C_A - C_bone / K_bone) / cnst_v['bone']
335
+ # Kidney V(Kidney)*dC(Kidney)/dt = Q(Kidney)*C(A)-Q(Kidney)*CV(Kidney)-CL(Kidney,int)*CV(Kidney,int)?
336
+ dC_kidney_dt = (cnst_q['kidney'] * (C_A - C_kidney / K_kidney) - CL_kidney * C_kidney / K_kidney_cl) / \
337
+ cnst_v['kidney'] # ???
338
+
339
+ # Liver V(Liver)*dC(Liver)/dt = (Q(Liver)-Q(Spleen)-Q(Gut)-Q(Pancreas)-Q(Stomach))*C(A) + Q(Spleen)*CV(Spleen) +
340
+ # + Q(Gut)*CV(Gut) + Q(Pancreas)*CV(Pancreas) + Q(Stomach)*CV(Stomach) -
341
+ # - Q(Liver)*CV(Liver) - CL(Liver,int)*CV(Liver,int)? # тут скорее всего нужно вычитать потоки из друг друга дополнительно по крови что бы сохранить массовый баланс
342
+ Q_liver_in_from_art = cnst_q['liver'] - cnst_q['gut'] - cnst_q['spleen'] - \
343
+ cnst_q['pancreas'] - cnst_q['stomach']
344
+ dC_liver_dt = (
345
+ Q_liver_in_from_art * C_A + cnst_q['gut'] * C_gut / K_gut
346
+ + cnst_q['spleen'] * C_spleen / K_spleen
347
+ + cnst_q['stomach'] * C_stomach / K_stomach
348
+ + cnst_q['pancreas'] * C_pancreas / K_pancreas
349
+ - cnst_q['liver'] * C_liver / K_liver
350
+ - CL_liver * C_liver / K_liver_cl # ???
351
+ ) / cnst_v['liver']
352
+
353
+ dC_gut_dt = cnst_q['gut'] * (C_A - C_gut / K_gut) / cnst_v['gut']
354
+ dC_spleen_dt = cnst_q['spleen'] * (C_A - C_spleen / K_spleen) / cnst_v['spleen']
355
+ dC_stomach_dt = cnst_q['stomach'] * (C_A - C_stomach / K_stomach) / cnst_v['stomach']
356
+ dC_pancreas_dt = cnst_q['pancreas'] * (C_A - C_pancreas / K_pancreas) / cnst_v['pancreas']
357
+
358
+ dC_venouse_dt = (
359
+ cnst_q['heart'] * C_heart / K_heart
360
+ + cnst_q['brain'] * C_brain / K_brain
361
+ + cnst_q['muscle'] * C_muscle / K_muscle
362
+ + cnst_q['skin'] * C_skin / K_skin
363
+ + cnst_q['adipose'] * C_fat / K_fat
364
+ + cnst_q['bone'] * C_bone / K_bone
365
+ + cnst_q['kidney'] * C_kidney / K_kidney
366
+ + cnst_q['liver'] * C_liver / K_liver
367
+ - cnst_q['lung'] * C_V
368
+ ) / cnst_v['venous_blood']
369
+
370
+ dC_arterial_dt = cnst_q['lung'] * (C_lung / K_lung - C_A) / cnst_v['arterial_blood']
371
+
372
+ 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, \
373
+ dC_kidney_dt, dC_liver_dt, dC_gut_dt, dC_spleen_dt, dC_stomach_dt, dC_pancreas_dt, dC_venouse_dt,
374
+ dC_arterial_dt]).astype(np.float64)
375
+ return y_new
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pypharm
3
- Version: 1.3.5
3
+ Version: 1.4.0
4
4
  Summary: Module for solving pharmacokinetic problems
5
5
  Home-page: https://github.com/Krash13/PyPharm
6
6
  Author: Krash13
@@ -17,6 +17,7 @@ Requires-Dist: numpy (>=1.22.1)
17
17
  Requires-Dist: scipy (>=1.8.0)
18
18
  Requires-Dist: numba (>=0.58.1)
19
19
  Requires-Dist: matplotlib (>=3.5.1)
20
+ Requires-Dist: graycode (>=1.0.5)
20
21
 
21
22
  PyPharm
22
23
  ----------
@@ -276,8 +277,72 @@ plt.show()
276
277
  в таком случае, искомое нужно просто задать как None. Тогда вектор неизвестных это
277
278
  x = [configuration_matrix (неизвестные), outputs(неизвестные), volumes(неизвестные), release_parameters(неизвестные), v_release]
278
279
 
280
+ **6) Использование PBPK модели**
279
281
 
280
- **6) Использование shared_memory**
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**
281
346
 
282
347
  Начиная с версии 1.3.0, вы можете использовать **shared_memory** для получения текущих данных
283
348
  оптимизации. Имя нужного вам участка памяти хранится в поле **memory_name**.
@@ -553,7 +618,72 @@ The release_parameters and v_release parameters can be optimized
553
618
  in this case, you just need to set the desired value as None. Then the vector of unknowns is
554
619
  x = [configuration_matrix (unknown), outputs(unknown), volumes(unknown), release_parameters(unknown), v_release]
555
620
 
556
- **6) Using shared_memory**
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**
557
687
 
558
688
  Since version 1.3.0, you can use **shared_memory** to get current data
559
689
  optimization. The name of the memory location you need is stored in the **memory_name** field.
@@ -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=NAhi5SMWc5CnQR9fflYWKbgksx5l2GyN8x9vQY3bBCA,17771
18
+ pypharm-1.4.0.dist-info/METADATA,sha256=_fkbYe3Us2hgO8f-JqJc0mMKsKLj_mdXqMI3LxKe5R0,22934
19
+ pypharm-1.4.0.dist-info/WHEEL,sha256=OqRkF0eY5GHssMorFjlbTIq072vpHpF60fIQA6lS9xA,92
20
+ pypharm-1.4.0.dist-info/top_level.txt,sha256=yybfSkKw8q1G3aEcnlfVL7_L9ufGFSAYZnpc7q6oYJk,8
21
+ pypharm-1.4.0.dist-info/RECORD,,
@@ -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.5.dist-info/METADATA,sha256=zodKyZM_l7ORmGwqdtFfqZJ4kpHLiAhexzqYPbvpfA4,17574
9
- pypharm-1.3.5.dist-info/WHEEL,sha256=OqRkF0eY5GHssMorFjlbTIq072vpHpF60fIQA6lS9xA,92
10
- pypharm-1.3.5.dist-info/top_level.txt,sha256=yybfSkKw8q1G3aEcnlfVL7_L9ufGFSAYZnpc7q6oYJk,8
11
- pypharm-1.3.5.dist-info/RECORD,,