/
cells_default.py
277 lines (236 loc) · 8.56 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
"""Default cell models."""
# Authors: Mainak Jas <mainak.jas@telecom-paristech.fr>
# Sam Neymotin <samnemo@gmail.com>
import numpy as np
from neuron import h
from .cell import Cell
from .params import compare_dictionaries
from .params_default import (get_L2Pyr_params_default,
get_L5Pyr_params_default,
_secs_L2Pyr, _secs_L5Pyr,
_secs_Basket)
# Units for e: mV
# Units for gbar: S/cm^2 unless otherwise noted
# units for taur: ms
def _get_dend_props(params, cell_type, section_names, prop_names):
"""Convert a flat dictionary to a nested dictionary.
Returns
-------
dend_props : dict
Nested dictionary. The outer dictionary has keys
with names of dendrites and the inner dictionary
specifies the geometry of these sections.
* L: length of a section in microns
* diam: diameter of a section in microns
* cm: membrane capacitance in micro-Farads
* Ra: axial resistivity in ohm-cm
"""
dend_props = 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}']
dend_props[section_name] = dend_prop
return dend_props
def _get_pyr_soma_props(p_all, cell_type):
"""Get somatic properties."""
return {
'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 _get_basket_soma_props(cell_name):
return {
'L': 39.,
'diam': 20.,
'cm': 0.85,
'Ra': 200.
}
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 basket(pos, cell_name='L2Basket', gid=None):
"""Get layer 2 / layer 5 basket cells.
Parameters
----------
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.
"""
p_secs = dict()
p_secs['soma'] = _get_basket_soma_props(cell_name)
p_syn = _get_basket_syn_props()
p_secs['soma']['syns'] = list(p_syn.keys())
p_secs['soma']['mechs'] = {'hh2': dict()}
sec_pts, _, _, _, topology = _secs_Basket()
for sec_name in p_secs:
p_secs[sec_name]['sec_pts'] = sec_pts[sec_name]
if cell_name == 'L2Basket':
sect_loc = dict(proximal=['soma'], distal=['soma'])
elif cell_name == 'L5Basket':
sect_loc = dict(proximal=['soma'], distal=[])
cell = Cell(cell_name, pos=pos, gid=gid)
cell.build(p_secs, p_syn, topology, sect_loc)
return cell
def pyramidal(pos, celltype, override_params=None, gid=None):
"""Pyramidal neuron.
Parameters
----------
pos : tuple
Coordinates of cell soma in xyz-space
celltype : str
'L5_pyramidal' or 'L2_pyramidal'. The pyramidal cell type.
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 celltype == 'L5_pyramidal':
p_all_default = get_L5Pyr_params_default()
cell_name = 'L5Pyr'
# 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']
}
section_names = ['apical_trunk', 'apical_1',
'apical_2', 'apical_tuft',
'apical_oblique', 'basal_1', 'basal_2', 'basal_3']
sec_pts, _, _, yscale, topology = _secs_L5Pyr()
elif celltype == 'L2_pyramidal':
p_all_default = get_L2Pyr_params_default()
cell_name = 'L2Pyr'
mechanisms = {
'km': ['gbar_km'],
'hh2': ['gkbar_hh2', 'gnabar_hh2',
'gl_hh2', 'el_hh2']}
section_names = ['apical_trunk', 'apical_1', 'apical_tuft',
'apical_oblique', 'basal_1', 'basal_2', 'basal_3']
sec_pts, _, _, yscale, topology = _secs_L2Pyr()
else:
raise ValueError(f'Unknown pyramidal cell type: {celltype}')
p_all = p_all_default
if override_params is not None:
assert isinstance(override_params, dict)
p_all = compare_dictionaries(p_all_default, override_params)
prop_names = ['L', 'diam', 'Ra', 'cm']
# Get somatic, dendritic, and synapse properties
p_soma = _get_pyr_soma_props(p_all, cell_name)
p_dend = _get_dend_props(p_all, cell_type=cell_name,
section_names=section_names,
prop_names=prop_names)
p_syn = _get_pyr_syn_props(p_all, cell_name)
p_secs = p_dend.copy()
p_secs['soma'] = p_soma
p_mech = _get_mechanisms(p_all, cell_name, ['soma'] + section_names,
mechanisms)
for key in p_secs:
p_secs[key]['mechs'] = p_mech[key]
if key == 'soma':
syns = ['gabaa', 'gabab']
else:
syns = list(p_syn.keys())
if celltype == 'L5_pyramidal':
p_secs[key]['mechs'][
'ar']['gbar_ar'] = lambda x: 1e-6 * np.exp(3e-3 * x)
p_secs[key]['syns'] = syns
for sec_name in p_secs:
p_secs[sec_name]['sec_pts'] = sec_pts[sec_name]
sect_loc = {'proximal': ['apicaloblique', 'basal2', 'basal3'],
'distal': ['apicaltuft']}
cell = Cell(name=cell_name, pos=pos, gid=gid)
cell.build(p_secs, p_syn, topology, sect_loc=sect_loc)
# insert dipole
yscale = yscale
cell.insert_dipole(yscale)
return cell