-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial_3.py
More file actions
100 lines (84 loc) · 3.67 KB
/
tutorial_3.py
File metadata and controls
100 lines (84 loc) · 3.67 KB
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
from neuron import h, gui
import matplotlib.pyplot as plt
class HHCell:
"""Two-section cell: A soma with active channels and
a dendrite with passive properties."""
def __init__(self):
self.create_sections()
self.build_topology()
self.define_geometry()
self.define_biophysics()
def create_sections(self):
"""Create the sections of the cell."""
self.soma = h.Section(name='soma')
self.dend = h.Section(name='dend')
def build_topology(self):
"""Connect the sections of the cell"""
self.dend.connect(self.soma(1))
def define_geometry(self):
"""Set the 3D geometry of the cell."""
self.soma.L = self.soma.diam = 12.6157 # microns
self.dend.L = 200 # microns
self.dend.diam = 1 # microns
self.dend.nseg = 10
def define_biophysics(self):
"""Assign the membrane properties across the cell."""
for sec in [self.soma, self.dend]: #
sec.Ra = 100 # Axial resistance in Ohm * cm
sec.cm = 1 # Membrane capacitance in micro Farads / cm^2
# Insert active Hodgkin-Huxley current in the soma
self.soma.insert('hh')
self.soma.gnabar_hh = 0.12 # Sodium conductance in S/cm2
self.soma.gkbar_hh = 0.036 # Potassium conductance in S/cm2
self.soma.gl_hh = 0.0003 # Leak conductance in S/cm2
self.soma.el_hh = -54.3 # Reversal potential in mV
# Insert passive current in the dendrite
self.dend.insert('pas')
self.dend.g_pas = 0.001 # Passive conductance in S/cm2
self.dend.e_pas = -65 # Leak reversal potential mV
def add_current_stim(self, delay):
self.stim = h.IClamp(self.dend(1.0))
self.stim.amp = 0.3 # input current in nA
self.stim.delay = delay # turn on after this time in ms
self.stim.dur = 1 # duration of 1 ms
def set_recording(self):
"""Set soma, dendrite, and time recording vectors on the cell. """
self.soma_v_vec = h.Vector() # Membrane potential vector at soma
self.dend_v_vec = h.Vector() # Membrane potential vector at dendrite
self.t_vec = h.Vector() # Time stamp vector
self.soma_v_vec.record(self.soma(0.5)._ref_v)
self.dend_v_vec.record(self.dend(0.5)._ref_v)
self.t_vec.record(h._ref_t)
def plot_voltage(self, title='Cell voltage', ylim=None, show=True):
"""Plot the recorded traces"""
fig = plt.figure(figsize=(8,4)) # Default figsize is (8,6)
plt.plot(self.t_vec, self.soma_v_vec, color='black', label='soma(0.5)')
plt.plot(self.t_vec, self.dend_v_vec, color='red', label='dend(0.5)')
plt.legend()
plt.xlabel('time (ms)')
plt.ylabel('mV')
plt.ylim(ylim)
plt.title(title)
if show:
plt.show()
return fig
postCell = HHCell()
postCell.set_recording()
preCell1 = HHCell()
preCell1.set_recording()
preCell1.add_current_stim(delay=10)
# connect preCell1 -> postCell to generate small EPSP (or spike)
postSyn1 = h.ExpSyn(postCell.dend(0.5))
postSyn1.e = 0 # excitatory synapse
# postSyn1.e = -80 # inhibitory synapse
postSyn1.tau = 2
pre1Conn = h.NetCon(preCell1.soma(0.5)._ref_v, postSyn1, sec=preCell1.soma)
pre1Conn.weight[0] = 0.002 # small EPSP
# pre1Conn.weight[0] = 0.005 # triggers spike postsynaptically
pre1Conn.delay = 1
h.tstop = 30 # set simulation duration
h.init()
h.run() # run simulation
# preCell1.plot_voltage(show=False, title='preCell1 voltage') # plot voltage
postCell.plot_voltage(show=False, title='postCell voltage', ylim=(-80, 30)) # plot voltage
plt.show()