Skip to content

Commit

Permalink
Enable targetting specific connections, add warnings for invalid conn…
Browse files Browse the repository at this point in the history
…ections
  • Loading branch information
ntolley committed Jul 18, 2022
1 parent fe01a58 commit f123980
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 13 deletions.
33 changes: 26 additions & 7 deletions hnn_core/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,10 +1072,10 @@ def add_connection(self, src_gids, target_gids, loc, receptor,
equivalent to passing a list of gids for the relevant cell type.
source - target connections are made in an all-to-all pattern.
loc : str
Location of synapse on target cell. Must be
'proximal', 'distal', or 'soma'. Note that inhibitory synapses
(receptor='gabaa' or 'gabab') of L2 pyramidal neurons are only
valid loc='soma'.
Location of synapse on target cell. Must be an element of
`Cell.sect_loc` such as 'proximal' or 'distal', which defines a
group of sections, or an existing section such as 'soma' or
'apical_tuft' (defined in `Cell.sections`)
receptor : str
Synaptic receptor of connection. Must be one of:
'ampa', 'nmda', 'gabaa', or 'gabab'.
Expand Down Expand Up @@ -1171,12 +1171,31 @@ def add_connection(self, src_gids, target_gids, loc, receptor,
_validate_type(loc, str, 'loc')
_validate_type(receptor, str, 'receptor')

valid_loc = ['proximal', 'distal', 'soma']
target_sect_loc = self.cell_types[target_type].sect_loc
target_sections = self.cell_types[target_type].sections
valid_loc = list(
target_sect_loc.keys()) + list(target_sections.keys())

_check_option('loc', loc, valid_loc)
conn['loc'] = loc

valid_receptor = ['ampa', 'nmda', 'gabaa', 'gabab']
_check_option('receptor', receptor, valid_receptor)
# `loc` specifies a group of sections, all must contain the synapse
# specified by `receptor`
if loc in target_sect_loc:
for sec_name in target_sect_loc[loc]:
valid_receptor = target_sections[sec_name].syns
_check_option('receptor', receptor, valid_receptor,
extra=f" (the '{receptor}' receptor is not "
f"defined for the '{sec_name}' of"
f"'{target_type}' cells)")
# `loc` specifies an individual section
else:
valid_receptor = target_sections[loc].syns
_check_option('receptor', receptor, valid_receptor,
extra=f"(the '{receptor}' receptor is not "
f"defined for the '{loc}' of"
f"'{target_type}' cells)")

conn['receptor'] = receptor

# Create and validate nc_dict
Expand Down
44 changes: 38 additions & 6 deletions hnn_core/tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,22 +309,45 @@ def test_network():
# instantiate drive events for NetworkBuilder
net._instantiate_drives(tstop=params['tstop'],
n_trials=params['N_trials'])
n_conn = len(network_builder.ncs['L2Basket_L2Pyr_gabaa'])
kwargs_default = dict(src_gids=[0, 1], target_gids=[35, 36],
loc='soma', receptor='gabaa',
n_conn_prox = len(network_builder.ncs['L2Pyr_L2Pyr_ampa'])
kwargs_default = dict(src_gids=[35, 36], target_gids=[35, 36],
loc='proximal', receptor='ampa',
weight=5e-4, delay=1.0, lamtha=1e9,
probability=1.0)
net.add_connection(**kwargs_default) # smoke test

# Test adding connection targeting single section
kwargs_trunk = kwargs_default.copy()
kwargs_trunk['loc'] = 'apical_trunk'
kwargs_trunk['receptor'] = 'nmda'
n_conn_trunk = len(network_builder.ncs['L2Pyr_L2Pyr_nmda'])
net.add_connection(**kwargs_trunk)

network_builder = NetworkBuilder(net)
assert len(network_builder.ncs['L2Basket_L2Pyr_gabaa']) == n_conn + 4
nc = network_builder.ncs['L2Basket_L2Pyr_gabaa'][-1]
# Check proximal targeted connection count increased by right number
# (2*2 connections between cells, 3 sections in proximal target)
assert len(network_builder.ncs['L2Pyr_L2Pyr_ampa']) == n_conn_prox + 4 * 3
nc = network_builder.ncs['L2Pyr_L2Pyr_ampa'][-1]
assert_allclose(nc.weight[0], kwargs_default['weight'])

# Check apical_trunk targeted connection count increased by right number
# (2*2 connections between cells, 1 section i.e. apical_turnk)
assert len(network_builder.ncs['L2Pyr_L2Pyr_nmda']) == n_conn_trunk + 4
nc = network_builder.ncs['L2Pyr_L2Pyr_nmda'][-1]
assert_allclose(nc.weight[0], kwargs_trunk['weight'])
# Check that exactly 4 apical_trunk connections appended
for idx in range(1, 5):
assert network_builder.ncs['L2Pyr_L2Pyr_nmda'][
-idx].postseg().__str__() == 'L2Pyr_apical_trunk(0.5)'
assert network_builder.ncs['L2Pyr_L2Pyr_nmda'][
-5].postseg().__str__() == 'L2Pyr_basal_3(0.5)'

kwargs_good = [
('src_gids', 0), ('src_gids', 'L2_pyramidal'), ('src_gids', range(2)),
('target_gids', 35), ('target_gids', range(2)),
('target_gids', 'L2_pyramidal'),
('target_gids', [[35, 36], [37, 38]]), ('probability', 0.5)]
('target_gids', [[35, 36], [37, 38]]), ('probability', 0.5),
('loc', 'apical_trunk')]
for arg, item in kwargs_good:
kwargs = kwargs_default.copy()
kwargs[arg] = item
Expand Down Expand Up @@ -380,6 +403,15 @@ def test_network():
kwargs['probability'] = -1.0
net.add_connection(**kwargs)

# Make sure warning raised if section targeted doesn't contain synapse
match = ('Invalid value for')
with pytest.raises(ValueError, match=match):
kwargs = kwargs_default.copy()
kwargs['target_gids'] = 'L5_pyramidal'
kwargs['loc'] = 'soma'
kwargs['receptor'] = 'ampa'
net.add_connection(**kwargs)

# Test net.pick_connection()
kwargs_default = dict(net=net, src_gids=None, target_gids=None,
loc=None, receptor=None)
Expand Down

0 comments on commit f123980

Please sign in to comment.