Skip to content

Commit

Permalink
instantiate cells in network_builder.py
Browse files Browse the repository at this point in the history
  • Loading branch information
rythorpe committed May 13, 2021
1 parent 82fb451 commit 51720e4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
10 changes: 2 additions & 8 deletions hnn_core/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from .drives import _get_target_populations, _add_drives_from_params
from .drives import _check_drive_parameter_values, _check_poisson_rates
from .cells_default import pyramidal, basket
from .cell import Cell
from .cell_response import CellResponse
from .params import _long_name, _short_name
from .viz import plot_cells, plot_cell_morphology
Expand Down Expand Up @@ -189,8 +188,7 @@ def __init__(self, params, add_drives_from_params=False,
self._update_gid_ranges()

self.cell_properties = dict()
self.cells = dict()
self._create_cells()
self._set_cell_properties()

# set n_cells, EXCLUDING Artificial ones
self.n_cells = sum(len(self.pos_dict[src]) for src in
Expand Down Expand Up @@ -231,7 +229,7 @@ def copy(self):
net_copy._reset_drives()
return net_copy

def _create_cells(self):
def _set_cell_properties(self):
'''Populate the network with cell objects'''

for cell_type in self.pos_dict.keys():
Expand All @@ -246,10 +244,6 @@ def _create_cells(self):
'synapses': p_syn,
'topology': topology,
'sect_loc': sect_loc}
for cell_idx, pos in enumerate(self.pos_dict[cell_type]):
gid = self.gid_dict[cell_type][cell_idx]
cell = Cell(name=_short_name(cell_type), pos=pos, gid=gid)
self.cells[cell_type].append(cell)

def add_evoked_drive(self, name, *, mu, sigma, numspikes,
sync_within_trial=False, location,
Expand Down
11 changes: 6 additions & 5 deletions hnn_core/network_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
if int(__version__[0]) >= 8:
h.nrnunit_use_legacy(1)

from .cell import _ArtificialCell
from .cell import Cell, _ArtificialCell
from .cells_default import pyramidal, basket
from .params import _long_name, _short_name
from copy import deepcopy
Expand Down Expand Up @@ -380,16 +380,16 @@ def _create_cells_and_drives(self, threshold, record_vsoma=False,
# have to loop over self._gid_list, since this is what we got
# on this rank (MPI)
for gid in self._gid_list:
src_type = self.net.gid_to_type(gid)
cell = self.net._gid_to_cell(gid)
src_type, src_pos, is_cell = self.net._get_src_type_and_pos(gid)

if cell is not None:
if is_cell:
cell = Cell(name=_short_name(src_type), pos=src_pos, gid=gid)
p_secs = self.net.cell_properties[src_type]['sections']
p_syn = self.net.cell_properties[src_type]['synapses']
topology = self.net.cell_properties[src_type]['topology']
sect_loc = self.net.cell_properties[src_type]['sect_loc']
# instantiate NEURON object
cell.build(p_secs, p_syn, topology, sect_loc=sect_loc)
cell.build(p_secs, p_syn, topology, sect_loc)
# insert dipole in pyramidal cells
if src_type in ('L2_pyramidal', 'L5_pyramidal'):
cell.insert_dipole(p_secs, 'apical_trunk')
Expand All @@ -403,6 +403,7 @@ def _create_cells_and_drives(self, threshold, record_vsoma=False,
# this call could belong in init of a _Cell (with threshold)?
nrn_netcon = cell.setup_source_netcon(threshold)
_PC.cell(cell.gid, nrn_netcon)
self.cells.append(cell)

# external inputs are special types of artificial-cells
# 'common': all cells impacted with identical TIMING of spike
Expand Down
2 changes: 1 addition & 1 deletion hnn_core/tests/test_cells_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ def test_cells_default():
assert len(times) == len(vsoma)

with pytest.raises(ValueError, match='Unknown basket cell type'):
l5p = basket(pos=(0, 0, 0), cell_name='blah')
p_secs, p_syn, topology, sect_loc = basket(cell_name='blah')

0 comments on commit 51720e4

Please sign in to comment.