def test_netcon_inter(self):
        from neuron import h

        s1 = h.NetStim()
        s2 = h.NetStim()
        s3 = p.NetStim()
        s4 = p.NetStim()
        # Test that only Python objects that play by the rules can be connected.
        self.assertRaises(NotConnectableError, p.NetCon, s1, s2)
        self.assertRaises(NotConnectableError, p.NetCon, s3, s2)
        self.assertRaises(NotConnectableError, p.NetCon, s1, s4)
        self.assertEqual(patch.objects.NetCon, type(p.NetCon(s3, s4)),
                         "Valid NetCon failed")
Beispiel #2
0
def get_netstim(start, number, interval, noise):
    stim = h.NetStim()
    stim.start = start
    stim.number = number
    stim.interval = interval
    stim.noise = noise
    return stim
Beispiel #3
0
def makeNoiseNetStim(cel, nsl, ncl, nrl, nrlsead, syn, w, ISI, time_limit,
                     sead):
    rd2 = h.Random()
    rd2.ACG(sead)
    rd2.uniform(0, 1e3)
    ns = h.NetStim()
    ns.interval = ISI
    ns.noise = 1
    ns.number = 2 * time_limit / ISI  # create enough spikes for extra time, in case goes over limit
    ns.start = 0  # tstart
    if type(syn) == str: nc = h.NetCon(ns, cel.__dict__[syn].syn)
    else: nc = h.NetCon(ns, syn)
    nc.delay = h.dt * 2  # 0
    nc.weight[0] = w
    rds = h.Random()
    rds.negexp(
        1)  # set random # generator using negexp(1) - avg interval in NetStim
    rds.MCellRan4(sead, sead)  # seeds are in order, shouldn't matter
    ns.noiseFromRandom(rds)  # use random # generator for this NetStim
    ns.start = 0.  # rd2.repick() # start inputs random time btwn 0-1e3 ms to avoid artificial sync
    nsl.append(ns)
    ncl.append(nc)
    nrl.append(rds)
    nrlsead.append(sead)
    cel.infod[syn] = [
        ns, nc
    ]  #store pointers to NetStim,NetCon for easier manipulation
Beispiel #4
0
def Add_NMDA_SingleSynapticEventToSegment(segment, activationTime,
                                          synapseWeight, exc_inh):

    if exc_inh == 0:  # inhibitory
        synapse = h.ProbGABAAB_EMS(segment)  #GABAA/B
        synapse.tau_r_GABAA = 0.2
        synapse.tau_d_GABAA = 8
        synapse.tau_r_GABAB = 3.5
        synapse.tau_d_GABAB = 260.9
        #        synapse.gmax = .001
        synapse.e_GABAA = -80
        synapse.e_GABAB = -97
        synapse.GABAB_ratio = 0.0

    else:  # excitatory
        synapse = h.ProbAMPANMDA2(segment)
        synapse.gmax = .0004
    synapse.Use = 1.0
    synapse.Dep = 0
    synapse.Fac = 0

    netStimulation = h.NetStim()
    netStimulation.number = 1
    netStimulation.start = activationTime

    netConnection = h.NetCon(netStimulation, synapse)
    netConnection.delay = 0
    netConnection.weight[0] = synapseWeight

    return netStimulation, netConnection, synapse
Beispiel #5
0
    def __init__(self, mechname):
        #set variables in case of exception so that __del__ still works.
        self.nc = None
        self.stim = None
        self.syn = None
        self.vc = None
        self.s = None

        self.mechname = mechname
        constructor = h.__getattribute__(mechname)
        self.soma = h.Section(name='soma')
        s = self.soma
        s.L = 10.
        s.diam = 10. / h.PI
        s.insert('pas')
        seg = s(0.5)
        seg.e_pas = -65.0
        seg.g_pas = 0.0001

        self.syn = constructor(seg)
        self.stim = h.NetStim()
        self.stim.number = 2
        self.stim.interval = 5
        self.stim.start = 1

        self.nc = h.NetCon(self.stim, self.syn)
        self.nc.delay = 1
        self.nc.weight[0] = .001

        if use_voltage_clamp:
            self.vc = h.SEClamp(seg)
            self.vc.amp1 = -65.0
            self.vc.dur1 = 1e9
Beispiel #6
0
 def __init__(self,
              N=5,
              stim_w=0.04,
              stim_t=9,
              stim_delay=1,
              syn_w=0.01,
              syn_delay=5,
              r=50):
     """
     :param N: Number of cells.
     :param stim_w: Weight of the stimulus
     :param stim_t: time of the stimulus (in ms)
     :param stim_delay: delay of the stimulus (in ms)
     :param syn_w: Synaptic weight
     :param syn_delay: Delay of the synapse
     :param r: radius of the network
     """
     self._N = N
     self.set_gids()  ### assign gids to processors
     self._syn_w = syn_w
     self._syn_delay = syn_delay
     self._create_cells(
         r)  ### changed to use self._N instead of passing in N
     self._connect_cells()
     ### the 0th cell only exists on one process... that's the only one that gets a netstim
     if pc.gid_exists(0):
         self._netstim = h.NetStim()
         self._netstim.number = 1
         self._netstim.start = stim_t
         self._nc = h.NetCon(
             self._netstim,
             pc.gid2cell(
                 0).syn)  ### grab cell with gid==0 wherever it exists
         self._nc.delay = stim_delay
         self._nc.weight[0] = stim_w
Beispiel #7
0
def izhstim () :
  stim=h.NetStim(0.5)
  stim.number = stim.start = 1
  nc = h.NetCon(stim,izh)
  nc.delay = 2
  nc.weight = 0.1
  izh.erev = -5
    def __init__(self, spike_train=None, position = np.array([0,0,0]),whatami ='mossy',record_all = 0):
        self.record_all = record_all
        self.spike_train = spike_train
        self.whatami = whatami
	
        self.position = position
        if spike_train is not None:
            self.spk_vector = h.Vector()
        
            # Populate Vector
            for time in spike_train:
                self.spk_vector.append(float(time))

            self.output = h.VecStim()
            self.output.play(self.spk_vector)
        else:
            self.output = h.NetStim(0.5)
            self.output.start = -10
            self.output.number = 0
            self.output.interval = 1e9
            
        self.record = {}
        self.nc_spike = h.NetCon(self.output,None)
        self.record['spk'] = h.Vector()
        self.nc_spike.record(self.record['spk'])
Beispiel #9
0
    def __init__(self, gid):
        self.soma = h.Section(name="soma", cell=self)
        if gid % 2 == 0:
            # CoreNEURON permutation not the identity if cell topology not homogeneous
            self.dend = h.Section(name="dend", cell=self)
            self.dend.connect(self.soma(0.5))
        self.gid = gid
        pc.set_gid2node(gid, pc.id())
        self.r = h.Random()
        self.r.Random123(gid, 0, 0)
        self.syn = h.DAsyn(self.soma(0.5))
        pc.cell(gid, h.NetCon(self.soma(0.5)._ref_v, None, sec=self.soma))
        # random start times for the internal events
        self.syn.tau0 = 10 * self.r.uniform(0.9, 1.1)
        self.syn.tau1 = 3 * self.r.uniform(0.9, 1.1)
        self.syn.dur = 6 * self.r.uniform(1, 10)

        self.ns = h.NetStim()
        self.ns.noise = 1
        self.ns.start = 0
        self.ns.number = 1e9
        self.ns.interval = 6
        self.ns.noiseFromRandom123(gid, 0, 1)
        self.nc = h.NetCon(self.ns, self.syn)
        self.nc.weight[0] = 0.1 * self.r.uniform(0.9, 1.1)
        self.nc.delay = 1
        self.msgvec = h.Vector()
        self.msgvec.record(self.syn._ref_msg, sec=self.soma)
Beispiel #10
0
    def addNetStim (self, params, stimContainer=None):
        from .. import sim

        if not stimContainer:
            self.stims.append(Dict(params.copy()))  # add new stim to Cell object
            stimContainer = self.stims[-1]

            if sim.cfg.verbose: print(('  Created %s NetStim for cell gid=%d'% (params['source'], self.gid)))
        
        if sim.cfg.createNEURONObj:
            rand = h.Random()
            stimContainer['hRandom'] = rand  # add netcon object to dict in conns list

            if isinstance(params['rate'], str):
                if params['rate'] == 'variable':
                    try:
                        netstim = h.NSLOC()
                        netstim.interval = 0.1**-1*1e3 # inverse of the frequency and then convert from Hz^-1 to ms (set very low)
                        netstim.noise = params['noise']
                    except:
                        print('Error: tried to create variable rate NetStim but NSLOC mechanism not available')
                else:
                    print('Error: Unknown stimulation rate type: %s'%(h.params['rate']))
            else:
                netstim = h.NetStim() 
                netstim.interval = params['rate']**-1*1e3 # inverse of the frequency and then convert from Hz^-1 to ms
                netstim.noise = params['noise'] # note: random number generator initialized via Random123() from sim.preRun()
                netstim.start = params['start']
            netstim.number = params['number']   
                
            stimContainer['hNetStim'] = netstim  # add netstim object to dict in stim list

            return stimContainer['hNetStim']
Beispiel #11
0
def setIPClamp(seg, delay, freq, number, dur, amp):
    ns = h.NetStim()
    ns.start, ns.interval, ns.number = delay, 1000 / freq, number
    ipstim = h.IPClamp(seg)
    ipstim.dur, ipstim.amp = dur, amp
    nc = h.NetCon(ns, ipstim, 0, 0.5, 1)
    return [ns, nc, ipstim]
Beispiel #12
0
 def addGABA(self, weightMap, numStims, jitter=False):
     tstart = self.stimStart
     tstop = self.stimStop
     for tuple in weightMap:
         loc = tuple[0]
         synapseWeight = tuple[1]
         treeNum = loc[0]
         tree = self.trees[treeNum]
         section = tree[loc[1]]
         segLoc = self.getSegLoc(loc)
         # syn = h.ExpSyn(self.getSegLoc(i),sec=self.dend)
         syn = h.ProbGABAAB_EMS(segLoc, sec=section)
         if self.Current:
             syn = h.ProbGABAAB_EMS_Current(segLoc, sec=section)
         #syn.GABAB_ratio = 0.33
         self.synapses[loc].append(syn)
         if jitter == True:
             stimTimes = np.random.randint(
                 tstart, tstop, size=numStims)  # 2 in 50 ms = 40Hz
         else:
             stimTimes = range(tstart, tstop, (tstop - tstart) / numStims)
         for time in stimTimes:
             stim = h.NetStim()
             stim.number = 1
             stim.start = time
             ncstim = h.NetCon(stim, syn)
             self.netStims[loc].append(stim)
             #ncstim.delay = 0.25
             ncstim.weight[0] = synapseWeight
             self.netCons[loc].append(ncstim)
    def __init__(self,
                 spike_train=None,
                 position=np.array([0, 0, 0]),
                 background=3.9,
                 cv=1,
                 whatami='glom'):
        self.whatami = whatami

        self.background = background

        self.position = position

        self.mfncpc = []

        self.record = {}
        if spike_train is not None:
            self.spk_vector = h.Vector()

            # Populate Vector
            for time in spike_train:
                self.spk_vector.append(float(time))
            self.spike = h.VecStim()
            self.spike.play(self.spk_vector)
        else:
            self.spike = h.NetStim(0.5)
            self.spike.start = -10
            self.spike.number = 1
            self.spike.interval = 1e9
        self.nc_spike = h.NetCon(self.spike, None)
        self.record['spk'] = h.Vector()
        self.nc_spike.record(self.record['spk'])
Beispiel #14
0
    def set_NetStim(self, noise=0.0):
        """
        Creates, sets and returns a NetStim.

        Parameters
        ----------
        noise : float
            the fractional randomness (default is 0.0)

        Returns
        -------
        neuron.hoc.HocObject
            NetStim
        """
        stim = h.NetStim()
        stim.seed(self.setting['netstim']['NETSTIM_SEED'])
        stim.start = np.random.rand(
        ) * self.setting['netstim']['NETSTIM_START']
        if self.setting['netstim']['NETSTIM_FREQUENCY'] == 0:
            stim.interval = 1e9
        else:
            stim.interval = 1000 / self.setting['netstim']['NETSTIM_FREQUENCY']
        stim.number = self.setting['netstim']['NETSTIM_NUMBER']
        stim.noise = noise
        return stim
Beispiel #15
0
def synon () : 
  "Turn on a synapse"
  global ns, nc
  ns = h.NetStim()
  nc = h.NetCon(ns,izh,0,1,10)
  ns.start, ns.interval, ns.number = 10, 10, 10
  nc.weight[0] = 2
  izh.taug = 3
    def __init__(self,
                 parallelContext,
                 neuralNetwork,
                 amplitude,
                 frequency,
                 burstsFrequency,
                 pulsesNumber,
                 species="rat",
                 stim_start=5):
        """ Object initialization.

		Keyword arguments:
		parallelContext -- Neuron parallelContext object.
		neuralNetwork -- EES object with the number of pulse and the frequency of the pulses during each burst
		amplitude -- Aplitude of stimulation. It could either be an integer
		value between _minCur and _maxCur or a list containing the percentages
		of recruited primary afferents, secondary afferents and motoneurons.
		frequency -- Stimulation frequency in Hz; It has to be set in a way that new bursts
		are not occuring while old burst are still ongoing.
		burstsFrequency -- Burst stimulation frequency in Hz; it has to be lower than the
		maximum stimulation frequency imposed by the AfferentFiber model.
		pulsesNumber -- number of pulses to send.
		"""

        self._pc = parallelContext
        self._burstStim = EES(parallelContext, neuralNetwork, amplitude,
                              burstsFrequency, pulsesNumber, species)
        self._burstStimId = self._burstStim.get_id()
        self._BurstingEesId = 1000001

        burstPulses = self._burstStim.get_n_pulses()
        burstFreq = self._burstStim.get_frequency()
        totBurstDuration = 1000. / burstFreq * burstPulses
        self._maxFrequency = 1000. / totBurstDuration

        # Create the netStim Object in the first process
        if rank == 0:
            # Tell this host it has this cellId
            self._pc.set_gid2node(self._BurstingEesId, rank)

            # Create the stim objetc
            self._stim = h.NetStim()
            self._stim.number = 100000
            self._stim.start = stim_start  #lets give few ms for init purposes
            self._stim.noise = 0

            self._pulses = h.Vector()
            # Associate the cell with this host and id
            # the nc is also necessary to use this cell as a source for all other hosts
            nc = h.NetCon(self._stim, None)
            self._pc.cell(self._BurstingEesId, nc)
            # Record the stimulation pulses
            nc.record(self._pulses)

        # Connect the stimulation to all dof of the neural network
        self._connect_to_burstStim()
        # Set stimulation frequency
        self.set_frequency(frequency)
Beispiel #17
0
	def __init__(self,parallelContext,neuralNetwork,amplitude,frequency,pulsesNumber=100000,species="rat",stim_start=5):
		""" Object initialization.

		Keyword arguments:
		parallelContext -- Neuron parallelContext object.
		neuralNetwork -- NeuralNetwork instance to connect to this object.
		amplitude -- Aplitude of stimulation. It could either be an integer
		value between _minCur and _maxCur or a list containing the percentages
		of recruited primary afferents, secondary afferents and motoneurons.
		frequency -- Stimulation frequency in Hz; it has to be lower than the
		maximum stimulation frequency imposed by the AfferentFiber model.
		pulsesNumber -- number of pulses to send (default 100000).
		species -- rat or human (it loads different recruitment curves)
		"""
		self._pc = parallelContext
		self._nn = neuralNetwork
		self._species = species
		# Lets assign an Id to the stim object (high value to be sure is not already take from some cell)
		self._eesId = 1000000
		# Initialize a dictionary to contain all the connections between this object and the stimulated cells
		self._connections = {}

		self._maxFrequency = AfferentFiber.get_max_ees_frequency()
		self._current = None
		self._percIf= None
		self._percIIf= None
		self._percMn = None

		# Create the netStim Object in the first process
		if rank==0:
			# Tell this host it has this cellId
			self._pc.set_gid2node(self._eesId, rank)

			# Create the stim objetc
			self._stim = h.NetStim()
			self._stim.number = pulsesNumber
			self._stim.start = stim_start #lets give few ms for init purposes
			self._stim.noise = 0

			self._pulses = h.Vector()
			# Associate the cell with this host and id
			# the nc is also necessary to use this cell as a source for all other hosts
			nc = h.NetCon(self._stim,None)
			self._pc.cell(self._eesId, nc)
			# Record the stimulation pulses
			nc.record(self._pulses)

			# Load the recruitment data
			self._load_rec_data()

		# lets define which type of cells are recruited by the stimulation
		self._recruitedCells = sum([self._nn.get_afferents_names(),self._nn.get_motoneurons_names()],[])

		# Connect the stimulation to all muscles of the neural network
		self._connect_to_network()
		# Set stimulation parameters
		self.set_amplitude(amplitude)
		self.set_frequency(frequency)
 def mkstim(self):
     if not self.pc.gid_exists(0):
         return
     self.stim = h.NetStim()
     self.stim.number = 1
     self.stim.start = 0
     self.ncstim = h.NetCon(self.stim, self.pc.gid2cell(0).synlist[0])
     self.ncstim.delay = 0
     self.ncstim.weight[0] = 0.01
 def _create_ees_objects(self):
     """ Create different ees objects with the defined stimulation frequencies. """
     scale = rnd.random()
     for i in range(len(self._eesFrequencies)):
         self._eesList.append(h.NetStim())
         self._eesList[i].interval = 1000.0 / self._eesFrequencies[i]
         self._eesList[i].number = 10000
         self._eesList[i].start = 10.0 * scale
         self._eesList[i].noise = 0
Beispiel #20
0
 def connect_stim(self):
     """Connect a spiking generator to the first cell to get
     the network going."""
     self.stim = h.NetStim()
     self.stim.number = self.stim_number
     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.
Beispiel #21
0
    def set_netstim_netcon(self, interval):

        self.ns = h.NetStim()
        self.ns.interval = interval
        self.ns.number = 0
        self.ns.start = self.start

        self.ampa_nc = h.NetCon(self.ns, self.ampa, 0, 0, 0)
        self.nmda_nc = h.NetCon(self.ns, self.nmda, 0, 0, 0)
Beispiel #22
0
 def mkstim(self):
   if not pc.gid_exists(0):
     return
   self.stim = h.NetStim()
   self.stim.number = 1
   self.stim.start = 0
   ncstim = h.NetCon(self.stim, pc.gid2cell(self.gidstart).synlist[0])
   ncstim.delay = 1
   ncstim.weight[0] = 0.01
   self.nclist.append(ncstim)
Beispiel #23
0
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)
Beispiel #24
0
    def make_stim(self):
        # random external input for first 50 ms
        # The first N_STIM (excitatory) cells are stimulated.
        self.N_STIM = int(self.NCELL / 50)  # number of neurons stimulated
        self.STOPSTIM = 50  # duration of stimulation (ms)
        self.NSYN_STIM = 20  # nb of stim (exc) synapses per neuron
        self.STIM_INTERVAL = 70  # mean interval between stims (ms)
        self.stimList = list()
        self.ncStimList = list()
        self.stvec = h.Vector()
        self.svec = h.Vector()

        h.mcell_ran4_init(self.run_random_low_start)
        for i in range(self.N_STIM):
            # The ith cell and its corresponding RandomStream.
            cell = self.cellList[i]
            rs = self.ranList[
                i]  # The ith cell and its corresponding RandomStream.
            stim = h.NetStim()
            stim.interval = self.STIM_INTERVAL
            stim.number = 1000  # but will shut off after STOPSTIM
            stim.noise = 1
            stim.start = 0
            stim.noiseFromRandom(rs.r)
            rs.r.negexp(1)
            rs.start()
            nc = h.NetCon(stim, cell.synlist.object(0))
            nc.delay = self.STIM_DELAY  # =1 to be consistent with Brette
            nc.weight[0] = self.AMPA_GMAX
            nc.record(self.stvec, self.svec, i)
            self.ncStimList.append(nc)
            self.stimList.append(stim)

        stim = h.NetStim()  # will turn off all the others
        stim.number = 1
        stim.start = self.STOPSTIM
        for st in self.stimList:
            nc = h.NetCon(stim, st)
            nc.delay = 1  # to be consistent with Brette
            nc.weight[0] = -1
            self.ncStimList.append(nc)

        self.stimList.append(stim)
Beispiel #25
0
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()
Beispiel #26
0
def add_Estims(model, locs, sstart=20.0, sinterval=20, snumber=1, snoise=0):
    model.Estimlist = []
    lidx = 0
    for loc in locs:
        Estim = h.NetStim()
        Estim.interval = sinterval
        Estim.number = snumber
        Estim.start = sstart
        Estim.noise = snoise
        model.Estimlist.append(Estim)
        lidx += 1
Beispiel #27
0
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)
Beispiel #28
0
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)
Beispiel #29
0
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
Beispiel #30
0
    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)