Code: Select all
# -*- coding: utf-8 -*-
'''
A small network around 10 neurons
Thomas
2014-11-18
'''
import neuron
import numpy as np
from pylab import *
class SmallNetwork:
neuronList = []
synapseList = []
def __init__(self, neuron_number):
self.neuron_number = neuron_number
def createNeurons(self):
for i in range(self.neuron_number):
name = "py_"+str(i)
neu = neuron.h.Section(name=name)
neu.insert('hh')
self.neuronList.insert(i, neu)
def createSynapse(self):
for i in range(self.neuron_number):
synapse = neuron.h.Exp2Syn(self.neuronList[i](0.5) ) # set a synapse on perticular cell
synapse.tau1=0.1 # rise
synapse.tau2=1.0 # decay
self.synapseList.insert(i, synapse)
def createConnections(self):
for i in range(self.neuron_number-1):
nc = neuron.h.NetCon(self.neuronList[i](0.5)._ref_v,self.synapseList[i+1],0,1,0.5,sec=self.neuronList[i]) #[threshold, delay, weight] [10,1,0]
def setRecorder(self):
self.trec = neuron.h.Vector()
self.trec.record(neuron.h._ref_t) # record time
self.vrec1 = neuron.h.Vector()
self.vrec1.record(self.neuronList[0](0.5)._ref_v) # record first input neuron voltage
self.vrec2 = neuron.h.Vector()
self.vrec2.record(self.neuronList[1](0.5)._ref_v)# record second input neuron voltage
def insertStims(self):
# drive cell1 with a current stim
#ic = neuron.h.IClamp(self.neuronList[0](0.5))
#ic.delay = 5 #ms
#ic.dur = 50 #ms
#ic.amp = 10 #nA, 5 -> 1 spike, 10 -> regular firing
ns = neuron.h.NetStim()
ns.interval = 1
ns.number = 10
ns.start = 40
ns.noise = 0.5
nc1 = neuron.h.NetCon(ns,self.synapseList[0])
def running(self):
self.createNeurons()
self.createSynapse()
self.createConnections()
self.setRecorder()
self.insertStims()
neuron.h.finitialize(-60)
neuron.init()
neuron.run(100)
def plotImages(self):
# plot output
plot(np.array(self.trec),np.array(self.vrec1),'k',linewidth=2)
plot(np.array(self.trec),np.array(self.vrec2),'r',linewidth=2)
xlim([0,neuron.h.tstop])
xlabel('Time (ms)')
ylabel('Vm (mV)')
tight_layout()
show()
smallnet = SmallNetwork(10)
smallnet.running()
smallnet.plotImages()