Neuron and Python, NetCon Error

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
tmczhangtielin
Posts: 4
Joined: Fri Aug 01, 2014 12:14 pm

Neuron and Python, NetCon Error

Post by tmczhangtielin » Sat Aug 02, 2014 12:13 pm

Hi, everyone, I want to connect some neurons to be a small network, but some problem happened. Can anybody help me?
Here is the error information:

NEURON: NetCon pointer not associated with currently accessed section
Use section ... (&var(x)...) intead of ...(&section.var(x)...)
near line 0
^
NetCon(..., ..., 0, 10, 0.5)
nc4 = h.NetCon(cell2(0.5)._ref_v,syn_5_2,0,10,0.5)

Any advice is appreciated.

Code: Select all

'''
Two layer hiddel neuron network
Thomas
2014-08-01
'''
import neuron
from neuron import h

import numpy as np
from pylab import *

h.load_file("stdrun.hoc")

# create cells
cell1 = h.Section(name="cell1")
cell1.insert('hh')

cell2 = h.Section(name="cell2")
cell2.insert('hh')

cell3 = h.Section(name="cell3")
cell3.insert('hh')

cell4 = h.Section(name="cell4")
cell4.insert('hh')

cell5 = h.Section(name="cell5")
cell5.insert('hh')

cell6 = h.Section(name="cell6")
cell6.insert('hh')

cell7 = h.Section(name="cell7")
cell7.insert('hh')

cell8 = h.Section(name="cell8")
cell8.insert('hh')

# recorder
trec = h.Vector()
trec.record(h._ref_t) # record time
vrec1 = h.Vector()
vrec1.record(cell1(0.5)._ref_v) # record input neuron voltage
vrec2 = h.Vector()
vrec2.record(cell2(0.5)._ref_v)
vrec3 = h.Vector()
vrec3.record(cell3(0.5)._ref_v)
vrec4 = h.Vector()
vrec4.record(cell4(0.5)._ref_v)
vrec5 = h.Vector()
vrec5.record(cell5(0.5)._ref_v)
vrec6 = h.Vector()
vrec6.record(cell6(0.5)._ref_v)
vrec7 = h.Vector()
vrec7.record(cell7(0.5)._ref_v)
vrec8 = h.Vector()
vrec8.record(cell8(0.5)._ref_v)

# drive cell1 with a current stim
ic = h.IClamp(cell1(0.5))
ic.delay = 5 #ms
ic.dur = 25 #ms
ic.amp = 5 #nA, 5 -> 1 spike, 10 -> regular firing

ic2 = h.IClamp(cell2(0.5))
ic2.delay = 5 #ms
ic2.dur = 25 #ms
ic2.amp = 5 #nA, 5 -> 1 spike, 10 -> regular firing

# set synapse
syn_2_1 = h.Exp2Syn( cell2(0.5)  ) # set a synapse on perticular cell
syn_2_1.tau1=0.1 # rise
syn_2_1.tau2=1.0 # decay

syn_3_1 = h.Exp2Syn( cell3(0.5)  ) 
syn_3_1.tau1=0.1 # rise
syn_3_1.tau2=1.0 # decay

syn_4_1 = h.Exp2Syn( cell4(0.5)  ) 
syn_4_1.tau1=0.1 # rise
syn_4_1.tau2=1.0 # decay

syn_5_2 = h.Exp2Syn( cell5(0.5)  ) 
syn_5_2.tau1=0.1 # rise
syn_5_2.tau2=1.0 # decay

syn_5_3 = h.Exp2Syn( cell5(0.5)  ) 
syn_5_3.tau1=0.1 # rise
syn_5_3.tau2=1.0 # decay

syn_5_4 = h.Exp2Syn( cell5(0.5)  ) 
syn_5_4.tau1=0.1 # rise
syn_5_4.tau2=1.0 # decay

syn_6_2 = h.Exp2Syn( cell6(0.5)  ) 
syn_6_2.tau1=0.1 # rise
syn_6_2.tau2=1.0 # decay

syn_6_3 = h.Exp2Syn( cell6(0.5)  ) 
syn_6_3.tau1=0.1 # rise
syn_6_3.tau2=1.0 # decay

syn_6_4 = h.Exp2Syn( cell6(0.5)  ) 
syn_6_4.tau1=0.1 # rise
syn_6_4.tau2=1.0 # decay

syn_7_2 = h.Exp2Syn( cell7(0.5)  ) 
syn_7_2.tau1=0.1 # rise
syn_7_2.tau2=1.0 # decay

syn_7_3 = h.Exp2Syn( cell7(0.5)  ) 
syn_7_3.tau1=0.1 # rise
syn_7_3.tau2=1.0 # decay

syn_7_4 = h.Exp2Syn( cell7(0.5)  )
syn_7_4.tau1=0.1 # rise
syn_7_4.tau2=1.0 # decay

syn_8_5 = h.Exp2Syn( cell8(0.5)  ) 
syn_8_5.tau1=0.1 # rise
syn_8_5.tau2=1.0 # decay

syn_8_6 = h.Exp2Syn( cell8(0.5)  ) 
syn_8_6.tau1=0.1 # rise
syn_8_6.tau2=1.0 # decay

syn_8_7 = h.Exp2Syn( cell8(0.5)  ) 
syn_8_7.tau1=0.1 # rise
syn_8_7.tau2=1.0 # decay

# set connections
nc1 = h.NetCon(cell1(0.5)._ref_v,syn_2_1,0,10,0.5) # connect cell to target
nc2 = h.NetCon(cell1(0.5)._ref_v,syn_3_1,0,10,0.5) # 0 is voltage threshold for synaptic event generation, 10 is delay between threshold crossing
nc3 = h.NetCon(cell1(0.5)._ref_v,syn_4_1,0,10,0.5) # and event delivery, 0.5 is weight - can also change weight via nc.weight[0] = x

nc4 = h.NetCon(cell2(0.5)._ref_v,syn_5_2,0,10,0.5)
nc5 = h.NetCon(cell2(0.5)._ref_v,syn_6_2,0,10,0.5)
nc6 = h.NetCon(cell2(0.5)._ref_v,syn_7_2,0,10,0.5)

nc7 = h.NetCon(cell3(0.5)._ref_v,syn_5_3,0,10,0.5)
nc8 = h.NetCon(cell3(0.5)._ref_v,syn_6_3,0,10,0.5)
nc9 = h.NetCon(cell3(0.5)._ref_v,syn_7_3,0,10,0.5)

nc10 = h.NetCon(cell4(0.5)._ref_v,syn_5_4,0,10,0.5)
nc11 = h.NetCon(cell4(0.5)._ref_v,syn_6_4,0,10,0.5)
nc12 = h.NetCon(cell4(0.5)._ref_v,syn_7_4,0,10,0.5)

nc13 = h.NetCon(cell5(0.5)._ref_v,syn_8_5,0,10,0.5)
nc14 = h.NetCon(cell6(0.5)._ref_v,syn_8_6,0,10,0.5)
nc15 = h.NetCon(cell7(0.5)._ref_v,syn_8_7,0,10,0.5)

# set simulation variables
h.tstop = 100   # simulation duration (ms)
h.v_init = -60 # voltage initialization (mV)
h.dt = 0.025 # timestep (ms)
h.run() # run sim for h.tstop

# plot output
plot(trec.as_numpy(),vrec1.as_numpy(),'k',linewidth=2)
plot(trec.as_numpy(),vrec2.as_numpy(),'r',linewidth=2)
xlim((0,h.tstop))
xlabel('Time (ms)')
ylabel('Vm (mV)')
legend(['cell1 Vm','cell8 Vm'])
tight_layout()
show()

ramcdougal
Posts: 163
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: Neuron and Python, NetCon Error

Post by ramcdougal » Sat Aug 02, 2014 12:55 pm

To fix this, you must specify the containing section explicitly with a sec=, as in

Code: Select all

nc4 = h.NetCon(cell2(0.5)._ref_v,syn_5_2,0,10,0.5, sec=cell2)
This is because NEURON needs to know what thread/etc contains the pointer, and this information is not accessible via the raw pointer.

As an aside, note that you can shorten your code significantly by using arrays an list comprehensions. For example, you could say

Code: Select all

cell = [h.Section(name='cell%d' % i) for i in range(8)]
and then access cell[0], cell[1], ... cell[7]. If you really wanted to call them cell1, etc... you can still do that via

Code: Select all

cell1, cell2, cell3, cell4, cell5, cell6, cell7, cell8 = tuple([h.Section(name='cell%d' % i) for i in range(8)])

tmczhangtielin
Posts: 4
Joined: Fri Aug 01, 2014 12:14 pm

Re: Neuron and Python, NetCon Error

Post by tmczhangtielin » Sun Aug 03, 2014 8:53 am

It is amazing that it works. ^^
Thank you so much.
I will take your advice to make my code shorter and more efficiency.

Post Reply