Skip to content

Commit

Permalink
further fixes to support for reduced cell models
Browse files Browse the repository at this point in the history
  • Loading branch information
iraikov committed Mar 25, 2024
1 parent e1c63c9 commit 6657a4f
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 123 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: check-json
- id: end-of-file-fixer
- id: requirements-txt-fixer
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 24.3.0
hooks:
- id: black
additional_dependencies: ["click==8.0.4"]
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "miv-simulator"
version = "0.0.3"
version = "0.0.4"
description = "Mind-in-Vitro simulator"
readme = "README.md"
authors = []
Expand Down
63 changes: 44 additions & 19 deletions src/miv_simulator/cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ def __init__(
self.random.seed(self.gid)
self.spike_detector = None
self.spike_onset_delay = 0.0
self.is_reduced = True
if not isinstance(cell_config, BRKconfig):
raise RuntimeError(
"BRKneuron: argument cell_attrs must be of type BRKconfig"
Expand Down Expand Up @@ -422,6 +421,10 @@ def ais(self):
def hillock(self):
return self.nodes["hillock"]

@property
def is_reduced(self):
return True


class PRneuron:
"""
Expand Down Expand Up @@ -458,7 +461,6 @@ def __init__(
self.random.seed(self.gid)
self.spike_detector = None
self.spike_onset_delay = 0.0
self.is_reduced = True
if not isinstance(cell_config, PRconfig):
raise RuntimeError(
"PRneuron: argument cell_attrs must be of type PRconfig"
Expand Down Expand Up @@ -558,6 +560,10 @@ def ais(self):
def hillock(self):
return self.nodes["hillock"]

@property
def is_reduced(self):
return True


class SCneuron:
"""
Expand Down Expand Up @@ -611,7 +617,6 @@ def __init__(
self.random.seed(self.gid)
self.spike_detector = None
self.spike_onset_delay = 0.0
self.is_reduced = True

SC_nrn = h.SC_nrn()

Expand Down Expand Up @@ -678,6 +683,10 @@ def ais(self) -> List[Any]:
def hillock(self):
return self.nodes["hillock"]

@property
def is_reduced(self):
return True


class BiophysCell:
"""
Expand Down Expand Up @@ -951,20 +960,18 @@ def import_morphology_from_hoc(
sec_info_dict = {}
root_sec = None
for sec_type, sec_index_list in default_hoc_sec_lists.items():
hoc_sec_attr_name = sec_type
hoc_sec_attr_name = f"{sec_type}_list"
if not hasattr(hoc_cell, hoc_sec_attr_name):
hoc_sec_attr_name = f"{sec_type}_list"
hoc_sec_attr_name = sec_type
if hasattr(hoc_cell, hoc_sec_attr_name) and (
getattr(hoc_cell, hoc_sec_attr_name) is not None
):
sec_list = list(getattr(hoc_cell, hoc_sec_attr_name))
hoc_obj = getattr(hoc_cell, hoc_sec_attr_name)
if hasattr(hoc_cell, sec_index_list):
sec_indexes = list(getattr(hoc_cell, sec_index_list))
else:
raise AttributeError(
"import_morphology_from_hoc: %s is not an attribute of the hoc cell"
% sec_index_list
)
sec_indexes = list(range(len(sec_list)))
if sec_type == "soma":
root_sec = sec_list[0]
for sec, index in zip(sec_list, sec_indexes):
Expand Down Expand Up @@ -1779,9 +1786,9 @@ def init_circuit_context(
cell_weights_dict,
) in cell_weights_iter:
assert cell_weights_gid == gid
cell_weights_dicts[
weights_namespace
] = cell_weights_dict
cell_weights_dicts[weights_namespace] = (
cell_weights_dict
)

else:
raise RuntimeError(
Expand Down Expand Up @@ -1810,12 +1817,14 @@ def init_circuit_context(
syn_name,
zip_longest(
weights_syn_ids,
[
{"weight": Promise(expr_closure, [x])}
for x in weights_values
]
if expr_closure
else [{"weight": x} for x in weights_values],
(
[
{"weight": Promise(expr_closure, [x])}
for x in weights_values
]
if expr_closure
else [{"weight": x} for x in weights_values]
),
),
multiple=multiple_weights,
append=append_weights,
Expand Down Expand Up @@ -2086,11 +2095,16 @@ def make_biophys_cell(
)
_, tree_dict = next(tree_attr_iter)

hoc_cell = make_hoc_cell(
env, population_name, gid, neurotree_dict=tree_dict
)

cell = BiophysCell(
env=env,
gid=gid,
population_name=population_name,
hoc_cell=hoc_cell,
neurotree_dict=tree_dict,
env=env,
mech_file_path=mech_file_path,
mech_dict=mech_dict,
)
Expand Down Expand Up @@ -2502,3 +2516,14 @@ def record_cell(
recs.append(rec)

return recs


default_reduced_cell_constructors = {
"pr_nrn": make_PR_cell,
"brk_nrn": make_BRK_cell,
"sc_nrn": make_SC_cell,
}


def get_reduced_cell_constructor(template_name):
return default_reduced_cell_constructors.get(template_name.lower(), None)
20 changes: 4 additions & 16 deletions src/miv_simulator/clamps/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,11 @@ def init_biophys_cell(
else:
correct_for_spines_flag = False

reduced_cons = cells.get_reduced_cell_constructor(template_name)

## Load cell gid and its synaptic attributes and connection data
if template_name.lower() == "pr_nrn":
cell = cells.make_PR_cell(
env,
pop_name,
gid,
tree_dict=cell_dict.get("morph", None),
synapses_dict=cell_dict.get("synapse", None),
connection_graph=cell_dict.get("connectivity", None),
weight_dict=cell_dict.get("weight", None),
mech_dict=mech_dict,
load_synapses=True,
load_weights=load_weights,
load_edges=load_connections,
)
elif template_name.lower() == "sc_nrn":
cell = cells.make_SC_cell(
if reduced_cons is not None:
cell = reduced_cons(
env,
pop_name,
gid,
Expand Down
Loading

0 comments on commit 6657a4f

Please sign in to comment.