-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparallel_simulatePTS3.py
208 lines (173 loc) · 7.38 KB
/
parallel_simulatePTS3.py
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
from driver import compute
from values import *
from defs import *
import electrochemical
import water
import glucose
import cotransport
import NHE3
import ATPase
import NKCC
import KCC
import NCC
import ENaC
import Pendrin
import AE1
import NHE1
import flux
import os
import sys
import argparse
import multiprocessing
from set_params import set_torq_params
import output
solute = ['Na','K','Cl','HCO3','H2CO3','CO2','HPO4','H2PO4','urea','NH3','NH4','H','HCO2','H2CO2','glu']
compart = ['Lumen','Cell','ICA','ICB','LIS','Bath']
cw=Vref*60e6
parser = argparse.ArgumentParser()
# required input
parser.add_argument('--sex',choices=['Male','Female'],required = True,type = str,help = 'Sex')
parser.add_argument('--species',choices=['human','rat'],required = True,type = str, help = 'Human model or Rat model')
parser.add_argument('--type',choices = ['superficial','multiple'],required = True,type=str,help='superficial nephron or multiple nephrons?')
parser.add_argument('--file2save', required = True, type = str, help = 'where to save?')
# diabetic options
parser.add_argument('--diabetes',choices = ['Severe','Moderate'],default='Non',type=str,help='diabete status (Severe/Moderate)')
parser.add_argument('--inhibition',choices=['ACE','SGLT2','NHE3-50','NHE3-80','NKCC2-70','NKCC2-100','NCC-70','NCC-100','ENaC-70','ENaC-100','SNB-70','SNB-100'],default = None,type = str,help = 'any transporter inhibition?')
parser.add_argument('--unx',choices=['N','Y'],default = 'N',type = str,help = 'uninephrectomy status')
# pregnancy option
parser.add_argument('--pregnant', choices=['mid','late'], default='non', type=str, help='pregnant female? (mid/late)')
args = parser.parse_args()
sex = args.sex
species = args.species
sup_or_multi = args.type
diabete = args.diabetes
inhib = args.inhibition
unx = args.unx
preg = args.pregnant
if diabete != 'Non':
if preg != 'non':
raise Exception('pregnant diabetic not done')
# if inhib != None:
# file_to_save = inhib+'_'+sex+'_'+species[0:3]+'_'+diabete+'_diab'+'_'+unx+'_unx'
# else:
# file_to_save = sex+'_'+species[0:3]+'_'+diabete+'_diab'+'_'+unx+'_unx'
elif preg != 'non':
if sex == 'Male':
raise Exception('pregnant only for female')
if species[0:3] == 'hum':
raise Exception('pregnant model not set up for human yet')
if inhib != None:
raise Exception('pregnant model does not have inhibition set up yet')
#file_to_save = preg+'pregnant_'+species[0:3]
# else:
# file_to_save = sex + '_' + species[0:3] +'_normal'
file_to_save = args.file2save
if os.path.isdir(file_to_save) == False:
os.makedirs(file_to_save)
if sup_or_multi == 'superficial':
parts = ['sup']
else:
parts = ['sup','jux1','jux2','jux3','jux4','jux5']
def compute_segmentPTS3(sup_or_jux,sex,species,sup_or_multi,diabete,inhib,unx,preg,file_to_save):
solute = ['Na','K','Cl','HCO3','H2CO3','CO2','HPO4','H2PO4','urea','NH3','NH4','H','HCO2','H2CO2','glu']
compart = ['Lumen','Cell','ICA','ICB','LIS','Bath']
cw=Vref*60e6
#========================================================
# Proximal convolute tubule
#========================================================
print('%s PCT start' %(sup_or_jux))
if species == 'human':
NPT = 181
elif species == 'rat':
NPT = 176
if sex == 'Male':
filename = './datafiles/PTparams_M_'+species[0:3]+'.dat'
elif sex == 'Female':
filename = './datafiles/PTparams_F_'+species[0:3]+'.dat'
else:
filename ='./datafiles/PTparams_F_'+species[0:3]+'.dat'
pt=compute(NPT,filename,'Broyden',sup_or_jux,diabete,species,sup_or_multi=sup_or_multi,inhibition = inhib,unx = unx, preg = preg)
Scaletorq = np.zeros(NPT)
for j in range(NPT):
if pt[j].segment == 'PT':
TS = 1.3
scaleT = 1.0
elif pt[j].segment == 'S3':
TS = 1.3
scaleT = 0.5
#torque-modulated effects
PM=pt[j].pres[0]
Radref,torqR,torqvm,PbloodPT,torqL,torqd = set_torq_params(pt[j].species,pt[j].sex,pt[j].preg)
if pt[j].species == 'rat':
fac1 = 8.0*visc*(pt[j].vol_init[0]*Vref)*torqL/(Radref**2)
elif pt[j].species == 'mou':
fac1 = 8.0*visc*(pt[j].vol_init[0]*Vref)*torqL/(Radref**2)
elif pt[j].species == 'hum':
fac1 = 8.0*visc*(pt[j].volref[0]*Vref)*torqL/(Radref**2)
else:
print('pt.species: ' + str(pt[j].species))
raise Exception('what is species?')
fac2 = 1.0 + (torqL+torqd)/Radref + 0.50*((torqL/Radref)**2)
TM0= fac1*fac2
RMtorq = torqR*(1.0e0+torqvm*(PM - PbloodPT))
factor1 = 8.0*visc*(pt[j].vol[0]*Vref)*torqL/(RMtorq**2)
factor2 = 1.0 + (torqL+torqd)/RMtorq + 0.50*((torqL/RMtorq)**2)
Torque = factor1*factor2
Scaletorq[j] = 1.0 + TS*scaleT*(Torque/TM0-1.0)
output.output_segment_results(pt,sup_or_jux,Scaletorq,file_to_save,NPT)
print('%s PCT finished.' %(sup_or_jux))
print('\n')
#========================================================
# S3
#========================================================
print('%s S3 start' %(sup_or_jux))
if species == 'human':
NS3 = 20
elif species == 'rat':
NS3 = 25
if sex == 'Male':
filename = './datafiles/S3params_M_'+species[0:3]+'.dat'
elif sex == 'Female':
filename = './datafiles/S3params_F_'+species[0:3]+'.dat'
else:
filename ='./datafiles/S3params_F_'+species[0:3]+'.dat'
s3=compute(NS3,filename,'Newton',sup_or_jux,diabete,species,sup_or_multi=sup_or_multi,inhibition = inhib,unx = unx,preg = preg)
Scaletorq = np.zeros(NS3)
for j in range(NS3):
if s3[j].segment == 'PT':
TS = 1.3
scaleT = 1.0
elif s3[j].segment == 'S3':
TS = 1.3
scaleT = 0.5
#torque-modulated effects
PM=s3[j].pres[0]
Radref,torqR,torqvm,PbloodPT,torqL,torqd = set_torq_params(s3[j].species,s3[j].sex,s3[j].preg)
if s3[j].species == 'rat':
fac1 = 8.0*visc*(s3[j].vol_init[0]*Vref)*torqL/(Radref**2)
elif s3[j].species == 'mou':
fac1 = 8.0*visc*(s3[j].vol_init[0]*Vref)*torqL/(Radref**2)
elif s3[j].species == 'hum':
fac1 = 8.0*visc*(s3[j].volref[0]*Vref)*torqL/(Radref**2)
else:
print('s3.species: ' + str(s3[j].species))
raise Exception('what is species?')
fac2 = 1.0 + (torqL+torqd)/Radref + 0.50*((torqL/Radref)**2)
TM0= fac1*fac2
RMtorq = torqR*(1.0e0+torqvm*(PM - PbloodPT))
factor1 = 8.0*visc*(s3[j].vol[0]*Vref)*torqL/(RMtorq**2)
factor2 = 1.0 + (torqL+torqd)/RMtorq + 0.50*((torqL/RMtorq)**2)
Torque = factor1*factor2
Scaletorq[j] = 1.0 + TS*scaleT*(Torque/TM0-1.0)
output.output_segment_results(s3,sup_or_jux,Scaletorq,file_to_save,NS3)
print('%s S3 finished.' %(sup_or_jux))
print('\n')
#=============================
# end compute_segmentPTS3
#=============================
def multiprocessing_funcPTS3(sup_or_jux):
compute_segmentPTS3(sup_or_jux, sex, species, sup_or_multi, diabete, inhib, unx, preg, file_to_save)
if __name__ == '__main__':
pool = multiprocessing.Pool()
pool.map(multiprocessing_funcPTS3, parts)
pool.close()