/
cells_default.py
429 lines (358 loc) · 13.1 KB
/
cells_default.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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
"""Default cell models."""
# Authors: Mainak Jas <mjas@mgh.harvard.edu>
# Sam Neymotin <samnemo@gmail.com>
import numpy as np
from functools import partial
from .cell import Cell, Section
from .params import compare_dictionaries
from .params_default import (get_L2Pyr_params_default,
get_L5Pyr_params_default)
# Units for e: mV
# Units for gbar: S/cm^2 unless otherwise noted
# units for taur: ms
def _get_dends(params, cell_type, section_names):
"""Convert a flat dictionary to a nested dictionary.
Returns
-------
sections : dict
Dictionary of sections. Keys are section names
"""
prop_names = ['L', 'diam', 'Ra', 'cm']
sections = dict()
for section_name in section_names:
dend_prop = dict()
for key in prop_names:
if key in ['Ra', 'cm']:
middle = 'dend'
else:
# map apicaltrunk -> apical_trunk etc.
middle = section_name.replace('_', '')
dend_prop[key] = params[f'{cell_type}_{middle}_{key}']
sections[section_name] = Section(L=dend_prop['L'],
diam=dend_prop['diam'],
Ra=dend_prop['Ra'],
cm=dend_prop['cm'])
return sections
def _get_pyr_soma(p_all, cell_type):
"""Get somatic properties."""
return Section(
L=p_all[f'{cell_type}_soma_L'],
diam=p_all[f'{cell_type}_soma_diam'],
cm=p_all[f'{cell_type}_soma_cm'],
Ra=p_all[f'{cell_type}_soma_Ra']
)
def _cell_L2Pyr(override_params, pos=(0., 0., 0), gid=0.):
"""The geometry of the default sections in L2Pyr neuron."""
p_all = get_L2Pyr_params_default()
if override_params is not None:
assert isinstance(override_params, dict)
p_all = compare_dictionaries(p_all, override_params)
section_names = ['apical_trunk', 'apical_1', 'apical_tuft',
'apical_oblique', 'basal_1', 'basal_2', 'basal_3']
sections = _get_dends(p_all, cell_type='L2Pyr',
section_names=section_names)
sections['soma'] = _get_pyr_soma(p_all, 'L2Pyr')
end_pts = {
'soma': [[-50, 0, 765], [-50, 0, 778]],
'apical_trunk': [[-50, 0, 778], [-50, 0, 813]],
'apical_oblique': [[-50, 0, 813], [-250, 0, 813]],
'apical_1': [[-50, 0, 813], [-50, 0, 993]],
'apical_tuft': [[-50, 0, 993], [-50, 0, 1133]],
'basal_1': [[-50, 0, 765], [-50, 0, 715]],
'basal_2': [[-50, 0, 715], [-156, 0, 609]],
'basal_3': [[-50, 0, 715], [56, 0, 609]],
}
mechanisms = {
'km': ['gbar_km'],
'hh2': ['gkbar_hh2', 'gnabar_hh2',
'gl_hh2', 'el_hh2']
}
p_mech = _get_mechanisms(p_all, 'L2Pyr', ['soma'] + section_names,
mechanisms)
for sec_name, section in sections.items():
section._end_pts = end_pts[sec_name]
if sec_name == 'soma':
section.syns = ['gabaa', 'gabab']
else:
section.syns = ['ampa', 'nmda', 'gabaa', 'gabab']
section.mechs = p_mech[sec_name]
# parent, parent_end, child, {child_start=0}
topology = [
# Distal (Apical)
['soma', 1, 'apical_trunk', 0],
['apical_trunk', 1, 'apical_1', 0],
['apical_1', 1, 'apical_tuft', 0],
# apical_oblique comes off distal end of apical_trunk
['apical_trunk', 1, 'apical_oblique', 0],
# Proximal (basal)
['soma', 0, 'basal_1', 0],
['basal_1', 1, 'basal_2', 0],
['basal_1', 1, 'basal_3', 0]
]
sect_loc = {'proximal': ['apical_oblique', 'basal_2', 'basal_3'],
'distal': ['apical_tuft']}
synapses = _get_pyr_syn_props(p_all, 'L2Pyr')
return Cell('L2Pyr', pos,
sections=sections,
synapses=synapses,
topology=topology,
sect_loc=sect_loc,
gid=gid)
def _cell_L5Pyr(override_params, pos=(0., 0., 0), gid=0.):
"""The geometry of the default sections in L5Pyr Neuron."""
p_all = get_L5Pyr_params_default()
if override_params is not None:
assert isinstance(override_params, dict)
p_all = compare_dictionaries(p_all, override_params)
section_names = ['apical_trunk', 'apical_1',
'apical_2', 'apical_tuft',
'apical_oblique', 'basal_1', 'basal_2', 'basal_3']
sections = _get_dends(p_all, cell_type='L5Pyr',
section_names=section_names)
sections['soma'] = _get_pyr_soma(p_all, 'L5Pyr')
end_pts = {
'soma': [[0, 0, 0], [0, 0, 23]],
'apical_trunk': [[0, 0, 23], [0, 0, 83]],
'apical_oblique': [[0, 0, 83], [-150, 0, 83]],
'apical_1': [[0, 0, 83], [0, 0, 483]],
'apical_2': [[0, 0, 483], [0, 0, 883]],
'apical_tuft': [[0, 0, 883], [0, 0, 1133]],
'basal_1': [[0, 0, 0], [0, 0, -50]],
'basal_2': [[0, 0, -50], [-106, 0, -156]],
'basal_3': [[0, 0, -50], [106, 0, -156]]
}
# units = ['pS/um^2', 'S/cm^2', 'pS/um^2', '??', 'tau', '??']
mechanisms = {
'hh2': ['gkbar_hh2', 'gnabar_hh2',
'gl_hh2', 'el_hh2'],
'ca': ['gbar_ca'],
'cad': ['taur_cad'],
'kca': ['gbar_kca'],
'km': ['gbar_km'],
'cat': ['gbar_cat'],
'ar': ['gbar_ar']
}
p_mech = _get_mechanisms(p_all, 'L5Pyr', ['soma'] + section_names,
mechanisms)
for sec_name, section in sections.items():
section._end_pts = end_pts[sec_name]
if sec_name == 'soma':
section.syns = ['gabaa', 'gabab']
else:
section.syns = ['ampa', 'nmda', 'gabaa', 'gabab']
section.mechs = p_mech[sec_name]
if sec_name != 'soma':
sections[sec_name].mechs['ar']['gbar_ar'] = \
partial(_exp_g_at_dist, zero_val=1e-6,
exp_term=3e-3, offset=0.0)
topology = [
# Distal (Apical)
['soma', 1, 'apical_trunk', 0],
['apical_trunk', 1, 'apical_1', 0],
['apical_1', 1, 'apical_2', 0],
['apical_2', 1, 'apical_tuft', 0],
# apical_oblique comes off distal end of apical_trunk
['apical_trunk', 1, 'apical_oblique', 0],
# Proximal (basal)
['soma', 0, 'basal_1', 0],
['basal_1', 1, 'basal_2', 0],
['basal_1', 1, 'basal_3', 0]
]
sect_loc = {'proximal': ['apical_oblique', 'basal_2', 'basal_3'],
'distal': ['apical_tuft']}
synapses = _get_pyr_syn_props(p_all, 'L5Pyr')
return Cell('L5Pyr', pos,
sections=sections,
synapses=synapses,
topology=topology,
sect_loc=sect_loc,
gid=gid)
def _get_basket_soma(cell_name):
end_pts = [[0, 0, 0], [0, 0, 39.]]
return Section(
L=39.,
diam=20.,
cm=0.85,
Ra=200.,
end_pts=end_pts
)
def _get_pyr_syn_props(p_all, cell_type):
return {
'ampa': {
'e': p_all['%s_ampa_e' % cell_type],
'tau1': p_all['%s_ampa_tau1' % cell_type],
'tau2': p_all['%s_ampa_tau2' % cell_type],
},
'nmda': {
'e': p_all['%s_nmda_e' % cell_type],
'tau1': p_all['%s_nmda_tau1' % cell_type],
'tau2': p_all['%s_nmda_tau2' % cell_type],
},
'gabaa': {
'e': p_all['%s_gabaa_e' % cell_type],
'tau1': p_all['%s_gabaa_tau1' % cell_type],
'tau2': p_all['%s_gabaa_tau2' % cell_type],
},
'gabab': {
'e': p_all['%s_gabab_e' % cell_type],
'tau1': p_all['%s_gabab_tau1' % cell_type],
'tau2': p_all['%s_gabab_tau2' % cell_type],
}
}
def _get_basket_syn_props():
return {
'ampa': {
'e': 0,
'tau1': 0.5,
'tau2': 5.
},
'gabaa': {
'e': -80,
'tau1': 0.5,
'tau2': 5.
},
'nmda': {
'e': 0,
'tau1': 1.,
'tau2': 20.
}
}
def _get_mechanisms(p_all, cell_type, section_names, mechanisms):
"""Get mechanism
Parameters
----------
cell_type : str
The cell type
section_names : str
The section_names
mechanisms : dict of list
The mechanism properties to extract
Returns
-------
mech_props : dict of dict of dict
Nested dictionary of the form
sections -> mechanism -> mechanism properties
used to instantiate the mechanism in Neuron
"""
mech_props = dict()
for sec_name in section_names:
this_sec_prop = dict()
for mech_name in mechanisms:
this_mech_prop = dict()
for mech_attr in mechanisms[mech_name]:
if sec_name == 'soma':
key = f'{cell_type}_soma_{mech_attr}'
else:
key = f'{cell_type}_dend_{mech_attr}'
this_mech_prop[mech_attr] = p_all[key]
this_sec_prop[mech_name] = this_mech_prop
mech_props[sec_name] = this_sec_prop
return mech_props
def _exp_g_at_dist(x, zero_val, exp_term, offset):
"""Compute exponential distance-dependent ionic conductance.
Parameters
----------
x : float | int
Distance from soma
zero_val : float | int
Value of function when x = 0
exp_term : float | int
Mutiplier of x in the exponent
offset: float |int
Offset value added to output
"""
return zero_val * np.exp(exp_term * x) + offset
def basket(cell_name, pos=(0, 0, 0), gid=None):
"""Get layer 2 / layer 5 basket cells.
Parameters
----------
cell_name : str
The name of the cell.
pos : tuple
Coordinates of cell soma in xyz-space
gid : int or None (optional)
Each cell in a network is uniquely identified by it's "global ID": GID.
The GID is an integer from 0 to n_cells, or None if the cell is not
yet attached to a network. Once the GID is set, it cannot be changed.
Returns
-------
cell : instance of BasketSingle
The basket cell.
"""
if cell_name == 'L2Basket':
sect_loc = dict(proximal=['soma'], distal=['soma'])
elif cell_name == 'L5Basket':
sect_loc = dict(proximal=['soma'], distal=[])
else:
raise ValueError(f'Unknown basket cell type: {cell_name}')
sections = dict()
sections['soma'] = _get_basket_soma(cell_name)
synapses = _get_basket_syn_props()
sections['soma'].syns = list(synapses.keys())
sections['soma'].mechs = {'hh2': dict()}
topology = None
return Cell(cell_name, pos,
sections=sections,
synapses=synapses,
topology=topology,
sect_loc=sect_loc,
gid=gid)
def pyramidal(cell_name, pos=(0, 0, 0), override_params=None, gid=None):
"""Pyramidal neuron.
Parameters
----------
cell_name : str
'L5Pyr' or 'L2Pyr'. The pyramidal cell type.
pos : tuple
Coordinates of cell soma in xyz-space
override_params : dict or None (optional)
Parameters specific to L2 pyramidal neurons to override the default set
gid : int or None (optional)
Each cell in a network is uniquely identified by it's "global ID": GID.
The GID is an integer from 0 to n_cells, or None if the cell is not
yet attached to a network. Once the GID is set, it cannot be changed.
"""
if cell_name == 'L2Pyr':
return _cell_L2Pyr(override_params, pos=pos, gid=gid)
elif cell_name == 'L5Pyr':
return _cell_L5Pyr(override_params, pos=pos, gid=gid)
else:
raise ValueError(f'Unknown pyramidal cell type: {cell_name}')
def _linear_g_at_dist(x, gsoma, gdend, xkink):
"""Compute linear distance-dependent ionic conductance.
Parameters
----------
x : float | int
Distance from soma
gsoma : float | int
Somatic conductance.
gdend : float | int
Dendritic conductance
xkink : float | int
Plateau value where conductance is fixed at gdend.
Notes
-----
Linearly scales conductance along dendrite.
Returns gdend when x > xkink.
"""
return gsoma + np.min([xkink, x]) * (gdend - gsoma) / xkink
def pyramidal_ca(cell_name, pos, override_params=None, gid=None):
"""Calcium dynamics."""
if override_params is None:
override_params = dict()
override_params['L5Pyr_soma_gkbar_hh2'] = 0.06
override_params['L5Pyr_soma_gnabar_hh2'] = 0.32
gbar_ca = partial(
_linear_g_at_dist, gsoma=10., gdend=40., xkink=1501)
gbar_na = partial(
_linear_g_at_dist, gsoma=override_params['L5Pyr_soma_gnabar_hh2'],
gdend=28e-4, xkink=962)
gbar_k = partial(
_exp_g_at_dist, zero_val=override_params['L5Pyr_soma_gkbar_hh2'],
exp_term=-0.006, offset=1e-4)
override_params['L5Pyr_dend_gbar_ca'] = gbar_ca
override_params['L5Pyr_dend_gnabar_hh2'] = gbar_na
override_params['L5Pyr_dend_gkbar_hh2'] = gbar_k
cell = pyramidal(cell_name, pos, override_params=override_params,
gid=gid)
return cell