def test_iclamp_after_sim(self): """ IClamp works in a regular way after simulation run. in this case (amplitude 3 pA) we have spike at the soma. However IClamp delay is in the absolute time. """ # Record rec = Record(self.soma(0.5)) # Run sim = Simulation(init_v=-70, warmup=20) sim.run(1) # IClamp to soma iclamp = IClamp(segment=self.soma(0.5)) iclamp.stim(delay=25, dur=3, amp=3) sim.run(100) r = rec.as_numpy(variable="v") sim.remove_immediate_from_neuron() rec.remove_immediate_from_neuron() iclamp.remove_immediate_from_neuron() # Make assertions self.assertEqual(4051, r.size) self.assertEqual(34.3815, round(r.records.max(), 4)) self.assertEqual(-75.3247, round(r.records.min(), 4)) self.assertEqual(330, r.records.argmax()) # time in ms of max mV value self.assertEqual(28, round(r.time[r.records.argmax()], 4))
def test_netcon_event_after_sim(self): syn = self.cell.add_synapse(source=None, 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) syn.make_event(50) sim.run(100) r = rec.as_numpy(variable="v") syn.remove_immediate_from_neuron() sim.remove_immediate_from_neuron() rec.remove_immediate_from_neuron() # Make assertions self.assertEqual(4051, r.size) self.assertEqual(34.4582, round(r.records.max(), 4)) self.assertEqual(-75.3478, round(r.records.min(), 4)) self.assertEqual(2159, r.records.argmax()) # time in ms of max mV value self.assertEqual(73.725, round(r.time[r.records.argmax()], 4))
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 prepare_da_cells(self, reward_cell, punish_cell): # make records for DA cells self.reward_cell = reward_cell self.punish_cell = punish_cell reward_soma = reward_cell.filter_secs("soma") punish_soma = punish_cell.filter_secs("soma") self.recs_rew_gs = [] for s in self.reward_cell.syns: r = Record(s.point_process, variables="g") self.recs_rew_gs.append(r) self.recs_pun_gs = [] for s in self.punish_cell.syns: r = Record(s.point_process, variables="g") self.recs_pun_gs.append(r) self.rec_v_rew = Record(reward_soma(0.5), variables="v") self.rec_v_pun = Record(punish_soma(0.5), variables="v") reward_syn = reward_cell.add_synapse(source=None, mod_name="ExpSyn", seg=reward_soma(0.5), netcon_weight=0.01, e=0, tau=1) punish_syn = punish_cell.add_synapse(source=None, mod_name="ExpSyn", seg=punish_soma(0.5), netcon_weight=0.01, e=0, tau=1) return reward_syn, punish_syn
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 test_add_netcon_and_make_event_separately(self): g1 = self.cell.filter_synaptic_group(mod_name="Exp2Syn", tag="aa") nc = g1.add_netcon(source=None) exp2syn_rec = Record(g1['Exp2Syn'][0], variables='i') expsyn_rec = Record(g1['ExpSyn'][0], variables='i') sim = Simulation() sim.run(1) nc['Exp2Syn'][0].make_event(10) nc['ExpSyn'][0].make_event(20) sim.run(100) exp2syn_np = exp2syn_rec.as_numpy('i') stim_time_exp2syn = exp2syn_np.time[(exp2syn_np.records != 0).argmax()] expsyn_np = expsyn_rec.as_numpy('i') stim_time_expsyn = expsyn_np.time[(expsyn_np.records != 0).argmax()] self.assertEqual(12.05, round(stim_time_exp2syn, 4)) self.assertEqual(22.025, round(stim_time_expsyn, 4)) # Remove variables and clear NEURON nc['Exp2Syn'][0].remove_immediate_from_neuron() nc['ExpSyn'][0].remove_immediate_from_neuron() nc = {} g1.remove_immediate_from_neuron() exp2syn_rec.remove_immediate_from_neuron() expsyn_rec.remove_immediate_from_neuron() sim.remove_immediate_from_neuron()
def test_record_before_sim(self): """ Record created before simulation run is full of data """ # Record rec = Record(self.soma(0.5)) # IClamp to soma iclamp = IClamp(segment=self.soma(0.5)) iclamp.stim(delay=25, dur=3, amp=3) # Run sim = Simulation(init_v=-70, warmup=20) sim.run(1) print(h.t) sim.run(100) r = rec.as_numpy(variable="v") # Make assertions self.assertEqual(4051, r.size) self.assertEqual(34.3815, round(r.records.max(), 4)) self.assertEqual(-75.3247, round(r.records.min(), 4)) self.assertEqual(330, r.records.argmax()) # time in ms of max mV value self.assertEqual(28, round(r.time[r.records.argmax()], 4))
def prepare_input_cells(self, input_cells): self.rec_inps = [] for c in input_cells: rec_gs = [] for s in c.syns: r = Record(s.point_process, variables="g") rec_gs.append(r) rec_v = Record(c.filter_secs("soma")(0.5), variables="v") self.rec_inps.append((rec_v, rec_gs))
def setUpClass(cls): morpho_path = os.path.join(path, "..", "commons/morphologies/asc/cell2.asc") # Create cell cell = Cell(name="cell") cell.load_morpho(filepath=morpho_path) cell.insert("pas") cell.insert("hh") soma = cell.filter_secs("soma") dend = cell.filter_secs("apic[10]") syn = cell.add_synapse(source=None, mod_name="ExpSyn", seg=dend(0.5)) # Prepare EPSP and AP (IClamp) protocols experiment = Experiment(iti=40) experiment.add_epsp(num=3, synapse=syn, init=20, interval=20, weight=0.02) experiment.add_iclamp(num=3, segment=soma(0.5), init=60, interval=20, dur=3, amp=1.6) experiment.build() # Prepare plots rec = Record([soma(0.5), dend(0.5)], variables='v') # Run sim = Simulation(init_v=-70, warmup=20, with_neuron_gui=False, constant_timestep=True) sim.run(runtime=100) cls.v_soma = rec.as_numpy('v', segment_name=soma(.5).name) cls.v_apic = rec.as_numpy('v', segment_name=dend(.5).name) syn.remove_immediate_from_neuron() soma.remove_immediate_from_neuron() dend.remove_immediate_from_neuron() rec.remove_immediate_from_neuron() experiment.remove_immediate_from_neuron() cell.remove_immediate_from_neuron() sim.remove_immediate_from_neuron() cls.sections_left = len(list(h.allsec()))
def test_timestep_constant(self): rec = Record(self.soma(0.5)) sim = Simulation(constant_timestep=True, dt=1) sim.run(100) r1 = rec.as_numpy('v') sim = Simulation(constant_timestep=False, dt=1) sim.run(100) r2 = rec.as_numpy('v') sim = Simulation(constant_timestep=False, dt=10) sim.run(100) r3 = rec.as_numpy('v') sim = Simulation(constant_timestep=False, dt=0.0001) sim.run(100) r4 = rec.as_numpy('v') sim.remove_immediate_from_neuron() rec.remove_immediate_from_neuron() self.assertEqual(101, r1.size) self.assertEqual(188, r2.size) self.assertEqual(180, r3.size) self.assertEqual(189, r4.size)
def add_seg(self, seg: Seg, sec_variables='v'): if not isinstance(seg, Seg): raise TypeError( "Param 'seg' must be of type Seg, but provided '%s'" % seg.__class__) rec = Record(elements=seg, variables=sec_variables) self.sec_recs.append(rec)
def record(self, sec_name="soma", loc=0.5, variable='v'): d = [ cell.filter_secs(sec_name, as_list=True)[0](loc) for cell in self.cells ] rec = Record(d, variables=variable) self.recs[variable] = rec
def run_and_get_rec(): rec = Record(self.soma(0.5)) iclamp = IClamp(segment=self.soma(0.5)) iclamp.stim(delay=25, dur=3, amp=3) sim = Simulation(init_v=-70, warmup=20) sim.run(100) return rec
def test_warmup(self): rec = Record(self.soma(0.5)) value_error = False try: sim = Simulation(warmup=-100) sim.run(100) r1 = rec.as_numpy('v') except ValueError: value_error = True self.assertTrue(value_error) sim = Simulation(warmup=100, dt=1) sim.run(100) r2 = rec.as_numpy('v') sim = Simulation(warmup=100, dt=1, warmup_dt=1) sim.run(100) r3 = rec.as_numpy('v') sim.remove_immediate_from_neuron() rec.remove_immediate_from_neuron() self.assertEqual(111, r2.size) self.assertEqual(201, r3.size)
def test_record_after_sim(self): """ record created after simulation run is empty """ # IClamp to soma iclamp = IClamp(segment=self.soma(0.5)) iclamp.stim(delay=25, dur=3, amp=3) # Run sim = Simulation(init_v=-70, warmup=20) sim.run(1) print(h.t) # Record rec = Record(self.soma(0.5)) sim.run(100) r = rec.as_numpy(variable="v") # Make assertion self.assertEqual(0, r.size)
def add_syn(self, syn: Synapse, syn_variables=None, key_press=None, plot=True): if not isinstance(syn, Synapse): raise TypeError( "Param 'syn' must be of type Synapse, but provided '%s'" % syn.__class__) if plot and syn_variables: rec = Record(elements=syn, variables=syn_variables) self.syn_recs.append(rec) name = key_press if name is None: name = str(len(self.syns)) self.syns[name].append(syn)
def get_cell_with_iclamps_as_synapses(warmup, dur, name, input_size, low=0.08, high=0.1): # Create cell cell = Cell(name=name) soma = cell.add_sec("soma", diam=10, l=10, nseg=5) dend = cell.add_sec("dend", diam=5, l=100, nseg=50) cell.connect_secs(child=dend, parent=soma) cell.insert("hh") # Make synapses iclamp_syns = [] for i in range(input_size): iclamp = IClamp(segment=dend(np.random.rand())) syn = iclamp.stim(delay=warmup, dur=dur, amp=UniformDist(low=low, high=high)) iclamp_syns.append(syn) # Make recording rec = Record(elements=soma(0.5), variables='v') cell.make_spike_detector(seg=soma(0.5)) return cell, iclamp_syns, rec
def test_init_v(self): rec = Record(self.soma(0.5)) sim = Simulation(init_v=-100) sim.run(100) r1 = rec.as_numpy('v') sim = Simulation(init_v=100) sim.run(100) r2 = rec.as_numpy('v') sim.remove_immediate_from_neuron() rec.remove_immediate_from_neuron() self.assertEqual(-100, r1.records[0]) self.assertEqual(100, r2.records[0])
def test_dt(self): rec = Record(self.soma(0.5)) sim = Simulation(dt=10) sim.run(100) r1 = rec.as_numpy('v') sim = Simulation(dt=0.01) sim.run(100) r2 = rec.as_numpy('v') sim.remove_immediate_from_neuron() rec.remove_immediate_from_neuron() self.assertEqual(11, r1.size) self.assertEqual(10001, r2.size)
from neuronpp.utils.record import Record from neuronpp.utils.simulation import Simulation path = os.path.dirname(os.path.abspath(__file__)) if __name__ == '__main__': # Prepare cell filepath = os.path.join(path, "..", "commons/mods/sigma3syn") cell = Cell("cell", compile_paths=filepath) soma = cell.add_sec("soma", diam=20, l=20, nseg=10) cell.insert('pas') cell.insert('hh') w = 0.003 # LTP #w = 0.0022 # LTD syn = cell.add_synapse(source=None, netcon_weight=w, seg=soma(0.5), mod_name="ExcSigma3Exp2Syn") # prepare plots and spike detector rec_v = Record(soma(0.5), variables="v") rec_w = Record(syn, variables="w") # run sim = Simulation(init_v=-68, warmup=5) syn.make_event(5) sim.run(runtime=50) # plot rec_w.plot() rec_v.plot()
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') # make plots rec_w = Record(cell.filter_point_processes(mod_name="Syn4P", name="head[0]"), variables="w") rec_v = Record(cell.filter_secs(name="head[0]")(1.0), variables="v") # init and run sim = Simulation(init_v=-70, warmup=WARMUP) sim.run(runtime=500) # plot rec_w.plot() rec_v.plot()
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 rec_v = Record(soma(0.5), variables="v") cell.make_spike_detector(soma(0.5)) # run sim = Simulation(init_v=-65, warmup=20, init_sleep=2, with_neuron_gui=True, shape_plots=[make_shape_plot()]) sim.run(runtime=200, stepsize=1, delay_between_steps=500) # plot cell.plot_spikes() rec_v.plot() plt.show()
# 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 cell.make_default_mechanisms() cell.make_apical_mechanisms(sections='head neck') # make plots rec_4psyn = Record(cell.filter_point_processes(mod_name="Syn4PAChDa", name="head[0]"), variables="w") # init and run sim = Simulation(init_v=-70, warmup=WARMUP) sim.run(runtime=200) # Event delivery syns_4p[0].make_event(10) sim.run(runtime=200) # plot rec_4psyn.plot()
def test_stim_syns(self): gs = self.cell.filter_synaptic_group() gs0_exp2syn_rec = Record(gs[0]['Exp2Syn'][0], variables='i') gs0_expsyn_rec = Record(gs[0]['ExpSyn'][0], variables='i') gs1_exp2syn_rec = Record(gs[1]['Exp2Syn'][0], variables='i') gs1_expsyn_rec = Record(gs[1]['ExpSyn'][0], variables='i') sim = Simulation() sim.run(1) gs[0].make_event(10) gs[1].make_event(20) sim.run(100) # Test stim time of synaptic group 1 gs0_exp2syn_np = gs0_exp2syn_rec.as_numpy('i') stim_time_gs0_exp2syn = gs0_exp2syn_np.time[(gs0_exp2syn_np.records != 0).argmax()] gs0_expsyn_np = gs0_expsyn_rec.as_numpy('i') stim_time_gs0_expsyn = gs0_expsyn_np.time[(gs0_expsyn_np.records != 0).argmax()] self.assertEqual(round(stim_time_gs0_exp2syn, 1), round(stim_time_gs0_expsyn, 1)) # Test stim time of synaptic group 2 gs1_exp2syn_np = gs1_exp2syn_rec.as_numpy('i') stim_time_gs1_exp2syn = gs1_exp2syn_np.time[(gs1_exp2syn_np.records != 0).argmax()] gs1_expsyn_np = gs1_expsyn_rec.as_numpy('i') stim_time_gs1_expsyn = gs1_expsyn_np.time[(gs1_expsyn_np.records != 0).argmax()] self.assertEqual(round(stim_time_gs1_exp2syn, 1), round(stim_time_gs1_expsyn, 1)) # Test values of mV in soma self.assertEqual(31.3285, round(gs0_exp2syn_np.records.max(), 4)) self.assertEqual(-61.309, round(gs0_exp2syn_np.records.min(), 4)) # Remove variables and clear NEURON gs0_exp2syn_rec.remove_immediate_from_neuron() gs0_expsyn_rec.remove_immediate_from_neuron() gs1_exp2syn_rec.remove_immediate_from_neuron() gs1_expsyn_rec.remove_immediate_from_neuron() gs[0].remove_immediate_from_neuron() gs[1].remove_immediate_from_neuron() sim.remove_immediate_from_neuron()
cell.insert("hh") soma = cell.filter_secs("soma") dend = cell.filter_secs("apic[10]") syn = cell.add_synapse(source=None, mod_name="ExpSyn", seg=dend(0.5)) # Prepare EPSP and AP (IClamp) protocols experiment = Experiment(iti=40) experiment.add_epsp(num=3, synapse=syn, init=20, interval=20, weight=0.02) experiment.add_iclamp(num=3, segment=soma(0.5), init=60, interval=20, dur=3, amp=1.6) experiment.build() # Prepare plots rec = Record([soma(0.5), dend(0.5)], variables='v') # Run sim = Simulation(init_v=-70, warmup=20, with_neuron_gui=False, constant_timestep=True) sim.run(runtime=100) rec.plot() v_soma = rec.as_numpy('v', segment_name=soma(.5).name) v_dend = rec.as_numpy('v', segment_name=dend(.5).name)
spine_number=10, spine_secs_names="apic", spine_seed=13) soma = cell.filter_secs("soma") syns = cell.filter_complex_synapses(tag="combe") # Prepare STDP protocol stdp = Experiment() stdp.make_protocol("3xEPSP[int=10] 3xAP[int=10,dur=3,amp=1.6]", start=1, isi=10, epsp_synapse=syns[0], i_clamp_section=soma) # Prepare plots v_soma_rec = Record([soma(0.5), syns[0].parent], variables='v') cai_head0_rec = Record(syns[0].parent, variables='cai') # Run sim = Simulation(init_v=-70, warmup=20, with_neuron_gui=True, constant_timestep=False) sim.run(runtime=100, debug=True) # Plot cai_head0_rec.plot() v_soma_rec.plot() v_soma_rec.to_csv("vrec.csv")
netcon_weight=0.1, delay=1) cell.set_synaptic_pointers(s, syn_ach, syn_da) cell.group_synapses(tag="input_syn", synapses=[s, syn_ach, syn_da]) # add mechanisms cell.make_default_mechanisms() cell.make_apical_mechanisms(sections='dend head neck') soma = cell.filter_secs("soma") syns = cell.filter_synaptic_group() syn4p = syns[0]['Syn4PAChDa'] synach = syns[0]['SynACh'] rec_syn = Record(syn4p, variables="w stdp_ach ach_stdp ACh ACh_w") rec_soma = Record(soma(0.5), variables="v") sim = Simulation(init_v=-80, warmup=WARMUP, warmup_on_create=True) event = 0 inter = 5 for i in range(10): for syn in syns: syn['Syn4PAChDa'][0].make_event(event) syn['SynACh'][0].make_event(event) event += inter sim.run(runtime=150) # plot
# 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 syn2 = cell.add_synapse(source=None, seg=soma(0.5), netcon_weight=0.01, mod_name="Syn4P", delay=1) # prepare plots rec_v = Record(soma(0.5), variables="v") # run sim = Simulation(init_v=-55, warmup=20) # Making external events to the synapse syn2.make_event(10) syn2.make_event(20) syn2.make_event(30) syn2.make_event(40) # Example of online update of the graph, however sim.run(runtime=1000) can be call in a single run for i in range(1000): sim.run(runtime=1) rec_v.plot(animate=True)
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]")]) # Run sim = Simulation(init_v=-70, warmup=WARMUP, dt=DT) total_time = REPS * interval + COOL_DOWN sim.run(total_time) # Plot rec.plot(position="merge") plt.show()