def connect2target(self, target, thresh=10): """ Make a new :class:`NetCon` with this cell's membrane potential at the soma as the source (i.e. the spike detector) onto the target passed in (i.e. a synapse on a cell). Subclasses may override with other spike detectors. """ nc = nrn.NetCon(self.soma(1)._ref_v, target, sec = self.soma) nc.threshold = thresh return nc
def recorder(ce, vloc): izhm = ce.izh #record spikes spikerecorder = h.NetCon(izhm, None) spikerecorder.record(spikevec) # record V,u,Iin recvecs[0].record(h._ref_t) # Record simulation time recvecs[1].record(vloc) # Record cell voltage recvecs[2].record(izhm._ref_u) # Record cell recovery variable recvecs[3].record(izhm._ref_Iin) # input
def __init__(self, rate=1, tau_refrac=0.0, start=0, duration=0): self.rate = rate self.tau_refrac = tau_refrac self.start = start self.duration = duration self.spike_times = h.Vector(0) self.source = self self.rec = h.NetCon(self, None) self.source_section = None self.seed(state.mpi_rank + state.native_rng_baseseed)
def makeStimulus(soma, simTime): stimNc = h.NetStim() stimNc.noise = 1 stimNc.start = 0 stimNc.number = simTime stimNc.interval = 10 syn = h.ExpSyn(0.5, sec=soma) nc = h.NetCon(stimNc, syn) nc.weight[0] = 20 return (stimNc, syn, nc)
def connect2target( self, target, delay=1, weight=0.04 ): # { localobj nc #$o1 target point process, optional $o2 returned NetCon self.ncstim.append(h.NetCon(self.stim, target)) self.ncstim[-1].delay = delay # ms self.ncstim[-1].weight[0] = weight # NetCon weight is a vector return self.ncstim[-1]
def test_NetStim_noise(): # Can use noiseFromRandom use_noiseFromRandom123 = False cells = { gid: (h.NetStim(), h.Random()) for gid in range(pc.id(), 5, pc.nhost()) } for gid, cell in cells.items(): pc.set_gid2node(gid, pc.id()) pc.cell(gid, h.NetCon(cell[0], None)) cell[1].Random123(gid, 2, 3) cell[1].negexp(1) if use_noiseFromRandom123: cell[0].noiseFromRandom123(gid, 2, 3) else: cell[0].noiseFromRandom(cell[1]) cell[0].interval = gid + 1 cell[0].number = 100 cell[0].start = 0 cell[0].noise = 1 spiketime = h.Vector() spikegid = h.Vector() pc.spike_record(-1, spiketime, spikegid) pc.set_maxstep(10) tstop = 100 for cell in cells.values(): cell[1].seq(0) # only _ran_compat==2 initializes the streams h.finitialize() pc.psolve(tstop) spiketime_std = spiketime.c() spikegid_std = spikegid.c() print("spiketime_std.size %d" % spiketime_std.size()) spiketime.resize(0) spikegid.resize(0) from neuron import coreneuron h.CVode().cache_efficient(True) coreneuron.verbose = 0 coreneuron.enable = True for cell in cells.values(): cell[1].seq(0) h.finitialize() while h.t < tstop: h.continuerun(h.t + 5) pc.psolve(h.t + 5) print("spiketime.size %d" % spiketime.size()) assert spiketime.eq(spiketime_std) assert spikegid.eq(spikegid_std) pc.gid_clear()
def simulate(self, T, dt, v_init, S_e, S_i, I_inj=0, break_flag=False): """Run simulation and record voltage from every compartment. Parameters ---------- T : int total simulation time (ms) dt : float time step (ms) v_init : float initial voltage (mV) S_e, S_i : array_like presynaptic spike times for each E and I synapse I_inj : int injected current at soma (default 0) break_flag : bool interupt simulation at time of first spike (default False) Returns ------- t : ndarray time vector v : ndarray voltage vector """ h.dt = dt h.steps_per_ms = 1.0 / h.dt t_a, stim_a, self.ampa = self.create_stim(S_e, self.AMPA, self.w_1) t_n, stim_n, self.nmda = self.create_stim(S_e, self.NMDA, self.w_2) t_g, stim_g, self.gaba = self.create_stim(S_i, self.GABA, self.w_3) t = h.Vector() t.record(h._ref_t, dt) v = [] for sec in self.tree: for k in range(sec.nseg): v_temp = h.Vector() v_temp.record(sec((k + 1 / 2) / sec.nseg)._ref_v, dt) v.append(v_temp) if np.abs(I_inj) > 0: stim = h.IClamp(0.5, sec=self.tree[0]) stim.dur = T - 150 stim.amp = I_inj stim.delay = 100 if break_flag: nc = h.NetCon(self.tree[0](0.5)._ref_v, None, sec=self.tree[0]) nc.threshold = 0 nc.record(self.halt) h.v_init = v_init h.tstop = T h.run() t = np.array(t) v = np.array(v) return t, v
def recv(thresh=35): global nrec spkt, spkid = h.Vector(len(nodl) + 10), h.Vector(len(nodl) + 10) ncl = [h.NetCon(sec(0.5)._ref_v, None, sec=sec) for sec in nodl] for nc in ncl: nc.threshold = thresh nrec = [h.Vector(h.tstop / h.dt + 10) for x in range(len(nodl))] for i, nc in enumerate(ncl): nc.record(spkt, spkid, i) # netcon.record(tvec, idvec, id) for v, n in zip(nrec, nodl): v.record(n(0.5)._ref_v)
def connect_stim(self): """Connect a spike generator on the first cell in the network.""" #### If the first cell is not on this host, return if not self.pc.gid_exists(0): return self.stim = h.NetStim() self.stim.number = self.stim_spike_num self.stim.start = 9 self.ncstim = h.NetCon(self.stim, self.cells[0].synlist[0]) self.ncstim.delay = 1 self.ncstim.weight[0] = self.stim_w # NetCon weight is a vector.
def main(var): global nc_w, nc_d setting = {'geometry': celldim(soma_d=12.6157, soma_l=12.6157, dend_d=1, dend_l=100, dend_seg=101), 'biophysics': cellbiophy(Ra=100, Cm=1, soma_hh_gnabar=0.12, soma_hh_gkbar=0.036, soma_hh_gl=0.0003, soma_hh_el=-54.3, dend_g=0.001, dend_e=-65)} N=3 var = np.float(var) deviation = lambda r: np.random.standard_normal(N)*r cell_settings = [] for i in range(N): set = {} set['geometry'] = celldim(soma_d=12.6157, soma_l=12.6157, dend_d=1, dend_l=100, dend_seg=101) set['biophysics'] = cellbiophy(Ra=100, Cm=1, soma_hh_gnabar=0.12 + 0.12*deviation(var)[i], soma_hh_gkbar=0.036 + 0.036*deviation(var)[i], soma_hh_gl= 0.0003 + 0.0003*deviation(var)[i], soma_hh_el=-54.3, dend_g=0.001, dend_e=-65) cell_settings.append(set) cells = [BallAndStick(settings) for settings in cell_settings] nclist = [] esyns = [] # Connect neuron in ring. for i in range(N): src = cells[i] tgt = cells[(i+1)%N] syn = h.ExpSyn(tgt.dend(0.5)) esyns.append(syn) nc = h.NetCon(src.soma(0.5)._ref_v, syn, sec=src.soma) nc.weight[0] = nc_w nc.delay = nc_d nclist.append(nc) # Create AlphaSynapse for init network syn = h.AlphaSynapse(cells[0].dend(0.5)) syn.gmax = 0.1 syn.tau = 1 syn.onset = 20 syn.e = 0 # Create output tables t_vec = h.Vector() soma1_vec = h.Vector() soma2_vec = h.Vector() soma3_vec = h.Vector() t_vec.record(h._ref_t) soma1_vec.record(cells[0].soma(0.5)._ref_v) soma2_vec.record(cells[1].soma(0.5)._ref_v) soma3_vec.record(cells[2].soma(0.5)._ref_v) # Run simulation h.tstop = 50 h.run() # plot results plt.plot(t_vec, soma1_vec, t_vec, soma2_vec, t_vec, soma3_vec)
def add_AMPAsyns(model, locs=[[0, 0.5]], gmax=0.5, tau1=0.5, tau2=1): model.AMPAlist = [] model.ncAMPAlist = [] gmax = gmax / 1000. # Set in nS and convert to muS for loc in locs: AMPA = h.Exp2Syn(float(loc[1]), sec=model.dends[int(loc[0])]) AMPA.tau1 = tau1 AMPA.tau2 = tau2 NC = h.NetCon(h.nil, AMPA, 0, 0, gmax) model.AMPAlist.append(AMPA) model.ncAMPAlist.append(NC)
def add_stimulation(self, label, start, interval, weight): stim = h.NetStim(0.5, sec=self.section) stim.noise = 0 stim.start = start stim.interval = interval stim.number = 1e12 delay = 1.0 nc = h.NetCon(stim, self.cell, 0.5, delay, weight) assert nc.weight[0] == weight nc.weight[1] = SYN_TYPES[label] self.stimuli[label] = (stim, nc)
def add_AMPA_NMDA_synapse(num_of_synapses): del SynList[:] del ConList[:] for j in range(num_of_synapses): SynList.append(h.Exp2Syn(SPINE_HEAD_X, sec=cell.spine[(j * 2) + 1])) ConList.append(h.NetCon(Stim1, SynList[-1])) SynList[-1].e = E_SYN SynList[-1].tau1 = TAU_1 SynList[-1].tau2 = TAU_2 ConList[-1].weight[0] = AMPA_W ConList[-1].delay = 0 SynList.append(h.NMDA(SPINE_HEAD_X, sec=cell.spine[(j * 2) + 1])) ConList.append(h.NetCon(Stim1, SynList[-1])) SynList[-1].e = E_SYN SynList[-1].tau_r_NMDA = TAU_1_NMDA SynList[-1].tau_d_NMDA = TAU_2_NMDA SynList[-1].n_NMDA = N_NMDA SynList[-1].gama_NMDA = GAMA_NMDA ConList[-1].weight[0] = NMDA_W ConList[-1].delay = 0
def setup_recording(self): self.times = h.Vector() self.times.record(h._ref_t) self.traces = {} for state_variable in self.component.state_variables: hoc_var = getattr(self.cell, "_ref_%s" % state_variable.name) self.traces[state_variable.name] = h.Vector() self.traces[state_variable.name].record(hoc_var) self.spike_times = h.Vector() self.source = h.NetCon(self.cell, None) self.source.record(self.spike_times)
def connect_pre(self, syn, wt, dly): # This function attaches my axon (or other generator of APs), to the synapse # that's passed to me from another cell. # The section of the cell that is going to be the AP generator has to be the # currectly accessed section, so do that... self.celltype.getSoma(self).push() nc = h.NetCon(self.celltype.getSoma(self)(1)._ref_v, syn, 0, dly, wt) self.nc_list.append(nc) h.pop_section() return nc
def mkstim(): ''' stimulate gid 0 with NetStim to start ring ''' global stim, ncstim if not pc.gid_exists(0): return stim = h.NetStim() stim.number = 1 stim.start = 0 ncstim = h.NetCon(stim, pc.gid2cell(0).synlist[0]) ncstim.delay = 0 ncstim.weight[0] = 0.01
def add_spike(self, t, weight, target=0): stim = h.NetStim() stim.number = 1 stim.start = 0 nc = h.NetCon(stim, self.synapses[target]) nc.delay = t nc.weight[0] = weight self.stims.append(stim) self.netcons.append(nc)
def _connect_ees_to_fibers(self): """ Connect fibers ojects to ees objects to make the stimulation activate these fibers. """ for i in range(len(self._eesFrequencies)): for j in range(len(self._fiberDelays)): for k in range(len(self._fiberFiringRates)): self._netconList[i][j].append( h.NetCon(self._eesList[i], self._fiberList[i][j][k].cell)) self._netconList[i][j][k].delay = 1 self._netconList[i][j][k].weight[ 0] = AfferentFiber.get_ees_weight()
def setup_source_netcon(self, threshold): """Created for _PC.cell and specifies SOURCES of spikes. Parameters ---------- threshold : float The voltage threshold for action potential. """ nc = h.NetCon(self.soma(0.5)._ref_v, None, sec=self.soma) nc.threshold = threshold return nc
def connect2target( self, target, delay=1, weight=0.04 ): # { localobj nc #$o1 target point process, optional $o2 returned NetCon self.nc.append(h.NetCon(self.soma(0.5)._ref_v, target, sec=self.soma)) self.nc[-1].threshold = -10 # mV self.nc[-1].delay = delay # ms self.nc[-1].weight[0] = weight # NetCon weight is a vector return self.nc[-1]
def __init__(self, event_times): # Convert event times into nrn vector self.nrn_eventvec = h.Vector() self.nrn_eventvec.from_python(event_times) # load eventvec into VecStim object self.nrn_vecstim = h.VecStim() self.nrn_vecstim.play(self.nrn_eventvec) # create the cell and artificial NetCon self.nrn_netcon = h.NetCon(self.nrn_vecstim, None)
def makeStimulus( soma, simTime ): interval = 25 stimNc = h.NetStim() stimNc.noise = 1 stimNc.start = ceil(25*rand(1,1)) stimNc.number = simTime stimNc.interval = interval syn = h.ExpSyn (0.5, sec = soma) nc = h.NetCon(stimNc, syn) nc.weight[0] = 20 return (stimNc, syn, nc)
def makeStimulus( soma, simTime,NCstrengthStim ): interval = 25 stimNc = h.NetStim() stimNc.noise = 1 stimNc.start = 0 stimNc.number = simTime stimNc.interval = interval syn = h.ExpSyn (0.5, sec = soma) nc = h.NetCon(stimNc, syn) nc.weight[0] = NCstrengthStim return (stimNc, syn, nc)
def test_5(): # NetStim (with no gid) stimulates intrinsically firing IntFire2 # which stimulates a soma with ExpSyn gids = range(pc.id(), 1, pc.nhost()) cells = {} for gid in gids: cells[gid] = h.IntFire2() cell = cells[gid] cell.ib = 2 cell.taus = 2 cell.taum = 1 pc.set_gid2node(gid, pc.id()) pc.cell(gid, h.NetCon(cell, None)) if pc.gid_exists(0): ns = h.NetStim() nc = h.NetCon(ns, cells[0]) ns.interval = 1 ns.start = 0.2 nc.weight[0] = 0.01 spiketimes = h.Vector() spikegids = h.Vector() pc.spike_record(-1, spiketimes, spikegids) tstop = 10 run2(tstop) spiketimes_std = spiketimes.c() spikegids_std = spikegids.c() run2(tstop, mode="save_test") cmpspikes2(0.0, spiketimes, spikegids, spiketimes_std, spikegids_std) run2(tstop, mode="restore_test") cmpspikes2(tstop / 2.0, spiketimes, spikegids, spiketimes_std, spikegids_std) for i, t in enumerate(spiketimes): print(t, spikegids[i]) pc.gid_clear()
def connect2target(self, target, thresh=-10): nc = h.NetCon(self.pp, target) nc.threshold = thresh #self.spike_times = [] #vecrecs = [] #vecrecs.append(h.Vector()) #nc.record(vecrecs[0]) #self.nclist.append(nc) #self.spike_times.append(vecrecs[0]) return nc
def setSpikeTrain(self, syn_index, syn_weight, spike_times): # add spiketrain spks = np.array(spike_times) + self.t_calibrate spks_vec = h.Vector(spks.tolist()) vecstim = h.VecStim() vecstim.play(spks_vec) netcon = h.NetCon(vecstim, self.syns[syn_index], 0, self.dt, syn_weight) # store the objects self.vecs.append(spks_vec) self.vecstims.append(vecstim) self.netcons.append(netcon)
def __init__(self, start=0, _interval=1e12, duration=0): self.start = start self.interval = _interval self.duration = duration self.noise = 1 self.spike_times = h.Vector(0) self.source = self self.switch = h.NetCon(None, self) self.source_section = None self.seed( state.mpi_rank + state.native_rng_baseseed ) # should allow user to set specific seeds somewhere, e.g. in setup()
def err_test1(): r = Ring(3, 2) expect_err("pc.set_gid2node(0, pc.id())") nc = pc.gid_connect(10000, r.cells[0].syn) expect_err("pc.set_gid2node(10000, pc.id())") expect_err("pc.threshold(10000)") expect_err("pc.cell(10000)") expect_err("pc.cell(99999)") expect_err("pc.cell(0, None)") expect_err("pc.gid_connect(0, None)") pc.set_gid2node(99999, pc.id()) expect_err("pc.gid_connect(99999, r.cells[0].syn)") expect_err("pc.gid_connect(1, r.cells[0].syn, h.Vector())") nc = h.NetCon(None, r.cells[1].syn) expect_err("pc.gid_connect(1, r.cells[0].syn, nc)") nc = h.NetCon(None, r.cells[0].syn) pc.gid_connect(1, r.cells[0].syn, nc) pc.gid_clear() del nc, r locals()
def connect_to_target(self, target, weight: float = 0, delay: float = 0, node_n: int = -1, **kwargs) -> h.NetCon: nc = h.NetCon(self.node[node_n](1)._ref_v, target, sec=self.node[node_n]) nc.threshold = -30 nc.delay = delay return nc
def mkstim(self): if not settings.pc.gid_exists(self.gidstart): return self.stim = h.NetStim() self.stim.number = 1 self.stim.start = 0 ncstim = h.NetCon(self.stim, settings.pc.gid2cell(self.gidstart).synlist[0]) ncstim.delay = 1 ncstim.weight[0] = 0.01 self.nclist.append(ncstim)