Skip to content

Commit

Permalink
fixed to synapse strategy for reduced cells
Browse files Browse the repository at this point in the history
  • Loading branch information
iraikov committed Aug 6, 2024
1 parent 859f032 commit 5ceabdc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/miv_simulator/cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,13 @@ def ais(self) -> List[Union[Any, SectionNode]]:
def hillock(self):
return self.nodes["hillock"]

@property
def is_reduced(self):
if self.hoc_cell is not None:
return getattr(self.hoc_cell, "is_reduced", False)
else:
return False


def get_distance_to_node(
cell: BiophysCell,
Expand Down
6 changes: 5 additions & 1 deletion src/miv_simulator/clamps/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ def init_biophys_cell(
is_reduced = False
if hasattr(cell, "is_reduced"):
is_reduced = cell.is_reduced
if callable(is_reduced):
is_reduced = is_reduced()
if isinstance(is_reduced, float):
is_reduced = is_reduced > 0.0

if not is_reduced:
cells.report_topology(env, cell)

Expand Down Expand Up @@ -373,7 +378,6 @@ def measure_passive(
"tau0": np.asarray([tau0], dtype=np.float32),
}

logger.info(f"results = {results}")
env.synapse_attributes.del_syn_id_attr_dict(gid)
if gid in env.biophys_cells[pop_name]:
del env.biophys_cells[pop_name][gid]
Expand Down
26 changes: 20 additions & 6 deletions src/miv_simulator/synapses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,9 @@ def insert_hoc_cell_syns(
py_sections = [sec for sec in cell.sections]
is_reduced = False
if hasattr(cell, "is_reduced"):
is_reduced = cell.is_reduced()
is_reduced = cell.is_reduced
if callable(is_reduced):
is_reduced = is_reduced()
if isinstance(is_reduced, float):
is_reduced = is_reduced > 0.0

Expand All @@ -1677,9 +1679,16 @@ def insert_hoc_cell_syns(
for swc_type_name in env.SWC_Types:
for layer_name in env.layers:
swc_layer_key = f"{swc_type_name}_{layer_name}_list"
swc_layer_index_key = f"{swc_type_name}_{layer_name}_index"
sec_list = getattr(cell, swc_layer_key, None)
sec_index = getattr(cell, swc_layer_index_key, None)
if sec_list is not None:
reduced_section_dict[swc_layer_key] = list(sec_list)
reduced_section_dict[swc_layer_key] = list(
zip(
np.asarray(sec_index, dtype=np.uint16),
list(sec_list),
)
)
if len(reduced_section_dict) == 0:
if hasattr(cell, "soma"):
cell_soma = cell.soma
Expand Down Expand Up @@ -1712,19 +1721,20 @@ def insert_hoc_cell_syns(
syn_layer_name = layer_name_dict[syn_layer]

if is_reduced:
sec_index = 0
sec_list_key = f"{swc_type_name}_{syn_layer_name}_list"
if sec_list_key != current_sec_list_key:
current_sec_list_key = sec_list_key
current_sec_list = reduced_section_dict.get(sec_list_key, None)
sec_pos = 0.0
sec_dx = 0.0
if current_sec_list is not None:
if sec_pos >= 1:
sec = current_sec_list.pop(0)
current_sec_list.append(sec)
if sec_pos >= 1.0:
sec_index, sec = current_sec_list.pop(0)
current_sec_list.append((sec_index, sec))
sec_pos = 0.0
sec_dx = 0.0
sec = current_sec_list[0]
sec_index, sec = current_sec_list[0]
sec_dx = syn_loc - sec_dx
sec_pos += sec_dx
elif (swc_type == swc_type_soma) and (cell_soma is not None):
Expand Down Expand Up @@ -2592,6 +2602,10 @@ def update_syn_mech_param_by_sec_type(
is_reduced = False
if hasattr(cell, "is_reduced"):
is_reduced = cell.is_reduced
if callable(is_reduced):
is_reduced = is_reduced()
if isinstance(is_reduced, float):
is_reduced = is_reduced > 0.0

if is_reduced:
synapse_filters["swc_types"] = [env.SWC_Types[sec_type]]
Expand Down

0 comments on commit 5ceabdc

Please sign in to comment.