Parcourir la source

Reconfigured cDiazepam to work with slightly updated cModel implementation

Andrej il y a 5 mois
Parent
commit
07cfdffdc5

+ 10 - 51
models/cDiazepam.json

@@ -1,8 +1,12 @@
 {
+   "timeUnit":"min",
    "compartments":["adipose","brain","heart","kidney","liver",
-   "splanchnic","stomach","muscle","skin","testes","remainder","lung",
-   "excrement","arterial","venous","source"],
+      "splanchnic","stomach","muscle","skin","testes","remainder","lung",
+      "excrement","arterial","venous","source"],
+   "commentScaled":"add compartments that only have inputs so they can be scaled to total input",
+   "scaled":["excrement"],
    "commentParameters":"every parameter must have a value, name is optional and used in SE computation",
+   "volumeComment":"in a compartment w/o volume, value is mass",
    "volumes":{
       "adipose":"adiposeVolume",
       "brain":"brainVolume",
@@ -33,9 +37,9 @@
       "(arterial,venous):testes":"testesFlow",
       "(arterial,venous):remainder":"remainderFlow"},
    "commentSources":"constants in concentration units per s",
-   "sources":{
-      "arterial":{"name":"exponential","k":-0.005,"constant":0},
-      "venous":{"name":"Heavyside","limit":300,"value":0.61e2}},
+   "commentHeavyside":"value is mass of exogene/volume of container/duration",
+   "inputs":{
+      "venous":"venousInput"},
    "commentBindings":"split to flow and diffusion dominated",
    "bindings": {
       "flowComments":"group common sources or targets with brackets",
@@ -60,50 +64,5 @@
        "skin":"skinPC",
        "splanchnic":"splanchnicPC",
        "stomach":"stomachPC",
-       "testes":"testesPC"},
-     "parameters":{
-        "adiposePC":{"value":23.1,"dist":"lognormal","cv":0.3},
-	     "brainPC":{"value":2.2,"dist":"lognormal","cv":0.3},
-	     "heartPC":{"value":4.3},
-        "kidneyPC":{"value":5.2},
-	     "liverPC":{"value":9.1},
-	     "lungPC":{"value":5.3},
-	     "musclePC":{"value":2.4},
-        "remainderPC":{"value":16.5},
-        "skinPC":{"value":3.2,"dist":"lognormal","cv":0.3},
-	     "splanchnicPC":{"value":4.3},
-	     "stomachPC":{"value":4.5},
-	     "testesPC":{"value":4.7},
-        "flowNotes":"liverOutFlow is sum of liver,splanchnic and stomach",
-        "flowNotes1":"liverOutFlow=3.55+20.25+1.9",
-        "adiposeFlow":{"value":2.55,"unit":"ml/min"},
-        "brainFlow":{"value":0.78,"unit":"ml/min"},
-        "heartFlow":{"value":4.2,"unit":"ml/min"},
-        "kidneyFlow":{"value":16.61,"unit":"ml/min"},
-        "liverInFlow":{"value":3.55,"unit":"ml/min"},
-        "liverOutFlow":{"value":25.7,"unit":"ml/min"},
-        "totalFlow":{"value":80,"unit":"ml/min"},
-        "muscleFlow":{"value":16.25,"unit":"ml/min"},
-        "skinFlow":{"value":7.1,"unit":"ml/min"},
-        "splanchnicFlow":{"value":20.25,"unit":"ml/min"},
-        "stomachFlow":{"value":1.9,"unit":"ml/min"},
-        "testesFlow":{"value":1.9,"unit":"ml/min"},
-        "remainderFlow":{"value":4.91,"unit":"ml/min"},
-        "adiposeVolume":{"value":10,"unit":"g"},
-        "brainVolume":{"value":1.2,"unit":"g"},
-        "heartVolume":{"value":1,"unit":"g"},
-        "kidneyVolume":{"value":2,"unit":"g"},
-        "liverVolume":{"value":11,"unit":"g"},
-        "lungVolume":{"value":1.2,"unit":"g"},
-        "muscleVolume":{"value":125,"unit":"g"},
-        "skinVolume":{"value":43.8,"unit":"g"},
-        "splanchnicVolume":{"value":15,"unit":"g"},
-        "stomachVolume":{"value":1.1,"unit":"g"},
-        "testesVolume":{"value":2.5,"unit":"g"},
-        "remainderVolume":{"value":15.8,"unit":"g"},
-        "venousVolume":{"value":13.6,"unit":"g"},
-        "arterialVolume":{"value":6.8,"unit":"g"},
-        "liverToExcrementNotes":"CL=422 ml/min,PC=9.1,f=0.15,V=11g->k1=0.0105/s",
-        "k1":{"value":0.0105,"unit":"1/s"}}
-
+       "testes":"testesPC"}
 }

+ 67 - 0
models/cDiazepam_parameters.json

@@ -0,0 +1,67 @@
+{
+     "parameters":{
+        "commentsInput":"X",
+        "_venousInput":{"value":0.010,"commentUnit":"sameUnitAsVolumes"},
+        "venousInput":{"function":"venousInput"},
+        "inputA":{"value":0.25e6,"commentUnit":"AU;reported concentrations are in AU/volumeUnit","dist":"normal","cv":0},
+        "inputTau":{"value":1,"commentUnit":"sameAsTimeUnit","dist":"normal","cv":0},
+        "commentPC":"X",
+        "adiposePC":{"value":23.1,"dist":"lognormal","cv":0.3},
+	     "brainPC":{"value":2.2,"dist":"lognormal","cv":0.3},
+	     "heartPC":{"value":4.3},
+        "kidneyPC":{"value":5.2},
+	     "liverPC":{"value":9.1},
+	     "lungPC":{"value":5.3},
+	     "musclePC":{"value":2.4},
+        "remainderPC":{"value":16.5},
+        "skinPC":{"value":3.2,"dist":"lognormal","cv":0.3},
+	     "splanchnicPC":{"value":4.3},
+	     "stomachPC":{"value":4.5},
+	     "testesPC":{"value":4.7},
+        "commentFlows":"X",
+        "flowNotes":"liverOutFlow is sum of liver,splanchnic and stomach",
+        "adiposeFlow":{"value":2.55,"unit":"ml/min"},
+        "brainFlow":{"value":0.78,"unit":"ml/min"},
+        "heartFlow":{"value":4.2,"unit":"ml/min"},
+        "kidneyFlow":{"value":16.61,"unit":"ml/min"},
+        "liverInFlow":{"value":3.55,"unit":"ml/min"},
+        "liverOutFlow":{"derived":"liverOutFlow"},
+        "gutOutFlow":{"derived":"gutOutFlow"},
+        "totalFlow":{"value":80,"unit":"ml/min"},
+        "muscleFlow":{"value":16.25,"unit":"ml/min"},
+        "skinFlow":{"value":7.1,"unit":"ml/min"},
+        "splanchnicFlow":{"value":20.25,"unit":"ml/min"},
+        "stomachFlow":{"value":1.9,"unit":"ml/min"},
+        "testesFlow":{"value":1.9,"unit":"ml/min"},
+        "remainderFlow":{"value":4.91,"unit":"ml/min"},
+        "adiposeVolume":{"value":10,"unit":"g"},
+        "brainVolume":{"value":1.2,"unit":"g"},
+        "heartVolume":{"value":1,"unit":"g"},
+        "kidneyVolume":{"value":2,"unit":"g"},
+        "liverVolume":{"value":11,"unit":"g"},
+        "lungVolume":{"value":1.2,"unit":"g"},
+        "muscleVolume":{"value":125,"unit":"g"},
+        "skinVolume":{"value":43.8,"unit":"g"},
+        "splanchnicVolume":{"value":15,"unit":"g"},
+        "stomachVolume":{"value":1.1,"unit":"g"},
+        "testesVolume":{"value":2.5,"unit":"g"},
+        "remainderVolume":{"value":15.8,"unit":"g"},
+        "venousVolume":{"value":13.6,"unit":"g","dist":"normal","cv":0},
+        "arterialVolume":{"value":6.8,"unit":"g"},
+        "liverToExcrementNotes":"CL=422 ml/min,PC=9.1,f=0.15,V=11g->k1=0.0105/s",
+        "k1":{"value":0.0105,"unit":"1/s"}},
+   "derivedParameters":{
+      "liverOutFlow":{
+         "type":"sum",
+         "a":"liverInFlow",
+         "b":"gutOutFlow"},
+      "gutOutFlow":{
+         "type":"sum",
+         "a":"splanchnicFlow",
+         "b":"stomachFlow"}
+   },
+   "functions":{
+      "venousInput":{"type":"exp","A":"inputA","tau":"inputTau"}
+   }
+
+}

+ 67 - 0
models/cDiazepam_parameters1.json

@@ -0,0 +1,67 @@
+{
+     "parameters":{
+        "commentsInput":"X",
+        "venousInput":{"value":0.3e6,"commentUnit":"sameUnitAsVolumes"},
+        "_venousInput":{"function":"venousInput"},
+        "inputA":{"value":0.01,"commentUnit":"sameAsVolumes"},
+        "inputTau":{"value":1,"commentUnit":"sameAsTimeUnit"},
+        "commentPC":"X",
+        "adiposePC":{"value":23.1,"dist":"lognormal","cv":0.3},
+	     "brainPC":{"value":2.2,"dist":"lognormal","cv":0.3},
+	     "heartPC":{"value":4.3},
+        "kidneyPC":{"value":5.2},
+	     "liverPC":{"value":9.1},
+	     "lungPC":{"value":5.3},
+	     "musclePC":{"value":2.4},
+        "remainderPC":{"value":16.5},
+        "skinPC":{"value":3.2,"dist":"lognormal","cv":0.3},
+	     "splanchnicPC":{"value":4.3},
+	     "stomachPC":{"value":4.5},
+	     "testesPC":{"value":4.7},
+        "commentFlows":"X",
+        "flowNotes":"liverOutFlow is sum of liver,splanchnic and stomach",
+        "adiposeFlow":{"value":2.55,"unit":"ml/min"},
+        "brainFlow":{"value":0.78,"unit":"ml/min"},
+        "heartFlow":{"value":4.2,"unit":"ml/min"},
+        "kidneyFlow":{"value":16.61,"unit":"ml/min"},
+        "liverInFlow":{"value":3.55,"unit":"ml/min"},
+        "liverOutFlow":{"derived":"liverOutFlow"},
+        "gutOutFlow":{"derived":"gutOutFlow"},
+        "totalFlow":{"value":80,"unit":"ml/min"},
+        "muscleFlow":{"value":16.25,"unit":"ml/min"},
+        "skinFlow":{"value":7.1,"unit":"ml/min"},
+        "splanchnicFlow":{"value":20.25,"unit":"ml/min"},
+        "stomachFlow":{"value":1.9,"unit":"ml/min"},
+        "testesFlow":{"value":1.9,"unit":"ml/min"},
+        "remainderFlow":{"value":4.91,"unit":"ml/min"},
+        "adiposeVolume":{"value":10,"unit":"g"},
+        "brainVolume":{"value":1.2,"unit":"g"},
+        "heartVolume":{"value":1,"unit":"g"},
+        "kidneyVolume":{"value":2,"unit":"g"},
+        "liverVolume":{"value":11,"unit":"g"},
+        "lungVolume":{"value":1.2,"unit":"g"},
+        "muscleVolume":{"value":125,"unit":"g"},
+        "skinVolume":{"value":43.8,"unit":"g"},
+        "splanchnicVolume":{"value":15,"unit":"g"},
+        "stomachVolume":{"value":1.1,"unit":"g"},
+        "testesVolume":{"value":2.5,"unit":"g"},
+        "remainderVolume":{"value":15.8,"unit":"g"},
+        "venousVolume":{"value":13.6,"unit":"g"},
+        "arterialVolume":{"value":6.8,"unit":"g"},
+        "liverToExcrementNotes":"CL=422 ml/min,PC=9.1,f=0.15,V=11g->k1=0.0105/s",
+        "k1":{"value":0.0105,"unit":"1/s"}},
+   "derivedParameters":{
+      "liverOutFlow":{
+         "type":"sum",
+         "a":"liverInFlow",
+         "b":"gutOutFlow"},
+      "gutOutFlow":{
+         "type":"sum",
+         "a":"splanchnicFlow",
+         "b":"stomachFlow"}
+   },
+   "functions":{
+      "venousInput":{"type":"exp","A":"inputA","tau":"inputTau"}
+   }
+
+}

+ 67 - 0
models/cDiazepam_parameters2.json

@@ -0,0 +1,67 @@
+{
+     "parameters":{
+        "commentsInput":"X",
+        "venousInput":{"value":0.000,"commentUnit":"sameUnitAsVolumes"},
+        "_venousInput":{"function":"venousInput"},
+        "inputA":{"value":0.01,"commentUnit":"sameAsVolumes"},
+        "inputTau":{"value":1,"commentUnit":"sameAsTimeUnit"},
+        "commentPC":"X",
+        "adiposePC":{"value":23.1,"dist":"lognormal","cv":0.3},
+	     "brainPC":{"value":2.2,"dist":"lognormal","cv":0.3},
+	     "heartPC":{"value":4.3},
+        "kidneyPC":{"value":5.2},
+	     "liverPC":{"value":9.1},
+	     "lungPC":{"value":5.3},
+	     "musclePC":{"value":2.4},
+        "remainderPC":{"value":16.5},
+        "skinPC":{"value":3.2,"dist":"lognormal","cv":0.3},
+	     "splanchnicPC":{"value":4.3},
+	     "stomachPC":{"value":4.5},
+	     "testesPC":{"value":4.7},
+        "commentFlows":"X",
+        "flowNotes":"liverOutFlow is sum of liver,splanchnic and stomach",
+        "adiposeFlow":{"value":2.55,"unit":"ml/min"},
+        "brainFlow":{"value":0.78,"unit":"ml/min"},
+        "heartFlow":{"value":4.2,"unit":"ml/min"},
+        "kidneyFlow":{"value":16.61,"unit":"ml/min"},
+        "liverInFlow":{"value":3.55,"unit":"ml/min"},
+        "liverOutFlow":{"derived":"liverOutFlow"},
+        "gutOutFlow":{"derived":"gutOutFlow"},
+        "totalFlow":{"value":80,"unit":"ml/min"},
+        "muscleFlow":{"value":16.25,"unit":"ml/min"},
+        "skinFlow":{"value":7.1,"unit":"ml/min"},
+        "splanchnicFlow":{"value":20.25,"unit":"ml/min"},
+        "stomachFlow":{"value":1.9,"unit":"ml/min"},
+        "testesFlow":{"value":1.9,"unit":"ml/min"},
+        "remainderFlow":{"value":4.91,"unit":"ml/min"},
+        "adiposeVolume":{"value":10,"unit":"g"},
+        "brainVolume":{"value":1.2,"unit":"g"},
+        "heartVolume":{"value":1,"unit":"g"},
+        "kidneyVolume":{"value":2,"unit":"g"},
+        "liverVolume":{"value":11,"unit":"g"},
+        "lungVolume":{"value":1.2,"unit":"g"},
+        "muscleVolume":{"value":125,"unit":"g"},
+        "skinVolume":{"value":43.8,"unit":"g"},
+        "splanchnicVolume":{"value":15,"unit":"g"},
+        "stomachVolume":{"value":1.1,"unit":"g"},
+        "testesVolume":{"value":2.5,"unit":"g"},
+        "remainderVolume":{"value":15.8,"unit":"g"},
+        "venousVolume":{"value":13.6,"unit":"g"},
+        "arterialVolume":{"value":6.8,"unit":"g"},
+        "liverToExcrementNotes":"CL=422 ml/min,PC=9.1,f=0.15,V=11g->k1=0.0105/s",
+        "k1":{"value":0.0105,"unit":"1/s"}},
+   "derivedParameters":{
+      "liverOutFlow":{
+         "type":"sum",
+         "a":"liverInFlow",
+         "b":"gutOutFlow"},
+      "gutOutFlow":{
+         "type":"sum",
+         "a":"splanchnicFlow",
+         "b":"stomachFlow"}
+   },
+   "functions":{
+      "venousInput":{"type":"exp","A":"inputA","tau":"inputTau"}
+   }
+
+}

Fichier diff supprimé car celui-ci est trop grand
+ 291 - 0
pythonScripts/cDiazepam.ipynb


+ 7 - 2
pythonScripts/cModel.py

@@ -159,6 +159,8 @@ class model:
       else:
          self.fu[self.lut['total']]=sum(self.uTotal)
       #build SE part
+
+
       self.buildSE()
 
    def buildSE(self):
@@ -422,7 +424,8 @@ class model:
          D=self.du[x]['derivatives']
          for p in D:
             k=self.lutSE[p]
-            self.fSu[k,self.lut[x]]=w[k]*D[p](t)
+            #print(f'[{p}]: {k}')
+            self.fSu[k,x]=w[k]*D[p](t)
       return self.fSu
 
    def jacobiFull(self,t):
@@ -644,8 +647,10 @@ class model:
          return function.linearGrowth(par1)
       if df['type']=='linearGrowthFixedSlope':
          return function.linearGrowthFixedSlope(par1)
+      if df['type']=='exp':
+         return function.exp(par1)
          
-      print('Function {} not found!'.format(fName))
+      print('Function {}/{} not found!'.format(fName,df))
 
    def getDerived(self,par):
       dName=par['derived']

+ 2 - 2
pythonScripts/compartmentModel.ipynb

@@ -2,7 +2,7 @@
  "cells": [
   {
    "cell_type": "code",
-   "execution_count": 39,
+   "execution_count": 1,
    "metadata": {},
    "outputs": [],
    "source": [
@@ -477,7 +477,7 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": "3.10.6"
+   "version": "3.10.12"
   }
  },
  "nbformat": 4,

+ 31 - 0
pythonScripts/function.py

@@ -1,5 +1,6 @@
 import numpy
 import functools
+import math
 
 def fval(t,W):
    if callable(W):
@@ -183,7 +184,37 @@ def linearGrowthFixedSlope(par):
 
    return Object(f,[dt1,dt2,dL1,dL2,dA])
 
+def feps(t,A,tau):
+   fA=fval(t,A)
+   fTau=fval(t,tau)
+   return fA*math.exp(-t/fTau)
 
+def dfepsdA(t,A,tau):
+   fTau=fval(t,tau)
+   return math.exp(-t/fTau)
+
+def dfepsdTau(t,A,tau):
+   fTau=fval(t,tau)
+   fA=fval(t,A)
+   if fTau==0:
+      return 0
+   return fA*math.exp(-t/fTau)*(t/fTau/fTau)
+
+
+def exp(par):
+   A=par['A']['value']
+   tau=par['tau']['value']
+   f=functools.partial(feps,A=A,tau=tau)
+
+   DA=par['A']['derivatives']
+   dfdA=functools.partial(dfepsdA,A=A,tau=tau)
+   dA=generate(dfdA,DA)
+
+   DTau=par['tau']['derivatives']
+   dfdTau=functools.partial(dfepsdTau,A=A,tau=tau)
+   dTau=generate(dfdTau,DTau)
+   
+   return Object(f,[dA,dTau])
 
 def Object(v,dArray):
    o={'value':v,'function':True}

+ 9 - 0
setup/setupHours.json

@@ -0,0 +1,9 @@
+{"method":"LSODA",
+"atol":1e-8,
+"rtol":1e-8,
+"mode":"IVPSimultaneous",
+"nt":201,
+"tmax":12,
+"tUnit":"hour",
+"stride":{"length":4,"tUnit":"hour"}
+}

+ 9 - 0
setup/setupMinute.json

@@ -0,0 +1,9 @@
+{"method":"LSODA",
+"atol":1e-8,
+"rtol":1e-8,
+"mode":"IVPSimultaneous",
+"nt":201,
+"tmax":1,
+"tUnit":"min",
+"stride":{"length":1,"tUnit":"min"}
+}

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff