1# -*- coding: utf-8 -*- 2# 3# hh_psc_alpha.py 4# 5# This file is part of NEST. 6# 7# Copyright (C) 2004 The NEST Initiative 8# 9# NEST is free software: you can redistribute it and/or modify 10# it under the terms of the GNU General Public License as published by 11# the Free Software Foundation, either version 2 of the License, or 12# (at your option) any later version. 13# 14# NEST is distributed in the hope that it will be useful, 15# but WITHOUT ANY WARRANTY; without even the implied warranty of 16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17# GNU General Public License for more details. 18# 19# You should have received a copy of the GNU General Public License 20# along with NEST. If not, see <http://www.gnu.org/licenses/>. 21 22""" 23Example using Hodgkin-Huxley neuron 24----------------------------------- 25 26This example produces a rate-response (FI) curve of the Hodgkin-Huxley 27neuron ``hh_psc_alpha`` in response to a range of different current (DC) stimulations. 28The result is plotted using matplotlib. 29 30Since a DC input affects only the neuron's channel dynamics, this routine 31does not yet check correctness of synaptic response. 32""" 33 34import nest 35import numpy as np 36import matplotlib.pyplot as plt 37 38nest.set_verbosity('M_WARNING') 39nest.ResetKernel() 40 41simtime = 1000 42 43# Amplitude range, in pA 44dcfrom = 0 45dcstep = 20 46dcto = 2000 47 48h = 0.1 # simulation step size in mS 49 50neuron = nest.Create('hh_psc_alpha') 51sr = nest.Create('spike_recorder') 52 53sr.record_to = 'memory' 54 55nest.Connect(neuron, sr, syn_spec={'weight': 1.0, 'delay': h}) 56 57# Simulation loop 58n_data = int(dcto / float(dcstep)) 59amplitudes = np.zeros(n_data) 60event_freqs = np.zeros(n_data) 61for i, amp in enumerate(range(dcfrom, dcto, dcstep)): 62 neuron.I_e = float(amp) 63 print(f"Simulating with current I={amp} pA") 64 nest.Simulate(1000) # one second warm-up time for equilibrium state 65 sr.n_events = 0 # then reset spike counts 66 nest.Simulate(simtime) # another simulation call to record firing rate 67 68 n_events = sr.n_events 69 amplitudes[i] = amp 70 event_freqs[i] = n_events / (simtime / 1000.) 71 72plt.plot(amplitudes, event_freqs) 73plt.show() 74