Page 1 of 1

Changing diameters of reconstructed neurons

Posted: Mon Jul 30, 2018 3:47 am
by Tuoma
I have a reconstructed morphology (loaded from an .asc file), where I would like to change the diameters of the sections by some factor. Is there a neat way of doing it? For a starter, I tried

forall {
for (j = 0; j < nseg+1; j+=1 ) {
diam(j/nseg) = diam(j/nseg)*1.0
}
}

but it changed the diameter at certain points. It would do that even if I replaced nseg by a large number.

Re: Changing diameters of reconstructed neurons

Posted: Mon Jul 30, 2018 6:20 am
by ramcdougal
Use diam3d instead of diam, and forall sections adjust indices from 0 to n3d-1, inclusive.

EDIT: The idea is right but this code is wrong. diam3d is read only and diameters most he changed with pt3dchange. See my next post.

Code: Select all

forall { 
  for (j = 0; j < n3d(); j+=1) { 
    diam3d(j) = diam3d(j)*1.0 
  } 
} 
There is a discussion at the top of the linked help page that explains all this, but in brief the functions ending with 3d are for imported morphologies which can have arbitrarily many different diameters and 3d points while the way you tried is for stylized morphologies where each segment has a uniform diameter.

Re: Changing diameters of reconstructed neurons

Posted: Mon Jul 30, 2018 9:34 am
by ted
Two suggested refinements.
1. Wrap the code in a procedure.
2. Provide a way to restore the original diameters.
Example:

Code: Select all

// revised 20180731 by NTC
// if $1>0 scale diam3ds by $1
// else restore original diams
objref diam3dvec
diam3dvec = new Vector() // to hold original diameters
proc scalediam3d() { local i, j, fac
  // if original diams haven't been saved, save them
  if (diam3dvec.length()==0) {
    forall for i=0,n3d()-1 diam3dvec.append(diam3d(i))
  }
  j = 0 // track where we are in diam3dvec
  if ($1>0) {
    fac = $1 // scale diameters
  } else {
    fac = 1 // restore original diameters
  }
  forall for i=0,n3d()-1 {
      // this won't work: diam3d(i) = fac * diam3dvec.x[j] (see note by ramcdougal below)
      // here's how to change diam3d:
      pt3dchange(i, fac * diam3dvec.x[j])
      j+=1
    }
  }
}
With scalediam3d() you can do things like this

Code: Select all

// run simulations with diameters 90%, 100%, and 110%
// of experimentally observed values 
for i = -1,1 {
  scale = 1+0.1*i
  scalediam3d(scale)
  run()
  postprocess() // analyze results of simulation
}

Re: Changing diameters of reconstructed neurons

Posted: Tue Jul 31, 2018 3:22 am
by Tuoma
I'm getting a syntax error with NEURON 7.5 whenever I try to assign something to diam3d(j), e.g.
forall {
for (j = 0; j < n3d(); j+=1) {
diam3d(j)=1.0
}
}

Re: Changing diameters of reconstructed neurons

Posted: Tue Jul 31, 2018 4:57 am
by ramcdougal
My mistake, sorry. I made that post on my phone without checking it.

You're right. diam3d is ready only. Use pt3dchange to set the diameter: the

Code: Select all

forall { 
  for (j = 0; j < n3d(); j+=1) { 
    pt3dchange(j, diam3d(j)*1.0)
  } 
} 

Re: Changing diameters of reconstructed neurons

Posted: Tue Jul 31, 2018 10:47 am
by ted
ramcdougal wrote:diam3d is ready only. Use pt3dchange to set the diameter
So in proc scalediam3d(), this statement
diam3d(i) = fac * diam3dvec.x[j]
should be replaced by
pt3dchange(i, fac * diam3dvec.x[j])
For the convenience of future readers of this thread, I have now made that change to my post from 20180730.