Coverage for biochemistry/tests/test_michaelis_menten.py: 100%
131 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
1"""
2Define the unit tests for the :mod:`colour.biochemistry.michaelis_menten`
3module.
4"""
6from __future__ import annotations
8from itertools import product
10import numpy as np
12from colour.biochemistry import (
13 reaction_rate_MichaelisMenten,
14 reaction_rate_MichaelisMenten_Abebe2017,
15 reaction_rate_MichaelisMenten_Michaelis1913,
16 substrate_concentration_MichaelisMenten,
17 substrate_concentration_MichaelisMenten_Abebe2017,
18 substrate_concentration_MichaelisMenten_Michaelis1913,
19)
20from colour.constants import TOLERANCE_ABSOLUTE_TESTS
21from colour.utilities import ignore_numpy_errors
23__author__ = "Colour Developers"
24__copyright__ = "Copyright 2013 Colour Developers"
25__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
26__maintainer__ = "Colour Developers"
27__email__ = "colour-developers@colour-science.org"
28__status__ = "Production"
30__all__ = [
31 "TestReactionRateMichaelisMentenMichaelis1913",
32 "TestSubstrateConcentrationMichaelisMentenMichaelis1913",
33 "TestReactionRateMichaelisMentenAbebe2017",
34 "TestSubstrateConcentrationMichaelisMentenAbebe2017",
35]
38class TestReactionRateMichaelisMentenMichaelis1913:
39 """
40 Define :func:`colour.biochemistry.michaelis_menten.\
41reaction_rate_MichaelisMenten_Michaelis1913` definition unit tests methods.
42 """
44 def test_reaction_rate_MichaelisMenten_Michaelis1913(self) -> None:
45 """
46 Test :func:`colour.biochemistry.michaelis_menten.\
47reaction_rate_MichaelisMenten_Michaelis1913` definition.
48 """
50 np.testing.assert_allclose(
51 reaction_rate_MichaelisMenten_Michaelis1913(0.25, 0.5, 0.25),
52 0.250000000000000,
53 atol=TOLERANCE_ABSOLUTE_TESTS,
54 )
56 np.testing.assert_allclose(
57 reaction_rate_MichaelisMenten_Michaelis1913(0.5, 0.5, 0.25),
58 0.333333333333333,
59 atol=TOLERANCE_ABSOLUTE_TESTS,
60 )
62 np.testing.assert_allclose(
63 reaction_rate_MichaelisMenten_Michaelis1913(0.65, 0.75, 0.35),
64 0.487500000000000,
65 atol=TOLERANCE_ABSOLUTE_TESTS,
66 )
68 def test_n_dimensional_reaction_rate_MichaelisMenten_Michaelis1913(self) -> None:
69 """
70 Test :func:`colour.biochemistry.michaelis_menten.\
71reaction_rate_MichaelisMenten_Michaelis1913` definition n-dimensional arrays
72 support.
73 """
75 v = 0.5
76 V_max = 0.5
77 K_m = 0.25
78 S = reaction_rate_MichaelisMenten_Michaelis1913(v, V_max, K_m)
80 v = np.tile(v, (6, 1))
81 S = np.tile(S, (6, 1))
82 np.testing.assert_allclose(
83 reaction_rate_MichaelisMenten_Michaelis1913(v, V_max, K_m),
84 S,
85 atol=TOLERANCE_ABSOLUTE_TESTS,
86 )
88 V_max = np.tile(V_max, (6, 1))
89 K_m = np.tile(K_m, (6, 1))
90 np.testing.assert_allclose(
91 reaction_rate_MichaelisMenten_Michaelis1913(v, V_max, K_m),
92 S,
93 atol=TOLERANCE_ABSOLUTE_TESTS,
94 )
96 v = np.reshape(v, (2, 3, 1))
97 V_max = np.reshape(V_max, (2, 3, 1))
98 K_m = np.reshape(K_m, (2, 3, 1))
99 S = np.reshape(S, (2, 3, 1))
100 np.testing.assert_allclose(
101 reaction_rate_MichaelisMenten_Michaelis1913(v, V_max, K_m),
102 S,
103 atol=TOLERANCE_ABSOLUTE_TESTS,
104 )
106 @ignore_numpy_errors
107 def test_nan_reaction_rate_MichaelisMenten_Michaelis1913(self) -> None:
108 """
109 Test :func:`colour.biochemistry.michaelis_menten.\
110reaction_rate_MichaelisMenten_Michaelis1913` definition nan support.
111 """
113 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
114 cases = np.array(list(set(product(cases, repeat=3))))
115 reaction_rate_MichaelisMenten_Michaelis1913(cases, cases, cases)
118class TestSubstrateConcentrationMichaelisMentenMichaelis1913:
119 """
120 Define :func:`colour.biochemistry.michaelis_menten.\
121reaction_rate_MichaelisMenten_Michaelis1913` definition unit tests methods.
122 """
124 def test_substrate_concentration_MichaelisMenten_Michaelis1913(self) -> None:
125 """
126 Test :func:`colour.biochemistry.michaelis_menten.\
127substrate_concentration_MichaelisMenten_Michaelis1913` definition.
128 """
130 np.testing.assert_allclose(
131 substrate_concentration_MichaelisMenten_Michaelis1913(0.25, 0.5, 0.25),
132 0.250000000000000,
133 atol=TOLERANCE_ABSOLUTE_TESTS,
134 )
136 np.testing.assert_allclose(
137 substrate_concentration_MichaelisMenten_Michaelis1913(1 / 3, 0.5, 0.25),
138 0.500000000000000,
139 atol=TOLERANCE_ABSOLUTE_TESTS,
140 )
142 np.testing.assert_allclose(
143 substrate_concentration_MichaelisMenten_Michaelis1913(0.4875, 0.75, 0.35),
144 0.650000000000000,
145 atol=TOLERANCE_ABSOLUTE_TESTS,
146 )
148 def test_n_dimensional_substrate_concentration_MichaelisMenten_Michaelis1913(
149 self,
150 ) -> None:
151 """
152 Test :func:`colour.biochemistry.michaelis_menten.\
153substrate_concentration_MichaelisMenten_Michaelis1913` definition n-dimensional
154 arrays support.
155 """
157 S = 1 / 3
158 V_max = 0.5
159 K_m = 0.25
160 v = substrate_concentration_MichaelisMenten_Michaelis1913(S, V_max, K_m)
162 S = np.tile(S, (6, 1))
163 v = np.tile(v, (6, 1))
164 np.testing.assert_allclose(
165 substrate_concentration_MichaelisMenten_Michaelis1913(S, V_max, K_m),
166 v,
167 atol=TOLERANCE_ABSOLUTE_TESTS,
168 )
170 V_max = np.tile(V_max, (6, 1))
171 K_m = np.tile(K_m, (6, 1))
172 np.testing.assert_allclose(
173 substrate_concentration_MichaelisMenten_Michaelis1913(S, V_max, K_m),
174 v,
175 atol=TOLERANCE_ABSOLUTE_TESTS,
176 )
178 S = np.reshape(S, (2, 3, 1))
179 V_max = np.reshape(V_max, (2, 3, 1))
180 K_m = np.reshape(K_m, (2, 3, 1))
181 v = np.reshape(v, (2, 3, 1))
182 np.testing.assert_allclose(
183 substrate_concentration_MichaelisMenten_Michaelis1913(S, V_max, K_m),
184 v,
185 atol=TOLERANCE_ABSOLUTE_TESTS,
186 )
188 @ignore_numpy_errors
189 def test_nan_substrate_concentration_MichaelisMenten_Michaelis1913(self) -> None:
190 """
191 Test :func:`colour.biochemistry.michaelis_menten.\
192substrate_concentration_MichaelisMenten_Michaelis1913` definition nan support.
193 """
195 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
196 cases = np.array(list(set(product(cases, repeat=3))))
197 substrate_concentration_MichaelisMenten_Michaelis1913(cases, cases, cases)
200class TestReactionRateMichaelisMentenAbebe2017:
201 """
202 Define :func:`colour.biochemistry.michaelis_menten.\
203reaction_rate_MichaelisMenten_Abebe2017` definition unit tests methods.
204 """
206 def test_reaction_rate_MichaelisMenten_Abebe2017(self) -> None:
207 """
208 Test :func:`colour.biochemistry.michaelis_menten.\
209reaction_rate_MichaelisMenten_Abebe2017` definition.
210 """
212 np.testing.assert_allclose(
213 reaction_rate_MichaelisMenten_Abebe2017(0.25, 0.5, 0.25, 0.25),
214 0.400000000000000,
215 atol=TOLERANCE_ABSOLUTE_TESTS,
216 )
218 np.testing.assert_allclose(
219 reaction_rate_MichaelisMenten_Abebe2017(0.5, 0.5, 0.25, 0.25),
220 0.666666666666666,
221 atol=TOLERANCE_ABSOLUTE_TESTS,
222 )
224 np.testing.assert_allclose(
225 reaction_rate_MichaelisMenten_Abebe2017(0.65, 0.75, 0.35, 0.25),
226 0.951219512195122,
227 atol=TOLERANCE_ABSOLUTE_TESTS,
228 )
230 def test_n_dimensional_reaction_rate_MichaelisMenten_Abebe2017(self) -> None:
231 """
232 Test :func:`colour.biochemistry.michaelis_menten.\
233reaction_rate_MichaelisMenten_Abebe2017` definition n-dimensional arrays
234 support.
235 """
237 v = 0.5
238 V_max = 0.5
239 K_m = 0.25
240 b_m = 0.25
241 S = reaction_rate_MichaelisMenten_Abebe2017(v, V_max, K_m, b_m)
243 v = np.tile(v, (6, 1))
244 S = np.tile(S, (6, 1))
245 np.testing.assert_allclose(
246 reaction_rate_MichaelisMenten_Abebe2017(v, V_max, K_m, b_m),
247 S,
248 atol=TOLERANCE_ABSOLUTE_TESTS,
249 )
251 V_max = np.tile(V_max, (6, 1))
252 K_m = np.tile(K_m, (6, 1))
253 b_m = np.tile(b_m, (6, 1))
254 np.testing.assert_allclose(
255 reaction_rate_MichaelisMenten_Abebe2017(v, V_max, K_m, b_m),
256 S,
257 atol=TOLERANCE_ABSOLUTE_TESTS,
258 )
260 v = np.reshape(v, (2, 3, 1))
261 V_max = np.reshape(V_max, (2, 3, 1))
262 K_m = np.reshape(K_m, (2, 3, 1))
263 b_m = np.reshape(b_m, (2, 3, 1))
264 S = np.reshape(S, (2, 3, 1))
265 np.testing.assert_allclose(
266 reaction_rate_MichaelisMenten_Abebe2017(v, V_max, K_m, b_m),
267 S,
268 atol=TOLERANCE_ABSOLUTE_TESTS,
269 )
271 @ignore_numpy_errors
272 def test_nan_reaction_rate_MichaelisMenten_Abebe2017(self) -> None:
273 """
274 Test :func:`colour.biochemistry.michaelis_menten.\
275reaction_rate_MichaelisMenten_Abebe2017` definition nan support.
276 """
278 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
279 cases = np.array(list(set(product(cases, repeat=3))))
280 reaction_rate_MichaelisMenten_Abebe2017(cases, cases, cases, cases)
283class TestSubstrateConcentrationMichaelisMentenAbebe2017:
284 """
285 Define :func:`colour.biochemistry.michaelis_menten.\
286reaction_rate_MichaelisMenten_Abebe2017` definition unit tests methods.
287 """
289 def test_substrate_concentration_MichaelisMenten_Abebe2017(self) -> None:
290 """
291 Test :func:`colour.biochemistry.michaelis_menten.\
292substrate_concentration_MichaelisMenten_Abebe2017` definition.
293 """
295 np.testing.assert_allclose(
296 substrate_concentration_MichaelisMenten_Abebe2017(
297 0.400000000000000, 0.5, 0.25, 0.25
298 ),
299 0.250000000000000,
300 atol=TOLERANCE_ABSOLUTE_TESTS,
301 )
303 np.testing.assert_allclose(
304 substrate_concentration_MichaelisMenten_Abebe2017(
305 0.666666666666666, 0.5, 0.25, 0.25
306 ),
307 0.500000000000000,
308 atol=TOLERANCE_ABSOLUTE_TESTS,
309 )
311 np.testing.assert_allclose(
312 substrate_concentration_MichaelisMenten_Abebe2017(
313 0.951219512195122, 0.75, 0.35, 0.25
314 ),
315 0.650000000000000,
316 atol=TOLERANCE_ABSOLUTE_TESTS,
317 )
319 def test_n_dimensional_substrate_concentration_MichaelisMenten_Abebe2017(
320 self,
321 ) -> None:
322 """
323 Test :func:`colour.biochemistry.michaelis_menten.\
324substrate_concentration_MichaelisMenten_Abebe2017` definition n-dimensional
325 arrays support.
326 """
328 S = 0.400000000000000
329 V_max = 0.5
330 K_m = 0.25
331 b_m = 0.25
332 v = substrate_concentration_MichaelisMenten_Abebe2017(S, V_max, K_m, b_m)
334 S = np.tile(S, (6, 1))
335 v = np.tile(v, (6, 1))
336 np.testing.assert_allclose(
337 substrate_concentration_MichaelisMenten_Abebe2017(S, V_max, K_m, b_m),
338 v,
339 atol=TOLERANCE_ABSOLUTE_TESTS,
340 )
342 V_max = np.tile(V_max, (6, 1))
343 K_m = np.tile(K_m, (6, 1))
344 b_m = np.tile(b_m, (6, 1))
345 np.testing.assert_allclose(
346 substrate_concentration_MichaelisMenten_Abebe2017(S, V_max, K_m, b_m),
347 v,
348 atol=TOLERANCE_ABSOLUTE_TESTS,
349 )
351 S = np.reshape(S, (2, 3, 1))
352 V_max = np.reshape(V_max, (2, 3, 1))
353 K_m = np.reshape(K_m, (2, 3, 1))
354 b_m = np.reshape(b_m, (2, 3, 1))
355 v = np.reshape(v, (2, 3, 1))
356 np.testing.assert_allclose(
357 substrate_concentration_MichaelisMenten_Abebe2017(S, V_max, K_m, b_m),
358 v,
359 atol=TOLERANCE_ABSOLUTE_TESTS,
360 )
362 @ignore_numpy_errors
363 def test_nan_substrate_concentration_MichaelisMenten_Abebe2017(self) -> None:
364 """
365 Test :func:`colour.biochemistry.michaelis_menten.\
366substrate_concentration_MichaelisMenten_Abebe2017` definition nan support.
367 """
369 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
370 cases = np.array(list(set(product(cases, repeat=3))))
371 substrate_concentration_MichaelisMenten_Abebe2017(cases, cases, cases, cases)
374class TestReactionRateMichaelisMenten:
375 """
376 Define :func:`colour.biochemistry.michaelis_menten.\
377reaction_rate_MichaelisMenten` wrapper definition unit tests methods.
378 """
380 def test_reaction_rate_MichaelisMenten(self) -> None:
381 """
382 Test :func:`colour.biochemistry.michaelis_menten.\
383reaction_rate_MichaelisMenten` wrapper definition.
384 """
386 np.testing.assert_allclose(
387 reaction_rate_MichaelisMenten(0.5, 2.5, 0.8),
388 0.961538461538461,
389 atol=TOLERANCE_ABSOLUTE_TESTS,
390 )
392 np.testing.assert_allclose(
393 reaction_rate_MichaelisMenten(
394 0.5, 2.5, 0.8, method="Abebe 2017", b_m=0.813
395 ),
396 1.036054742705597,
397 atol=TOLERANCE_ABSOLUTE_TESTS,
398 )
401class TestSubstrateConcentrationMichaelisMenten:
402 """
403 Define :func:`colour.biochemistry.michaelis_menten.\
404substrate_concentration_MichaelisMenten` wrapper definition unit tests methods.
405 """
407 def test_substrate_concentration_MichaelisMenten(self) -> None:
408 """
409 Test :func:`colour.biochemistry.michaelis_menten.\
410substrate_concentration_MichaelisMenten` wrapper definition.
411 """
413 np.testing.assert_allclose(
414 substrate_concentration_MichaelisMenten(0.25, 0.5, 0.25),
415 0.250000000000000,
416 atol=TOLERANCE_ABSOLUTE_TESTS,
417 )
419 np.testing.assert_allclose(
420 substrate_concentration_MichaelisMenten(
421 0.400000000000000, 0.5, 0.25, method="Abebe 2017", b_m=0.25
422 ),
423 0.250000000000000,
424 atol=TOLERANCE_ABSOLUTE_TESTS,
425 )