drux 0.2__tar.gz → 0.4__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.
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: drux
3
- Version: 0.2
3
+ Version: 0.4
4
4
  Summary: Drux: Drug Release Analysis Framework
5
5
  Home-page: https://github.com/openscilab/drux
6
- Download-URL: https://github.com/openscilab/drux/tarball/v0.2
6
+ Download-URL: https://github.com/openscilab/drux/tarball/v0.4
7
7
  Author: Drux Development Team
8
8
  Author-email: drux@openscilab.com
9
9
  License: MIT
@@ -20,6 +20,7 @@ Classifier: Programming Language :: Python :: 3.10
20
20
  Classifier: Programming Language :: Python :: 3.11
21
21
  Classifier: Programming Language :: Python :: 3.12
22
22
  Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
23
24
  Classifier: Intended Audience :: Developers
24
25
  Classifier: Intended Audience :: Education
25
26
  Classifier: Intended Audience :: End Users/Desktop
@@ -53,6 +54,7 @@ Dynamic: summary
53
54
 
54
55
 
55
56
  <div align="center">
57
+ <img src="https://github.com/openscilab/drux/raw/main/otherfiles/logo.png" width="350">
56
58
  <h1>Drux: Drug Release Analysis Framework</h1>
57
59
  <br/>
58
60
  <a href="https://badge.fury.io/py/drux"><img src="https://badge.fury.io/py/drux.svg" alt="PyPI version"></a>
@@ -116,9 +118,9 @@ Drux is a Python-based framework for simulating drug release profiles using math
116
118
 
117
119
  ### PyPI
118
120
  - Check [Python Packaging User Guide](https://packaging.python.org/installing/)
119
- - Run `pip install drux==0.2`
121
+ - Run `pip install drux==0.4`
120
122
  ### Source code
121
- - Download [Version 0.2](https://github.com/openscilab/drux/archive/v0.2.zip) or [Latest Source](https://github.com/openscilab/drux/archive/dev.zip)
123
+ - Download [Version 0.4](https://github.com/openscilab/drux/archive/v0.4.zip) or [Latest Source](https://github.com/openscilab/drux/archive/dev.zip)
122
124
  - Run `pip install .`
123
125
 
124
126
  ## Supported Models
@@ -175,6 +177,7 @@ where:
175
177
  - $c_s (\frac{mg}{cm^3})$ is the solubility of the drug in the polymer (carrier)
176
178
 
177
179
  ⚠️ The Higuchi model assumes that $c_0 \ge c_s$
180
+
178
181
  #### Applications
179
182
  1. Matrix Tablets
180
183
  2. Hydrophilic polymer matrices
@@ -182,6 +185,49 @@ where:
182
185
  4. Semisolid Systems
183
186
  5. Implantable Drug delivery systems
184
187
 
188
+ ### Weibull
189
+ Weibull model is an empirical model used to describe drug release kinetics from various pharmaceutical dosage forms. It is characterized by a flexible empirical equation that captures various release kinetics.
190
+ According to this model, the cumulative amount of drug released at time $t$ is given by:
191
+
192
+ $$
193
+ M_t = M \left(1 - e^{-at^b}\right)
194
+ $$
195
+
196
+ where:
197
+ - $M_t (mg)$ is the cumulative absolute amount of drug released at time $t$
198
+ - $M (mg)$ is the total amount of drug released at infinite time
199
+ - $a$ is the scale parameter (related to the release rate)
200
+ - $b$ is the shape parameter (indicates the release mechanism)
201
+
202
+ #### Applications
203
+ 1. Controlled-release modeling
204
+ 2. Dissolution profiling
205
+ 3. Comparative studies
206
+ 4. Vivo predictions
207
+
208
+ ### Hopfenberg
209
+ The Hopfenberg model describes drug release from surface-eroding polymers with a constant surface area.
210
+ It is particularly useful for modeling drug release from biodegradable polymers where the drug is uniformly distributed throughout the matrix.
211
+ According to this model, the cumulative amount of drug released at time $t$ is given by:
212
+
213
+ $$
214
+ M_t = M_{\infty} \left(1 - \left(1 - \frac{k_0t}{c_0 a_0}\right)^n\right)
215
+ $$
216
+
217
+ where:
218
+ - $M_t (mg)$ is the cumulative absolute amount of drug released at time $t
219
+ - $M_{\infty} (mg)$ is the total amount of drug released at infinite time
220
+ - $k_0 (\frac{mg}{mm^2 s})$ is the surface erosion rate constant
221
+ - $c_0 (\frac{mg}{mm^3})$ is the initial drug concentration in the polymer matrix
222
+ - $a_0 (mm)$ is the initial radius (for spheres) or half-thickness (for slabs) of the device
223
+ - $n$ is the geometry-dependent exponent (1 for slabs, 2 for cylinders, 3 for spheres)
224
+
225
+ #### Applications
226
+ 1. Biodegradable Implants
227
+ 2. Surface-eroding drug delivery systems
228
+ 3. Transdermal Patches
229
+ 4. Injectable depots
230
+
185
231
  ## Usage
186
232
  ### Zero-Order Model
187
233
  ```python
@@ -210,6 +256,27 @@ model.plot(show=True)
210
256
  ```
211
257
  <img src="https://github.com/openscilab/drux/raw/main/otherfiles/higuchi_plot.png" alt="Higuchi Plot">
212
258
 
259
+ ### Weibull Model
260
+
261
+ ```python
262
+ from drux import WeibullModel
263
+ model = WeibullModel(M=1, a=0.095, b=0.7)
264
+ model.simulate(duration=100, time_step=1)
265
+ model.plot(show=True)
266
+ ```
267
+ <img src="https://github.com/openscilab/drux/raw/main/otherfiles/weibull_plot.png" alt="Weibull Plot">
268
+
269
+ ### Hopfenberg Model
270
+
271
+ ```python
272
+ from drux import HopfenbergModel
273
+ model = HopfenbergModel(M=1, k0=0.00067, c0=0.0374, a0=3.51, n=2)
274
+ model.simulate(duration=100, time_step=1)
275
+ model.plot(show=True)
276
+ ```
277
+ <img src="https://github.com/openscilab/drux/raw/main/otherfiles/hopfenberg_plot.png" alt="Hopfenberg Plot">
278
+
279
+
213
280
  ## Issues & bug reports
214
281
 
215
282
  Just fill an issue and describe it. We'll check it ASAP! or send an email to [drux@openscilab.com](mailto:drux@openscilab.com "drux@openscilab.com").
@@ -230,6 +297,10 @@ You can also join our discord server
230
297
  <blockquote>4- R. Vaju and K. V. Murthy, "Development and validation of new discriminative dissolution method for carvedilol tablets," <i>Indian Journal of Pharmaceutical Sciences</i>, vol. 73, no. 5, pp. 527–536, Sep. 2011.</blockquote>
231
298
  <blockquote>5- S. Dash, "Kinetic modeling on drug release from controlled drug delivery systems," <i>Acta Poloniae Pharmaceutica</i>, 2010.</blockquote>
232
299
  <blockquote>6- K. H. Ramteke, P. A. Dighe, A. R. Kharat, S. V. Patil, <i>Mathematical models of drug dissolution: A review</i>, <i>Sch. Acad. J. Pharm.</i>, vol. 3, no. 5, pp. 388-396, 2014.</blockquote>
300
+ <blockquote>7- C. Corsaro, G. Neri, A. M. Mezzasalma, and E. Fazio, "Weibull modeling of controlled drug release from Ag-PMA nanosystems," <i>Polymers</i>, vol. 13, no. 17, p. 2897, 2021.</blockquote>
301
+ <blockquote>8- H. B. Hopfenberg, "Controlled release from erodible slabs, cylinders, and spheres," in <i>Controlled Release Polymeric Formulations</i>, ACS Symposium Series, vol. 33, pp. 26–32, 1976.</blockquote>
302
+ <blockquote>9- H. V. Chavda, M. S. Patel, and C. N. Patel, "Preparation and in vitro evaluation of guar gum based triple-layer matrix tablet of diclofenac sodium," <i>Research in Pharmaceutical Sciences</i>, vol. 7, no. 1, pp. 57–64, Jan. 2012.</blockquote>
303
+
233
304
 
234
305
  ## Show your support
235
306
  ### Star this repo
@@ -248,6 +319,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
248
319
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
249
320
 
250
321
  ## [Unreleased]
322
+ ## [0.4] - 2026-05-18
323
+ ### Added
324
+ - Hopfenberg model
325
+ ## [0.3] - 2025-12-08
326
+ ### Added
327
+ - Weibull model
328
+ - Logo
329
+ - `__repr__` method for models
330
+ ### Changed
331
+ - `Python 3.14` added to `test.yml`
251
332
  ## [0.2] - 2025-09-27
252
333
  ### Added
253
334
  - Zero-order model
@@ -264,6 +345,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
264
345
  - Higuchi model
265
346
 
266
347
 
267
- [Unreleased]: https://github.com/openscilab/drux/compare/v0.2...dev
348
+ [Unreleased]: https://github.com/openscilab/drux/compare/v0.4...dev
349
+ [0.4]: https://github.com/openscilab/drux/compare/v0.3...v0.4
350
+ [0.3]: https://github.com/openscilab/drux/compare/v0.2...v0.3
268
351
  [0.2]: https://github.com/openscilab/drux/compare/v0.1...v0.2
269
352
  [0.1]: https://github.com/openscilab/drux/compare/48548f0...v0.1
@@ -1,4 +1,5 @@
1
1
  <div align="center">
2
+ <img src="https://github.com/openscilab/drux/raw/main/otherfiles/logo.png" width="350">
2
3
  <h1>Drux: Drug Release Analysis Framework</h1>
3
4
  <br/>
4
5
  <a href="https://badge.fury.io/py/drux"><img src="https://badge.fury.io/py/drux.svg" alt="PyPI version"></a>
@@ -62,9 +63,9 @@ Drux is a Python-based framework for simulating drug release profiles using math
62
63
 
63
64
  ### PyPI
64
65
  - Check [Python Packaging User Guide](https://packaging.python.org/installing/)
65
- - Run `pip install drux==0.2`
66
+ - Run `pip install drux==0.4`
66
67
  ### Source code
67
- - Download [Version 0.2](https://github.com/openscilab/drux/archive/v0.2.zip) or [Latest Source](https://github.com/openscilab/drux/archive/dev.zip)
68
+ - Download [Version 0.4](https://github.com/openscilab/drux/archive/v0.4.zip) or [Latest Source](https://github.com/openscilab/drux/archive/dev.zip)
68
69
  - Run `pip install .`
69
70
 
70
71
  ## Supported Models
@@ -121,6 +122,7 @@ where:
121
122
  - $c_s (\frac{mg}{cm^3})$ is the solubility of the drug in the polymer (carrier)
122
123
 
123
124
  ⚠️ The Higuchi model assumes that $c_0 \ge c_s$
125
+
124
126
  #### Applications
125
127
  1. Matrix Tablets
126
128
  2. Hydrophilic polymer matrices
@@ -128,6 +130,49 @@ where:
128
130
  4. Semisolid Systems
129
131
  5. Implantable Drug delivery systems
130
132
 
133
+ ### Weibull
134
+ Weibull model is an empirical model used to describe drug release kinetics from various pharmaceutical dosage forms. It is characterized by a flexible empirical equation that captures various release kinetics.
135
+ According to this model, the cumulative amount of drug released at time $t$ is given by:
136
+
137
+ $$
138
+ M_t = M \left(1 - e^{-at^b}\right)
139
+ $$
140
+
141
+ where:
142
+ - $M_t (mg)$ is the cumulative absolute amount of drug released at time $t$
143
+ - $M (mg)$ is the total amount of drug released at infinite time
144
+ - $a$ is the scale parameter (related to the release rate)
145
+ - $b$ is the shape parameter (indicates the release mechanism)
146
+
147
+ #### Applications
148
+ 1. Controlled-release modeling
149
+ 2. Dissolution profiling
150
+ 3. Comparative studies
151
+ 4. Vivo predictions
152
+
153
+ ### Hopfenberg
154
+ The Hopfenberg model describes drug release from surface-eroding polymers with a constant surface area.
155
+ It is particularly useful for modeling drug release from biodegradable polymers where the drug is uniformly distributed throughout the matrix.
156
+ According to this model, the cumulative amount of drug released at time $t$ is given by:
157
+
158
+ $$
159
+ M_t = M_{\infty} \left(1 - \left(1 - \frac{k_0t}{c_0 a_0}\right)^n\right)
160
+ $$
161
+
162
+ where:
163
+ - $M_t (mg)$ is the cumulative absolute amount of drug released at time $t
164
+ - $M_{\infty} (mg)$ is the total amount of drug released at infinite time
165
+ - $k_0 (\frac{mg}{mm^2 s})$ is the surface erosion rate constant
166
+ - $c_0 (\frac{mg}{mm^3})$ is the initial drug concentration in the polymer matrix
167
+ - $a_0 (mm)$ is the initial radius (for spheres) or half-thickness (for slabs) of the device
168
+ - $n$ is the geometry-dependent exponent (1 for slabs, 2 for cylinders, 3 for spheres)
169
+
170
+ #### Applications
171
+ 1. Biodegradable Implants
172
+ 2. Surface-eroding drug delivery systems
173
+ 3. Transdermal Patches
174
+ 4. Injectable depots
175
+
131
176
  ## Usage
132
177
  ### Zero-Order Model
133
178
  ```python
@@ -156,6 +201,27 @@ model.plot(show=True)
156
201
  ```
157
202
  <img src="https://github.com/openscilab/drux/raw/main/otherfiles/higuchi_plot.png" alt="Higuchi Plot">
158
203
 
204
+ ### Weibull Model
205
+
206
+ ```python
207
+ from drux import WeibullModel
208
+ model = WeibullModel(M=1, a=0.095, b=0.7)
209
+ model.simulate(duration=100, time_step=1)
210
+ model.plot(show=True)
211
+ ```
212
+ <img src="https://github.com/openscilab/drux/raw/main/otherfiles/weibull_plot.png" alt="Weibull Plot">
213
+
214
+ ### Hopfenberg Model
215
+
216
+ ```python
217
+ from drux import HopfenbergModel
218
+ model = HopfenbergModel(M=1, k0=0.00067, c0=0.0374, a0=3.51, n=2)
219
+ model.simulate(duration=100, time_step=1)
220
+ model.plot(show=True)
221
+ ```
222
+ <img src="https://github.com/openscilab/drux/raw/main/otherfiles/hopfenberg_plot.png" alt="Hopfenberg Plot">
223
+
224
+
159
225
  ## Issues & bug reports
160
226
 
161
227
  Just fill an issue and describe it. We'll check it ASAP! or send an email to [drux@openscilab.com](mailto:drux@openscilab.com "drux@openscilab.com").
@@ -176,6 +242,10 @@ You can also join our discord server
176
242
  <blockquote>4- R. Vaju and K. V. Murthy, "Development and validation of new discriminative dissolution method for carvedilol tablets," <i>Indian Journal of Pharmaceutical Sciences</i>, vol. 73, no. 5, pp. 527–536, Sep. 2011.</blockquote>
177
243
  <blockquote>5- S. Dash, "Kinetic modeling on drug release from controlled drug delivery systems," <i>Acta Poloniae Pharmaceutica</i>, 2010.</blockquote>
178
244
  <blockquote>6- K. H. Ramteke, P. A. Dighe, A. R. Kharat, S. V. Patil, <i>Mathematical models of drug dissolution: A review</i>, <i>Sch. Acad. J. Pharm.</i>, vol. 3, no. 5, pp. 388-396, 2014.</blockquote>
245
+ <blockquote>7- C. Corsaro, G. Neri, A. M. Mezzasalma, and E. Fazio, "Weibull modeling of controlled drug release from Ag-PMA nanosystems," <i>Polymers</i>, vol. 13, no. 17, p. 2897, 2021.</blockquote>
246
+ <blockquote>8- H. B. Hopfenberg, "Controlled release from erodible slabs, cylinders, and spheres," in <i>Controlled Release Polymeric Formulations</i>, ACS Symposium Series, vol. 33, pp. 26–32, 1976.</blockquote>
247
+ <blockquote>9- H. V. Chavda, M. S. Patel, and C. N. Patel, "Preparation and in vitro evaluation of guar gum based triple-layer matrix tablet of diclofenac sodium," <i>Research in Pharmaceutical Sciences</i>, vol. 7, no. 1, pp. 57–64, Jan. 2012.</blockquote>
248
+
179
249
 
180
250
  ## Show your support
181
251
  ### Star this repo
@@ -5,5 +5,7 @@ from .params import DRUX_VERSION
5
5
  from .higuchi import HiguchiModel, HiguchiParameters
6
6
  from .zero_order import ZeroOrderModel, ZeroOrderParameters
7
7
  from .first_order import FirstOrderModel, FirstOrderParameters
8
+ from .weibull import WeibullModel, WeibullParameters
9
+ from .hopfenberg import HopfenbergModel, HopfenbergParameters
8
10
 
9
11
  __version__ = DRUX_VERSION
@@ -34,6 +34,10 @@ class FirstOrderModel(DrugReleaseModel):
34
34
  self._parameters = FirstOrderParameters(k=k, M0=M0)
35
35
  self._plot_parameters["label"] = "First-Order Model"
36
36
 
37
+ def __repr__(self):
38
+ """Return a string representation of the First-Order model."""
39
+ return f"drux.FirstOrderModel(k={self._parameters.k}, M0={self._parameters.M0})"
40
+
37
41
  def _model_function(self, t: float) -> float:
38
42
  """
39
43
  Calculate the drug release at time t using the first-order model.
@@ -43,6 +43,13 @@ class HiguchiModel(DrugReleaseModel):
43
43
  self._parameters = HiguchiParameters(D=D, c0=c0, cs=cs)
44
44
  self._plot_parameters["label"] = "Higuchi Model"
45
45
 
46
+ def __repr__(self):
47
+ """Return a string representation of the Higuchi model."""
48
+ return (
49
+ f"drux.HiguchiModel(D={self._parameters.D}, "
50
+ f"c0={self._parameters.c0}, cs={self._parameters.cs})"
51
+ )
52
+
46
53
  def _model_function(self, t: float) -> float:
47
54
  """
48
55
  Calculate the drug release at time t using the Higuchi model.
@@ -0,0 +1,92 @@
1
+ # -*- coding: utf-8 -*-
2
+ """Drux Hopfenberg model implementation."""
3
+
4
+ from .base_model import DrugReleaseModel
5
+ from .messages import (
6
+ ERROR_INVALID_EROSION_CONSTANT,
7
+ ERROR_INVALID_INITIAL_RADIUS,
8
+ ERROR_INVALID_GEOMETRY_FACTOR,
9
+ ERROR_INVALID_CONCENTRATION,
10
+ ERROR_RELEASABLE_AMOUNT,
11
+ )
12
+ from dataclasses import dataclass
13
+
14
+
15
+ @dataclass
16
+ class HopfenbergParameters:
17
+ """
18
+ Parameters for the Hopfenberg model based on surface erosion.
19
+
20
+ Attributes:
21
+ k0 (float): Erosion rate constant (mg/(mm^2·s))
22
+ c0 (float): Initial drug concentration in the matrix (mg/mm^3)
23
+ a0 (float): Initial radius or half-thickness of the device (mm)
24
+ n (int): Geometry factor (1=slab, 2=cylinder, 3=sphere)
25
+ """
26
+
27
+ M: float
28
+ k0: float
29
+ c0: float
30
+ a0: float
31
+ n: int
32
+
33
+
34
+ class HopfenbergModel(DrugReleaseModel):
35
+ """Simulator for the Hopfenberg drug release model for surface-eroding polymers."""
36
+
37
+ def __init__(self, M: float, k0: float, c0: float, a0: float, n: int) -> None:
38
+ """
39
+ Initialize the Hopfenberg model with the given parameters.
40
+
41
+ :param M: entire releasable amount of drug (normally M > 0) (mg)
42
+ :param k0: Erosion rate constant (mg/(mm^2·s))
43
+ :param c0: Initial drug concentration in the matrix (mg/mm^3)
44
+ :param a0: Initial radius or half-thickness of the device (mm)
45
+ :param n: Geometry factor (1=slab, 2=cylinder, 3=sphere)
46
+ """
47
+ super().__init__()
48
+ self._parameters = HopfenbergParameters(M=M, k0=k0, c0=c0, a0=a0, n=n)
49
+ self._plot_parameters["label"] = "Hopfenberg Model"
50
+
51
+ def __repr__(self):
52
+ """Return a string representation of the Hopfenberg model."""
53
+ return (
54
+ f"drux.HopfenbergModel(M={self._parameters.M}, k0={self._parameters.k0}, "
55
+ f"c0={self._parameters.c0}, a0={self._parameters.a0}, "
56
+ f"n={self._parameters.n})"
57
+ )
58
+
59
+ def _model_function(self, t: float) -> float:
60
+ """
61
+ Calculate the fractional drug release at time t using the Hopfenberg model.
62
+
63
+ Formula:
64
+ - Mt = M∞(1 - (1 - k0*t / (c0*a0))^n)
65
+
66
+ :param t: time (s)
67
+ :return: drug release
68
+ """
69
+ M = self._parameters.M
70
+ k0 = self._parameters.k0
71
+ c0 = self._parameters.c0
72
+ a0 = self._parameters.a0
73
+ n = self._parameters.n
74
+
75
+ inner_term = 1 - (k0 * t) / (c0 * a0)
76
+
77
+ Mt = M * (1 - (inner_term**n))
78
+
79
+ return Mt
80
+
81
+ def _validate_parameters(self) -> None:
82
+ """Validate the parameters of the Hopfenberg model."""
83
+ if self._parameters.M < 0:
84
+ raise ValueError(ERROR_RELEASABLE_AMOUNT)
85
+ if self._parameters.k0 < 0:
86
+ raise ValueError(ERROR_INVALID_EROSION_CONSTANT)
87
+ if self._parameters.c0 <= 0:
88
+ raise ValueError(ERROR_INVALID_CONCENTRATION)
89
+ if self._parameters.a0 <= 0:
90
+ raise ValueError(ERROR_INVALID_INITIAL_RADIUS)
91
+ if self._parameters.n not in (1, 2, 3):
92
+ raise ValueError(ERROR_INVALID_GEOMETRY_FACTOR)
@@ -32,3 +32,15 @@ ERROR_FIRST_ORDER_RELEASE_RATE = "Release rate (k) must be non-negative."
32
32
  ERROR_FIRST_ORDER_INITIAL_AMOUNT = (
33
33
  "Entire releasable amount of drug (M0) must be non-negative."
34
34
  )
35
+
36
+ # Error messages for Weibull
37
+ ERROR_WEIBULL_SCALE_PARAMETER = "Scale parameter (a) must be positive."
38
+ ERROR_WEIBULL_SHAPE_PARAMETER = "Shape parameter (b) must be positive."
39
+ ERROR_RELEASABLE_AMOUNT = (
40
+ "Entire releasable amount of drug (M) must be non-negative."
41
+ )
42
+
43
+ # Hopfenberg model error messages
44
+ ERROR_INVALID_EROSION_CONSTANT = "Erosion rate constant (k0) must be non-negative."
45
+ ERROR_INVALID_INITIAL_RADIUS = "Initial radius or half-thickness (a0) must be positive."
46
+ ERROR_INVALID_GEOMETRY_FACTOR = "Geometry factor (n) must be 1 (slab), 2 (cylinder), or 3 (sphere)."
@@ -1,4 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  """Drux parameters and constants."""
3
3
 
4
- DRUX_VERSION = "0.2"
4
+ DRUX_VERSION = "0.4"
@@ -0,0 +1,72 @@
1
+ # -*- coding: utf-8 -*-
2
+ """Drux Weibull model implementation."""
3
+
4
+ from .base_model import DrugReleaseModel
5
+ from .messages import (
6
+ ERROR_WEIBULL_SCALE_PARAMETER,
7
+ ERROR_RELEASABLE_AMOUNT,
8
+ ERROR_WEIBULL_SHAPE_PARAMETER,
9
+ )
10
+ from dataclasses import dataclass
11
+ from math import exp
12
+
13
+
14
+ @dataclass
15
+ class WeibullParameters:
16
+ """
17
+ Parameters for the Weibull model based on physical formulation.
18
+
19
+ Attributes:
20
+ M (float): entire releasable amount of drug (normally M > 0) (mg)
21
+ a (float): scale factor
22
+ b (float): shape factor
23
+ """
24
+
25
+ M: float
26
+ a: float
27
+ b: float
28
+
29
+
30
+ class WeibullModel(DrugReleaseModel):
31
+ """Simulator for the Weibull drug release model using analytical expressions based on concentration conditions."""
32
+
33
+ def __init__(self, M: float, a: float, b: float) -> None:
34
+ """
35
+ Initialize the Weibull model with the given parameters.
36
+
37
+ :param M: entire releasable amount of drug (normally M > 0) (mg)
38
+ :param a: scale factor
39
+ :param b: shape factor
40
+ """
41
+ super().__init__()
42
+ self._parameters = WeibullParameters(M=M, a=a, b=b)
43
+ self._plot_parameters["label"] = "Weibull Model"
44
+
45
+ def __repr__(self):
46
+ """Return a string representation of the Weibull model."""
47
+ return f"drux.WeibullModel(M={self._parameters.M}, a={self._parameters.a}, b={self._parameters.b})"
48
+
49
+ def _model_function(self, t: float) -> float:
50
+ """
51
+ Calculate the drug release at time t using the Weibull model.
52
+
53
+ Formula:
54
+ - General case: Mt = M * (1 - exp(-a*t ** b))
55
+ :param t: time (s)
56
+ """
57
+ M = self._parameters.M
58
+ a = self._parameters.a
59
+ b = self._parameters.b
60
+
61
+ Mt = M * (1 - exp(-a * t**b))
62
+
63
+ return Mt
64
+
65
+ def _validate_parameters(self) -> None:
66
+ """Validate the parameters of the Weibull model."""
67
+ if self._parameters.M < 0:
68
+ raise ValueError(ERROR_RELEASABLE_AMOUNT)
69
+ if self._parameters.a <= 0:
70
+ raise ValueError(ERROR_WEIBULL_SCALE_PARAMETER)
71
+ if self._parameters.b <= 0:
72
+ raise ValueError(ERROR_WEIBULL_SHAPE_PARAMETER)
@@ -34,6 +34,10 @@ class ZeroOrderModel(DrugReleaseModel):
34
34
  self._parameters = ZeroOrderParameters(k0=k0, M0=M0)
35
35
  self._plot_parameters["label"] = "Zero-Order Model"
36
36
 
37
+ def __repr__(self):
38
+ """Return a string representation of the Zero-Order model."""
39
+ return f"drux.ZeroOrderModel(k0={self._parameters.k0}, M0={self._parameters.M0})"
40
+
37
41
  def _model_function(self, t: float) -> float:
38
42
  """
39
43
  Calculate the drug release at time t using the zero-order model.
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: drux
3
- Version: 0.2
3
+ Version: 0.4
4
4
  Summary: Drux: Drug Release Analysis Framework
5
5
  Home-page: https://github.com/openscilab/drux
6
- Download-URL: https://github.com/openscilab/drux/tarball/v0.2
6
+ Download-URL: https://github.com/openscilab/drux/tarball/v0.4
7
7
  Author: Drux Development Team
8
8
  Author-email: drux@openscilab.com
9
9
  License: MIT
@@ -20,6 +20,7 @@ Classifier: Programming Language :: Python :: 3.10
20
20
  Classifier: Programming Language :: Python :: 3.11
21
21
  Classifier: Programming Language :: Python :: 3.12
22
22
  Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
23
24
  Classifier: Intended Audience :: Developers
24
25
  Classifier: Intended Audience :: Education
25
26
  Classifier: Intended Audience :: End Users/Desktop
@@ -53,6 +54,7 @@ Dynamic: summary
53
54
 
54
55
 
55
56
  <div align="center">
57
+ <img src="https://github.com/openscilab/drux/raw/main/otherfiles/logo.png" width="350">
56
58
  <h1>Drux: Drug Release Analysis Framework</h1>
57
59
  <br/>
58
60
  <a href="https://badge.fury.io/py/drux"><img src="https://badge.fury.io/py/drux.svg" alt="PyPI version"></a>
@@ -116,9 +118,9 @@ Drux is a Python-based framework for simulating drug release profiles using math
116
118
 
117
119
  ### PyPI
118
120
  - Check [Python Packaging User Guide](https://packaging.python.org/installing/)
119
- - Run `pip install drux==0.2`
121
+ - Run `pip install drux==0.4`
120
122
  ### Source code
121
- - Download [Version 0.2](https://github.com/openscilab/drux/archive/v0.2.zip) or [Latest Source](https://github.com/openscilab/drux/archive/dev.zip)
123
+ - Download [Version 0.4](https://github.com/openscilab/drux/archive/v0.4.zip) or [Latest Source](https://github.com/openscilab/drux/archive/dev.zip)
122
124
  - Run `pip install .`
123
125
 
124
126
  ## Supported Models
@@ -175,6 +177,7 @@ where:
175
177
  - $c_s (\frac{mg}{cm^3})$ is the solubility of the drug in the polymer (carrier)
176
178
 
177
179
  ⚠️ The Higuchi model assumes that $c_0 \ge c_s$
180
+
178
181
  #### Applications
179
182
  1. Matrix Tablets
180
183
  2. Hydrophilic polymer matrices
@@ -182,6 +185,49 @@ where:
182
185
  4. Semisolid Systems
183
186
  5. Implantable Drug delivery systems
184
187
 
188
+ ### Weibull
189
+ Weibull model is an empirical model used to describe drug release kinetics from various pharmaceutical dosage forms. It is characterized by a flexible empirical equation that captures various release kinetics.
190
+ According to this model, the cumulative amount of drug released at time $t$ is given by:
191
+
192
+ $$
193
+ M_t = M \left(1 - e^{-at^b}\right)
194
+ $$
195
+
196
+ where:
197
+ - $M_t (mg)$ is the cumulative absolute amount of drug released at time $t$
198
+ - $M (mg)$ is the total amount of drug released at infinite time
199
+ - $a$ is the scale parameter (related to the release rate)
200
+ - $b$ is the shape parameter (indicates the release mechanism)
201
+
202
+ #### Applications
203
+ 1. Controlled-release modeling
204
+ 2. Dissolution profiling
205
+ 3. Comparative studies
206
+ 4. Vivo predictions
207
+
208
+ ### Hopfenberg
209
+ The Hopfenberg model describes drug release from surface-eroding polymers with a constant surface area.
210
+ It is particularly useful for modeling drug release from biodegradable polymers where the drug is uniformly distributed throughout the matrix.
211
+ According to this model, the cumulative amount of drug released at time $t$ is given by:
212
+
213
+ $$
214
+ M_t = M_{\infty} \left(1 - \left(1 - \frac{k_0t}{c_0 a_0}\right)^n\right)
215
+ $$
216
+
217
+ where:
218
+ - $M_t (mg)$ is the cumulative absolute amount of drug released at time $t
219
+ - $M_{\infty} (mg)$ is the total amount of drug released at infinite time
220
+ - $k_0 (\frac{mg}{mm^2 s})$ is the surface erosion rate constant
221
+ - $c_0 (\frac{mg}{mm^3})$ is the initial drug concentration in the polymer matrix
222
+ - $a_0 (mm)$ is the initial radius (for spheres) or half-thickness (for slabs) of the device
223
+ - $n$ is the geometry-dependent exponent (1 for slabs, 2 for cylinders, 3 for spheres)
224
+
225
+ #### Applications
226
+ 1. Biodegradable Implants
227
+ 2. Surface-eroding drug delivery systems
228
+ 3. Transdermal Patches
229
+ 4. Injectable depots
230
+
185
231
  ## Usage
186
232
  ### Zero-Order Model
187
233
  ```python
@@ -210,6 +256,27 @@ model.plot(show=True)
210
256
  ```
211
257
  <img src="https://github.com/openscilab/drux/raw/main/otherfiles/higuchi_plot.png" alt="Higuchi Plot">
212
258
 
259
+ ### Weibull Model
260
+
261
+ ```python
262
+ from drux import WeibullModel
263
+ model = WeibullModel(M=1, a=0.095, b=0.7)
264
+ model.simulate(duration=100, time_step=1)
265
+ model.plot(show=True)
266
+ ```
267
+ <img src="https://github.com/openscilab/drux/raw/main/otherfiles/weibull_plot.png" alt="Weibull Plot">
268
+
269
+ ### Hopfenberg Model
270
+
271
+ ```python
272
+ from drux import HopfenbergModel
273
+ model = HopfenbergModel(M=1, k0=0.00067, c0=0.0374, a0=3.51, n=2)
274
+ model.simulate(duration=100, time_step=1)
275
+ model.plot(show=True)
276
+ ```
277
+ <img src="https://github.com/openscilab/drux/raw/main/otherfiles/hopfenberg_plot.png" alt="Hopfenberg Plot">
278
+
279
+
213
280
  ## Issues & bug reports
214
281
 
215
282
  Just fill an issue and describe it. We'll check it ASAP! or send an email to [drux@openscilab.com](mailto:drux@openscilab.com "drux@openscilab.com").
@@ -230,6 +297,10 @@ You can also join our discord server
230
297
  <blockquote>4- R. Vaju and K. V. Murthy, "Development and validation of new discriminative dissolution method for carvedilol tablets," <i>Indian Journal of Pharmaceutical Sciences</i>, vol. 73, no. 5, pp. 527–536, Sep. 2011.</blockquote>
231
298
  <blockquote>5- S. Dash, "Kinetic modeling on drug release from controlled drug delivery systems," <i>Acta Poloniae Pharmaceutica</i>, 2010.</blockquote>
232
299
  <blockquote>6- K. H. Ramteke, P. A. Dighe, A. R. Kharat, S. V. Patil, <i>Mathematical models of drug dissolution: A review</i>, <i>Sch. Acad. J. Pharm.</i>, vol. 3, no. 5, pp. 388-396, 2014.</blockquote>
300
+ <blockquote>7- C. Corsaro, G. Neri, A. M. Mezzasalma, and E. Fazio, "Weibull modeling of controlled drug release from Ag-PMA nanosystems," <i>Polymers</i>, vol. 13, no. 17, p. 2897, 2021.</blockquote>
301
+ <blockquote>8- H. B. Hopfenberg, "Controlled release from erodible slabs, cylinders, and spheres," in <i>Controlled Release Polymeric Formulations</i>, ACS Symposium Series, vol. 33, pp. 26–32, 1976.</blockquote>
302
+ <blockquote>9- H. V. Chavda, M. S. Patel, and C. N. Patel, "Preparation and in vitro evaluation of guar gum based triple-layer matrix tablet of diclofenac sodium," <i>Research in Pharmaceutical Sciences</i>, vol. 7, no. 1, pp. 57–64, Jan. 2012.</blockquote>
303
+
233
304
 
234
305
  ## Show your support
235
306
  ### Star this repo
@@ -248,6 +319,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
248
319
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
249
320
 
250
321
  ## [Unreleased]
322
+ ## [0.4] - 2026-05-18
323
+ ### Added
324
+ - Hopfenberg model
325
+ ## [0.3] - 2025-12-08
326
+ ### Added
327
+ - Weibull model
328
+ - Logo
329
+ - `__repr__` method for models
330
+ ### Changed
331
+ - `Python 3.14` added to `test.yml`
251
332
  ## [0.2] - 2025-09-27
252
333
  ### Added
253
334
  - Zero-order model
@@ -264,6 +345,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
264
345
  - Higuchi model
265
346
 
266
347
 
267
- [Unreleased]: https://github.com/openscilab/drux/compare/v0.2...dev
348
+ [Unreleased]: https://github.com/openscilab/drux/compare/v0.4...dev
349
+ [0.4]: https://github.com/openscilab/drux/compare/v0.3...v0.4
350
+ [0.3]: https://github.com/openscilab/drux/compare/v0.2...v0.3
268
351
  [0.2]: https://github.com/openscilab/drux/compare/v0.1...v0.2
269
352
  [0.1]: https://github.com/openscilab/drux/compare/48548f0...v0.1
@@ -6,8 +6,10 @@ drux/__init__.py
6
6
  drux/base_model.py
7
7
  drux/first_order.py
8
8
  drux/higuchi.py
9
+ drux/hopfenberg.py
9
10
  drux/messages.py
10
11
  drux/params.py
12
+ drux/weibull.py
11
13
  drux/zero_order.py
12
14
  drux.egg-info/PKG-INFO
13
15
  drux.egg-info/SOURCES.txt
@@ -16,4 +18,6 @@ drux.egg-info/requires.txt
16
18
  drux.egg-info/top_level.txt
17
19
  tests/test_first_order.py
18
20
  tests/test_higuchi.py
21
+ tests/test_hopfenberg.py
22
+ tests/test_weibull.py
19
23
  tests/test_zero_order.py
@@ -33,14 +33,14 @@ setup(
33
33
  name='drux',
34
34
  packages=[
35
35
  'drux', ],
36
- version='0.2',
36
+ version='0.4',
37
37
  description='Drux: Drug Release Analysis Framework',
38
38
  long_description=read_description(),
39
39
  long_description_content_type='text/markdown',
40
40
  author='Drux Development Team',
41
41
  author_email='drux@openscilab.com',
42
42
  url='https://github.com/openscilab/drux',
43
- download_url='https://github.com/openscilab/drux/tarball/v0.2',
43
+ download_url='https://github.com/openscilab/drux/tarball/v0.4',
44
44
  keywords="drug-release drug-delivery mathematical-modeling simulation kinetics",
45
45
  project_urls={
46
46
  'Source': 'https://github.com/openscilab/drux',
@@ -59,6 +59,7 @@ setup(
59
59
  'Programming Language :: Python :: 3.11',
60
60
  'Programming Language :: Python :: 3.12',
61
61
  'Programming Language :: Python :: 3.13',
62
+ 'Programming Language :: Python :: 3.14',
62
63
  'Intended Audience :: Developers',
63
64
  'Intended Audience :: Education',
64
65
  'Intended Audience :: End Users/Desktop',
@@ -26,6 +26,12 @@ def test_invalid_parameters():
26
26
  FirstOrderModel(M0=M0, k=-k).simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
27
27
 
28
28
 
29
+ def test_repr():
30
+ model = FirstOrderModel(M0=M0, k=k)
31
+ repr_str = repr(model)
32
+ assert repr_str == f"drux.FirstOrderModel(k={k}, M0={M0})"
33
+
34
+
29
35
  def test_first_order_simulation(): # Reference: https://europepmc.org/article/pmc/3425064
30
36
  model = FirstOrderModel(M0=M0, k=k)
31
37
  profile = model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
@@ -115,6 +115,12 @@ def test_higuchi_release_rate_error():
115
115
  model.get_release_rate()
116
116
 
117
117
 
118
+ def test_repr():
119
+ model = HiguchiModel(D=D, c0=C0, cs=CS)
120
+ repr_str = repr(model)
121
+ assert repr_str == f"drux.HiguchiModel(D={D}, c0={C0}, cs={CS})"
122
+
123
+
118
124
  def test_higuchi_time_for_release(): # Reference: https://www.wolframalpha.com/input?i=solve+for+t+in+sqrt%2810%5E%28-6%29*0.5*%282*1.5-0.5%29*t%29+%3D+0.5*sqrt%2810%5E%28-6%29*0.5*%282*1.5-0.5%29*1000%29
119
125
  model = HiguchiModel(D=D, c0=C0, cs=CS)
120
126
  model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
@@ -0,0 +1,151 @@
1
+ """Tests for the Hopfenberg model implementation in drux package."""
2
+
3
+ from pytest import raises
4
+ from numpy import isclose
5
+ from re import escape
6
+ from drux import HopfenbergModel
7
+
8
+ TEST_CASE_NAME = "Hopfenberg model tests"
9
+ M, k0, c0, a0, n = 1, 0.00067, 0.0374, 3.51, 2
10
+ SIM_DURATION, SIM_TIME_STEP = 100, 1
11
+ RELATIVE_TOLERANCE = 1e-1
12
+
13
+
14
+ def test_hopfenberg_parameters():
15
+ model = HopfenbergModel(M=M, k0=k0, c0=c0, a0=a0, n=n)
16
+ assert model._parameters.M == M
17
+ assert model._parameters.k0 == k0
18
+ assert model._parameters.c0 == c0
19
+ assert model._parameters.a0 == a0
20
+ assert model._parameters.n == n
21
+
22
+
23
+ def test_invalid_parameters():
24
+ with raises(ValueError, match=escape("Entire releasable amount of drug (M) must be non-negative.")):
25
+ HopfenbergModel(M=-M, k0=k0, c0=c0, a0=a0, n=n).simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
26
+
27
+ with raises(ValueError, match=escape("Erosion rate constant (k0) must be non-negative")):
28
+ HopfenbergModel(M=M, k0=-k0, c0=c0, a0=a0, n=n).simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
29
+
30
+ with raises(ValueError, match=escape("Initial drug concentration (c0) must be positive.")):
31
+ HopfenbergModel(M=M, k0=k0, c0=-c0, a0=a0, n=n).simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
32
+
33
+ with raises(ValueError, match=escape("Initial radius or half-thickness (a0) must be positive.")):
34
+ HopfenbergModel(M=M, k0=k0, c0=c0, a0=-a0, n=n).simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
35
+
36
+ with raises(ValueError, match=escape("Geometry factor (n) must be 1 (slab), 2 (cylinder), or 3 (sphere).")):
37
+ HopfenbergModel(M=M, k0=k0, c0=c0, a0=a0, n=4).simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
38
+
39
+
40
+ def test_repr():
41
+ model = HopfenbergModel(M=M, k0=k0, c0=c0, a0=a0, n=n)
42
+ repr_str = repr(model)
43
+ assert repr_str == f"drux.HopfenbergModel(M={M}, k0={k0}, c0={c0}, a0={a0}, n={n})"
44
+
45
+
46
+ def test_hopfenberg_simulation(): # Reference: https://pmc.ncbi.nlm.nih.gov/articles/PMC3500559/
47
+ model = HopfenbergModel(M=M, k0=k0, c0=c0, a0=a0, n=n)
48
+ profile = model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
49
+
50
+ actual_release = [M * (1 - (1 - (k0 * t) / (c0 * a0))**n) for t in range(0, SIM_DURATION+SIM_TIME_STEP, SIM_TIME_STEP)]
51
+ assert all(isclose(p, r, rtol=RELATIVE_TOLERANCE) for p, r in zip(profile, actual_release))
52
+
53
+
54
+ def test_hopfenberg_simulation_errors():
55
+ model = HopfenbergModel(M=M, k0=k0, c0=c0, a0=a0, n=n)
56
+
57
+ with raises(ValueError, match="Duration and time step must be positive values"):
58
+ model.simulate(duration=-100, time_step=10)
59
+
60
+ with raises(ValueError, match="Duration and time step must be positive values"):
61
+ model.simulate(duration=100, time_step=-10)
62
+
63
+ with raises(ValueError, match="Time step cannot be greater than duration"):
64
+ model.simulate(duration=10, time_step=20)
65
+
66
+
67
+ def test_hopfenberg_plot1():
68
+ model = HopfenbergModel(M=M, k0=k0, c0=c0, a0=a0, n=n)
69
+ model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
70
+ fig, ax = model.plot()
71
+ assert fig is not None
72
+ assert ax is not None
73
+ assert ax.get_title() == model._plot_parameters["title"]
74
+ assert ax.get_xlabel() == model._plot_parameters["xlabel"]
75
+ assert ax.get_ylabel() == model._plot_parameters["ylabel"]
76
+ assert [text.get_text() for text in ax.get_legend().get_texts()] == [model._plot_parameters["label"]]
77
+
78
+
79
+ def test_hopfenberg_plot2():
80
+ model = HopfenbergModel(M=M, k0=k0, c0=c0, a0=a0, n=n)
81
+ model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
82
+ fig, ax = model.plot(title="test-title", xlabel="test-xlabel", ylabel="test-ylabel", label="test-label")
83
+ assert fig is not None
84
+ assert ax is not None
85
+ assert ax.get_title() == "test-title"
86
+ assert ax.get_xlabel() == "test-xlabel"
87
+ assert ax.get_ylabel() == "test-ylabel"
88
+ assert [text.get_text() for text in ax.get_legend().get_texts()] == ["test-label"]
89
+
90
+
91
+ def test_hopfenberg_plot_error():
92
+ model = HopfenbergModel(M=M, k0=k0, c0=c0, a0=a0, n=n)
93
+
94
+ with raises(ValueError, match=escape("No simulation data available. Run simulate() first.")):
95
+ model.plot()
96
+
97
+ model._time_points = [0] # manually set time points to simulate error (TODO: it will be caught with prior errors)
98
+ # manually set a too short profile to simulate error (TODO: it will be caught with prior errors)
99
+ model._release_profile = [0.0]
100
+ with raises(ValueError, match="Release profile is too short to calculate release rate."):
101
+ model.plot()
102
+
103
+
104
+ def test_hopfenberg_release_rate():
105
+ small_timestep = 0.001 # smaller time step for better accuracy in numerical derivative
106
+ small_duration = 10
107
+ model = HopfenbergModel(M=M, k0=k0, c0=c0, a0=a0, n=n)
108
+ model.simulate(duration=small_duration, time_step=small_timestep)
109
+ rate = model.get_release_rate().tolist()
110
+ import numpy as np
111
+ # Ref: https://www.wolframalpha.com/input?i=get+the+derivative+of+%28M+*+%281+-+%281+-+%28k0+*+t%29+%2F+%28c0+*+a0%29%29**n%29%29+with+respect+to+t
112
+ actual_rate = [
113
+ k0*M*n*((1-((k0*t)/(a0*c0)))**(n-1))/(a0*c0)
114
+ for t in np.arange(small_timestep, small_duration + small_timestep, small_timestep)
115
+ ] # avoid t=0 to prevent division by zero
116
+ assert all(isclose(r, ar, rtol=1e-1) for r, ar in zip(rate[2:], actual_rate[1:])) # skip first two points due to numerical derivative inaccuracies
117
+
118
+
119
+ def test_hopfenberg_release_rate_error():
120
+ model = HopfenbergModel(M=M, k0=k0, c0=c0, a0=a0, n=n)
121
+
122
+ with raises(ValueError, match=escape("No simulation data available. Run simulate() first.")):
123
+ model.get_release_rate()
124
+
125
+ model._time_points = [0] # manually set time points to simulate error (TODO: it will be caught with prior errors)
126
+ # manually set a too short profile to simulate error (TODO: it will be caught with prior errors)
127
+ model._release_profile = [0.0]
128
+ with raises(ValueError, match="Release profile is too short to calculate release rate."):
129
+ model.get_release_rate()
130
+
131
+
132
+ def test_hopfenberg_time_for_release():
133
+ model = HopfenbergModel(M=M, k0=k0, c0=c0, a0=a0, n=n)
134
+ model.simulate(duration=SIM_DURATION, time_step=1)
135
+ tx = model.time_for_release(0.8 * model._release_profile[-1])
136
+ # Ref: https://www.wolframalpha.com/input?i=solve+for+t+in+%281+-+%281+-+%280.00067*+t%29+%2F+%280.0374+*+3.51%29%29**2%29+%3D+0.8*0.7602750594732341
137
+ assert isclose(tx, 74, rtol=1e-2)
138
+
139
+
140
+ def test_hopfenberg_time_for_release_error():
141
+ model = HopfenbergModel(M=M, k0=k0, c0=c0, a0=a0, n=n)
142
+
143
+ with raises(ValueError, match=escape("No simulation data available. Run simulate() first.")):
144
+ model.time_for_release(0.5)
145
+ model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
146
+
147
+ with raises(ValueError, match="Target release must be non-negative."):
148
+ model.time_for_release(-0.1)
149
+
150
+ with raises(ValueError, match="Target release exceeds maximum release of the simulated duration."):
151
+ model.time_for_release(model._release_profile[-1] + 0.1)
@@ -0,0 +1,141 @@
1
+ """Tests for the Weibull model implementation in drux package."""
2
+
3
+ from pytest import raises
4
+ from numpy import isclose
5
+ from re import escape
6
+ from math import exp
7
+ from drux import WeibullModel
8
+
9
+ TEST_CASE_NAME = "Weibull model tests"
10
+ M, a, b = 1, 0.095, 0.7
11
+ SIM_DURATION, SIM_TIME_STEP = 100, 1
12
+ RELATIVE_TOLERANCE = 1e-1
13
+
14
+
15
+ def test_weibull_parameters():
16
+ model = WeibullModel(M=M, a=a, b=b)
17
+ assert model._parameters.M == M
18
+ assert model._parameters.a == a
19
+ assert model._parameters.b == b
20
+
21
+
22
+ def test_invalid_parameters():
23
+ with raises(ValueError, match=escape("Entire releasable amount of drug (M) must be non-negative.")):
24
+ WeibullModel(M=-M, a=a, b=b).simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
25
+
26
+ with raises(ValueError, match=escape("Scale parameter (a) must be positive.")):
27
+ WeibullModel(M=M, a=-a, b=b).simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
28
+
29
+ with raises(ValueError, match=escape("Shape parameter (b) must be positive.")):
30
+ WeibullModel(M=M, a=a, b=-b).simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
31
+
32
+
33
+ def test_repr():
34
+ model = WeibullModel(M=M, a=a, b=b)
35
+ repr_str = repr(model)
36
+ assert repr_str == f"drux.WeibullModel(M={M}, a={a}, b={b})"
37
+
38
+
39
+ def test_weibull_simulation(): # Reference: https://www.mdpi.com/2073-4360/13/17/2897
40
+ model = WeibullModel(M=M, a=a, b=b)
41
+ profile = model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
42
+ actual_release = [M * (1 - exp(-a * t ** b)) for t in range(0, SIM_DURATION+SIM_TIME_STEP, SIM_TIME_STEP)]
43
+ assert all(isclose(p, r, rtol=RELATIVE_TOLERANCE) for p, r in zip(profile, actual_release))
44
+
45
+
46
+ def test_weibull_simulation_errors():
47
+ model = WeibullModel(M=M, a=a, b=b)
48
+
49
+ with raises(ValueError, match="Duration and time step must be positive values"):
50
+ model.simulate(duration=-100, time_step=10)
51
+
52
+ with raises(ValueError, match="Duration and time step must be positive values"):
53
+ model.simulate(duration=100, time_step=-10)
54
+
55
+ with raises(ValueError, match="Time step cannot be greater than duration"):
56
+ model.simulate(duration=10, time_step=20)
57
+
58
+
59
+ def test_weibull_plot1():
60
+ model = WeibullModel(M=M, a=a, b=b)
61
+ model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
62
+ fig, ax = model.plot()
63
+ assert fig is not None
64
+ assert ax is not None
65
+ assert ax.get_title() == model._plot_parameters["title"]
66
+ assert ax.get_xlabel() == model._plot_parameters["xlabel"]
67
+ assert ax.get_ylabel() == model._plot_parameters["ylabel"]
68
+ assert [text.get_text() for text in ax.get_legend().get_texts()] == [model._plot_parameters["label"]]
69
+
70
+
71
+ def test_weibull_plot2():
72
+ model = WeibullModel(M=M, a=a, b=b)
73
+ model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
74
+ fig, ax = model.plot(title="test-title", xlabel="test-xlabel", ylabel="test-ylabel", label="test-label")
75
+ assert fig is not None
76
+ assert ax is not None
77
+ assert ax.get_title() == "test-title"
78
+ assert ax.get_xlabel() == "test-xlabel"
79
+ assert ax.get_ylabel() == "test-ylabel"
80
+ assert [text.get_text() for text in ax.get_legend().get_texts()] == ["test-label"]
81
+
82
+
83
+ def test_weibull_plot_error():
84
+ model = WeibullModel(M=M, a=a, b=b)
85
+
86
+ with raises(ValueError, match=escape("No simulation data available. Run simulate() first.")):
87
+ model.plot()
88
+
89
+ model._time_points = [0] # manually set time points to simulate error (TODO: it will be caught with prior errors)
90
+ # manually set a too short profile to simulate error (TODO: it will be caught with prior errors)
91
+ model._release_profile = [0.0]
92
+ with raises(ValueError, match="Release profile is too short to calculate release rate."):
93
+ model.plot()
94
+
95
+
96
+ def test_weibull_release_rate(): # Reference: https://www.wolframalpha.com/input?i=get+the+derivative+of+%28M+*+%281+-+exp%28-+%28%28t+%2F+r%29+**+beta%29%29%29%29+with+respect+to+t
97
+ small_timestep = 0.001 # smaller time step for better accuracy in numerical derivative
98
+ small_duration = 10
99
+ model = WeibullModel(M=M, a=a, b=b)
100
+ model.simulate(duration=small_duration, time_step=small_timestep)
101
+ rate = model.get_release_rate().tolist()
102
+ import numpy as np
103
+ actual_rate = [
104
+ (M*b*a) * t**(b - 1) * exp(-a * t**b)
105
+ for t in np.arange(small_timestep, small_duration + small_timestep, small_timestep)
106
+ ] # avoid t=0 to prevent division by zero
107
+ assert all(isclose(r, ar, rtol=1e-1) for r, ar in zip(rate[2:], actual_rate[1:])) # skip first two points due to numerical derivative inaccuracies
108
+
109
+
110
+ def test_weibull_release_rate_error():
111
+ model = WeibullModel(M=M, a=a, b=b)
112
+
113
+ with raises(ValueError, match=escape("No simulation data available. Run simulate() first.")):
114
+ model.get_release_rate()
115
+
116
+ model._time_points = [0] # manually set time points to simulate error (TODO: it will be caught with prior errors)
117
+ # manually set a too short profile to simulate error (TODO: it will be caught with prior errors)
118
+ model._release_profile = [0.0]
119
+ with raises(ValueError, match="Release profile is too short to calculate release rate."):
120
+ model.get_release_rate()
121
+
122
+
123
+ def test_weibull_time_for_release(): # Reference: https://www.wolframalpha.com/input?i=solve+for+t+in+%281+-+exp%28-0.095+*+t+**+0.7%29%29+%3D+0.8*0.908
124
+ model = WeibullModel(M=M, a=a, b=b)
125
+ model.simulate(duration=SIM_DURATION, time_step=1)
126
+ tx = model.time_for_release(0.8 * model._release_profile[-1])
127
+ assert isclose(tx, 42, rtol=1e-2)
128
+
129
+
130
+ def test_weibull_time_for_release_error():
131
+ model = WeibullModel(M=M, a=a, b=b)
132
+
133
+ with raises(ValueError, match=escape("No simulation data available. Run simulate() first.")):
134
+ model.time_for_release(0.5)
135
+ model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
136
+
137
+ with raises(ValueError, match="Target release must be non-negative."):
138
+ model.time_for_release(-0.1)
139
+
140
+ with raises(ValueError, match="Target release exceeds maximum release of the simulated duration."):
141
+ model.time_for_release(model._release_profile[-1] + 0.1)
@@ -26,6 +26,12 @@ def test_invalid_parameters():
26
26
  ZeroOrderModel(M0=M0, k0=-k0).simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
27
27
 
28
28
 
29
+ def test_repr():
30
+ model = ZeroOrderModel(M0=M0, k0=k0)
31
+ repr_str = repr(model)
32
+ assert repr_str == f"drux.ZeroOrderModel(k0={k0}, M0={M0})"
33
+
34
+
29
35
  def test_zero_order_simulation(): # Reference: https://europepmc.org/article/pmc/3425064
30
36
  model = ZeroOrderModel(M0=M0, k0=k0)
31
37
  profile = model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes