pypharm 1.3.6__tar.gz → 1.4.1__tar.gz
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-1.3.6 → pypharm-1.4.1}/PKG-INFO +135 -5
- {pypharm-1.3.6 → pypharm-1.4.1}/PyPharm/__init__.py +3 -1
- pypharm-1.4.1/PyPharm/algorithms/__init__.py +0 -0
- {pypharm-1.3.6/PyPharm → pypharm-1.4.1/PyPharm/algorithms}/country_optimization.py +0 -1
- {pypharm-1.3.6/PyPharm → pypharm-1.4.1/PyPharm/algorithms}/country_optimization_v3.py +47 -45
- pypharm-1.4.1/PyPharm/constants.py +56 -0
- pypharm-1.4.1/PyPharm/models/__init__.py +2 -0
- pypharm-1.3.6/PyPharm/models.py → pypharm-1.4.1/PyPharm/models/compartment_models.py +3 -3
- pypharm-1.4.1/PyPharm/models/pbpk.py +404 -0
- {pypharm-1.3.6 → pypharm-1.4.1}/README.md +134 -5
- {pypharm-1.3.6 → pypharm-1.4.1}/pypharm.egg-info/PKG-INFO +135 -5
- pypharm-1.4.1/pypharm.egg-info/SOURCES.txt +19 -0
- {pypharm-1.3.6 → pypharm-1.4.1}/setup.py +1 -1
- pypharm-1.3.6/pypharm.egg-info/SOURCES.txt +0 -15
- {pypharm-1.3.6/PyPharm → pypharm-1.4.1/PyPharm/algorithms}/country_optimization_v2.py +0 -0
- {pypharm-1.3.6/PyPharm → pypharm-1.4.1/PyPharm/algorithms}/genetic_optimization.py +0 -0
- {pypharm-1.3.6/PyPharm → pypharm-1.4.1/PyPharm/algorithms}/gold_digger_optimization.py +0 -0
- {pypharm-1.3.6 → pypharm-1.4.1}/pypharm.egg-info/dependency_links.txt +0 -0
- {pypharm-1.3.6 → pypharm-1.4.1}/pypharm.egg-info/requires.txt +0 -0
- {pypharm-1.3.6 → pypharm-1.4.1}/pypharm.egg-info/top_level.txt +0 -0
- {pypharm-1.3.6 → pypharm-1.4.1}/setup.cfg +0 -0
|
@@ -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
|
|
@@ -235,7 +235,7 @@ res = model(90, d=5700, compartment_number=0)
|
|
|
235
235
|
Если оба параметра не заданы, то модель выраздается
|
|
236
236
|
в простую BaseCompartmentModel.
|
|
237
237
|
|
|
238
|
-
**5) Модель
|
|
238
|
+
**5) Модель ReleaseCompartmentModel**
|
|
239
239
|
|
|
240
240
|
Данная модель учитывает поправку на высвобождение
|
|
241
241
|
ЛВ в модель вводятся дополнительные параметры:
|
|
@@ -272,8 +272,72 @@ plt.show()
|
|
|
272
272
|
в таком случае, искомое нужно просто задать как None. Тогда вектор неизвестных это
|
|
273
273
|
x = [configuration_matrix (неизвестные), outputs(неизвестные), volumes(неизвестные), release_parameters(неизвестные), v_release]
|
|
274
274
|
|
|
275
|
+
**6) Использование PBPK модели**
|
|
275
276
|
|
|
276
|
-
|
|
277
|
+
Вы можете использовать PBPK модель как для рассчёта по известным
|
|
278
|
+
данным так и для поиска параметров, исходя из ваших экспериментальных данных.
|
|
279
|
+
|
|
280
|
+
Чтобы задать исзвестные вам константы, при инициализации объекта следует использовать
|
|
281
|
+
параметры know_k и know_cl, которые содержат словари с известными параметрами, имена органов следует брать
|
|
282
|
+
из класса ORGAN_NAMES.
|
|
283
|
+
|
|
284
|
+
Ниже приведен пример поиска параметров и построение кривых распределения вещества
|
|
285
|
+
в органах с использованием генетического алгоритма.
|
|
286
|
+
|
|
287
|
+
```python
|
|
288
|
+
from PyPharm import PBPKmod
|
|
289
|
+
from PyPharm.constants import ORGAN_NAMES, MODEL_CONST
|
|
290
|
+
|
|
291
|
+
model = PBPKmod()
|
|
292
|
+
print(model.get_unknown_params())
|
|
293
|
+
model.load_optimization_data(
|
|
294
|
+
time_exp=[12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
295
|
+
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],
|
|
296
|
+
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],
|
|
297
|
+
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]
|
|
298
|
+
},
|
|
299
|
+
start_c_in_venous=150 * 1e-3 / MODEL_CONST['rat']['venous_blood']['V']
|
|
300
|
+
)
|
|
301
|
+
result = model.optimize(
|
|
302
|
+
method='GA',
|
|
303
|
+
x_min=17 * [0.0001],
|
|
304
|
+
x_max=17 * [5],
|
|
305
|
+
genes=17 * [16],
|
|
306
|
+
n=300,
|
|
307
|
+
child_percent=0.3,
|
|
308
|
+
mutation_chance=0.5,
|
|
309
|
+
max_mutation=5,
|
|
310
|
+
t_max=300,
|
|
311
|
+
printing=True,
|
|
312
|
+
)
|
|
313
|
+
model.update_know_params(result)
|
|
314
|
+
|
|
315
|
+
result = model(max_time=24 * 60, start_c_in_venous=150 * 1e-3 / MODEL_CONST['rat']['venous_blood']['V'], step=0.1)
|
|
316
|
+
model.plot_last_result(
|
|
317
|
+
organ_names=[ORGAN_NAMES.LUNG, ORGAN_NAMES.LIVER, ORGAN_NAMES.SPLEEN],
|
|
318
|
+
user_names={
|
|
319
|
+
ORGAN_NAMES.LUNG: 'Лёгкие',
|
|
320
|
+
ORGAN_NAMES.LIVER: 'Печень',
|
|
321
|
+
ORGAN_NAMES.SPLEEN: 'Селезёнка',
|
|
322
|
+
},
|
|
323
|
+
theoretic_data={
|
|
324
|
+
ORGAN_NAMES.LIVER: {
|
|
325
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
326
|
+
'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],
|
|
327
|
+
},
|
|
328
|
+
ORGAN_NAMES.LUNG: {
|
|
329
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
330
|
+
'y': [26.96 * 1e-6, 22.67 * 1e-6, 15.51 * 1e-6, 12.07 * 1e-6, 4.53 * 1e-6, 0 * 1e-6],
|
|
331
|
+
},
|
|
332
|
+
ORGAN_NAMES.SPLEEN: {
|
|
333
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
334
|
+
'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]
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
)
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
**7) Использование shared_memory**
|
|
277
341
|
|
|
278
342
|
Начиная с версии 1.3.0, вы можете использовать **shared_memory** для получения текущих данных
|
|
279
343
|
оптимизации. Имя нужного вам участка памяти хранится в поле **memory_name**.
|
|
@@ -512,7 +576,7 @@ of variables.
|
|
|
512
576
|
If both parameters are not set, then the model is deleted
|
|
513
577
|
into a simple BaseCompartmentModel.
|
|
514
578
|
|
|
515
|
-
**5) The
|
|
579
|
+
**5) The ReleaseCompartmentModel model**
|
|
516
580
|
|
|
517
581
|
This model takes into account the release adjustment
|
|
518
582
|
medicinal substance additional parameters are introduced into the model:
|
|
@@ -549,7 +613,72 @@ The release_parameters and v_release parameters can be optimized
|
|
|
549
613
|
in this case, you just need to set the desired value as None. Then the vector of unknowns is
|
|
550
614
|
x = [configuration_matrix (unknown), outputs(unknown), volumes(unknown), release_parameters(unknown), v_release]
|
|
551
615
|
|
|
552
|
-
**6) Using
|
|
616
|
+
**6) Using the PBPK model**
|
|
617
|
+
|
|
618
|
+
You can use the PBPK model both for calculations based on known
|
|
619
|
+
data and for searching for parameters based on your experimental data.
|
|
620
|
+
|
|
621
|
+
To set constants known to you, when initializing an object, you should use the
|
|
622
|
+
parameters know_k and know_cl, which contain dictionaries with known parameters, the names of organs should be taken
|
|
623
|
+
from the ORGAN_NAMES class.
|
|
624
|
+
|
|
625
|
+
Below is an example of searching for parameters and constructing distribution curves of a substance
|
|
626
|
+
in organs using a genetic algorithm.
|
|
627
|
+
|
|
628
|
+
```python
|
|
629
|
+
from PyPharm import PBPKmod
|
|
630
|
+
from PyPharm.constants import ORGAN_NAMES, MODEL_CONST
|
|
631
|
+
|
|
632
|
+
model = PBPKmod()
|
|
633
|
+
print(model.get_unknown_params())
|
|
634
|
+
model.load_optimization_data(
|
|
635
|
+
time_exp=[12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
636
|
+
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],
|
|
637
|
+
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],
|
|
638
|
+
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]
|
|
639
|
+
},
|
|
640
|
+
start_c_in_venous=150 * 1e-3 / MODEL_CONST['rat']['venous_blood']['V']
|
|
641
|
+
)
|
|
642
|
+
result = model.optimize(
|
|
643
|
+
method='GA',
|
|
644
|
+
x_min=17 * [0.0001],
|
|
645
|
+
x_max=17 * [5],
|
|
646
|
+
genes=17 * [16],
|
|
647
|
+
n=300,
|
|
648
|
+
child_percent=0.3,
|
|
649
|
+
mutation_chance=0.5,
|
|
650
|
+
max_mutation=5,
|
|
651
|
+
t_max=300,
|
|
652
|
+
printing=True,
|
|
653
|
+
)
|
|
654
|
+
model.update_know_params(result)
|
|
655
|
+
|
|
656
|
+
result = model(max_time=24 * 60, start_c_in_venous=150 * 1e-3 / MODEL_CONST['rat']['venous_blood']['V'], step=0.1)
|
|
657
|
+
model.plot_last_result(
|
|
658
|
+
organ_names=[ORGAN_NAMES.LUNG, ORGAN_NAMES.LIVER, ORGAN_NAMES.SPLEEN],
|
|
659
|
+
user_names={
|
|
660
|
+
ORGAN_NAMES.LUNG: 'Лёгкие',
|
|
661
|
+
ORGAN_NAMES.LIVER: 'Печень',
|
|
662
|
+
ORGAN_NAMES.SPLEEN: 'Селезёнка',
|
|
663
|
+
},
|
|
664
|
+
theoretic_data={
|
|
665
|
+
ORGAN_NAMES.LIVER: {
|
|
666
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
667
|
+
'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],
|
|
668
|
+
},
|
|
669
|
+
ORGAN_NAMES.LUNG: {
|
|
670
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
671
|
+
'y': [26.96 * 1e-6, 22.67 * 1e-6, 15.51 * 1e-6, 12.07 * 1e-6, 4.53 * 1e-6, 0 * 1e-6],
|
|
672
|
+
},
|
|
673
|
+
ORGAN_NAMES.SPLEEN: {
|
|
674
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
675
|
+
'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]
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
)
|
|
679
|
+
```
|
|
680
|
+
|
|
681
|
+
**7) Using shared_memory**
|
|
553
682
|
|
|
554
683
|
Since version 1.3.0, you can use **shared_memory** to get current data
|
|
555
684
|
optimization. The name of the memory location you need is stored in the **memory_name** field.
|
|
@@ -563,3 +692,4 @@ print(c)
|
|
|
563
692
|
|
|
564
693
|
The data is stored in list format [current_iteration, x0, ... , xn, f], works only for the country_optimization algorithm.
|
|
565
694
|
|
|
695
|
+
|
|
File without changes
|
|
@@ -345,30 +345,31 @@ class CountriesAlgorithm:
|
|
|
345
345
|
f_min=f_min,
|
|
346
346
|
f_max=f_max
|
|
347
347
|
)
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
# )
|
|
354
|
-
self.countries = sorted(self.countries, key=attrgetter('best_function'))
|
|
355
|
-
f_min = self.countries[0].best_function
|
|
356
|
-
f_max = self.countries[-1].best_function
|
|
357
|
-
s = sum(country.roulette_function(f_min, f_max) for country in self.countries if len(country.population) > 1)
|
|
358
|
-
self.countries.reverse()
|
|
359
|
-
for country in self.countries:
|
|
360
|
-
plus = 0
|
|
361
|
-
if len(country.population) >= 1:
|
|
362
|
-
res = country.extinction1(
|
|
363
|
-
max(self.N // 2, ceil(country.roulette_function(f_min, f_max) / s * self.N * self.M)) + plus
|
|
348
|
+
country.extinction(
|
|
349
|
+
m_min=self.m[0],
|
|
350
|
+
m_max=self.m[1],
|
|
351
|
+
f_min=f_min,
|
|
352
|
+
f_max=f_max
|
|
364
353
|
)
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
354
|
+
self.countries = [country for country in self.countries if len(country.population)]
|
|
355
|
+
# self.countries = sorted(self.countries, key=attrgetter('best_function'))
|
|
356
|
+
# f_min = self.countries[0].best_function
|
|
357
|
+
# f_max = self.countries[-1].best_function
|
|
358
|
+
# s = sum(country.roulette_function(f_min, f_max) for country in self.countries if len(country.population) > 1)
|
|
359
|
+
# self.countries.reverse()
|
|
360
|
+
# for country in self.countries:
|
|
361
|
+
# plus = 0
|
|
362
|
+
# if len(country.population) >= 1:
|
|
363
|
+
# res = country.extinction1(
|
|
364
|
+
# max(self.N // 2, ceil(country.roulette_function(f_min, f_max) / s * self.N * self.M)) + plus
|
|
365
|
+
# )
|
|
366
|
+
# if res:
|
|
367
|
+
# plus += res
|
|
368
|
+
# else:
|
|
369
|
+
# plus = 0
|
|
370
|
+
#
|
|
371
|
+
# indexes = np.where(vector_check_population(self.countries) == True)
|
|
372
|
+
# self.countries = [self.countries[i] for i in indexes[0]]
|
|
372
373
|
|
|
373
374
|
for individual in e_individuals:
|
|
374
375
|
random_country = self.countries[random.randint(0, len(self.countries) - 1)]
|
|
@@ -392,32 +393,33 @@ class CountriesAlgorithm:
|
|
|
392
393
|
for i in range(len(result.real_x)):
|
|
393
394
|
self.memory_list[i + 1] = float(result.real_x[i])
|
|
394
395
|
self.memory_list[-1] = float(result.f)
|
|
396
|
+
|
|
395
397
|
return (result.real_x, result.f, False, ti)
|
|
396
398
|
|
|
397
399
|
|
|
398
400
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
#
|
|
402
|
-
#
|
|
403
|
-
#
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
401
|
+
def f(x):
|
|
402
|
+
return sum([(xi ** 4 - 16 * xi ** 2 + 5 *xi) / 2 for xi in x])
|
|
403
|
+
#
|
|
404
|
+
# k = 0
|
|
405
|
+
# for i in range(100):
|
|
406
|
+
CA = CountriesAlgorithm(
|
|
407
|
+
f=f,
|
|
408
|
+
Xmin=[-5.12 for i in range(20)],
|
|
409
|
+
Xmax=[5.12 for i in range(20)],
|
|
410
|
+
genes=[16 for i in range(20)],
|
|
411
|
+
M=20,
|
|
412
|
+
N=15,
|
|
413
|
+
n=[1, 10],
|
|
414
|
+
m=[3, 8],
|
|
415
|
+
k=8,
|
|
416
|
+
l=3,
|
|
417
|
+
ep=[0.2, 0.4],
|
|
418
|
+
max_mutation=16,
|
|
419
|
+
tmax=300,
|
|
420
|
+
printing=True,
|
|
421
|
+
)
|
|
422
|
+
r = CA.start()
|
|
421
423
|
|
|
422
424
|
# print(i, r[2], r[0], r[1])
|
|
423
425
|
# if r[2]:
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
MODEL_CONST = {
|
|
2
|
+
'human':{
|
|
3
|
+
'adipose': {'V':143, 'Q':3.7},
|
|
4
|
+
'bone': {'V':124, 'Q': 3.6} ,
|
|
5
|
+
'brain': {'V':20.7, 'Q': 10} ,
|
|
6
|
+
'gut': {'V':23.6, 'Q': 13} ,
|
|
7
|
+
'heart': {'V':3.8, 'Q': 2.14},
|
|
8
|
+
'kidney': {'V':4.4, 'Q': 15.7} ,
|
|
9
|
+
'liver': {'V':24.1, 'Q': 21} ,
|
|
10
|
+
'lung': {'V':16.7, 'Q': 71} ,
|
|
11
|
+
'muscle': {'V':429, 'Q': 10.7} ,
|
|
12
|
+
'pancreas': {'V':1.2, 'Q': 1.9} ,
|
|
13
|
+
'skin': {'V':111, 'Q': 4.3} ,
|
|
14
|
+
'spleen': {'V':2.7, 'Q': 1.1},
|
|
15
|
+
'stomach': {'V':2.2, 'Q':0.56},
|
|
16
|
+
'teaster': {'V':0.51, 'Q':0.04},
|
|
17
|
+
'arterial_blood': {'V':25.7} ,
|
|
18
|
+
'venous_blood': {'V':51.4}
|
|
19
|
+
},
|
|
20
|
+
'rat':{
|
|
21
|
+
'adipose': {'V':40, 'Q':1.6},
|
|
22
|
+
'bone': {'V':53.2, 'Q': 10.12},
|
|
23
|
+
'brain': {'V':6.8, 'Q': 5.32} ,
|
|
24
|
+
'gut': {'V':40, 'Q': 52} ,
|
|
25
|
+
'heart': {'V':3.2, 'Q': 15.68},
|
|
26
|
+
'kidney': {'V':9.2, 'Q': 36.92},
|
|
27
|
+
'liver': {'V':41.2, 'Q': 80} ,
|
|
28
|
+
'lung': {'V':4, 'Q': 203.2} ,
|
|
29
|
+
'muscle': {'V':487.6, 'Q': 30} ,
|
|
30
|
+
'pancreas': {'V':5.2, 'Q': 4} ,
|
|
31
|
+
'skin': {'V':160, 'Q': 20} ,
|
|
32
|
+
'spleen': {'V':2.4, 'Q': 5} ,
|
|
33
|
+
'stomach': {'V':4.4, 'Q':8.2} ,
|
|
34
|
+
'teaster': {'V':10, 'Q':1.8} ,
|
|
35
|
+
'arterial_blood': {'V':22.4, 'Q':10.8} ,
|
|
36
|
+
'venous_blood': {'V':45.2}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
class ORGAN_NAMES:
|
|
41
|
+
|
|
42
|
+
LUNG = 'lung'
|
|
43
|
+
HEART = 'heart'
|
|
44
|
+
BRAIN = 'brain'
|
|
45
|
+
MUSCLE = 'muscle'
|
|
46
|
+
ADIPOSE = 'adipose'
|
|
47
|
+
SKIN = 'skin'
|
|
48
|
+
BONE = 'bone'
|
|
49
|
+
KIDNEY = 'kidney'
|
|
50
|
+
LIVER = 'liver'
|
|
51
|
+
GUT = 'gut'
|
|
52
|
+
SPLEEN = 'spleen'
|
|
53
|
+
STOMACH = 'stomach'
|
|
54
|
+
PANCREAS = 'pancreas'
|
|
55
|
+
VENOUS = 'venous_blood'
|
|
56
|
+
ARTERIAL = 'arterial_blood'
|
|
@@ -4,9 +4,9 @@ import numpy as np
|
|
|
4
4
|
from scipy.integrate import solve_ivp, RK45
|
|
5
5
|
from scipy.integrate import simps
|
|
6
6
|
from scipy.optimize import minimize
|
|
7
|
-
from .country_optimization import CountriesAlgorithm
|
|
8
|
-
from .country_optimization_v2 import CountriesAlgorithm_v2
|
|
9
|
-
from .genetic_optimization import GeneticAlgorithm
|
|
7
|
+
from ..algorithms.country_optimization import CountriesAlgorithm
|
|
8
|
+
from ..algorithms.country_optimization_v2 import CountriesAlgorithm_v2
|
|
9
|
+
from ..algorithms.genetic_optimization import GeneticAlgorithm
|
|
10
10
|
from numba import njit
|
|
11
11
|
import matplotlib.pyplot as plt
|
|
12
12
|
|
|
@@ -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()
|
|
@@ -219,7 +219,7 @@ res = model(90, d=5700, compartment_number=0)
|
|
|
219
219
|
Если оба параметра не заданы, то модель выраздается
|
|
220
220
|
в простую BaseCompartmentModel.
|
|
221
221
|
|
|
222
|
-
**5) Модель
|
|
222
|
+
**5) Модель ReleaseCompartmentModel**
|
|
223
223
|
|
|
224
224
|
Данная модель учитывает поправку на высвобождение
|
|
225
225
|
ЛВ в модель вводятся дополнительные параметры:
|
|
@@ -256,8 +256,72 @@ plt.show()
|
|
|
256
256
|
в таком случае, искомое нужно просто задать как None. Тогда вектор неизвестных это
|
|
257
257
|
x = [configuration_matrix (неизвестные), outputs(неизвестные), volumes(неизвестные), release_parameters(неизвестные), v_release]
|
|
258
258
|
|
|
259
|
+
**6) Использование PBPK модели**
|
|
259
260
|
|
|
260
|
-
|
|
261
|
+
Вы можете использовать PBPK модель как для рассчёта по известным
|
|
262
|
+
данным так и для поиска параметров, исходя из ваших экспериментальных данных.
|
|
263
|
+
|
|
264
|
+
Чтобы задать исзвестные вам константы, при инициализации объекта следует использовать
|
|
265
|
+
параметры know_k и know_cl, которые содержат словари с известными параметрами, имена органов следует брать
|
|
266
|
+
из класса ORGAN_NAMES.
|
|
267
|
+
|
|
268
|
+
Ниже приведен пример поиска параметров и построение кривых распределения вещества
|
|
269
|
+
в органах с использованием генетического алгоритма.
|
|
270
|
+
|
|
271
|
+
```python
|
|
272
|
+
from PyPharm import PBPKmod
|
|
273
|
+
from PyPharm.constants import ORGAN_NAMES, MODEL_CONST
|
|
274
|
+
|
|
275
|
+
model = PBPKmod()
|
|
276
|
+
print(model.get_unknown_params())
|
|
277
|
+
model.load_optimization_data(
|
|
278
|
+
time_exp=[12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
279
|
+
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],
|
|
280
|
+
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],
|
|
281
|
+
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]
|
|
282
|
+
},
|
|
283
|
+
start_c_in_venous=150 * 1e-3 / MODEL_CONST['rat']['venous_blood']['V']
|
|
284
|
+
)
|
|
285
|
+
result = model.optimize(
|
|
286
|
+
method='GA',
|
|
287
|
+
x_min=17 * [0.0001],
|
|
288
|
+
x_max=17 * [5],
|
|
289
|
+
genes=17 * [16],
|
|
290
|
+
n=300,
|
|
291
|
+
child_percent=0.3,
|
|
292
|
+
mutation_chance=0.5,
|
|
293
|
+
max_mutation=5,
|
|
294
|
+
t_max=300,
|
|
295
|
+
printing=True,
|
|
296
|
+
)
|
|
297
|
+
model.update_know_params(result)
|
|
298
|
+
|
|
299
|
+
result = model(max_time=24 * 60, start_c_in_venous=150 * 1e-3 / MODEL_CONST['rat']['venous_blood']['V'], step=0.1)
|
|
300
|
+
model.plot_last_result(
|
|
301
|
+
organ_names=[ORGAN_NAMES.LUNG, ORGAN_NAMES.LIVER, ORGAN_NAMES.SPLEEN],
|
|
302
|
+
user_names={
|
|
303
|
+
ORGAN_NAMES.LUNG: 'Лёгкие',
|
|
304
|
+
ORGAN_NAMES.LIVER: 'Печень',
|
|
305
|
+
ORGAN_NAMES.SPLEEN: 'Селезёнка',
|
|
306
|
+
},
|
|
307
|
+
theoretic_data={
|
|
308
|
+
ORGAN_NAMES.LIVER: {
|
|
309
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
310
|
+
'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],
|
|
311
|
+
},
|
|
312
|
+
ORGAN_NAMES.LUNG: {
|
|
313
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
314
|
+
'y': [26.96 * 1e-6, 22.67 * 1e-6, 15.51 * 1e-6, 12.07 * 1e-6, 4.53 * 1e-6, 0 * 1e-6],
|
|
315
|
+
},
|
|
316
|
+
ORGAN_NAMES.SPLEEN: {
|
|
317
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
318
|
+
'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]
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
)
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
**7) Использование shared_memory**
|
|
261
325
|
|
|
262
326
|
Начиная с версии 1.3.0, вы можете использовать **shared_memory** для получения текущих данных
|
|
263
327
|
оптимизации. Имя нужного вам участка памяти хранится в поле **memory_name**.
|
|
@@ -496,7 +560,7 @@ of variables.
|
|
|
496
560
|
If both parameters are not set, then the model is deleted
|
|
497
561
|
into a simple BaseCompartmentModel.
|
|
498
562
|
|
|
499
|
-
**5) The
|
|
563
|
+
**5) The ReleaseCompartmentModel model**
|
|
500
564
|
|
|
501
565
|
This model takes into account the release adjustment
|
|
502
566
|
medicinal substance additional parameters are introduced into the model:
|
|
@@ -533,7 +597,72 @@ The release_parameters and v_release parameters can be optimized
|
|
|
533
597
|
in this case, you just need to set the desired value as None. Then the vector of unknowns is
|
|
534
598
|
x = [configuration_matrix (unknown), outputs(unknown), volumes(unknown), release_parameters(unknown), v_release]
|
|
535
599
|
|
|
536
|
-
**6) Using
|
|
600
|
+
**6) Using the PBPK model**
|
|
601
|
+
|
|
602
|
+
You can use the PBPK model both for calculations based on known
|
|
603
|
+
data and for searching for parameters based on your experimental data.
|
|
604
|
+
|
|
605
|
+
To set constants known to you, when initializing an object, you should use the
|
|
606
|
+
parameters know_k and know_cl, which contain dictionaries with known parameters, the names of organs should be taken
|
|
607
|
+
from the ORGAN_NAMES class.
|
|
608
|
+
|
|
609
|
+
Below is an example of searching for parameters and constructing distribution curves of a substance
|
|
610
|
+
in organs using a genetic algorithm.
|
|
611
|
+
|
|
612
|
+
```python
|
|
613
|
+
from PyPharm import PBPKmod
|
|
614
|
+
from PyPharm.constants import ORGAN_NAMES, MODEL_CONST
|
|
615
|
+
|
|
616
|
+
model = PBPKmod()
|
|
617
|
+
print(model.get_unknown_params())
|
|
618
|
+
model.load_optimization_data(
|
|
619
|
+
time_exp=[12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
620
|
+
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],
|
|
621
|
+
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],
|
|
622
|
+
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]
|
|
623
|
+
},
|
|
624
|
+
start_c_in_venous=150 * 1e-3 / MODEL_CONST['rat']['venous_blood']['V']
|
|
625
|
+
)
|
|
626
|
+
result = model.optimize(
|
|
627
|
+
method='GA',
|
|
628
|
+
x_min=17 * [0.0001],
|
|
629
|
+
x_max=17 * [5],
|
|
630
|
+
genes=17 * [16],
|
|
631
|
+
n=300,
|
|
632
|
+
child_percent=0.3,
|
|
633
|
+
mutation_chance=0.5,
|
|
634
|
+
max_mutation=5,
|
|
635
|
+
t_max=300,
|
|
636
|
+
printing=True,
|
|
637
|
+
)
|
|
638
|
+
model.update_know_params(result)
|
|
639
|
+
|
|
640
|
+
result = model(max_time=24 * 60, start_c_in_venous=150 * 1e-3 / MODEL_CONST['rat']['venous_blood']['V'], step=0.1)
|
|
641
|
+
model.plot_last_result(
|
|
642
|
+
organ_names=[ORGAN_NAMES.LUNG, ORGAN_NAMES.LIVER, ORGAN_NAMES.SPLEEN],
|
|
643
|
+
user_names={
|
|
644
|
+
ORGAN_NAMES.LUNG: 'Лёгкие',
|
|
645
|
+
ORGAN_NAMES.LIVER: 'Печень',
|
|
646
|
+
ORGAN_NAMES.SPLEEN: 'Селезёнка',
|
|
647
|
+
},
|
|
648
|
+
theoretic_data={
|
|
649
|
+
ORGAN_NAMES.LIVER: {
|
|
650
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
651
|
+
'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],
|
|
652
|
+
},
|
|
653
|
+
ORGAN_NAMES.LUNG: {
|
|
654
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
655
|
+
'y': [26.96 * 1e-6, 22.67 * 1e-6, 15.51 * 1e-6, 12.07 * 1e-6, 4.53 * 1e-6, 0 * 1e-6],
|
|
656
|
+
},
|
|
657
|
+
ORGAN_NAMES.SPLEEN: {
|
|
658
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
659
|
+
'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]
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
)
|
|
663
|
+
```
|
|
664
|
+
|
|
665
|
+
**7) Using shared_memory**
|
|
537
666
|
|
|
538
667
|
Since version 1.3.0, you can use **shared_memory** to get current data
|
|
539
668
|
optimization. The name of the memory location you need is stored in the **memory_name** field.
|
|
@@ -545,4 +674,4 @@ print(c)
|
|
|
545
674
|
# ShareableList([4, 3.5192100752465563, 1.4158559227257506, 1.7264077213115414, 0.008336751860551, 0.2549196311342251, 0.5160375718404234, 6.915499993374695, 2.944744649331201, 0.5, 1.907294741996761], name='wnsm_0c50aa90')
|
|
546
675
|
```
|
|
547
676
|
|
|
548
|
-
The data is stored in list format [current_iteration, x0, ... , xn, f], works only for the country_optimization algorithm.
|
|
677
|
+
The data is stored in list format [current_iteration, x0, ... , xn, f], works only for the country_optimization algorithm.
|
|
@@ -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
|
|
@@ -235,7 +235,7 @@ res = model(90, d=5700, compartment_number=0)
|
|
|
235
235
|
Если оба параметра не заданы, то модель выраздается
|
|
236
236
|
в простую BaseCompartmentModel.
|
|
237
237
|
|
|
238
|
-
**5) Модель
|
|
238
|
+
**5) Модель ReleaseCompartmentModel**
|
|
239
239
|
|
|
240
240
|
Данная модель учитывает поправку на высвобождение
|
|
241
241
|
ЛВ в модель вводятся дополнительные параметры:
|
|
@@ -272,8 +272,72 @@ plt.show()
|
|
|
272
272
|
в таком случае, искомое нужно просто задать как None. Тогда вектор неизвестных это
|
|
273
273
|
x = [configuration_matrix (неизвестные), outputs(неизвестные), volumes(неизвестные), release_parameters(неизвестные), v_release]
|
|
274
274
|
|
|
275
|
+
**6) Использование PBPK модели**
|
|
275
276
|
|
|
276
|
-
|
|
277
|
+
Вы можете использовать PBPK модель как для рассчёта по известным
|
|
278
|
+
данным так и для поиска параметров, исходя из ваших экспериментальных данных.
|
|
279
|
+
|
|
280
|
+
Чтобы задать исзвестные вам константы, при инициализации объекта следует использовать
|
|
281
|
+
параметры know_k и know_cl, которые содержат словари с известными параметрами, имена органов следует брать
|
|
282
|
+
из класса ORGAN_NAMES.
|
|
283
|
+
|
|
284
|
+
Ниже приведен пример поиска параметров и построение кривых распределения вещества
|
|
285
|
+
в органах с использованием генетического алгоритма.
|
|
286
|
+
|
|
287
|
+
```python
|
|
288
|
+
from PyPharm import PBPKmod
|
|
289
|
+
from PyPharm.constants import ORGAN_NAMES, MODEL_CONST
|
|
290
|
+
|
|
291
|
+
model = PBPKmod()
|
|
292
|
+
print(model.get_unknown_params())
|
|
293
|
+
model.load_optimization_data(
|
|
294
|
+
time_exp=[12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
295
|
+
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],
|
|
296
|
+
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],
|
|
297
|
+
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]
|
|
298
|
+
},
|
|
299
|
+
start_c_in_venous=150 * 1e-3 / MODEL_CONST['rat']['venous_blood']['V']
|
|
300
|
+
)
|
|
301
|
+
result = model.optimize(
|
|
302
|
+
method='GA',
|
|
303
|
+
x_min=17 * [0.0001],
|
|
304
|
+
x_max=17 * [5],
|
|
305
|
+
genes=17 * [16],
|
|
306
|
+
n=300,
|
|
307
|
+
child_percent=0.3,
|
|
308
|
+
mutation_chance=0.5,
|
|
309
|
+
max_mutation=5,
|
|
310
|
+
t_max=300,
|
|
311
|
+
printing=True,
|
|
312
|
+
)
|
|
313
|
+
model.update_know_params(result)
|
|
314
|
+
|
|
315
|
+
result = model(max_time=24 * 60, start_c_in_venous=150 * 1e-3 / MODEL_CONST['rat']['venous_blood']['V'], step=0.1)
|
|
316
|
+
model.plot_last_result(
|
|
317
|
+
organ_names=[ORGAN_NAMES.LUNG, ORGAN_NAMES.LIVER, ORGAN_NAMES.SPLEEN],
|
|
318
|
+
user_names={
|
|
319
|
+
ORGAN_NAMES.LUNG: 'Лёгкие',
|
|
320
|
+
ORGAN_NAMES.LIVER: 'Печень',
|
|
321
|
+
ORGAN_NAMES.SPLEEN: 'Селезёнка',
|
|
322
|
+
},
|
|
323
|
+
theoretic_data={
|
|
324
|
+
ORGAN_NAMES.LIVER: {
|
|
325
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
326
|
+
'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],
|
|
327
|
+
},
|
|
328
|
+
ORGAN_NAMES.LUNG: {
|
|
329
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
330
|
+
'y': [26.96 * 1e-6, 22.67 * 1e-6, 15.51 * 1e-6, 12.07 * 1e-6, 4.53 * 1e-6, 0 * 1e-6],
|
|
331
|
+
},
|
|
332
|
+
ORGAN_NAMES.SPLEEN: {
|
|
333
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
334
|
+
'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]
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
)
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
**7) Использование shared_memory**
|
|
277
341
|
|
|
278
342
|
Начиная с версии 1.3.0, вы можете использовать **shared_memory** для получения текущих данных
|
|
279
343
|
оптимизации. Имя нужного вам участка памяти хранится в поле **memory_name**.
|
|
@@ -512,7 +576,7 @@ of variables.
|
|
|
512
576
|
If both parameters are not set, then the model is deleted
|
|
513
577
|
into a simple BaseCompartmentModel.
|
|
514
578
|
|
|
515
|
-
**5) The
|
|
579
|
+
**5) The ReleaseCompartmentModel model**
|
|
516
580
|
|
|
517
581
|
This model takes into account the release adjustment
|
|
518
582
|
medicinal substance additional parameters are introduced into the model:
|
|
@@ -549,7 +613,72 @@ The release_parameters and v_release parameters can be optimized
|
|
|
549
613
|
in this case, you just need to set the desired value as None. Then the vector of unknowns is
|
|
550
614
|
x = [configuration_matrix (unknown), outputs(unknown), volumes(unknown), release_parameters(unknown), v_release]
|
|
551
615
|
|
|
552
|
-
**6) Using
|
|
616
|
+
**6) Using the PBPK model**
|
|
617
|
+
|
|
618
|
+
You can use the PBPK model both for calculations based on known
|
|
619
|
+
data and for searching for parameters based on your experimental data.
|
|
620
|
+
|
|
621
|
+
To set constants known to you, when initializing an object, you should use the
|
|
622
|
+
parameters know_k and know_cl, which contain dictionaries with known parameters, the names of organs should be taken
|
|
623
|
+
from the ORGAN_NAMES class.
|
|
624
|
+
|
|
625
|
+
Below is an example of searching for parameters and constructing distribution curves of a substance
|
|
626
|
+
in organs using a genetic algorithm.
|
|
627
|
+
|
|
628
|
+
```python
|
|
629
|
+
from PyPharm import PBPKmod
|
|
630
|
+
from PyPharm.constants import ORGAN_NAMES, MODEL_CONST
|
|
631
|
+
|
|
632
|
+
model = PBPKmod()
|
|
633
|
+
print(model.get_unknown_params())
|
|
634
|
+
model.load_optimization_data(
|
|
635
|
+
time_exp=[12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
636
|
+
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],
|
|
637
|
+
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],
|
|
638
|
+
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]
|
|
639
|
+
},
|
|
640
|
+
start_c_in_venous=150 * 1e-3 / MODEL_CONST['rat']['venous_blood']['V']
|
|
641
|
+
)
|
|
642
|
+
result = model.optimize(
|
|
643
|
+
method='GA',
|
|
644
|
+
x_min=17 * [0.0001],
|
|
645
|
+
x_max=17 * [5],
|
|
646
|
+
genes=17 * [16],
|
|
647
|
+
n=300,
|
|
648
|
+
child_percent=0.3,
|
|
649
|
+
mutation_chance=0.5,
|
|
650
|
+
max_mutation=5,
|
|
651
|
+
t_max=300,
|
|
652
|
+
printing=True,
|
|
653
|
+
)
|
|
654
|
+
model.update_know_params(result)
|
|
655
|
+
|
|
656
|
+
result = model(max_time=24 * 60, start_c_in_venous=150 * 1e-3 / MODEL_CONST['rat']['venous_blood']['V'], step=0.1)
|
|
657
|
+
model.plot_last_result(
|
|
658
|
+
organ_names=[ORGAN_NAMES.LUNG, ORGAN_NAMES.LIVER, ORGAN_NAMES.SPLEEN],
|
|
659
|
+
user_names={
|
|
660
|
+
ORGAN_NAMES.LUNG: 'Лёгкие',
|
|
661
|
+
ORGAN_NAMES.LIVER: 'Печень',
|
|
662
|
+
ORGAN_NAMES.SPLEEN: 'Селезёнка',
|
|
663
|
+
},
|
|
664
|
+
theoretic_data={
|
|
665
|
+
ORGAN_NAMES.LIVER: {
|
|
666
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
667
|
+
'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],
|
|
668
|
+
},
|
|
669
|
+
ORGAN_NAMES.LUNG: {
|
|
670
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
671
|
+
'y': [26.96 * 1e-6, 22.67 * 1e-6, 15.51 * 1e-6, 12.07 * 1e-6, 4.53 * 1e-6, 0 * 1e-6],
|
|
672
|
+
},
|
|
673
|
+
ORGAN_NAMES.SPLEEN: {
|
|
674
|
+
'x': [12, 60, 3 * 60, 5* 60, 15 * 60, 24 * 60],
|
|
675
|
+
'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]
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
)
|
|
679
|
+
```
|
|
680
|
+
|
|
681
|
+
**7) Using shared_memory**
|
|
553
682
|
|
|
554
683
|
Since version 1.3.0, you can use **shared_memory** to get current data
|
|
555
684
|
optimization. The name of the memory location you need is stored in the **memory_name** field.
|
|
@@ -563,3 +692,4 @@ print(c)
|
|
|
563
692
|
|
|
564
693
|
The data is stored in list format [current_iteration, x0, ... , xn, f], works only for the country_optimization algorithm.
|
|
565
694
|
|
|
695
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.cfg
|
|
3
|
+
setup.py
|
|
4
|
+
PyPharm/__init__.py
|
|
5
|
+
PyPharm/constants.py
|
|
6
|
+
PyPharm/algorithms/__init__.py
|
|
7
|
+
PyPharm/algorithms/country_optimization.py
|
|
8
|
+
PyPharm/algorithms/country_optimization_v2.py
|
|
9
|
+
PyPharm/algorithms/country_optimization_v3.py
|
|
10
|
+
PyPharm/algorithms/genetic_optimization.py
|
|
11
|
+
PyPharm/algorithms/gold_digger_optimization.py
|
|
12
|
+
PyPharm/models/__init__.py
|
|
13
|
+
PyPharm/models/compartment_models.py
|
|
14
|
+
PyPharm/models/pbpk.py
|
|
15
|
+
pypharm.egg-info/PKG-INFO
|
|
16
|
+
pypharm.egg-info/SOURCES.txt
|
|
17
|
+
pypharm.egg-info/dependency_links.txt
|
|
18
|
+
pypharm.egg-info/requires.txt
|
|
19
|
+
pypharm.egg-info/top_level.txt
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
README.md
|
|
2
|
-
setup.cfg
|
|
3
|
-
setup.py
|
|
4
|
-
PyPharm/__init__.py
|
|
5
|
-
PyPharm/country_optimization.py
|
|
6
|
-
PyPharm/country_optimization_v2.py
|
|
7
|
-
PyPharm/country_optimization_v3.py
|
|
8
|
-
PyPharm/genetic_optimization.py
|
|
9
|
-
PyPharm/gold_digger_optimization.py
|
|
10
|
-
PyPharm/models.py
|
|
11
|
-
pypharm.egg-info/PKG-INFO
|
|
12
|
-
pypharm.egg-info/SOURCES.txt
|
|
13
|
-
pypharm.egg-info/dependency_links.txt
|
|
14
|
-
pypharm.egg-info/requires.txt
|
|
15
|
-
pypharm.egg-info/top_level.txt
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|