コード例 #1
0
ファイル: variants.py プロジェクト: mishra-lab/turnover
def run_fit():
    t = system.get_t(tmax=500)
    sims = odict([
        ('Turnover', get_sim('full', t=t)),
        ('No Turnover', get_sim('no-turnover', t=t)),
    ])
    for name, sim in sims.items():
        sim.init_outputs(
            system.get_outputs(spaces=sim.model.spaces,
                               select=sim.model.select,
                               t=sim.t,
                               names=['prevalence']))
        sim.solve()
        targets = system.get_targets(
            sim.model.spaces,
            sim.model.select,
            sim.outputs,
            t=sim.t,
        )
        if config.model == 'mort':
            sim.model.params['C'].update([25, 10,
                                          5])  # HACK to get low prev > 0
        calsim = calibration.CalibrationSim(
            name,
            sim=sim,
            targets=targets,
            verbose=True,
        )
        calsim.optimize(ftol=1e-3, plot='tmp.png')
        if config.save:
            utils.savejson(fname_fit(name), calsim.fitted_params().todict())
        else:
            print(dict(calsim.fitted_params().todict()))
コード例 #2
0
ファイル: spider.py プロジェクト: schoeu/spid
def gettypehash(url):
    rs = utils.gethtml(url)
    soup = BeautifulSoup(rs, "lxml")
    # parse main page info
    listitems = soup.select('#list_categories_categories_list_items > a')
    listinfos = [{'type': item['title'], 'url': item['href']} for item in listitems]
    # save json data
    utils.savejson(alljsonpath, listinfos)
コード例 #3
0
ファイル: spider.py プロジェクト: schoeu/spid
def getleavelsinfo():
    rootpath = './infolist'
    lpath = './leaveinfo'
    lists = os.listdir(path = rootpath)
    for i in range(len(lists)):
        p = os.path.join(rootpath, lists[i])
        if p.find('all') == -1 and os.path.splitext(p)[1] == '.json':
            data = utils.getjsondata(p)
            for item in data:
                if item['url']:
                    levlestr = utils.gethtml(item['url'])
                    vurl = getleavesinfo(levlestr)
                    print(item['title'], vurl)
                    if vurl:
                        item['vurl'] = vurl
            utils.savejson(os.path.join(lpath, lists[i]), data)
            print(os.path.join(lpath, lists[i]), ' done.')
コード例 #4
0
ファイル: spider.py プロジェクト: schoeu/spid
def savesubinfo():
    '''
        sub page info
    '''
    data = utils.getjsondata(alljsonpath)
    vinfo = []
    for i in data:
        purl = i['pageurl']
        vtype = i['type']
        # initial page num to 1
        pagenum = 1
        if purl:
            while True:
                tpurl = purl.replace('pagenum', str(pagenum))
                subrs = utils.gethtml(tpurl)
                slists = getsubinfo(subrs)
                if len(slists) == 0:
                    break
                vinfo.extend(slists)
                pagenum += 1

            utils.savejson('./infolist/{vtype}.json'.format(vtype = vtype), vinfo)
            print('共{count}条'.format(count=len(vinfo)))
            vinfo = []
コード例 #5
0
def bAP(Bnum = 34, TTX = False, Atype = False, vec = []):
    """
    Bnum: the recording branch
    -----------
    Outputs:
        json: soma and dendritc voltage recording and parameters info
    """
    timestr = time.strftime("%H%M")
    data = time.strftime("%m_%d")
    directory = 'Fig2/'
    # directory = 'Data_' + data +'/'
    Cell = de.CA229()
    ###########################################
    if (TTX == False and Atype == False):
        title = "Control_" + "Bnum_" + str(Bnum) + "_" + timestr
        ###########################################
        # Current injection in soma
        ###########################################
        ic = h.IClamp(Cell.soma[2](0.5))
        ic.dur = 1.75
        ic.delay = 150
        ic.amp = 3
    elif (TTX == True):
        Cell.TTX_bAP()
        Vstim = h.SEClamp(Cell.soma[2](0.5))
        Vstim.rs= 0.01
        Vstim.dur1 = 1e9
        vec.play(Vstim._ref_amp1, h.dt)
        title = "TTX_" + "Bnum_" + str(Bnum) + "_" + timestr
    else:
        Cell = de.CA229(KA_ratio = 0.0)
        ic = h.IClamp(Cell.soma[2](0.5))
        ic.dur = 1.75
        ic.delay = 150
        ic.amp = 3
        title = "4AP_" + "Bnum_" + str(Bnum) + "_" + timestr

    ###########################################
    ### Recording
    ###########################################
    t_vec = h.Vector()
    t_vec.record(h._ref_t)
    v_vec_soma = h.Vector()
    v_vec_soma.record(Cell.soma[2](0.5)._ref_v)

    dist = []
    Loc = []
    for seg in Cell.basal[Bnum]:
        Loc.append(seg.x)
        dist.append(h.distance(seg.x, sec = Cell.basal[Bnum]))

    v_vec_dend = []
    for loc in Loc:
        v_vec_dend.append(h.Vector())
        v_vec_dend[-1].record(Cell.basal[Bnum](loc)._ref_v)
    ###########################################
    ### Run & Plot
    ### Be careful, vmax does not have value before run
    ###########################################
    h.celsius = 32 # 32
    h.v_init =  -73.6927850677
    h.init()
    h.tstop = 300
    h.run()

#    pdb.set_trace()   #Debugging
    # print v_vec_soma[-1]
    # plt.clf()
    # plt.close()
    # plt.figure(figsize = (16, 6), dpi = 100)
    # plt.plot(t_vec, v_vec_soma, label = 'soma(0.5)', color = 'black')
    # for index, loc in enumerate(Loc):
    #     plt.plot(t_vec, v_vec_dend[index], label = 'dend-loc'+"{0:.2f}".format(loc))
    # plt.ylim([-90, 40])
    # plt.xlim([0, 300])
    # plt.legend(loc = 'upper right')
    # plt.ylabel('mV')
    # plt.xlabel('Time (ms)')
    # plt.title ("bAP")
    # ut.save(title, directory, ext="png", close=True, verbose=True)

    #######################
    data = ut.Vividict()
    data['Bnum'] = Bnum
    data['Loc'] = Loc
    data['dist'] = dist
    data['recording']['time'] = list(t_vec)
    data['recording']['soma']['voltage'] = list(v_vec_soma)
    for index, dist in enumerate(dist):
        data['recording']['dend']["{0:.2f}".format(dist)] = list(v_vec_dend[index])
    ut.savejson(data, title, directory, ext = "json", verbose = False)

    if (TTX == False and Atype == False):
        return v_vec_soma
コード例 #6
0
 def __init__(self, TTX = False, Pool1_num = 9, Pool2_num = 9, Beta = 0.067,
Cdur = 1, Syn_w1 = 0.01, Syn_w2 = 0.01, Loc = [0.2, 0.6]):
    """
    Model the Glumate Stimulation.
    Model the Receptors in 2 pools:
        Pool 1: AMPA + NMDA (same synaptic weight, represent spine conductance)
        Pool 2: NMDA only (represent the extrasyanptic NMDARs)

    Parameters:
    -----------
    TTX: True or False.
        True: setting all the sodium channel conductance to 0 to mimic
              TTX application in experiments
        False: default
    Pool1_num: syanptic AMPA/NMDA numbers
    Pool2_num: extrasyanptic NMDA numbers
    Beta: parameter for NMDA Receptors
    Cdur: parameter for NMDA Receptors
    Syn_w1: the syanptic weight of AMPA/NMDA receptors in pool1
    Syn_w2: the syanptic weight of AMPA/NMDA receptors in pool2
    Loc: the stimulation location
    -----------
    Outputs:
        Figures: recording from soma and 3 different locations from basal dendrites
        json: soma and dendritc voltage recording and parameters info
    """
    Cell = de.CA229(HVA_ratio = 0.0, LVA_ratio = 0.0)
    self.Cell = Cell
    # Can adjust channel conductance ratio here:
    # eg. Cell = CA229(KA_ratio = 0.5)
    ###########################################
    timestr = time.strftime("%H%M")
    data = time.strftime("%m_%d")
    # directory = 'Data_' + data +'/'
    directory_root = 'Fig3/'
    directory = directory_root + 'DMS/Plot/'
    # directory = directory_root + 'DMS/Analysis/'

    if (TTX == True):
        Cell.TTX()
        title = "TTX_Pool1_"+ str(Pool1_num) + "_Pool2_" + str(Pool2_num) + "_NMDA_Beta_" + \
            str(Beta) + "_NMDA_Cdur_"+str(Cdur)+ "_Pool1_W_" + str(Syn_w1) + \
            "_Pool2_W_" + str(Syn_w2) + "_"+ timestr
    else:
        title = "Pool1_"+ str(Pool1_num) + "_Pool2_" + str(Pool2_num) + "_NMDA_Beta_" + \
            str(Beta) + "_NMDA_Cdur_"+str(Cdur)+ "_Pool1_W_" + str(Syn_w1) + \
            "_Pool2_W_" + str(Syn_w2) + "_"+ timestr

    ###########################################
    # Adding Pool 1
    ###########################################
    ##### AMPA
    SynAMPA = []
    nc_AMPA = []
    SynNMDA = []
    nc_NMDA = []
    self.SynAMPA = SynAMPA
    self.nc_AMPA = nc_AMPA
    self.SynNMDA = SynNMDA
    self.nc_NMDA = nc_NMDA

    ###########################################
    loc1 = list(np.linspace(Loc[0], Loc[1], Pool1_num))
    ###########################################
    # Loc and time delay set up
    delay1 = random_2(10, 50 + int(Syn_w1*50), Pool1_num)
    # delay1 = random_beta(10, 50 + int(Syn_w1*50), Pool1_num)
    ns = h.NetStim()
    self.ns = ns
    ns.interval = 20
    ns.number = 1
    ns.start = 190
    ns.noise = 0
    ###########################################
    for i in range(Pool1_num):
        ###########################
        # Adding AMPA
        SynAMPA.append(h.AMPA(Cell.basal[34](loc1[i])))
        SynAMPA[-1].gmax = 0.05
        nc_AMPA.append(h.NetCon(ns, SynAMPA[i]))
        nc_AMPA[-1].delay = delay1[i]
        nc_AMPA[-1].weight[0] = Syn_w1
        ###########################
        #Adding NMDA
        SynNMDA.append(h.NMDA(Cell.basal[34](loc1[i])))
        SynNMDA[-1].gmax = 0.005
        SynNMDA[-1].Beta = Beta
        SynNMDA[-1].Cdur = Cdur
        nc_NMDA.append(h.NetCon(ns, SynNMDA[i]))
        nc_NMDA[-1].delay = delay1[i]
        nc_NMDA[-1].weight[0] = Syn_w1

    ###########################################
    # Adding Pool 2
    ###########################################
    ExNMDA = []
    nc_ExNMDA = []
    self.ExNMDA = ExNMDA
    self.nc_ExNMDA = nc_ExNMDA

    loc2 = list(np.linspace(Loc[0], Loc[1], Pool2_num))
#    delay2 = list(np.linspace(5, 10, Pool2_num))
    delay2 = random_2(15, 55 + int(Syn_w2*60), Pool2_num)
    # delay2 = random_beta(15, 55 + int(Syn_w2*60), Pool2_num)
    for i in range(Pool2_num):
        ###########################
        # Adding extrasyanptic NMDA
        ExNMDA.append(h.NMDA(Cell.basal[34](loc2[i])))
        ExNMDA[-1].gmax = 0.005
        ExNMDA[-1].Beta = Beta
        ExNMDA[-1].Cdur = Cdur

        nc_ExNMDA.append(h.NetCon(ns, ExNMDA[i]))
        nc_ExNMDA[-1].delay = delay2[i]
        nc_ExNMDA[-1].weight[0] = Syn_w2

    ###########################################
    ### Recording
    ###########################################
    t_vec = h.Vector()
    t_vec.record(h._ref_t)
    v_vec_soma = h.Vector()
    v_vec_dend1 = h.Vector()
    v_vec_dend2 = h.Vector()
    v_vec_dend3 = h.Vector()
    cai_soma = h.Vector()
    cai_dend = h.Vector()

    v_vec_soma.record(Cell.soma[2](0.5)._ref_v)
    v_vec_dend1.record(Cell.basal[34](0.8)._ref_v)
    v_vec_dend2.record(Cell.basal[34](0.5)._ref_v)
    v_vec_dend3.record(Cell.basal[34](0.3)._ref_v)
    cai_soma.record(Cell.soma[2](0.5)._ref_cai)
    cai_dend.record(Cell.basal[34](0.3)._ref_cai)


    ###########################################
    ### Run & Plot
    ###########################################
    h.celsius = 32
    h.v_init =  -73.6927850677
    h.init()
    h.tstop = 1000
    h.run()

#    pdb.set_trace()   #Debugging
    # print v_vec_soma[-1]
    # plt.clf()
    # plt.close()
    # plt.figure(figsize = (16, 6), dpi = 100)
    # plt.plot(t_vec, v_vec_soma, label = 'soma(0.5)', color = 'black')
    # plt.plot(t_vec, v_vec_dend1, label = 'bdend[34](0.8)', color = 'red')
    # plt.plot(t_vec, v_vec_dend2, label = 'Basal[34](0.5)', color = 'blue')
    # plt.plot(t_vec, v_vec_dend3, label = 'Basal[34](0.3)', color = 'green')
    # plt.ylim([-90, 40])
    # plt.xlim([0, 800])
    # plt.legend(loc = 'best')
    # plt.ylabel('mV')
    # plt.xlabel('Time (ms)')
    # plt.title ("Glumate Receptor Activated Plateau Potential")
    #
    # save(title, directory, ext="png", close=True, verbose=True)

    #######################
    # Plot the intracelluar calcium concentration
    # plt.clf()
    # plt.close()
    # plt.figure(figsize = (16, 6), dpi = 100)
    # plt.plot(t_vec, cai_soma, label = 'soma(0.5)', color = 'black')
    # #plt.plot(t_vec, cai_dend, label = 'bdend[34](0.3)', color = 'red')
    #
    # # plt.ylim([-90, 60])
    # plt.xlim([0, 800])
    # plt.legend(loc = 'best')
    # plt.ylabel('mM')
    # plt.xlabel('Time (ms)')
    # plt.title ("Calcium concentration")
    # title1 = "Calcium_" + title
    # ut.save(title1, directory, ext="png", close=True, verbose=True)

    data = ut.Vividict()
    data['SynAMPA']['num'] = Pool1_num
    data['SynAMPA']['locs'] = loc1
    data['SynAMPA']['weight'] = Syn_w1
    data['SynNMDA']['num'] = Pool1_num
    data['SynNMDA']['locs'] = loc1
    data['SynNMDA']['weight'] = Syn_w1
    data['SynNMDA']['Beta'] = Beta
    data['SynNMDA']['Cdur'] = Cdur
    data['ExNMDA']['num'] = Pool2_num
    data['ExNMDA']['locs'] = loc2
    data['ExNMDA']['weight'] = Syn_w2
    data['ExNMDA']['Beta'] = Beta
    data['ExNMDA']['Cdur'] = Cdur

    data['recording']['time'] = list(t_vec)
    data['recording']['soma']['voltage'] = list(v_vec_soma)
    data['recording']['basal_34']['voltage_0.8'] = list(v_vec_dend1)
    data['recording']['basal_34']['voltage_0.5'] = list(v_vec_dend2)
    data['recording']['basal_34']['voltage_0.3'] = list(v_vec_dend3)
    data['recording']['soma']['ica'] = list(cai_soma)
    data['recording']['basal_34']['ica_0.3'] = list(cai_dend)


    ut.savejson(data, title, directory, ext = "json", verbose = False)
コード例 #7
0
def Glu_Stim(Bnum=34,
             TTX=False,
             Pool1_num=9,
             Pool2_num=9,
             Syn_w1=0.01,
             Syn_w2=0.01,
             Loc=[0.2, 0.6],
             DenLoc=0.5):
    """
    Model the Glumate Stimulation.
    Model the Receptors in 2 pools:
        Pool 1: AMPA + NMDA (same synaptic weight, represent spine conductance)
        Pool 2: NMDA only (represent the extrasyanptic NMDARs)

    Parameters:
    -----------
    Bnum: the number of basal branch to explore
    TTX: True or False.
        True: setting all the sodium channel conductance to 0.
        False: default
    Pool1_num: syanptic AMPA/NMDA numbers
    Pool2_num: extrasyanptic NMDA numbers
    Syn_w1: the syanptic weight of AMPA/NMDA receptors in pool1
    Syn_w2: the syanptic weight of AMPA/NMDA receptors in pool2
    Loc: the stimulation location
    DenLoc: the targeted recording location on dendrite
    -----------
    Outputs:
        Figures: recording from soma and 3 different locations from basal dendrites
        json: soma and dendritc voltage recording and parameters info
    """
    Cell = de.CA229()
    timestr = time.strftime("%Y%m%d-%H%M")
    data = time.strftime("%m_%d")
    directory_root = "Fig5/Major/"

    L1 = "{:.2f}".format(Loc[0])
    L2 = "{:.2f}".format(Loc[1])
    if (TTX == True):
        Cell.TTX()
        directory = directory_root + "B" + str(
            Bnum) + "/Loc" + L1 + "_" + L2 + "/TTX/"
        title =  "TTX_Pool1_"+ \
        str(Pool1_num) + "_Pool2_" + str(Pool2_num) + \
        "_Pool1_W_" + str(Syn_w1) + \
        "_Pool2_W_" + str(Syn_w2) + "_"+ timestr
    else:
        directory = directory_root + "B" + str(
            Bnum) + "/Loc" + L1 + "_" + L2 + "/N/"
        title = "Pool1_"+ \
        str(Pool1_num) + "_Pool2_" + str(Pool2_num) + \
        "_Pool1_W_" + str(Syn_w1) + \
        "_Pool2_W_" + str(Syn_w2) + "_"+ timestr

    ###########################################
    # Adding Pool 1
    ###########################################
    ##### AMPA
    SynAMPA = []
    nc_AMPA = []
    SynNMDA = []
    nc_NMDA = []

    loc1 = list(np.linspace(Loc[0], Loc[1], Pool1_num))
    ###########################################
    delay1 = random_2(10, 20 + int(Syn_w1 * 50), Pool1_num)
    ns = h.NetStim()
    ns.interval = 20
    ns.number = 1
    ns.start = 190
    ns.noise = 0

    for i in range(Pool1_num):
        ###########################
        # Adding AMPA
        SynAMPA.append(h.AMPA(Cell.basal[Bnum](loc1[i])))
        SynAMPA[-1].gmax = 0.05
        nc_AMPA.append(h.NetCon(ns, SynAMPA[i]))
        nc_AMPA[-1].delay = delay1[i]
        nc_AMPA[-1].weight[0] = Syn_w1
        ###########################
    for i in range(Pool1_num):
        tempNMDA = h.nmda(Cell.basal[Bnum](loc1[i]))
        tempNMDA.gmax = 0.005 * Syn_w1
        tempNMDA.onset = delay1[i] + ns.start
        SynNMDA.append(tempNMDA)
    ###########################################
    # Adding Pool 2
    ###########################################
    ExNMDA = []
    nc_ExNMDA = []

    loc2 = list(np.linspace(Loc[0], Loc[1], Pool2_num))
    delay2 = random_2(15, 25 + int(Syn_w2 * 60), Pool2_num)
    for i in range(Pool2_num):
        ###########################
        # Adding extrasyanptic NMDA
        tempNMDA2 = h.nmda(Cell.basal[Bnum](loc2[i]))
        tempNMDA2.gmax = 0.005 * Syn_w2
        tempNMDA2.onset = delay2[i] + ns.start
        ExNMDA.append(tempNMDA2)

    ###########################################
    ### Recording
    ###########################################
    t_vec = h.Vector()
    t_vec.record(h._ref_t)
    v_vec_soma = h.Vector()
    v_vec_dend1 = h.Vector()
    v_vec_dend2 = h.Vector()
    v_vec_dend3 = h.Vector()
    v_vec_dend = h.Vector()

    v_vec_soma.record(Cell.soma[2](0.5)._ref_v)
    v_vec_dend1.record(Cell.basal[Bnum](0.8)._ref_v)
    v_vec_dend2.record(Cell.basal[Bnum](0.5)._ref_v)
    v_vec_dend3.record(Cell.basal[Bnum](0.3)._ref_v)
    v_vec_dend.record(Cell.basal[Bnum](DenLoc)._ref_v)

    ###########################################
    ### Run & Plot
    ###########################################
    h.celsius = 32
    h.v_init = -73.6927850677
    h.init()
    h.tstop = 1000
    h.run()

    #    pdb.set_trace()   #Debugging
    # plt.figure(figsize = (16, 6), dpi = 100)
    # plt.plot(t_vec, v_vec_soma, label = 'soma(0.5)', color = 'black')
    # plt.plot(t_vec, v_vec_dend1, label = 'Basal['+str(Bnum)+'](0.8)', color = 'red')
    # plt.plot(t_vec, v_vec_dend2, label = 'Basal['+str(Bnum)+'](0.5)', color = 'blue')
    # plt.plot(t_vec, v_vec_dend3, label = 'Basal['+str(Bnum)+'](0.3)', color = 'green')
    # plt.ylim([-90, 40])
    # plt.xlim([0, 700])
    # plt.legend(loc = 'best')
    # plt.ylabel('mV')
    # plt.xlabel('Time (ms)')
    # plt.title ("Glumate Receptor Activated Plateau Potential")
    # save(title, directory, ext="png", close=True, verbose=True)

    data = ut.Vividict()
    data['TTX'] = TTX
    data['SynAMPA']['num'] = Pool1_num
    data['SynAMPA']['locs'] = Loc
    data['SynAMPA']['weight'] = Syn_w1
    data['SynNMDA']['num'] = Pool1_num
    data['SynNMDA']['locs'] = Loc
    data['SynNMDA']['weight'] = Syn_w1
    data['ExNMDA']['num'] = Pool2_num
    data['ExNMDA']['locs'] = Loc
    data['ExNMDA']['weight'] = Syn_w2

    data['recording']['time'] = list(t_vec)
    data['recording']['soma']['voltage'] = list(v_vec_soma)
    data['recording']['basal']['voltage_0.8'] = list(v_vec_dend1)
    data['recording']['basal']['voltage_0.5'] = list(v_vec_dend2)
    data['recording']['basal']['voltage_0.3'] = list(v_vec_dend3)
    data['recording']['basal']['voltage_input'] = list(v_vec_dend)

    ut.savejson(data, title, directory, ext="json", verbose=False)