Created
May 29, 2017 15:08
-
-
Save DaisukeMiyamoto/906e308420e227632842a2ffb3c7917c to your computer and use it in GitHub Desktop.
example2 of neuron with pyhon
This file contains hidden or 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
| 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 | |
| #ndend = 10 | |
| 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 | |
| # Create an electrode injecting current in the soma | |
| stim = neuron.h.IClamp(soma(0.5)) | |
| # Set the electrode properties | |
| stim.delay = 100 | |
| stim.dur = 100 | |
| stim.amp = 0.1 | |
| # 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""" | |
| 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_d = rec(dends[0](0.9)) | |
| rec_s = rec(soma(0.5)) | |
| run() | |
| plot_v(rec_t, rec_d) | |
| 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