Printing the final values

The basics of how to develop, test, and use models.
Post Reply
afc
Posts: 23
Joined: Tue Jul 08, 2014 1:31 pm

Printing the final values

Post by afc »

Hello,

I am pretty new to NEURON, but I am using the Impedance class tools to analyse the electrotonic structure of some neurons and I am using the following chunk of code to do that:

Code: Select all

// prepare to use Impedance class

// always a good idea to finitialize before computing impedance
v_init=-65
finitialize(v_init)

// demonstrate use of impedance class

objref zz
zz = new Impedance()

FREQ = 0 // Hz
WHERE = 0.5 // location in the soma that is the reference point

soma distance(0, WHERE)  // sets origin for distance calculations

proc calcZ() {
  soma zz.loc(WHERE)  // sets origin for impedance calculations
  zz.compute(FREQ, 1) // takes the impedance contributions of 
                      // gating state differential equations into account
                      // but requires mechanisms to be compatible with CVODE

  print "distance(x) ratio(x)"
  forall {
    print secname()
    for (x) print x, x3d(x), y3d(x), z3d(x), log(1/(zz.ratio(x)))
  }
}

calcZ()
and the output on the terminal will be something like this:

Code: Select all

dend[38]
0 -15.63 3.8699999 5.23 0 
0.16666667 -15.63 3.8699999 5.23 0.64765023 
0.5 -15.63 3.8699999 5.23 1.3266357 
0.83333333 -15.63 3.8699999 5.23 1.7573273 
1 -16.469999 3.8699999 5.23 1.9388532 
but unfortunately, for what I want to do next, I would like to only print the last line, i.e. when x=1.

Is there any way to tweak the previous code to have it print only the "x=1" line?

Thank you all!
afc
Posts: 23
Joined: Tue Jul 08, 2014 1:31 pm

Re: Printing the final values

Post by afc »

I think I figured it out, I just had to add "if (x==1) " after the for (x) statement:

Code: Select all

// prepare to use Impedance class

// always a good idea to finitialize before computing impedance
v_init=-65
finitialize(v_init)

// demonstrate use of impedance class

objref zz
zz = new Impedance()

FREQ = 0 // Hz
WHERE = 0.5 // location in the soma that is the reference point

soma distance(0, WHERE)  // sets origin for distance calculations

proc calcZ() {
  soma zz.loc(WHERE)  // sets origin for impedance calculations
  zz.compute(FREQ, 1) // takes the impedance contributions of 
                      // gating state differential equations into account
                      // but requires mechanisms to be compatible with CVODE

  print "distance(x) ratio(x)"
  forall {
    print secname()
    for (x) if (x==1) print x3d(x), y3d(x), z3d(x), log(1/(zz.ratio(x)))
  }
}

calcZ()
Nevertheless, let me now if this will not work in some situations or if there is a better way to achieve what I wanted.
Thank you all!
ted
Site Admin
Posts: 6300
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Printing the final values

Post by ted »

First, consider this excerpt from your first post in this thread

Code: Select all

proc calcZ() {
  . . .
  print "distance(x) ratio(x)"
  forall {
    print secname()
    for (x) print x, x3d(x), y3d(x), z3d(x), log(1/(zz.ratio(x)))
  }
}
which produces this output:

Code: Select all

dend[38]
0 -15.63 3.8699999 5.23 0 
0.16666667 -15.63 3.8699999 5.23 0.64765023 
0.5 -15.63 3.8699999 5.23 1.3266357 
0.83333333 -15.63 3.8699999 5.23 1.7573273 
1 -16.469999 3.8699999 5.23 1.9388532 
It prints a header
distance(x) ratio(x)
that has nothing to do with the numerical values that follow. The first numerical value on each line will be the normalized location of a node in a section, and will have a value that lies in the range 0..1. This is by no means "distance(x)"; the distance() function returns path distance of a specified node from a reference point in microns. Also, none of the other numerical values on the line are equal to Impedance.ratio(x)--not even close. So the header is misleading. Best to change the print statement to something like
print "x log(1/(zz.ratio(x)))"

Next look closely at the actual numerical values that are printed. Wonder why the 2nd-4th values are identical from line to line? It's because the code abuses x3d(), y3d(), and z3d(). Please read the Programmer's Reference entries on these functions, and the related material on pt3d specification of geometry, and then change the print statement to
for (x) print x, log(1/(zz.ratio(x)))

Now for the code in your second post.

Code: Select all

I would like to only print the last line, i.e. when x=1
Then there's no need to iterate over all nodes that belong to each section. Instead of

Code: Select all

  forall {
    print secname()
    for (x) if (x==1) print x3d(x), y3d(x), z3d(x), log(1/(zz.ratio(x)))
  }
just do this:
forall print secname(), log(1/(zz.ratio(1)))
Of course you'll want to change the header to something that is more appropriate.
Post Reply