Example #1
0
 def _ap_counters(self):
     """ Create action potential counters, esp. useful for threshold
     calculation """
     self.apcs = []
     self.apc_times = []
     if h.number_of_apc > 0:
         try:
             sec = h.node[h.axonnodes.__int__()-2]
         except AttributeError:
             print "No node compartments!"
             return 0
         apc = h.APCount(0.5, sec=sec)
         apc.thresh = 0 # mV
         apc_time = h.Vector()
         apc.record(apc_time)
         self.apcs.append(apc)
         self.apc_times.append(apc_time)
     if h.number_of_apc == 2:
         sec = h.node[1]
         apc = h.APCount(0.5, sec=sec)
         apc.thresh = 0 # mV
         apc_time = h.Vector()
         apc.record(apc_time)
         self.apcs.append(apc)
         self.apc_times.append(apc_time)
     else:
         if h.number_of_apc>2:
             raise ValueError,"Too many apc counters; only 1 or 2 allowed"
Example #2
0
def simulatepar(delay, dur, Ra, std, offset, amp, freq, dt, tau, mu, loc,
                simdur, init, cel, seed, loop):
    soma, axon = Mcm.create_sec('soma', 'axon')
    Mcm.define_geometry(soma, 30, 20, 1)
    Mcm.define_geometry(axon, 50, 1, 11)
    Mcm.build_topology_axso(axon, soma, 0)
    Mcm.define_biophysics(2, soma, 250, 400, 0.3e-3, .75, 150, -65, 55, -70,
                          -25., 6., -35., 6., -15., 4.)
    Mcm.define_biophysics(2, axon, 0, 500, 0.3e-3, .75 * 0.75, 150, -65, 55,
                          -70, -25., 6., -35., 6., -15., 4.)

    axon(Ra).gbar_na = 1000 * 15
    counts = h.Vector()
    apc = h.APCount(soma(0.5))
    apc.thresh = -15
    apc.record(counts)
    stim = attach_noise_sin_clamp(soma, delay, dur, offset, amp, freq, dt, tau,
                                  std, mu, loc, seed)
    # soma_vec, axon_vec, i_inj_vec, t_vec = set_recording_vectors(stim, soma, axon)
    h.dt = dt
    h.tstop = simdur
    h.v_init = init
    h.celsius = cel
    h.run()
    filename = './OUTPUT/spiketrain5Hzmfr' + str(Ra) + 'Ra' + str(
        freq) + 'freq' + str(std) + 'std' + str(seed) + 'seed' + str(
            loop) + 'loop.txt'
    writetofile(filename, counts)
    return 0
Example #3
0
    def _AP_counter(self, thr=0):
        """Action Potential counter at the soma of GenNeuron or a subclass.

        Parameters
        ----------
        thr - numeric
            the threshold value for action potential detection

        Returns
        -------
        time_vec - h.Vector
            the current clamp point process
        ap - h.APCount
            the ap counter object that counts number and records time stamps

        Use Cases
        ---------
        >>> myNeuron = GenNeuron()
        >>> myNeuron.mk_soma()
        >>> myNeuron._AP_counter
        """

        ap = h.APCount(self.soma(0.5))
        self.ap = ap
        self.ap.thresh = thr
        self.time_vec = h.Vector()
        self.ap.record(self.time_vec)
        return self.time_vec, self.ap
Example #4
0
def getfi(amp, simiter):
    h.tstop = 500  # to match synaptic input runs
    h.tsamp = h.tstop / h.dt + 1
    tsamp = int(h.tsamp)

    # 'background' injection
    npy.random.seed(int(simiter + h.luckyoffset))
    icr = h.IClamp(0.5, sec=h.soma)
    icr.dur = h.tstop
    if numbranches == 2:
        icmean = .75
    if numbranches == 8:
        icmean = 0
    icstd = 1
    icvals = icmean + icstd * npy.random.randn(tsamp)
    icrand = h.Vector(tsamp)
    for i in xrange(tsamp):
        icrand.x[i] = icvals[i]
    icrand.play(icr._ref_amp, h.dt)

    # do current injection run
    ic = h.IClamp(0.5, sec=h.soma)
    ap = h.APCount(0.5, sec=h.soma)
    ic.delay = 0
    ic.dur = h.tstop
    ic.amp = amp
    h.run()
    return ap.n * 1000. / h.tstop
    def _ap_counters(self):
        """ Create action potential counters, esp. useful for threshold
        calculation """

        self.apc = h.APCount(0.5, sec=self.root)
        self.apc.thresh = -20.0  #mV, threshold voltage for AP detection
        self.apc_times = h.Vector()
        self.apc.record(self.apc_times)
Example #6
0
def plot_histogram(cell, T, I0, S, I1, F):
    #F = 60          # Hz
    #T  = 200000.   # ms

    #I0 = 500.      # pA
    #S  = 300.      # pA
    #I1 = 80.       # pA
    tau = 5.  # ms
    delay = 0
    dt = 0.05
    mu = 0
    loc = 0.5
    seed = random.randint(0, 1000)
    F = F / 1000.
    stim = attach_noise_sin_clamp(cell, delay, T, I0, I1, F, dt, tau, S, mu,
                                  loc, seed)

    counts = h.Vector()
    apc = h.APCount(cell.soma[0](0.5))
    apc.thresh = 0
    apc.record(counts)
    run_model(dt, T)

    N = len(counts)
    tsp = np.array(counts.to_python())
    x = np.cos(6.28318530718 * tsp * F) / N
    y = np.sin(6.28318530718 * tsp * F) / N

    R0 = 1000. * N / T  # spikes/s
    R1 = 2 * R0 * np.absolute(np.complex(np.sum(x), np.sum(y)))
    PHI = np.angle(np.complex(np.sum(x), np.sum(y)), deg=False)
    tsp = np.remainder(tsp, 2 / F)
    C = np.floor_divide(T, 2 / F)

    fig = plt.figure(figsize=(14, 4))
    hist, bins = np.histogram(tsp, bins=40)
    hist = 1000. * hist / ((bins[3] - bins[2]) * C)  # Hz
    # R1 = (np.max(hist) - np.min(hist))/2

    W = (2. / F) / 40.
    plt.bar(bins[:-1], hist, width=W, color='black')

    y = R0 + R1 * np.cos(6.28318530718 * bins * F - PHI)
    z = R0 + R1 * np.cos(6.28318530718 * bins * F)
    plt.plot(bins, y, 'r', linewidth=1)
    plt.plot(bins, z, 'g--', linewidth=1)

    ax = fig.add_subplot(111)
    ax.set_xlim((0, 2. / F - (bins[3] - bins[2])))  # Set the horizontal limits
    # ax.set_ylim( (0, 2*R0) )                         # Set the horizontal limits
    ax.set_xlabel(
        'time within two periods [ms]')  # Label for the horizontal axis
    ax.set_ylabel(
        'Instantaneous firing rate [spikes/s]')  # Label for the vertical axis
    #ax.grid()                                               # "Grid" on

    plt.show()
Example #7
0
def plot_transferfunction(cell, T, I0, S, I1, FRange):
    tau = 5
    delay = 0
    dt = 0.05
    mu = 0
    loc = 0.5

    myfile = "spikes.x"
    transfervec = np.zeros(
        (len(FRange), 1))  # Create vector to store all transfer factor
    phasevec = np.zeros(
        (len(FRange), 1))  # Create vector to store all the phase delay values
    counter = 0
    for freq in FRange:
        seed = random.randint(0, 1000)
        stim = attach_noise_sin_clamp(cell, delay, T, I0, I1, freq / 1000., dt,
                                      tau, S, mu, loc, seed)

        counts = h.Vector()
        apc = h.APCount(cell.soma[0](0.5))
        apc.thresh = 0
        apc.record(counts)
        run_model(dt, T)

        N = len(counts)
        tsp = np.array(counts.to_python())

        x = np.cos(6.28318530718 * tsp * freq / 1000.) / N
        y = np.sin(6.28318530718 * tsp * freq / 1000.) / N
        R0 = 1000. * N / T  # spikes/s
        transfervec[counter] = np.absolute(np.complex(np.sum(x), np.sum(y)))
        phasevec[counter] = -np.angle(np.complex(np.sum(x), np.sum(y)),
                                      deg=False)
        counter += 1

    phasevec = phase_unwrap(phasevec)
    try:
        calc_cof(FRange, transfervec)
    except:
        print("Couldn't find a crossing between transfer curve and 70% line.")
    fig = plt.figure(figsize=(14, 4))
    ax1 = plt.subplot(2, 1, 1)
    plt.grid('on')
    plt.loglog(FRange, transfervec, 'o-', linewidth=3)
    plt.loglog(FRange,
               transfervec[0] * 0.707 * np.ones((FRange.size)),
               linewidth=2,
               color='black')
    plt.xlabel('Frequency [Hz]')
    plt.ylabel('Transfer factor')
    ax2 = plt.subplot(2, 1, 2, sharex=ax1)
    plt.semilogx(FRange, phasevec, 'o-', linewidth=3)
    plt.xlabel('Frequency [Hz]')
    plt.ylabel('Phase delay [Rad]')
    plt.grid('on')
    plt.subplots_adjust(hspace=0)
    plt.show()
Example #8
0
def rhoebase_counter(cell):
    #Not working in some cases due to the low current required, in the very small somato dendritic trees
    #What is the minimum current in these area? Via article or Yaki Results
    apc = h.APCount(cell.soma(0.5))
    apc.thresh = -10
    step = 0.00005
    min = 0.00005
    max = 0.02
    current_lst = np.arange(min, max, step)
Example #9
0
 def record(self, cells='all'):
     """Adds spike recorders."""
     log.info('Adding spike recorders.')
     if cells=='all':
         self.rec_cells = range(len(self.cells))
     else:
         self.rec_cells = cells
     self.apc = [(h.Vector(), 
                  h.APCount(0.5, sec=self.cells[i].soma)) 
                 for i in self.rec_cells]
     for tspike, apc in self.apc: 
         apc.thresh = -10
         apc.record(tspike)
def rhoebase_counter(cell, min_current = min_current, max_current = max_current, rheobase_step = rheobase_step):
    apc = h.APCount(cell.soma(0.5))
    apc.thresh = -30 #Changed from -10
    current_lst = np.arange(min_current, max_current, rheobase_step)
    for new_current in current_lst:
        stim.amp = new_current
        h.run()
        if (apc.n>0):
            print(apc.n)
            list_of_elem = [list_id[0],list_id[1],list_id[2],1/cell.dend.g_pas, cell.dend.Ra, cell.dend.cm, cell.dend.L,
                            cell.spacer.L, 1/cell.spacer.g_pas, cell.spacer.Ra, cell.spacer.cm ,
                            1/cell.AIS.g_pas, new_current]
            append_list_as_row(file_name, list_of_elem)
            return new_current
    def _my_ap_counters(self):

        self.apCounterDict = dict()
        self.apTimesDict = dict()
        for sec in self.get_secs():
            if ('node' in sec.name()):
                name = sec.name()
                self.apCounterDict[name] = h.APCount(0.5, sec=sec)
                self.apCounterDict[name].thresh = -30
                self.apCounterDict[name + '_times'] = h.Vector()
                self.apTimesDict[sec.name()] = h.Vector()
                self.apCounterDict[name].record(self.apCounterDict[name +
                                                                   '_times'])
                self.apCounterDict[name].record(self.apTimesDict[sec.name()])
Example #12
0
def run_exp(HCell, config):
    Vsoma = h.Vector()
    Vsoma.record(HCell.soma[0](.5)._ref_v)
    tvec = h.Vector()
    tvec.record(h._ref_t)
    apc = h.APCount(0.5, sec=HCell.soma[0])
    apc.thresh = 0
    apc.time = 10000000.

    h.init(h.v_init)
    h.run()

    np_t = np.array(tvec)
    np_v = np.array(Vsoma)
    max_v = np.max(np_v[np.where(np_t > config.Spike_time)[0][0]:])
    return apc.n, max_v
Example #13
0
def special_run(stim, cell, simdur, dt, init, cel):
    soma_v_vec = h.Vector()
    t_vec = h.Vector()
    soma_v_vec.record(cell.soma[0](0.5)._ref_v)
    t_vec.record(h._ref_t)
    apc = h.APCount(cell.soma[0](0.5)) #####
    spikes = h.Vector()     ########
    apc.thresh = 0          ####
    apc.record(spikes)      ######
    h.dt = dt
    h.tstop = simdur
    h.v_init = init
    h.celsius = cel
    h.run()
    # soma_v_vec.resize(0)
    # t_vec.resize(0)
    # spikes.resize(0)
    # h.continuerun(10001.)
    return soma_v_vec; #spikes;
Example #14
0
	def __init__(self,v):
		self.soma = h.Section()
		self.soma.L		= 200.
		self.soma.diam	= 20./np.pi
		self.soma.nseg	= 1
		self.soma.insert('hh')
		self.soma(0.5).el_hh = -30.3
		self.soma(0.5).v = v
		self.isyn	= h.Exp2Syn(0.5, sec=self.soma)
		self.isyn.e		= -75.0
		self.isyn.tau1	= 0.99
		self.isyn.tau2	= 1.0
		self.esyn	= h.ExpSyn(0.5, sec=self.soma)
		self.esyn.e		= 0.0
		self.esyn.tau	= 0.8
		self.spks	= h.Vector()
		self.sptr	= h.APCount(.5, sec=self.soma)
		self.sptr.thresh = 25
		self.sptr.record(self.spks)
Example #15
0
    def record_spikes(self, threshold=-30, pos=.5):
        """
        Records the spikes of this section.
        Note: Values are updated after each NEURON h.run().

        :param: pos: Indicates the position on the Section at which is recorded (number between 0 and 1).
        :type: pos: float
        :param: threshold: Only spikes above this threshold are counted as spikes.
        :type: threshold: float
        :return: vec: Contains the times where spikes occurred
        :rtype: vec: h.Vector
        """
        vec = h.Vector()
        self.spike_count = h.APCount(
            pos,
            sec=self)  # spike_count assigned to self to keep NEURON reference
        self.spike_count.thresh = threshold
        self.spike_count.record(vec)
        return vec
Example #16
0
def plot_FI(cell, T, I0range, Srange):
    delay = 0
    dt = 0.05
    mu = 0
    loc = 0.5

    m = np.size(I0range)
    n = np.size(Srange)
    F = np.zeros((m, n))

    I1 = 0.
    F0 = 0.
    tau = 5.

    for j in range(n):
        for i in range(m):
            seed = random.randint(0, 1000)
            I0 = I0range[i]
            S = Srange[j]
            stim = attach_noise_sin_clamp(cell, delay, T, I0, I1, F0, dt, tau,
                                          S, mu, loc, seed)

            counts = h.Vector()
            apc = h.APCount(cell.soma[0](0.5))
            apc.thresh = 0
            apc.record(counts)
            run_model(dt, T)

            N = len(counts)

            F[i, j] = 1000. * N / T

    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot(I0range, F, 'o-', linewidth=3.0)
    ax.set_xlim(
        (np.min(I0range), np.max(I0range)))  # Set the horizontal limits
    #ax.set_ylim( (0,40) )                             # Set the vertical limits
    ax.set_xlabel('Mean input current [pA]')  # Label for the horizontal axis
    ax.set_ylabel('Mean Firing Rate [Hz]')  # Label for the vertical axis
    ax.grid()  # "Grid" on
    plt.show()
def fig_rheobase_check(cell):
    #Not working in some cases due to the low current required, in the very small somato dendritic trees
    #What is the minimum current in these area? Via article or Yaki Results
    apc = h.APCount(cell.soma(0.5))
    apc.thresh = 0
    current_lst = np.arange(min_current, max_current, rheobase_step)
    soma_v_vec, AIS_v_vec, t_vec = set_recording_vectors(cell)
    for new_current in current_lst:
        stim.amp = new_current
        h.run()
        if apc.n>0:
            print(apc)
            pyplot.plot(t_vec, soma_v_vec, label=str(new_current) + ', Rheobase = {}'.format(new_current))
            pyplot.suptitle('Spike Graph', fontsize=14, fontweight='bold')
            # pyplot.text(0.1, 2.8, "The number of action potentials is {}".format(apc.n))
            pyplot.xlabel('time (ms)')
            pyplot.ylabel('mV')
            pyplot.legend()
            pyplot.show()
            return new_current
def spike_fig(cell):
    #Setup recording
    soma_v_vec, AIS_v_vec, t_vec = set_recording_vectors(cell)
    apc = h.APCount(cell.soma(0.5))
    apc.thresh = 0
    #Setup Graphs:
    pyplot.figure(figsize=(20, 8))
    step = 0.02
    num_steps = 2
    for new_current in np.linspace(step, step * num_steps, num_steps):
        stim.amp = new_current
        h.run()
        pyplot.plot(t_vec, soma_v_vec, label=str(new_current)+', Spike Number = {}'.format(apc.n))
    #Design Graph
    pyplot.suptitle('Spike Graph', fontsize=14, fontweight='bold')
    # pyplot.text(0.1, 2.8, "The number of action potentials is {}".format(apc.n))
    pyplot.xlabel('time (ms)')
    pyplot.ylabel('mV')
    pyplot.legend()
    pyplot.show()
Example #19
0
def simulatepar(delay, dur, std, offset, amp, freq, dt, tau, mu, loc, simdur,
                init, cel, seed, loop):
    init_simulation()
    cell = rn.create_cell(False)
    h.psection()
    counts = h.Vector()
    apc = h.APCount(cell.soma[0](0.5))
    apc.thresh = -15
    apc.record(counts)
    stim = attach_noise_sin_clamp(cell, delay, dur, offset, amp, freq, dt, tau,
                                  std, mu, loc, seed)
    h.dt = dt
    h.tstop = simdur
    h.v_init = init
    h.celsius = cel
    h.run()
    filename = './OUTPUT/spiketrain5Hzmfr' + str(freq) + 'freq' + str(
        std) + 'std' + str(seed) + 'seed' + str(loop) + 'loop.txt'
    writetofile(filename, counts)
    return 0
def fig_rheobase_check(cell):
    apc = h.APCount(cell.soma(0.5))
    apc.thresh = 0
    current_lst = np.arange(min_current, max_current, rheobase_step)
    soma_v_vec, AIS_v_vec, t_vec = set_recording_vectors(cell)
    for new_current in current_lst:
        stim.amp = new_current
        h.run()
        if apc.n > 0:
            print(apc)
            pyplot.plot(t_vec,
                        soma_v_vec,
                        label=str(new_current) +
                        ', Rheobase = {}'.format(new_current))
            pyplot.suptitle('Spike Graph', fontsize=14, fontweight='bold')
            # pyplot.text(0.1, 2.8, "The number of action potentials is {}".format(apc.n))
            pyplot.xlabel('time (ms)')
            pyplot.ylabel('mV')
            pyplot.legend()
            pyplot.show()
            return new_current
Example #21
0
    def record_spikes(self, threshold=-30):
        """
        Record the number of spikes produced in this section,
        which is the number of time a voltage is crossed in
        the middle of a section

        Parameters
        ----------
        threshold: a float
            voltage determining the presence or not of a spike

        Returns
        -------
        nothing, but change the self.spikecount

        """


        self.spiketimes = h.Vector()
        self.spikecount = h.APCount(0.5, sec=self)
        self.spikecount.thresh = threshold
        self.spikecount.record(self.spiketimes)
Example #22
0
def main():
    init_simulation()
    cell = create_cell(False)
    std = 0.
    currRange = numpy.arange(0.038, .04, 0.001)
    #looks like it may be in [mA] instead of [nA]
    dt = 0.005
    tau = 10.  #22.5 # [ms] # 10.
    mu = 0.
    totalcount = []
    stepi = []
    for i in currRange:
        curr = i
        counts = h.Vector()
        apc = h.APCount(cell.soma[0](0.5))
        apc.thresh = 10
        apc.record(counts)
        delay = 0
        dur = 100
        stim = attach_noise_sin_clamp(cell, delay, dur, curr, 0., 0., dt, tau,
                                      std, mu, 0.5)
        soma_vec, axon_vec, i_inj_vec, t_vec = set_recording_vectors(
            stim, cell)
        simulate(dur, dt, -70, 37)
        if len(counts) > 1:
            deltat = counts[-1] - counts[0]
            totalcount.append(((len(counts)) / deltat) * 1000)
            stepi.append(curr)
        else:
            totalcount.append(0)
            stepi.append(curr)
        pyplot.figure()
        pyplot.plot(t_vec, soma_vec)
    filename = 'FIVal' + str(0) + 'bis.txt'
    writetofile(filename, stepi, totalcount)
    pyplot.figure()
    pyplot.plot(stepi, totalcount)
Example #23
0
 def spike_record(self, gid, thresh=0):
     self.spikes[gid] = (h.APCount(self.gid2cell[gid].soma(0.5)), h.Vector())
     self.spikes[gid][0].thresh = thresh
     self.spikes[gid][0].record(self.spikes[gid][1])
Example #24
0
distRange = numpy.arange(0, 0.9, 0.3)
con = 1
stdcounts = numpy.zeros(shape=(num_steps, len(distRange) + 1))
for distSAIS in distRange:
    std = 0.03
    Mcm.define_biophysics(2, soma, 800, 320, 1 / 30000, 0.75, 150, -70, 60,
                          -80)
    Mcm.define_biophysics(2, axon, 0, 1600, 1 / 30000, 0.75 * 0.75, 150, -70,
                          60, -80)
    axon(distSAIS).gbar_na = 8000 * 15
    totalcount = []
    stepi = []
    counter = 0
    for i in range(0, num_steps):
        counts = h.Vector()
        apc = h.APCount(soma(0.5))
        apc.thresh = 0
        apc.record(counts)
        offset = startcur + (step * i)
        # stim = Mcm.attach_current_clamp(soma, 1, 1000, startcur + (step * i), 0.5)
        stim = Mcm.attach_noise_sin_clamp(soma, delay, dur, offset, amp, freq,
                                          dt, tau, std, mu, loc, seed)
        soma_vec, axon_vec, i_inj_vec, i_cap_vec, t_vec = Mcm.set_recording_vectors(
            stim, soma, axon)
        icap = h.Vector()
        icap.record(soma(.5)._ref_i_cap)
        Mcm.simulate(T, 0.005, -70, 37)
        # dvdt_vec = Mcm.calc_dvdt(soma_vec, t_vec)
        # fig = pyplot.figure()
        # ax1 = fig.add_subplot(2, 1, 1)
        # ax2 = fig.add_subplot(2, 1, 2)
Example #25
0
 def record_spikes(self, threshold=-30):
     self.spiketimes = h.Vector()
     self.spikecount = h.APCount(0.5, sec=self)
     self.spikecount.thresh = threshold
     self.spikecount.record(self.spiketimes)
Example #26
0
def plot_FI_and_modulation(cell, T, I0range, S, M, M1, FF):

    m = np.size(I0range)
    F = np.zeros((m, 1))
    I1 = 0.
    F0 = 0.
    tau = 5.
    FF = FF / 1000
    delay = 0
    dt = 0.05
    mu = 0
    loc = 0.5

    for i in range(m):
        I0 = I0range[i]
        seed = random.randint(0, 1000)
        I0 = I0range[i]
        stim = attach_noise_sin_clamp(cell, delay, T, I0, I1, F0, dt, tau, S,
                                      mu, loc, seed)

        counts = h.Vector()
        apc = h.APCount(cell.soma[0](0.5))
        apc.thresh = 0
        apc.record(counts)
        run_model(dt, T)

        N = len(counts)

        F[i, 0] = 1000. * N / T

    I1 = 0.
    F0 = 0.

    seed = random.randint(0, 1000)
    stim = attach_noise_sin_clamp(cell, delay, T, M, I1, F0, dt, tau, S, mu,
                                  loc, seed)

    counts = h.Vector()
    apc = h.APCount(cell.soma[0](0.5))
    apc.thresh = 0
    apc.record(counts)
    run_model(dt, T)

    N = len(counts)

    stim = attach_noise_sin_clamp(cell, delay, T, M * 1.1, I1, F0, dt, tau, S,
                                  mu, loc, seed)

    counts = h.Vector()
    apc = h.APCount(cell.soma[0](0.5))
    apc.thresh = 0
    apc.record(counts)
    run_model(dt, T)

    N1 = len(counts)

    I1 = M1
    F0 = FF

    seed = random.randint(0, 1000)
    stim = attach_noise_sin_clamp(cell, delay, T, M, I1, F0, dt, tau, S, mu,
                                  loc, seed)

    counts = h.Vector()
    apc = h.APCount(cell.soma[0](0.5))
    apc.thresh = 0
    apc.record(counts)
    somav = h.Vector()
    somav.record(cell.soma[0](0.5)._ref_v)
    timevec = h.Vector()
    timevec.record(h._ref_t)
    iinj = h.Vector()
    iinj.record(stim._ref_i)
    run_model(dt, T)

    fig = plt.figure(figsize=(14, 4))
    ax1 = fig.add_subplot(121)
    ax1.plot(I0range, F, 'o-', linewidth=3.0)
    ax1.set_xlim(
        (np.min(I0range), np.max(I0range)))  # Set the horizontal limits
    #ax1.set_ylim( (0,40) )                             # Set the vertical limits
    ax1.set_xlabel('Mean input current [pA]')  # Label for the horizontal axis
    ax1.set_ylabel('Mean Firing Rate [Hz]')  # Label for the vertical axis
    ax1.grid()  # "Grid" on

    p = [M, 1000. * N / T]
    indthres = np.nonzero(I0range > M)
    crossind = indthres[0]
    rico = (F[crossind[0]] - F[crossind[0] - 1]) / (I0range[crossind[0]] -
                                                    I0range[crossind[0] - 1])
    p[1] = rico * (M - I0range[crossind[0] - 1]) + F[crossind[0] - 1]
    p1amp = rico * (M + M1 - I0range[crossind[0] - 1]) + F[crossind[0] -
                                                           1] - p[1]

    xmin, xmax = ax1.get_xbound()
    ymin, ymax = ax1.get_ybound()
    l1 = mlines.Line2D([p[0], p[0]], [ymin, p[1]])
    l2 = mlines.Line2D([xmin, p[0]], [p[1], p[1]])
    ax1.add_line(l1)
    ax1.add_line(l2)

    t = np.arange(ymin, p[1], (p[1] - ymin) * 0.005)
    i = M + M1 * np.cos(6.28 * t * 5. / (p[1] - ymin))
    ax1.plot(i, t)
    t = np.arange(xmin, p[0], (p[0] - xmin) * 0.005)
    f = p[1] + p1amp * np.cos(6.28 * t * 5. / (p[0] - xmin))
    ax1.plot(t, f)

    ax2 = fig.add_subplot(122)
    ax2.plot(timevec, somav)  # Make the actual plot versus time

    timevecpyt = np.arange(0., T, dt)
    tmp1 = -60 + 10 * np.cos(6.28 * FF * timevecpyt)
    ax2.plot(timevecpyt, tmp1)
    ax2.set_xlim((0, 400))  # Set the horizontal limits
    ax2.set_ylim((-80, 50))  # Set the vertical limits
    ax2.set_xlabel('time [ms]')  # Label for the horizontal axis
    ax2.set_ylabel(
        'u - membrane potential [mV]')  # Label for the vertical axis
    ax2.grid()  # "Grid" on

    plt.show()
Example #27
0
    for sec in bc.all_secs:
        sec.ek = sec.ek + 0
    for sec in hc.all_secs:
        sec.ek = sec.ek + 0

    gc_stim = gc._current_clamp_soma(x, 500, 50)
    mc_stim = mc._current_clamp_soma(x, 500, 50)
    bc_stim = bc._current_clamp_soma(x, 500, 50)
    hc_stim = hc._current_clamp_soma(x, 500, 50)

    gc_rec = gc._voltage_recording()
    mc_rec = mc._voltage_recording()
    bc_rec = bc._voltage_recording()
    hc_rec = hc._voltage_recording()

    gc_apc_curr = h.APCount(gc.soma(0.5))
    mc_apc_curr = h.APCount(mc.soma(0.5))
    bc_apc_curr = h.APCount(bc.soma(0.5))
    hc_apc_curr = h.APCount(hc.soma(0.5))

    time_vec = h.Vector()
    time_vec.record(h._ref_t)

    h.cvode.active(0)
    dt = 0.1
    h.steps_per_ms = 1.0 / dt
    h.tstop = 1500
    h.finitialize(-60)
    h.t = -2000
    h.secondorder = 0
    h.dt = 10
def Constructing_the_ball_and_tree(params, cables,
                                   spiking_mech=False, nmda_on=False, Ca_spikes_on=False, HH_on=False):

    # list of excitatory stuff
    exc_synapses, exc_netcons, exc_spike_trains, exc_Ks  = [], [], [], []
    # list of inhibitory stuff
    inh_synapses, inh_netcons, inh_spike_trains, inh_Ks = [], [], [], []
    # area list
    area_lists = []
    
    area_tot = 0

    ## --- CREATING THE NEURON
    for level in range(len(cables)):
        
        # list of excitatory stuff per level
        exc_synapse, exc_netcon, exc_spike_train, exc_K = [], [], [], []
        # list of inhibitory stuff per level
        inh_synapse, inh_netcon, inh_spike_train, inh_K = [], [], [], []
        
        area_list = []

        for comp in range(max(1,2**(level-1))):
                nrn('create cable_'+str(int(level))+'_'+\
                    str(int(comp)))
                exec('section = nrn.cable_'+str(level)+'_'+str(comp))

                ## --- geometric properties
                section.L = cables[level]['L']*1e6
                section.diam = cables[level]['D']*1e6
                section.nseg = cables[level]['NSEG']
                
                ## --- passive properties
                section.Ra = params['Ra']*1e2
                section.cm = params['cm']*1e2
                section.insert('pas')
                section.g_pas = params['g_pas']*1e-4
                section.e_pas = params['El']*1e3
                if comp==0 and HH_on:
	            section.insert('hh3Larkum2009')
                if (comp==1 or comp==2) and Ca_spikes_on:
                    section.insert('scaLarkum2009')
                    section.gbar_scaLarkum2009=10
	            # section.insert('kdrLarkum2009')
                    # section.insert('kcaLarkum2009')
                    # section.gbar_kcaLarkum2009=30
                    section.insert('cad2Larkum2009')
	            section.insert('it2Larkum2009')
                    # section.gcabar_it2Larkum2009=0.000
	            # section.insert('hh3Larkum2009')
                    # section.gkbar_hh3Larkum2009=0
                    # section.gkbar2_hh3Larkum2009=0.0001
                    # section.gnabar_hh3Larkum2009=0.01
	            # section.insert('kapLarkum2009')
                    # section.gkabar_kapLarkum2009=0.003
	            # section.insert('kmLarkum2009')
                    # section.gbar_kmLarkum2009=0
                    # section.gbar_kdrLarkum2009=0

                if level>=1: # if not soma
                    # in NEURON : connect daughter, mother branch
                    nrn('connect cable_'+str(int(level))+'_'+\
                        str(int(comp))+'(0), '+\
                        'cable_'+str(int(level-1))+\
                        '_'+str(int(comp/2.))+'(1)')
                    
                ## --- SPREADING THE SYNAPSES (bis)
                for seg in section:

                    tree_fraction = np.max([0,float(seg.x)/(len(cables)-1)+float(level-1)/(len(cables)-1)])
                    if tree_fraction>params['fraction_for_L_prox']:
                        # print 'strengthen synapse !'
                        Ftau = 1. # removed params !
                        Fq = params['factor_for_distal_synapses_weight']
                    else:
                        Ftau = 1.
                        Fq = 1.

                    # in each segment, we insert an excitatory synapse
                    if nmda_on:
                        syn = nrn.my_glutamate(seg.x, sec=section)
                        syn.tau_ampa, syn.e = Ftau*params['Te']*1e3, params['Ee']*1e3
                        syn.gmax = 1e9*params['Qe'] # nS in my_glutamate.mod
                    else:
                        syn = nrn.ExpSyn(seg.x, sec=section)
                        syn.tau, syn.e = Ftau*params['Te']*1e3, params['Ee']*1e3
                    exc_synapse.append(syn)
                    netcon = nrn.NetCon(nrn.nil, syn)
                    netcon.weight[0] = Fq*params['Qe']*1e6
                    exc_netcon.append(netcon)
                    exc_K.append(cables[level]['Ke_per_seg'])
                    exc_spike_train.append([])

                    syn = nrn.ExpSyn(seg.x, sec=section)
                    syn.tau, syn.e = Ftau*params['Ti']*1e3, params['Ei']*1e3
                    inh_synapse.append(syn)
                    inh_K.append(cables[level]['Ki_per_seg'])
                    inh_spike_train.append([])
                    netcon = nrn.NetCon(nrn.nil, syn)
                    netcon.weight[0] = Fq*params['Qi']*1e6
                    inh_netcon.append(netcon)

                    # then just the area to check
                    area_tot+=nrn.area(seg.x, sec=section)
                    area_list.append(nrn.area(seg.x, sec=section))
                        

        exc_synapses.append(exc_synapse)
        exc_netcons.append(exc_netcon)
        exc_Ks.append(exc_K)
        exc_spike_trains.append(exc_spike_train)
        inh_synapses.append(inh_synapse)
        inh_netcons.append(inh_netcon)
        inh_Ks.append(inh_K)
        inh_spike_trains.append(inh_spike_train)
        area_lists.append(area_list)

        
    # ## --- spiking properties
    if spiking_mech: # only at soma if we want it !
        nrn('cable_0_0 insert hh')
        # + spikes recording !
        counter = nrn.APCount(0.5, sec=nrn.cable_0_0)
        spkout = nrn.Vector()
        counter.thresh = -30
        counter.record(spkout)
    else:
        spkout = np.zeros(0)
        
    print("=======================================")
    print(" --- checking if the neuron is created ")
    nrn.topology()
    print(("with the total surface : ", area_tot))
    print("=======================================")
        
    return exc_synapses, exc_netcons, exc_Ks, exc_spike_trains,\
       inh_synapses, inh_netcons, inh_Ks, inh_spike_trains, area_lists, spkout
Example #29
0
# record the membrane potentials and
# synaptic currents
#vec[ 'v_apic16'].record ( post (0.5)._ref_v )
vec['v_apic16'].record(pyramidal.apic[16](1)._ref_v)
#vec[ 'i_syn'].record ( syn._ref_i )
vec['v_soma'].record(pyramidal.soma(0.5)._ref_v)
vec['v_apic12'].record(pyramidal.apic[12](0.5)._ref_v)

#record current of different synapses:
#vec[ 'i_syn'].record ( syn_exp._ref_i )
vec['i_syn'].record(syn._ref_i)
vec['i_syn2'].record(syn2._ref_i)
vec['i_syn3'].record(syn3._ref_i)
vec['t'].record(h._ref_t)
# run the simulation
apcount = h.APCount(pyramidal.soma(0.5))
apcount.thresh = 1

h.load_file("stdrun.hoc")
h.init()
h.tstop = 1000.0
h.run()

print "number of spikes = ", apcount.n

# plot the results
#import pylab
import matplotlib.pyplot as plt
from matplotlib.pyplot import cm
import numpy as np
import matplotlib.patches as mpatches
Example #30
0
def rhoebase_counter(cell, min_current = min_current, max_current = max_current, rheobase_step = rheobase_step):
    apc = h.APCount(cell.soma(0.5))
    apc.thresh = -30 #Changed from -10
    current_lst = np.arange(min_current, max_current, rheobase_step)