#----------------------------------------------------------------------------- # Revised: 2003-03-11 # Copyright: (c) 2003 Donnal C. Walter (http://mindwrapper.org) # License: BSD License (http://www.mindwrapper.org/license) #----------------------------------------------------------------------------- from math import log, exp from Mindwrapper.api import * class HrPreInfusion(Number): """Hours between trough and start of infusion.""" scale = 0 digits = 2 def Assemble(self, tTrough, tStart, hrDosing): """(time trough drawn, time infusion started, dosing interval)""" hr = (tStart - tTrough) / 3600 if hr < 0: hr += hrDosing return hr class HrPeakTrough(Number): """Hours between peak and trough. This could be calculated with HrInterval using peak and trough times, but for estimating from new dosing interval, this Cell is necessary.""" scale = 0 digits = 2 def Assemble(self, hrDosing, hrInf, hrPost, hrPre): """(time dosing interval, infusion interval, post infusion interval, pre infusion interval)""" hr = hrDosing - (hrInf + hrPost + hrPre) return hr class KElim(Number): """Elimination constant for exponential decay.""" scale = 0 digits = 3 def Assemble(self, pk, tr, hr): """(peak, trough, hours)""" return (log(pk) - log(tr)) / hr class TFall(Number): """Time to fall to a desired level from current level.""" scale = 0 digits = 2 def Assemble(self, kElim, level1, level2): """(elimination constant, level now, desired level)""" return (log(level1) - log(level2)) / kElim class THalf(Number): """Half-life for exponential decay.""" scale = 0 digits = 2 def Assemble(self, kElim): """(elimination constant)""" return log(2) / kElim class VolDist(Number): """Volume of distribution for multiple dosing.""" scale = 0 digits = 2 def Assemble(self, kE, dose, cPk, tDose, tInf, tPost): """(elimination constant, dose, peak concentration, dosing interval, infusion time, post-infusion time to peak)""" d = kE * tInf a = exp(-d) b = exp(-kE * tPost) c = exp(-kE * tDose) x = ((1 - a) * b) / ((1 - c) * d) # adjustment for timing vol = dose / cPk # volume of distribution return vol * x # adjusted volume of distribution ## For illustration purposes. Use Quotient and Product in real life. class VolDistPerKg(Quotient): pass # vD / Wt class Clearance(Product): pass # (vD / Wt) * kE VolDistPerKg.Elaborate(scale = 0.001, digits = 2) Clearance.Elaborate(scale = 0.001, digits = 2) class PeakEst(Number): """Estimate new peak concentration in multiple dosing.""" scale = 0 digits = 2 def Assemble(self, kE, dose, vDist, tDose, tInf, tPost): """(elimination constant, dose, distribution volume, dosing interval, infusion time, post-infusion time to peak)""" d = kE * tInf a = exp(-d) b = exp(-kE * tPost) c = exp(-kE * tDose) x = ((1 - a) * b) / ((1 - c) * d) # adjustment for timing conc = dose / vDist # estimate of concentration return conc * x # adjusted estimate for peak conc class TroughEst(Number): """Estimate new trough concentration in multiple dosing.""" scale = 0 digits = 2 def Assemble(self, kElim, cPk, tDose, tInf, tPre, tPost): """(elimination constant, estimated peak concentration, dosing interval, infusion time, pre-infusion time from trough)""" time = tDose - tInf - tPre - tPost return cPk * exp(-kElim * time)