diff --git a/snudda/cli.py b/snudda/cli.py index d6d731917..9e9886326 100644 --- a/snudda/cli.py +++ b/snudda/cli.py @@ -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") diff --git a/snudda/core.py b/snudda/core.py index 61b4b1500..0ec1d388a 100755 --- a/snudda/core.py +++ b/snudda/core.py @@ -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 """ @@ -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) @@ -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): @@ -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) diff --git a/snudda/detect/detect.py b/snudda/detect/detect.py index 45d452a41..1c81314a6 100644 --- a/snudda/detect/detect.py +++ b/snudda/detect/detect.py @@ -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] @@ -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"], diff --git a/snudda/neurons/neuron_model_extended.py b/snudda/neurons/neuron_model_extended.py index a91bb8be3..b1937c61e 100644 --- a/snudda/neurons/neuron_model_extended.py +++ b/snudda/neurons/neuron_model_extended.py @@ -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 diff --git a/snudda/simulate/simulate.py b/snudda/simulate/simulate.py index a40fd6d64..930e71e8a 100644 --- a/snudda/simulate/simulate.py +++ b/snudda/simulate/simulate.py @@ -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) diff --git a/tests/test_cli.py b/tests/test_cli.py index e577b8dea..8508c2c57 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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")