-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneurons.py
223 lines (196 loc) · 7.83 KB
/
neurons.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
import numpy as np
from neuron import h
def taper_diam(sec, zero_bound, one_bound):
dx = 1.0 / sec.nseg
for seg, x in zip(sec, np.arange(dx / 2, 1, dx)):
seg.diam = (one_bound - zero_bound) * x + zero_bound
class ExcMorrisLecar(object):
def __init__(self, i, synapse_mechanisms={}):
super().__init__()
self.synapse_mechanisms = synapse_mechanisms
self.ndends = 4
self.syndict = {}
self.create_sections()
self.define_geometry()
self.build_topology()
self.build_subsets()
self.define_biophysics()
self.create_synapses()
self.position = 0
def create_sections(self):
"""create a soma"""
self.soma = h.Section(name="soma", cell=self)
self.trunk = h.Section(name="trunk", cell=self)
self.dends = []
for n in range(self.ndends):
self.dends.append(h.Section(name=f"dend{(n+1)}", cell=self))
def build_topology(self):
self.trunk.connect(self.soma)
for sec in self.dends:
sec.connect(self.trunk)
def build_subsets(self):
self.all = self.soma.wholetree()
def define_geometry(self):
self.soma.L = 10
self.soma.diam = 10
self.soma.nseg = 3
self.trunk.L = 10
self.trunk.diam = 5
self.trunk.nseg = 3
taper_diam(self.trunk, 10.0, 1.0)
for sec in self.dends:
sec.L = 20
sec.diam = 1.0
sec.nseg = 5
def define_biophysics(self):
Ra = 200
for sec in self.all:
sec.Ra = Ra
sec.cm = 1
self.soma.insert("ml")
for seg in self.soma:
seg.betaw_ml = 12.0
seg.gammaw_ml = 17.0
seg.phi_ml = 0.067
seg.gcabar_ml = 0.005 # Ca conductance in S/cm2
seg.gkbar_ml = 0.008 # K conductance in S/cm2
seg.gl_ml = 1.0e-4 # Passive conductance in S/cm2
seg.el_ml = -70 # Leak reversal potential mV
seg.ek = -90 # K reversal potential mV
self.trunk.insert("ml")
for seg in self.trunk:
seg.betaw_ml = 12.0
seg.gammaw_ml = 17.0
seg.phi_ml = 0.067
seg.gcabar_ml = 0.001 # Ca conductance in S/cm2
seg.gkbar_ml = 0.004 # K conductance in S/cm2
seg.gl_ml = 1.0e-4 # Passive conductance in S/cm2
seg.el_ml = -70 # Leak reversal potential mV
seg.ek = -90 # K reversal potential mV
for sec in self.dends:
sec.insert("pas")
for seg in sec:
seg.pas.g = 1e-5 # Passive conductance in S/cm2
seg.pas.e = -70 # Leak reversal potential mV
def create_synapses(self):
input_synlist = []
GABA_syn_mech_name = self.synapse_mechanisms["GABA"]
AMPA_syn_mech_name = self.synapse_mechanisms["AMPA"]
NMDA_syn_mech_name = self.synapse_mechanisms["NMDA"]
for sec in self.dends:
syn_AMPA = getattr(h, AMPA_syn_mech_name)(sec(0.5))
syn_NMDA = getattr(h, NMDA_syn_mech_name)(sec(0.5))
input_synlist.append({"AMPA": syn_AMPA, "NMDA": syn_NMDA})
self.syndict["input excitatory"] = input_synlist
excitatory_synlist = []
for sec in self.dends:
syn_AMPA = getattr(h, AMPA_syn_mech_name)(sec(0.5))
syn_NMDA = getattr(h, NMDA_syn_mech_name)(sec(0.5))
excitatory_synlist.append({"AMPA": syn_AMPA, "NMDA": syn_NMDA})
self.syndict["recurrent excitatory"] = excitatory_synlist
inhibitory_synlist = []
for sec in [self.soma, self.trunk] + self.dends:
syn_GABA = getattr(h, GABA_syn_mech_name)(sec(0.5))
inhibitory_synlist.append({"GABA": syn_GABA})
self.syndict["inhibitory"] = inhibitory_synlist
def set_position(self, pos):
self.position = pos
def connect2target(self, target, thresh=0):
"""Make a new NetCon with this cell's membrane
potential at the soma as the source (i.e. the spike detector)
onto the target passed in (i.e. a synapse on a cell).
Subclasses may override with other spike detectors."""
nc = h.NetCon(self.soma(1)._ref_v, target, sec=self.soma)
nc.threshold = thresh
return nc
class InhMorrisLecar(object):
def __init__(self, i, synapse_mechanisms={}):
super().__init__()
self.synapse_mechanisms = synapse_mechanisms
self.ndends = 4
self.syndict = {}
self.create_sections()
self.define_geometry()
self.build_topology()
self.build_subsets()
self.define_biophysics()
self.create_synapses()
self.position = 0
def create_sections(self):
"""create a soma"""
self.soma = h.Section(name="soma", cell=self)
self.trunk = h.Section(name="trunk", cell=self)
self.dends = []
for n in range(self.ndends):
self.dends.append(h.Section(name=f"dend{(n+1)}", cell=self))
def build_topology(self):
self.trunk.connect(self.soma)
for sec in self.dends:
sec.connect(self.trunk)
def build_subsets(self):
self.all = self.soma.wholetree()
def define_geometry(self):
self.soma.L = 10
self.soma.diam = 10
self.soma.nseg = 3
self.trunk.L = 10
self.trunk.diam = 5
self.trunk.nseg = 3
taper_diam(self.trunk, 10.0, 1.0)
for sec in self.dends:
sec.L = 20
sec.diam = 1.0
sec.nseg = 5
def define_biophysics(self):
Ra = 200
for sec in self.all:
sec.Ra = Ra
sec.cm = 1
self.soma.insert("ml")
for seg in self.soma:
seg.betaw_ml = 12.0
seg.gammaw_ml = 17.0
seg.phi_ml = 0.067
seg.gcabar_ml = 0.005 # Ca conductance in S/cm2
seg.gkbar_ml = 0.008 # K conductance in S/cm2
seg.gl_ml = 1.0e-4 # Passive conductance in S/cm2
seg.el_ml = -70 # Leak reversal potential mV
seg.ek = -90 # K reversal potential mV
self.trunk.insert("ml")
for seg in self.trunk:
seg.betaw_ml = 12.0
seg.gammaw_ml = 17.0
seg.phi_ml = 0.067
seg.gcabar_ml = 0.001 # Ca conductance in S/cm2
seg.gkbar_ml = 0.004 # K conductance in S/cm2
seg.gl_ml = 1.0e-4 # Passive conductance in S/cm2
seg.el_ml = -70 # Leak reversal potential mV
seg.ek = -90 # K reversal potential mV
for sec in self.dends:
sec.insert("pas")
for seg in sec:
seg.pas.g = 1e-5 # Passive conductance in S/cm2
seg.pas.e = -70 # Leak reversal potential mV
def create_synapses(self):
GABA_syn_mech_name = self.synapse_mechanisms["GABA"]
AMPA_syn_mech_name = self.synapse_mechanisms["AMPA"]
excitatory_synlist = []
for sec in self.dends:
syn_AMPA = getattr(h, AMPA_syn_mech_name)(sec(0.5))
excitatory_synlist.append({"AMPA": syn_AMPA})
self.syndict["excitatory"] = excitatory_synlist
inhibitory_synlist = []
for sec in [self.soma, self.trunk] + self.dends:
syn_GABA = getattr(h, GABA_syn_mech_name)(sec(0.5))
inhibitory_synlist.append({"GABA": syn_GABA})
self.syndict["inhibitory"] = inhibitory_synlist
def set_position(self, pos):
self.position = pos
def connect2target(self, target, thresh=0):
"""Make a new NetCon with this cell's membrane
potential at the soma as the source (i.e. the spike detector)
onto the target passed in (i.e. a synapse on a cell).
Subclasses may override with other spike detectors."""
nc = h.NetCon(self.soma(1)._ref_v, target, sec=self.soma)
nc.threshold = thresh
return nc