Skip to content

Instantly share code, notes, and snippets.

@DaisukeMiyamoto
Created May 29, 2017 15:09
Show Gist options
  • Select an option

  • Save DaisukeMiyamoto/ff8c85bb506854f16ffd89f7b9f650ea to your computer and use it in GitHub Desktop.

Select an option

Save DaisukeMiyamoto/ff8c85bb506854f16ffd89f7b9f650ea to your computer and use it in GitHub Desktop.
example3 of neuron with python
import matplotlib.pyplot as plt
import neuron
soma = neuron.h.Section(name="soma")
# Set the geometry of the section
soma.nseg = 1
soma.diam = 10
soma.L = 10
# Insert Hodgkin Huxley channel models in this soma
soma.insert("hh")
# Create ndendrites
ndend = 2
dends = range(ndend)
for i in dends:
dend = neuron.h.Section()
dend.nseg = 5
dend.L = 300
dend.diam = 0.5
dend.Ra = 125
dend.insert("pas")
dend.connect(soma, 0)
dends[i] = dend
def add_syn(seg, time):
"""Add a synapse at a given location"""
stim = neuron.h.AlphaSynapse(seg)
stim.onset = time
stim.gmax = 0.2
return stim
# Record Time from NEURON (neuron.h._ref_t)
rec_t = neuron.h.Vector()
rec_t.record(neuron.h._ref_t)
def rec(seg):
"""Record voltage of a segment"""
rec_v = neuron.h.Vector()
rec_v.record(seg._ref_v)
return rec_v
def run():
"""Run a simulation"""
# Initialise the value of the voltagec
neuron.h.finitialize(-65)
# Set the time of the simulation
tstop = 300
# Run the simulation
neuron.run(tstop)
def plot_v(rec_t, rec_v, color="b"):
"""Plot a voltage trace"""
time = rec_t.as_numpy()
voltage = rec_v.as_numpy()
plt.plot(time, voltage, color=color)
plt.xlabel("Time [ms]")
plt.ylabel("Voltage [mV]")
plt.axis(xmin=0, xmax=max(time), ymin=min(voltage)-5, ymax=max(voltage)+5)
rec_s = rec(soma(0.5))
syn_a = add_syn(dends[0](0.5), 100)
syn_b = add_syn(dends[0](0.5), 100)
syn_a1 = add_syn(dends[0](0.5), 200)
syn_b1 = add_syn(dends[1](0.5), 200)
run()
plot_v(rec_t, rec_s, color="red")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment