def resource_branching(neuron_params): ds.reset_kernel() np.random.seed(kernel['seeds']) ds.set_kernel_status(kernel, simulation_id="van_pelt_branching") neuron_params['growth_cone_model'] = 'run_tumble_critical' neuron_params['res_branching_threshold'] = np.inf neuron_params["position"] = np.random.uniform(-500, 500, (num_neurons, 2)) gid = ds.create_neurons(n=num_neurons, params=neuron_params, axon_params=neuron_params, num_neurites=1, position=[]) step(10, 1, False, False) neuron_params['res_branching_threshold'] = b_th ds.set_object_properties(gid, params=neuron_params, axon_params=neuron_params) step(5000, 1, False, False) # neuron_params['use_lateral_branching'] = True ds.SaveSwc(swc_resolution=5) ds.save_json_info() swc_file = ds.get_simulation_id() # print(swc_file) return swc_file
def test_network(plot=False): ''' Bigger network ''' ds.reset_kernel() ds.set_kernel_status({ "resolution": 10. * minute, "num_local_threads": 6, }) initial_state = np.random.get_state() num_neurons = 100 positions = np.random.uniform(-200, 200, (num_neurons, 2)) * um params = { "position": positions, "growth_cone_model": "run-and-tumble", } neurons = ds.create_neurons(num_neurons, params, num_neurites=3) ds.simulate(0.45 * day) net = ds.morphology.generate_network(method="spines", max_spine_length=4. * um) if plot: ds.plot.plot_neurons(neurons, show_neuron_id=True) assert net.node_nb() == num_neurons, \ "Incorrect node number in the network; failed with state " + \ str(initial_state)
def test_models(): ''' Simulate one neurons with each defaults model ''' models = ds.get_models() observables = ds.get_default_properties('neuron', 'observables', settables_only=False) for m in models: print(m) ds.reset_kernel() kernel = {"environment_required": False} params = { "growth_cone_model": m, "position" : [0.,0.]*um } ds.set_kernel_status(kernel) gids = ds.create_neurons(n=1, num_neurites=3, params=params) rec = [ds.create_recorders(gids, obs, levels="neuron") for obs in observables] ds.simulate(10*hour) for r in rec: ds.get_recording(r)
def run_dense(kernel, neuron_params, ID, plot): """ """ resolution = 1. np.random.seed(kernel['seeds']) kernel["resolution"] = resolution kernel["angles_in_radians"] = True ds.set_kernel_status(kernel, simulation_id=ID) neuron_params['growth_cone_model'] = gc_model neuron_params["position"] = np.random.uniform(-1000, 1000, (num_neurons, 2)) gid = ds.create_neurons(n=num_neurons, params=neuron_params, axon_params=axon_params, dendrites_params=dendrite_params, num_neurites=6, position=[]) # ds.set_object_properties(gid, params=neuron_params, # axon_params=neuron_params) step(3. / resolution, 1, False, plot) step(300. / resolution, 1, False, plot) neuron_params['use_van_pelt'] = True dendrite_params['use_van_pelt'] = True axon_params['use_flpl_branching'] = False axon_params['flpl_branching_rate'] = 0.001 ds.set_object_properties(gid, params=neuron_params, dendrites_params=dendrite_params, axon_params=axon_params) step(6000. / resolution, 1, False, plot) axon_migated = { 'use_van_pelt': True, # "flpl_branching_rate" : 0.004, "res_retraction_threshold": 0.4, "res_elongation_threshold": 0.15, "res_elongation_factor": 0.6, # 'use_van_pelt' : True, "res_neurite_generated": 4500., "res_neurite_delivery_tau": 50., "res_correlation": 0.15, "res_variance": 0.02, "res_use_ratio": 0.3, } axon_params.update(axon_migated) ds.set_object_properties(gid, params=neuron_params, dendrites_params=dendrite_params, axon_params=axon_params) step(3000. / resolution, 1, False, plot) ds.SaveSwc(swc_resolution=25) ds.save_json_info() swc_file = ds.get_simulation_id() # print(swc_file) # ds.reset_kernel() return swc_file
def run_dense(neuron_params): """ """ resolution = 1. # np.random.seed(kernel['seeds']) np.random.seed(13) kernel["resolution"] = resolution * minute # kernel["angles_in_radians"] = False ds.set_kernel_status(kernel, simulation_id="van_pelt_branching") neuron_params['growth_cone_model'] = gc_model neuron_params["position"] = np.random.uniform(-2500, 2500, (num_neurons, 2)) * um gid = ds.create_neurons(n=num_neurons, params=neuron_params, num_neurites=3, position=[]) step(6000. / resolution * hour, 1, False, True) ds.SaveSwc(swc_resolution=5) ds.save_json_info() swc_file = ds.get_simulation_id() print(swc_file) # ds.reset_kernel() return swc_file
def run_axon_only(B, E, S, T, seed): neuron_params = { "position": np.random.uniform(-1000, 1000, (1, 2)) * um, "retraction_probability": 1., "somatropic_factor": 0.02, "self_avoidance_factor": 1., "growth_cone_model": "self-referential-forces", "filopodia_finger_length": 20. * um } ds.reset_kernel() axon_params = { "use_van_pelt": True, "B": B, "E": E, "S": S, "T": T * minute, "gc_split_angle_mean": 35. * deg, } kernel = { "resolution": 30. * minute, "seeds": [seed], "environment_required": False, "num_local_threads": 1, } ds.set_kernel_status(kernel) neurite_params = {"axon": axon_params} n = ds.create_neurons(n=1, params=neuron_params, neurite_params=neurite_params, num_neurites=1) ds.simulate(21 * day) return n
def test_functions(): ''' Run each of the main functions. ''' ds.reset_kernel() ds.set_kernel_status('environment_required', False) m = ds.generate_model('constant', 'memory-based', 'run-and-tumble') dp = ds.get_default_properties(m) e = ds.get_environment() ks = ds.get_kernel_status() ms = ds.get_models() pp = {"growth_cone_model": m, "position": (0., 0.) * um} gn = ds.create_neurons(params=pp, num_neurites=2) n = ds.get_neurons() ns = ds.get_object_properties(n) ns = ds.get_object_properties(n, level="neurite") ns = ds.get_object_properties(n, level="growth_cone") ns = ds.get_object_state(n) assert ds.get_object_state(n, "num_growth_cones") == 2 ns = ds.get_object_state(n, level="dendrite_1") si = ds.get_simulation_id() ds.simulate(20 * hour) ni = ds.get_neurons()
def lateral_branching(neuron_params): ds.reset_kernel() np.random.seed(kernel['seeds']) ds.set_kernel_status(kernel, simulation_id="uniform_branching") neuron_params['growth_cone_model'] = 'run_tumble' neuron_params[use_type] = False neuron_params["position"] = np.random.uniform(-500, 500, (num_neurons, 2)) * um gid = ds.create_neurons(n=num_neurons, params=neuron_params, num_neurites=2) step(1 * hour, 1, False, False) neuron_params[use_type] = True ds.set_object_properties(gid, params=neuron_params) # ~ axon_params=neuron_params) step(2 * day, 1, False, False) # neuron_params['use_lateral_branching'] = True ds.SaveSwc(swc_resolution=5) ds.save_json_info() swc_file = ds.get_simulation_id() # print(swc_file) return swc_file
def test_2neuron_network(plot=True): ''' Most simple network of 2 neurons ''' ds.reset_kernel() ds.set_kernel_status("resolution", 10. * minute) num_neurons = 2 positions = [(0, 0), (20, -20)] * um params = { "position": positions, "growth_cone_model": "run-and-tumble", "neurite_angles": [ { "axon": 90. * deg, "dendrite_1": 270. * deg }, { "axon": 180. * deg, "dendrite_1": 60. * deg }, ], } neurons = ds.create_neurons(num_neurons, params, num_neurites=2) ds.simulate(0.45 * day) net = ds.morphology.generate_network(method="spines", spine_density=1. / um**2, max_spine_length=4. * um) if plot: ds.plot.plot_neurons(neurons, show_neuron_id=True) assert net.node_nb() == num_neurons, \ "Incorrect node number in the network" assert net.edge_nb() == 1, \ "Incorrect number of edges in the network" assert net.get_edge_attributes(name="weight")[0] > 1, \ "Incorrect weight" net = ds.morphology.generate_network(method="intersections", connection_probability=1., default_synaptic_strength=2.) assert net.node_nb() == num_neurons, \ "Incorrect node number in the network" assert net.edge_nb() == 1, \ "Incorrect number of edges in the network" assert net.get_edge_attributes(name="weight")[0] == 2, \ "Incorrect weight"
def test_delete_neurites(): ''' Neurons deletion ''' ds.reset_kernel() initial_state = np.random.get_state() num_neurons = 50 simtime = 2. * minute ds.set_kernel_status("environment_required", False) # create and delete pos = np.random.uniform(-1000, 1000, (num_neurons, 2)) * um neurons = ds.create_neurons(num_neurons, params={"position": pos}, num_neurites=2) ds.delete_neurites("axon") for n in neurons: assert not n.has_axon, \ "Failed with state " + str(initial_state) assert "axon" not in n.neurites, \ "Failed with state " + str(initial_state) assert len(n.neurites) == 1, \ "Failed with state " + str(initial_state) ds.create_neurites(neurons[0], neurite_types="axon") assert neurons[0].has_axon, \ "Failed with state " + str(initial_state) assert len(neurons[0].neurites) == 2, \ "Failed with state " + str(initial_state) ds.delete_neurites("dendrite_1", neurons[1]) for n in neurons: if n == neurons[1]: assert "dendrite_1" not in n.neurites, \ "Failed with state " + str(initial_state) assert not n.neurites, \ "Failed with state " + str(initial_state) elif n == neurons[0]: assert len(n.neurites) == 2, \ "Failed with state " + str(initial_state) else: assert len(n.neurites) == 1, \ "Failed with state " + str(initial_state) ds.delete_neurites() for n in neurons: assert not n.neurites, \ "Failed with state " + str(initial_state)
def run_dense(neuron_params): """ """ resolution = 1. np.random.seed(kernel['seeds']) kernel["resolution"] = resolution * minute ds.set_kernel_status(kernel, simulation_id="van_pelt_branching") neuron_params['growth_cone_model'] = gc_model neuron_params["position"] = np.random.uniform( -500, 500, (num_neurons, 2)) * um gid = ds.create_neurons(n=num_neurons, params=neuron_params, axon_params=axon_params, num_neurites=3, position=[] ) neuron_params['use_van_pelt'] = False neuron_params['use_flpl_branching'] = False ds.set_object_properties(gid, params=neuron_params, axon_params=axon_params) step(200./resolution * minute, 1, False, True) neuron_params['use_van_pelt'] = True # neuron_params['use_flpl_branching'] = True # neuron_params["flpl_branching_rate"] = 0.001 ds.set_object_properties(gid, params=neuron_params, axon_params=neuron_params) step(1000./resolution * minute, 1, False, True) step(1000./resolution * minute, 1, False, True) step(1000./resolution * minute, 1, False, True) step(1000./resolution * minute, 1, False, True) # step(180, 1, False, True) # step(1080, 1, False, True) # step(1080, 1, False, True) # step(1080, 1, False, True) # step(1080, 1, False, True) # step(1080, 1, False, True) # step(1080, 1, False, True) # step(4080, 1, False, True) # neuron_params['use_van_pelt'] = True # ds.set_object_properties(gid,params = neuron_params, # axon_params=neuron_params) # step(10, 1, False, True) # step(10, 1, False, False) # neuron_params['use_lateral_branching'] = True ds.SaveSwc(swc_resolution=5) ds.save_json_info() swc_file = ds.get_simulation_id() # print(swc_file) # ds.reset_kernel() return swc_file
def random_walk_axon(neuron_params): np.random.seed(kernel['seeds']) ds.set_kernel_status(kernel, simulation_id="random_walk_axons") neuron_params['growth_cone_model'] = 'random_walk' neuron_params["position"] = np.random.uniform(-500, 500, (num_neurons, 2)) ds.create_neurons(n=num_neurons, params=neuron_params, num_neurites=1, position=[]) name = str(neuron_params["persistence_length"]) step(1000, 1, os.path.join(os.getcwd(), "random_walk_axon_" + name)) ds.reset_kernel()
def run_dense(neuron_params, axes, letter, single=False): # neuron_params["rw_memory_tau"]: 4., # neuron_params["rw_delta_corr"]: 1.8, ds.set_kernel_status(kernel, simulation_id="random_walk_axons") neuron_params["position"] = np.zeros((num_neurons, 2)) * um simulated_neurons = num_neurons if single: simulated_neurons = 1. neuron_params["position"] = np.array([0, 0]) * um gids = ds.create_neurons(n=simulated_neurons, params=neuron_params, num_neurites=1, position=[]) step(1000 * second, 1, os.path.join(os.getcwd(), "primo"), plot=False) neurons = ds.get_neurons() structure = ds.morphology.NeuronStructure(neurons) population = ds.Population.from_structure(structure) axons = population.axon_all_points() from matplotlib.colors import LogNorm import matplotlib import copy axes.text(0.03, 1.2, letter, horizontalalignment='center', verticalalignment='center', weight='bold', fontsize=12, transform=axes.transAxes) if not single: my_cmap = copy.copy( matplotlib.cm.get_cmap('viridis')) # copy the default cmap my_cmap.set_bad((0, 0, 0)) axes.hist2d(axons[:, 0], axons[:, 1], bins=100, range=[[0, 400], [-200, 200]], norm=LogNorm(), cmap=my_cmap) axes.set_xlabel("X") axes.set_ylabel("Y") axes.set_title("path density for\n {}".format( neuron_params["growth_cone_model"])) else: axes.plot(axons[:, 0], axons[:, 1], c='r') ds.reset_kernel()
def test_dendrogram(): ''' Run each of the main functions. ''' ds.reset_kernel() ds.set_kernel_status('environment_required', False) m = ds.generate_model('constant', 'pull-only', 'noisy-weighted-average') pp = {"growth_cone_model": m, "position": (0., 0.) * um} np = {"use_uniform_branching": True, "uniform_branching_rate": 3. * cpd} gn = ds.create_neurons(params=pp, neurite_params=np, num_neurites=2) ds.simulate(2 * day) ds.plot.plot_dendrogram(gn.axon, show=False) gn.dendrites["dendrite_1"].plot_dendrogram(show=False)
def run_dense(neuron_params,letter,length_simulation,single=False): # neuron_params["rw_memory_tau"]: 4., # neuron_params["rw_delta_corr"]: 1.8, ds.set_kernel_status(kernel, simulation_id="random_walk_axons") neuron_params["position"]=np.zeros((num_neurons,2)) simulated_neurons = num_neurons gids = ds.create_neurons(n=simulated_neurons, params=neuron_params, num_neurites=1, position=[] ) step(length_simulation, 1, False ,plot=False) neurons = ds.get_neurons() structure = ds.morphology.NeuronStructure(neurons) population = ds.Population.from_structure(structure) ens = ds.EnsembleRW(population) ens.characterizeRW("axon") ens.name = neuron_params["growth_cone_model"] fits = ens.fit() # import pdb; pdb.set_trace() # XXX BREAKPOINT ds.reset_kernel() return ens
"E": 0.6, "S": 1., "T": 10000. * minute, } if __name__ == '__main__': kernel = { #~ "seeds": [33, 345, 17, 193, 177], #~ "num_local_threads": 5, "seeds": [0], "num_local_threads": 1, "environment_required": False, "resolution": resolution * minute, } ds.set_kernel_status(kernel, simulation_id="case_neuron") neuron_params['growth_cone_model'] = gc_model neuron_params["position"] = np.random.uniform(-1000, 1000, (num_neurons, 2)) * um gid = ds.create_neurons(n=num_neurons, params=neuron_params, axon_params=axon_params, num_neurites=1) rec = ds.create_recorders(gid, ["length", "resource"], levels="growth_cone") ds.simulate(3 * day) ''' Get recording
"use_uniform_branching": True, "uniform_branching_rate": 0.009 * cph, } neurite_params = { "axon": { "initial_diameter": 4. * um }, "dendrites": { "taper_rate": 1. / 200., "initial_diameter": 3. * um } } # configure DeNSE ds.set_kernel_status(simu_params) # create neurons n = ds.create_neurons(n=num_neurons, params=neuron_params, neurite_params=neurite_params, num_neurites=2) ''' Plot the initial state ''' ds.plot.plot_neurons() ''' Simulate a few days then plot the result ''' ds.simulate(7 * day) ds.plot.plot_neurons() ''' Change parameters and simulate again '''
def test_branching(): do_plot = int(os.environ.get("DO_PLOT", True)) num_omp = 4 res = 10. # seed initial_state = np.random.get_state() seeds = np.random.choice(np.arange(0, 1000), size=num_omp, replace=False) num_neurons = 10 gc_model = 'gf_po_nm' btype = 'flpl' branching_rate = btype + '_branching_rate' branching_type = 'use_' + btype + '_branching' neuron_params = { "position" : np.random.uniform( -1000, 1000, (num_neurons, 2)) * um, "growth_cone_model": gc_model, "sensing_angle": 45.*deg, "speed_growth_cone": .1 * um / minute, "persistence_length": 100. * um, "filopodia_finger_length": 10. * um, "filopodia_min_number": 30, "lateral_branching_angle_mean": 25.*deg, "lateral_branching_angle_std": 0.*deg, "min_branching_distance": 5.*um, "taper_rate": 0., "diameter_fraction_lb": 1., branching_type: True, "use_van_pelt": False, } expected_branching = 500. test_nb = 6 rates = np.linspace(0.001, 0.005, test_nb) mean = [] er = [] Nb = [] scipy_exp = [] for rate in rates: ds.reset_kernel() kernel = { "resolution": res*minute, "seeds": seeds, "environment_required": False, "interactions": False, "num_local_threads": num_omp, } ds.set_kernel_status(kernel) sim_time = expected_branching/rate * minute sim_time.ito(day) neuron_params[branching_rate] = rate * cpm pop = ds.create_neurons(n=num_neurons, params=neuron_params, num_neurites=1) rec = ds.create_recorders(pop, 'num_growth_cones', levels='neuron') ds.simulate(sim_time) branch_times = ds.get_recording(rec)['num_growth_cones']['times'] Dt = [] for bn in branch_times.values(): if len(bn) > 1: Dt.extend(np.diff(bn)) mean.append(np.mean(Dt)) # 99% confidence interval for a Poisson distribution gives 2.576 er.append(2.576/rate/np.sqrt(len(Dt))) Nb.append(len(Dt)) mean_merr = np.subtract(mean, er) mean_perr = np.add(mean, er) test1 = (1/rates > mean_merr) test2 = (1/rates < mean_perr) if do_plot: import matplotlib.pyplot as plt plt.plot(rates, mean) plt.plot(rates, 1/rates, ls=":") plt.fill_between(rates, mean_merr, mean_perr, alpha=0.5) plt.show() assert test1.all() and test2.all(), \ "Failed test with state " + str(initial_state)
resolutions = (1., 2., 5., 10., 18., 35., 50.)[::-1] # ~ resolutions = (10., 18., 35., 50.)[::-1] fractions = [] lengths = [] for k, resol in enumerate(resolutions): print("\nSimulating with resol {}\n".format(resol)) np.random.seed(1) ds.reset_kernel() ds.set_kernel_status({ "resolution": resol * ms, "num_local_threads": num_omp, "seeds": [2 * i for i in range(num_omp)], }) ds.set_environment(shape) params = { "sensing_angle": 70. * deg, "persistence_length": 200. * um, "filopodia_wall_affinity": 2.5, "proba_down_move": 0.1, "scale_up_move":
def run_dense(neuron_params): """ """ resolution = 1. np.random.seed(kernel['seeds']) kernel["resolution"] = resolution kernel["angles_in_radians"] = True ds.set_kernel_status(kernel, simulation_id="case_neuron") neuron_params['growth_cone_model'] = gc_model neuron_params["position"] = np.random.uniform(-1000, 1000, (num_neurons, 2)) gid = ds.create_neurons(n=num_neurons, params=neuron_params, axon_params=axon_params, dendrites_params=dendrite_params, num_neurites=4, position=[]) step(100. / resolution, 1, False, True) arborization = { "use_van_pelt": True, "gc_split_angle_mean": 0.50, "B": 11., "T": 200. } arborization_axon = { "use_van_pelt": True, "gc_split_angle_mean": 1.0, "B": 19., "T": 5000. } dendrite_params.update(arborization) axon_params.update(arborization_axon) ds.set_object_properties(gid, params=neuron_params, dendrites_params=dendrite_params, axon_params=axon_params) step(1000. / resolution, 1, False, True) elongation = { "use_van_pelt": False, "persistence_length": 30., "res_retraction_factor": 0.01, "res_elongation_factor": 0.1, # "res_leakage": 0.05, "res_retraction_threshold": 0.1, "res_elongation_threshold": 0.2, "res_leakage": 30.0, "res_neurite_generated": 4500., "res_correlation": 0.05, "res_variance": 0.002, "res_use_ratio": 0.1, } elongation_axon = {"res_elongation_factor": 0.5} dendrite_params.update(elongation) axon_params.update(elongation_axon) print("elongation") ds.set_object_properties(gid, params=neuron_params, dendrites_params=dendrite_params, axon_params=axon_params) step(2002. / resolution, 1, False, True) # stop the dendrites stortignation = { "use_van_pelt": False, "persistence_length": 10., "res_retraction_factor": 0.0, "res_elongation_factor": 0.0, "res_retraction_threshold": 0.000, "res_elongation_threshold": 10., } stortignation_axon = { "use_van_pelt": False, "sensing_angle": 0.20, "persistence_length": 91., "flpl_branching_rate": 0.002, "use_flpl_branching": True, "res_retraction_factor": 0.02, "res_elongation_factor": 0.2910, # "res_leakage": 0.05, "res_retraction_threshold": 0.0001, "res_elongation_threshold": 0.10, "res_leakage": 10.0, "res_neurite_generated": 45000., "res_correlation": 0.05, "res_weight_diameter": 0., "res_variance": 0.001, "res_use_ratio": 0.1, } print("stortignation") dendrite_params.update(stortignation) axon_params.update(stortignation_axon) ds.set_object_properties(gid, params=neuron_params, dendrites_params=dendrite_params, axon_params=axon_params) step(2000. / resolution, 1, False, True) ds.SaveSwc(swc_resolution=5) ds.save_json_info() swc_file = ds.get_simulation_id() # print(swc_file) # ds.reset_kernel() return swc_file
def run_dense(neuron_params): """ """ resolution = 1. np.random.seed(kernel['seeds']) kernel["resolution"] = resolution kernel["angles_in_radians"] = True ds.set_kernel_status(kernel, simulation_id="case_neuron") neuron_params['growth_cone_model'] = gc_model neuron_params["position"] = np.random.uniform(-1000, 1000, (num_neurons, 2)) gid = ds.create_neurons(n=num_neurons, params=neuron_params, axon_params=axon_params, dendrites_params=dendrite_params, num_neurites=4, position=[]) step(2000. / resolution, 1, False, True) splitting_dendrites = { 'use_van_pelt': True, "persistence_length": 60.0, "gc_split_angle_mean": 1., 'use_flpl_branching': True, "flpl_branching_rate": 0.0036, "B": 30., "E": 0.9, "S": 1.0, "T": 10000., } dendrite_params.update(splitting_dendrites) ds.set_object_properties(gid, params=neuron_params, dendrites_params=dendrite_params) step(2000. / resolution, 1, False, True) arborization = { 'use_van_pelt': False, 'use_flpl_branching': False, "persistence_length": 30.0, "res_weight_diameter": 0.1, "res_retraction_threshold": 0.01, "res_elongation_threshold": 0.12, "res_elongation_factor": 0.0612, "res_retraction_factor": 10., # 'use_van_pelt' : True, "res_neurite_generated": 9500., "res_neurite_delivery_tau": 50., "res_correlation": 0.15, "res_variance": 0.02, "res_use_ratio": 0.3, } dendrite_params.update(arborization) ds.set_object_properties(gid, params=neuron_params, dendrites_params=dendrite_params, axon_params=axon_params) step(2000. / resolution, 1, False, True) arborization = { 'use_van_pelt': True, # 'use_flpl_branching' : True, "flpl_branching_rate": 0.00036, "persistence_length": 5.0, "res_retraction_threshold": 0.1, "res_weight_diameter": 0.001, "res_elongation_threshold": 0.14, "res_elongation_factor": 0.12, # 'use_van_pelt' : True, "res_neurite_generated": 9500., "res_neurite_delivery_tau": 50., "res_correlation": 0.5, "res_variance": 0.2, "res_use_ratio": 0.4, } dendrite_params.update(arborization) ds.set_object_properties(gid, params=neuron_params, dendrites_params=dendrite_params, axon_params=axon_params) step(2000. / resolution, 1, False, True) step(2000. / resolution, 1, False, True) # neuron_params['use_flpl_branching'] = True # neuron_params["flpl_branching_rate"] = 0.001 # ds.set_object_properties(gid,params = neuron_params, # axon_params= neuron_params) # step(1000./resolution, 1, False, True) # step(1000./resolution, 1, False, True) # step(1000./resolution, 1, False, True) # step(1000./resolution, 1, False, True) # step(180, 1, False, True) # step(1080, 1, False, True) # step(1080, 1, False, True) # step(1080, 1, False, True) # step(1080, 1, False, True) # step(1080, 1, False, True) # step(1080, 1, False, True) # step(4080, 1, False, True) # neuron_params['use_van_pelt'] = True # ds.set_object_properties(gid,params = neuron_params, # axon_params=neuron_params) # step(10, 1, False, True) # step(10, 1, False, False) # neuron_params['use_lateral_branching'] = True ds.SaveSwc(swc_resolution=15) ds.save_json_info() swc_file = ds.get_simulation_id() # print(swc_file) # ds.reset_kernel() return swc_file
def test_persistence(): persistences = [] for k, resol in enumerate(resolutions): np.random.seed(1) ds.reset_kernel() ds.set_kernel_status({ "resolution": resol * minute, "num_local_threads": num_omp, "seeds": [2 * i for i in range(num_omp)], "environment_required": False, "adaptive_timestep": -1., "interactions": False, }) params = { "growth_cone_model": gc_model, "speed_growth_cone": speed * um / minute, "filopodia_wall_affinity": 2.5, "filopodia_min_number": 100, "proba_down_move": 0.05, "scale_up_move": 5. * um, "persistence_length": l_p * um, "sensing_angle": sensing_angle, "position": [(0., 0.) for _ in range(num_neurons)] * um, "taper_rate": 0., } gids = ds.create_neurons(n=num_neurons, num_neurites=1, params=params) rec = ds.create_recorders(gids, "length") ds.simulate(simtime * minute) ''' Analyze the resulting neurons ''' population = ds.elements.Population.from_gids(gids) axons = [neuron.axon.xy.m.transpose() for neuron in population] sequence = [] for i, points in enumerate(axons): sequence.append(correlation(points, distances)) avg_corr = np.average(sequence, axis=0) lp, _ = curve_fit(exp_decay, distances, avg_corr, p0=l_p) persistences.append(lp) if do_plot: ax2.scatter(resol, lp[0]) ax.plot(distances, avg_corr, color=cmap(colors[k]), alpha=1, label="resol: {}".format(resol)) ax.plot(distances, exp_decay(distances, lp[0])) if show_neurons: ds.plot.plot_neurons(show=False, title=str(resol)) if do_plot: ax.plot(distances, np.exp(-distances / l_p), ls="--", c="k") ax.legend(loc=1, fancybox=True, frameon=True) ax.set_ylabel("Correlation") ax.set_ylabel(r"Distance ($\mu$m)") ax2.set_ylabel(r"Persistence length ($\mu$m)") ax2.set_xlabel("Resolution (minutes)") ax2.axhline(l_p) fig.patch.set_alpha(0.) fig2.patch.set_alpha(0.) plt.show() # just check that no ridiculous number is encountered for lp in persistences: assert lp > 0. and np.abs((lp - l_p) / l_p) < 0.5
def run_dense(kernel, neuron_params, ID, plot=True): """ """ np.random.seed(kernel['seeds']) resolution = kernel["resolution"] kernel["angles_in_radians"] = True ds.set_kernel_status(kernel, simulation_id=ID) neuron_params['growth_cone_model'] = gc_model neuron_params["position"] = np.random.uniform(-1000, 1000, (num_neurons, 2)) gid = ds.create_neurons(n=num_neurons, params=neuron_params, axon_params=axon_params, dendrites_params=dendrite_params, num_neurites=4, position=[]) step(100. / resolution, 1, False, plot) arborization = { "use_van_pelt": True, "gc_split_angle_mean": 0.50, "B": 11., "T": 200. } arborization_axon = { "use_van_pelt": True, "gc_split_angle_mean": 1.0, "B": 19., "T": 2000. } dendrite_params.update(arborization) axon_params.update(arborization_axon) ds.set_object_properties(gid, params=neuron_params, dendrites_params=dendrite_params, axon_params=axon_params) step(1000. / resolution, 1, False, plot) elongation = { "use_van_pelt": False, "persistence_length": 30., } dendrite_params.update(elongation) ds.set_object_properties(gid, params=neuron_params, dendrites_params=dendrite_params, axon_params=axon_params) step(2002. / resolution, 1, False, plot) stortignation = { "use_van_pelt": False, "persistence_length": 10., } stortignation_axon = { "use_van_pelt": False, # "sensing_angle": 0.20, "use_flpl_branching": True, "persistence_length": 91., "flpl_branching_rate": 0.0066, } # dendrite_params.update(stortignation) # axon_params.update(stortignation_axon) # ds.set_object_properties(gid, # params=neuron_params, # dendrites_params=dendrite_params, # axon_params=axon_params) step(2000. / resolution, 1, False, plot) # stortignation = {"use_van_pelt": False, # "persistence_length":10., # } # stortignation_axon={ # "use_van_pelt": False, # "use_flpl_branching": True, # "flpl_branching_rate" : 0.003, # "sensing_angle": 0.63, # "persistence_length": 40., # } # dendrite_params.update(stortignation) # axon_params.update(stortignation_axon) # ds.set_object_properties(gid, # params=neuron_params, # dendrites_params=dendrite_params, # axon_params=axon_params) # step(2000./resolution, 1, False, True) # step(2000./resolution, 1, False, True) ds.SaveSwc(swc_resolution=5) ds.save_json_info() swc_file = ds.get_simulation_id() # print(swc_file) # ds.reset_kernel() return swc_file
def run_dense(neuron_params): """ """ resolution = 30. * minute np.random.seed(kernel['seeds']) #Seeds the random number generator kernel["resolution"] = resolution # kernel["angles_in_radians"] = True ds.set_kernel_status(kernel, simulation_id="multipolar") neuron_params["position"] = np.random.uniform(-1000, 1000, (num_neurons, 2)) * um gid = ds.create_neurons(n=num_neurons, params=neuron_params, axon_params=axon_params, dendrites_params=dendrite_params, num_neurites=4) # ds.set_object_properties(gid, params=neuron_params, # axon_params=neuron_params) step(3 * day, 1, False, True) axon_params['use_van_pelt'] = True axon_params["B"] = 90. * cpm axon_params["E"] = 0.2 axon_params["S"] = 1. axon_params["T"] = 10000. * minute dendrite_params['use_van_pelt'] = True dendrite_params["B"] = 90. * cpm dendrite_params["E"] = 0.2 dendrite_params["S"] = 1. dendrite_params["T"] = 10000. * minute axon_params['use_flpl_branching'] = False axon_params['flpl_branching_rate'] = 0.001 * cpm ds.set_object_properties(gid, params=neuron_params, dendrites_params=dendrite_params, axon_params=axon_params) step(6 * day, 1, False, True) axon_migated = { 'use_van_pelt': True, # "flpl_branching_rate" : 0.004, "res_retraction_threshold": 0.4 * uM, "res_elongation_threshold": 0.15 * uM, "res_elongation_factor": 0.6 * um / minute, # 'use_van_pelt' : True, "res_neurite_generated": 4500. * uM, "res_neurite_delivery_tau": 50. * minute, "res_correlation": 0.15, "res_variance": 0.02 * uM / minute**0.5, "res_use_ratio": 0.3 * cpm, } axon_params.update(axon_migated) ds.set_object_properties(gid, params=neuron_params, dendrites_params=dendrite_params, axon_params=axon_params) step(3 * day, 1, False, True) # neuron_params['use_flpl_branching'] = True # neuron_params["flpl_branching_rate"] = 0.001 # ds.set_object_properties(gid,params = neuron_params, # axon_params= neuron_params) # step(1000./resolution, 1, False, True) # step(1000./resolution, 1, False, True) # step(1000./resolution, 1, False, True) # step(1000./resolution, 1, False, True) # step(180, 1, False, True) # step(1080, 1, False, True) # step(1080, 1, False, True) # step(1080, 1, False, True) # step(1080, 1, False, True) # step(1080, 1, False, True) # step(1080, 1, False, True) # step(4080, 1, False, True) # neuron_params['use_van_pelt'] = True # ds.set_object_properties(gid,params = neuron_params, # axon_params=neuron_params) # step(10, 1, False, True) # step(10, 1, False, False) # neuron_params['use_lateral_branching'] = True ds.io.save_to_swc(resolution=25) ds.save_json_info() swc_file = ds.get_simulation_id() # print(swc_file) # ds.reset_kernel() return swc_file
"taper_rate": 1. / 200., "use_uniform_branching": False, "use_van_pelt": True, "B": 1. * cpm, "T": 5000. * minute, "gc_split_angle_mean": 25. * deg, } kernel = { "resolution": 30. * minute, "seeds": [8], "environment_required": False, "num_local_threads": num_omp, } ds.set_kernel_status(kernel) # create neurons n = ds.create_neurons(n=num_neurons, params=neuron_params, axon_params=axon_params, dendrites_params=dend_params, num_neurites=2) # first, elongation ds.simulate(10000 * minute) ds.plot.plot_neurons() # then branching
# # DeNSE is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with DeNSE. If not, see <http://www.gnu.org/licenses/>. import dense as ds from dense.units import * # import matplotlib as mpl # mpl.use("Qt5Agg") ds.set_kernel_status("resolution", 10. * minute) params = { # "growth_cone_model": "run-and-tumble", "growth_cone_model": "self-referential-forces", "somatropic_factor": 0.03, "somatropic_scale": 50. * um, "noise_amplitude": 1. * deg, "position": (0., 0.) * um, } neuron = ds.create_neurons(params=params, num_neurites=1) rec = ds.create_recorders(neuron, ["length", "stepping_probability"], levels="growth_cone")
"num_local_threads": 6, "resolution": 5. * minute, "interactions": True } # kernel = {"seeds":[33], # "num_local_threads": 1, # "resolution": 5.*minute, # "interactions": True} # ~ kernel={ # ~ "seeds":[23, 68], # ~ "num_local_threads": 2, # ~ "resolution": 30.*minute # ~ } kernel["environment_required"] = False ds.set_kernel_status(kernel, simulation_id="ID") gids, culture = None, None if kernel["environment_required"]: shape = ds.environment.Shape.disk(300.) culture = ds.set_environment(shape) # generate the neurons inside the left chamber # pos_left = culture.seed_neurons( # neurons=100, xmax=540, soma_radius=soma_radius) neuron_params['position'] = culture.seed_neurons( neurons=num_neurons, soma_radius=soma_radius) else: neuron_params['position'] = \ np.random.uniform(-1000, 1000, (num_neurons, 2))*um print("\nCreating neurons\n")
def test_delete_neurons(): ''' Neurons deletion ''' ds.reset_kernel() num_neurons = 50 simtime = 2.*minute initial_state = np.random.get_state() ds.set_kernel_status("environment_required", False) # create and delete nparams = { "position": np.random.uniform(-1000, 1000, (num_neurons, 2))*um, "growth_cone_model": "res_po_rt" } neurons = ds.create_neurons(num_neurons, params=nparams, num_neurites=2) ds.delete_neurons(3) ds.delete_neurons(neurons[8]) # check neurons have been deleted neurons_got = ds.get_neurons() n_to_ints = [int(n) for n in neurons_got] n_to_ints += ds.get_neurons(True) assert len(n_to_ints) == 2*(num_neurons - 2), \ "Failed with state " + str(initial_state) assert 3 not in n_to_ints, \ "Failed with state " + str(initial_state) assert 8 not in n_to_ints, \ "Failed with state " + str(initial_state) # simulate then delete ds.simulate(simtime) ds.delete_neurons([5, 7]) ds.delete_neurons(neurons[40:45]) # recreate neurons and resimulate nparams = { "position": np.random.uniform(-1000, 1000, (num_neurons, 2))*um, "growth_cone_model": "res_po_rt" } _ = ds.create_neurons(num_neurons, params=nparams, num_neurites=2) ds.simulate(simtime) neurons_got = ds.get_neurons() n_to_ints = [int(n) for n in neurons_got] n_to_ints += ds.get_neurons(True) assert len(n_to_ints) == 2*(2*num_neurons - 4 - len(neurons[40:45])), \ "Failed with state " + str(initial_state) assert 5 not in n_to_ints, \ "Failed with state " + str(initial_state) assert 7 not in n_to_ints, \ "Failed with state " + str(initial_state) for n in neurons[40:45]: assert int(n) not in n_to_ints, \ "Failed with state " + str(initial_state) # delete all neurons ds.delete_neurons() # check no neurons are left assert not ds.get_neurons(), \ "Failed with state " + str(initial_state)
def run_dense(neuron_params): """ """ kernel["resolution"] = resolution * minute ds.set_kernel_status(kernel, simulation_id="case_neuron") neuron_params['growth_cone_model'] = gc_model print(neuron_params['growth_cone_model']) neuron_params["position"] = np.random.uniform(-1000, 1000, (num_neurons, 2)) * um print(neuron_params['growth_cone_model']) gid = ds.create_neurons(n=num_neurons, params=neuron_params, axon_params=axon_params, dendrites_params=dendrite_params, num_neurites=1) print(neuron_params['growth_cone_model']) # ~ rec = ds.create_recorders(gid, ["speed", "resource"], levels="growth_cone") rec = ds.create_recorders(gid, ["resource"], levels="growth_cone") print(neuron_params['growth_cone_model']) # ds.set_object_properties(gid, params=neuron_params, # axon_params=neuron_params) step(3. / resolution * minute, 1, False, False) step(500. / resolution * minute, 1, False, False) print(neuron_params['growth_cone_model']) neuron_params['use_van_pelt'] = True dendrite_params['use_van_pelt'] = True axon_params['use_flpl_branching'] = True axon_params['flpl_branching_rate'] = 0.001 * cpm neuron_params.pop('growth_cone_model') print(dendrite_params) ds.set_object_properties(gid, params=neuron_params, dendrites_params=dendrite_params, axon_params=axon_params) step(2000. / resolution * minute, 1, False, True) axon_migated = { # 'use_flpl_branching' : True, # "flpl_branching_rate" : 0.004 * cpm, "res_retraction_threshold": 0.4 * uM, "res_elongation_threshold": 0.15 * uM, "res_elongation_factor": 0.4 * um / minute, # 'use_van_pelt' : True, "res_neurite_generated": 4500. * uM, "res_neurite_delivery_tau": 50. * minute, "res_correlation": 0.15, "res_variance": 0.02 * uM / minute**0.5, "res_use_ratio": 0.3, } axon_params.update(axon_migated) ds.set_object_properties(gid, params=neuron_params, dendrites_params=dendrite_params, axon_params=axon_params) step(3000. / resolution * minute, 1, False, True) # neuron_params['use_flpl_branching'] = True # neuron_params["flpl_branching_rate"] = 0.001 * cpm # ds.set_object_properties(gid,params = neuron_params, # axon_params= neuron_params) # step(1000./resolution, 1, False, True) # step(1000./resolution, 1, False, True) # step(1000./resolution, 1, False, True) # step(1000./resolution, 1, False, True) # step(180, 1, False, True) # step(1080, 1, False, True) # step(1080, 1, False, True) # step(1080, 1, False, True) # step(1080, 1, False, True) # step(1080, 1, False, True) # step(1080, 1, False, True) # step(4080, 1, False, True) # neuron_params['use_van_pelt'] = True # ds.set_object_properties(gid,params = neuron_params, # axon_params=neuron_params) # step(10, 1, False, True) # step(10, 1, False, False) # neuron_params['use_lateral_branching'] = True #~ ds.SaveSwc(swc_resolution=5) #~ ds.save_json_info() ds.plot.plot_recording(rec, show=False) swc_file = ds.get_simulation_id() # print(swc_file) # ds.reset_kernel() return swc_file
for i, m in enumerate(masks): shape.add_area(m, height=30., name="top_{}".format(i + 1)) env.plot_shape(shape, show=True) ''' Set the environment in DeNSE, then create the neurons ''' num_omp = 1 resol = 2. * minute nngt.seed(0) ds.set_kernel_status({ "resolution": resol, "num_local_threads": num_omp, "seeds": [2 * i + 1 for i in range(num_omp)], # ~ "seeds": [11, 6, 7, 9], }) np.random.seed(1) ds.set_environment(shape) shape = ds.get_environment() # ~ for a in shape.areas.values(): # ~ env.plot_shape(a, show=False) # ~ env.plot_shape(shape, show=True) # seed the neurons on top top_areas = [k for k in shape.areas.keys() if k.find("default_area") != 0]