Skip to content

Commit

Permalink
Fixed bend morphology load for simulations
Browse files Browse the repository at this point in the history
  • Loading branch information
Hjorthmedh committed Oct 25, 2023
1 parent 49bebb8 commit e2cd8eb
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 38 deletions.
4 changes: 1 addition & 3 deletions snudda/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ def snudda_cli():
place_parser = sub_parsers.add_parser("place")
place_parser.add_argument("path", help="Location of network")
place_parser.add_argument("-randomseed", "--randomseed", "--seed", default=None, help="Random seed", type=int)
place_parser.add_argument("--raytraceBorders", help="Ray traces for more precise mesh edge detection",
action="store_true", dest="raytrace_borders", default=False)
place_parser.add_argument("--honorStayInside", dest="stay_inside", default=False)
place_parser.add_argument("--honorStayInside", "--stayInside", dest="stay_inside", default=False, action="store_true")
place_parser.add_argument("--profile", help="Run python cProfile", action="store_true")
place_parser.add_argument("--verbose", action="store_true")
place_parser.add_argument("--h5legacy", help="Use legacy hdf5 support", action="store_true")
Expand Down
5 changes: 1 addition & 4 deletions snudda/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def place_neurons_wrapper(self, args):
args : command line arguments from argparse
Example:
snudda place [--raytraceBorders] [--profile] [--verbose] [--h5legacy] [-parallel] path
snudda place [--profile] [--verbose] [--h5legacy] [-parallel] path
"""

Expand All @@ -176,7 +176,6 @@ def place_neurons_wrapper(self, args):
self.place_neurons(random_seed=args.randomseed,
parallel=args.parallel,
ipython_profile=args.ipython_profile,
raytrace_borders=args.raytrace_borders,
h5libver=h5libver,
verbose=args.verbose,
honor_stay_inside=args.stay_inside)
Expand All @@ -185,7 +184,6 @@ def place_neurons(self,
random_seed=None,
parallel=False,
ipython_profile=None,
raytrace_borders=False,
h5libver="latest",
verbose=False,
honor_stay_inside=False):
Expand All @@ -208,7 +206,6 @@ def place_neurons(self,
verbose=verbose,
d_view=self.d_view,
h5libver=h5libver,
raytrace_borders=raytrace_borders,
random_seed=random_seed,
morphologies_stay_inside=honor_stay_inside)

Expand Down
3 changes: 2 additions & 1 deletion snudda/detect/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2301,6 +2301,7 @@ def load_neuron(self, neuron_info, use_cache=True):
"""

neuron_id = neuron_info["neuronID"]

if use_cache and neuron_id in self.neuron_cache:
return self.neuron_cache[neuron_id]

Expand All @@ -2310,7 +2311,7 @@ def load_neuron(self, neuron_info, use_cache=True):
else:
morphology_path = None # Get morpholog automatically from morphology_key

print(f"morphology_path = {morphology_path}")
# print(f"morphology_path = {morphology_path}")

# Clone prototype neuron (it is centred, and not rotated)
neuron = self.prototype_neurons[neuron_info["name"]].clone(parameter_key=neuron_info["parameterKey"],
Expand Down
60 changes: 33 additions & 27 deletions snudda/neurons/neuron_model_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,33 +59,39 @@ def __init__(self,
self.script_dir = os.path.dirname(__file__)
self.config_dir = os.path.join(self.script_dir, 'config')

morph_file = None
if parameter_key is not None and morphology_key is not None and param_file is not None:
meta_file = os.path.join(os.path.dirname(param_file), "meta.json")
if os.path.isfile(meta_file):
with open(meta_file, "r") as f:
meta_data = json.load(f, object_pairs_hook=OrderedDict)
morph_file = os.path.join(morph_path, meta_data[parameter_key][morphology_key]["morphology"])

if not morph_file:
# We now allow multiple variations of morphologies for a given neuron name, so here NeuronPrototype
# is used to acquire the actual morphology file we will use for this particular neuron
# based on parameter_id and morphology_id.
neuron_prototype = NeuronPrototype(neuron_name=cell_name,
neuron_path=None,
morphology_path=morph_path,
parameter_path=param_file,
mechanism_path=mech_file,
modulation_path=modulation_file)

morph_file, _ = neuron_prototype.get_morphology(parameter_id=parameter_id,
morphology_id=morphology_id,
parameter_key=parameter_key,
morphology_key=morphology_key)

assert morph_file, (f"Neuron {cell_name} with morph_path = {morph_path} ({morphology_id}, "
f"parameter_path = {param_file} ({parameter_id}) "
f"has morph_file = {morph_file} (Should not be None)")
if os.path.isfile(morph_path):
# If morph_path is a swc file, use it directly
morph_file = morph_path
else:
# Figure out what file in the morphology path we should use

morph_file = None
if parameter_key is not None and morphology_key is not None and param_file is not None:
meta_file = os.path.join(os.path.dirname(param_file), "meta.json")
if os.path.isfile(meta_file):
with open(meta_file, "r") as f:
meta_data = json.load(f, object_pairs_hook=OrderedDict)
morph_file = os.path.join(morph_path, meta_data[parameter_key][morphology_key]["morphology"])

if not morph_file:
# We now allow multiple variations of morphologies for a given neuron name, so here NeuronPrototype
# is used to acquire the actual morphology file we will use for this particular neuron
# based on parameter_id and morphology_id.
neuron_prototype = NeuronPrototype(neuron_name=cell_name,
neuron_path=None,
morphology_path=morph_path,
parameter_path=param_file,
mechanism_path=mech_file,
modulation_path=modulation_file)

morph_file, _ = neuron_prototype.get_morphology(parameter_id=parameter_id,
morphology_id=morphology_id,
parameter_key=parameter_key,
morphology_key=morphology_key)

assert morph_file, (f"Neuron {cell_name} with morph_path = {morph_path} ({morphology_id}, "
f"parameter_path = {param_file} ({parameter_id}) "
f"has morph_file = {morph_file} (Should not be None)")

self.morph_file = morph_file

Expand Down
4 changes: 3 additions & 1 deletion snudda/simulate/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,9 @@ def setup_neurons(self):

config = self.config["Neurons"][name]

morph = snudda_parse_path(config["morphology"], self.snudda_data)
# We need to get morphology from network_info, since it can now be redefined for bent morphologies
morph = snudda_parse_path(self.network_info["neurons"][ID]["morphology"], self.snudda_data)
# morph = snudda_parse_path(config["morphology"], self.snudda_data)
param = snudda_parse_path(config["parameters"], self.snudda_data)
mech = snudda_parse_path(config["mechanisms"], self.snudda_data)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ def test_workflow(self):
config_name = os.path.join("tiny_parallel", "network-config.json")
cnc = SnuddaInit(struct_def={}, config_file=config_name, random_seed=123456)
cnc.define_striatum(num_dSPN=4, num_iSPN=4, num_FS=2, num_LTS=2, num_ChIN=2,
volume_type="cube")
volume_type="cube", stay_inside=True)
cnc.write_json(config_name)

with self.subTest(stage="place-parallel"):
run_cli_command("place tiny_parallel --parallel --raytraceBorders")
run_cli_command("place tiny_parallel --parallel --stayInside")

with self.subTest(stage="detect-parallel"):
run_cli_command("detect tiny_parallel --parallel")
Expand Down

0 comments on commit e2cd8eb

Please sign in to comment.