def biophysics(self, morpho_data):
        """Inserting biophysics"""

        neuron = br2.SpatialNeuron(morphology=self.morpho, model=eqs, \
            Cm=Capacit, Ri=R_axial, threshold  = "v/mV>0", refractory = "v/mV > -10",
            threshold_location = 0, reset = 's_trace += x_reset*(taux/ms)',method='heun') #

        # define the different parts of the neuron
        N_soma = neuron[morpho_data['soma'][0]:morpho_data['soma'][-1] + 1]
        N_axon = neuron[morpho_data['axon'][0]:morpho_data['axon'][-1] + 1]
        N_basal = neuron[morpho_data['basal'][0]:morpho_data['basal'][-1] + 1]
        N_apical = neuron[morpho_data['apical'][0]:morpho_data['apical'][-1] +
                          1]
        Theta_low = morpho_data['thetalow'] * mV

        # insert leak conductance
        neuron.gLeak = g_leak

        # noise
        neuron.noise_sigma = 0 * pA  # initial value membrane voltage
        neuron.noise_avg = 0 * pA  # initial value membrane voltage
        N_soma.noise_sigma = noise_std  # initial value membrane voltage
        N_soma.noise_avg = noise_mean  # initial value membrane voltage

        ####################
        # ACTIVE CHANNELS
        ####################

        # Na channels soma, axon, apical dendrites
        N_soma.gNav = somaNa
        N_axon.gNav = axonNa
        N_apical.gNav = apicalNa
        neuron.thi1 = thi1_all
        N_axon.thi1 = thi1_axn
        neuron.thi2 = thi2_all
        N_axon.thi2 = thi2_axn

        #Kv channels
        N_soma.gKv = somagKv
        N_basal.gKv = dendgKv
        N_apical.gKv = dendgKv
        N_axon.gKv = axongKv

        #Ca channels sina
        N_soma.gCav = ratio_ca * somaCa
        N_soma.gIt = (1 - ratio_ca) * somaCa

        #Ka channels soma
        N_soma.gKa_prox = somaKap

        #Ka channels dendrites, Na channels basal dendrites, Ca channels dendrites, axon initial segment
        for sec in self.sections:
            secNr = self.sections[sec][2]
            seclen = len(self.sections[sec][0].x)

            #BASAL
            if secNr in morpho_data['basal']:
                # decreasing Na channels
                gNa_diff = 0.5 * np.array(
                    self.distances[sec][:]) * psiemens / um**2
                neuron[secNr:secNr + seclen].gNav = np.multiply(
                    basalNa - gNa_diff, basalNa - gNa_diff > 0)

                # increasing Ka channels
                gKa_diff = 0.7 * np.array(
                    self.distances[sec][:]) * psiemens / um**2
                ratio_A = np.multiply(
                    1. - (1. / 300.) * np.array(self.distances[sec][:]),
                    1. - (1. / 300.) * np.array(self.distances[sec][:]) > 0)
                neuron[secNr:secNr + seclen].gKa_prox = ratio_A * np.multiply(
                    basalKa + gKa_diff, basalKa + gKa_diff > 0)
                neuron[secNr:secNr +
                       seclen].gKa_dist = (1. - ratio_A) * np.multiply(
                           basalKa + gKa_diff, basalKa + gKa_diff > 0)

                # Ca channels
                neuron[secNr:secNr + seclen].gCav = dendCa * ratio_ca * (
                    np.array(self.distances[sec][:]) >
                    30) + somaCa * ratio_ca * (np.array(self.distances[sec][:])
                                               <= 30)
                neuron[secNr:secNr + seclen].gIt = dendCa * (1. - ratio_ca) * (
                    np.array(self.distances[sec][:]) > 30) + somaCa * (
                        1. -
                        ratio_ca) * (np.array(self.distances[sec][:]) <= 30)

                #spines
                addSpines = np.array(self.distances[sec][:]) > spinedist
                noSpines = np.array(self.distances[sec][:]) <= spinedist
                neuron[
                    secNr:secNr +
                    seclen].gLeak = noSpines * g_leak + addSpines * g_leak_dend
                neuron[
                    secNr:secNr +
                    seclen].Cm = noSpines * Capacit + addSpines * Capacit_dend

            #APICAL
            if secNr in morpho_data['apical']:
                #ratio of Ka channels
                ratio_A = np.multiply(
                    1. - (1. / 300.) * np.array(self.distances[sec][:]),
                    1. - (1. / 300.) * np.array(self.distances[sec][:]) > 0)
                neuron[secNr:secNr + seclen].gKa_prox = ratio_A * apicalKa
                neuron[secNr:secNr +
                       seclen].gKa_dist = (1. - ratio_A) * apicalKa

                # Ca channels
                neuron[secNr:secNr + seclen].gCav = dendCa * ratio_ca * (
                    np.array(self.distances[sec][:]) >
                    30) + somaCa * ratio_ca * (np.array(self.distances[sec][:])
                                               <= 30)
                neuron[secNr:secNr + seclen].gIt = dendCa * (1. - ratio_ca) * (
                    np.array(self.distances[sec][:]) > 30) + somaCa * (
                        1. -
                        ratio_ca) * (np.array(self.distances[sec][:]) <= 30)

                #spines
                addSpines = np.array(self.distances[sec][:]) > spinedist
                noSpines = np.array(self.distances[sec][:]) <= spinedist
                neuron[
                    secNr:secNr +
                    seclen].gLeak = noSpines * g_leak + addSpines * g_leak_dend
                neuron[
                    secNr:secNr +
                    seclen].Cm = noSpines * Capacit + addSpines * Capacit_dend

            #AXON
            if secNr in morpho_data['axon']:
                #KL current
                addKL = np.array(self.distances[sec][:]) > 35
                neuron[secNr:secNr + seclen].gKL = addKL * axongL
                neuron[1:6].gKv = [40., 100., 500., 500., 500.
                                   ] * psiemens / um**2
                neuron[1:6].gKL = [20., 35., 125., 250., 0] * psiemens / um**2
                neuron[1:6].gNav = 4 * np.array(
                    [8000., 7000., 5000., 5000., 5000.]) * psiemens / um**2
                #                neuron[1:6].gNav = [8000.,7000.,5000.,5000.,5000.]*psiemens/um**2
                neuron[1:3].gCav = somaCa * ratio_ca
                neuron[1:3].gIt = somaCa * (1. - ratio_ca)

        # SET INITIAL VALUES
        set_init_nrn(neuron, Theta_low)

        return neuron
        # Run
        #####################################################
        weight_change1 = np.zeros(shape(hz_array))
        weight_change2 = np.zeros(shape(hz_array))

        print('Start running ...')

        for jj in range(size(hz_array)):
            pair_interval = 1000. / hz_array[jj] - 13.
            print('-> ' + str(hz_array[jj]) + 'Hz')

            set_init_syn(Syn_1, init_weight)
            set_init_syn(Syn_2, init_weight)

            # Initial values
            set_init_nrn(neuron, Theta_low)
            set_init_nrn(neuron2, Theta_low)
            N_input.v = V_rest
            N_input.s_trace = 0.

            run(100 * ms)

            # Pairings
            for ii in range(reps):
                neuron.I = 0. * pA
                neuron2.I = 0. * pA
                N_input.Idrive = 0. * mA
                ###### 1st SPIKE
                neuron2.main.I = 1000. * pA
                N_input.Idrive[zzz] = 2000. * pA
                run(3 * ms)
Esempio n. 3
0
    def run(self, morphodata):
        """run """

        # Set Biophysics
        neuron = self.biophysics(morphodata)
        neuron.run_regularly('Mgblock = 1./(1.+ exp(-0.062*vu2)/3.57)',
                             dt=br2.defaultclock.dt)
        # Record in every section
        #        monitor = self.v_record(neuron)
        monitor = br2.StateMonitor(neuron,
                                   'v',
                                   record=True,
                                   dt=20 * defaultclock.dt)

        morph_data = morphodata

        axo = len(morph_data['axon'])
        bsl = list(morph_data['basal'])
        apc = list(morph_data['apical'])
        #        dc = distal_compartments_Branco_eff
        #        pc = proximal_compartments_Branco
        dc = distal_compartments_Acker_eff
        pc = proximal_compartments_Acker

        #        nrComp = 10 #len(bsl)

        #####################################################
        # Input Neuron
        #####################################################
        Theta_low = morph_data['thetalow'] * br2.mV

        V_rest = 0. * br2.mV
        V_thresh = 0.5 * br2.mV

        NrInGroups = 4
        Nr_clust_dist = NrInGroups  #5     # Nr of clustered ensembles distally
        Nr_clust_prox = 0  #5    # Nr of clustered ensembles proximally
        Nr_scattered = 0  #5    # Nr of scattered ensembles
        Ens_size = 20  # Ensemble size
        GrpSize = Ens_size * NrInGroups
        NrEnsembles = (Nr_clust_dist + Nr_clust_prox + Nr_scattered)
        NrGroups = int(NrEnsembles / NrInGroups)
        NrIn = NrEnsembles * Ens_size  # nr of input neurons
        init_weight = .2  # initial weight

        signal_rate = 30. * br2.Hz  # activation rate of synapses
        t_stim = 50 * br2.ms  # stimulation length
        buffertime = 50 * br2.ms  # resting time between stimulations

        reps = 1  # nr of activations of each ensemble

        # Equations input neuron
        eqs_in = ''' 
        dv/dt = (V_rest-v)/ms: volt
        v2 = rand()<rate_v*dt :1 (constant over dt)
        rate_v :Hz
        ds_trace/dt = -s_trace/taux :1
        '''

        #####################################################
        # Create neurons
        #####################################################
        N_input = br2.NeuronGroup(NrIn,
                                  eqs_in,
                                  threshold='v+v2*2*V_thresh>V_thresh',
                                  reset='v=V_rest;s_trace+=x_reset*(taux/ms)',
                                  method='linear')  #

        Syn_1 = br2.Synapses(N_input,
                             neuron,
                             model=eq_1_nonPlast,
                             on_pre=eq_2_nonPlast,
                             method='heun')

        # distally clustered ensembles
        c_ndx = np.floor(np.random.rand(Nr_clust_dist) * len(dc))
        for cc in range(Nr_clust_dist):
            Syn_1.connect(i=range(cc * Ens_size, (cc + 1) * Ens_size),
                          j=neuron[dc[int(c_ndx[cc])]:dc[int(c_ndx[cc])] + 1])

        # proximally clustered ensembles
        c_ndx2 = np.floor(np.random.rand(Nr_clust_prox) * len(pc))
        for cc in range(Nr_clust_prox):
            Syn_1.connect(
                i=range(cc * Ens_size + Nr_clust_dist * Ens_size,
                        (cc + 1) * Ens_size + Nr_clust_dist * Ens_size),
                j=neuron[pc[int(c_ndx2[cc])]:pc[int(c_ndx2[cc])] + 1])

        # distributed ensembles
        rand_post_comp = np.floor(
            np.random.rand(Ens_size * Nr_scattered) * (len(bsl) - axo - 1) +
            axo + 1)
        for pp in range(Ens_size * (Nr_clust_dist + Nr_clust_prox), NrIn):
            Syn_1.connect(
                i=pp,
                j=neuron[int(rand_post_comp[pp - Ens_size *
                                            (Nr_clust_dist + Nr_clust_prox)]):
                         int(rand_post_comp[pp - Ens_size *
                                            (Nr_clust_dist + Nr_clust_prox)] +
                             1)])

        # Initialize the model
        neuron.v = EL
        neuron.I = 0. * br2.nA
        #        neuron.I[0] = 0.2*nA
        set_init_syn(Syn_1, init_weight)
        set_init_nrn(neuron, Theta_low)
        N_input.v = V_rest

        #####################################################
        # Run
        #####################################################
        print('Simulating ...')
        for tt in range(reps * NrGroups):
            print(tt)
            N_input.rate_v[np.mod(tt, NrGroups) *
                           GrpSize:np.mod(tt, NrGroups) * GrpSize +
                           GrpSize] = signal_rate
            br2.run(t_stim)
            N_input.rate_v = np.zeros(NrIn)
            br2.run(buffertime)
        print('Simulation Finished!')

        #store data in sec[1]
        for sec in self.sections.values():
            kk = sec[2]
            sec[1] = monitor.v[kk:kk + len(sec[0].x)]


#            sec[1] = monitor.gKL[kk:kk+len(sec[0].x)]

        plt.figure()
        plt.plot(monitor.t / br2.ms, monitor.v[0] / br2.mV)
        return monitor, neuron