-
-
Save wannaphong/7dc3aa6ffb4beecfe9d69c98924f19d3 to your computer and use it in GitHub Desktop.
ตัวอย่างการใช้งาน NEURON กับ Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The python version of the legacy NEURON tutorial | |
# | |
# The model consists of an axon and soma with HH channels | |
# and 3 passive dendrite cones. | |
# | |
# Start with | |
# $ nrngui -python | |
# >>> execfile('neuron_example.py') | |
# | |
# - E. Muller 03.2009. | |
# import the hoc interpreter object | |
from neuron import h | |
# enable the gui | |
from neuron import gui | |
soma = h.Section() | |
axon = h.Section() | |
axon.L = 1000.0 | |
axon.diam = 1.0 | |
axon.nseg = 40 | |
soma.L = 30.0 | |
soma.diam = 30.0 | |
soma.nseg = 1 | |
# make a list of 3 dendrites | |
dendrites = [h.Section() for x in range(3)] | |
# connect them up | |
# In [x]: ? soma.connect | |
# ... | |
# childSection.connect(parentSection, [parentX], [childEnd]) | |
axon.connect(soma,0,0) # hoc equiv: connect soma(0) axon(0) | |
for dend in dendrites: | |
dend.connect(soma,1,0) | |
# add Hodgkin-Huxley channels in soma and axon | |
soma.insert('hh') | |
axon.insert('hh') | |
# configure dendrites | |
for d in dendrites: | |
d.L = 200.0 # total length [micrometers] | |
d.insert('pas') # insert passive current | |
d.nseg = 20 # number of spatial discretization segments | |
# loop over segments setting parameters | |
for seg in d: | |
seg.pas.e = -65.0 #[mV] | |
seg.pas.g = 0.002 #[S/cm^2] | |
# set diameters as for a code with: | |
# d = 10 at x=0 | |
# d = 3 at x=1 | |
f = lambda x: 5.0*(1-x) + 1.0*(x) | |
for seg in d: | |
seg.diam = f(seg.x) | |
# biophysics | |
for sec in h.allsec (): | |
sec.Ra = 100 | |
sec.cm = 1 | |
# Stimulus | |
stim = h.IClamp(soma(0.5)) | |
stim.delay = 1.0 # [ms] | |
stim.dur = 5 # [ms] duration | |
stim.amp = 0.5 # [nA] amplitude | |
# Record the voltage | |
v = h.Vector() | |
v.record(soma(0.5)._ref_v) | |
#v1 = h.Vector() | |
#v1.record(axon(1.0)._ref_v) | |
#v2 = h.Vector() | |
#v2.record(dendrites[0](1.0)._ref_v) | |
# set | |
h.dt = 0.01 | |
# run for 50 ms | |
tstop = 50.0 | |
# Use NEURON's graphing functionality | |
# as there may still be issues importing neuron in ipython. | |
g = h.Graph() | |
g.size(0 , 10, -80 , 40) | |
g.addvar('v(0.5)', sec = soma) | |
#g.addvar('v(0.5)', sec=axon) | |
#g.addvar('v(1.0)', sec=axon) | |
#g.addvar('v(0.9)', sec=dendrites[0]) | |
# run the simulation | |
def go(): | |
h.finitialize() | |
g.begin() | |
while h.t<tstop: | |
h.fadvance() | |
# update the graph while simulating | |
g.plot(h.t) | |
g.flush() | |
go() | |
# g.size(0 , tstop, -80 , 40) | |
# stim.amp = 3 | |
# stim.dur = 20 | |
# use pylab to get a better plot | |
def pyplot(): | |
global v,tstop | |
# convert neuron vector to array | |
v_arr = array(v) | |
# time bins | |
t = linspace(0,tstop,len(v_arr)) | |
# normal pylab plot | |
plot(t,v_arr) | |
#pyplot() | |
#stim.amp = 2 | |
#stim.dur = 20.0 | |
#go() | |
#pyplot() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment