Skip to content

Commit

Permalink
[MRG]: refactor parconnect (#6)
Browse files Browse the repository at this point in the history
* MAINT: refactor parconnect

* FIX remove redundant self

* FIX A_weight

* MAINT: use postsyns instead of dendrites

* DOC synapse -> receptor
  • Loading branch information
jasmainak committed Feb 6, 2019
1 parent c3d8a7b commit c76a27b
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 207 deletions.
8 changes: 4 additions & 4 deletions mne_neuron/basket.py
Expand Up @@ -44,7 +44,7 @@ def _synapse_create(self):
self.soma_nmda = self.syn_nmda_create(self.soma(0.5))

def _connect(self, gid, gid_dict, pos_dict, p, type_src, name_src,
lamtha=3., synapse='ampa'):
lamtha=3., receptor='ampa'):
for gid_src, pos in zip(gid_dict[type_src],
pos_dict[type_src]):
if gid_src == gid:
Expand All @@ -60,7 +60,7 @@ def _connect(self, gid, gid_dict, pos_dict, p, type_src, name_src,

getattr(self, 'ncfrom_%s' % name_src).append(
self.parconnect_from_src(
gid_src, nc_dict, getattr(self, 'soma_%s' % synapse)))
gid_src, nc_dict, getattr(self, 'soma_%s' % receptor)))


class L2Basket(BasketSingle):
Expand All @@ -78,7 +78,7 @@ def __init__(self, gid=-1, pos=-1):
def parconnect(self, gid, gid_dict, pos_dict, p):
self._connect(gid, gid_dict, pos_dict, p, 'L2_pyramidal', 'L2Pyr')
self._connect(gid, gid_dict, pos_dict, p, 'L2_basket', 'L2Basket',
lamtha=20., synapse='gabaa')
lamtha=20., receptor='gabaa')

# this function might make more sense as a method of net?
# par: receive from external inputs
Expand Down Expand Up @@ -225,7 +225,7 @@ def __init__(self, gid=-1, pos=-1):
# there are no connections from the L2Basket cells. congrats!
def parconnect(self, gid, gid_dict, pos_dict, p):
self._connect(gid, gid_dict, pos_dict, p, 'L5_basket', 'L5Basket',
lamtha=20., synapse='gabaa')
lamtha=20., receptor='gabaa')
self._connect(gid, gid_dict, pos_dict, p, 'L5_pyramidal', 'L5Pyr')
self._connect(gid, gid_dict, pos_dict, p, 'L2_pyramidal', 'L2Pyr')

Expand Down
56 changes: 46 additions & 10 deletions mne_neuron/cell.py
Expand Up @@ -16,7 +16,16 @@


class Cell(object):
"""Create a cell class."""
"""Create a cell object.
Parameters
----------
gid : int
The cell ID
soma_props : dict
The properties of the soma. Must contain
keys 'L', 'diam', and 'pos'
"""

def __init__(self, gid, soma_props):
self.gid = gid
Expand Down Expand Up @@ -80,12 +89,8 @@ def getbbox(self):
return ((minx, maxx), (miny, maxy), (minz, maxz))

def translate3d(self, dx, dy, dz):
#s = self.soma
# 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)
for s in self.get_sections():
for i in range(s.n3d()):
# print(s,i,s.x3d(i)+dx,s.y3d(i)+dy,s.z3d(i)+dz,s.diam3d(i))
h.pt3dchange(i, s.x3d(i) + dx, s.y3d(i) + dy,
s.z3d(i) + dz, s.diam3d(i), sec=s)

Expand All @@ -104,7 +109,8 @@ def movetopos(self):

# 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
# 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
Expand Down Expand Up @@ -134,7 +140,8 @@ def dipole_insert(self, yscale):
loc = np.array([seg.x for seg in sect])
# these are the positions, including 0 but not L
pos = np.array([seg.x for seg in sect.allseg()])
# diff in yvals, scaled against the pos np.array. y_long as in longitudinal
# diff in yvals, scaled against the pos np.array. y_long as
# in longitudinal
y_scale = (yscale[sect.name()] * sect.L) * pos
# y_long = (h.y3d(1, sec=sect) - h.y3d(0, sec=sect)) * pos
# diff values calculate length between successive section points
Expand Down Expand Up @@ -205,6 +212,21 @@ def record_current_soma(self):
# General fn that creates any Exp2Syn synapse type
# requires dictionary of synapse properties
def syn_create(self, secloc, p):
"""Create an h.Exp2Syn synapse.
Parameters
----------
p : dict
Should contain keys
- 'e' (reverse potential)
- 'tau1' (rise time)
- 'tau2' (decay time)
Returns
-------
syn : instance of h.Exp2Syn
A two state kinetic scheme synapse.
"""
syn = h.Exp2Syn(secloc)
syn.e = p['e']
syn.tau1 = p['tau1']
Expand Down Expand Up @@ -258,8 +280,23 @@ def connect_to_target(self, target, threshold):

def parconnect_from_src(self, gid_presyn, nc_dict, postsyn):
"""Parallel receptor-centric connect FROM presyn TO this cell,
based on GID."""
# nc_dict keys are: {pos_src, A_weight, A_delay, lamtha}
based on GID.
Parameters
----------
gid_presyn : int
The cell ID of the presynaptic neuron
nc_dict : dict
Dictionary with keys: pos_src, A_weight, A_delay, lamtha
Defines the connection parameters
postsyn : str
The postsynaptic cell object.
Returns
-------
nc : instance of h.NetCon
A network connection object.
"""
nc = self.pc.gid_connect(gid_presyn, postsyn)
# calculate distance between cell positions with pardistance()
d = self.__pardistance(nc_dict['pos_src'])
Expand All @@ -276,7 +313,6 @@ def parconnect_from_src(self, gid_presyn, nc_dict, postsyn):
def __pardistance(self, pos_pre):
dx = self.pos[0] - pos_pre[0]
dy = self.pos[1] - pos_pre[1]
#dz = self.pos[2] - pos_pre[2]
return np.sqrt(dx**2 + dy**2)

# Define 3D shape of soma -- is needed for gui representation of cell
Expand Down

0 comments on commit c76a27b

Please sign in to comment.