Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Hjorthmedh committed Jul 17, 2024
2 parents 3f32436 + 061eaf3 commit 5679e58
Show file tree
Hide file tree
Showing 6 changed files with 529,549 additions and 97 deletions.
1 change: 1 addition & 0 deletions examples/notebooks/neuromodulation/data/input_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"frequency" : [40],
"conductance" : 0.5e-9,
"num_inputs" : 100,
"num_soma_synapses" : 10,
"mod_file": "DASyn",
"RxD": {
"species_name": "DA",
Expand Down
529,475 changes: 529,430 additions & 45 deletions examples/notebooks/neuromodulation/neuromodulation_example_anu_on_real_dspn.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"sample_dt": 0.01,
"time": 4.5,
"record_all_soma": true,
"record_rxd_species_concentration_all_compartments": [["PKA", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]], ["DA", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]]],
"record_density_mechanism": {
"neuron_id": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50],
"section_id": [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
"section_x": [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5]
}
"section_x": [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5],
"record_rxd_species_concentration_all_compartments": [["PKAc", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]], ["DA", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]]]

}
69 changes: 68 additions & 1 deletion snudda/simulate/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,19 @@ def setup_parse_sim_info(self):
for rxd_neuron_id in record_rxd_neuron_id:
self.add_rxd_internal_concentration_recording_all(record_rx_species, rxd_neuron_id)

if "record_density_mechanism" in self.sim_info:
record_info = self.sim_info["record_density_mechanism"]

for (density_mechanism_name, variable_name), density_data in record_info.items():
neuron_id = density_data["neuron_id"]
sec_id = density_data["section_id"]
sec_x = density_data["section_x"]

self.add_density_mechanism_recording(neuron_id=neuron_id,
sec_id=sec_id, sec_x=sec_x,
density_mechanism_name=density_mechanism_name,
variable_name=variable_name)

# Do we need blocking call here, to make sure all neurons are setup
# before we try and connect them

Expand Down Expand Up @@ -1691,7 +1704,46 @@ def add_synapse_current_recording(self, source_id, dest_id):

return syn_ctr

def add_rxd_concentration_recording(self, species, neuron_id, region, sec_type, sec_id, sec_x):
def add_density_mechanism_recording(self, neuron_id, sec_id, sec_x, density_mechanism_name, variable_name):

""" Record density mechanism:
Args:
neuron_id (int) : Id of neuron
sec_id (list[int]) : List of section id:s for compartments
sec_x (list[int]) : List of section x for compartments
density_mechanism_name (str): Name of density mechanism, e.g. "pas"
variable_name (str): Variable name to record, e.g. "i" (will then read _ref_i)
"""

if type(sec_id) == int:
sec_id = [sec_id]

if type(sec_x) == float:
sec_x = [sec_x]

reference_name = f"_ref_{variable_name}"

sections = self.neurons[neuron_id].map_id_to_compartment(sec_id)

assert len(sections) == len(sec_id) == len(sec_x), f"Length mismatch {len(sections) = }, {len(sec_id) = }, {len(sec_x) = }"

for sec, sid, sx in zip(sections, sec_id, sec_x):
vector = self.sim.neuron.h.Vector()
mech_ref = getattr(sec(sx), density_mechanism_name)
vector.record(getattr(mech_ref, reference_name))

# From the Snudda synapse matrix. sec_id -1 is soma, sec_id >= 0 is dendrite, sec_id <= -2 is axon
self.record.register_compartment_data(neuron_id=neuron_id,
data_type=f"{density_mechanism_name}.{variable_name}", data=vector,
sec_id=sid, sec_x=sx)

if self.record.time is None:
t_save = self.sim.neuron.h.Vector()
t_save.record(self.sim.neuron.h._ref_t)
self.record.register_time(time=t_save)

def add_rxd_concentration_recording(self, species: str, neuron_id: int, region, sec_type, sec_id, sec_x):

if self.neurons[neuron_id].modulation is None:
raise ValueError(f"No modulation specified for neuron {self.neurons[neuron_id].name} ({neuron_id})")
Expand Down Expand Up @@ -1726,6 +1778,21 @@ def add_rxd_internal_concentration_recording_all(self, species, neuron_id):
f"Internal error, assumed {sid} was section id of {sec.name()}"
self.add_rxd_concentration_recording(species, neuron_id, "dend_internal", "dend", sid, 0.5)

def add_rxd_internal_concentration_recording_all_species(self, neuron_id):

if neuron_id not in self.neuron_id:
return

for species in self.neurons[neuron_id].modulation.species.keys():

# Add soma
self.add_rxd_concentration_recording(species, neuron_id, "soma_internal", "soma", -1, 0.5)

for sid, sec in enumerate(self.neurons[neuron_id].icell.dend):
assert int(sec.name().split('[')[-1].strip(']')) == sid, \
f"Internal error, assumed {sid} was section id of {sec.name()}"
self.add_rxd_concentration_recording(species, neuron_id, "dend_internal", "dend", sid, 0.5)

############################################################################

def run(self, t=None, hold_v=None):
Expand Down
31 changes: 24 additions & 7 deletions snudda/utils/load_network_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import h5py
import numpy as np
from collections import OrderedDict
from numba import jit

from snudda.utils.load import SnuddaLoad
Expand Down Expand Up @@ -156,13 +155,31 @@ def get_frequency(self, neuron_id, time_ranges=None):

return freq_table

def list_data_types(self, neuron_id):
return list(self.network_simulation_file["neurons"][str(neuron_id)].keys())

def get_all_data(self, neuron_id, exclude=None, include_time=False):
data = dict()

for data_type in self.list_data_types(neuron_id=neuron_id):

if exclude is not None and data_type in exclude:
continue

data[data_type] = self.get_data(data_type=data_type, neuron_id=neuron_id)

if include_time:
data["time"] = self.get_time()

return data

def get_data(self, data_type, neuron_id=None):

""" Returns data for neuron_id """

data = OrderedDict()
sec_id_x = OrderedDict()
syn_info = OrderedDict()
data = dict()
sec_id_x = dict()
syn_info = dict()

if neuron_id is None:
neuron_id = self.network_simulation_file["neurons"].keys()
Expand Down Expand Up @@ -307,9 +324,9 @@ def get_synaptic_current(self, pre_id=None, post_id=None):
if pre_id is None:
return current, sec_id_x, syn_info

filtered_current = OrderedDict()
filtered_sec_id_x = OrderedDict()
filtered_syn_info = OrderedDict()
filtered_current = dict()
filtered_sec_id_x = dict()
filtered_syn_info = dict()

for neuron_id, info in syn_info.items():
idx = np.where(syn_info[1] == pre_id)[0]
Expand Down

0 comments on commit 5679e58

Please sign in to comment.