Repository navigation
Expand file tree
/
Copy pathvl_mrgsolve_model.R
More file actions
1432 lines (1345 loc) · 67.1 KB
/
Copy pathvl_mrgsolve_model.R
File metadata and controls
1432 lines (1345 loc) · 67.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
## =============================================================================
## vl_mrgsolve_model.R
## Visceral Leishmaniasis (kala-azar) — 73-ODE QSP model for mrgsolve
## 내장 리슈만편모충증 QSP 모델 (mrgsolve, 73개 ODE)
##
## Author's note on provenance
## ---------------------------
## No R runtime was available in the environment where this file was written,
## so every equation below was first implemented independently in Python
## (`vl_reference_model.py`) and integrated there; the numbers quoted in
## README.md are that integration's output, and `vl_reference_output.txt` is
## its verbatim log. Three real defects were found by doing it that way and
## each is marked in place with a "BUG FOUND" comment, because a reader of a
## QSP model deserves to know which lines were hard:
##
## 1. an extinction floor written INSIDE the derivative block
## (`if (P < 1e-7 && dPdt > 0) dPdt = 0`) is a discontinuous switch; it
## is invisible while burdens are high and then stalls the integrator
## completely once any compartment clears. The floor belongs between
## integration steps, not in f(t,y).
## 2. CD4 was written with a loss term and no set point, so every
## immunocompetent patient drifted to 4 cells/uL over an 18-month
## follow-up and the entire host-immunity arm silently switched off —
## which made five regimens that cure >90% of real patients "fail".
## 3. TGF-beta driven by the saturating antigen signal AG (rather than by
## the high-burden signal AGH) stayed near-maximal down to 1e4
## amastigotes and permanently clamped macrophage activation, so no
## slow-acting drug could ever hand off to the host.
##
## What the model is for
## --------------------
## One structural commitment: THE DRUG AND THE PARASITE NEVER MEET IN PLASMA.
## Amastigotes live inside macrophages of spleen, liver, marrow and skin, so
## every drug effect is driven by an INTRAMACROPHAGE concentration, while
## amphotericin nephrotoxicity is driven by the FREE PLASMA concentration of
## the same dose. Liposomal encapsulation moves those two integrals in
## opposite directions because the liposome is cleared by the very cell
## lineage that harbours the parasite. Cure is then not "zero parasites" but
## crossing a separatrix in the (burden, primed-memory) plane — and that
## separatrix moves with CD4 count.
##
## Compartment map (73 ODEs)
## -------------------------
## 1– 8 amphotericin B: liposome-associated and free plasma species,
## peripheral tissue, four macrophage organs, renal cortex
## 9–15 miltefosine: gut, central, peripheral, four macrophage organs
## 16–24 paromomycin: depot, central, peripheral, four organs, kidney,
## cochlea
## 25–32 antimony: depot, plasma Sb(V), (spare), four organs Sb(III),
## deep tissue depot
## 33–40 amastigotes: replicating + quiescent, in each of four organs
## 41–47 TMEM, IFN-gamma, IL-10, TNF, TGF-beta, CD4, activated macrophage
## 48–57 spleen, liver, Hb, platelets, WBC, albumin, IgG, temperature,
## weight loss, PKDL lesion load
## 58–66 tubular injury, creatinine, K, Mg, hearing, QTc, lipase, ALT, GI
## 67–73 five exposure integrals, cumulative hazard, cumulative mg/kg
##
## Dosing compartments
## -------------------
## cmt 1 = A_LIP liposomal amphotericin B, IV bolus/infusion
## cmt 2 = A_FRE amphotericin B deoxycholate, IV (straight to free pool)
## cmt 9 = MIL_G miltefosine, oral
## cmt 16 = PM_D paromomycin, IM
## cmt 25 = SB5_D sodium stibogluconate / meglumine antimoniate, IM or IV
##
## Time unit is HOURS. Burden unit is 1e6 amastigotes.
## =============================================================================
library(mrgsolve)
library(dplyr)
library(tidyr)
library(ggplot2)
vl_code <- '
$PARAM @annotated
// ---- covariates -----------------------------------------------------------
WT : 50.0 : Body weight (kg)
AGE : 30.0 : Age (y)
CD40 : 700.0 : Baseline CD4 count (cells/uL)
HIV : 0.0 : HIV co-infection flag (0/1)
ART : 0.0 : On suppressive antiretroviral therapy (0/1)
MALNUT : 0.0 : Malnutrition index 0-1, scales T-cell priming
P0SCALE : 1.0 : Multiplier on presenting parasite burden
// ---- amphotericin B disposition -------------------------------------------
V_LIP : 0.10 : Liposome distribution volume (L/kg, ~plasma volume)
CL_LIP : 0.50 : Liposome disposition clearance (L/h/70kg)
FREL : 0.30 : Fraction of liposome clearance that LEAKS drug to plasma
V_FRE : 0.50 : Free/bound AmB central volume (L/kg)
CL_FRE : 1.40 : Free AmB elimination clearance (L/h/70kg)
Q_AMB : 1.20 : Free AmB intercompartmental clearance (L/h/70kg)
V_PER : 3.00 : AmB peripheral volume (L/kg)
FSP_A : 0.10 : Spleen share of MPS liposome uptake
FLI_A : 0.60 : Liver (Kupffer) share of MPS liposome uptake
FBM_A : 0.12 : Bone marrow share of MPS liposome uptake
FSK_A : 0.03 : Dermal share of MPS liposome uptake
KOUT_A : 0.00825 : Egress of the pharmacologically available tissue AmB (1/h)
KPSP_A : 14.0 : Spleen:free-plasma partition coefficient, AmB
KPLI_A : 20.0 : Liver:free-plasma partition coefficient, AmB
KPBM_A : 9.0 : Marrow:free-plasma partition coefficient, AmB
KPSK_A : 1.5 : Skin:free-plasma partition coefficient, AmB
KPKID_A : 8.0 : Kidney:free-plasma partition coefficient, AmB
KIN_KID : 0.15 : Renal cortical uptake rate (1/h)
KOUT_KID : 0.012 : Renal cortical egress rate (1/h)
// ---- miltefosine ----------------------------------------------------------
KA_MIL : 0.40 : Oral absorption rate constant (1/h)
F_MIL : 1.00 : Relative bioavailability
CL_MIL : 0.166 : Apparent clearance (L/h/70kg)
V1_MIL : 40.0 : Apparent central volume (L/70kg)
V2_MIL : 52.0 : Apparent peripheral volume (L/70kg)
Q_MIL : 0.90 : Apparent intercompartmental clearance (L/h/70kg)
KPSP_M : 8.0 : Spleen macrophage partition, miltefosine
KPLI_M : 8.0 : Liver macrophage partition, miltefosine
KPBM_M : 6.0 : Marrow macrophage partition, miltefosine
KPSK_M : 4.0 : Dermal macrophage partition, miltefosine
KIN_M : 0.05 : Tissue equilibration rate, miltefosine (1/h)
EM50_GI : 25.0 : Plasma conc for half-maximal GI intolerance (mg/L)
// ---- paromomycin ----------------------------------------------------------
KA_PM : 1.80 : IM absorption rate constant (1/h)
V_PM : 0.25 : Central volume (L/kg)
CL_PM : 5.50 : Clearance, glomerular (L/h/70kg)
Q_PM : 1.00 : Intercompartmental clearance (L/h/70kg)
V2_PM : 0.20 : Peripheral volume (L/kg)
KIN_PM : 0.020 : Pinocytic entry into macrophage (1/h) - deliberately SLOW
KOUT_PM : 0.004 : Macrophage egress (1/h)
FSK_PM : 0.25 : Dermal access relative to MPS organs
KIN_PMK : 0.10 : Renal cortical (megalin) uptake (1/h)
KOUT_PMK : 0.008 : Renal cortical egress (1/h)
KIN_COC : 0.004 : Cochlear uptake (1/h)
KOUT_COC : 0.0004 : Cochlear egress (1/h) - near-irreversible
// ---- antimony -------------------------------------------------------------
KA_SB : 1.50 : IM absorption rate constant (1/h)
V_SB : 0.22 : Sb(V) central volume (L/kg)
CL_SB : 7.00 : Sb(V) renal clearance (L/h/70kg)
Q_SB : 0.45 : Clearance to the deep antimony depot (L/h/70kg)
V2_SB : 0.90 : Deep antimony depot volume (L/kg)
KRED : 0.045 : Sb(V) -> Sb(III) intracellular reduction rate (1/h)
KEFF_SB : 0.30 : Sb(III) efflux rate, MRPA/trypanothione route (1/h)
RES_SB : 1.0 : Antimony resistance multiplier ON EFFLUX (Bihar ~9)
KPSK_SB : 0.30 : Dermal Sb access relative to MPS organs
// ---- organ compartment volumes -------------------------------------------
VSP : 0.25 : Spleen macrophage compartment volume (L)
VLI : 1.50 : Liver macrophage compartment volume (L)
VBM : 1.50 : Marrow macrophage compartment volume (L)
VSK : 3.00 : Dermal macrophage compartment volume (L)
VKID : 0.30 : Renal cortex volume (L)
VCOC : 0.002 : Cochlear volume (L)
// ---- parasite dynamics ----------------------------------------------------
KG_SP : 0.0072 : Amastigote replication rate, spleen (1/h)
KG_LI : 0.0065 : Amastigote replication rate, liver (1/h)
KG_BM : 0.0068 : Amastigote replication rate, marrow (1/h)
KG_SK : 0.0040 : Amastigote replication rate, skin (1/h)
PMAX_SP : 3.0e3 : Spleen carrying capacity (1e6 amastigotes)
PMAX_LI : 1.0e4 : Liver carrying capacity (1e6 amastigotes)
PMAX_BM : 3.0e3 : Marrow carrying capacity (1e6 amastigotes)
PMAX_SK : 1.0e2 : Skin carrying capacity (1e6 amastigotes)
KIMM : 0.065 : Maximal immune (NO-mediated) killing rate (1/h)
KMIG : 2.0e-4 : Redistribution among spleen/liver/marrow (1/h)
KMIG_SKIN : 3.0e-6 : Visceral pool -> dermis trafficking (1/h)
KMIG_BACK : 3.0e-7 : Dermis -> visceral pool trafficking (1/h)
FR0 : 5.0e-4 : Quiescent (persister) fraction at presentation
KQ0 : 2.0e-6 : Basal entry into quiescence (1/h)
KQS : 1.5e-5 : Stress-induced quiescence per unit of kill pressure
KR_REACT : 8.0e-4 : Reactivation out of quiescence (1/h)
COSTR : 0.05 : Replication rate of quiescent forms, fraction of KG
FIMM_R : 0.15 : Immune killing of quiescent forms, fraction of KIMM
FIMM_SK : 0.12 : Immune killing in the DERMIS, fraction of KIMM
RFAC_A : 20.0 : EC50 multiplier for quiescent forms, amphotericin B
RFAC_M : 25.0 : EC50 multiplier for quiescent forms, miltefosine
RFAC_P : 30.0 : EC50 multiplier for quiescent forms, paromomycin
RFAC_S : 40.0 : EC50 multiplier for quiescent forms, Sb(III)
RES_M : 1.0 : Acquired miltefosine resistance multiplier on EC50
RES_P : 1.0 : Acquired paromomycin resistance multiplier on EC50
// ---- drug PD (Emax on INTRAMACROPHAGE concentration) ---------------------
EMAX_A : 0.060 : Maximal AmB kill rate (1/h)
EC50_A : 6.0 : AmB EC50, intramacrophage (mg/L)
HILL_A : 2.0 : AmB Hill coefficient
EMAX_M : 0.034 : Maximal miltefosine kill rate (1/h)
EC50_M : 90.0 : Miltefosine EC50, intramacrophage (mg/L)
HILL_M : 1.5 : Miltefosine Hill coefficient
EMAX_P : 0.042 : Maximal paromomycin kill rate (1/h)
EC50_P : 25.0 : Paromomycin EC50, intramacrophage (mg/L)
HILL_P : 1.5 : Paromomycin Hill coefficient
EMAX_S : 0.045 : Maximal Sb(III) kill rate (1/h)
EC50_S : 0.50 : Sb(III) EC50, intramacrophage (mg/L)
HILL_S : 1.5 : Sb(III) Hill coefficient
// ---- immunity -------------------------------------------------------------
KAG : 0.01 : Burden giving half-maximal antigen signal (1e6 amastigotes)
KTP : 0.0050 : Memory/effector T-cell priming rate (1/h)
TMEMAX : 2.0 : Ceiling on the primed memory pool
KTD : 0.00015 : Memory decay rate (1/h, t1/2 ~192 d)
KI_T : 0.35 : IL-10 concentration halving priming
KIP : 0.045 : IFN-gamma production rate
KID : 0.060 : IFN-gamma decay rate (1/h)
FAG_IFN : 0.04 : Antigen-only contribution to IFN-gamma (innate, small)
KLP : 0.030 : IL-10 production rate
KLD : 0.020 : IL-10 decay rate (1/h)
K50_IL10 : 60.0 : Burden for half-maximal IL-10 (1e6 amastigotes)
K50_SYS : 300.0 : Burden for half-maximal systemic illness (1e6 amastigotes)
HIL10 : 2.0 : Hill coefficient of the IL-10 burden response
KNP : 0.050 : TNF production rate
KND : 0.070 : TNF decay rate (1/h)
KGP : 0.010 : TGF-beta production rate
KGD : 0.012 : TGF-beta decay rate (1/h)
KI_IFN : 0.35 : IFN-gamma for half-maximal macrophage activation
KI_IL10 : 0.25 : IL-10 inhibition constant on macrophage activation
KI_TGFB : 0.40 : TGF-beta inhibition constant on macrophage activation
KCD4 : 350.0 : CD4 count for half-maximal T-cell help (cells/uL)
CD4SET : 800.0 : CD4 homeostatic set point without HIV (cells/uL)
CD4SET_ART : 600.0 : CD4 set point achieved on suppressive ART (cells/uL)
KCD4H : 0.0015 : CD4 homeostatic restoration rate (1/h)
KCD4L : 0.00080 : Burden-driven CD4 depression rate (1/h)
KMPH : 0.015 : Activated-macrophage pool turnover (1/h)
FHIV_MAC : 0.50 : Residual macrophage killing capacity in HIV
// ---- clinical -------------------------------------------------------------
SPL0 : 0.5 : Healthy spleen size (cm below costal margin)
SPLMAX : 12.0 : Maximal added spleen size (cm)
K50_SPL : 300.0 : Spleen burden for half-maximal splenomegaly
KSPL : 0.0035 : Spleen size relaxation rate (1/h)
LIV0 : 0.5 : Healthy liver size (cm)
LIVMAX : 5.0 : Maximal added liver size (cm)
KLIV : 0.0030 : Liver size relaxation rate (1/h)
HGB0 : 14.0 : Baseline haemoglobin (g/dL)
KHGB : 0.0060 : Haemoglobin pool turnover (1/h)
FSUP_HGB : 0.75 : Maximal marrow suppression of erythropoiesis
KSPL_HGB : 0.045 : Hypersplenic RBC destruction per cm of spleen
PLT0 : 250.0 : Baseline platelets (1e9/L)
KPLT : 0.0090 : Platelet turnover (1/h)
KSPL_PLT : 0.085 : Hypersplenic platelet destruction per cm of spleen
WBC0 : 7.0 : Baseline leucocytes (1e9/L)
KWBC : 0.020 : Leucocyte turnover (1/h)
KSPL_WBC : 0.055 : Hypersplenic leucocyte destruction per cm of spleen
ALB0 : 4.3 : Baseline albumin (g/dL)
KALB : 0.0035 : Albumin turnover (1/h)
IGG0 : 1.1 : Baseline IgG (g/dL)
KIGG_P : 0.00087 : Polyclonal IgG production per antigen unit
KIGG_D : 0.00030 : IgG decay rate (1/h, t1/2 ~96 d)
TEMP0 : 36.7 : Baseline temperature (degC)
KTEMP : 0.060 : Temperature relaxation rate (1/h)
TNF_FEV : 3.2 : Maximal TNF-driven temperature rise (degC)
KBWL : 0.0012 : Weight-loss dynamics rate (1/h)
BWLMAX : 0.28 : Maximal fractional weight loss
KPKDL_P : 0.0022 : PKDL lesion formation rate
KPKDL_D : 0.0015 : PKDL lesion resolution rate (1/h)
// ---- toxicity -------------------------------------------------------------
KTUB : 0.00035 : Tubular injury per mg/L renal AmB per h
KTUBR : 0.0030 : Tubular repair rate (1/h)
GFR0 : 100.0 : Baseline GFR (mL/min)
KSCR : 0.030 : Creatinine turnover (1/h)
SCR0 : 0.85 : Baseline creatinine (mg/dL)
KWK : 0.0039 : Renal K wasting per mg/L renal AmB per h
K_K0 : 4.1 : Baseline serum potassium (mEq/L)
KKR : 0.030 : Potassium restoration rate (1/h)
KWMG : 0.00146 : Renal Mg wasting per mg/L renal AmB per h
MG0 : 2.0 : Baseline serum magnesium (mg/dL)
KMGR : 0.025 : Magnesium restoration rate (1/h)
KHEAR : 0.00040 : Hearing threshold shift per mg/L cochlear PM per h
QTC0 : 400.0 : Baseline QTc (ms)
KQTC : 0.145 : QTc sensitivity to deep-depot antimony
KQTCR : 0.020 : QTc recovery rate (1/h)
LIPA0 : 30.0 : Baseline lipase (U/L)
KLIPA : 0.85 : Lipase response to Sb(V)
KLIPAR : 0.015 : Lipase recovery rate (1/h)
ALT0 : 25.0 : Baseline ALT (U/L)
KALTX : 0.18 : ALT response to Sb(V)
KALT_M : 0.013 : ALT response to miltefosine
KALTR : 0.012 : ALT recovery rate (1/h)
KGITX : 0.10 : GI intolerance accumulation rate
KGITR : 0.09 : GI intolerance resolution rate (1/h)
// ---- mortality ------------------------------------------------------------
H0 : 2.2e-5 : Baseline hazard of the severe VL state (1/h)
HGB_H : 7.0 : Haemoglobin below which hazard climbs (g/dL)
ALB_H : 2.8 : Albumin below which hazard climbs (g/dL)
WBC_H : 1.5 : Leucocytes below which hazard climbs (1e9/L)
$CMT @annotated
A_LIP : Liposome-associated amphotericin B, plasma (mg)
A_FRE : Released / protein-bound amphotericin B, central (mg)
A_PER : Amphotericin B, peripheral tissue (mg)
AMB_SP : Amphotericin B, spleen macrophage compartment (mg)
AMB_LI : Amphotericin B, liver Kupffer compartment (mg)
AMB_BM : Amphotericin B, marrow macrophage compartment (mg)
AMB_SK : Amphotericin B, dermal macrophage compartment (mg)
AMB_KID : Amphotericin B, renal cortex (mg)
MIL_G : Miltefosine, gut depot (mg)
MIL_C : Miltefosine, central (mg)
MIL_P : Miltefosine, peripheral (mg)
MIL_SP : Miltefosine, spleen macrophage compartment (mg)
MIL_LI : Miltefosine, liver macrophage compartment (mg)
MIL_BM : Miltefosine, marrow macrophage compartment (mg)
MIL_SK : Miltefosine, dermal macrophage compartment (mg)
PM_D : Paromomycin, IM depot (mg)
PM_C : Paromomycin, central (mg)
PM_P : Paromomycin, peripheral (mg)
PM_SP : Paromomycin, spleen macrophage compartment (mg)
PM_LI : Paromomycin, liver macrophage compartment (mg)
PM_BM : Paromomycin, marrow macrophage compartment (mg)
PM_SK : Paromomycin, dermal macrophage compartment (mg)
PM_KID : Paromomycin, renal cortex (mg)
PM_COC : Paromomycin, cochlea (mg)
SB5_D : Antimony, IM depot (mg Sb)
SB5_C : Sb(V), plasma (mg)
SB5_P : Spare compartment, kept for state-vector parity (mg)
SB3_SP : Sb(III), spleen macrophage compartment (mg)
SB3_LI : Sb(III), liver macrophage compartment (mg)
SB3_BM : Sb(III), marrow macrophage compartment (mg)
SB3_SK : Sb(III), dermal macrophage compartment (mg)
SB_DEP : Antimony, deep tissue depot (mg)
P_SP_S : Replicating amastigotes, spleen (1e6)
P_SP_R : Quiescent amastigotes, spleen (1e6)
P_LI_S : Replicating amastigotes, liver (1e6)
P_LI_R : Quiescent amastigotes, liver (1e6)
P_BM_S : Replicating amastigotes, marrow (1e6)
P_BM_R : Quiescent amastigotes, marrow (1e6)
P_SK_S : Replicating amastigotes, skin (1e6)
P_SK_R : Quiescent amastigotes, skin (1e6)
TMEM : Primed effector/memory T-cell pool (0-2)
IFNG : IFN-gamma (arbitrary units)
IL10 : IL-10 (arbitrary units)
TNFA : TNF-alpha (arbitrary units)
TGFB : TGF-beta (arbitrary units)
CD4 : CD4 T-cell count (cells/uL)
MPHA : Activated-macrophage pool (0-1)
SPL : Spleen size (cm below costal margin)
LIVS : Liver size (cm below costal margin)
HGB : Haemoglobin (g/dL)
PLT : Platelets (1e9/L)
WBC : Leucocytes (1e9/L)
ALB : Albumin (g/dL)
IGG : Polyclonal IgG (g/dL)
TEMP : Body temperature (degC)
BWTL : Fractional body-weight loss
PKDL : PKDL lesion load (arbitrary units)
TUBI : Tubular injury index
SCR : Serum creatinine (mg/dL)
KSER : Serum potassium (mEq/L)
MGSER : Serum magnesium (mg/dL)
HEAR : Hearing threshold shift (dB)
QTC : QTc interval (ms)
LIPA : Serum lipase (U/L)
ALTX : Serum ALT (U/L)
GITX : GI intolerance index
AUCFRE : AUC of free plasma AmB (mg.h/L) <- nephrotoxicity driver
AUCASP : AUC of spleen-macrophage AmB (mg.h/L) <- efficacy driver
AUCMSP : AUC of spleen-macrophage miltefosine (mg.h/L)
AUCBSP : AUC of spleen-macrophage Sb(III) (mg.h/L)
AUCPSP : AUC of spleen-macrophage paromomycin (mg.h/L)
CUMHAZ : Cumulative mortality hazard
CUMDOSE : Cumulative dose administered (mg/kg)
$GLOBAL
#define _EMX(conc, ec50, emax, hill) \\
((conc) <= 0.0 ? 0.0 : (emax) * pow((conc), (hill)) / \\
(pow((ec50), (hill)) + pow((conc), (hill))))
// allometry: clearances ^0.75, volumes ^1.0. THIS IS THE WHOLE OF THE
// PAEDIATRIC MILTEFOSINE PROBLEM: dose is prescribed per kg (exponent 1.0)
// but cleared with exponent 0.75, so steady-state exposure scales as WT^0.25
// and a 10 kg child on 2.5 mg/kg/d is 33% underexposed relative to a 50 kg
// adult on the identical mg/kg.
#define _FCL (pow(WT/70.0, 0.75))
#define _FV (WT/70.0)
$MAIN
// -- allometrically scaled disposition parameters ---------------------------
double CLlip = CL_LIP * _FCL;
double CLfre = CL_FRE * _FCL;
double Qamb = Q_AMB * _FCL;
double CLmil = CL_MIL * _FCL;
double Qmil = Q_MIL * _FCL;
double CLpm = CL_PM * _FCL;
double Qpm = Q_PM * _FCL;
double CLsb = CL_SB * _FCL;
double Qsb = Q_SB * _FCL;
double VlipA = V_LIP * WT;
double VfreA = V_FRE * WT;
double VperA = V_PER * WT;
double V1mil = V1_MIL * _FV;
double V2mil = V2_MIL * _FV;
double VpmA = V_PM * WT;
double V2pmA = V2_PM * WT;
double VsbA = V_SB * WT;
double V2sbA = V2_SB * WT;
double VspA = VSP * _FV;
double VliA = VLI * _FV;
double VbmA = VBM * _FV;
double VskA = VSK * _FV;
double VkidA = VKID * _FV;
double GFRb = GFR0 * _FCL;
// -- initial conditions: a patient presenting with established, symptomatic
// VL, i.e. sitting on the untreated high-burden attractor ---------------
if (NEWIND < 2) {
P_SP_S_0 = 0.80 * PMAX_SP * P0SCALE * (1.0 - FR0);
P_SP_R_0 = 0.80 * PMAX_SP * P0SCALE * FR0;
P_LI_S_0 = 0.55 * PMAX_LI * P0SCALE * (1.0 - FR0);
P_LI_R_0 = 0.55 * PMAX_LI * P0SCALE * FR0;
P_BM_S_0 = 0.60 * PMAX_BM * P0SCALE * (1.0 - FR0);
P_BM_R_0 = 0.60 * PMAX_BM * P0SCALE * FR0;
P_SK_S_0 = 0.25 * PMAX_SK * P0SCALE * (1.0 - FR0);
P_SK_R_0 = 0.25 * PMAX_SK * P0SCALE * FR0;
TMEM_0 = 0.05;
IFNG_0 = 0.11;
IL10_0 = 0.62;
TNFA_0 = 0.55;
TGFB_0 = 0.42;
CD4_0 = CD40;
MPHA_0 = 0.04; // BUG FOUND (twice): MPHA is the ACTIVATED fraction of
// the macrophage pool, so both an active-VL patient and
// a healthy host sit near zero, not near one. Leaving
// it high on day 0 flattered the fast-killing drugs, and
// leaving it high in the treatment-naive initial state
// sterilised every fresh sandfly inoculum on arrival.
SPL_0 = 8.5;
LIVS_0 = 2.8;
HGB_0 = 7.4;
PLT_0 = 78.0;
WBC_0 = 2.4;
ALB_0 = 2.7;
IGG_0 = 3.6;
TEMP_0 = 38.9;
BWTL_0 = 0.16;
SCR_0 = SCR0;
KSER_0 = K_K0;
MGSER_0 = MG0;
QTC_0 = QTC0;
LIPA_0 = LIPA0;
ALTX_0 = ALT0;
}
$ODE
// =========================================================================
// 1. AMPHOTERICIN B -- one dose, two integrals, opposite directions
// =========================================================================
double C_LIP = A_LIP / VlipA;
double C_FRE = A_FRE / VfreA;
double C_PER = A_PER / VperA;
double cAsp = AMB_SP / VspA;
double cAli = AMB_LI / VliA;
double cAbm = AMB_BM / VbmA;
double cAsk = AMB_SK / VskA;
double cAkid = AMB_KID / VkidA;
double lip_out = CLlip * C_LIP;
double rel = FREL * lip_out; // leaks into the free plasma pool
double mps = (1.0 - FREL) * lip_out; // PHAGOCYTOSED: handed to the
// infected cell. This single line
// is why liposomal amphotericin is a
// targeting device and not just a
// better-tolerated formulation.
dxdt_A_LIP = -lip_out;
dxdt_A_FRE = rel - CLfre * C_FRE - Qamb * (C_FRE - C_PER);
dxdt_A_PER = Qamb * (C_FRE - C_PER);
dxdt_AMB_SP = FSP_A * mps + KOUT_A * (KPSP_A * C_FRE * VspA - AMB_SP);
dxdt_AMB_LI = FLI_A * mps + KOUT_A * (KPLI_A * C_FRE * VliA - AMB_LI);
dxdt_AMB_BM = FBM_A * mps + KOUT_A * (KPBM_A * C_FRE * VbmA - AMB_BM);
dxdt_AMB_SK = FSK_A * mps + KOUT_A * (KPSK_A * C_FRE * VskA - AMB_SK);
// BUG FOUND: written first as an uptake/egress pair, this multiplied the
// free plasma concentration by Kp AND by KIN/KOUT = 12.5 -- a 100-fold
// amplification that gave amphotericin deoxycholate a peak creatinine of
// 32 mg/dL and a NEGATIVE serum potassium. It must use the same
// equilibration form as the four macrophage organs, so that steady-state
// cortical concentration is exactly Kp x C_free.
dxdt_AMB_KID = KIN_KID * (KPKID_A * C_FRE * VkidA - AMB_KID);
// =========================================================================
// 2. MILTEFOSINE
// =========================================================================
double C_MIL = MIL_C / V1mil;
double C_MILP = MIL_P / V2mil;
double cMsp = MIL_SP / VspA;
double cMli = MIL_LI / VliA;
double cMbm = MIL_BM / VbmA;
double cMsk = MIL_SK / VskA;
dxdt_MIL_G = -KA_MIL * MIL_G;
dxdt_MIL_C = F_MIL * KA_MIL * MIL_G - CLmil * C_MIL - Qmil * (C_MIL - C_MILP);
dxdt_MIL_P = Qmil * (C_MIL - C_MILP);
dxdt_MIL_SP = KIN_M * (KPSP_M * C_MIL * VspA - MIL_SP);
dxdt_MIL_LI = KIN_M * (KPLI_M * C_MIL * VliA - MIL_LI);
dxdt_MIL_BM = KIN_M * (KPBM_M * C_MIL * VbmA - MIL_BM);
dxdt_MIL_SK = KIN_M * (KPSK_M * C_MIL * VskA - MIL_SK);
// =========================================================================
// 3. PAROMOMYCIN -- slow in, slow out: that lag is the 21-day course
// =========================================================================
double C_PM = PM_C / VpmA;
double C_PMP = PM_P / V2pmA;
double cPsp = PM_SP / VspA;
double cPli = PM_LI / VliA;
double cPbm = PM_BM / VbmA;
double cPsk = PM_SK / VskA;
double cPkid = PM_KID / VkidA;
double cPcoc = PM_COC / VCOC;
dxdt_PM_D = -KA_PM * PM_D;
dxdt_PM_C = KA_PM * PM_D - CLpm * C_PM - Qpm * (C_PM - C_PMP);
dxdt_PM_P = Qpm * (C_PM - C_PMP);
dxdt_PM_SP = KIN_PM * C_PM * VspA - KOUT_PM * PM_SP;
dxdt_PM_LI = KIN_PM * C_PM * VliA - KOUT_PM * PM_LI;
dxdt_PM_BM = KIN_PM * C_PM * VbmA - KOUT_PM * PM_BM;
dxdt_PM_SK = FSK_PM * KIN_PM * C_PM * VskA - KOUT_PM * PM_SK;
dxdt_PM_KID = KIN_PMK * C_PM * VkidA - KOUT_PMK * PM_KID;
dxdt_PM_COC = KIN_COC * C_PM * VCOC - KOUT_COC * PM_COC;
// =========================================================================
// 4. ANTIMONY -- activation and escape share one thiol chemistry
// =========================================================================
double C_SB5 = SB5_C / VsbA;
double C_SBD = SB_DEP / V2sbA;
double cSsp = SB3_SP / VspA;
double cSli = SB3_LI / VliA;
double cSbm = SB3_BM / VbmA;
double cSsk = SB3_SK / VskA;
dxdt_SB5_D = -KA_SB * SB5_D;
dxdt_SB5_C = KA_SB * SB5_D - CLsb * C_SB5 - Qsb * (C_SB5 - C_SBD);
dxdt_SB5_P = 0.0;
dxdt_SB_DEP = Qsb * (C_SB5 - C_SBD);
// Resistance is modelled as INCREASED EFFLUX (MRPA / Sb-trypanothione
// conjugate export), not as a change in target affinity. That is why dose
// escalation cannot recover a resistant strain in this model: raising the
// dose raises the intracellular load, and the efflux term is proportional to
// exactly that load, while QTc and lipase are not.
double keff = KEFF_SB * RES_SB;
dxdt_SB3_SP = KRED * C_SB5 * VspA - keff * SB3_SP;
dxdt_SB3_LI = KRED * C_SB5 * VliA - keff * SB3_LI;
dxdt_SB3_BM = KRED * C_SB5 * VbmA - keff * SB3_BM;
dxdt_SB3_SK = KPSK_SB * KRED * C_SB5 * VskA - keff * SB3_SK;
// =========================================================================
// 5. IMMUNITY
// =========================================================================
double P_SP = P_SP_S + P_SP_R;
double P_LI = P_LI_S + P_LI_R;
double P_BM = P_BM_S + P_BM_R;
double P_SK = P_SK_S + P_SK_R;
double PTOT = P_SP + P_LI + P_BM + P_SK;
if (PTOT < 0.0) PTOT = 0.0;
// KAG << K50_IL10 is a structural statement, not a fitted convenience.
// Antigen is still abundant over a burden range in which IL-10 has already
// switched off. That window -- roughly 1e4 to 6e7 amastigotes -- is where
// the host can be primed, and getting the patient into it and holding them
// there is the entire job of a drug course.
double PVIS = P_SP + P_LI + P_BM;
// Three signals, three thresholds, and TWO DIFFERENT SOURCES.
// AG = antigen availability, from the TOTAL burden. Dermal parasites do
// prime T cells; that is why PKDL patients are leishmanin-positive.
// AGH = the IL-10 signal, from the VISCERAL burden only.
// AGS = the systemic-illness signal, also visceral only.
// BUG FOUND: keying IL-10 to the total burden let a growing dermal reservoir
// re-immunosuppress the host -- skin load climbed past K50_IL10, IL-10 came
// back on, macrophage activation collapsed and the viscera regrew, so EVERY
// regimen relapsed. That is backwards: PKDL patients are not
// immunosuppressed, and the IL-10 of active kala-azar comes from spleen and
// marrow, not from skin lesions.
double AG = PTOT / (PTOT + KAG);
double AGH = pow(PVIS, HIL10) / (pow(PVIS, HIL10) + pow(K50_IL10, HIL10));
// A THIRD threshold, above the IL-10 one, for systemic illness. Keyed to AG
// (which saturates at 1e4 amastigotes) the clinical module made a host
// carrying a controlled subclinical infection febrile and anaemic.
double AGS = PVIS / (PVIS + K50_SYS);
double FCD4 = CD4 / (CD4 + KCD4);
double prime = 1.0 - 0.55 * MALNUT;
dxdt_TMEM = KTP * prime * AG * FCD4 * (1.0 - TMEM / TMEMAX)
/ (1.0 + IL10 / KI_T) - KTD * TMEM;
dxdt_IFNG = KIP * (FAG_IFN * AG + TMEM) * FCD4 - KID * IFNG;
dxdt_IL10 = KLP * AGH - KLD * IL10;
dxdt_TNFA = KNP * AGS - KND * TNFA;
// BUG FOUND: driven by AGH, not AG. With AG the TGF-beta term stayed near
// maximal down to 1e4 amastigotes and permanently clamped macrophage
// activation, so no slow drug could ever hand off to the host.
dxdt_TGFB = KGP * (0.5 * AGH + IL10) - KGD * TGFB;
// BUG FOUND: CD4 is a HOMEOSTATIC pool with a set point. An earlier version
// had only the loss term, so every immunocompetent patient drifted to CD4 = 4
// over an 18-month follow-up and the host arm silently switched off.
double cd4set = (HIV < 0.5) ? CD4SET : (CD4SET_ART * ART + CD40 * (1.0 - ART));
dxdt_CD4 = KCD4H * (cd4set - CD4) - KCD4L * AG * CD4 * (1.0 + 0.5 * HIV);
double MACTdrive = (IFNG / (IFNG + KI_IFN))
/ (1.0 + IL10 / KI_IL10 + TGFB / KI_TGFB)
* FCD4
* (1.0 - (1.0 - FHIV_MAC) * HIV);
dxdt_MPHA = KMPH * (MACTdrive - MPHA);
double MACT = (MPHA > 0.0) ? MPHA : 0.0;
double kimm = KIMM * MACT;
// =========================================================================
// 6. PARASITE DYNAMICS
// Two populations per organ. The quiescent pool is not a resistance
// genotype, it is a physiological state, and it is where every relapse in
// this model comes from: all four drugs need a metabolically active cell
// (ergosterol turnover, inward transport, active translation, prodrug
// reduction), and the macrophage sees quiescent forms poorly too.
// =========================================================================
double kSa, kSm, kSp, kSs, kRa, kRm, kRp, kRs;
// -- spleen ---------------------------------------------------------------
kSa = _EMX(cAsp, EC50_A, EMAX_A, HILL_A);
kSm = _EMX(cMsp, EC50_M * RES_M, EMAX_M, HILL_M);
kSp = _EMX(cPsp, EC50_P * RES_P, EMAX_P, HILL_P);
kSs = _EMX(cSsp, EC50_S, EMAX_S, HILL_S);
kRa = _EMX(cAsp, EC50_A * RFAC_A, EMAX_A, HILL_A);
kRm = _EMX(cMsp, EC50_M * RES_M * RFAC_M, EMAX_M, HILL_M);
kRp = _EMX(cPsp, EC50_P * RES_P * RFAC_P, EMAX_P, HILL_P);
kRs = _EMX(cSsp, EC50_S * RFAC_S, EMAX_S, HILL_S);
double killS_SP = kSa + kSm + kSp + kSs; // Bliss independence
double killR_SP = kRa + kRm + kRp + kRs;
// -- liver ----------------------------------------------------------------
kSa = _EMX(cAli, EC50_A, EMAX_A, HILL_A);
kSm = _EMX(cMli, EC50_M * RES_M, EMAX_M, HILL_M);
kSp = _EMX(cPli, EC50_P * RES_P, EMAX_P, HILL_P);
kSs = _EMX(cSli, EC50_S, EMAX_S, HILL_S);
kRa = _EMX(cAli, EC50_A * RFAC_A, EMAX_A, HILL_A);
kRm = _EMX(cMli, EC50_M * RES_M * RFAC_M, EMAX_M, HILL_M);
kRp = _EMX(cPli, EC50_P * RES_P * RFAC_P, EMAX_P, HILL_P);
kRs = _EMX(cSli, EC50_S * RFAC_S, EMAX_S, HILL_S);
double killS_LI = kSa + kSm + kSp + kSs;
double killR_LI = kRa + kRm + kRp + kRs;
// -- marrow ---------------------------------------------------------------
kSa = _EMX(cAbm, EC50_A, EMAX_A, HILL_A);
kSm = _EMX(cMbm, EC50_M * RES_M, EMAX_M, HILL_M);
kSp = _EMX(cPbm, EC50_P * RES_P, EMAX_P, HILL_P);
kSs = _EMX(cSbm, EC50_S, EMAX_S, HILL_S);
kRa = _EMX(cAbm, EC50_A * RFAC_A, EMAX_A, HILL_A);
kRm = _EMX(cMbm, EC50_M * RES_M * RFAC_M, EMAX_M, HILL_M);
kRp = _EMX(cPbm, EC50_P * RES_P * RFAC_P, EMAX_P, HILL_P);
kRs = _EMX(cSbm, EC50_S * RFAC_S, EMAX_S, HILL_S);
double killS_BM = kSa + kSm + kSp + kSs;
double killR_BM = kRa + kRm + kRp + kRs;
// -- skin -----------------------------------------------------------------
kSa = _EMX(cAsk, EC50_A, EMAX_A, HILL_A);
kSm = _EMX(cMsk, EC50_M * RES_M, EMAX_M, HILL_M);
kSp = _EMX(cPsk, EC50_P * RES_P, EMAX_P, HILL_P);
kSs = _EMX(cSsk, EC50_S, EMAX_S, HILL_S);
kRa = _EMX(cAsk, EC50_A * RFAC_A, EMAX_A, HILL_A);
kRm = _EMX(cMsk, EC50_M * RES_M * RFAC_M, EMAX_M, HILL_M);
kRp = _EMX(cPsk, EC50_P * RES_P * RFAC_P, EMAX_P, HILL_P);
kRs = _EMX(cSsk, EC50_S * RFAC_S, EMAX_S, HILL_S);
double killS_SK = kSa + kSm + kSp + kSs;
double killR_SK = kRa + kRm + kRp + kRs;
// Inter-organ trafficking of infected monocytes, written as a mass-conserving
// redistribution toward each compartment's equilibrium share so it can never
// create parasites from nothing. BUG FOUND: an earlier version scaled this
// by an extra 1e-4, giving an effective rate of 2e-8 per hour -- not
// trafficking but zero, so a dermal sandfly inoculum stayed in the skin for
// eighteen months and never visceralised. Only REPLICATING amastigotes
// traffic; quiescent forms are arrested.
// Trafficking is ASYMMETRIC, and it has to be. Spleen, liver and marrow share
// the blood monocyte pool and redistribute freely. The dermis receives
// infected monocytes from that pool, but its own macrophages are largely
// resident and do not recirculate.
// BUG FOUND (twice): written first with an extra 1e-4 factor the effective
// rate was 2e-8 /h -- not trafficking but zero, so a dermal inoculum never
// visceralised. Written SYMMETRICALLY, the immune-privileged skin became an
// incurable reservoir that re-seeded the viscera and ALL TWENTY regimens
// relapsed -- whereas in reality most cured patients never develop PKDL and
// PKDL patients rarely relapse to visceral disease.
double pmax_vis = PMAX_SP + PMAX_LI + PMAX_BM;
double PS_VIS = fmax(P_SP_S, 0.0) + fmax(P_LI_S, 0.0) + fmax(P_BM_S, 0.0);
double net_to_skin = KMIG_SKIN * PS_VIS - KMIG_BACK * fmax(P_SK_S, 0.0);
double crowd, S, R, kq, seed;
// NOTE: there is deliberately NO extinction floor in this block. Writing
// `if (P < 1e-7 && dxdt > 0) dxdt = 0` here is a discontinuous switch that
// flips between solver probes as soon as any compartment clears; it stalls
// the integrator completely (a 28-day miltefosine course failed to finish).
// The system as written is homogeneous in the parasite states, so a cleared
// compartment decays smoothly and cannot regrow on its own. Apply the
// one-amastigote floor between calls -- see `vl_clamp_extinct()` below.
crowd = 1.0 - P_SP / PMAX_SP; if (crowd < 0.0) crowd = 0.0;
S = (P_SP_S > 0.0) ? P_SP_S : 0.0; R = (P_SP_R > 0.0) ? P_SP_R : 0.0;
kq = KQ0 + KQS * (killS_SP + kimm);
seed = KMIG * ((PMAX_SP / pmax_vis) * PS_VIS - fmax(P_SP_S, 0.0))
- (PMAX_SP / pmax_vis) * net_to_skin;
dxdt_P_SP_S = S * (KG_SP * crowd - kimm - killS_SP) - kq * S + KR_REACT * R
+ seed;
dxdt_P_SP_R = R * (KG_SP * COSTR * crowd - FIMM_R * kimm - killR_SP)
+ kq * S - KR_REACT * R;
crowd = 1.0 - P_LI / PMAX_LI; if (crowd < 0.0) crowd = 0.0;
S = (P_LI_S > 0.0) ? P_LI_S : 0.0; R = (P_LI_R > 0.0) ? P_LI_R : 0.0;
kq = KQ0 + KQS * (killS_LI + kimm);
seed = KMIG * ((PMAX_LI / pmax_vis) * PS_VIS - fmax(P_LI_S, 0.0))
- (PMAX_LI / pmax_vis) * net_to_skin;
dxdt_P_LI_S = S * (KG_LI * crowd - kimm - killS_LI) - kq * S + KR_REACT * R
+ seed;
dxdt_P_LI_R = R * (KG_LI * COSTR * crowd - FIMM_R * kimm - killR_LI)
+ kq * S - KR_REACT * R;
crowd = 1.0 - P_BM / PMAX_BM; if (crowd < 0.0) crowd = 0.0;
S = (P_BM_S > 0.0) ? P_BM_S : 0.0; R = (P_BM_R > 0.0) ? P_BM_R : 0.0;
kq = KQ0 + KQS * (killS_BM + kimm);
seed = KMIG * ((PMAX_BM / pmax_vis) * PS_VIS - fmax(P_BM_S, 0.0))
- (PMAX_BM / pmax_vis) * net_to_skin;
dxdt_P_BM_S = S * (KG_BM * crowd - kimm - killS_BM) - kq * S + KR_REACT * R
+ seed;
dxdt_P_BM_R = R * (KG_BM * COSTR * crowd - FIMM_R * kimm - killR_BM)
+ kq * S - KR_REACT * R;
// The dermis is relatively immune-privileged for this parasite, and it has to
// be: PKDL lesions persist for years in hosts whose systemic immunity has
// fully returned. With dermal killing set equal to splenic killing the model
// made untreated PKDL self-resolving, which it is not in South Asia.
double kimm_sk = kimm * FIMM_SK;
crowd = 1.0 - P_SK / PMAX_SK; if (crowd < 0.0) crowd = 0.0;
S = (P_SK_S > 0.0) ? P_SK_S : 0.0; R = (P_SK_R > 0.0) ? P_SK_R : 0.0;
kq = KQ0 + KQS * (killS_SK + kimm_sk);
seed = net_to_skin;
dxdt_P_SK_S = S * (KG_SK * crowd - kimm_sk - killS_SK) - kq * S + KR_REACT * R
+ seed;
dxdt_P_SK_R = R * (KG_SK * COSTR * crowd - FIMM_R * kimm_sk - killR_SK)
+ kq * S - KR_REACT * R;
// =========================================================================
// 7. CLINICAL
// =========================================================================
double spl_target = SPL0 + SPLMAX * P_SP / (P_SP + K50_SPL);
dxdt_SPL = KSPL * (spl_target - SPL);
double liv_target = LIV0 + LIVMAX * P_LI / (P_LI + 3.0 * K50_SPL);
dxdt_LIVS = KLIV * (liv_target - LIVS);
// Two independent mechanisms, not one: marrow occupancy plus hypersplenic
// destruction. Platelets carry the largest spleen coefficient, which is why
// thrombocytopenia tracks spleen size and anaemia does not.
double marrow = 1.0 / (1.0 + P_BM / (0.35 * PMAX_BM));
double inflam = 1.0 / (1.0 + TNFA / 0.30);
dxdt_HGB = KHGB * HGB0 * (1.0 - FSUP_HGB * (1.0 - marrow * inflam))
- (KHGB + KSPL_HGB * KHGB * SPL) * HGB;
dxdt_PLT = KPLT * PLT0 * marrow - (KPLT + KSPL_PLT * KPLT * SPL) * PLT;
dxdt_WBC = KWBC * WBC0 * marrow * inflam
- (KWBC + KSPL_WBC * KWBC * SPL) * WBC;
dxdt_ALB = KALB * (ALB0 * (1.0 - 0.42 * AGS) - ALB);
dxdt_IGG = KIGG_P * AG - KIGG_D * (IGG - IGG0);
dxdt_TEMP = KTEMP * (TEMP0 + TNF_FEV * TNFA / (TNFA + 0.45) - TEMP);
dxdt_BWTL = KBWL * (BWLMAX * AGS - BWTL);
// PKDL: dermal amastigotes become lesions only when immunity RETURNS, which
// is why the rash appears AFTER apparently successful treatment
dxdt_PKDL = KPKDL_P * P_SK * MACT - KPKDL_D * PKDL;
// =========================================================================
// 8. TOXICITY
// =========================================================================
dxdt_TUBI = KTUB * cAkid - KTUBR * TUBI;
double gfr = GFRb / (1.0 + ((TUBI > 0.0) ? TUBI : 0.0));
if (gfr < 1.0) gfr = 1.0;
dxdt_SCR = KSCR * (SCR0 * GFRb / gfr - SCR);
dxdt_KSER = KKR * (K_K0 - KSER) - KWK * cAkid;
dxdt_MGSER = KMGR * (MG0 - MGSER) - KWMG * cAkid;
dxdt_HEAR = KHEAR * cPcoc; // irreversible: no repair term
dxdt_QTC = KQTC * C_SBD * KQTCR * 50.0 - KQTCR * (QTC - QTC0);
dxdt_LIPA = KLIPA * C_SB5 - KLIPAR * (LIPA - LIPA0);
dxdt_ALTX = KALTX * C_SB5 + KALT_M * C_MIL - KALTR * (ALTX - ALT0);
dxdt_GITX = KGITX * C_MIL / (C_MIL + EM50_GI) - KGITR * GITX;
// =========================================================================
// 9. MORTALITY HAZARD AND EXPOSURE INTEGRALS
// =========================================================================
double dh_hgb = (HGB_H - HGB) > 0.0 ? (HGB_H - HGB) / HGB_H : 0.0;
double dh_alb = (ALB_H - ALB) > 0.0 ? (ALB_H - ALB) / ALB_H : 0.0;
double dh_wbc = (WBC_H - WBC) > 0.0 ? (WBC_H - WBC) / WBC_H : 0.0;
double haz = H0 * (1.0 + 2.2 * dh_hgb) * (1.0 + 2.6 * dh_alb)
* (1.0 + 2.0 * dh_wbc) * (0.15 + 0.85 * AGS)
* (1.0 + 1.6 * HIV);
dxdt_AUCFRE = C_FRE; // the nephrotoxicity integral
dxdt_AUCASP = cAsp; // the efficacy integral -- SAME DOSE, DIFFERENT ORGAN
dxdt_AUCMSP = cMsp;
dxdt_AUCBSP = cSsp;
dxdt_AUCPSP = cPsp;
dxdt_CUMHAZ = haz;
dxdt_CUMDOSE = 0.0; // incremented in $MAIN-free fashion by the caller
$TABLE
double PTOT_OUT = P_SP_S + P_SP_R + P_LI_S + P_LI_R
+ P_BM_S + P_BM_R + P_SK_S + P_SK_R;
if (PTOT_OUT < 0.0) PTOT_OUT = 0.0;
double LOG10P = log10(PTOT_OUT + 1e-12);
double SURV = exp(-CUMHAZ);
double CFRAC = 100.0 * (1.0 - SURV);
// splenic aspirate grade: the clinical reference standard is a log scale,
// so report the model burden on it (grade 6+ = >100 parasites/field)
double SPLGRADE = log10(P_SP_S + P_SP_R + 1e-12) - log10(0.003);
if (SPLGRADE < 0.0) SPLGRADE = 0.0;
if (SPLGRADE > 6.0) SPLGRADE = 6.0;
double CFRE_OUT = A_FRE / (V_FRE * WT);
double CLIP_OUT = A_LIP / (V_LIP * WT);
double CMIL_OUT = MIL_C / (V1_MIL * (WT / 70.0));
double CASP_OUT = AMB_SP / (VSP * (WT / 70.0));
double CMSP_OUT = MIL_SP / (VSP * (WT / 70.0));
double CPSP_OUT = PM_SP / (VSP * (WT / 70.0));
double CSSP_OUT = SB3_SP / (VSP * (WT / 70.0));
$CAPTURE PTOT_OUT LOG10P SURV CFRAC SPLGRADE CFRE_OUT CLIP_OUT CMIL_OUT
$CAPTURE CASP_OUT CMSP_OUT CPSP_OUT CSSP_OUT
'
vl_mod <- mcode("vl_qsp", vl_code)
## =============================================================================
## The one-amastigote floor, applied BETWEEN integration calls
## =============================================================================
## A population smaller than one organism does not exist. Enforcing that is
## both biologically correct and what stops the ODE from "relapsing" out of
## 1e-300. It MUST NOT go inside $ODE (see the note there); mrgsolve lets us
## do it properly by simulating in segments and resetting the initial
## condition between them.
EXTINCT <- 1e-6 # burden units = one whole amastigote
PAR_CMT <- c("P_SP_S", "P_SP_R", "P_LI_S", "P_LI_R",
"P_BM_S", "P_BM_R", "P_SK_S", "P_SK_R")
vl_clamp_extinct <- function(x) {
x[PAR_CMT] <- lapply(x[PAR_CMT], function(v) ifelse(v < EXTINCT, 0, v))
x
}
#' Simulate a regimen in 14-day segments, applying the extinction floor at
#' each segment boundary.
#'
#' @param mod an mrgsolve model object
#' @param dosing a data frame of events (mrgsolve event format)
#' @param par named list of parameter overrides
#' @param days follow-up duration in days
vl_simulate <- function(mod = vl_mod, dosing = NULL, par = list(),
days = 540, delta = 6, seg_days = 14) {
m <- mod
if (length(par)) m <- param(m, par)
edges <- unique(c(seq(0, days, by = seg_days), days))
out <- NULL
init_now <- NULL
for (i in seq_len(length(edges) - 1L)) {
t0 <- edges[i] * 24
t1 <- edges[i + 1L] * 24
mm <- m
if (!is.null(init_now)) mm <- init(mm, init_now)
ev_seg <- NULL
if (!is.null(dosing)) {
ev_seg <- dosing[dosing$time >= t0 & dosing$time < t1, , drop = FALSE]
if (nrow(ev_seg) == 0) ev_seg <- NULL
}
sim <- mm %>%
(function(z) if (is.null(ev_seg)) z else data_set(z, ev_seg)) %>%
mrgsim(start = t0, end = t1, delta = delta, hmax = 2,
recover = "numeric") %>%
as.data.frame()
out <- rbind(out, if (i == 1L) sim else sim[sim$time > t0, , drop = FALSE])
last <- sim[nrow(sim), , drop = FALSE]
init_now <- vl_clamp_extinct(
as.list(last[, names(last) %in% names(init(m)@data), drop = FALSE]))
}
out$day <- out$time / 24
out
}
## =============================================================================
## Regimen library -- 20 scenarios
## mg/kg doses are converted with the subject's weight; parenteral routes go
## to their own compartment so no route is silently assumed.
## =============================================================================
CMT_LAMB <- 1; CMT_DAMB <- 2; CMT_MIL <- 9; CMT_PM <- 16; CMT_SB <- 25
vl_ev <- function(cmt, mgkg = NULL, mg = NULL, start_day = 0, n = 1,
ii_h = 24, wt = 50) {
amt <- if (is.null(mg)) mgkg * wt else mg
data.frame(ID = 1, time = start_day * 24 + (seq_len(n) - 1L) * ii_h,
cmt = cmt, amt = amt, evid = 1)
}
vl_regimens <- function(wt = 50) {
list(
## --- natural history -------------------------------------------------
S01_untreated = NULL,
## --- pentavalent antimony -------------------------------------------
S02_ssg_africa = vl_ev(CMT_SB, mgkg = 20, n = 30, wt = wt),
S03_ssg_bihar_res = vl_ev(CMT_SB, mgkg = 20, n = 30, wt = wt),
## --- amphotericin B --------------------------------------------------
S04_damb_alt30 = vl_ev(CMT_DAMB, mgkg = 1, n = 15, ii_h = 48, wt = wt),
S05_lamb_single10 = vl_ev(CMT_LAMB, mgkg = 10, n = 1, wt = wt),
S06_lamb_21_multi = rbind(
vl_ev(CMT_LAMB, mgkg = 3, n = 5, wt = wt),
vl_ev(CMT_LAMB, mgkg = 3, start_day = 13, n = 1, wt = wt),
vl_ev(CMT_LAMB, mgkg = 3, start_day = 20, n = 1, wt = wt)),
S07_lamb_5x3 = vl_ev(CMT_LAMB, mgkg = 3, n = 5, wt = wt),
## --- miltefosine, and the allometry trap -----------------------------
S08_mil28_adult = vl_ev(CMT_MIL, mgkg = 2.5, n = 28, wt = wt),
S09_mil28_child_linear = vl_ev(CMT_MIL, mgkg = 2.5, n = 28, wt = 10),
## the mg/day that gives a 10 kg child the SAME AUC as 125 mg/day in a
## 50 kg adult, i.e. scaled by WT^0.75 instead of WT^1.0
S10_mil28_child_allom = vl_ev(CMT_MIL, mg = 125 * (10 / 50)^0.75, n = 28),
## --- paromomycin -----------------------------------------------------
S11_pm21 = vl_ev(CMT_PM, mgkg = 15, n = 21, wt = wt),
S12_pm21_africa = vl_ev(CMT_PM, mgkg = 15, n = 21, wt = wt),
## --- combinations: synergy in TIME, not in concentration -------------
S13_lamb5_mil7 = rbind(
vl_ev(CMT_LAMB, mgkg = 5, n = 1, wt = wt),
vl_ev(CMT_MIL, mgkg = 2.5, start_day = 1, n = 7, wt = wt)),
S14_lamb5_pm10 = rbind(
vl_ev(CMT_LAMB, mgkg = 5, n = 1, wt = wt),
vl_ev(CMT_PM, mgkg = 15, start_day = 1, n = 10, wt = wt)),
S15_mil10_pm10 = rbind(
vl_ev(CMT_MIL, mgkg = 2.5, n = 10, wt = wt),
vl_ev(CMT_PM, mgkg = 15, n = 10, wt = wt)),
S16_ssg_pm17 = rbind(
vl_ev(CMT_SB, mgkg = 20, n = 17, wt = wt),
vl_ev(CMT_PM, mgkg = 15, n = 17, wt = wt)),
## --- HIV co-infection ------------------------------------------------
S17_hiv_lamb10 = vl_ev(CMT_LAMB, mgkg = 10, n = 1, wt = wt),
S18_hiv_lamb30_mil28 = rbind(
vl_ev(CMT_LAMB, mgkg = 5, start_day = 0, n = 6, ii_h = 48, wt = wt),
vl_ev(CMT_MIL, mgkg = 2.5, n = 28, wt = wt)),
## --- PKDL ------------------------------------------------------------
S19_pkdl_mil84 = vl_ev(CMT_MIL, mgkg = 2.5, n = 84, wt = wt),
S20_pkdl_lamb = vl_ev(CMT_LAMB, mgkg = 5, n = 4, ii_h = 7 * 24, wt = wt)
)
}
vl_scenario_par <- function(name) {
p <- list()
## resistance is an EFFLUX parameter; FR0 is the quiescent pool and has
## nothing to do with antimony susceptibility
if (name == "S02_ssg_africa") p$RES_SB <- 1.0
if (name == "S03_ssg_bihar_res") p$RES_SB <- 9.0
if (name %in% c("S09_mil28_child_linear", "S10_mil28_child_allom")) {
p$WT <- 10; p$AGE <- 3; p$MALNUT <- 0.45
}
if (name == "S12_pm21_africa") p$EC50_P <- 25.0 * 1.60
if (name == "S17_hiv_lamb10") {
## the common real-world sequence: VL treated before ART is started, so
## there is no CD4 recovery during the window that decides cure
p$HIV <- 1; p$ART <- 0; p$CD40 <- 90
}
if (name == "S18_hiv_lamb30_mil28") { p$HIV <- 1; p$ART <- 1; p$CD40 <- 90 }
p
}
## PKDL scenarios start from a different patient: visceral compartments
## cured, dermal amastigotes still present, immunity restored -- which is
## exactly the state that makes the lesions appear.
vl_pkdl_init <- function() list(
P_SP_S = 0, P_SP_R = 0, P_LI_S = 0, P_LI_R = 0, P_BM_S = 0, P_BM_R = 0,
P_SK_S = 45 * (1 - 5e-4), P_SK_R = 45 * 5e-4,
TMEM = 0.85, IFNG = 0.30, IL10 = 0.08, TNFA = 0.10, TGFB = 0.12,
MPHA = 0.45, SPL = 1.5, HGB = 12.2, PLT = 210, WBC = 5.4, ALB = 3.9,
IGG = 2.9, TEMP = 36.9, PKDL = 1.2)
## =============================================================================
## Outcome classification
## Every cure rate this model reports depends on these three thresholds, so
## they are stated once, here, and nowhere else.
## =============================================================================
vl_outcome <- function(sim, eot_day) {
## IMPORTANT: cure and relapse are judged on the VISCERAL compartments
## (spleen + liver + marrow), not on total body burden. That is what
## "definitive cure at 6 months" means in every VL trial ever run. The
## dermal compartment clears far more slowly -- little drug reaches it and
## the dermis is relatively immune-privileged -- and its residue is what
## becomes PKDL. Scoring skin residue as VL treatment failure made all
## twenty regimens "relapse", which is a finding about the wrong endpoint.
## Skin burden and lesion load are reported separately, exactly as trials
## report PKDL incidence separately from cure rate.
PV <- sim$P_SP_S + sim$P_SP_R + sim$P_LI_S + sim$P_LI_R +
sim$P_BM_S + sim$P_BM_R
PSK <- sim$P_SK_S + sim$P_SK_R
d <- sim$day
i0 <- which.min(abs(d - eot_day))
P0 <- PV[1]
post <- PV[i0:length(PV)]
nadir <- min(post)
Pend <- PV[length(PV)]