Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_axon_direction(hobj):
for sec in hobj.somatic:
n3d = int(h.n3d()) # get number of n3d points in each section
soma_end = np.asarray([h.x3d(n3d - 1), h.y3d(n3d - 1), h.z3d(n3d - 1)])
mid_point = int(n3d / 2)
soma_mid = np.asarray([h.x3d(mid_point), h.y3d(mid_point), h.z3d(mid_point)])
for sec in hobj.all:
section_name = sec.name().split(".")[1][:4]
if section_name == 'axon':
n3d = int(h.n3d()) # get number of n3d points in each section
axon_p3d = np.zeros((n3d, 3)) # to hold locations of 3D morphology for the current section
for i in range(n3d):
axon_p3d[i, 0] = h.x3d(i)
axon_p3d[i, 1] = h.y3d(i) # shift coordinates such to place soma at the origin.
axon_p3d[i, 2] = h.z3d(i)
# Add soma coordinates to the list
p3d = np.concatenate(([soma_mid], axon_p3d), axis=0)
def retrieve_coordinate(self, sec):
"""Retrieve the coordinates of the section"""
coords = {}
sec.push()
coords['x0'] = h.x3d((h.n3d()- h.n3d()))
coords['x1'] = h.x3d((h.n3d()- 1))
coords['y0'] = h.y3d((h.n3d()- h.n3d()))
coords['y1'] = h.y3d((h.n3d()- 1))
coords['z0'] = h.z3d((h.n3d()- h.n3d()))
coords['z1'] = h.z3d((h.n3d()- 1))
h.pop_section()
return coords
def retrieve_coordinate(self, sec):
"""Retrieve the coordinates of the section"""
coords = {}
sec.push()
coords['x0'] = h.x3d((h.n3d()- h.n3d()))
coords['x1'] = h.x3d((h.n3d()- 1))
coords['y0'] = h.y3d((h.n3d()- h.n3d()))
coords['y1'] = h.y3d((h.n3d()- 1))
coords['z0'] = h.z3d((h.n3d()- h.n3d()))
coords['z1'] = h.z3d((h.n3d()- 1))
h.pop_section()
return coords
def retrieve_coordinate(self, sec):
"""Retrieve the coordinates of the section"""
coords = {}
sec.push()
coords['x0'] = h.x3d((h.n3d()- h.n3d()))
coords['x1'] = h.x3d((h.n3d()- 1))
coords['y0'] = h.y3d((h.n3d()- h.n3d()))
coords['y1'] = h.y3d((h.n3d()- 1))
coords['z0'] = h.z3d((h.n3d()- h.n3d()))
coords['z1'] = h.z3d((h.n3d()- 1))
h.pop_section()
return coords
def set_position(self, x, y, z):
"""
Set the base location in 3D and move all other
parts of the cell relative to that location.
"""
for sec in self.all:
for i in range(int(h.n3d())):
h.pt3dchange(i,
x - self.x + h.x3d(i),
y - self.y + h.y3d(i),
z - self.z + h.z3d(i),
h.diam3d(i))
self.x, self.y, self.z = x, y, z
def get_coords_and_radii(self):
nrn_section = self.nrn_section
# Count 3D points
point_count = int(h.n3d(sec=nrn_section))
# Let NEURON create them if missing
if point_count == 0:
h.define_shape(sec=self.nrn_section)
point_count = int(h.n3d(sec=self.nrn_section))
# Collect the coordinates
coords = [None] * point_count * 3 # 3 for xy and z
radii = [None] * point_count
for c in range(point_count):
ci = c * 3
coords[ci] = h.x3d(c, sec=nrn_section)
coords[ci + 1] = h.y3d(c, sec=nrn_section)
coords[ci + 2] = h.z3d(c, sec=nrn_section)
def retrieve_coordinate(self, sec):
"""Retrieve the coordinates of the section"""
coords = {}
sec.push()
coords['x0'] = h.x3d((h.n3d()- h.n3d()))
coords['x1'] = h.x3d((h.n3d()- 1))
coords['y0'] = h.y3d((h.n3d()- h.n3d()))
coords['y1'] = h.y3d((h.n3d()- 1))
coords['z0'] = h.z3d((h.n3d()- h.n3d()))
coords['z1'] = h.z3d((h.n3d()- 1))
h.pop_section()
return coords
# if len(secs) == 1: secName = 'soma' # if just one section rename to 'soma' -- REMOVED, doesn't always apply
secDic[secName] = {'geom': {}, 'topol': {}, 'mechs': {}} # create dictionary to store sec info
# store geometry properties
standardGeomParams = ['L', 'nseg', 'diam', 'Ra', 'cm']
secDir = dir(sec)
for geomParam in standardGeomParams:
#if geomParam in secDir:
try:
secDic[secName]['geom'][geomParam] = sec.__getattribute__(geomParam)
except:
pass
# store 3d geometry
sec.push() # access current section so ismembrane() works
numPoints = int(h.n3d())
if numPoints:
points = []
for ipoint in range(numPoints):
x = h.x3d(ipoint)
y = h.y3d(ipoint)
z = h.z3d(ipoint)
diam = h.diam3d(ipoint)
points.append((x, y, z, diam))
secDic[secName]['geom']['pt3d'] = points
# store mechanisms
#varList = mechVarList() # list of properties for all density mechanisms and point processes
ignoreMechs = ['dist'] # dist only used during cell creation
ignoreVars = [] #
mechDic = {}
ionDic = {}
'mechs': {}, 'neuronSec': sec}
# store geometry properties
standardGeomParams = ['L', 'nseg', 'diam', 'Ra', 'cm']
secDir = dir(sec)
for geomParam in standardGeomParams:
# if geomParam in secDir:
try:
secDic[secName]['geom'][
geomParam] = sec.__getattribute__(geomParam)
except:
pass
# store 3d geometry
sec.push() # access current section so ismembrane() works
numPoints = int(h.n3d())
if numPoints:
points = []
for ipoint in range(numPoints):
x = h.x3d(ipoint)
y = h.y3d(ipoint)
z = h.z3d(ipoint)
diam = h.diam3d(ipoint)
points.append((x, y, z, diam))
secDic[secName]['geom']['pt3d'] = points
# store mechanisms
# list of properties for all density mechanisms and point processes
varList = mechVarList()
ignoreMechs = ['dist'] # dist only used during cell creation
ignoreVars = [] #
mechDic = {}