Help saving section currents

Anything that doesn't fit elsewhere.
Post Reply
catubc
Posts: 21
Joined: Mon Apr 07, 2014 6:46 pm

Help saving section currents

Post by catubc » Fri Jun 06, 2014 2:01 am

Hi everyone. I'm a new user of NEURON and have gotten pretty far just hacking other people's code. But I'm stuck at trying to save individual segment currents to a file. I've gotten as far as shown below. I can generate current output but all the currents in a segment come out to be the same.

So this code:

Code: Select all

	j = 0

	forall {
		for i=1, n3d()-1 {  //COSTAS: Need to start from ZERO; Not sure... i_membrane doesn't start at 0
                 j = j + 1            // global segment index
                
                 //Use indexes which chop up the segment into appropriate fractions; e.g. 1/8, 3/8, 5/8, 7/8            
                 i_segment.x[j] = i_membrane(((i-1)*2+1)/(2*(n3d()-1)))*area(((i-1)*2+1)/(2*(n3d()-1)))
		 fprint("%f\n", i_segment.x[j]) //current segment saved
		}
    }
	wopen()
Gives this output which is just the same currents for each segment in section:

Code: Select all

...
0.018351
0.018351
0.018351
0.018351
0.018351
0.018351
0.018351
0.018351
0.018351
0.018351
0.018351
0.018351
0.018351
0.018351
0.018351
0.018351
0.018351
0.018351
0.018351
0.018351
0.001033
0.001033
0.001033
0.001033
0.000085
0.000085
0.000085
0.000085
0.000085
0.000005
0.000005
0.000005
0.000005
...
I'm sure there's a simple correction, but I can't figure it out. I'm not even sure if "i_membrane" and "area" are intrinsic variables or the person whose code I'm using has generated these values. Help please!

Hoc syntax is driving me bananas!

Thanks in advance for any help.

Cat

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

Re: Help saving section currents

Post by ted » Fri Jun 06, 2014 9:32 am

The spatial discretization of a section (number of compartments used to represent it) is controlled by the section parameter nseg. nseg has nothing to do with n3d(). n3d() is merely the number of pt3dadd statements that are used to specify section geometry in terms of anatomical (x,y,z) location and diameter at that location. Detailed morphologies obtained from real neurons invariably have more (usually far more) pt3dadd statements than the number of compartments that are necessary for reasonable spatial accuracy in a simulation.

Consequently, this code cannot do anything useful

Code: Select all

		for i=1, n3d()-1 {
 . . .
                 i_segment.x[j] = i_membrane(((i-1)*2+1)/(2*(n3d()-1)))*area(((i-1)*2+1)/(2*(n3d()-1)))
The arguments to i_membrane() and area() are supposed to be range values, i.e. relative distance along the length of a section from its 0 end to its 1 end. There is no necessary relationship between
((i-1)*2+1)/(2*(n3d()-1))
and the relative distance of the ith anatomical (x,y,z) point from the 0 end of a section.

catubc
Posts: 21
Joined: Mon Apr 07, 2014 6:46 pm

Re: Help saving section currents

Post by catubc » Fri Jun 06, 2014 12:37 pm

Ok, I see... I was not looking at the right variables then. I guess I was just saving the 1st?! segment's currents?

So how do I loop over the number of nsegs in the forall{} loop? This seems to be so trivial... but I'm a bit lost as I've just started out.

shailesh
Posts: 104
Joined: Thu Mar 10, 2011 12:11 am

Re: Help saving section currents

Post by shailesh » Fri Jun 06, 2014 2:54 pm

You could get it done using a variant of NEURON's 'for' loop. Check out the third variant mentioned in the documentation: http://www.neuron.yale.edu/neuron/stati ... ml#index-8:
for (var) stmt

Loops over all segments of the currently accessed section. var begins at 0 and ends at 1. In between var is set to the center position of each segment. Ie. stmt is executed nseg+2 times.
For example, if you have a section with nseg = 5, you would effectively have 5 internal nodes (at 0.1, 0.3, 0.5, 0.7, 0.9) and 2 terminal nodes (at 0, 1). To access these, you could write:

Code: Select all

oc>for (x) { print x, v(x) }
This would print the node location and the membrane potential at that node. For example:
0 -33.169083
0.1 -33.169083
0.3 -33.169011
0.5 -33.168867
0.7 -33.169011
0.9 -33.169083
1 -33.169083
You could modify it to print your segment current or other parameters.

If you are just concerned about the internal nodes, just add an if clause:

Code: Select all

for (x) { if (x>0 && x<1) print x, v(x) }

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

Re: Help saving section currents

Post by ted » Fri Jun 06, 2014 4:23 pm

for (x,0) ...
iterates over the internal nodes (segment centers) of the currently accessed section without requiring the user to test for x==0 or 1.

The significance of internal nodes vs. nodes at 0 and 1 is that only internal nodes are associated with membrane area, therefore only internal nodes contribute to membrane current.

"Yes, but I have a model with extracellular, and I see that i_membrane(0) and i_membrane(1) are both reported as nonzero during a run."

That's because i_membrane(x) reports the membrane current density that is associated with the internal node that is closest to x. If your code does
itotal = 0
for (x) itotal += i_membrane(x)*area(x)
you'll be saved from your folly by the fact that area(0) = area(1) = 0
But you'll be skating on thin ice, because the next time you do something that involves iterating over segments (e.g. setting channel densities according to some function of location) your
for (x) gbar_whatever(x) = f(x)
code will set gbar_whatever at the last internal node to an incorrect value. Try it for yourself and see
e.g.

Code: Select all

create dend
access dend
dend.nseg = 3
insert pas
for (x) g_pas(x) = 1*x // what do you think this will do?
for (x) print x, g_pas(x) // what did it actually do, and why?
"Oh, but I would never let that happen because I always check my work."

Sure. Somehow a lot of smart people have made exactly that mistake, or one very much like it.

catubc
Posts: 21
Joined: Mon Apr 07, 2014 6:46 pm

Re: Help saving section currents

Post by catubc » Sat Jun 07, 2014 3:36 pm

Thanks Ted and shailesh, much appreciate your advice. I am a summer intern at the Allen Institute and trying to build some models to be used for spikesorting.

I actually figured out that what I was looking at wasn't wrong, it's just way too much. I was basically saving all the currents for every single portion of neuron between every single pair of n3d() points. But many neighbouring portions of the neuron will have the same voltages/currents because they are spanned by a single NEURON generated segment. That being said, I'm generating some really cool videos using FORTRAN.

https://www.dropbox.com/s/75n8kvc0sy42u3q/output.avi

I now understand that what I was doing is overkill and will eventually make the transition to just deal with NEURON computed segments which will cut some parts of my processing time by 50%-80%.

catubc

catubc
Posts: 21
Joined: Mon Apr 07, 2014 6:46 pm

Re: Help saving section currents

Post by catubc » Wed Jun 11, 2014 7:16 pm

For anyone reading this post and trying to compute LSA's from 3d morphology, the full answer was provided by Ted here:

http://www.neuron.yale.edu/phpbb/viewto ... tes#p11821

Post Reply