def test_stimulate(self): from patch import p, connection from random import random s1 = p.Section() s2 = p.Section() s3 = p.Section() se = p.PointProcess(p.ExpSyn, s1) se2 = p.PointProcess(p.ExpSyn, s2) se3 = p.PointProcess(p.ExpSyn, s3) ns = se.stimulate(start=1, number=3, interval=1) vs = se2.stimulate(pattern=[1, 2, 3]) vs2 = se3.stimulate(pattern=[random() * 2, random() + 2, random() * 2 + 3]) rs1 = s1.record() rs2 = s2.record() rs3 = s3.record() t = p.time from neuron import h p.finitialize() p.continuerun(10) self.assertGreater( max(list(rs1)), min(list(rs1)), "Flatline where stimulation was expected." ) for ns_y, vs_y in zip(rs1, rs2): self.assertAlmostEqual(ns_y, vs_y, delta=1e-6) equal = True for vs_y, vs2_y in zip(rs2, rs3): equal = abs(vs2_y - vs_y) < 1e-6 if not equal: break equal = False self.assertFalse(equal, "Random and periodic VecStim yielded identical results.")
def test_netcon_record(self): s1 = p.Section() se = p.ExpSyn(s1) ns = se.stimulate(start=1, number=3, interval=1, weight=100) r = s1.record() s2 = p.Section() r2 = s2.record() syn = p.ExpSyn(s2) nc = s1.connect_points(syn) v = p.Vector() t = p.time nc.record(v) v2 = nc.record() v3 = nc.record() p.finitialize() p.continuerun(10) self.assertEqual(v, v2, "NetCon recorder should be a singleton.") self.assertEqual(v2, v3, "NetCon recorder should be a singleton.") self.assertNotEqual(len(v), 0, "NetCon recorder should record a spike.") self.assertEqual( len(v), len(v2), "Different NetCon recorders should record same spikes.")
def test_stimulate(self): s = p.Section() pp = p.ExpSyn(s(0.5)) stim = pp.stimulate(start=0, number=1) stim._connections[pp].weight[0] = 0.4 r = s.record() p.finitialize(-70) p.continuerun(10) self.assertAlmostEqual(list(r)[-1], -68.0, delta=0.1)
def run_protocol(cell, duration=100): disable_cvode() init_simulator(tstop=duration) _vm = cell.record_soma() _time = p.time p.finitialize() p.run() return ezfel(T=list(_time), V=list(_vm))
def run_protocol(cell, duration=100): disable_cvode() init_simulator(tstop=duration) _vm = cell.record_soma() _time = p.time p.finitialize() p.run() # Create a build artifact VoltageTrace(cell, "Autorhythm", _time, _vm, duration=duration) return ezfel(T=list(_time), V=list(_vm))
def quick_test(*models, duration=300, temperature=32, v_init=-65): from patch import p p.time p.celsius = temperature p.v_init = v_init for model in models: model.record_soma() p.finitialize(v_init) p.continuerun(duration) return list(p.time), [{ "Vm": list(model.Vm), "model": model.__class__.__name__ } for model in models]
def _test_synapse_multiplicity(self, name, synapse_factory, finit=-65): from patch import p section_single = p.Section() section_single.record() section_multi = p.Section() section_multi.record() synapse_single = synapse_factory(section_single) synapse_multi_1 = synapse_factory(section_multi) synapse_multi_2 = synapse_factory(section_multi) for s in [synapse_multi_1, synapse_single, synapse_single]: s.stimulate(delay=0, number=4, interval=25, weight=1) p.finitialize(finit) p.continuerun(150)
def quick_test(model, duration=300, temperature=32, v_init=-65): from patch import p p.time p.celsius = temperature p.v_init = v_init model.record_soma() p.finitialize(v_init) p.continuerun(duration) from plotly import graph_objs as go go.Figure( go.Scatter(x=list(p.time), y=list(model.Vm), name=model.__class__.__name__)).show()
def test_iclamp(self): s0 = p.Section() s0.record() s1 = p.Section() s1.record() s2 = p.Section() s2.record() s3 = p.Section() s3.record() s4 = p.Section() s4.record() p.time s1.iclamp(amplitude=10, delay=5) c = p.IClamp(sec=s2) c.amp = 10 c.dur = 10 c2 = s3.iclamp(amplitude=10) s4.iclamp(amplitude=[-10 for _ in range(int(10 / p.dt))]) p.finitialize() p.continuerun(10) self.assertGreater( max(s1.recordings[0.5]), max(s0.recordings[0.5]), "No injected current detected", ) self.assertGreater( max(s2.recordings[0.5]), max(s0.recordings[0.5]), "No injected current detected", ) self.assertGreater( max(s3.recordings[0.5]), max(s0.recordings[0.5]), "No injected current detected", ) self.assertGreater( max(s3.recordings[0.5]), max(s1.recordings[0.5]), "Half of injected charge not smaller than full charge", ) self.assertGreater( min(s0.recordings[0.5]), min(s4.recordings[0.5]), "No negative injected current detected", )
def simulate(self, simulator): from plotly import graph_objects as go from plotly.subplots import make_subplots pc = simulator.parallel self.pc = pc pc.barrier() report("Simulating...", level=2) pc.set_maxstep(10) simulator.finitialize(self.initial) progression = 0 while progression < self.duration: progression += 1 pc.psolve(progression) pc.barrier() self.progress(progression, self.duration) if os.path.exists("interrupt_neuron"): report("Iterrupt requested. Stopping simulation.", level=1) break report("Finished simulation.", level=2)
def run_protocol(cell, amplitude=0.01): disable_cvode() init_simulator(tstop=200) stim = p.IClamp(0.5, sec=cell.soma[0].__neuron__()) stim.delay = 0 stim.dur = 200 stim.amp = amplitude # 10pA, or 16 or 22pA _vm = cell.record_soma() _time = p.time p.finitialize() p.run() return ezfel(T=list(_time), V=list(_vm), stim_start=stim.delay, stim_end=stim.delay + stim.dur)
def run_protocol(cell, *synapses, duration=500, start=200, interval=10, number=10): disable_cvode() init_simulator(tstop=duration) _vm = cell.record_soma() _time = p.time for syn_spec in synapses: t = syn_spec["type"] n = syn_spec["number"] loc = syn_spec["location"] syn = [loc(cell.sections, i) for i in range(n)] for s in syn: s.stimulate(start=start, interval=interval, number=number) p.finitialize() p.run() I = list(list(i) for i in synaptic_currents) # Create a build artifact SynapticCurrentTrace(cell, "SynchronousSynapseActivation", _time, I=I, vm=_vm, duration=duration, spike_interval=interval, spike_number=number, spike_start=start, synapses=synapses) return ezfel(T=list(_time), V=list(_vm), I=I)
def run_protocol(cell, amplitude=0.01): disable_cvode() init_simulator(tstop=200) stim = p.IClamp(0.5, sec=cell.soma[0].__neuron__()) stim.delay = 0 stim.dur = 200 stim.amp = amplitude # 10pA, or 16 or 22pA _vm = cell.record_soma() _time = p.time p.finitialize() p.run() # Create a build artifact VoltageTrace(cell, "Current injection", _time, _vm, amplitude=amplitude) return ezfel(T=list(_time), V=list(_vm), stim_start=stim.delay, stim_end=stim.delay + stim.dur)