Coverage for biochemistry/tests/test_michaelis_menten.py: 100%

1"""

2 Define the unit tests for the :mod:`colour.biochemistry.michaelis_menten`

3 module.

4"""

5

6 from __future__ import annotations

7

8 from itertools import product

9

10 import numpy as np

11

12 from 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)

20 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

21 from colour.utilities import ignore_numpy_errors

22

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"

29

30 __all__ = [

31 "TestReactionRateMichaelisMentenMichaelis1913",

32 "TestSubstrateConcentrationMichaelisMentenMichaelis1913",

33 "TestReactionRateMichaelisMentenAbebe2017",

34 "TestSubstrateConcentrationMichaelisMentenAbebe2017",

35]

36

37

38 class TestReactionRateMichaelisMentenMichaelis1913:

39 """

40 Define :func:`colour.biochemistry.michaelis_menten.\

41 reaction_rate_MichaelisMenten_Michaelis1913` definition unit tests methods.

42 """

43

44 def test_reaction_rate_MichaelisMenten_Michaelis1913(self) -> None:

45 """

46 Test :func:`colour.biochemistry.michaelis_menten.\

47 reaction_rate_MichaelisMenten_Michaelis1913` definition.

48 """

49

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 )

55

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 )

61

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 )

67

68 def test_n_dimensional_reaction_rate_MichaelisMenten_Michaelis1913(self) -> None:

69 """

70 Test :func:`colour.biochemistry.michaelis_menten.\

71 reaction_rate_MichaelisMenten_Michaelis1913` definition n-dimensional arrays

72 support.

73 """

74

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)

79

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 )

87

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 )

95

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 )

105

106 @ignore_numpy_errors

107 def test_nan_reaction_rate_MichaelisMenten_Michaelis1913(self) -> None:

108 """

109 Test :func:`colour.biochemistry.michaelis_menten.\

110 reaction_rate_MichaelisMenten_Michaelis1913` definition nan support.

111 """

112

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)

116

117

118 class TestSubstrateConcentrationMichaelisMentenMichaelis1913:

119 """

120 Define :func:`colour.biochemistry.michaelis_menten.\

121 reaction_rate_MichaelisMenten_Michaelis1913` definition unit tests methods.

122 """

123

124 def test_substrate_concentration_MichaelisMenten_Michaelis1913(self) -> None:

125 """

126 Test :func:`colour.biochemistry.michaelis_menten.\

127 substrate_concentration_MichaelisMenten_Michaelis1913` definition.

128 """

129

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 )

135

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 )

141

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 )

147

148 def test_n_dimensional_substrate_concentration_MichaelisMenten_Michaelis1913(

149 self,

150 ) -> None:

151 """

152 Test :func:`colour.biochemistry.michaelis_menten.\

153 substrate_concentration_MichaelisMenten_Michaelis1913` definition n-dimensional

154 arrays support.

155 """

156

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)

161

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 )

169

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 )

177

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 )

187

188 @ignore_numpy_errors

189 def test_nan_substrate_concentration_MichaelisMenten_Michaelis1913(self) -> None:

190 """

191 Test :func:`colour.biochemistry.michaelis_menten.\

192 substrate_concentration_MichaelisMenten_Michaelis1913` definition nan support.

193 """

194

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)

198

199

200 class TestReactionRateMichaelisMentenAbebe2017:

201 """

202 Define :func:`colour.biochemistry.michaelis_menten.\

203 reaction_rate_MichaelisMenten_Abebe2017` definition unit tests methods.

204 """

205

206 def test_reaction_rate_MichaelisMenten_Abebe2017(self) -> None:

207 """

208 Test :func:`colour.biochemistry.michaelis_menten.\

209 reaction_rate_MichaelisMenten_Abebe2017` definition.

210 """

211

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 )

217

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 )

223

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 )

229

230 def test_n_dimensional_reaction_rate_MichaelisMenten_Abebe2017(self) -> None:

231 """

232 Test :func:`colour.biochemistry.michaelis_menten.\

233 reaction_rate_MichaelisMenten_Abebe2017` definition n-dimensional arrays

234 support.

235 """

236

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)

242

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 )

250

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 )

259

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 )

270

271 @ignore_numpy_errors

272 def test_nan_reaction_rate_MichaelisMenten_Abebe2017(self) -> None:

273 """

274 Test :func:`colour.biochemistry.michaelis_menten.\

275 reaction_rate_MichaelisMenten_Abebe2017` definition nan support.

276 """

277

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)

281

282

283 class TestSubstrateConcentrationMichaelisMentenAbebe2017:

284 """

285 Define :func:`colour.biochemistry.michaelis_menten.\

286 reaction_rate_MichaelisMenten_Abebe2017` definition unit tests methods.

287 """

288

289 def test_substrate_concentration_MichaelisMenten_Abebe2017(self) -> None:

290 """

291 Test :func:`colour.biochemistry.michaelis_menten.\

292 substrate_concentration_MichaelisMenten_Abebe2017` definition.

293 """

294

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 )

302

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 )

310

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 )

318

319 def test_n_dimensional_substrate_concentration_MichaelisMenten_Abebe2017(

320 self,

321 ) -> None:

322 """

323 Test :func:`colour.biochemistry.michaelis_menten.\

324 substrate_concentration_MichaelisMenten_Abebe2017` definition n-dimensional

325 arrays support.

326 """

327

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)

333

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 )

341

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 )

350

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 )

361

362 @ignore_numpy_errors

363 def test_nan_substrate_concentration_MichaelisMenten_Abebe2017(self) -> None:

364 """

365 Test :func:`colour.biochemistry.michaelis_menten.\

366 substrate_concentration_MichaelisMenten_Abebe2017` definition nan support.

367 """

368

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)

372

373

374 class TestReactionRateMichaelisMenten:

375 """

376 Define :func:`colour.biochemistry.michaelis_menten.\

377 reaction_rate_MichaelisMenten` wrapper definition unit tests methods.

378 """

379

380 def test_reaction_rate_MichaelisMenten(self) -> None:

381 """

382 Test :func:`colour.biochemistry.michaelis_menten.\

383 reaction_rate_MichaelisMenten` wrapper definition.

384 """

385

386 np.testing.assert_allclose(

387 reaction_rate_MichaelisMenten(0.5, 2.5, 0.8),

388 0.961538461538461,

389 atol=TOLERANCE_ABSOLUTE_TESTS,

390 )

391

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 )

399

400

401 class TestSubstrateConcentrationMichaelisMenten:

402 """

403 Define :func:`colour.biochemistry.michaelis_menten.\

404 substrate_concentration_MichaelisMenten` wrapper definition unit tests methods.

405 """

406

407 def test_substrate_concentration_MichaelisMenten(self) -> None:

408 """

409 Test :func:`colour.biochemistry.michaelis_menten.\

410 substrate_concentration_MichaelisMenten` wrapper definition.

411 """

412

413 np.testing.assert_allclose(

414 substrate_concentration_MichaelisMenten(0.25, 0.5, 0.25),

415 0.250000000000000,

416 atol=TOLERANCE_ABSOLUTE_TESTS,

417 )

418

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 )