-
Notifications
You must be signed in to change notification settings - Fork 3
/
MSN_builder.py
273 lines (226 loc) · 12.4 KB
/
MSN_builder.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
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
#
'''
The MSN class defining the cell
'''
from neuron import h
import numpy as np
import json
# Distributions:
'''
T-type Ca: g = 1.0/( 1 +np.exp{(x-70)/-4.5} )
naf (den): (0.1 + 0.9/(1 + np.exp((x-60.0)/10.0)))
'''
def calculate_distribution(d3, dist, a4, a5, a6, a7, g8):
'''
Used for setting the maximal conductance of a segment.
Scales the maximal conductance based on somatic distance and distribution type.
Parameters:
d3 = distribution type:
0 linear,
1 sigmoidal,
2 exponential
3 step function
dist = somatic distance of segment
a4-7 = distribution parameters
g8 = base conductance (similar to maximal conductance)
'''
if d3 == 0:
value = a4 + a5*dist
elif d3 == 1:
value = a4 + a5/(1 + np.exp((dist-a6)/a7) )
elif d3 == 2:
value = a4 + a5*np.exp((dist-a6)/a7)
elif d3 == 3:
if (dist > a6) and (dist < a7):
value = a4
else:
value = a5
if value < 0:
value = 0
value = value*g8
return value
# ======================= the MSN class ==================================================
class MSN:
def __init__(self, params=None, \
morphology=None, \
variables=None, \
section=None ):
Import = h.Import3d_SWC_read()
Import.input(morphology)
imprt = h.Import3d_GUI(Import, 0)
imprt.instantiate(None)
h.define_shape()
# h.cao0_ca_ion = 2 # default in nrn
h.celsius = 35
self._create_sectionlists()
self._set_nsegs(section=section)
self.v_init = -80
self.dendritic_channels = [
"naf",
"kaf",
"kas",
"kdr",
"kir",
"cal12",
"cal13",
"can",
"car",
"cav32",
"cav33",
"sk",
"bk" ]
self.somatic_channels = [
"naf",
"kaf",
"kas",
"kdr",
"kir",
"cal12",
"cal13",
"can",
"car",
"sk",
"bk" ]
self.axonal_channels = [
"naf",
"kas" ,
"Im" ]
# insert active mechanisms (related to channels) -------------
for sec in self.somalist:
for mech in self.somatic_channels+["cadyn", "caldyn"]:
sec.insert(mech)
for sec in self.axonlist:
for mech in self.axonal_channels:
sec.insert(mech)
for sec in self.dendlist:
for mech in self.dendritic_channels+["cadyn", "caldyn"]:
sec.insert(mech)
with open(params) as file:
par = json.load(file)
# set passive parameters --------------------------------------------
for sec in self.allseclist:
sec.Ra = 150
sec.cm = 1.0
sec.insert('pas')
#sec.g_pas = 1e-5 # set using json file
sec.e_pas = -70 # -73
sec.g_pas = float(par['g_pas_all']['Value'])
sec.ena = 50
sec.ek = -85 # -90
self.distribute_channels("soma", "gbar_naf", 0, 1, 0, 0, 0, float(par['gbar_naf_somatic']['Value']))
self.distribute_channels("soma", "gbar_kaf", 0, 1, 0, 0, 0, float(par['gbar_kaf_somatic']['Value']))
self.distribute_channels("soma", "gbar_kas", 0, 1, 0, 0, 0, float(par['gbar_kas_somatic']['Value']))
self.distribute_channels("soma", "gbar_kdr", 0, 1, 0, 0, 0, float(par['gbar_kdr_somatic']['Value']))
self.distribute_channels("soma", "gbar_bk", 0, 1, 0, 0, 0, float(par['gbar_bk_somatic' ]['Value']))
self.distribute_channels("soma", "pbar_cal12", 0, 1, 0, 0, 0, 1.34e-5)
self.distribute_channels("soma", "pbar_cal13", 0, 1, 0, 0, 0, 1.34e-6)
self.distribute_channels("soma", "pbar_car", 0, 1, 0, 0, 0, 1.34e-4)
self.distribute_channels("soma", "pbar_can", 0, 1, 0, 0, 0, 4e-5)
self.distribute_channels("dend", "gbar_kdr", 0, 1, 0, 0, 0, float(par['gbar_kdr_basal']['Value']))
self.distribute_channels("dend", "gbar_bk", 0, 1, 0, 0, 0, float(par['gbar_bk_basal' ]['Value']))
self.distribute_channels("dend", "pbar_cal12", 0, 1, 0, 0, 0, 1e-5)
self.distribute_channels("dend", "pbar_cal13", 0, 1, 0, 0, 0, 1e-6)
self.distribute_channels("dend", "pbar_car", 0, 1, 0, 0, 0, 1e-4)
self.distribute_channels("axon", "gbar_kas", 0, 1, 0, 0, 0, float(par['gbar_kas_axonal']['Value']))
self.distribute_channels("axon", "gbar_naf", 3, 1, 1.1, 30, 500, float(par['gbar_naf_axonal']['Value']))
self.distribute_channels("axon", "gbar_Im", 0, 1, 0, 0, 0, 1.0e-3)
# in ephys step functions are not supported so something like below formula will be used instead.
#self.distribute_channels("axon", "gbar_naf", 1, 1, 0.1, 30, -1, float(par['gbar_naf_axonal']['Value']))
#(1 + 0.9/(1 + math.exp(({distance}-30.0)/-1.0) ))
if variables:
self.distribute_channels("dend", "gbar_naf", 1, 1.0-variables['naf'][1], \
variables['naf'][1], \
variables['naf'][2], \
variables['naf'][3], \
np.power(10,variables['naf'][0])*float(par['gbar_naf_basal']['Value']))
self.distribute_channels("dend", "gbar_kaf", 1, 1.0, \
variables['kaf'][1], \
variables['kaf'][2], \
variables['kaf'][3], \
np.power(10,variables['kaf'][0])*float(par['gbar_kaf_basal']['Value']))
self.distribute_channels("dend", "gbar_kas", 1, 0.1, \
0.9, \
variables['kas'][1], \
variables['kas'][2], \
np.power(10,variables['kas'][0])*float(par['gbar_kas_basal']['Value']))
self.distribute_channels("dend", "gbar_kir", 0, np.power(10,variables['kir'][0]), 0, 0, 0, float(par['gbar_kir_basal' ]['Value']))
self.distribute_channels("soma", "gbar_kir", 0, np.power(10,variables['kir'][0]), 0, 0, 0, float(par['gbar_kir_somatic']['Value']))
self.distribute_channels("dend", "gbar_sk", 0, np.power(10,variables['sk' ][0]), 0, 0, 0, float(par['gbar_sk_basal' ]['Value']))
self.distribute_channels("soma", "gbar_sk", 0, np.power(10,variables['sk' ][0]), 0, 0, 0, float(par['gbar_sk_somatic' ]['Value']))
self.distribute_channels("dend", "pbar_can", 1, 1.0-variables['can'][1], \
variables['can'][1], \
variables['can'][2], \
variables['can'][3], \
np.power(10,variables['can'][0]))
self.distribute_channels("dend", "pbar_cav32", 1, 0, \
1, \
variables['c32'][1], \
variables['c32'][2], \
np.power(10,variables['c32'][0]))
self.distribute_channels("dend", "pbar_cav33", 1, 0, \
1, \
variables['c33'][1], \
variables['c33'][2], \
np.power(10,variables['c33'][0]))
else:
self.distribute_channels("dend", "gbar_naf", 1, 0.1, 0.9, 60.0, 10.0, float(par['gbar_naf_basal']['Value']))
self.distribute_channels("dend", "gbar_kaf", 1, 1, 0.5, 120.0, -30.0, float(par['gbar_kaf_basal']['Value']))
self.distribute_channels("dend", "gbar_kas", 2, 1, 9.0, 0.0, -5.0, float(par['gbar_kas_basal']['Value']))
self.distribute_channels("dend", "gbar_kir", 0, 1, 0, 0, 0, float(par['gbar_kir_basal']['Value']))
self.distribute_channels("soma", "gbar_kir", 0, 1, 0, 0, 0, float(par['gbar_kir_somatic']['Value']))
self.distribute_channels("dend", "gbar_sk", 0, 1, 0, 0, 0, float(par['gbar_sk_basal']['Value']))
self.distribute_channels("soma", "gbar_sk", 0, 1, 0, 0, 0, float(par['gbar_sk_basal']['Value']))
self.distribute_channels("dend", "pbar_can", 0, 1, 0, 0, 0, 1e-7)
self.distribute_channels("dend", "pbar_cav32", 1, 0, 1.0, 120.0, -30.0, 1e-7)
self.distribute_channels("dend", "pbar_cav33", 1, 0, 1.0, 120.0, -30.0, 1e-8)
def _create_sectionlists(self):
self.allsecnames = []
self.allseclist = h.SectionList()
for sec in h.allsec():
self.allsecnames.append(sec.name())
self.allseclist.append(sec=sec)
self.nsomasec = 0
self.somalist = h.SectionList()
for sec in h.allsec():
if sec.name().find('soma') >= 0:
self.somalist.append(sec=sec)
if self.nsomasec == 0:
self.soma = sec
self.nsomasec += 1
self.axonlist = h.SectionList()
for sec in h.allsec():
if sec.name().find('axon') >= 0:
self.axonlist.append(sec=sec)
self.dendlist = h.SectionList()
for sec in h.allsec():
if sec.name().find('dend') >= 0:
self.dendlist.append(sec=sec)
def _set_nsegs(self, section=None, N=20):
""" def seg/sec. if section: set seg ~= 1/um """
if section:
dend_name = 'dend[' + str(int(section)) + ']'
for sec in self.allseclist:
if sec.name() == dend_name:
# TODO: this needs some thinking; how to best set number of segments
n = 2*int(sec.L/2.0)+1
if n > N:
sec.nseg = n
else:
sec.nseg = 2*(N/2) + 1 # odd number of seg
else:
sec.nseg = 2*int(sec.L/40.0)+1
else:
for sec in self.allseclist:
sec.nseg = 2*int(sec.L/40.0)+1
for sec in self.axonlist:
sec.nseg = 2 # two segments in axon initial segment
def distribute_channels(self, as1, as2, d3, a4, a5, a6, a7, g8):
h.distance(sec=self.soma)
for sec in self.allseclist:
# if right cellular compartment (axon, soma or dend)
if sec.name().find(as1) >= 0:
for seg in sec:
dist = h.distance(seg.x, sec=sec)
val = calculate_distribution(d3, dist, a4, a5, a6, a7, g8)
cmd = 'seg.%s = %g' % (as2, val)
exec(cmd)