extracellular stimulation in a particular order

The basics of how to develop, test, and use models.
Post Reply
Nuri

extracellular stimulation in a particular order

Post by Nuri »

Dear Ted,

I have used the subthalamic neuron template (by Gillies) and created a separate file for extracellular stimulation of the neuron.
The sections are created in a particular order, so I have attempted to create a seclist to stimulate them in a particular order.
However, the output file has produced zeros only, so I would like to know if you can spot the flaws in my code.

Furthermore, each of the dend sections (i.e. dend[0] and dend[1]) have 5 segments each, and my goal is to apply an extracellular stimulus to

dend[0] segment 1, dend[0] segment 2, dend[0] segment 3... soma, dend[1] segment 1, dend[1] segment 2... etc in this order.

Here is the code:

Code: Select all

objref tvec, pvec, datafile, dummy, m, veclist

   nosegs = 11
   numpts = 1001

//2 vectors to store time and potential 
tvec = new Vector(numpts)
pvec = new Vector(numpts)

//to scan in the datafile
datafile= new File()
datafile.ropen("stnSTIM1.txt") //external stimulus file 1001x1001 elements

m = new Matrix()
m.scanf(datafile)  

tvec=m.getcol(0) //column[0] of the matrix is the time vector

//number of sthcells
nsthcells=100

//creation of a seclist that contains all elements in the order they are connected
	objref sl
	sl = new SectionList()

//does this stimulate all the compartments? 11 in total (5 from dend[0], 1 from soma, 5 from dend[1]

for j=0, nsthcells-1 {
				
		 SThcells[j].dend[0] sl.append()
		 SThcells[j].soma sl.append()
		 SThcells[j].dend[1] sl.append()
 			}

//apply the extracellular stimulus each section

ii=0
veclist= new List()

	forsec sl{
		for (x, 0) {  
		ii+=1
			pvec=m.getcol(ii)
			insert extracellular
			pvec.play(&e_extracellular(x),tvec)
			veclist.append(pvec)
				}
		print secname()
			}
I also created a separate file that counts the number of action potentials at the soma of each cell and stores everything in another datafile

Thank you very much for your help
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: extracellular stimulation in a particular order

Post by ted »

You are in the best position to debug your own code.

Start with a single model cell, and forget about extracellular stimulation. Can you record from a single cell that is stimulated by a single IClamp attached to its soma?

After you get that to work, try to stimulate a single cell with an extracellular stimulus. Even if you seem to have success, verify that it works properly by using a space plot to monitor both extracellular potential and v along the entire length of the cell. Make sure that you understand the results that the model generates.

When that has succeeded, proceed to multiple cells--but not 100, or even a dozen. _Two_ cells. Then do three cells.

Make your life easier by following a cycle of incremental revision, testing, and debugging. Break your code into procs and funcs, each of which contains no more than maybe a dozen lines of code.
my goal is to apply an extracellular stimulus to

dend[0] segment 1, dend[0] segment 2, dend[0] segment 3... soma, dend[1] segment 1, dend[1] segment 2... etc in this order.
By "apply an extracellular stimulus" do you mean merely that you want model setup to be performed in a particular order, or do you mean that you want stimulation in the course of a simulation to follow a particular temporal sequence?
Nuri

Re: extracellular stimulation in a particular order

Post by Nuri »

By "apply an extracellular stimulus" do you mean merely that you want model setup to be performed in a particular order, or do you mean that you want stimulation in the course of a simulation to follow a particular temporal sequence?
I have an external stimulation (STNstim1.txt) file that contains the following voltage data for a given time:

column [0] column[1] column[2] column[3] .... column[6] .... column[n]
t dend[0].v(0.1) dend[0].v(0.3) dend[0].v(0.5) soma.v(0.5)

I believe the problem lies in the forsec loop, as it does not allow me to specify the particular segment within the section, so I wanted to know if there is a way to apply each voltage column to its corresponding section in this order.
If you have any suggestions on how to do this I would greatly appreciate.

I am trying to debug the code at the moment, as you advised.

Thank you very much
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: extracellular stimulation in a particular order

Post by ted »

So you want model setup to be performed in a particular order.
I believe the problem lies in the forsec loop, as it does not allow me to specify the particular segment within the section

Code: Select all

   forsec sl {
      for (x, 0) {
written in pseudocode is

Code: Select all

for each section in sl, make this section the currently accessed section
  for each internal node in the currently accessed section
    . . . 
which is OK so far. However, the

Code: Select all

         insert extracellular
in the internal loop gives me pause. I don't know whether this is a "doesn't matter" situation (just wastes a tiny bit of model setup time), or whether repeatedly asserting
insert densitymechanism
into the same section breaks previous Vector play() statements that affect densitymechanism in that section. The efficient location for the insert statement is inside the outer loop, just before the "for (x,0) {"--i.e.

Code: Select all

   forsec sl {
      insert extracellular
      for (x, 0) {
The way to be sure about the nature of the problem, of course, is to work on a very simple model (needs at least one section that has multiple segments) and see what happens to the time course of e_extracellular and v along the length of the model. Which you are now doing, and which may provide the key clue to solving the problem.
Nuri

Re: extracellular stimulation in a particular order

Post by Nuri »

I have tried to stimulate the 100 cells in 2 different ways, but the results I am getting are different.

In the first piece of code, I modified my template for the sthcells and created them in the order:

Code1

Code: Select all

/*Creating the cell template*/

begintemplate SThcell
public soma, dend0,dend1

create dend0,soma, dend1

proc init() {

    ndend = 2

    create dend0,soma,dend1

    dend0 {
      nseg = 5
      diam = 2.0
      L = 549.1
      Ra = 123
      insert pas
      g_pas = .0001666
      e_pas = -60.0
    }
etc... and so on

Then, instead of using a forsec loop in my stim file, I used a forall, because the sections are already created in the right order.

code2

Code: Select all

ii=0
veclist= new List()


//Part that will apply the extracellular stimulus to all sections of the sthcell

forall{
insert extracellular
for (x, 0) {  
ii+=1
	pvec=m.getcol(ii)
	pvec.play(&e_extracellular(x),tvec)
	veclist.append(pvec)
	}		
print secname()
}	
However, what I do not understand is why when I use a forsec loop instead, I do not get the same results. I have checked, and the voltages have been read in, but for some reason the results I am getting are different.

here is the forsec code:
code3

Code: Select all

sl = new SectionList()

//creation of a seclist that contains all elements in the order they are connected

for j=0, nsthcells-1 {
				
		 SThcells[j].dend[0] sl.append()
		 SThcells[j].soma sl.append()
		 SThcells[j].dend[1] sl.append()
		 
			}

//apply the extracellular stimulus to this section

ii=0
veclist= new List()


	forsec sl{
		insert extracellular
		for (x, 0) {  
		ii+=1
			pvec=m.getcol(ii)
			pvec.play(&e_extracellular(x),tvec)
			veclist.append(pvec)
				}
		print secname()
			}


Is there a functional difference between the forall and the forsec? Why do they give different results? I would really like the forsec way to work, since I am intending to increase the size of the dendritic trees, and writing each of the sections for that separately may be inefficient.

Thanks again for your help.
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: extracellular stimulation in a particular order

Post by ted »

For complete, unambiguous specification of cell and section, it may be best to put the forall statement in a public proc that is contained in the template, e.g.

Code: Select all

begintemplate SThcell
public soma, dend0,dend1
public attachstim
 . . .
proc attacstim() {
  forall {
    . . .
  }
}
Then you can iterate over all cell instances, calling each instance's attachstim() in turn.
for i=0,NUMCELLS cell.attachstim()

Question for you: what is the difference between the various e_extracellular time courses--do they differ by a mere scale factor?
Nuri

Re: extracellular stimulation in a particular order

Post by Nuri »

ted wrote:Question for you: what is the difference between the various e_extracellular time courses--do they differ by a mere scale factor?
The extracellular stimulus is the result of an FEM model. I can paste some sample columns of the file I am using to give you a better idea. In this case, I am applying a "square" pulse at each particular segment. I am not sure what you mean by scale factor, but the input at each section is different, and varies according to the results obtained from the external program that generated them.

Is this approach (proc attach stim) intended for solving the problem with the forsec loop too? So far I still havent managed to make that one work.
The top line of the text file contains the number of rows and columns. The first column is the time data and the others are the voltage (the initial voltages are all zeros, but this is not the case for the rest of the file)

1,00E+10 1,10E+10
0.0000000e+000 0.0000000e+000 0.0000000e+000
1,00E+06 0.0000000e+000 0.0000000e+000
2,00E+06 0.0000000e+000 0.0000000e+000
3,00E+06 0.0000000e+000 0.0000000e+000
4,00E+06 0.0000000e+000 0.0000000e+000
5,00E+06 0.0000000e+000 0.0000000e+000
6,00E+06 0.0000000e+000 0.0000000e+000
7,00E+06 0.0000000e+000 0.0000000e+000
8,00E+06 0.0000000e+000 0.0000000e+000
9,00E+06 0.0000000e+000 0.0000000e+000
1,00E+07 0.0000000e+000 0.0000000e+000
1,10E+07 0.0000000e+000 0.0000000e+000
1,20E+07 0.0000000e+000 0.0000000e+000
1,30E+07 0.0000000e+000 0.0000000e+000
1,40E+07 0.0000000e+000 0.0000000e+000
1,50E+07 0.0000000e+000 0.0000000e+000
1,60E+07 0.0000000e+000 0.0000000e+000
1,70E+07 0.0000000e+000 0.0000000e+000
1,80E+07 0.0000000e+000 0.0000000e+000
1,90E+07 0.0000000e+000 0.0000000e+000
2,00E+07 0.0000000e+000 0.0000000e+000
2,10E+07 0.0000000e+000 0.0000000e+000
2,20E+07 0.0000000e+000 0.0000000e+000
2,30E+07 0.0000000e+000 0.0000000e+000
2,40E+07 0.0000000e+000 0.0000000e+000
2,50E+07 0.0000000e+000 0.0000000e+000
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: extracellular stimulation in a particular order

Post by ted »

Nuri wrote:I am not sure what you mean by scale factor
Let vp1 and vp2 be the extracellular potentials at any two points p1 and p2. Does vp1(t) = vp2(t)*k where k is a constant? This will be true if the extracellular medium is linear and purely resistive.
Post Reply