Sinusoidal extracellular stimulation

NMODL and the Channel Builder.
Post Reply
bee
Posts: 7
Joined: Sun Oct 23, 2011 8:37 pm

Sinusoidal extracellular stimulation

Post by bee »

Hello everyone,

I built a model using Neuron and would like to use an extracellular electrode and apply a sinusoidal stimulating current. I read the extracellular mechanism and it seams like I would want to set vext[n] = rho*Iext(t)/(4*pi*(X^2 + (L*(n-11))^2)^(.5)) where rho is the external resistivity, X is the distance from the axon to the electrode (at a 90 degree angle), L is the internodal length, and Iext(t) is my stimulating current (this is for an axon with 21 nodes). Is it OK if I declare my Iext(t) = amp * sin(2*PI*(t)*f*) as a variable in my hoc file and then insert extracellular and set vext[n] equal to the equation above? I do not think that I understand this mechanism very well. This is my first time using neuron and would greatly appreciate any suggestions.

Thank you!
bee
Posts: 7
Joined: Sun Oct 23, 2011 8:37 pm

Re: Sinusoidal extracellular stimulation

Post by bee »

I now understand that vext[n] is not the external voltage at each node. Also, I believe that I have to write an extra mod file for my sinusoidal stimulation and add it as a point process? I found a file called fsin.mod that does this but I am not sure how to deal with the pointer x. I would define the values for f, amp, del, and n in my hoc file right? But then there is also the xtra.mod file that works with the extracellular mechanism and I am confused about the different pointers and how to tie it all together.
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Sinusoidal extracellular stimulation

Post by ted »

A bit of clarification appears to be in order.
bee wrote:I now understand that vext[n] is not the external voltage at each node.
The word "node" is ambiguous in this context. Must distinguish between "node of Ranvier" (if your axon is myelinated) and "node as a discrete point in space at which NEURON computes the local potential." Which did you have in mind when writing "vext[n]"? In the following comments I use "node" without other qualifications to refer to the latter, and "node of Ranvier" to refer to the former.
Also, I believe that I have to write an extra mod file for my sinusoidal stimulation and add it as a point process?
The question is: how to make potential at extracellular nodes follow the desired time course. One could literally insert hoc statements into the main computational loop that would, at every time step, evaluate the sine function, then loop over all extracellular nodes, one at a time, computing the product of the sine value and an appropriate scale factor and storing the result in v at this node. This would be much slower than necessary, and it would also be incompatible with adaptive integration.
I found a file called fsin.mod
Presumably you refer to http://www.neuron.yale.edu/ftp/ted/neuron/fsin.mod. Be sure to follow the instructions in its header with regard to order of compilation of mod files.
I am not sure how to deal with the pointer x.
Time to review what the Programmer's Reference says about setpointer. Also look for other examples of setpointer usage in the hoc files that accompanied xtra.mod. Then realize that it's mercifully simpler than you thought, because is_xtra is GLOBAL -- which means you only need one instance of the Fsin class and just one setpointer statement to link its x variable to is_xtra.

Code: Select all

objref fsin
soma fsin = new Fsin(0.5)
setpointer fsin.x, is_xtra
I would define the values for f, amp, del, and n in my hoc file right?
True.
But then there is also the xtra.mod file that works with the extracellular mechanism and I am confused about the different pointers
There is no change in how xtra's im and ex POINTER variables are dealt with. The only new thing is the Fsin object and its x POINTER. I know it seems kind of mindbending the first time, if not migraine inducing, but it's really not that bad.
bee
Posts: 7
Joined: Sun Oct 23, 2011 8:37 pm

Re: Sinusoidal extracellular stimulation

Post by bee »

Hello Ted,

Thank you so much for replying.
ted wrote:The word "node" is ambiguous in this context. Must distinguish between "node of Ranvier" (if your axon is myelinated) and "node as a discrete point in space at which NEURON computes the local potential." Which did you have in mind when writing "vext[n]"? .
I meant node of ranvier on a myelinated axon
ted wrote:how to make potential at extracellular nodes follow the desired time course. One could literally insert hoc statements into the main computational loop that would, at every time step, evaluate the sine function, then loop over all extracellular nodes, one at a time, computing the product of the sine value and an appropriate scale factor and storing the result in v at this node.
For now I decided to start by calculating the extracellular voltage at each of the nodes of ranvier and then possibly start messing around with the mod files later.

Here is the section of the code where I try to calculate each voltage

for i=0, 20 {
node{
iext = amp * sin(2*PI*(t-del)*f*(0.001))
v(i) = rhoa*iext/(4*PI*(X1^2+(L*(i-11)^2)^.5)
insert extracellular e_extracellular(i) = v(i) }
}
would something like that work? I tried compiling but got an error: range variable domain is 0<=x<=1
I am now going through all the other variables to try to figure out what is wrong
bee
Posts: 7
Joined: Sun Oct 23, 2011 8:37 pm

Re: Sinusoidal extracellular stimulation

Post by bee »

When I comment out

e_extracellular(i) = v(i)

it works just fine. But then I am not setting the extracellular potential to the value I calculated. Am I using e_extracellular the wrong way?
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Sinusoidal extracellular stimulation

Post by ted »

The problem to be overcome is how to make each e_extracellular follow the desired time course throughout the simulation. Any code you plan to use for that purpose will have to be executed at each fadvance(). An efficient way to implement a sinusoidally fluctuating field is to use Fsin and xtra, and to use a setpointer statement to link Fsin's x variable to xtra's is variable. It doesn't get simpler than that.
bee
Posts: 7
Joined: Sun Oct 23, 2011 8:37 pm

Re: Sinusoidal extracellular stimulation

Post by bee »

Hello again,

I got busy and was not able to work on this for a while but I am giving it another try. I used a setpointer statement to link Fsin's x variable to xtra's is variable like you suggested

objref fsin
soma fsin = new Fsin(0.5)
setpointer fsin.x, is_xtra

I was able to compile, however when I try to run the program it complains about the last line:

setpointer fsin.x, is_xtra

It is hard to get going since I have not looked at this in a while. I made sure I had all the MOD files in the same folder and am trying to figure out what is wrong but any insight in the meantime would be appreciated.
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Sinusoidal extracellular stimulation

Post by ted »

If you insert xtra into a section, each internal node of that section has a separate instance of the xtra mechanism, and that instance of xtra has its own ex POINTER which must be linked to the e_extracellular variable at that node's location. I use a procedure to do this, right after model setup is complete.

Code: Select all

proc setpointers() {
  grindaway()  // in interpxyz.hoc, determines interpolated locations of nodes
  forall {
    if (ismembrane("xtra")) {
        for (x, 0) { // iterate over each internal node
                setpointer im_xtra(x), i_membrane(x)
                setpointer ex_xtra(x), e_extracellular(x)
        }
    }
  }
}

setpointers()
If you do anything that affects nseg in any section that has the xtra mechanism, or changes cell geometry, it is necessary to execute setpointers() again.
bee
Posts: 7
Joined: Sun Oct 23, 2011 8:37 pm

Re: Sinusoidal extracellular stimulation

Post by bee »

Instead of using all the given files for extracellular stimulation I am trying to write my own code because I think that is the only way I will really understand it, so instead of inserting an extracellular mechanism I am going to try to insert the equivalent current intracellularly. I am still going to use the fsin.mod file to generate the input pulse but I will then use that to calculate the potential at each of the nodes and then use that to calculate the intracellular current to be injected at each node. I have a few questions. How do I keep track of the timing in the hoc file?

I added the following code in my hoc file

proc voltages() {
objref fsin
objref Iext
node fsin = new Fsin(.5)
setpointer fsin.x, Iext

objref Ve
Ve = new Vector(21,0)
objref stim
stim = new Vector(21,0)

for i=0,20 {
Ve.x = rhoa*Iext/(4*PI*(X1^2+(L*(i-11))^2)^.5)
}
for i =1,19 {
stim.x = Ve.x[i-1]-2*Ve.x + Ve.x[i+1]
}
}
voltages()

First, it says I have a syntax error in the lines:
node fsin = new Fsin(.5)
setpointer fsin.x, Iext

I am also not sure if I am using the vectors correctly. If all of that was working, how can I make the hoc file calculate the new Ve's and stim's as Iext changes with time?
bee
Posts: 7
Joined: Sun Oct 23, 2011 8:37 pm

Re: Sinusoidal extracellular stimulation

Post by bee »

The reason why I got a syntax error for the following lines:

node fsin = new Fsin(.5)
setpointer fsin.x, Iext

is because I declared objref fsin inside of a proc

My program compiles and runs now without any error messages but when I plot the transmembrane voltage nothing happens. Right now I am just injecting the equivalent intracellular current from the extracellular stimulus into one of the nodes to see if it works. If it works with one then I will add the others. I modified NEURON block in fsin.mod like this:

NEURON {
POINT_PROCESS fsin
RANGE Ve1, Ve2, Ve3, stim2, del, f, amp, n
ELECTRODE_CURRENT stim2
}

I also added two other sections:

PROCEDURE settables (x) {
Ve1 = rhoa*x/(4*PI*(X1^2+(L*(0-11))^2)^.5)
Ve2 = rhoa*x/(4*PI*(X1^2+(L*(1-11))^2)^.5)
Ve3 = rhoa*x/(4*PI*(X1^2+(L*(2-11))^2)^.5)
}

BREAKPOINT {
stim2 = Ve1-2*Ve2 + Ve3
}

and in my hoc file I added this:

objref volt
proc voltages() {
node[2] volt = new Istim(.5)
}
voltages()

I thought this way the current calculated in fsin.mod would be injected into node 2 of my model but when I run the process nothing happens. Any ideas?
Thank you!
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Sinusoidal extracellular stimulation

Post by ted »

bee wrote:How do I keep track of the timing in the hoc file?
I don't understand this question. During a simulation, NEURON's run control system automatically advances t from whatever the start time is until t reaches the value specified by tstop.

Code: Select all

proc voltages() {
objref fsin
objref Iext
node fsin = new Fsin(.5)
setpointer fsin.x, Iext
 . . .
. . .
First, it says I have a syntax error in the lines:

Code: Select all

 node fsin = new Fsin(.5)
setpointer fsin.x, Iext
Iext is a NULLobject. What good does setpointer do if Iext is a NULLobject?
I am also not sure if I am using the vectors correctly. If all of that was working, how can I make the hoc file calculate the new Ve's and stim's as Iext changes with time?
You need a custom proc advance(). Have you read chapter 7 of The NEURON Book, specifically the discussion of the standard run system? You need to define a proc advance() of the form

Code: Select all

proc advance() {
  . . . statement(s) to be executed before calling fadvance() . . .
  fadvance()
}
and this should be done before your code calls run().
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Sinusoidal extracellular stimulation

Post by ted »

bee wrote:The reason why I got a syntax error for the following lines:

node fsin = new Fsin(.5)
setpointer fsin.x, Iext
What is Iext? If it's a NULLobject, the setpointer statement will do nothing useful.
when I run the process nothing happens. Any ideas?
Suggest you test everything you have done to verify that it works as you expected. Assume that nothing works properly.
I modified NEURON block in fsin.mod like this:

Code: Select all

NEURON {
  POINT_PROCESS fsin
  RANGE  Ve1, Ve2, Ve3, stim2, del, f, amp, n
  ELECTRODE_CURRENT stim2
}
I also added two other sections:

Code: Select all

PROCEDURE settables (x) {	      
 		Ve1 =  rhoa*x/(4*PI*(X1^2+(L*(0-11))^2)^.5)
		Ve2 =  rhoa*x/(4*PI*(X1^2+(L*(1-11))^2)^.5)
		Ve3 =  rhoa*x/(4*PI*(X1^2+(L*(2-11))^2)^.5)	
}

BREAKPOINT {
 stim2 = Ve1-2*Ve2 + Ve3
}
and in my hoc file I added this:

Code: Select all

objref volt
proc voltages() {
	node[2] volt = new Istim(.5)
}
voltages()
What is Istim? Have you verified that an Istim works the way you think it should work? What do you think your changes to fsin have accomplished? Did they in fact accomplish what you expected?

When developing something more or less de novo, it's best to proceed in small steps, making only one change at a time and verifying that every change works as expected.
Post Reply