pbpk-lite 0.0.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.
- pbpk_lite-0.0.1/LICENSE +19 -0
- pbpk_lite-0.0.1/PKG-INFO +21 -0
- pbpk_lite-0.0.1/README.md +3 -0
- pbpk_lite-0.0.1/pyproject.toml +29 -0
- pbpk_lite-0.0.1/src/pbpk_lite/__init__.py +3 -0
- pbpk_lite-0.0.1/src/pbpk_lite/distribution_params.py +41 -0
- pbpk_lite-0.0.1/src/pbpk_lite/graph.py +26 -0
- pbpk_lite-0.0.1/src/pbpk_lite/main.py +110 -0
- pbpk_lite-0.0.1/src/pbpk_lite/ode_system.py +40 -0
- pbpk_lite-0.0.1/src/pbpk_lite/solve.py +26 -0
pbpk_lite-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2026 Gregor Čekada cekada.gregor@gmail.com
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
pbpk_lite-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pbpk-lite
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: This is a simple implementation of PBPK modeling in python.
|
|
5
|
+
Project-URL: Homepage, https://github.com/cekadagregor/pbpk-lite
|
|
6
|
+
Project-URL: Issues, https://github.com/cekadagregor/pbpk-lite/issues
|
|
7
|
+
Author-email: Gregor Čekada <cekada.gregor@gmail.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: model,pbpk,pharmacokinetics
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Requires-Dist: matplotlib>=3.8.0
|
|
15
|
+
Requires-Dist: numpy>=2.0.0
|
|
16
|
+
Requires-Dist: scipy>=1.12.0
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# pbpk-lite
|
|
20
|
+
|
|
21
|
+
This is a simple implementation of PBPK modeling in python.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling >= 1.26"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pbpk-lite"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
keywords = ["pbpk", "pharmacokinetics", "model"]
|
|
9
|
+
authors = [
|
|
10
|
+
{ name="Gregor Čekada", email="cekada.gregor@gmail.com" },
|
|
11
|
+
]
|
|
12
|
+
description = "This is a simple implementation of PBPK modeling in python."
|
|
13
|
+
readme = "README.md"
|
|
14
|
+
requires-python = ">=3.9"
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
dependencies = [
|
|
20
|
+
"scipy>=1.12.0",
|
|
21
|
+
"numpy>=2.0.0",
|
|
22
|
+
"matplotlib>=3.8.0",
|
|
23
|
+
]
|
|
24
|
+
license = "MIT"
|
|
25
|
+
license-files = ["LICENSE"]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://github.com/cekadagregor/pbpk-lite"
|
|
29
|
+
Issues = "https://github.com/cekadagregor/pbpk-lite/issues"
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
V_a = np.array((143, 124, 20.7, 23.6, 3.8, 4.4, 24.1, 16.7, 429, 1.2, 111, 2.7, 2.2, 0.51, 25.7, 51.4)) # kg/mL
|
|
4
|
+
def V_function(bw): return V_a * bw
|
|
5
|
+
|
|
6
|
+
Q_a = np.array((3.7, 3.6, 10, 13, 2.14, 15.7, 21, 71, 10.7, 1.9, 4.3, 1.1, 0.56, 0.04)) # mL/min/kg
|
|
7
|
+
def Q_function(bw): return Q_a * (bw**0.75)
|
|
8
|
+
|
|
9
|
+
# phospholipid, neutral lipid, water
|
|
10
|
+
Tissue_composition = np.array(((0.002, 0.79, 0.18),
|
|
11
|
+
(0.0005, 0.074, 0.439),
|
|
12
|
+
(0.0565, 0.051, 0.77),
|
|
13
|
+
(0.0163, 0.0487, 0.718),
|
|
14
|
+
(0.0166, 0.0115, 0.758),
|
|
15
|
+
(0.0162, 0.0207, 0.783),
|
|
16
|
+
(0.0252, 0.0348, 0.751),
|
|
17
|
+
(0.009, 0.003, 0.811),
|
|
18
|
+
(0.0072, 0.0238, 0.76),
|
|
19
|
+
(0.0188, 0.0723, 0.66),
|
|
20
|
+
(0.0111, 0.0284, 0.718),
|
|
21
|
+
(0.0198, 0.0201, 0.788),
|
|
22
|
+
(0.0182, 0.0338, 0.784),
|
|
23
|
+
(0, 0, 0.859),
|
|
24
|
+
(0.0033, 0.0022, 0.651),
|
|
25
|
+
(0.00225, 0.0035, 0.945))) # L/kg
|
|
26
|
+
|
|
27
|
+
f_pl = Tissue_composition[:, 0]
|
|
28
|
+
f_nl = Tissue_composition[:, 1]
|
|
29
|
+
f_w = Tissue_composition[:, 2]
|
|
30
|
+
|
|
31
|
+
f_pl_p = 0.067
|
|
32
|
+
f_nl_p = 0.0012
|
|
33
|
+
f_w_p = 0.939
|
|
34
|
+
|
|
35
|
+
def partition_model(logp, fu):
|
|
36
|
+
fut = 1/(1 + 0.5*((1-fu)/fu))
|
|
37
|
+
p_ow = 10**logp
|
|
38
|
+
|
|
39
|
+
k_p = fu*(p_ow*(f_nl + 0.3*f_pl) + f_w + 0.7*f_pl)/(p_ow*(f_nl_p + 0.3*f_pl_p) + f_w_p + 0.7*f_pl_p)
|
|
40
|
+
k_p[1:] /= fut
|
|
41
|
+
return k_p
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import matplotlib.pyplot as plt
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
compartment_names = ['adipose', 'bone', 'brain' , 'gut', 'heart', 'kidney', 'liver', 'lung', 'muscle', 'pancreas', 'skin', 'spleen', 'stomach', 'testes', 'arterial_blood', 'venous_blood']
|
|
5
|
+
|
|
6
|
+
def identify_compartment(arg):
|
|
7
|
+
if type(arg) == int:
|
|
8
|
+
return compartment_names[arg]
|
|
9
|
+
else:
|
|
10
|
+
return compartment_names.index(arg)
|
|
11
|
+
|
|
12
|
+
def matrix_index():
|
|
13
|
+
for i in range(4):
|
|
14
|
+
for j in range(4):
|
|
15
|
+
yield i, j
|
|
16
|
+
|
|
17
|
+
def graph_whole_helper(time, concentrations, save_as):
|
|
18
|
+
plt.rcParams['font.size'] = 8
|
|
19
|
+
fig, axs = plt.subplots(4, 4, layout='constrained', sharex=True, figsize=(6.27, 3.5), dpi=300)
|
|
20
|
+
comp = 0
|
|
21
|
+
for i in matrix_index():
|
|
22
|
+
axs[i].plot(time, concentrations[comp, :])
|
|
23
|
+
axs[i].set_title(identify_compartment(comp))
|
|
24
|
+
axs[i].set_facecolor('#F2F2F2')
|
|
25
|
+
comp += 1
|
|
26
|
+
plt.savefig(save_as, dpi=300, bbox_inches="tight")
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from .distribution_params import V_function, Q_function, partition_model
|
|
3
|
+
from .graph import graph_whole_helper
|
|
4
|
+
from .solve import solver
|
|
5
|
+
from .ode_system import system_generator
|
|
6
|
+
|
|
7
|
+
class model:
|
|
8
|
+
def __init__(self):
|
|
9
|
+
# placeholder parameters
|
|
10
|
+
logp = 6.97
|
|
11
|
+
fu = 0.0022448
|
|
12
|
+
bw = 70
|
|
13
|
+
self.partition_coefficients = partition_model(logp, fu)
|
|
14
|
+
self.blood_flows = Q_function(bw)
|
|
15
|
+
self.volumes = V_function(bw)
|
|
16
|
+
|
|
17
|
+
cl_k = 0
|
|
18
|
+
cl_l = 10
|
|
19
|
+
def elimination(c):
|
|
20
|
+
outflow = np.zeros(16)
|
|
21
|
+
outflow[5] += cl_k*c[5]
|
|
22
|
+
outflow[6] += cl_l*c[6]
|
|
23
|
+
return outflow
|
|
24
|
+
|
|
25
|
+
self.elimination = elimination
|
|
26
|
+
|
|
27
|
+
def set_substance(self, log_p, fu):
|
|
28
|
+
"""
|
|
29
|
+
Set the substance that is being investigated.
|
|
30
|
+
|
|
31
|
+
Parameters
|
|
32
|
+
----------
|
|
33
|
+
log_p : float
|
|
34
|
+
Log of the octanol water partition of the substance.
|
|
35
|
+
fu : float
|
|
36
|
+
Free unbound value of the substance.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
self.partition_coefficients = partition_model(log_p, fu)
|
|
40
|
+
self.odes = system_generator(self.volumes, self.blood_flows, self.partition_coefficients, self.elimination)
|
|
41
|
+
|
|
42
|
+
def set_patient(self, bw):
|
|
43
|
+
"""
|
|
44
|
+
Set the patient's distribution parameters.
|
|
45
|
+
|
|
46
|
+
Parameters
|
|
47
|
+
----------
|
|
48
|
+
bw : float
|
|
49
|
+
Patient's body weight.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
self.blood_flows = Q_function(bw)
|
|
53
|
+
self.volumes = V_function(bw)
|
|
54
|
+
self.odes = system_generator(self.volumes, self.blood_flows, self.partition_coefficients, self.elimination)
|
|
55
|
+
|
|
56
|
+
def set_elimination(self, /, cl_l = 0, cl_k= 0):
|
|
57
|
+
'''
|
|
58
|
+
Set the elimination parameters.
|
|
59
|
+
|
|
60
|
+
Parameters
|
|
61
|
+
----------
|
|
62
|
+
cl_l : float
|
|
63
|
+
Clearance from the liver based linearly on concentration.
|
|
64
|
+
cl_k : float
|
|
65
|
+
Clearance from the kidney based linearly on concentration.
|
|
66
|
+
'''
|
|
67
|
+
|
|
68
|
+
def elimination(c):
|
|
69
|
+
outflow = np.zeros(16)
|
|
70
|
+
outflow[5] += cl_k*c[5]
|
|
71
|
+
outflow[6] += cl_l*c[6]
|
|
72
|
+
return outflow
|
|
73
|
+
|
|
74
|
+
self.elimination = elimination
|
|
75
|
+
self.odes = system_generator(self.volumes, self.blood_flows, self.partition_coefficients, self.elimination)
|
|
76
|
+
|
|
77
|
+
def solve(self, doses, times):
|
|
78
|
+
"""
|
|
79
|
+
Set the administration regime and solve the system of odes.
|
|
80
|
+
|
|
81
|
+
Each dose at index i is administered at time at index i.
|
|
82
|
+
|
|
83
|
+
Parameters
|
|
84
|
+
----------
|
|
85
|
+
doses : array-like
|
|
86
|
+
A list of all doses.
|
|
87
|
+
times : array-like
|
|
88
|
+
A list of times at which doses ware given.
|
|
89
|
+
|
|
90
|
+
Returns
|
|
91
|
+
-------
|
|
92
|
+
t : ndarray
|
|
93
|
+
Times at which there is some c.
|
|
94
|
+
c : ndarray
|
|
95
|
+
Concentrations in each tissue at given t.
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
self.t, self.c = solver(self.odes, doses, times, self.volumes)
|
|
99
|
+
return self.t, self.c
|
|
100
|
+
|
|
101
|
+
def graph_whole(self, name):
|
|
102
|
+
"""
|
|
103
|
+
Graph the concentrations in each tissue and save the figure.
|
|
104
|
+
|
|
105
|
+
Parameters
|
|
106
|
+
----------
|
|
107
|
+
name : str
|
|
108
|
+
File path to save the figure.
|
|
109
|
+
"""
|
|
110
|
+
graph_whole_helper(self.t, self.c, name)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
# 0 adipose, 1 bone, 2 brain, 3 gut, 4 heart, 5 kidney, 6 liver, 7 lung, 8 muscle,
|
|
4
|
+
# 9 pancreas, 10 skin, 11 spleen, 12 stomach, 13 testes, 14 arterial blood, 15 venous blood
|
|
5
|
+
|
|
6
|
+
arterial_input = np.ones(14)
|
|
7
|
+
arterial_input[7] = 0
|
|
8
|
+
|
|
9
|
+
liver_input = np.zeros(14)
|
|
10
|
+
liver_input[11] = 1
|
|
11
|
+
liver_input[9] = 1
|
|
12
|
+
liver_input[12] = 1
|
|
13
|
+
liver_input[3] = 1
|
|
14
|
+
|
|
15
|
+
venous_input = np.ones(14)
|
|
16
|
+
venous_input[7] = 0
|
|
17
|
+
venous_input[11] = 0
|
|
18
|
+
venous_input[9] = 0
|
|
19
|
+
venous_input[12] = 0
|
|
20
|
+
venous_input[3] = 0
|
|
21
|
+
|
|
22
|
+
no_lung = np.ones(14)
|
|
23
|
+
no_lung[7] = 0
|
|
24
|
+
|
|
25
|
+
iv_input = 0
|
|
26
|
+
ia_input = 0
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def system_generator(V, Q, K, elimination):
|
|
30
|
+
def inner(t, A):
|
|
31
|
+
C = A/V
|
|
32
|
+
dA = np.zeros(16)
|
|
33
|
+
dA[7] = Q[7]*(C[15] - C[7]/K[7])
|
|
34
|
+
dA[:14] += no_lung*Q*(C[14] - C[:14]/K[:14])
|
|
35
|
+
dA[6] += sum(liver_input*Q*C[:14]/K[:14])
|
|
36
|
+
dA -= elimination(C)
|
|
37
|
+
dA[15] = - Q[7]*C[15] + sum(venous_input*Q*C[:14]/K[:14]) + iv_input
|
|
38
|
+
dA[14] = Q[7]*C[7]/K[7] - (sum(Q) - Q[7])*C[14] + ia_input
|
|
39
|
+
return dA
|
|
40
|
+
return inner
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from scipy.integrate import solve_ivp
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
def solver(ode_system, doses, times, volumes):
|
|
5
|
+
t_full = np.array([])
|
|
6
|
+
a_full = np.array([[] for i in range(16)])
|
|
7
|
+
|
|
8
|
+
for i in range(len(doses)):
|
|
9
|
+
dose = doses[i]
|
|
10
|
+
time_interval = times[i:i+2]
|
|
11
|
+
if i == 0:
|
|
12
|
+
a0 = np.zeros(16)
|
|
13
|
+
else:
|
|
14
|
+
a0 = a_full[:, -1]
|
|
15
|
+
a0[15] += dose # iv_bolus
|
|
16
|
+
|
|
17
|
+
sol = solve_ivp(ode_system, time_interval, a0)
|
|
18
|
+
t_partial = sol.t
|
|
19
|
+
a_partial = sol.y
|
|
20
|
+
|
|
21
|
+
t_full = np.concatenate((t_full, t_partial))
|
|
22
|
+
a_full = np.concatenate((a_full, a_partial), axis=1)
|
|
23
|
+
|
|
24
|
+
volumes = volumes[:, np.newaxis]
|
|
25
|
+
c_full = a_full/volumes
|
|
26
|
+
return t_full, c_full
|