drux 0.1__tar.gz → 0.2__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.1
3
+ Version: 0.2
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.1
6
+ Download-URL: https://github.com/openscilab/drux/tarball/v0.2
7
7
  Author: Drux Development Team
8
8
  Author-email: drux@openscilab.com
9
9
  License: MIT
@@ -34,7 +34,7 @@ Requires-Python: >=3.7
34
34
  Description-Content-Type: text/markdown
35
35
  License-File: LICENSE
36
36
  License-File: AUTHORS.md
37
- Requires-Dist: numpy>=1.19.0
37
+ Requires-Dist: numpy>=1.21.0
38
38
  Requires-Dist: matplotlib>=3.2.2
39
39
  Dynamic: author
40
40
  Dynamic: author-email
@@ -57,7 +57,9 @@ Dynamic: summary
57
57
  <br/>
58
58
  <a href="https://badge.fury.io/py/drux"><img src="https://badge.fury.io/py/drux.svg" alt="PyPI version"></a>
59
59
  <a href="https://www.python.org/"><img src="https://img.shields.io/badge/built%20with-Python3-green.svg" alt="built with Python3"></a>
60
+ <a href="https://codecov.io/gh/openscilab/drux"><img src="https://codecov.io/gh/openscilab/drux/branch/dev/graph/badge.svg?token=5O41J3XX2L"></a>
60
61
  <a href="https://github.com/openscilab/drux"><img alt="GitHub repo size" src="https://img.shields.io/github/repo-size/openscilab/drux"></a>
62
+ <a href="https://discord.gg/8Rf6bGBtse"><img src="https://img.shields.io/discord/1064533716615049236.svg" alt="Discord Channel"></a>
61
63
  </div>
62
64
 
63
65
  ----------
@@ -101,18 +103,62 @@ Drux is a Python-based framework for simulating drug release profiles using math
101
103
  </td>
102
104
  </tr>
103
105
  </table>
106
+ <table>
107
+ <tr>
108
+ <td align="center">Code Quality</td>
109
+ <td align="center"><a href="https://www.codefactor.io/repository/github/openscilab/drux"><img src="https://www.codefactor.io/repository/github/openscilab/drux/badge" alt="CodeFactor"></a></td>
110
+ <td align="center"><a href="https://app.codacy.com/gh/openscilab/drux/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade"><img src="https://app.codacy.com/project/badge/Grade/06ed95529d284c81a846205baa1f4c6a"></a></td>
111
+ </tr>
112
+ </table>
104
113
 
105
114
 
106
115
  ## Installation
107
116
 
108
117
  ### PyPI
109
118
  - Check [Python Packaging User Guide](https://packaging.python.org/installing/)
110
- - Run `pip install drux==0.1`
119
+ - Run `pip install drux==0.2`
111
120
  ### Source code
112
- - Download [Version 0.1](https://github.com/openscilab/drux/archive/v0.1.zip) or [Latest Source](https://github.com/openscilab/drux/archive/dev.zip)
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)
113
122
  - Run `pip install .`
114
123
 
115
124
  ## Supported Models
125
+ ### Zero-Order
126
+ The Zero-Order model describes a constant rate of drug release over time. According to this model, the cumulative amount of drug released at time $t$ is given by:
127
+
128
+ $$
129
+ M_t = M_0 + k_0 t
130
+ $$
131
+
132
+ where:
133
+ - $M_t (mg)$ is the cumulative absolute amount of drug released at time $t$.
134
+ - $M_0 (mg)$ is the initial amount of drug in the system. $M_0$ defaults to zero in this model.
135
+ - $k_0 (\frac{mg}{s})$ is the zero-order release rate constant.
136
+
137
+ #### Applications
138
+ 1. Tablets with extended release
139
+ 2. Transdermal Patches
140
+ 3. Implantable Device
141
+ 4. Intraocular Implants
142
+ 5. Infusion Systems
143
+
144
+ ### First-Order
145
+ The first-order drug release model describes a process where the rate of drug release is proportional to the remaining amount of drug in the system. According to this model, the cumulative amount of drug released at time $t$ is given by:
146
+
147
+ $$
148
+ M_t = M_0 (1 - e^{-kt})
149
+ $$
150
+
151
+ where:
152
+ - $M_t (mg)$ is the cumulative absolute amount of drug released at time $t$.
153
+ - $M_0 (mg)$ is entire releasable amount of drug (the asymptotic maximum).
154
+ - $k (\frac{1}{s})$ is the first-order release rate constant.
155
+
156
+ #### Applications
157
+ 1. Immediate-release tablets and capsules
158
+ 2. Liquid drug formulations (oral solutions, intravenous injections)
159
+ 3. Controlled-release matrix systems
160
+ 4. Elastomeric infusion pumps
161
+
116
162
  ### Higuchi
117
163
  The Higuchi model describes the release of a drug from a matrix system, where the drug diffuses through a porous medium.
118
164
  The Higuchi equation addressed important aspects of drug transport and release from planar
@@ -137,6 +183,24 @@ where:
137
183
  5. Implantable Drug delivery systems
138
184
 
139
185
  ## Usage
186
+ ### Zero-Order Model
187
+ ```python
188
+ from drux import ZeroOrderModel
189
+ model = ZeroOrderModel(k0=0.1, M0=0)
190
+ model.simulate(duration=1000, time_step=10)
191
+ model.plot(show=True)
192
+ ```
193
+ <img src="https://github.com/openscilab/drux/raw/main/otherfiles/zero_order_plot.png" alt="Zero-order Plot">
194
+
195
+ ### First-Order Model
196
+ ```python
197
+ from drux import FirstOrderModel
198
+ model = FirstOrderModel(k=0.003, M0=0.1)
199
+ model.simulate(duration=1000, time_step=10)
200
+ model.plot(show=True)
201
+ ```
202
+ <img src="https://github.com/openscilab/drux/raw/main/otherfiles/first_order_plot.png" alt="First-order Plot">
203
+
140
204
  ### Higuchi Model
141
205
  ```python
142
206
  from drux import HiguchiModel
@@ -152,10 +216,20 @@ Just fill an issue and describe it. We'll check it ASAP! or send an email to [dr
152
216
 
153
217
  - Please complete the issue template
154
218
 
219
+ You can also join our discord server
220
+
221
+ <a href="https://discord.gg/8Rf6bGBtse">
222
+ <img src="https://img.shields.io/discord/1064533716615049236.svg?style=for-the-badge" alt="Discord Channel">
223
+ </a>
224
+
225
+
155
226
  ## References
156
227
  <blockquote>1- T. Higuchi, "Rate of release of medicaments from ointment bases containing drugs in suspension," <i>Journal of Pharmaceutical Sciences</i>, vol. 50, no. 10, pp. 874–875, 1961.</blockquote>
157
228
  <blockquote>2- D. R. Paul, "Elaborations on the Higuchi model for drug delivery," <i>International Journal of Pharmaceutics</i>, vol. 418, no. 1, pp. 13–17, 2011.</blockquote>
158
229
  <blockquote>3- R. T. Medarametla, K. V. Gopaiah, J. N. Suresh Kumar, G. Anand Babu, M. Shaggir, G. Raghavendra, D. Naveen Reddy, and B. Venkamma, "Drug Release Kinetics and Mathematical Models," <i>International Journal of Science and Research Methodology</i>, vol. 27, no. 9, pp. 12–19, Sep. 2024.</blockquote>
230
+ <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
+ <blockquote>5- S. Dash, "Kinetic modeling on drug release from controlled drug delivery systems," <i>Acta Poloniae Pharmaceutica</i>, 2010.</blockquote>
232
+ <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>
159
233
 
160
234
  ## Show your support
161
235
  ### Star this repo
@@ -174,11 +248,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
174
248
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
175
249
 
176
250
  ## [Unreleased]
251
+ ## [0.2] - 2025-09-27
252
+ ### Added
253
+ - Zero-order model
254
+ - First-order model
255
+ ### Changed
256
+ - `README.md` modified
257
+ - Test system modified
258
+ - Release range bug in `time_for_release` fixed
259
+ - `matplotlib` import bug fixed
260
+ - `plot` method modified
177
261
  ## [0.1] - 2025-07-27
178
262
  ### Added
179
263
  - Base model
180
264
  - Higuchi model
181
265
 
182
266
 
183
- [Unreleased]: https://github.com/openscilab/drux/compare/v0.1...dev
267
+ [Unreleased]: https://github.com/openscilab/drux/compare/v0.2...dev
268
+ [0.2]: https://github.com/openscilab/drux/compare/v0.1...v0.2
184
269
  [0.1]: https://github.com/openscilab/drux/compare/48548f0...v0.1
@@ -3,7 +3,9 @@
3
3
  <br/>
4
4
  <a href="https://badge.fury.io/py/drux"><img src="https://badge.fury.io/py/drux.svg" alt="PyPI version"></a>
5
5
  <a href="https://www.python.org/"><img src="https://img.shields.io/badge/built%20with-Python3-green.svg" alt="built with Python3"></a>
6
+ <a href="https://codecov.io/gh/openscilab/drux"><img src="https://codecov.io/gh/openscilab/drux/branch/dev/graph/badge.svg?token=5O41J3XX2L"></a>
6
7
  <a href="https://github.com/openscilab/drux"><img alt="GitHub repo size" src="https://img.shields.io/github/repo-size/openscilab/drux"></a>
8
+ <a href="https://discord.gg/8Rf6bGBtse"><img src="https://img.shields.io/discord/1064533716615049236.svg" alt="Discord Channel"></a>
7
9
  </div>
8
10
 
9
11
  ----------
@@ -47,18 +49,62 @@ Drux is a Python-based framework for simulating drug release profiles using math
47
49
  </td>
48
50
  </tr>
49
51
  </table>
52
+ <table>
53
+ <tr>
54
+ <td align="center">Code Quality</td>
55
+ <td align="center"><a href="https://www.codefactor.io/repository/github/openscilab/drux"><img src="https://www.codefactor.io/repository/github/openscilab/drux/badge" alt="CodeFactor"></a></td>
56
+ <td align="center"><a href="https://app.codacy.com/gh/openscilab/drux/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade"><img src="https://app.codacy.com/project/badge/Grade/06ed95529d284c81a846205baa1f4c6a"></a></td>
57
+ </tr>
58
+ </table>
50
59
 
51
60
 
52
61
  ## Installation
53
62
 
54
63
  ### PyPI
55
64
  - Check [Python Packaging User Guide](https://packaging.python.org/installing/)
56
- - Run `pip install drux==0.1`
65
+ - Run `pip install drux==0.2`
57
66
  ### Source code
58
- - Download [Version 0.1](https://github.com/openscilab/drux/archive/v0.1.zip) or [Latest Source](https://github.com/openscilab/drux/archive/dev.zip)
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)
59
68
  - Run `pip install .`
60
69
 
61
70
  ## Supported Models
71
+ ### Zero-Order
72
+ The Zero-Order model describes a constant rate of drug release over time. According to this model, the cumulative amount of drug released at time $t$ is given by:
73
+
74
+ $$
75
+ M_t = M_0 + k_0 t
76
+ $$
77
+
78
+ where:
79
+ - $M_t (mg)$ is the cumulative absolute amount of drug released at time $t$.
80
+ - $M_0 (mg)$ is the initial amount of drug in the system. $M_0$ defaults to zero in this model.
81
+ - $k_0 (\frac{mg}{s})$ is the zero-order release rate constant.
82
+
83
+ #### Applications
84
+ 1. Tablets with extended release
85
+ 2. Transdermal Patches
86
+ 3. Implantable Device
87
+ 4. Intraocular Implants
88
+ 5. Infusion Systems
89
+
90
+ ### First-Order
91
+ The first-order drug release model describes a process where the rate of drug release is proportional to the remaining amount of drug in the system. According to this model, the cumulative amount of drug released at time $t$ is given by:
92
+
93
+ $$
94
+ M_t = M_0 (1 - e^{-kt})
95
+ $$
96
+
97
+ where:
98
+ - $M_t (mg)$ is the cumulative absolute amount of drug released at time $t$.
99
+ - $M_0 (mg)$ is entire releasable amount of drug (the asymptotic maximum).
100
+ - $k (\frac{1}{s})$ is the first-order release rate constant.
101
+
102
+ #### Applications
103
+ 1. Immediate-release tablets and capsules
104
+ 2. Liquid drug formulations (oral solutions, intravenous injections)
105
+ 3. Controlled-release matrix systems
106
+ 4. Elastomeric infusion pumps
107
+
62
108
  ### Higuchi
63
109
  The Higuchi model describes the release of a drug from a matrix system, where the drug diffuses through a porous medium.
64
110
  The Higuchi equation addressed important aspects of drug transport and release from planar
@@ -83,6 +129,24 @@ where:
83
129
  5. Implantable Drug delivery systems
84
130
 
85
131
  ## Usage
132
+ ### Zero-Order Model
133
+ ```python
134
+ from drux import ZeroOrderModel
135
+ model = ZeroOrderModel(k0=0.1, M0=0)
136
+ model.simulate(duration=1000, time_step=10)
137
+ model.plot(show=True)
138
+ ```
139
+ <img src="https://github.com/openscilab/drux/raw/main/otherfiles/zero_order_plot.png" alt="Zero-order Plot">
140
+
141
+ ### First-Order Model
142
+ ```python
143
+ from drux import FirstOrderModel
144
+ model = FirstOrderModel(k=0.003, M0=0.1)
145
+ model.simulate(duration=1000, time_step=10)
146
+ model.plot(show=True)
147
+ ```
148
+ <img src="https://github.com/openscilab/drux/raw/main/otherfiles/first_order_plot.png" alt="First-order Plot">
149
+
86
150
  ### Higuchi Model
87
151
  ```python
88
152
  from drux import HiguchiModel
@@ -98,10 +162,20 @@ Just fill an issue and describe it. We'll check it ASAP! or send an email to [dr
98
162
 
99
163
  - Please complete the issue template
100
164
 
165
+ You can also join our discord server
166
+
167
+ <a href="https://discord.gg/8Rf6bGBtse">
168
+ <img src="https://img.shields.io/discord/1064533716615049236.svg?style=for-the-badge" alt="Discord Channel">
169
+ </a>
170
+
171
+
101
172
  ## References
102
173
  <blockquote>1- T. Higuchi, "Rate of release of medicaments from ointment bases containing drugs in suspension," <i>Journal of Pharmaceutical Sciences</i>, vol. 50, no. 10, pp. 874–875, 1961.</blockquote>
103
174
  <blockquote>2- D. R. Paul, "Elaborations on the Higuchi model for drug delivery," <i>International Journal of Pharmaceutics</i>, vol. 418, no. 1, pp. 13–17, 2011.</blockquote>
104
175
  <blockquote>3- R. T. Medarametla, K. V. Gopaiah, J. N. Suresh Kumar, G. Anand Babu, M. Shaggir, G. Raghavendra, D. Naveen Reddy, and B. Venkamma, "Drug Release Kinetics and Mathematical Models," <i>International Journal of Science and Research Methodology</i>, vol. 27, no. 9, pp. 12–19, Sep. 2024.</blockquote>
176
+ <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
+ <blockquote>5- S. Dash, "Kinetic modeling on drug release from controlled drug delivery systems," <i>Acta Poloniae Pharmaceutica</i>, 2010.</blockquote>
178
+ <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>
105
179
 
106
180
  ## Show your support
107
181
  ### Star this repo
@@ -3,5 +3,7 @@
3
3
 
4
4
  from .params import DRUX_VERSION
5
5
  from .higuchi import HiguchiModel, HiguchiParameters
6
+ from .zero_order import ZeroOrderModel, ZeroOrderParameters
7
+ from .first_order import FirstOrderModel, FirstOrderParameters
6
8
 
7
9
  __version__ = DRUX_VERSION
@@ -1,8 +1,9 @@
1
1
  """This file contains the abstract base class for drug release models."""
2
2
 
3
3
  import numpy as np
4
+ import matplotlib.pyplot as plt
4
5
  from abc import ABC, abstractmethod
5
- from typing import Any
6
+ from typing import Any, Optional
6
7
 
7
8
  from .messages import (
8
9
  ERROR_TARGET_RELEASE_RANGE,
@@ -11,7 +12,6 @@ from .messages import (
11
12
  ERROR_NO_SIMULATION_DATA,
12
13
  ERROR_RELEASE_PROFILE_TOO_SHORT,
13
14
  ERROR_TARGET_RELEASE_EXCEEDS_MAX,
14
- MATPLOT_IMPORT_ERROR,
15
15
  )
16
16
 
17
17
 
@@ -29,8 +29,13 @@ class DrugReleaseModel(ABC):
29
29
 
30
30
  def __init__(self):
31
31
  """Initialize the drug release model."""
32
- self.time_points = None
33
- self.release_profile = None
32
+ self._time_points = None
33
+ self._release_profile = None
34
+ self._plot_parameters = {
35
+ "xlabel": "Time (s)",
36
+ "ylabel": "Cumulative Release",
37
+ "title": "Drug Release Profile",
38
+ "label": "Release Profile"}
34
39
 
35
40
  @abstractmethod
36
41
  def _validate_parameters(self) -> None:
@@ -52,25 +57,19 @@ class DrugReleaseModel(ABC):
52
57
 
53
58
  def _get_release_profile(self) -> np.ndarray:
54
59
  """Calculate the drug release profile over the specified time points."""
55
- return np.vectorize(self._model_function)(self.time_points)
60
+ return np.vectorize(self._model_function)(self._time_points)
56
61
 
57
62
  def _validate_plot(self) -> tuple:
58
63
  """
59
64
  Validate plotting process.
60
65
 
61
- :raises ImportError: if matplotlib is not installed
62
66
  :raises ValueError: if simulation data is not available
63
67
  :raises ValueError: if release profile is too short
64
68
  """
65
- try:
66
- import matplotlib.pyplot as plt
67
- except ImportError:
68
- raise ImportError(MATPLOT_IMPORT_ERROR)
69
-
70
- if self.time_points is None or self.release_profile is None:
69
+ if self._time_points is None or self._release_profile is None:
71
70
  raise ValueError(ERROR_NO_SIMULATION_DATA)
72
71
 
73
- if len(self.release_profile) < 2:
72
+ if len(self._release_profile) < 2:
74
73
  raise ValueError(ERROR_RELEASE_PROFILE_TOO_SHORT)
75
74
  fig, ax = plt.subplots()
76
75
  return fig, ax
@@ -86,27 +85,38 @@ class DrugReleaseModel(ABC):
86
85
  raise ValueError(ERROR_DURATION_TIME_STEP_POSITIVE)
87
86
  if time_step > duration:
88
87
  raise ValueError(ERROR_TIME_STEP_GREATER_THAN_DURATION)
89
- self.time_points = np.arange(0, duration + time_step, time_step)
88
+ self._time_points = np.arange(0, duration + time_step, time_step)
90
89
  self._validate_parameters()
91
- self.release_profile = self._get_release_profile()
92
- return self.release_profile
93
-
94
- def plot(self, show: bool = True, **kwargs: Any) -> tuple:
90
+ self._release_profile = self._get_release_profile()
91
+ return self._release_profile
92
+
93
+ def plot(
94
+ self,
95
+ show: bool = True,
96
+ label: Optional[str] = None,
97
+ xlabel: Optional[str] = None,
98
+ ylabel: Optional[str] = None,
99
+ title: Optional[str] = None,
100
+ **kwargs: Any) -> tuple:
95
101
  """
96
102
  Plot the drug release profile.
97
103
 
98
104
  :param show: Whether to display the plot (default: True)
105
+ :param label: The legend label for the release profile curve
106
+ :param xlabel: Label for the x-axis
107
+ :param ylabel: Label for the y-axis
108
+ :param title: Title of the plot
99
109
  """
100
110
  # Create a new figure and axis if not provided
101
111
  fig, ax = self._validate_plot()
102
112
 
103
113
  # Plotting the release profile
104
114
  ax.plot(
105
- self.time_points, self.release_profile, label="Release Profile", **kwargs
115
+ self._time_points, self._release_profile, label=label or self._plot_parameters["label"], **kwargs
106
116
  )
107
- ax.set_xlabel("Time (s)")
108
- ax.set_ylabel("Cumulative Release")
109
- ax.set_title("Drug Release Profile")
117
+ ax.set_xlabel(xlabel or self._plot_parameters["xlabel"])
118
+ ax.set_ylabel(ylabel or self._plot_parameters["ylabel"])
119
+ ax.set_title(title or self._plot_parameters["title"])
110
120
  ax.grid()
111
121
  ax.legend()
112
122
 
@@ -118,35 +128,35 @@ class DrugReleaseModel(ABC):
118
128
 
119
129
  def get_release_rate(self) -> np.ndarray:
120
130
  """Calculate the instantaneous release rate (derivative of release profile)."""
121
- if self.time_points is None or self.release_profile is None:
131
+ if self._time_points is None or self._release_profile is None:
122
132
  raise ValueError(ERROR_NO_SIMULATION_DATA)
123
133
 
124
- if len(self.release_profile) < 2:
134
+ if len(self._release_profile) < 2:
125
135
  raise ValueError(ERROR_RELEASE_PROFILE_TOO_SHORT)
126
136
 
127
137
  # Calculate the derivative of the release profile
128
- release_rate = np.gradient(self.release_profile, self.time_points)
138
+ release_rate = np.gradient(self._release_profile, self._time_points)
129
139
  return release_rate
130
140
 
131
141
  def time_for_release(self, target_release: float) -> float:
132
142
  """
133
143
  Estimate time needed to reach a specific release percentage.
134
144
 
135
- :param target_release: target release fraction (0-1)
145
+ :param target_release: target release fraction (>= 0)
136
146
 
137
- :raises ValueError: if target_release is not between 0 and 1
147
+ :raises ValueError: if target_release is negative
138
148
  :raises ValueError: if simulation data is not available
139
149
  :raises ValueError: if target_release exceeds maximum release
140
150
  """
141
- if self.time_points is None or self.release_profile is None:
151
+ if self._time_points is None or self._release_profile is None:
142
152
  raise ValueError(ERROR_NO_SIMULATION_DATA)
143
153
 
144
- if target_release < 0 or target_release > 1:
154
+ if target_release < 0:
145
155
  raise ValueError(ERROR_TARGET_RELEASE_RANGE)
146
156
 
147
- if target_release > self.release_profile[-1]:
157
+ if target_release > self._release_profile[-1]:
148
158
  raise ValueError(ERROR_TARGET_RELEASE_EXCEEDS_MAX)
149
159
 
150
160
  # Find first time point where release >= target
151
- idx = np.argmax(self.release_profile >= target_release)
152
- return self.time_points[idx]
161
+ idx = np.argmax(self._release_profile >= target_release)
162
+ return self._time_points[idx]
@@ -0,0 +1,57 @@
1
+ # -*- coding: utf-8 -*-
2
+ """Drux first-order model implementation."""
3
+ from math import exp
4
+ from .base_model import DrugReleaseModel
5
+ from .messages import ERROR_FIRST_ORDER_INITIAL_AMOUNT, ERROR_FIRST_ORDER_RELEASE_RATE
6
+ from dataclasses import dataclass
7
+
8
+
9
+ @dataclass
10
+ class FirstOrderParameters:
11
+ """
12
+ Parameters for the first-order model.
13
+
14
+ Attributes:
15
+ M0 (float): entire releasable amount of drug (normally M0 > 0) (mg)
16
+ k (float): first-order release rate constant (1/s)
17
+ """
18
+
19
+ M0: float
20
+ k: float
21
+
22
+
23
+ class FirstOrderModel(DrugReleaseModel):
24
+ """Simulator for the first-order drug release model."""
25
+
26
+ def __init__(self, k: float, M0: float) -> None:
27
+ """
28
+ Initialize the first-order model with the given parameters.
29
+
30
+ :param k: first-order release rate constant (1/s)
31
+ :param M0: entire releasable amount of drug (the asymptotic maximum) (mg)
32
+ """
33
+ super().__init__()
34
+ self._parameters = FirstOrderParameters(k=k, M0=M0)
35
+ self._plot_parameters["label"] = "First-Order Model"
36
+
37
+ def _model_function(self, t: float) -> float:
38
+ """
39
+ Calculate the drug release at time t using the first-order model.
40
+
41
+ Formula:
42
+ - M(t) = M0 * (1 - exp(-k * t))
43
+ :param t: time (s)
44
+ """
45
+ M0 = self._parameters.M0
46
+ k = self._parameters.k
47
+
48
+ Mt = M0 * (1 - exp(-k * t))
49
+
50
+ return Mt
51
+
52
+ def _validate_parameters(self) -> None:
53
+ """Validate the parameters of the first-order model."""
54
+ if self._parameters.M0 < 0:
55
+ raise ValueError(ERROR_FIRST_ORDER_INITIAL_AMOUNT)
56
+ if self._parameters.k < 0:
57
+ raise ValueError(ERROR_FIRST_ORDER_RELEASE_RATE)
@@ -40,7 +40,8 @@ class HiguchiModel(DrugReleaseModel):
40
40
  :param cs: Drug solubility in the polymer (mg/cm^3)
41
41
  """
42
42
  super().__init__()
43
- self.params = HiguchiParameters(D=D, c0=c0, cs=cs)
43
+ self._parameters = HiguchiParameters(D=D, c0=c0, cs=cs)
44
+ self._plot_parameters["label"] = "Higuchi Model"
44
45
 
45
46
  def _model_function(self, t: float) -> float:
46
47
  """
@@ -50,9 +51,9 @@ class HiguchiModel(DrugReleaseModel):
50
51
  - General case: Mt = sqrt(D * c0 * (2*c0 - cs) * cs * t)
51
52
  :param t: time (s)
52
53
  """
53
- D = self.params.D
54
- c0 = self.params.c0
55
- cs = self.params.cs
54
+ D = self._parameters.D
55
+ c0 = self._parameters.c0
56
+ cs = self._parameters.cs
56
57
 
57
58
  Mt = sqrt(D * (2 * c0 - cs) * cs * t)
58
59
 
@@ -60,11 +61,11 @@ class HiguchiModel(DrugReleaseModel):
60
61
 
61
62
  def _validate_parameters(self) -> None:
62
63
  """Validate the parameters of the Higuchi model."""
63
- if self.params.D <= 0:
64
+ if self._parameters.D <= 0:
64
65
  raise ValueError(ERROR_INVALID_DIFFUSION)
65
- if self.params.c0 <= 0:
66
+ if self._parameters.c0 <= 0:
66
67
  raise ValueError(ERROR_INVALID_CONCENTRATION)
67
- if self.params.cs <= 0:
68
+ if self._parameters.cs <= 0:
68
69
  raise ValueError(ERROR_INVALID_SOLUBILITY)
69
- if self.params.cs > self.params.c0:
70
+ if self._parameters.cs > self._parameters.c0:
70
71
  raise ValueError(ERROR_SOLUBILITY_HIGHER_THAN_CONCENTRATION)
@@ -8,14 +8,27 @@ ERROR_NO_SIMULATION_DATA = "No simulation data available. Run simulate() first."
8
8
  ERROR_RELEASE_PROFILE_TOO_SHORT = (
9
9
  "Release profile is too short to calculate release rate."
10
10
  )
11
- ERROR_TARGET_RELEASE_RANGE = "Target release must be between 0 and 1."
11
+ ERROR_TARGET_RELEASE_RANGE = "Target release must be non-negative."
12
12
  ERROR_TARGET_RELEASE_EXCEEDS_MAX = (
13
13
  "Target release exceeds maximum release of the simulated duration."
14
14
  )
15
- MATPLOT_IMPORT_ERROR = "Matplotlib is required for plotting but not installed."
16
15
 
17
16
  # Error messages for Higuchi
18
17
  ERROR_INVALID_DIFFUSION = "Diffusivity (D) must be positive."
19
18
  ERROR_INVALID_CONCENTRATION = "Initial drug concentration (c0) must be positive."
20
19
  ERROR_INVALID_SOLUBILITY = "Solubility (cs) must be positive."
21
- ERROR_SOLUBILITY_HIGHER_THAN_CONCENTRATION = "Solubility (cs) must be lower or equal to initial concentration (c0)."
20
+ ERROR_SOLUBILITY_HIGHER_THAN_CONCENTRATION = (
21
+ "Solubility (cs) must be lower or equal to initial concentration (c0)."
22
+ )
23
+
24
+ # Error messages for zero-order
25
+ ERROR_ZERO_ORDER_RELEASE_RATE = "Release rate (k0) must be non-negative."
26
+ ERROR_ZERO_ORDER_INITIAL_AMOUNT = (
27
+ "Initial amount of drug in the solution (M0) must be non-negative."
28
+ )
29
+
30
+ # Error messages for first-order
31
+ ERROR_FIRST_ORDER_RELEASE_RATE = "Release rate (k) must be non-negative."
32
+ ERROR_FIRST_ORDER_INITIAL_AMOUNT = (
33
+ "Entire releasable amount of drug (M0) must be non-negative."
34
+ )
@@ -1,4 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  """Drux parameters and constants."""
3
3
 
4
- DRUX_VERSION = "0.1"
4
+ DRUX_VERSION = "0.2"
@@ -0,0 +1,57 @@
1
+ # -*- coding: utf-8 -*-
2
+ """Drux zero-order model implementation."""
3
+
4
+ from .base_model import DrugReleaseModel
5
+ from .messages import ERROR_ZERO_ORDER_RELEASE_RATE, ERROR_ZERO_ORDER_INITIAL_AMOUNT
6
+ from dataclasses import dataclass
7
+
8
+
9
+ @dataclass
10
+ class ZeroOrderParameters:
11
+ """
12
+ Parameters for the Zero-order model.
13
+
14
+ Attributes:
15
+ M0 (float): initial amount of drug in the solution (most times, M0 = 0)
16
+ k0 (float): zero-order release rate constant (mg/s)
17
+ """
18
+
19
+ M0: float
20
+ k0: float
21
+
22
+
23
+ class ZeroOrderModel(DrugReleaseModel):
24
+ """Simulator for the Zero-order drug release model."""
25
+
26
+ def __init__(self, k0: float, M0: float = 0) -> None:
27
+ """
28
+ Initialize the zero-order model with the given parameters.
29
+
30
+ :param k0: Zero-order release rate constant (mg/s)
31
+ :param M0: Initial amount of drug in the solution (mg), default is 0
32
+ """
33
+ super().__init__()
34
+ self._parameters = ZeroOrderParameters(k0=k0, M0=M0)
35
+ self._plot_parameters["label"] = "Zero-Order Model"
36
+
37
+ def _model_function(self, t: float) -> float:
38
+ """
39
+ Calculate the drug release at time t using the zero-order model.
40
+
41
+ Formula:
42
+ - M(t) = M0 + k0 * t
43
+ :param t: time (s)
44
+ """
45
+ M0 = self._parameters.M0
46
+ k0 = self._parameters.k0
47
+
48
+ Mt = M0 + k0 * t
49
+
50
+ return Mt
51
+
52
+ def _validate_parameters(self) -> None:
53
+ """Validate the parameters of the zero-order model."""
54
+ if self._parameters.M0 < 0:
55
+ raise ValueError(ERROR_ZERO_ORDER_INITIAL_AMOUNT)
56
+ if self._parameters.k0 < 0:
57
+ raise ValueError(ERROR_ZERO_ORDER_RELEASE_RATE)
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: drux
3
- Version: 0.1
3
+ Version: 0.2
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.1
6
+ Download-URL: https://github.com/openscilab/drux/tarball/v0.2
7
7
  Author: Drux Development Team
8
8
  Author-email: drux@openscilab.com
9
9
  License: MIT
@@ -34,7 +34,7 @@ Requires-Python: >=3.7
34
34
  Description-Content-Type: text/markdown
35
35
  License-File: LICENSE
36
36
  License-File: AUTHORS.md
37
- Requires-Dist: numpy>=1.19.0
37
+ Requires-Dist: numpy>=1.21.0
38
38
  Requires-Dist: matplotlib>=3.2.2
39
39
  Dynamic: author
40
40
  Dynamic: author-email
@@ -57,7 +57,9 @@ Dynamic: summary
57
57
  <br/>
58
58
  <a href="https://badge.fury.io/py/drux"><img src="https://badge.fury.io/py/drux.svg" alt="PyPI version"></a>
59
59
  <a href="https://www.python.org/"><img src="https://img.shields.io/badge/built%20with-Python3-green.svg" alt="built with Python3"></a>
60
+ <a href="https://codecov.io/gh/openscilab/drux"><img src="https://codecov.io/gh/openscilab/drux/branch/dev/graph/badge.svg?token=5O41J3XX2L"></a>
60
61
  <a href="https://github.com/openscilab/drux"><img alt="GitHub repo size" src="https://img.shields.io/github/repo-size/openscilab/drux"></a>
62
+ <a href="https://discord.gg/8Rf6bGBtse"><img src="https://img.shields.io/discord/1064533716615049236.svg" alt="Discord Channel"></a>
61
63
  </div>
62
64
 
63
65
  ----------
@@ -101,18 +103,62 @@ Drux is a Python-based framework for simulating drug release profiles using math
101
103
  </td>
102
104
  </tr>
103
105
  </table>
106
+ <table>
107
+ <tr>
108
+ <td align="center">Code Quality</td>
109
+ <td align="center"><a href="https://www.codefactor.io/repository/github/openscilab/drux"><img src="https://www.codefactor.io/repository/github/openscilab/drux/badge" alt="CodeFactor"></a></td>
110
+ <td align="center"><a href="https://app.codacy.com/gh/openscilab/drux/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade"><img src="https://app.codacy.com/project/badge/Grade/06ed95529d284c81a846205baa1f4c6a"></a></td>
111
+ </tr>
112
+ </table>
104
113
 
105
114
 
106
115
  ## Installation
107
116
 
108
117
  ### PyPI
109
118
  - Check [Python Packaging User Guide](https://packaging.python.org/installing/)
110
- - Run `pip install drux==0.1`
119
+ - Run `pip install drux==0.2`
111
120
  ### Source code
112
- - Download [Version 0.1](https://github.com/openscilab/drux/archive/v0.1.zip) or [Latest Source](https://github.com/openscilab/drux/archive/dev.zip)
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)
113
122
  - Run `pip install .`
114
123
 
115
124
  ## Supported Models
125
+ ### Zero-Order
126
+ The Zero-Order model describes a constant rate of drug release over time. According to this model, the cumulative amount of drug released at time $t$ is given by:
127
+
128
+ $$
129
+ M_t = M_0 + k_0 t
130
+ $$
131
+
132
+ where:
133
+ - $M_t (mg)$ is the cumulative absolute amount of drug released at time $t$.
134
+ - $M_0 (mg)$ is the initial amount of drug in the system. $M_0$ defaults to zero in this model.
135
+ - $k_0 (\frac{mg}{s})$ is the zero-order release rate constant.
136
+
137
+ #### Applications
138
+ 1. Tablets with extended release
139
+ 2. Transdermal Patches
140
+ 3. Implantable Device
141
+ 4. Intraocular Implants
142
+ 5. Infusion Systems
143
+
144
+ ### First-Order
145
+ The first-order drug release model describes a process where the rate of drug release is proportional to the remaining amount of drug in the system. According to this model, the cumulative amount of drug released at time $t$ is given by:
146
+
147
+ $$
148
+ M_t = M_0 (1 - e^{-kt})
149
+ $$
150
+
151
+ where:
152
+ - $M_t (mg)$ is the cumulative absolute amount of drug released at time $t$.
153
+ - $M_0 (mg)$ is entire releasable amount of drug (the asymptotic maximum).
154
+ - $k (\frac{1}{s})$ is the first-order release rate constant.
155
+
156
+ #### Applications
157
+ 1. Immediate-release tablets and capsules
158
+ 2. Liquid drug formulations (oral solutions, intravenous injections)
159
+ 3. Controlled-release matrix systems
160
+ 4. Elastomeric infusion pumps
161
+
116
162
  ### Higuchi
117
163
  The Higuchi model describes the release of a drug from a matrix system, where the drug diffuses through a porous medium.
118
164
  The Higuchi equation addressed important aspects of drug transport and release from planar
@@ -137,6 +183,24 @@ where:
137
183
  5. Implantable Drug delivery systems
138
184
 
139
185
  ## Usage
186
+ ### Zero-Order Model
187
+ ```python
188
+ from drux import ZeroOrderModel
189
+ model = ZeroOrderModel(k0=0.1, M0=0)
190
+ model.simulate(duration=1000, time_step=10)
191
+ model.plot(show=True)
192
+ ```
193
+ <img src="https://github.com/openscilab/drux/raw/main/otherfiles/zero_order_plot.png" alt="Zero-order Plot">
194
+
195
+ ### First-Order Model
196
+ ```python
197
+ from drux import FirstOrderModel
198
+ model = FirstOrderModel(k=0.003, M0=0.1)
199
+ model.simulate(duration=1000, time_step=10)
200
+ model.plot(show=True)
201
+ ```
202
+ <img src="https://github.com/openscilab/drux/raw/main/otherfiles/first_order_plot.png" alt="First-order Plot">
203
+
140
204
  ### Higuchi Model
141
205
  ```python
142
206
  from drux import HiguchiModel
@@ -152,10 +216,20 @@ Just fill an issue and describe it. We'll check it ASAP! or send an email to [dr
152
216
 
153
217
  - Please complete the issue template
154
218
 
219
+ You can also join our discord server
220
+
221
+ <a href="https://discord.gg/8Rf6bGBtse">
222
+ <img src="https://img.shields.io/discord/1064533716615049236.svg?style=for-the-badge" alt="Discord Channel">
223
+ </a>
224
+
225
+
155
226
  ## References
156
227
  <blockquote>1- T. Higuchi, "Rate of release of medicaments from ointment bases containing drugs in suspension," <i>Journal of Pharmaceutical Sciences</i>, vol. 50, no. 10, pp. 874–875, 1961.</blockquote>
157
228
  <blockquote>2- D. R. Paul, "Elaborations on the Higuchi model for drug delivery," <i>International Journal of Pharmaceutics</i>, vol. 418, no. 1, pp. 13–17, 2011.</blockquote>
158
229
  <blockquote>3- R. T. Medarametla, K. V. Gopaiah, J. N. Suresh Kumar, G. Anand Babu, M. Shaggir, G. Raghavendra, D. Naveen Reddy, and B. Venkamma, "Drug Release Kinetics and Mathematical Models," <i>International Journal of Science and Research Methodology</i>, vol. 27, no. 9, pp. 12–19, Sep. 2024.</blockquote>
230
+ <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
+ <blockquote>5- S. Dash, "Kinetic modeling on drug release from controlled drug delivery systems," <i>Acta Poloniae Pharmaceutica</i>, 2010.</blockquote>
232
+ <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>
159
233
 
160
234
  ## Show your support
161
235
  ### Star this repo
@@ -174,11 +248,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
174
248
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
175
249
 
176
250
  ## [Unreleased]
251
+ ## [0.2] - 2025-09-27
252
+ ### Added
253
+ - Zero-order model
254
+ - First-order model
255
+ ### Changed
256
+ - `README.md` modified
257
+ - Test system modified
258
+ - Release range bug in `time_for_release` fixed
259
+ - `matplotlib` import bug fixed
260
+ - `plot` method modified
177
261
  ## [0.1] - 2025-07-27
178
262
  ### Added
179
263
  - Base model
180
264
  - Higuchi model
181
265
 
182
266
 
183
- [Unreleased]: https://github.com/openscilab/drux/compare/v0.1...dev
267
+ [Unreleased]: https://github.com/openscilab/drux/compare/v0.2...dev
268
+ [0.2]: https://github.com/openscilab/drux/compare/v0.1...v0.2
184
269
  [0.1]: https://github.com/openscilab/drux/compare/48548f0...v0.1
@@ -4,12 +4,16 @@ README.md
4
4
  setup.py
5
5
  drux/__init__.py
6
6
  drux/base_model.py
7
+ drux/first_order.py
7
8
  drux/higuchi.py
8
9
  drux/messages.py
9
10
  drux/params.py
11
+ drux/zero_order.py
10
12
  drux.egg-info/PKG-INFO
11
13
  drux.egg-info/SOURCES.txt
12
14
  drux.egg-info/dependency_links.txt
13
15
  drux.egg-info/requires.txt
14
16
  drux.egg-info/top_level.txt
15
- tests/test_higuchi.py
17
+ tests/test_first_order.py
18
+ tests/test_higuchi.py
19
+ tests/test_zero_order.py
@@ -1,2 +1,2 @@
1
- numpy>=1.19.0
1
+ numpy>=1.21.0
2
2
  matplotlib>=3.2.2
@@ -33,14 +33,14 @@ setup(
33
33
  name='drux',
34
34
  packages=[
35
35
  'drux', ],
36
- version='0.1',
36
+ version='0.2',
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.1',
43
+ download_url='https://github.com/openscilab/drux/tarball/v0.2',
44
44
  keywords="drug-release drug-delivery mathematical-modeling simulation kinetics",
45
45
  project_urls={
46
46
  'Source': 'https://github.com/openscilab/drux',
@@ -0,0 +1,125 @@
1
+ """Tests for the first-order 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 FirstOrderModel
8
+
9
+ TEST_CASE_NAME = "first-order model tests"
10
+ M0, k = 0.1, 0.003
11
+ SIM_DURATION, SIM_TIME_STEP = 1000, 10
12
+ RELATIVE_TOLERANCE = 1e-1
13
+
14
+
15
+ def test_first_order_parameters():
16
+ model = FirstOrderModel(M0=M0, k=k)
17
+ assert model._parameters.M0 == M0
18
+ assert model._parameters.k == k
19
+
20
+
21
+ def test_invalid_parameters():
22
+ with raises(ValueError, match=escape("Entire releasable amount of drug (M0) must be non-negative.")):
23
+ FirstOrderModel(M0=-M0, k=k).simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
24
+
25
+ with raises(ValueError, match=escape("Release rate (k) must be non-negative.")):
26
+ FirstOrderModel(M0=M0, k=-k).simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
27
+
28
+
29
+ def test_first_order_simulation(): # Reference: https://europepmc.org/article/pmc/3425064
30
+ model = FirstOrderModel(M0=M0, k=k)
31
+ profile = model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
32
+ actual_release = [M0 * (1 - exp(-k * t)) for t in range(0, 1001, 10)]
33
+ assert all(isclose(p, a, rtol=RELATIVE_TOLERANCE) for p, a in zip(profile, actual_release))
34
+
35
+
36
+ def test_first_order_simulation_errors():
37
+ model = FirstOrderModel(M0=M0, k=k)
38
+
39
+ with raises(ValueError, match="Duration and time step must be positive values"):
40
+ model.simulate(duration=-100, time_step=10)
41
+
42
+ with raises(ValueError, match="Duration and time step must be positive values"):
43
+ model.simulate(duration=100, time_step=-10)
44
+
45
+ with raises(ValueError, match="Time step cannot be greater than duration"):
46
+ model.simulate(duration=10, time_step=20)
47
+
48
+
49
+ def test_first_order_plot1():
50
+ model = FirstOrderModel(M0=M0, k=k)
51
+ model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
52
+ fig, ax = model.plot()
53
+ assert fig is not None
54
+ assert ax is not None
55
+ assert ax.get_title() == model._plot_parameters["title"]
56
+ assert ax.get_xlabel() == model._plot_parameters["xlabel"]
57
+ assert ax.get_ylabel() == model._plot_parameters["ylabel"]
58
+ assert [text.get_text() for text in ax.get_legend().get_texts()] == [model._plot_parameters["label"]]
59
+
60
+
61
+ def test_first_order_plot2():
62
+ model = FirstOrderModel(M0=M0, k=k)
63
+ model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
64
+ fig, ax = model.plot(title="test-title", xlabel="test-xlabel", ylabel="test-ylabel", label="test-label")
65
+ assert fig is not None
66
+ assert ax is not None
67
+ assert ax.get_title() == "test-title"
68
+ assert ax.get_xlabel() == "test-xlabel"
69
+ assert ax.get_ylabel() == "test-ylabel"
70
+ assert [text.get_text() for text in ax.get_legend().get_texts()] == ["test-label"]
71
+
72
+
73
+ def test_first_order_plot_error():
74
+ model = FirstOrderModel(M0=M0, k=k)
75
+
76
+ with raises(ValueError, match=escape("No simulation data available. Run simulate() first.")):
77
+ model.plot()
78
+
79
+ model._time_points = [0] # manually set time points to simulate error (TODO: it will be caught with prior errors)
80
+ # manually set a too short profile to simulate error (TODO: it will be caught with prior errors)
81
+ model._release_profile = [0.0]
82
+ with raises(ValueError, match="Release profile is too short to calculate release rate."):
83
+ model.plot()
84
+
85
+
86
+ def test_first_order_release_rate(): # Reference: https://www.wolframalpha.com/input?i=get+the+derivative+of+M0*exp%28-k*t%29+with+respect+to+t
87
+ model = FirstOrderModel(M0=M0, k=k)
88
+ model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
89
+ rate = model.get_release_rate()
90
+ actual_rate = [k * M0 * exp(-k * t) for t in range(0, 1001, 10)]
91
+ assert all(isclose(r, a, rtol=1e-1) for r, a in zip(rate, actual_rate))
92
+
93
+
94
+ def test_first_order_release_rate_error():
95
+ model = FirstOrderModel(M0=M0, k=k)
96
+
97
+ with raises(ValueError, match=escape("No simulation data available. Run simulate() first.")):
98
+ model.get_release_rate()
99
+
100
+ model._time_points = [0] # manually set time points to simulate error (TODO: it will be caught with prior errors)
101
+ # manually set a too short profile to simulate error (TODO: it will be caught with prior errors)
102
+ model._release_profile = [0.0]
103
+ with raises(ValueError, match="Release profile is too short to calculate release rate."):
104
+ model.get_release_rate()
105
+
106
+
107
+ def test_first_order_time_for_release(): # Reference: https://www.wolframalpha.com/input?i=solve+for+t+in+0.1+*+%281+-+exp%28-0.003*t%29%29+%3D+0.5*+0.1+*+%281-+exp%28-0.003*1000%29%29
108
+ model = FirstOrderModel(M0=M0, k=k)
109
+ model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
110
+ tx = model.time_for_release(0.5 * model._release_profile[-1])
111
+ assert isclose(tx, 220, rtol=1e-2)
112
+
113
+
114
+ def test_first_order_time_for_release_error():
115
+ model = FirstOrderModel(M0=M0, k=k)
116
+
117
+ with raises(ValueError, match=escape("No simulation data available. Run simulate() first.")):
118
+ model.time_for_release(0.5)
119
+ model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
120
+
121
+ with raises(ValueError, match="Target release must be non-negative."):
122
+ model.time_for_release(-0.1)
123
+
124
+ with raises(ValueError, match="Target release exceeds maximum release of the simulated duration."):
125
+ model.time_for_release(model._release_profile[-1] + 0.1)
@@ -1,7 +1,6 @@
1
1
  """Tests for the Higuchi model implementation in drux package."""
2
2
 
3
3
  from pytest import raises
4
- from unittest import mock
5
4
  from numpy import isclose
6
5
  from math import sqrt
7
6
  from re import escape
@@ -15,9 +14,9 @@ RELATIVE_TOLERANCE = 1e-2
15
14
 
16
15
  def test_higuchi_parameters():
17
16
  model = HiguchiModel(D=D, c0=C0, cs=CS)
18
- assert model.params.D == D
19
- assert model.params.c0 == C0
20
- assert model.params.cs == CS
17
+ assert model._parameters.D == D
18
+ assert model._parameters.c0 == C0
19
+ assert model._parameters.cs == CS
21
20
 
22
21
 
23
22
  def test_invalid_parameters():
@@ -54,16 +53,30 @@ def test_higuchi_simulation_errors():
54
53
  model.simulate(duration=10, time_step=20)
55
54
 
56
55
 
57
- @mock.patch("matplotlib.pyplot.subplots")
58
- def test_higuchi_plot(mock_subplots: mock.MagicMock):
59
- mock_subplots.return_value = (mock.MagicMock(), mock.MagicMock())
56
+ def test_higuchi_plot1():
60
57
  model = HiguchiModel(D=D, c0=C0, cs=CS)
61
58
  model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
62
59
 
63
60
  fig, ax = model.plot()
64
61
  assert fig is not None
65
62
  assert ax is not None
66
- mock_subplots.assert_called_once()
63
+ assert ax.get_title() == model._plot_parameters["title"]
64
+ assert ax.get_xlabel() == model._plot_parameters["xlabel"]
65
+ assert ax.get_ylabel() == model._plot_parameters["ylabel"]
66
+ assert [text.get_text() for text in ax.get_legend().get_texts()] == [model._plot_parameters["label"]]
67
+
68
+
69
+ def test_higuchi_plot2():
70
+ model = HiguchiModel(D=D, c0=C0, cs=CS)
71
+ model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
72
+
73
+ fig, ax = model.plot(title="test-title", xlabel="test-xlabel", ylabel="test-ylabel", label="test-label")
74
+ assert fig is not None
75
+ assert ax is not None
76
+ assert ax.get_title() == "test-title"
77
+ assert ax.get_xlabel() == "test-xlabel"
78
+ assert ax.get_ylabel() == "test-ylabel"
79
+ assert [text.get_text() for text in ax.get_legend().get_texts()] == ["test-label"]
67
80
 
68
81
 
69
82
  def test_higuchi_plot_error():
@@ -72,17 +85,12 @@ def test_higuchi_plot_error():
72
85
  with raises(ValueError, match=escape("No simulation data available. Run simulate() first.")):
73
86
  model.plot()
74
87
 
75
- model.time_points = [0] # manually set time points to simulate error (TODO: it will be caught with prior errors)
88
+ model._time_points = [0] # manually set time points to simulate error (TODO: it will be caught with prior errors)
76
89
  # manually set a too short profile to simulate error (TODO: it will be caught with prior errors)
77
- model.release_profile = [0.0]
90
+ model._release_profile = [0.0]
78
91
  with raises(ValueError, match="Release profile is too short to calculate release rate."):
79
92
  model.plot()
80
93
 
81
- model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
82
- with mock.patch.dict('sys.modules', {'matplotlib': None}):
83
- with raises(ImportError, match="Matplotlib is required for plotting but not installed."):
84
- model.plot()
85
-
86
94
 
87
95
  def test_higuchi_release_rate(): # Reference: https://www.wolframalpha.com/input?i=get+the+derivative+of+sqrt%28D*C_s*%282*C_0-C_s%29*t%29+with+respect+to+t
88
96
  model = HiguchiModel(D=D, c0=C0, cs=CS)
@@ -100,9 +108,9 @@ def test_higuchi_release_rate_error():
100
108
  with raises(ValueError, match=escape("No simulation data available. Run simulate() first.")):
101
109
  model.get_release_rate()
102
110
 
103
- model.time_points = [0] # manually set time points to simulate error (TODO: it will be caught with prior errors)
111
+ model._time_points = [0] # manually set time points to simulate error (TODO: it will be caught with prior errors)
104
112
  # manually set a too short profile to simulate error (TODO: it will be caught with prior errors)
105
- model.release_profile = [0.0]
113
+ model._release_profile = [0.0]
106
114
  with raises(ValueError, match="Release profile is too short to calculate release rate."):
107
115
  model.get_release_rate()
108
116
 
@@ -110,7 +118,7 @@ def test_higuchi_release_rate_error():
110
118
  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
111
119
  model = HiguchiModel(D=D, c0=C0, cs=CS)
112
120
  model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
113
- tx = model.time_for_release(0.5 * model.release_profile[-1])
121
+ tx = model.time_for_release(0.5 * model._release_profile[-1])
114
122
  assert isclose(tx, 250.0, rtol=1e-2)
115
123
 
116
124
 
@@ -121,11 +129,8 @@ def test_higuchi_time_for_release_error():
121
129
  model.time_for_release(0.5)
122
130
  model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
123
131
 
124
- with raises(ValueError, match="Target release must be between 0 and 1."):
132
+ with raises(ValueError, match="Target release must be non-negative."):
125
133
  model.time_for_release(-0.1)
126
134
 
127
- with raises(ValueError, match="Target release must be between 0 and 1."):
128
- model.time_for_release(2.0)
129
-
130
135
  with raises(ValueError, match="Target release exceeds maximum release of the simulated duration."):
131
- model.time_for_release(min(model.release_profile[-1] + 0.1, 1))
136
+ model.time_for_release(min(model._release_profile[-1] + 0.1, 1))
@@ -0,0 +1,125 @@
1
+ """Tests for the Zero-order model implementation in drux package."""
2
+
3
+ from pytest import raises
4
+ from numpy import isclose
5
+ from math import sqrt
6
+ from re import escape
7
+ from drux import ZeroOrderModel
8
+
9
+ TEST_CASE_NAME = "Zero-order model tests"
10
+ M0, k0 = 0.01, 0.1
11
+ SIM_DURATION, SIM_TIME_STEP = 1000, 10
12
+ RELATIVE_TOLERANCE = 1e-2
13
+
14
+
15
+ def test_zero_order_parameters():
16
+ model = ZeroOrderModel(M0=M0, k0=k0)
17
+ assert model._parameters.M0 == M0
18
+ assert model._parameters.k0 == k0
19
+
20
+
21
+ def test_invalid_parameters():
22
+ with raises(ValueError, match=escape("Initial amount of drug in the solution (M0) must be non-negative.")):
23
+ ZeroOrderModel(M0=-M0, k0=k0).simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
24
+
25
+ with raises(ValueError, match=escape("Release rate (k0) must be non-negative.")):
26
+ ZeroOrderModel(M0=M0, k0=-k0).simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
27
+
28
+
29
+ def test_zero_order_simulation(): # Reference: https://europepmc.org/article/pmc/3425064
30
+ model = ZeroOrderModel(M0=M0, k0=k0)
31
+ profile = model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
32
+ actual_release = [M0 + (k0 * t) for t in range(0, 1001, 10)]
33
+ assert all(isclose(p, a, rtol=RELATIVE_TOLERANCE) for p, a in zip(profile, actual_release))
34
+
35
+
36
+ def test_zero_order_simulation_errors():
37
+ model = ZeroOrderModel(M0=M0, k0=k0)
38
+
39
+ with raises(ValueError, match="Duration and time step must be positive values"):
40
+ model.simulate(duration=-100, time_step=10)
41
+
42
+ with raises(ValueError, match="Duration and time step must be positive values"):
43
+ model.simulate(duration=100, time_step=-10)
44
+
45
+ with raises(ValueError, match="Time step cannot be greater than duration"):
46
+ model.simulate(duration=10, time_step=20)
47
+
48
+
49
+ def test_zero_order_plot1():
50
+ model = ZeroOrderModel(M0=M0, k0=k0)
51
+ model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
52
+ fig, ax = model.plot()
53
+ assert fig is not None
54
+ assert ax is not None
55
+ assert ax.get_title() == model._plot_parameters["title"]
56
+ assert ax.get_xlabel() == model._plot_parameters["xlabel"]
57
+ assert ax.get_ylabel() == model._plot_parameters["ylabel"]
58
+ assert [text.get_text() for text in ax.get_legend().get_texts()] == [model._plot_parameters["label"]]
59
+
60
+
61
+ def test_zero_order_plot2():
62
+ model = ZeroOrderModel(M0=M0, k0=k0)
63
+ model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
64
+ fig, ax = model.plot(title="test-title", xlabel="test-xlabel", ylabel="test-ylabel", label="test-label")
65
+ assert fig is not None
66
+ assert ax is not None
67
+ assert ax.get_title() == "test-title"
68
+ assert ax.get_xlabel() == "test-xlabel"
69
+ assert ax.get_ylabel() == "test-ylabel"
70
+ assert [text.get_text() for text in ax.get_legend().get_texts()] == ["test-label"]
71
+
72
+
73
+ def test_zero_order_plot_error():
74
+ model = ZeroOrderModel(M0=M0, k0=k0)
75
+
76
+ with raises(ValueError, match=escape("No simulation data available. Run simulate() first.")):
77
+ model.plot()
78
+
79
+ model._time_points = [0] # manually set time points to simulate error (TODO: it will be caught with prior errors)
80
+ # manually set a too short profile to simulate error (TODO: it will be caught with prior errors)
81
+ model._release_profile = [0.0]
82
+ with raises(ValueError, match="Release profile is too short to calculate release rate."):
83
+ model.plot()
84
+
85
+
86
+ def test_zero_order_release_rate(): # Reference: https://www.wolframalpha.com/input?i=get+the+derivative+of+M0+%2B+%28k0+*+t%29+with+respect+to+t
87
+ model = ZeroOrderModel(M0=M0, k0=k0)
88
+ model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
89
+ rate = model.get_release_rate()
90
+ actual_rate = [k0 for _ in range(0, 1001, 10)]
91
+ assert all(isclose(r, a, rtol=1e-2) for r, a in zip(rate, actual_rate))
92
+
93
+
94
+ def test_zero_order_release_rate_error():
95
+ model = ZeroOrderModel(M0=M0, k0=k0)
96
+
97
+ with raises(ValueError, match=escape("No simulation data available. Run simulate() first.")):
98
+ model.get_release_rate()
99
+
100
+ model._time_points = [0] # manually set time points to simulate error (TODO: it will be caught with prior errors)
101
+ # manually set a too short profile to simulate error (TODO: it will be caught with prior errors)
102
+ model._release_profile = [0.0]
103
+ with raises(ValueError, match="Release profile is too short to calculate release rate."):
104
+ model.get_release_rate()
105
+
106
+
107
+ def test_zero_order_time_for_release(): # Reference: https://www.wolframalpha.com/input?i=solve+for+t+in+0.01+%2B+%280.1*t%29+%3D+0.5*+%280.01+%2B+%280.1*1000%29%29
108
+ model = ZeroOrderModel(M0=M0, k0=k0)
109
+ model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
110
+ tx = model.time_for_release(0.5 * model._release_profile[-1])
111
+ assert isclose(tx, 499.95, rtol=1e-2)
112
+
113
+
114
+ def test_zero_order_time_for_release_error():
115
+ model = ZeroOrderModel(M0=M0, k0=k0)
116
+
117
+ with raises(ValueError, match=escape("No simulation data available. Run simulate() first.")):
118
+ model.time_for_release(0.5)
119
+ model.simulate(duration=SIM_DURATION, time_step=SIM_TIME_STEP)
120
+
121
+ with raises(ValueError, match="Target release must be non-negative."):
122
+ model.time_for_release(-0.1)
123
+
124
+ with raises(ValueError, match="Target release exceeds maximum release of the simulated duration."):
125
+ model.time_for_release(model._release_profile[-1] + 0.1)
File without changes
File without changes
File without changes
File without changes