-
Notifications
You must be signed in to change notification settings - Fork 0
/
example3.py
84 lines (65 loc) · 1.87 KB
/
example3.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
from neuron import h, gui
from neuron.units import mV,ms
import plotly
import plotly.graph_objects as go
import sys
import itertools, math
h.load_file('import3d.hoc')
h.load_file('stdrun.hoc') # when you import gui, it automatically loads stdrun.hoc
print(f'analyzing {sys.argv[1]}')
class Cell:
def __init__(self,morphology):
self.morphology = morphology
self.load_morphology()
self.discretize()
self.add_channels()
def __str__(self) -> str:
return self.morphology
def add_channels(self):
h.hh.insert(self.axon) #insert accepts list of sections
h.hh.insert(self.soma)
passive_locs = [
sec for sec in self.all if sec not in self.axon and sec not in self.soma
]
h.pas.insert(passive_locs)
for sec in passive_locs:
for seg in sec:
seg.pas.g = 1e-6
def discretize(self):
freq = 100 #Hz
d_lambda = 0.1
for sec in self.all:
sec.nseg = math.ceil((sec.L / (d_lambda * h.lambda_f(freq))) / 2.) * 2 + 1
def load_morphology(self):
cell = h.Import3d_SWC_read()
cell.input(f'{self.morphology}.swc')
i3d = h.Import3d_GUI(cell, False)
i3d.instantiate(self)
c = Cell(sys.argv[1])
syn = h.ExpSyn(c.soma[0](0.5))
syn.e = 0 # mV
syn.tau = 2 * ms
ns = h.NetStim()
ns.number = 1
ns.start = 5 * ms
nc = h.NetCon(ns,syn)
nc.weight[0] = 0.1
nc.delay = 0
t = h.Vector().record(h._ref_t)
v = h.Vector().record(c.soma[0](0.5)._ref_v)
h.finitialize(-65 * mV)
h.continuerun(10 * ms)
ps = h.PlotShape(False)
ps.variable("v")
ps.scale(-65,20)
# add colorbar
ps.show(0)
ps.plot(plotly).show()
fig = go.Figure()
fig.add_trace(go.Scatter(x=t, y=v))
fig.update_layout({
"title": "soma(0.5) membrane potential",
"xaxis_title": "Time (ms)",
"yaxis_title": "Voltage (mV)"
})
fig.show()