def test_netstim_after_sim(self): """ NetStim created after simulation run has no effect, it won't go on this simulation at all. However NetStim start is in the absolute time. """ # Record rec = Record(self.soma(0.5)) # Run sim = Simulation(init_v=-70, warmup=20) sim.run(1) # Netstim to synapse stim = NetStimCell("stim").add_netstim(start=25, number=10, interval=2) self.cell.add_synapse(source=stim, netcon_weight=0.5, mod_name="ExpSyn", delay=1, seg=self.apic1(0.5)) sim.run(100) r = rec.as_numpy(variable="v") # Make assertions self.assertEqual(4051, r.size) self.assertEqual(-67.1917, round(r.records.max(), 4)) self.assertEqual(-70.0, round(r.records.min(), 4)) self.assertEqual(3, r.records.argmax()) # time in ms of max mV value self.assertEqual(6, r.time[r.records.argmax()]) stim.remove_immediate_from_neuron() sim.remove_immediate_from_neuron() rec.remove_immediate_from_neuron()
def test_netstim_before_sim(self): """ NetStim run in a regular way before Simulation run, in this cale (netcon weight=1.0) we have spike of the soma. However NetStim start is in the absolute time. """ # Netstim to synapse stim = NetStimCell("stim").add_netstim(start=25, number=10, interval=2) self.cell.add_synapse(source=stim, netcon_weight=1.0, mod_name="ExpSyn", delay=1, seg=self.apic1(0.5)) # Record rec = Record(self.soma(0.5)) # Run sim = Simulation(init_v=-70, warmup=20) sim.run(1) sim.run(100) r = rec.as_numpy(variable="v") stim.remove_immediate_from_neuron() sim.remove_immediate_from_neuron() rec.remove_immediate_from_neuron() # Make assertions self.assertEqual(4051, r.size) self.assertEqual(34.5205, round(r.records.max(), 4)) self.assertEqual(-75.3053, round(r.records.min(), 4)) self.assertEqual(319, r.records.argmax()) # time in ms of max mV value self.assertEqual(27.725, round(r.time[r.records.argmax()], 4))
def _prepare_epsp_protocol(self, epsp: EpspProtocol, global_time): synapse = epsp.syn current_time = global_time + epsp.init netstim = NetStimCell(name="stim") self.netstims.append(netstim) stim = netstim.add_netstim(start=current_time, number=epsp.num, interval=epsp.int) synapse.add_netcon(source=stim, weight=epsp.w, threshold=epsp.thr, delay=epsp.delay) current_time += epsp.int * epsp.num return current_time
def setUpClass(cls): morpho_path = os.path.join(path, "..", "commons/morphologies/swc/my.swc") def cell_template(): cell = Cell(name="cell") cell.load_morpho(filepath=morpho_path) cell.insert("pas") cell.insert("hh") return cell # Create NetStim cls.netstim = NetStimCell("stim1").add_netstim(start=21, number=100, interval=2) # Define connection probabilities Dist.set_seed(13) weight_dist = NormalDist(mean=0.01, std=0.024) # Create population 1 cls.pop1 = Population("pop_0") cls.pop1.add_cells(num=30, cell_function=cell_template) connector = cls.pop1.connect(cell_connection_proba=0.6) connector.set_source(cls.netstim) connector.set_target([c.filter_secs("dend") for c in cls.pop1.cells]) syn_adder = connector.add_synapse("Exp2Syn") syn_adder.add_netcon(weight=weight_dist) connector.build() # Create population 2 cls.pop2 = Population("pop_1") cls.pop2.add_cells(num=40, cell_function=cell_template) connector = cls.pop2.connect(cell_connection_proba=0.8) connector.set_source( [c.filter_secs("soma")(0.5) for c in cls.pop1.cells]) connector.set_target([c.filter_secs("dend") for c in cls.pop2.cells]) syn_adder = connector.add_synapse("Exp2Syn") syn_adder.add_netcon(weight=weight_dist) connector.build() # Create population 3 cls.pop3 = Population("pop_2") cls.pop3.add_cells(num=50, cell_function=cell_template) connector = cls.pop3.connect(cell_connection_proba=0.3) connector.set_source( [c.filter_secs("soma")(0.5) for c in cls.pop2.cells]) connector.set_target([c.filter_secs("dend") for c in cls.pop3.cells]) syn_adder = connector.add_synapse("Exp2Syn") syn_adder.add_netcon(weight=weight_dist) connector.build()
from neuronpp.cells.ebner2019_cell import Ebner2019Cell from neuronpp.core.cells.netstim_cell import NetStimCell path = os.path.dirname(os.path.abspath(__file__)) WEIGHT = 0.0035 # µS, conductance of (single) synaptic potentials WARMUP = 200 if __name__ == '__main__': # define cell cell = Ebner2019Cell(name="cell") filepath = os.path.join(path, "..", "commons/morphologies/asc/cell1.asc") cell.load_morpho(filepath=filepath) # stimulation stim = NetStimCell("stim_cell").add_netstim(start=WARMUP + 1, number=300, interval=1) cell.add_random_synapses_with_spine(source=stim, secs=cell.secs, mod_name="Syn4P", netcon_weight=WEIGHT, delay=1, head_nseg=10, neck_nseg=10, number=10, **cell.params_4p_syn) # add mechanisms cell.make_default_mechanisms() cell.make_apical_mechanisms(sections='dend head neck')
from neuronpp.utils.record import Record from neuronpp.utils.iclamp import IClamp from neuronpp.utils.utils import make_shape_plot from neuronpp.core.cells.netstim_cell import NetStimCell # Create cell cell = Cell(name="cell") path = os.path.dirname(os.path.abspath(__file__)) morpho_path = os.path.join(path, "..", "commons/morphologies/asc/cell2.asc") cell.load_morpho(filepath=morpho_path) cell.insert("pas") cell.insert("hh") # Create stim and synapses ns_cell = NetStimCell("stim_cell") ns = ns_cell.make_netstim(start=30, number=5, interval=10) syns = cell.add_synapses_with_spine(source=ns, secs=cell.filter_secs("apic"), mod_name="ExpSyn", netcon_weight=0.01, delay=1, number=100) soma = cell.filter_secs("soma") # Create IClamp ic = IClamp(segment=soma(0.5)) ic.stim(delay=100, dur=10, amp=0.1) # prepare plots and spike detector
path = os.path.dirname(os.path.abspath(__file__)) WEIGHT = 0.0035 # µS, conductance of (single) synaptic potentials WARMUP = 200 if __name__ == '__main__': # define cell cell = Ebner2019AChDACell(name="cell") filepath = os.path.join(path, "..", "commons/morphologies/swc/my.swc") cell.load_morpho(filepath=filepath) # make NetStim stims ns_cell = NetStimCell("netstim_cell") stim1 = ns_cell.make_netstim(start=WARMUP + 1, number=1) # make VecStim vs_cell = VecStimCell("vecstim_cell") stim2 = vs_cell.make_vecstim(np.array([WARMUP+50])) # make synapses with spines syns_4p, heads = cell.add_synapses_with_spine(source=None, secs=cell.secs, number=100, netcon_weight=WEIGHT, mod_name="Syn4PAChDa", delay=1, **cell.params_4p_syn) for s, h in zip(syns_4p, heads): syn_ach = cell.add_synapse(source=stim1, mod_name="SynACh", seg=h(1.0), netcon_weight=0.1, delay=1) syn_da = cell.add_synapse(source=stim2, mod_name="SynDa", seg=h(1.0), netcon_weight=0.1, delay=1) cell.set_synaptic_pointers(s, syn_ach, syn_da) # add mechanisms
def make_protocol(self, protocol: str, start, isi=1, iti=1, epsp_synapse: [Synapse, ComplexSynapse] = None, i_clamp_section: Sec = None, train_number=1, copy_netconn_params=True): """ Create an experimental protocol of EPSPs and APs. Each element of the experiment (EPSP or AP) is separated by isi (in ms). :param protocol: string eg. 3xEPSP[int=10,w=2.5,thr=5,del=2] 3xAP[int=10,dur=3,amp=1.6] Params ofr EPSP and AP: int - interval between in ms Params for EPSP only: w - weight for netconn (default is 1.0) -> used only when copy_netconn_params=False del - delay for netconn (default is 1.0) -> used only when copy_netconn_params=False thr - threshold for netconn (default is 10) -> used only when copy_netconn_params=False Params for AP only: dur - duration of AP in ms amp - amplitude in nA :param epsp_synapse: synapse to stimulate. Default is None if you don't want to stimulate synapse :param i_clamp_section: section to input IClamp. Default is None if you don't want to stimulate any section by electrode (eg. making AP) It is assumed that IClamp stimulate i_clamp_section(0.5) segment. :param start: start time of the first stimuli in ms, it is absolute time, so bear in mind warmup time. :param isi: Inter Stimulus Interval, eg. 3xEPSP,2xAP -isi- 3xEPSP,2xAP :param iti: Inter Train Interval eg. 3xEPSP,2xAP -isi- 3xEPSP,2xAP -iti- 3xEPSP,2xAP-isi-3xEPSP,2xAP :param train_number: number of trains. Default is 1 :param copy_netconn_params: If copy_netconn_params=True it will copy NetConn params from the last NetConn added to the synapse. :return: tuple(NetStim, IClamp). If epsp_synapse is None NetStim will be None If i_clamp_section is None IClamp will be None """ #if start < h.t: # raise ValueError("Experimental protocol 'start' param must > h.t (time of the simulation), but your " # "start=%s and h.t=%s. Bear in mind that 'start' param is the absolute time" % (start, h.t)) protocol = protocol.lower() protocols = protocol.split(" ") netstim = None if epsp_synapse: netstim = NetStimCell(name="stim") self.netstims.append(netstim) iclamp = None if i_clamp_section: iclamp = IClamp(i_clamp_section(0.5)) self.iclamps.append(iclamp) event_time = start for train_no in range(train_number): for p in protocols: event_time = self._prepare_protocol(p, netstim, iclamp, event_time, epsp_synapse, copy_netconn_params) event_time += isi event_time += iti return netstim, iclamp
from neuronpp.core.distributions import Dist, NormalTruncatedDist, NormalTruncatedSegDist path = os.path.dirname(os.path.abspath(__file__)) if __name__ == '__main__': def cell_function(): cell = Cell(name="cell") morpho_path = os.path.join(path, "..", "commons/morphologies/asc/cell1.asc") cell.load_morpho(filepath=morpho_path) cell.insert("pas") cell.insert("hh") cell.make_spike_detector(seg=cell.filter_secs("soma")(0.5)) return cell # Create NetStim netstim = NetStimCell("stim").add_netstim(start=21, number=100, interval=2) # Define connection probabilities Dist.set_seed(13) connection_proba = NormalConnectionProba(mean=0.8, std=0.1, threshold=0.6) weight_dist = NormalTruncatedDist(mean=0.1, std=0.2) # Create population 1 pop1 = Population("pop_1") pop1.add_cells(num=4, cell_function=cell_function) connector = pop1.connect(cell_connection_proba=connection_proba) connector.set_source(netstim) connector.set_target([d(0.5) for c in pop1.cells for d in c.filter_secs("dend")]) syn_adder = connector.add_synapse("Exp2Syn") syn_adder.add_netcon(weight=weight_dist)
freq = 50 # freqs.append(10, 20, 40, 50) interval = 1000 / freq delta_t = 10 # LTP if __name__ == '__main__': cell = Ebner2019Cell(name="cell") filepath = os.path.join(path, "..", "commons/morphologies/asc/cell1.asc") cell.load_morpho(filepath=filepath) cell.make_default_mechanisms() soma = cell.filter_secs("soma") # Netstim to synapse stim = NetStimCell("stim").add_netstim(start=WARMUP, number=REPS, interval=interval) syn = cell.add_synapse(source=stim, netcon_weight=WEIGHT, mod_name="Syn4P", delay=1, seg=cell.filter_secs('apic[1]')(0.5)) # IClamp to soma iclamp = IClamp(segment=cell.filter_secs("soma")(0.5)) for i in range(REPS): start_t = WARMUP + delta_t + i * interval iclamp.stim(delay=start_t, dur=DUR, amp=AMP) # Record rec = Record([s(0.5) for s in cell.filter_secs("apic[1],apic[50]")])
from neuronpp.core.cells.netstim_cell import NetStimCell path = os.path.dirname(os.path.abspath(__file__)) model_path1 = os.path.join(path, "..", "commons/mods/ebner2019") model_path2 = os.path.join(path, "..", "commons/morphologies/swc/my.swc") # Prepare cell cell = Cell(name="cell", compile_paths=model_path1) cell.load_morpho(filepath=model_path2) cell.add_sec("dend[1]", diam=10, l=10, nseg=10) cell.connect_secs(source="dend[1]", target="soma") cell.insert("pas") cell.insert("hh") # Two examples of synapses with NetStim: stim_cell = NetStimCell("stim_cell") stim = stim_cell.make_netstim(start=250, number=30, interval=1) soma = cell.filter_secs("soma") # 1) Hoc-style synapse pp = cell.add_point_process(mod_name="ExpSyn", seg=soma(0.5)) cell.add_netcon(source=stim, point_process=pp, netcon_weight=0.01, delay=1) # 2) Recommended synapse syn1 = cell.add_synapse(source=stim, seg=soma(0.5), netcon_weight=0.01, mod_name="Syn4P", delay=1) # 3) Event synapse