Issues using NetStim

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

Moderator: hines

Post Reply
maxwellphenderson
Posts: 22
Joined: Mon Mar 07, 2011 12:17 am

Issues using NetStim

Post by maxwellphenderson » Fri Feb 01, 2013 4:11 pm

Hello, I am having an issue creating NetStim objects in my neural networks. Basically, I am testing the dynamics of different neural networks and I want to give all neurons some random stimulus over the entire simulation. NetStim seems to be built for that, however; it is not appearing to work in my code.

So, since my neural networks were responding properly to set stimulus using Iclamps, I figured I would test out NetStim using a single neural compartment. I couldn't get that to work either! My code for this is below; what am I missing?

Code: Select all

from neuron import *
from neuron import h as nrn
from numpy import *
from neuronGen import *
from pylab import *

soma = h.Section()
stimNc = h.NetStim()		
stimNc.noise = 0		
stimNc.start = 1		
stimNc.number = 1000
stimNc.interval = 0.1
soma.push()		
stim = h.NetCon(soma(0.5)._ref_v, stimNc)
stim.weight[0] = 1
vec = {}
for var in 'v_1 ','t ':
    vec[var] = h.Vector()

# record the membrane potentials and
# synaptic currents
vec['v_1 '].record(soma(0.5)._ref_v)
vec ['t '].record(h._ref_t)

# run the simulation
h.load_file("stdrun.hoc")
h.init()
h.tstop = 20.0
h.run()

# plot the results
figure()
plot(vec['t '],vec['v_1 '])
show()
Also, I was wondering about another option... I was able to have success (aka activity) in my neural networks creating a random stimulus using the following code for each of my neurons in the network:

Code: Select all

VecSoma= h.Vector()
	VecSoma.record(neuron(0.5)._ref_v)
	stim = h.IClamp(neuron(0))
	stim.dur = simTime
	vecCurrent = h.Vector()
	vecCurrent.record(stim._ref_i)
	time = h.Vector()
	time.record(h._ref_t)
	listOfStims = []
	listOfTimes = []
	times = linspace(0,1000,40001) #For 1000 simulation length
	for i in times:
		a = random.randint(1, 100)
		if a > 90:
			listOfStims.append(5)
		else:
			listOfStims.append(0)
		#a = random.uniform(0,8)
		#listOfStims.append(3)
		#listOfTimes.append(i)
	VecT = h.Vector(listOfTimes)
	VecStim = h.Vector(listOfStims)
	VecStim.play(stim._ref_amp, VecT, 1)
This works in creating random stimulus... but a weird thing is that once a neuron fires an action potential, it seems to fire them at regular intervals for a while regardless of stimulus during that time. Is this just a natural bursting effect I am experiencing due to the neural geometry? Anyway, sorry this ended up being a lot of questions, but the main thing would still be getting the NetStim thing to work :) Thanks!

ted
Site Admin
Posts: 5567
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Issues using NetStim

Post by ted » Sat Feb 02, 2013 11:35 am

maxwellphenderson wrote:I am having an issue creating NetStim objects in my neural networks.
Actually the problem is that you aren't quite sure how to debug your code. The process is a methodical, repeated application of
propose a hypothesis
test the hypothesis

Your first sentence suggests a starting hyptothesis: "The NetStim doesn't exist."
How can you determine whether this is true or false? Address this hypothesis before going on to the next.
NetStim . . . is not appearing to work in my code.
Another hypothesis. After you discover that a NetStim exists (I'm not saying that it does--that's up to you to prove or disprove), how can you tell if it generates an event when you run a simulation? If it doesn't seem to, is that because its number parameter is 0, or is it because the start parameter is bigger than tstop?
I figured I would test out NetStim using a single neural compartment. I couldn't get that to work either!
How do you know it doesn't work? If the NetStim exists, If it does exist, does it generate an event during a run? If it does generate an event, have you used a NetCon to attach the NetStim to a synaptic mechanism like an ExpSyn or an Exp2Syn? If yes, are you sure that the NetCon's weight is not 0? If yes to that, have you checked the synaptic mechanism's conductance and current variables to see if they are changing in the course of a simulation? If yes to that, have you looked really closely at the membrane potential of your model cell to make sure that it isn't budging? If the membrane potential changes by a very small amount, are you sure that the NetCon's weight is large enough? or maybe the model cell is too big or has a huge specific membrane capacitance (how big is your cell, and what are its membrane properties?).
Also, I was wondering about another option...
. . .
This works in creating random stimulus...
Have you proved this by examining the contents of the vector?
but a weird thing is that once a neuron fires an action potential, it seems to fire them at regular intervals for a while regardless of stimulus during that time. Is this just a natural bursting effect I am experiencing due to the neural geometry?
Who knows. You haven't said anything about your model cell's geometry or membrane properties. Most likely it's a case of GIGO. Suggest you
1. use short run times, much shorter than 1000 ms.
2. determine how your model cell responds to simple stimuli. Use a known stimulus waveform--a single square pulse with known amplitude and duration would do for starters.

maxwellphenderson
Posts: 22
Joined: Mon Mar 07, 2011 12:17 am

Re: Issues using NetStim

Post by maxwellphenderson » Tue Feb 12, 2013 10:45 am

Thanks for getting back to me! I applied a more rigorous method checking my code one step at a time and eventually found my error. The following code ended up working for me to produce random stimulus:

Code: Select all

stimNc = h.NetStim()
	stimNc.noise = 1		
	stimNc.start = 0		
	stimNc.number = 100
	stimNc.interval = 5
	syn = h.ExpSyn (0.5, sec = soma)		
	nc = h.NetCon(stimNc, syn)
	nc.weight[0] = 10
This order seems very specific:

1. Make netstim
2. Make synapse attached to neural section
3. Make NC between synapse and netstim.

The fact that you cannot create a netstim and directly connect it to a neural section didn't make total sense to me (that it is possible to do this, but then without the synapse the neural section never actually receives any stimulus. So you can do it within the code but nothing ever happens).

One question though: is there an easy way in python to record the Netstim and see exactly when stimulus is happening? It seems in some of my runs that the stimulus is dying off a bit later in the simulation, and I wanted to know exactly when each neuron was receiving a netstim event. Thanks again!

ted
Site Admin
Posts: 5567
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Issues using NetStim

Post by ted » Tue Feb 12, 2013 11:14 am

maxwellphenderson wrote:I applied a more rigorous method checking my code one step at a time and eventually found my error.
A painful but necessary process. Think of how much you learned, and recall the Aha! moment when you found the error.
This order seems very specific:
1. Make netstim
2. Make synapse attached to neural section
3. Make NC between synapse and netstim.
Exactly as stated in the documentation of the NetCon class.
The fact that you cannot create a netstim and directly connect it to a neural section didn't make total sense to me (that it is possible to do this, but then without the synapse the neural section never actually receives any stimulus. So you can do it within the code but nothing ever happens).
The original implementation of artificial spiking cells in NEURON was done by adding a NET_RECEIVE block to a point process that generated no current. Before the advent of the ARTIFICIAL_CELL keyword in NMODL, all artificial spiking cells were point processes and had to be attached to a dummy section--a section whose sole purpose was to "host" one or more artificial spiking cells. Even today it is occasionally necessary to implement an artificial cell as a point process (for an example see Voltage waveform as a NetCon source viewtopic.php?f=15&t=2753).

So yes, you can "attach" an artificial spiking cell directly to a section, but if it generates no current--and NetCon generates no current--it won't affect the section. You have to use a NetCon to connect it to a point process that WRITEs an ionic current or generates a NONSPECIFIC_CURRENT or ELECTRODE_CURRENT.

Code: Select all

is there an easy way in python to record the Netstim and see exactly when stimulus is happening?
Use the NetCon class's record() method to capture event times.
It seems in some of my runs that the stimulus is dying off a bit later in the simulation, and I wanted to know exactly when each neuron was receiving a netstim event.
Wouldn't it be more informative to record the current generated by the synaptic mechanism?

Post Reply