Extracting coordinates in stylized geometry

Anything that doesn't fit elsewhere.
dinkc
Posts: 25
Joined: Mon Nov 28, 2016 12:38 pm

Extracting coordinates in stylized geometry

Hello all,

I made 10 neurons with a soma,1 axon and 10 dendrites using 'template' function. The code works well and I could see my neurons in my shape plot. But now, I am trying to extract the coordinates for each of the section of my neurons which I created with stylized geometry using n3d(), x3d(), y3d() etc available in neuron syntax. The exact code I wrote for it is :

Code: Select all

``````forall {
print secname()
for i=0,n3d()-1 print i, x3d(i), y3d(i), z3d(i), diam3d(i)
}``````

Although it might look really easy, I got stuck in it since last few days. I only get the name of the section printed after executing this code. However, I do not get any coordinates which I wanted to have. When I just gave the command n3d() to check it, it returned me the value 0. I couldn't understand how the number of 3d locations could be 0? Could somebody kindly look into my code (the complete code with neuron model is attached below) and suggest me what went wrong? I would highly appreciate your help.

Sincerely,
Dina

Code: Select all

``````load_file("nrngui.hoc")

begintemplate Neuron
public soma, dend, axon

create soma, axon, dend[1]

proc init() {

ndend = 10

create soma, axon, dend[ndend]

soma {
nseg = 1
diam = 80
L = 80
Ra = 123.0
insert hh
gnabar_hh=0.25
gl_hh = .0001666
el_hh = -60.0
}

axon {
nseg = 100
diam = 15
L = 200
Ra = 123
insert hh
gnabar_hh=0.25
gl_hh = .0001666
el_hh = -60.0
}

for i=0, ndend-1 dend[i] {
nseg = 20
diam = 1.0
L = 100
Ra = 123
insert pas
g_pas = .0001666
e_pas = -60.0
}

// Connect things together
connect axon(0), soma(0)
for i=0, ndend-1 {
connect dend[i](0), soma(1)
}

}
endtemplate Neuron

ndend = 10
nNeurons = 10

objectvar Neurons[nNeurons]

for i = 0, nNeurons-1 {
Neurons[i] = new Neuron()
}

for i = 0, nNeurons-1 {
Neurons[i].soma psection()

}

// This is where I have problem
forall {
print secname()
for i=0,n3d()-1 print i, x3d(i), y3d(i), z3d(i), diam3d(i)
}

access Neurons[0].soma

``````

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

Re: Extracting coordinates in stylized geometry

Nothing went wrong. You used the stylized method (L, diam) to specify the geometry of your model's sections, but didn't do anything that would force generation of corresponding 3d data, so there are no 3d data. You'll want to read about define_shape(), or consider whether you want to create an instance of the ShapePlot class--see their entries in the Programmer's Reference.

dinkc
Posts: 25
Joined: Mon Nov 28, 2016 12:38 pm

Re: Extracting coordinates in stylized geometry

Dear Ted,

Thank you so much! I did as you said and it worked. Thanks a lot for your suggestion!

Yours sincerely,
Dina

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

Re: Extracting coordinates in stylized geometry

Here are a couple of suggestions.

1. Use the CellBuilder to generate cell class templates after you have set up topology (including definition of subsets), specified geometry (including specification of spatial discretization method), and biophysics (including algorithmic specification of spatial variation of channel densities), go to the Management page and click on Cell Type, specify the class name, and finally click on the button "Save hoc code in a file" (you may have to drag the bottom margin of the CellBuilder down to expose that button). The resulting code will be very nicely organized, human readable, and will contain useful procedures like the one that can be used to position each cell instance at the xyz location of your choice, and another that discretizes the cell according to the d_lambda rule (assuming that you selected the d_lambda rule as the discretization strategy). The file is also fully customizable by revising with a plain text editor; for example, instead of using the stylized (L, diam) specification of cell geometry, you can use the 3d specification which gives you complete control over section lengths and orientations as well as diameter variation over the length of any or all sections. For that matter, you could even generate the topology and geometry of the cell algorithmically.

2. When writing 3d a section's 3d specification, it is useful to treat the 0 end of each section as being located at 0,0,0, and specify the remaining 3d points of the section using relative coordinates (i.e. relative to the section's 0 end). After all connect statements have been executed, just call define_shape() and all sections will be translated so that the first point of each section has the same coordinates as the coordinates of the point in the parent section to which it is attached. This works as long as each non-root section is connected to the 0 or 1 end of its parent. (the root section of a model cell is the section that has no parent).

dinkc
Posts: 25
Joined: Mon Nov 28, 2016 12:38 pm

Re: Extracting coordinates in stylized geometry

Dear Ted,

Thank you so much for your valuable suggestions. I really enjoyed working with Cell Builder. I have a couple of queries, could you please help me understand it?

1) When I use template function to create multiple neurons (say 100 neurons), I got neurons being arranged in (1*100) fashion (neurons being added only along one direction) but however I wanted it to be arranged in 10*10 fashion (like a cube of neurons). You explained that I could position each cell instance at xyz location of my choice with this cell builder. So, probably this should solve this problem but however I could not make out exactly what needs to be done next after I have the hoc code exported from the cell builder. Could you kindly explain it to me?
2) I always wanted to have the tip of my dendrite to be located at certain depth from the surface of the skull but since I am just modeling the neuron, I found no means to explain this to the software. Is there any thing by any chance to deal with this issue? I would appreciate your suggestions.

Your guidance has always helped me a lot. Thank you once again for your valuable guidance!

Yours sincerely,
Dina KC

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

Re: Extracting coordinates in stylized geometry

When you export a cell class from the CellBuilder, the class has a method called position that you can use to change the xyz coordinates of the root node (0 end) of the root section (the section that has no parent). Examine the template and you'll see what I mean--notice the public proc called position?

Assuming that Cell is the name of such a cell class, these statements create an instance of that class which is called foo and has its root node located at (10,20,30):
objref foo
foo = new Cell()
foo.position(10,20,30)
I always wanted to have the tip of my dendrite to be located at certain depth from the surface of the skull
Assuming that the y axis is perpendicular to the cortical surface, the positive direction for y is up, and you want the highest location in your cell to be at ytop, the first step is to find ymax (the most positive y coordinate in your model cell), and the second step is to call position with the arguments 0, ytop-ymax, 0. This bit of hoc will do the job:
ymax = -1e9
forsec foo.all for i=0,n3d()-1 if (y3d(i)>ymax) ymax=y3d(i)
// ymax is now the y coordinate of the highest point in foo
foo.position(0,ytop-ymax,0) // shifts all points in foo vertically

dinkc
Posts: 25
Joined: Mon Nov 28, 2016 12:38 pm

Re: Extracting coordinates in stylized geometry

Dear Ted,

Once again thank you so much for your valuable suggestions. I will let you know how it goes. Tons of thanks for your help.

Yours sincerely,
Dina KC

dinkc
Posts: 25
Joined: Mon Nov 28, 2016 12:38 pm

Re: Extracting coordinates in stylized geometry

Dear Ted,

As you explained, I used Cell Builder to generate cell class template and used that template to create 5 neurons by adding few lines of code to the hoc file I exported. However, I cannot see my 5 neurons in the 'shape plot' when I do '3-D rotate'. I just see the schematic diagram of one neuron but cannot see 5 neurons . I added following code to the hoc file I exported from Cell Builder.

Code: Select all

``````nNeurons = 5  // number of neurons=5

objectvar Neurons[nNeurons]

for i = 0, nNeurons-1 {
Neurons[i] = new pyramidalneuron()  //pyramidalneuron is the name of the cell class
}

for i = 0, nNeurons-1 {
Neurons[i].soma psection()
}

``````
I could however see the section properties of all 5 neurons. Could you please tell me what went wrong with my process? I look forward to hearing from you.
Yours sincerely,
Dina KC

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

Re: Extracting coordinates in stylized geometry

dinkc wrote:used that template to create 5 neurons by adding few lines of code to the hoc file I exported.
That works, but it is best to leave the hoc file that contains the template unchanged. Instead it is best for your program to be organized in a modular fashion.
(why? suppose you want to use the same cell class template in a different model, or you want to use a different cell class template in this model).

So write a main file called init.hoc that is organized like this:

Code: Select all

``````/*
comments that say what the program is supposed to do
*/
load_file("cellclass1.hoc") // or whatever you call the hoc file that defines the cell class
// next load any other template files this program needs
// then statements that create cell instances, connect them, etc.``````
I cannot see my 5 neurons in the 'shape plot' when I do '3-D rotate'. I just see the schematic diagram of one neuron but cannot see 5 neurons
But you were able to verify that their sections existed--excellent, you have the instincts of a debugger. And you're closer to figuring out the cause of the problem than you know.

What did you do about the xyz coordinates of their root nodes? If you didn't move them to new locations, then they're all on top of each other. Remember the classs's position() method . . .

Code: Select all

``````objectvar Neurons[nNeurons]

for i = 0, nNeurons-1 {
Neurons[i] = new pyramidalneuron()  //pyramidalneuron is the name of the cell class
}``````
Suggest you use Lists to manage collections of objects such as cells. Much more flexible than using indexed notation (for one thing, you won't have to sprinkle the names of symbolic constants like nNeurons throughout your code). This would be a good time to see some examples of the use of Lists to manage collections of cells and other objects. Check out the source code for the serial implementations of the models described in
Hines, M.L. and Carnevale, N.T. Translating network models to parallel hardware in NEURON. J. Neurosci. Methods 169:425-455, 2008.
You can pick up a preprint of that paper from http://www.neuron.yale.edu/neuron/nrnpubs, and the source code is downloadable from ModelDB.

dinkc
Posts: 25
Joined: Mon Nov 28, 2016 12:38 pm

Re: Extracting coordinates in stylized geometry

Dear Ted,

Thank you so much for your suggestions. Indeed all neurons were on top of each other. As you explained, I shifted the xyz coordinates of their root nodes and soon was able to see all my 5 neurons in shape plot. Next, I will try implementing Lists to manage collection of objects as you have explained it to me. Thank you so much for the link.
Once again thanks a lot for your support and guidance.

Yours sincerely,
Dina KC

dinkc
Posts: 25
Joined: Mon Nov 28, 2016 12:38 pm

Re: Extracting coordinates in stylized geometry

Dear Ted,

I am facing some weird problem which I am not able to figure out. Could you please help me?
When I was using stylized geometry, I was able to get coordinates for every segments of the section I built. For example if the number of segments in axon is 10 , I got 12 sets of coordinates. Since stylized method didn't meet my needs, I switched to point3D method to define my own coordinates. However when I define 3D coordinates on my own (using pt3Dclear and pt3Dadd) , I only get coordinates for the 0-end and 1-end of each section i.e I only get two sets of coordinates as if I had just 1 segment. Although the number of segments in axon is 10, I just get 2 sets of coordinates irrespective of my number of segments. Could you kindly give an insight to me about this problem?
I also noticed in the template obtained from cell builder that all sections had same diameter of 1 micrometers although I defined different diameters. For example, my soma has a diameter of 80 micrometers but however I saw that my soma is defined to be of 1 micrometers. eg.

Code: Select all

``soma {pt3dclear() pt3dadd(0, 0, 0, 1) pt3dadd(0, 15, 0, 1)}``
We can see that diameter in (x,y,z,diam) is 1 in this code. I am also not able to relate this part of the code. Could you please help me understand this? I have attached the complete code I obtained from cell builder along with this message. You will notice that I added few lines of code below the template code to generate the coordinates.
I would appreciate your guidance and support.

Yours sincerely,
Dina KC

Code: Select all

``````//execute1("celltypes.element(\"pyramidalneuron\")")

begintemplate pyramidalneuron
public init, topol, basic_shape, subsets, geom, biophys, geom_nseg, biophys_inhomo
public synlist, x, y, z, position, connect2target

public soma, apicaldend, dend, axon
public all, apicaldendrite, dendrite, axons

objref synlist

proc init() {
topol()
subsets()
geom()
biophys()
geom_nseg()
synlist = new List()
synapses()
x = y = z = 0 // only change via position
}

create soma, apicaldend, dend[10], axon

proc topol() { local i
connect apicaldend(0), soma(1)
for i = 0, 9 connect dend[i](0), soma(1)
connect axon(0), soma(0)
basic_shape()
}
proc basic_shape() {
soma {pt3dclear() pt3dadd(0, 0, 0, 1) pt3dadd(0, 15, 0, 1)}
apicaldend {pt3dclear() pt3dadd(0, 15, 0, 1) pt3dadd(0, 165, 0, 1)}
dend {pt3dclear() pt3dadd(0, 15, 0, 1) pt3dadd(135, 30, 0, 1)}
dend[1] {pt3dclear() pt3dadd(0, 15, 0, 1) pt3dadd(135, -29, 0, 1)}
dend[2] {pt3dclear() pt3dadd(0, 15, 0, 1) pt3dadd(45, 120, 0, 1)}
dend[3] {pt3dclear() pt3dadd(0, 15, 0, 1) pt3dadd(60, 105, 0, 1)}
dend[4] {pt3dclear() pt3dadd(0, 15, 0, 1) pt3dadd(-44, 120, 0, 1)}
dend[5] {pt3dclear() pt3dadd(0, 15, 0, 1) pt3dadd(-59, 105, 0, 1)}
dend[6] {pt3dclear() pt3dadd(0, 15, 0, 1) pt3dadd(-74, 90, 0, 1)}
dend[7] {pt3dclear() pt3dadd(0, 15, 0, 1) pt3dadd(75, 90, 0, 1)}
dend[8] {pt3dclear() pt3dadd(0, 15, 0, 1) pt3dadd(90, 75, 0, 1)}
dend[9] {pt3dclear() pt3dadd(0, 15, 0, 1) pt3dadd(-89, 75, 0, 1)}
axon {pt3dclear() pt3dadd(0, 0, 0, 1) pt3dadd(0, -194, 0, 1)}
}

objref all, apicaldendrite, dendrite, axons
proc subsets() { local i
objref all, apicaldendrite, dendrite, axons
all = new SectionList()
soma all.append()
apicaldend all.append()
for i=0, 9 dend[i] all.append()
axon all.append()

apicaldendrite = new SectionList()
apicaldend apicaldendrite.append()

dendrite = new SectionList()
for i=0, 9 dend[i] dendrite.append()

axons = new SectionList()
axon axons.append()

}
proc geom() {
forsec all {  }
soma.L = 80
apicaldend.L = 2000
dend.L = 100
dend[1].L = 100
dend[2].L = 100
dend[3].L = 100
dend[4].L = 100
dend[5].L = 100
dend[6].L = 100
dend[7].L = 100
dend[8].L = 100
dend[9].L = 100
axon.L = 6500
soma.diam = 80
apicaldend.diam = 2
dend.diam = 1
dend[1].diam = 1
dend[2].diam = 1
dend[3].diam = 1
dend[4].diam = 1
dend[5].diam = 1
dend[6].diam = 1
dend[7].diam = 1
dend[8].diam = 1
dend[9].diam = 1
axon.diam = 15
forsec apicaldendrite {  }
forsec dendrite {  }
forsec axons {  }
soma {  }
}
external lambda_f
proc geom_nseg() {
forsec apicaldendrite { nseg = 20  }
forsec dendrite { nseg = 2  }
forsec axons { nseg = 65  }
soma { nseg = 2  }
}
proc biophys() {
forsec all {
Ra = 123
cm = 1
}
forsec apicaldendrite {
insert pas
g_pas = 0.001666
e_pas = -60
}
forsec dendrite {
insert pas
g_pas = 0.001666
e_pas = -60
}
forsec axons {
insert hh
gnabar_hh = 0.52
gkbar_hh = 0.036
gl_hh = 0.0001666
el_hh = -60
}
soma {
insert hh
gnabar_hh = 0.25
gkbar_hh = 0.036
gl_hh = 0.0001666
el_hh = -60
}
}
proc biophys_inhomo(){}
proc position() { local i
soma for i = 0, n3d()-1 {
pt3dchange(i, \$1-x+x3d(i), \$2-y+y3d(i), \$3-z+z3d(i), diam3d(i))
}
x = \$1  y = \$2  z = \$3
}
obfunc connect2target() { localobj nc //\$o1 target point process, optional \$o2 returned NetCon
soma nc = new NetCon(&v(1), \$o1)
nc.threshold = 10
if (numarg() == 2) { \$o2 = nc } // for backward compatibility
return nc
}
proc synapses() {}
endtemplate pyramidalneuron

//codes that I added to the template obtained from cell builder
nNeurons = 100 //for 10X10 neuron matrix

objectvar Neurons[nNeurons]

for i = 0, nNeurons-1 {
Neurons[i] = new pyramidalneuron()
}

//calling procedure position for repositioning the neurons at different coordinates
a = 0
for x=0, 9 {
for y=0, 9 {
b = x*2000
c = y*2000
Neurons[a].position(b,0,c) //distance between neurons equals 2000 micrometers
a = a+1
}
}

for i = 0, nNeurons-1 {
Neurons[i].soma psection()
}
// this generates coordinates

objref s
s = new Shape()
s.show(0)
topology()
finitialize()
forall {
print secname()
for i=0,n3d()-1 print i, x3d(i), y3d(i), z3d(i), diam3d(i)
}

``````

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

Re: Extracting coordinates in stylized geometry

The problem is lack of clarity about what define_shape() does.
dinkc wrote:When I was using stylized geometry, I was able to get coordinates for every segments of the section I built. For example if the number of segments in axon is 10 , I got 12 sets of coordinates. Since stylized method didn't meet my needs, I switched to point3D method to define my own coordinates. However when I define 3D coordinates on my own (using pt3Dclear and pt3Dadd) , I only get coordinates for the 0-end and 1-end of each section
Before I answer your question, I should point out that it is best to use an odd value for nseg. See
Why should I use an odd value for nseg?
in the Frequently Asked Questions list
http://www.neuron.yale.edu/neuron/faq

Code: Select all

``i.e I only get two sets of coordinates``
Correct. That's exactly what should happen if your pt3d geometry specification code specifies the xyzdiam values at only the 0 and 1 ends of each section. The number of 3d points that you use to define the geometry of any section has nothing to do with that section's spatial discretization parameter nseg.

If you use the stylized method to specify a section's geometry, that section will have no 3d points at all, unless you execute
define_shape()
which, according to the Programmer's Reference documentation http://www.neuron.yale.edu/neuron/stati ... fine_shape, "fills in empty pt3d information with a naive algorithm based on current values for L and diam."

Pay attention to that word "empty."

For some reason or other, define_shape() does this not only for the 0 and 1 ends, but also for the internal nodes between the 0 and 1 ends.

------Comment------
A "node" is a point in space at which NEURON will calculate the value of membrane potential. Internal nodes are located at segment centers, and membrane potential at internal nodes is calculated by integrating the discretized cable equation which related local membrane potential to transmembrane current that exits the segment and axial current that enters the segment from adjacent compartments. Membrane potential at the 0 and 1 nodes is calculated algebraically as the weighted sum of the membrane potentials at adjacent internal nodes.
------End of Comment------

Values at internal nodes are calculated by linear interpolation from the xyzdiam values at the 0 and 1 ends.
I also noticed in the template obtained from cell builder that all sections had same diameter of 1 micrometers although I defined different diameters.
1. Examine the template's proc init() and note that topol() is called before geom().
2. Next examine proc topol() and note that it first assembles the branched structure of the model, and then calls basic_shape().
3. Now look at basic_shape() and note that it sets up the pt3d specifications of the sections, but notice that the coordinates and diameters have no relationship to the user-specified lengths and diameters. Instead, basic_shape()'s 3d specs govern only the appearance of the cartoon of the model cell that is shown in the CellBuilder.
4. Go back to proc init() and notice that proc geom() is called AFTER proc topol(). Examine the contents of proc geom() and you will see that this is where each section's length and diameter are assigned. Since these assignment statements are executed AFTER the pt3dadd statements, they override whatever the pt3dadd statements did. In other words, each section ends up with the correct, user-specified length and diameter.

dinkc
Posts: 25
Joined: Mon Nov 28, 2016 12:38 pm

Re: Extracting coordinates in stylized geometry

Dear Ted,

Thank you so much for your nice explanation. I understood that pt3D geometry specification would always return me two set of coordinates because I just used two 3d points to define the geometry of my section. But however, I could not still make out how to retrieve coordinates for all internal nodes (nodes in between 0 end and 1 end ) while working with pt3D geometry because this is what I was actually looking for.
I am not willing to work with stylized method any more because it didn't meet my needs and at the same time I also need to retrieve coordinates for all nodes and internodes defined by nseg. I will be using these coordinates in different program to calculate extracellular potential at each point along the section length. So, calculating coordinates at each nodes and internodes is crucial to me. Could you kindly elaborate a bit more about it? I couldn't really grasp it. I am sorry for pestering you with my never ending queries. I am quite new to Neuron world and I hope you will bear with me.

Thank you so much for your time and support.

Yours sincerely,
Dina KC

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

Re: Extracting coordinates in stylized geometry

I don't recall whether I have already suggested that you look at
Extracellular stimulation and recording
in the Hot tips area of the NEURON Forum. Download the zip file mentioned there, expand it, and examine interpxyz.hoc which calculates the coordinates of segment centers.

dinkc
Posts: 25
Joined: Mon Nov 28, 2016 12:38 pm

Re: Extracting coordinates in stylized geometry

Dear Ted,

Thank you so much for the information. I found the zip file. I will try to implement it and let you know how it goes.
Thanks a lot!

Yours sincerely,
Dina KC