PROGRAM malathion_postnatal_rat

	INITIAL
  !Abbreviations: 
  !MAL--malathion
  !MOX--malaoxon
  !DMP--dimethyl phosphate metabolites
  !MCA--malathion monocarboxylic acid 
  !DCA--malathion dicarboxylic acid
  !AChE--acetylcholinesterase
  !BuChE--butyrlcholinesterase
  !CaE--carboxylesterase

  !no skin compartment/dermal exposure or lung compartment/inhalation exposure in postnatal rat

  !compartments included for liver, kidney, brain, fat, and lumped for slow and rapidly perfused. 
  !exposure routes:  oral 
  !bioactivation (MAL -> MOX) occurs in liver 
  !inhibition of B-esterases (AChE, BuChE, CaE) described in liver, kidney, brain, plasma, RBCs. 

  !detoxification of MAL by CaE occurs in liver, kidney, brain, plasma, RBCs (to MCA/DCA; these are modeled as a single compartment). 
  !detoxificatoin of oxon by B-esterases is stoichiometric; the oxon-enzyme complex serves as a "trap" for the oxon.
  !CaE assumed to undergo reactivation; AChE and BuChE assumed to undergo reactivation/aging.

!Physiological parameters--rat
  !blood flows (as fraction of cardiac output)
  constant MVC = 0.0    !minute ventilation rate (L/kg/BW)
  constant QCC = 0.0    !cardiac output (L/hr/kg BW^0.75)
  constant QFC = 0.0    !fraction of cardiac output to fat 
  constant QLC = 0.0    !fraction of cardiac output to liver
  constant QKC = 0.0    !fraction of cardiac output to kidney
  constant QBrC = 0.0   !fraction of cardiac output to brain
  constant QRC = 0.0    !fraction of cardiac output to richly perfused tissues

  variable time = 0.0   !hr

  constant AGE0 = 1.0   !age
  
  !tissue volumes (as fraction of BW)
  constant BW0 = 0.0     !rat body weight (kg)
  constant VBLC = 0.0    !fractional volume of blood
  constant VFC = 0.0     !fractional volume of fat
  constant VKC = 0.0     !fractional volume of kidney
  constant VSC = 0.0     !fractional volume of slowly perfused tissues
  constant HCT = 0.0     !hematocrit
  constant VRC = 0.0     !rapidly perfused
  constant VINTC = 0.0   !intestine
  
  !partition coefficients (tissue:blood); from 2007 USEPA malathion lice assessment
  !malathion
  constant PMalF = 0.0    !fat:blood
  constant PMalR = 0.0    !richly perfused:blood
  constant PMalL = 0.0    !liver:blood
  constant PMalK = 0.0    !kidney:blood
  constant PMalBr = 0.0   !brain:blood
  constant PMalS = 0.0    !slowly perfused:blood
  
  !malaoxon
  constant PMoxF = 0.0   !fat:blood
  constant PMoxR = 0.0   !richly perfused:blood
  constant PMoxL = 0.0   !liver:blood
  constant PMoxK = 0.0   !kidney:blood
  constant PMoxBr = 0.0  !brain:blood
  constant PMoxS = 0.0   !slowly perfused: blood

  !volumes of distribution for metabolite compartment
  constant V1 = 0.0      !MCA + DCA (L)

  
  !metabolism parameters
  !maximum rates of metabolism (umol/hr/kg tissue)
  !malathion detoxification 
  constant VMAXMALLC = 0.0       !liver--CaE; based on in vitro data (Chambers & Meek 2017) 
  constant VMAXMALKC = 0.0       !kidney--CaE; 60% of liver, based on Talcott 1979
  constant VMAXMALBLC = 0.0      !plasma--CaE(umol/hr/L serum); CaE--74% of liver, based on Talcott 1979
  constant VMAXMALBRC = 0.0      !brain--CaE; 5% of liver, based on Talcott 1979

  
  !malathion oxidation--malathion to oxon
  constant VMAXMALMOXC = 0.0     !liver--CYPs; based on in vitro data (Chambers & Meek 2017)

  !oxon detox--fit to oxon oral dose data
  constant VMOXDMPLC = 0.0       !liver
  constant VMOXDMPPC = 0.0       !plasma
  constant VMOXDMPBC = 0.0       !brain
  constant VMOXDMPKC = 0.0       !kidney

  !affinity constants (umol/L)
  !malathion detoxification
  constant KMMALL = 0.0    !liver--CaE (Chambers & Meek 2017)
  constant KMMALK = 0.0    !kidney--CaE
  constant KMMALBL = 0.0   !plasma--CaE
  constant KMMALBR = 0.0   !brain--CaE

  !malathion oxidation--malathion to oxon
  constant KMMALMOX = 0.0  !liver--CYPs; based on in vitro data (Chambers & Meek 2017)

  constant KMOXDMPL = 0.0        !liver
  constant KMOXDMPP = 0.0        !plasma
  constant KMOXDMPB = 0.0        !brain
  constant KMOXDMPK = 0.0        !kidney
  constant KI = 0.0              !dissociation constant

  !pharmacodynamics--esterase inhibition
  !Enzyme turnover rates (umol hydrolysis/h/umol active sites)--not chemical specific
  constant TRCE=0.0		!AChE (all tissues)
  constant TRBE=0.0		!BuCHE (all tissue)
  constant TRCR=0.0		!CaE  (all tissues)

  !Enzyme activities (umol/hr/kg tissue)--not chemical-specific
  !AChE
  constant BACHE=0.0		!brain AChE
  constant HACHE=0.0		!liver AChE
  constant BLACHE=0.0	 !Plasma AChE
  constant RBCHE=0.0		!RBC AChE
  constant KACHE=0.0    !kidney AChE

  !BuChE
  constant BBUCE=0.0		!brain BuChE
  constant HBUCE=0.0		!liver BuChE
  constant BLBUCE=0.0	 !Plasma BuChE
  constant KBUCE=0.0    !kidney BuChE

  !CaE
  constant BRCE=0.0     !Brain CaE
  constant HECE=0.0     !liver CaE
  constant PLOCE=0.0		!Plasma CaE
  constant KECE=0.0     !kidney CaE

  !chemical-specific parameters for inhibition
  !liver AChE rate constants
  constant KDHCE=0.0	! degradation of esterase (/hr)
  constant KIHCE=0.0	! inhibition of esterase (per umol/L/hr)
  constant KRHCE=0.0	! reactivation of esterase (/hr)
  constant KAHCE=0.0	! aging of esterase (/hr)

 !liver BuChE rate constants
  constant KDHBE=0.0	! degradation of esterase (/hr)
  constant KIHBE=0.0	! inhibition of esterase (per umol/L/hr)
  constant KRHBE=0.0	! reactivation of esterase (/hr)
  constant KAHBE=0.0	! aging of esterase (/hr)

 !liver CaE rate constants
  constant KDHCR=0.0	! degradation of esterase (/hr)
  constant KIHCR=0.0	! inhibition of esterase (per umol/L/hr)
  constant KRHCR=0.0	! reactivation of esterase (/hr)
  constant KAHCR=0.0	! aging of esterase (/hr)

 !brain AChE rate constants
 constant KDBCE=0.0	! degradation of esterase (/hr)
 constant KIBCE=0.0	! inhibition of esterase (per umol/L/hr)
 constant KRBCE=0.0	! reactivation of esterase (/hr)
 constant KABCE=0.0	! aging of esterase (/hr)

 !brain BuChE rate constants
 constant KDBBE=0.0	! degradation of esterase (/hr)
 constant KIBBE=0.0	! inhibition of esterase (per umol/L/hr)
 constant KRBBE=0.0	! reactivation of esterase (/hr)
 constant KABBE=0.0	! aging of esterase (/hr)

 !brain CaE rate constants
 constant KDBCR=0.0	!degradation of esterase (/hr)
 constant KIBCR=0.0	!inhibition of esterase (per umol/L/hr)
 constant KRBCR=0.0	!reactivation of esterase (/hr)
 constant KABCR=0.0	!aging of esterase (/hr)

!kidney AChE rate constants
constant KDKCE=0.0	! degradation of esterase (/hr)
constant KIKCE=0.0	! inhibition of esterase (per umol/L/hr)
constant KRKCE=0.0	! HR-1;reactivation of esterase
constant KAKCE=0.0	! aging of esterase (/hr)

!kidney BuChE rate constants
constant KDKBE=0.0	! degradation of esterase (/hr)
constant KIKBE=0.0	! inhibition of esterase (per umol/L/hr)
constant KRKBE=0.0	! reactivation of esterase (/hr)
constant KAKBE=0.0	! aging of esterase (/hr)

!kidney CaE rate constants
constant KDKCR=0.0	! degradation of esterase (/hr)
constant KIKCR=0.0	! inhibition of esterase (per umol/L/hr)
constant KRKCR=0.0	! reactivation of esterase (/hr)
constant KAKCR=0.0	! aging of esterase (/hr)

!plasma AChE rate constants
constant KDBLCE=0.0		! degradation of esterase (/hr)
constant KIBLCE=0.0		! inhibition of esterase (per umol/L/hr)
constant KRBLCE=0.0		! reactivation of esterase (/hr)
constant KABLCE=0.0		! aging of esterase (/hr)

!plasma BuChE rate constants
constant KDBLBE=0.0		! degradation of esterase (/hr)
constant KIBLBE=0.0		! inhibition of esterase (per umol/L/hr)
constant KRBLBE=0.0	  ! reactivation of esterase (/hr)
constant KABLBE=0.0 	 ! aging of esterase (/hr)

!plasma CaE rate constants
constant KDBLCR=0.0		! degradation of esterase (/hr)
constant KIBLCR=0.0		! inhibition of esterase (per umol/L/hr)
constant KRBLCR=0.0		! reactivation of esterase (/hr)
constant KABLCR=0.0		! aging of esterase (/hr)

!RBC AChE rate constants
constant KDRBCE=0.0		! degradation of esterase (/hr)
constant KIRBCE=0.0		! inhibition of esterase (per umol/L/hr)
constant KRRBCE=0.0		! reactivation of esterase (/hr)
constant KARBCE=0.0		! aging of esterase (/hr)

!uptake parameters
!malathion
constant KAS=0.0		  !transfer stomach to liver (/h)
constant KSI=0.0	    !transfer stomach to intestine (/h)
constant KAI=0.0      !transfer intestine to liver (/h)
constant FA=0.0       !Fractional oral Absorption

!oxon
constant KASO=0.0  		 !transfer stomach to liver (/h)
constant KSIO=0.0	     !transfer stomach to intestine (/h)
constant KAIO=0.0       !transfer intestine to liver (/h)
constant FAO=0.0        !fractional oral Absorption

!elimination rate constants for metabolite compartments (/h)
constant KE1=0.0  !MCA + DCA

!molecular weights
constant MWMAL=0.0 !molecular wt of malathion (g/mol)
constant MWMOX=0.0 !molecular wt of malaoxon (g/mol)
  

!oral dosing--single oral dose
constant ORALMAL=0.0	      !MAL single oral bolus dose (ug/kg)
constant ORALMOX=0.0	      !oxon oral bolus dose (ug/kg)
  
!oral dosing--multiple doses
!put times in the array DT (in hours) (absolute time, NOT time since last dose)
!Put the oral dose of malathion in the array DORAL (UG/KG)(DORALO FOR OXON)
!for dosing AMOUNT instead of /kg (ug) put the oral dose of malathion (AMTMDOSE) OR OXON (AMTODOSE)
!Add one additional dose of zero at a time greater than TSTOP to keep the model running
  DIMENSION DT(2000), DORAL(2000), DORALO(2000), AMTMDOSE(2000), AMTODOSE(2000)
  INTEGER indx
  indx=1  			! indx is a counter used to track multiple doses
  SCHEDULE DOSEX .AT. DT(indx)
  ODOSE=0.0     !oral dose (MAL; ug/kg BW)
  ODOSEO=0.0    !oral dose (oxon; ug/kg BW)
  ADOSEM=0.0    !oral dose (MAL; ug)
  ADOSEO=0.0    !oral dose (oxon; ug)

! TIMING COMMANDS
constant POINTS=100.0		!OUTPUT POINTS
constant TSTOP=0.0		   !STOP SIMULATION (HR)
CINT=TSTOP/POINTS        !Communication interval
VARIABLE time = 0.0      !simulation time in hour
 
 END ! INITIAL

DYNAMIC

ALGORITHM IALG = 2      !Gear algorithm
TERMT(TIME .GE. TSTOP)	!stop execution
PND = time/24+AGE0


DERIVATIVE

AGE = AGE0+(TIME/24)    !age in days

!growth of postnatal rat
BW= BW0+ (-1E-8 * AGE**4) + (5E-7 * AGE**3) + (8E-5 * AGE**2)- (0.0001 * AGE) + 0.0101             !body weight (kg)
VBrC= 0.02956 + (0.003697 * AGE) + (-2.989E-4 * AGE**2)+ (6.84E-6 * AGE**3) + (-4.99E-8 * AGE**4)  !brain, % of BW
VLC= 0.04738 + (-0.004162 * AGE) + (2.796E-4 * AGE**2)+ (-6.054E-6 * AGE**3) + (4.187E-8 * AGE**4) !liver, % of BW

!scaling for blood flows
  QC = QCC*(BW**0.75)              !cardiac output (L/h)
  QSC = 1.0-(QFC+QLC+QBrC+QRC+QKC) !% of blood flow not going to other tissues (i.e., % to slowly perfused)
  QK = QKC*QC                      !kidney (L/h)
  QF = QFC*QC                      !fat (L/h)
  QL = QLC*QC                      !liver (L/h)
  QBr = QBrC*QC                    !brain (L/h)
  QR = QRC*QC                      !rapidly perfused tissues (L/h)
  QS = QSC*QC                      !slowly perfused tissues (L/h)
  
  QBal = QC-(QF+QL+QBr+QR+QS+QK)  !balance check

!scaling for tissue volumes (L)
  VBL = VBLC*BW                    !blood
  VF = VFC*BW                      !fat
  VL =  VLC*BW                     !liver
  VBr = VBrC*BW                    !brain
  VK = VKC*BW                      !kidney
  VR = VRC*BW                      !rapidly perfused tissues
  VS = VSC*BW                      !slowly perfused tissues
  VINT = VINTC*BW                  !intestine
  VPLAS = VBL*(1-HCT)              !plasma
  VRBC = VBL*HCT                   !RBC

  !Tissue volume checks
  VTOTCOMPARTMENTS=(VLC+VFC+VSC+VRC+VBRC+VBLC+VKC+VINTC)/0.9 !should be ~0.9-1.1

  !scaling for Vmax for malathion detoxification (umol/hr/kg tissue to umol/hr)
  VMAXMALL = VMAXMALLC * VL                      !liver--CaE
  VMAXMALK = VMAXMALKC * VK                      !kidney--CaE
  VMAXMALBL = VMAXMALBLC * VBL * (1-HCT)         !plasma--CaE
  VMAXMALBR = VMAXMALBRC * VBR                   !brain--CaE

  !oxidation--malathion to oxon
  VMAXMALMOX = VMAXMALMOXC * VL                  !liver--CYPs

  !oxon detox
  VMOXDMPL = VMOXDMPLC*VL                        !liver oxon detox
  VMOXDMPP = VMOXDMPPC*VBL*(1-HCT)               !plasma oxon detox
  VMOXDMPB = VMOXDMPBC*VBr                       !brain oxon detox
  VMOXDMPK = VMOXDMPKC*VK                        !kidney oxon detox

!Enzyme activity (umol/h) in tissues--these are currently scaled to BW 
!AChE
SBACH=BACHE*VBr             !brain
SHACH=HACHE*VL	            !liver
SBLACH=BLACHE*VBL*(1-HCT)   !plasma
SRBACH=RBCHE*VBL*HCT        !RBC
SKACH=KACHE*VK              !kidney

!BuChE
SBBUC=BBUCE*VBr             !brain
SHBUC=HBUCE*VL	            !liver
SBLBUC=BLBUCE*VBL*(1-HCT)   !plasma
SKBUC=KBUCE*VK              !kidney

!CaE
SBRCE=BRCE*VBr	            !brain
SHECE=HECE*VL			         !liver
SPLOCE=PLOCE*VBL*(1-HCT)    !plasma
SKACE=KECE*VK               !kidney

!calculation of esterase binding sites (umol)
!AChE
IBCE=SBACH/TRCE		!total brain AchE (umol)
IHCE=SHACH/TRCE		!total liver AchE (umol)
IBLCE=SBLACH/TRCE	!total plasma AchE (umol)
IRBCE=SRBACH/TRCE	!total RBC AChE (umol)
IKCE=SKACH/TRCE		!total kidney AchE (umol)

!BuChE
IBBE=SBBUC/TRBE		!total brain BuChE (umol)
IHBE=SHBUC/TRBE		!total liver BuChE (umol)
IBLBE=SBLBUC/TRBE	!total plasma BuChE (umol)
IKBE=SKBUC/TRBE		!total kidney BuChE (umol)

!CaE
IBCR=SBRCE/TRCR		!total brain CaE (umol)
IHCR=SHECE/TRCR		!total liver CaE (umol)
IBLCR=SPLOCE/TRCR	!total plasma CaE (umol)
IKCR=SKACE/TRCR		!total kidney CaE (umol)


!calculation of enzyme synthesis rates in tissues (umol/hr)
!liver
KSHCE=IHCE*KDHCE	!AChE
KSHBE=IHBE*KDHBE	!BuChE
KSHCR=IHCR*KDHCR	!CaE
!brain
KSBCE=IBCE*KDBCE	!AChE
KSBBE=IBBE*KDBBE	!BuChE
KSBCR=IBCR*KDBCR	!CaE
!kidney
KSKCE=IKCE*KDKCE	!AChE
KSKBE=IKBE*KDKBE	!BuChE
KSKCR=IKCR*KDKCR	!CaE
!plasma
KSBLCE=IBLCE*KDBLCE	!AChE
KSBLBE=IBLBE*KDBLBE	!BuChE
KSBLCR=IBLCR*KDBLCR	!CaE
!RBC
KSRBCE=KDRBCE*IRBCE	!AChE



!oral dose molar conversion with fractional absorption--single oral dose
ODOSEMAL=ORALMAL*(BW/MWMAL)*FA	 ! MAL dose conversion (ug/kg to umol)
ODOSEMOX=ORALMOX*(BW/MWMOX)*FAO	! malaoxon dose conversion (ug/kg to umol)

!oral dose--multiple dose
DISCRETE DOSEX				
ODOSE=ODOSE+DORAL(indx)*(BW/MWMAL)*FA	   !malathion dose ug/kg to umol
ODOSEO=ODOSEO+DORALO(indx)*(BW/MWMOX)*FAO !oxon dose ug/kg to umol
ADOSEO=ADOSEO+AMTODOSE(indx)*FA/MWMAL     !malathion dose ug to umol
ADOSEM=ADOSEM+AMTMDOSE(indx)*FAO/MWMOX    !oxon dose ug to umol
indx=indx+1
SCHEDULE DOSEX .AT. DT(indx)
END

!--------------------------------------------------------------
!malathion (parent compound)-----------------------------------
!---------------------------------------------------------------

!stomach
RSTOM = -kas*Astom-ksi*Astom                      !rate of change in stomach (umol/hr)
AStom = integ(RStom,0.0)+ODOSE+ADOSEM+ODOSEMAL    !amount in stomach (umol)

!intestine
RInst = ksi*AStom - kai*AIntM                     !rate of change in intestine (umol/hr)
AIntM=integ(RInst,0.0)                            !amount in intestine (umol)                                 
CINTM = AINTM/VINT                                !concentration in intestine (umol/L)

!liver
RALM=QL*CBL-QL*CVLM+kai*AIntM+kas*AStom-RALM1-RALM2          !rate of change in liver (umol/hr)
ALM = integ(RALM,0.0)                                        !amt in liver (umol)
CLM = ALM/VL                                                 !concentration in liver (umol/L)
CVLM = CLM/PMalL                                             !concn in venous blood leaving liver (umol/L)

!Liver metabolism of Mal by CYPs--oxidation
RALM1 = (VmaxMalMox*CVLM)/(KmMalMox+CVLM)            !rate of metabolite formation (umol/hr)
ALM1 = integ(RALM1, 0.0)                             !amt oxon formed (umol)

!Liver--metabolism of MAL to MCA/DCA by CaE
RALM2 = VMAXMALL*CVLM/(KMMALL*(1+CVLO/KI)+CVLM)  !rate of metabolites formed (umol/hr)
ALM2 = integ(RALM2,0.0)                          !amount of metabolites formed (umol)

!kidney
RAKM = QK*CBL-QK*CVKM-RAKM2                          !rate of change in kidney (umol/hr)
AKM = integ(RAKM,0.0)                                !amt in kidney (umol)
CKM = AKM/VK                                         !concn in kidney (umol/L)
CVKM = CKM/PMalK                                     !concn in venous blood leaving kidney (umol/L)

!kidney--metabolism of MAL to MCA/DCA by CaE
RAKM2 = VMAXMALK*CVKM/(KMMALK*(1+CVKO/KI)+CVKM)   !rate of metabolites formed (umol/hr)
AKM2 = integ(RAKM2,0.0)                           !amount of metabolites formed (umol)

!fat
RAFM = QF*CBL-QF*CVFM                                !rate of change in fat (umol/hr)
AFM = integ(RAFM, 0.0)                               !amt in fat (umol)
CFM = AFM/VF                                         !concn. in fat (umol/L)
CVFM = CFM/PMalF                                     !concn. in venous blood leaving fat (umol/L)

!slowly perfused
RASM = QS*CBL-QS*CVSM                                !rate of change in slowly perfused (umol/hr)
ASMal = integ(RASM, 0.0)                             !amt in slowly perfused (umol)
CSM = ASMal/VS                                       !concn. in slowly perfused (umol/L)
CVSM = CSM/PMalS                                     !concn. in venous blood leaving slowly perfused (umol/L)

!brain
RABrM = QBr*CBL-QBr*CVBrM-RABRM2                     !rate of change in brain (umol/hr)
ABrM = integ(RABrM,0.0)                              !amt. in brain (umol)
CBrM = ABrM/VBr                                      !concn in brain (umol/L)
CVBrM = CBrM/PMalBr                                  !concn. in venous blood leaving brain (umol/L)

!brain--metabolism of MAL to MCA/DCA by CaE
RABRM2 = VMAXMALBR*CVBrM/(KMMALBr*(1+CVBrO/KI)+CVBrM)!rate of metabolites formed (umol/hr)
ABRM2 = integ(RABRM2,0.0)                            !amount of metabolites formed (umol)

!rapidly perfused tissues
RARM = QR*CBL-QR*CVRM                                !rate of change in rapidly perfused (umol/hr)
ARM = integ(RARM,0.0)                                !amt in rapidly perfused (umol)
CRM = ARM/VR                                         !concn in rapidly perfused (umol/L)
CVRM = CRM/PMalR                                     !concn in venous blood leaving rapidly perfused (umol/L)

!blood
RABL=QC*(CV-CBL)-RABLM2 	                      !rate of change in mixed blood (arterial & venous; umol/hr)
ABL=INTEG(RABL,0.0)                  		       !amount in mixed blood (umol)
CBL=ABL/VBL			                               !concn in mixed blood (umol/L)

!blood--metabolism of MAL to MCA/DCA by CaE
RABLM2 = VMAXMALBL*CBL/(KMMALBL*(1+CBLO/KI)+CBL) !rate of metabolism (umol/hr)
ABLM2 = integ(RABLM2,0.0)                       !amt metabolite formed (umol)


CV=(QL*CVLM+QF*CVFM+QK*CVKM+QS*CVSM+QBr*CVBrM+QR*CVRM)/QC   !concentration free in venous blood (umol/L)


!-------------------------------------------------------------------------------
!oxon
!-------------------------------------------------------------------------------

!stomach
RAstomO = -ksiO*AStomO-kasO*AStomO                       !rate of change in stomach (umol/hr)
AStomO = integ(RASTomO,0.0)+ODOSEO+ADOSEO+ODOSEMOX       !amount in stomach (umol)

!intestine
RAIntO = -kaiO*AINTO+ksiO*AStomO                 !rate of change in intestine (umol/hr)
AintO = integ(RAIntO,0.0)                        !amount in intestine (umol)
CINTO = AINTO/VINTC                              !concn in intestine (umol/L)

!liver
RALO = QL*CBLO-QL*CVLO+kaiO*AINTO+kasO*AStomO+RALM1-(RHPCE+RHPBE+RHPCR)-RALOD        !rate of change in liver (umol/hr)
ALO = integ(RALO,0.0)                                     !amt in liver (umol)
CLO = ALO/VL                                              !concentration in liver (umol/L)
CVLO = CLO/PMOXL                                          !concn in venous blood leaving liver (umol/L)

!oxon detox
RALOD = (VMOXDMPL*CVLO)/(KMOXDMPL*(1+CVLO/KI)+CVLO)
AALOD = integ(RALOD,0.0)

!AChE activity--liver
RHCE=KSHCE-AHCE*(KDHCE+KIHCE*CLO)+HOCE*KRHCE	     ! rate of AChE activity (umol/hr)
AHCE=INTEG(RHCE,IHCE)				                      ! liver AChE activity (umol)
RNHCE=KSHCE-ANHCE*KDHCE				                    ! rate of baseline AChE act (umol/hr)
ANHCE=INTEG(RNHCE,IHCE)				                    ! Amt of baseline AChE (umol)
RHOCE=AHCE*KIHCE*CLO-HOCE*(KAHCE+KRHCE)		        ! rate of AChE inhibition (umol/hr)
HOCE=INTEG(RHOCE,0.0)				                      ! amount of liver AChE inhibited (umol)
RHPCE=AHCE*KIHCE*CLO				                       ! rate of oxon consumption (umol/hr)
AHPCE=integ(RHPCE,0.0)                             ! amt of oxon consumed (umol)
        
!BuChE activity--liver
RHBE=KSHBE-AHBE*(KDHBE+KIHBE*CLO)+HOBE*KRHBE	     ! rate of BuChE activity (umol/hr)
AHBE=INTEG(RHBE,IHBE)				                      ! liver BuChE activity (umol)
RNHBE=KSHBE-ANHBE*KDHBE				                    ! rate of baseline BuChE act (umol/hr)
ANHBE=INTEG(RNHBE,IHBE)				                    ! Amt of baseline BuChE (umol)
RHOBE=AHBE*KIHBE*CLO-HOBE*(KAHBE+KRHBE)		        ! rate of BuChE inhibition (umol/hr)
HOBE=INTEG(RHOBE,0.0)				                      ! amount of liver BuChE inhibited (umol)
RHPBE=AHBE*KIHBE*CLO				                       ! rate of oxon consumption (umol/hr)
AHPBE=integ(RHPBE,0.0)                             ! amt of oxon consumed (umol)
        
!CaE activity--liver
RHCR=KSHCR-AHCR*(KDHCR+KIHCR*CLO)+HOCR*KRHCR	     ! rate of CaE activity (umol/hr)
AHCR=INTEG(RHCR,IHCR)				                      ! liver CaE activity (umol)
RNHCR=KSHCR-ANHCR*KDHCR				                    ! rate of baseline CaE act (umol/hr)
ANHCR=INTEG(RNHCR,IHCR)				                    ! Amt of baseline CaE (umol)
RHOCR=AHCR*KIHCR*CLO-HOCR*(KAHCR+KRHCR)		        ! rate of CaE inhibition (umol/hr)
HOCR=INTEG(RHOCR,0.0)				                      ! amount of liver CaE inhibited (umol)
RHPCR=AHCR*KIHCR*CLO				                       ! rate of oxon consumption (umol/hr)
AHPCR=integ(RHPCR,0.0)                             ! amt of oxon consumed (umol)

!liver B-esterase (AChE, BuChE, and CaE) activity
HBE=AHCE+AHBE+AHCR			                           ! total B-esterase=AChE+BuChE+CaE (umol)
IHE=100*(HBE/(ANHCE+ANHBE+ANHCR))	                ! % total B-esterase inhibition
HCE=100*(AHCE/ANHCE)			                         ! % AChE inhibition
HBES=100*(AHBE/ANHBE)			                        ! % BuChE inhibition
HCR=100*(AHCR/ANHCR)			                         ! % CaE inhibition

!fat
RAFO = QF*CBLO-QF*CVFO                             !rate of change in fat (umol/hr)
AFO = integ(RAFO, 0.0)                             !amt in fat (umol)
CFO = AFO/VF                                       !concn. in fat (umol/L)
CVFO = CFO/PMOXF                                   !concn. in venous blood leaving fat (umol/L)

!slowly perfused
RASO = QS*CBLO-QS*CVSO                             !rate of change in slowly perfused (umol/hr)
ASO = integ(RASO, 0.0)                             !amt in slowly perfused (umol)
CSO = ASO/VS                                       !concn. in slowly perfused (umol/L)
CVSO = CSO/PMOXS                                   !concn. in venous blood leaving slowly perfused (umol/L)

!rapidly perfused tissues
RARO = QR*CBLO-QR*CVRO                            !rate of change in rapidly perfused (umol/hr)
ARO = integ(RARO,0.0)                             !amt in rapidly perfused (umol)
CRO = ARO/VR                                      !concn in rapidly perfused (umol/L)
CVRO = CRO/PMOXR                                  !concn in venous blood leaving rapidly perfused (umol/L)

!brain
RABrO = QBr*CBLO-QBr*CVBrO-(RBPCE+RBPBE+RBPCR)-RABROD      !rate of change in brain (umol/hr)
ABrO = integ(RABrO,0.0)                                    !amt. in brain (umol)
CBrO = ABrO/VBr                                            !concn in brain (umol/L)
CVBrO = CBrO/PMOXBR                                        !concn. in venous blood leaving brain (umol/L)

!oxon detox
RABROD = (VMOXDMPB*CVBrO)/(KMOXDMPB*(1+CVBrO/KI)+CVBrO)
AABRO = integ(RABROD,0.0)


!AChE activity--brain
RBCE=KSBCE-ABCE*(KDBCE+KIBCE*CBrO)+BOCE*KRBCE	       ! rate of AChE activity (umol/hr)
ABCE=INTEG(RBCE,IBCE)				                         ! brain AChE activity (umol)
RNBCE=KSBCE-ANBCE*KDBCE				                       ! rate of baseline AChE act (umol/hr)
ANBCE=INTEG(RNBCE,IBCE)				                       ! Amt of baseline AChE (umol)
RBOCE=ABCE*KIBCE*CBrO-BOCE*(KABCE+KRBCE)		          ! rate of AChE inhibition (umol/hr)
BOCE=INTEG(RBOCE,0.0)				                         ! amount of brain AChE inhibited (umol)
RBPCE=ABCE*KIBCE*CBrO				                         ! rate of oxon consumption (umol/hr)
ABPCE=integ(RBPCE,0.0)                                ! amt of oxon consumed (umol)
        
!BuChE activity--brain
RBBE=KSBBE-ABBE*(KDBBE+KIBBE*CBrO)+BOBE*KRBBE	       ! rate of BuChE activity (umol/hr)
ABBE=INTEG(RBBE,IBBE)				                         ! brain BuChE activity (umol)
RNBBE=KSBBE-ANBBE*KDBBE				                       ! rate of baseline BuChE act (umol/hr)
ANBBE=INTEG(RNBBE,IBBE)				                       ! Amt of baseline BuChE (umol)
RBOBE=ABBE*KIBBE*CBrO-BOBE*(KABBE+KRBBE)		          ! rate of BuChE inhibition (umol/hr)
BOBE=INTEG(RBOBE,0.0)				                         ! amount of brain BuChE inhibited (umol)
RBPBE=ABBE*KIBBE*CBrO 				                        ! rate of oxon consumption (umol/hr)
ABPBE=integ(ABPBE,0.0)                                ! amt of oxon consumed (umol)
        
!CaE activity--brain
RBCR=KSBCR-ABCR*(KDBCR+KIBCR*CBrO)+BOCR*KRBCR	       ! rate of CaE activity (umol/hr)
ABCR=INTEG(RBCR,IBCR)				                         ! brain CaE activity (umol)
RNBCR=KSBCR-ANBCR*KDBCR				                       ! rate of baseline CaE act (umol/hr)
ANBCR=INTEG(RNBCR,IBCR)				                       ! Amt of baseline CaE (umol)
RBOCR=ABCR*KIBCR*CBrO-BOCR*(KABCR+KRBCR)		          ! rate of CaE inhibition (umol/hr)
BOCR=INTEG(RBOCR,0.0)				                         ! amount of brain CaE inhibited (umol)
RBPCR=ABCR*KIBCR*CBrO				                         ! rate of oxon consumption (umol/hr)
ABPCR=integ(RBPCR,0.0)                                ! amt of oxon consumed (umol)

!brain B-esterase (AChE, BuChE, and CaE) activity
BBE=ABCE+ABBE+ABCR			                              ! total B-esterase=AChE+BuChE+CaE (umol)
IBE=100*(BBE/(ANBCE+ANBBE+ANBCR))	                   ! total B-esterase inhibition
BCE=100*(ABCE/ANBCE)			                            ! % AChE inhibition
BBES=100*(ABBE/ANBBE)			                           ! % BuChE inhibition
BCR=100*(ABCR/ANBCR)			                            ! % CaE inhibition


!kidney
RAKO = QK*CBLO-QK*CVKO-(RKPCE+RKPBE+RKPCR)-RAKOD            !rate of change in kidney (umol/hr)
AKO = integ(RAKO,0.0)                                 !amt in kidney (umol)
CKO = AKO/VK                                          !concn in kidney (umol/L)
CVKO = CKO/PMOXK                                      !concn in venous blood leaving kidney  (umol/L)

!oxon detox
RAKOD = (VMOXDMPK*CVKO)/(KMOXDMPK*(1+CVKO/KI)+CVKO)
AAKOD = integ(RAKOD,0.0)

! AChE activity--kidney
RKCE=KSKCE-AKCE*(KDKCE+KIKCE*CKO)+KOCE*KRKCE	            ! rate of AChE activity (umol/hr)
AKCE=INTEG(RKCE,IKCE)				                             ! kidney AChE activity (umol)
RNKCE=KSKCE-ANKCE*KDKCE				                           ! rate of baseline AChE act (umol/hr)
ANKCE=INTEG(RNKCE,IKCE)				                           ! Amt of baseline AChE (umol)
RKOCE=AKCE*KIKCE*CKO-KOCE*(KAKCE+KRKCE)		               ! rate of AChE inhibition (umol/hr)
KOCE=INTEG(RKOCE,0.0)				                             ! amount of kidney AChE inhibited (umol)
RKPCE=AKCE*KIKCE*CKO				                              ! rate of oxon consumption (umol/hr)
AKPCE=integ(RKPCE,0.0)                                    ! amt of oxon consumed (umol)
        
! BuChE activity--kidney
RKBE=KSKBE-AKBE*(KDKBE+KIKBE*CKO)+KOBE*KRKBE	            ! rate of BuChE activity (umol/hr)
AKBE=INTEG(RKBE,IKBE)				                             ! kidney BuChE activity (umol)
RNKBE=KSKBE-ANKBE*KDKBE				                           ! rate of baseline BuChE act (umol/hr)
ANKBE=INTEG(RNKBE,IKBE)				                           ! Amt of baseline BuChE (umol)
RKOBE=AKBE*KIKBE*CKO-KOBE*(KAKBE+KRKBE)		               ! rate of BuChE inhibition (umol/hr)
KOBE=INTEG(RKOBE,0.0)				                             ! amount of kidney BuChE inhibited (umol)
RKPBE=AKBE*KIKBE*CKO 				                             ! rate of oxon consumption (umol/hr)
AKPBE=integ(RKPBE,0.0)                                    ! amt of oxon consumed (umol)
        
! CaE activity--kidney
RKCR=KSKCR-AKCR*(KDKCR+KIKCR*CKO)+KOCR*KRKCR	            ! rate of CaE activity (umol/hr)
AKCR=INTEG(RKCR,IKCR)				                             ! kidney CaE activity (umol)
RNKCR=KSKCR-ANKCR*KDKCR				                           ! rate of baseline CaE act (umol/hr)
ANKCR=INTEG(RNKCR,IKCR)				                           ! Amt of baseline CaE (umol)
RKOCR=AKCR*KIKCR*CKO-KOCR*(KAKCR+KRKCR)		               ! rate of CaE inhibition (umol/hr)
KOCR=INTEG(RKOCR,0.0)				                             ! amount of kidney CaE inhibited (umol)
RKPCR=AKCR*KIKCR*CKO				                              ! rate of oxon consumption (umol/hr)
AKPCR=integ(RKPCR,0.0)                                    ! amt of oxon consumed (umol)

!kidney B-esterase (AChE, BuChE, and CaE) activity
KBE=AKCE+AKBE+AKCR			                                  ! total B-esterase=AChE+BuChE+CaE (umol)
IKE=100*(KBE/(ANKCE+ANKBE+ANKCR))	                       ! % total B-esterase inhibition
KCE=100*(AKCE/ANKCE)			                                ! % AChE inhibition
KBES=100*(AKBE/ANKBE)			                               ! % BuChE inhibition
KCR=100*(AKCR/ANKCR)			                                ! % CaE inhibition

!blood
RABLO=QC*(CVO-CBLO)-(RBLPBE+RBLPCR+RBLPCE+RRBPCE)-RAPLD   !rate of change in blood (umol/hr)
ABLO=integ(RABLO,0.0)                          !amount in blood (umol)
CBLO=ABLO/VBL				                          !concn in blood (umol/L)


CVO=(QL*CVLO+QF*CVFO+QS*CVSO+QR*CVRO+QBr*CVBrO+QK*CVKO)/QC   !concn in venous blood (umol/L)

!oxon detox--catalytic
RAPLD = (VMOXDMPP*CBLO)/(KMOXDMPP*(1+CBLO/KI)+CBLO) 
AAPLD = integ(RAPLD,0.0)

! AChE activity--plasma
RBLCE=KSBLCE-ABLCE*(KDBLCE+KIBLCE*CBLO)+BLOCE*KRBLCE	! rate of AChE activity (umol/hr)
ABLCE=INTEG(RBLCE,IBLCE)      				                ! plasma AChE activity (umol)
RNBLCE=KSBLCE-ANBLCE*KDBLCE				                   ! rate of baseline AChE act (umol/hr)
ANBLCE=INTEG(RNBLCE,IBLCE)				                    ! Amt of baseline AChE (umol)
RBLOCE=ABLCE*KIBLCE*CBLO-BLOCE*(KABLCE+KRBLCE)		    ! rate of AChE inhibition (umol/hr)
BLOCE=INTEG(RBLOCE,0.0)					                     ! amount of plasma AChE inhibited (umol)
RBLPCE=ABLCE*KIBLCE*CBLO				                      ! rate of oxon consumption (umol/hr)
ABLPCE=integ(RBLPCE,0.0)                              ! amt of oxon consumed (umol)
      
! BuChE activity--plasma
RBLBE=KSBLBE-ABLBE*(KDBLBE+KIBLBE*CBLO)+BLOBE*KRBLBE	! rate of BuChE activity (umol/hr)
ABLBE=INTEG(RBLBE,IBLBE)				                      ! plasma BuChE activity (umol)
RNBLBE=KSBLBE-ANBLBE*KDBLBE				                   ! rate of baseline BuChE act (umol/hr)
ANBLBE=INTEG(RNBLBE,IBLBE)				                    ! Amt of baseline BuChE (umol)
RBLOBE=ABLBE*KIBLBE*CBLO-BLOBE*(KABLBE+KRBLBE)		    ! rate of BuChE inhibition (umol/hr)
BLOBE=INTEG(RBLOBE,0.0)					                     ! amount of plasma BuChE inhibited (umol)
RBLPBE=ABLBE*KIBLBE*CBLO				                      ! rate of oxon consumption (umol/hr)
ABLPBE=integ(RBLPBE,0.0)                              ! amt of oxon consumed (umol)
        
! CaE activity--plasma
RBLCR=KSBLCR-ABLCR*(KDBLCR+KIBLCR*CBLO)+BLOCR*KRBLCR	! rate of CaE activity (umol/hr)
ABLCR=INTEG(RBLCR,IBLCR)				                      ! plasma CaE activity (umol)
RNBLCR=KSBLCR-ANBLCR*KDBLCR				                   ! rate of baseline CaE act (umol/hr)
ANBLCR=INTEG(RNBLCR,IBLCR)				                    ! Amt of baseline CaE (umol)
RBLOCR=ABLCR*KIBLCR*CBLO-BLOCR*(KABLCR+KRBLCR)		    ! rate of CaE inhibition (umol/hr)
BLOCR=INTEG(RBLOCR,0.0)					                     ! amount of plasma CaE inhibited (umol)
RBLPCR=ABLCR*KIBLCR*CBLO				                      ! rate of oxon consumption (umol/hr)
ABLPCR=integ(RBLPCR,0.0)                              ! amt of oxon consumed (umol)

!plasma B-esterase (AChE, BuChE, and CaE) activity
BLBE=ABLCE+ABLBE+ABLCR				                !total B-esterase=AChE+BuChE+CaE (umol)
IBLE=100*(BLBE/(ANBLCE+ANBLBE+ANBLCR))		    ! % Total B-esterase inhibition in plasma
BLCE=100*(ABLCE/ANBLCE)				               ! % AChE inhibition in plasma
BLBES=100*(ABLBE/ANBLBE)			                ! % BuChE inhibition in plasma
BLCR=100*(ABLCR/ANBLCR)				               ! % CaE inhibition in plasma

! AChE activity--RBCs
RRBCCE=KSRBCE-ARBCE*(KDRBCE+KIRBCE*CBLO)+RBCOCE*KRRBCE	! rate of AChE activity (umol/hr)
ARBCE=INTEG(RRBCCE,IRBCE)				                       ! RBC AChE activity (umol)
RNRBCCE=KSRBCE-ANRBCE*KDRBCE				                    ! rate of baseline AChE act (umol/hr)
ANRBCE=INTEG(RNRBCCE,IRBCE)				                     ! Amt of baseline AChE (umol)
RRBOCE=ARBCE*KIRBCE*CBLO-RBCOCE*(KARBCE+KRRBCE)		     ! rate of AChE inhibition (umol/hr)
RBCOCE=INTEG(RRBOCE,0.0)				                        ! amount of RBC AChE inhibited (umol)
RRBPCE=ARBCE*KIRBCE*CBLO				                        ! rate of oxon consumption (umol/hr)
ARBPCE=integ(RRBPCE,0.0)                                ! amt of oxon consumed (umol)

!RBC B-esterase (AChE only)activity
RBCCE=100*(ARBCE/ANRBCE)			                          ! % AChE inhibition in RBCs
RBCPERC=100-RBCCE							                         ! % inhibited versus inhibition


!--------------------------------------------------------------------------------------
!metabolite excretion
!MCA + DCA metabolites--compartment 1
RAMCA = RAKM2+RABRM2+RABLM2+RALM2 !           !total rate of metabolite formation (umol/hr)
AMCA = integ(RAMCA, 0.0)                      !amount of MCA+DCA (umol)
RA1 = RAMCA-RAMCAex                           !rate of change of MCA+DCA in compartment 1 (umol/hr)
A1 = integ(RA1,0.0)                           !amount of MCA+DCA in compartment 1 (umol)
CBMCA = A1/V1                                 !concentration of MCA+DCA in compartment 1 (umol/L)
RAMCAex = A1*KE1                              !rate of MCA+DCA excretion (umol/hr)
AMCAex = integ(RAMCAex,0.0)                   !amount of MCA+DCA excreted (umol)



end  !dynamic

!----------------------------------------------------------------------------------
!mass balance
TMASSMAL=ASTOM+AINTM+ALM+AKM+AFM+ASMal+ABRM+ARM+ABL         !umol
TMASSMOX=ASTOMO+AINTO+ALO+AFO+ASO+AKO+ARO+ABRO+ABLO         !umol
TMASSMCA=A1+AMCAEX                                          !umol        
TMASSODT=AAPLD+AALOD+AAKOD+AABRO                            !catalytic oxon detox (umol)
TMASSOXONNC=AHPCE+AHPBE+AHPCR+ABPCE+ABPBE+ABPCR+AKPCE+AKPBE+AKPCR+ABLPCE+ABLPBE+ABLPCR+ARBPCE     !non-catalytic oxon detox (umol)                    
TMASSTOTAL=TMASSMAL+TMASSMOX+TMASSMCA+TMASSODT+TMASSOXONNC              !umol--total better add up to what went in 

TDOSE=ODOSE+ODOSEMAL+ADOSEM+ADOSEO+ODOSEO+ODOSEMOX   !total dose (umol)
MASSBAL=TDOSE/(TMASSTOTAL+1E-99)  !should equal 1 (or really close to it)



end !derivative
end !program

