Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MRG: Improve cells #200

Merged
merged 14 commits into from
Nov 9, 2020
6 changes: 3 additions & 3 deletions hnn_core/basket.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, gid, pos, cell_name='Basket'):
self.shape_soma()
self.synapses = dict()

def _biophysics(self):
def set_biophysics(self):
self.soma.insert('hh2')

def _get_soma_props(self, cell_name, pos):
Expand Down Expand Up @@ -71,7 +71,7 @@ def __init__(self, gid=-1, pos=-1):
self.celltype = 'L2_basket'

self._synapse_create()
self._biophysics()
self.set_biophysics()
self.sect_loc = dict(proximal=['soma'], distal=['soma'])


Expand All @@ -84,5 +84,5 @@ def __init__(self, gid=-1, pos=-1):
self.celltype = 'L5_basket'

self._synapse_create()
self._biophysics()
self.set_biophysics()
self.sect_loc = dict(proximal=['soma'], distal=[])
83 changes: 28 additions & 55 deletions hnn_core/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,73 +105,46 @@ def create_soma(self):
self.soma.Ra = soma_props['Ra']
self.soma.cm = soma_props['cm']

def get3dinfo(self):
"""Get 3d info."""
ls = self.get_sections()
lx, ly, lz, ldiam = [], [], [], []
for s in ls:
for i in range(s.n3d()):
lx.append(s.x3d(i))
ly.append(s.y3d(i))
lz.append(s.z3d(i))
ldiam.append(s.diam3d(i))
return lx, ly, lz, ldiam

def getbbox(self):
"""Get cell's bounding box."""
lx, ly, lz, ldiam = self.get3dinfo()
minx, miny, minz = 1e9, 1e9, 1e9
maxx, maxy, maxz = -1e9, -1e9, -1e9
for x, y, z in zip(lx, ly, lz):
minx = min(x, minx)
miny = min(y, miny)
minz = min(z, minz)
maxx = max(x, maxx)
maxy = max(y, maxy)
maxz = max(z, maxz)
return ((minx, maxx), (miny, maxy), (minz, maxz))

def translate3d(self, dx, dy, dz):
"""Translate 3d."""
for s in self.get_sections():
for i in range(s.n3d()):
h.pt3dchange(i, s.x3d(i) + dx, s.y3d(i) + dy,
s.z3d(i) + dz, s.diam3d(i), sec=s)

def translate_to(self, x, y, z):
"""Translate to position."""
def move_to_pos(self):
"""Move cell to position."""
x0 = self.soma.x3d(0)
y0 = self.soma.y3d(0)
z0 = self.soma.z3d(0)
dx = x - x0
dy = y - y0
dz = z - z0
# print('dx:',dx,'dy:',dy,'dz:',dz)
self.translate3d(dx, dy, dz)
dx = self.pos[0] * 100 - x0
dy = self.pos[2] - y0
dz = self.pos[1] * 100 - z0

def move_to_pos(self):
"""Move cell to position."""
self.translate_to(self.pos[0] * 100, self.pos[2], self.pos[1] * 100)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite get this ... why pos[2] for y and why not pos[2] * 100

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing. Why pos[2] instead of pos[1] for the y-coordinate?

Is the factor of 100 supposed to represent the actual distance between cells (i.e., scales the integer positions within the coordinate grid)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly don't know ... I raised an issue #202. Keeping it unchanged for now. Just reorganized the code.

for s in self.get_sections():
for i in range(s.n3d()):
h.pt3dchange(i, s.x3d(i) + dx, s.y3d(i) + dy,
s.z3d(i) + dz, s.diam3d(i), sec=s)

# two things need to happen here for h:
# 1. dipole needs to be inserted into each section
# 2. a list needs to be created with a Dipole (Point Process) in each
# section at position 1
# In Cell() and not Pyr() for future possibilities
def dipole_insert(self, yscale):
"""Insert dipole into each section of this cell."""
def insert_dipole(self, yscale):
"""Insert dipole into each section of this cell.

Parameters
----------
yscale : dict
Dictionary of length scales to calculate dipole without
3d shape.
"""
# dends must have already been created!!
# it's easier to use wholetree here, this includes soma
seclist = h.SectionList()
seclist.wholetree(sec=self.soma)
# create a python section list list_all
self.list_all = [sec for sec in seclist]
for sect in self.list_all:
list_all = [sec for sec in seclist]
for sect in list_all:
sect.insert('dipole')
# Dipole is defined in dipole_pp.mod
self.dipole_pp = [h.Dipole(1, sec=sect) for sect in self.list_all]
self.dipole_pp = [h.Dipole(1, sec=sect) for sect in list_all]
# setting pointers and ztan values
for sect, dpp in zip(self.list_all, self.dipole_pp):
for sect, dpp in zip(list_all, self.dipole_pp):
# assign internal resistance values to dipole point process (dpp)
dpp.ri = h.ri(1, sec=sect)
# sets pointers in dipole mod file to the correct locations
Expand All @@ -188,7 +161,7 @@ def dipole_insert(self, yscale):
pos = np.array([seg.x for seg in sect.allseg()])
# diff in yvals, scaled against the pos np.array. y_long as
# in longitudinal
y_scale = (yscale[sect.name()] * sect.L) * pos
y_scale = (yscale[sect.name().split('_', 1)[1]] * sect.L) * pos
# y_long = (h.y3d(1, sec=sect) - h.y3d(0, sec=sect)) * pos
# diff values calculate length between successive section points
y_diff = np.diff(y_scale)
Expand Down Expand Up @@ -244,14 +217,14 @@ def syn_create(self, secloc, e, tau1, tau2):

Parameters
----------
secloc : float (0. to 1.0)
The section location
secloc : instance of nrn.Segment
The section location. E.g., soma(0.5).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Describing nrn objects with floats and ints shows up in several docstrings. Is this just referencing the numerical argument that instantiates the object?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might be documented wrongly :-) fix is always welcome!

btw, soma(0.5) just means the middle of the soma ... I guess you know that already but putting it out there in case that was not clear.

e: float
Reverse potential
Reverse potential (in mV)
tau1: float
Rise time
Rise time (in ms)
tau2: float
Decay time
Decay time (in ms)

Returns
-------
Expand Down
Loading