コード例 #1
0
def main(args=None):
    """Main"""

    # Simulation general parameters
    data.dt = 0.1
    lb.h.dt = data.dt
    lb.h.steps_per_ms = 1.0 / lb.h.dt
    data.st_onset = 200.0
    data.st_duration = 200.
    data.TSTOP = 600
    data.TRIALS = 5
    data.Egmax = 1
    data.Igmax = 1
    data.Irev = -80
    data.Ensyn = 100
    data.Insyn = int(data.Ensyn * 0.2)
    data.bEnsyn = 200
    data.bInsyn = int(data.bEnsyn * 0.2)

    # Simulation CONTROL
    data.model = 'L23'
    data.locType = 'fixed'
    data.simType = 'rateIteration'
    data.fixedINPUT = False

    data.ACTIVE = True
    data.ACTIVEdend = True
    data.ACTIVEdendNa = True
    data.ACTIVEdendCa = True
    data.ACTIVEaxonSoma = True
    data.ACTIVEhotSpot = True
    data.SYN = True
    data.SPINES = False
    data.ICLAMP = False
    data.NMDA = True
    data.GABA = True
    data.BGROUND = True
    global model
    # Create neuron and add mechanisms
    if data.model == 'BS': model = lb.BS()
    if data.model == 'L23': model = lb.L23()
    if data.model == 'CELL': model = lb.CELL()
    if data.SPINES: lb.addSpines(model)
    if data.ACTIVE:
        lb.init_active(model,
                       axon=data.ACTIVEaxonSoma,
                       soma=data.ACTIVEaxonSoma,
                       dend=data.ACTIVEdend,
                       dendNa=data.ACTIVEdendNa,
                       dendCa=data.ACTIVEdendCa)
    if data.ACTIVEhotSpot: lb.hotSpot(model)

    # Generate synapse locations
    if data.locType == 'random':
        data.Elocs = genRandomLocs(data, model, data.Ensyn)
        data.Ilocs = genRandomLocs(data, model, data.Insyn)

    if data.locType == 'fixed':
        loadElocs = np.load('./Elocs.npy')
        data.Elocs = loadElocs[0:data.Ensyn]
        loadIlocs = np.load('./Ilocs.npy')
        data.Ilocs = loadIlocs[0:data.Insyn]

    if data.BGROUND:
        data.bElocs = genRandomLocs(data, model, data.bEnsyn)
        data.bIlocs = genRandomLocs(data, model, data.bInsyn)
        data.Elocs = np.vstack((data.Elocs, data.bElocs))
        data.Ilocs = np.vstack((data.Ilocs, data.bIlocs))

        # Hack for freezing the background
        # Uncomment first 2 lines and comment out last 2 for
        # random background

        #data.bElocs = loadElocs[data.Ensyn+1:]
        #data.bIlocs = loadIlocs[data.Insyn+1:]
        data.Elocs = loadElocs
        data.Ilocs = loadIlocs

    # Insert synapses
    if data.SYN:
        lb.add_AMPAsyns(model, locs=data.Elocs, gmax=data.Egmax)
        if data.NMDA: lb.add_NMDAsyns(model, locs=data.Elocs, gmax=data.Egmax)
        if data.GABA:
            lb.add_GABAsyns(model,
                            locs=data.Ilocs,
                            gmax=data.Igmax,
                            rev=data.Irev)

    # Insert IClamp
    data.iclampLoc = ['dend', 0.5, 28]
    data.iclampOnset = 50
    data.iclampDur = 250
    data.iclampAmp = 0

    if data.ICLAMP:
        if data.iclampLoc[0] == 'soma':
            lb.add_somaStim(model,
                            data.iclampLoc[1],
                            onset=data.iclampOnset,
                            dur=data.iclampDur,
                            amp=data.iclampAmp)
        if data.iclampLoc[0] == 'dend':
            lb.add_dendStim(model,
                            data.iclampLoc[1],
                            data.iclampLoc[2],
                            onset=data.iclampOnset,
                            dur=data.iclampDur,
                            amp=data.iclampAmp)

    #----------------------------------------------------------------------------
    # Data storage lists
    data.vdata, data.vDdata, data.gdata, data.idata, data.caDdata, data.vsec = [], [], [], [], [], []
    data.rates = []

    #----------------------------------------------------------------------------
    # Run simulation

    # Specific parameters
    data.rateRange = np.arange(8, 9, 10)
    data.lagRange = np.arange(-100, 110, 10)
    data.iRange = np.arange(-0.1, 0.2, 0.1)
    data.singleRate = 51
    data.tInterval = 1
    data.EbGroundRate = 2
    data.IbGroundRate = 2
    data.recordDend = True
    data.recordSec = False

    if data.simType == 'rateIteration':
        SIM_rateIteration(data, model, data.rateRange, data.BGROUND)
    if data.simType == 'iSteps':
        SIM_currentSteps(data, model, data.iRange, data.BGROUND)

    #----------------------------------------------------------------------------
    # Save data
    modelData = sc.emptyObject()
    lb.props(modelData)

    tstamp = time.strftime("sim%Y%b%d_%H%M%S")
    tstamp = 'temp'

    dataList = [data, modelData]
    fname = './' + tstamp + '.pkl'
    f = open(fname, 'wb')
    pickle.dump(dataList, f)
    f.close()
コード例 #2
0
def run_iclamp(iRange, run, nogui, vFileName):

    # Data saving object
    data = sc.emptyObject()

    # Simulation general parameters
    data.dt = 0.025
    lb.h.dt = data.dt
    lb.h.steps_per_ms = 1.0/lb.h.dt
    data.st_onset = 200.0
    data.st_duration = 200.
    data.TSTOP = 400


    # Simulation CONTROL
    data.model = 'L23'


    data.ACTIVE = True
    data.ACTIVEdend = True
    data.ACTIVEdendNa = True
    data.ACTIVEdendCa = True
    data.ACTIVEaxonSoma = True
    data.ACTIVEhotSpot = False             ##### Note: no hot spots!!!
    data.SYN = False
    data.SPINES = False
    data.ICLAMP = True
    data.NMDA = False
    data.GABA = False
    data.BGROUND = False

    model = lb.L23()
    print("Created cell: %s"%model.__class__)

    if data.SPINES: lb.addSpines(model)
    if data.ACTIVE: lb.init_active(model, axon=data.ACTIVEaxonSoma,
                                 soma=data.ACTIVEaxonSoma, dend=data.ACTIVEdend,
                                 dendNa=data.ACTIVEdendNa, dendCa=data.ACTIVEdendCa) 
    if data.ACTIVEhotSpot: lb.hotSpot(model)

    #data.iclampLoc = ['dend', 0.5, 28]
    data.iclampLoc = ['soma', 0.5]
    data.iclampOnset = 50
    data.iclampDur = 250
    data.iclampAmp = 0

    if data.ICLAMP:
        if data.iclampLoc[0]=='soma':
            lb.add_somaStim(model, data.iclampLoc[1], onset=data.iclampOnset,
                            dur=data.iclampDur, amp=data.iclampAmp)
        if data.iclampLoc[0]=='dend':
            lb.add_dendStim(model, data.iclampLoc[1], data.iclampLoc[2],
                     onset=data.iclampOnset, dur=data.iclampDur, amp=data.iclampAmp)

    h('count=0')
    h('forall {print "--------------- ", secname() \n count=count+1 } ')
    h('print "Number of sections: ", count')
    
    if run:
        data.vdata, data.vDdata, data.gdata, data.idata, data.caDdata, data.vsec = [], [], [], [], [], []
        data.rates = []


        data.recordDend = False
        data.recordSec = True

        data.iRange = iRange
        print("Running current clamp simulation with parameters:")
        for k in sorted(data.__dict__.keys()):
            print("    %s:\t\t%s"%(k, data.__dict__[k]))
        SIM_currentSteps(data, model, data.iRange, data.BGROUND)

        modelData = sc.emptyObject()
        lb.props(modelData)

        tstamp = time.strftime("sim%Y%b%d_%H%M%S")
        tstamp = 'temp'

        dataList = [data, modelData]
        fname = './test/'+tstamp+'.pkl'
        f = open(fname, 'wb')
        pickle.dump(dataList, f)
        f.close()


        times = data.taxis

        vFile = open(vFileName, "w")
        for i in range(len(times)):
            vFile.write('%s'%(times[i]/1000.0))
            for vd in data.vdata:
                vFile.write('\t%s'%(vd[i]/1000.0))
            vFile.write('\n')


        vFile.close()
        print('Written traces to: %s'%vFileName)

        if not nogui:

            import matplotlib.pyplot as plt
            fig = plt.figure() 


            for volts in data.vdata:
                plt.plot(times, volts)
            fig.show()


        print("Done!")

    return model
コード例 #3
0
            print("    %s:\t\t%s" % (k, data.__dict__[k]))
        model.stim.amp = step
        taxis, v, vD, g, i, ca, vsec = lb.simulate(model,
                                                   t_stop=data.TSTOP,
                                                   NMDA=data.NMDA,
                                                   recDend=data.recordDend)
        if data.NMDA == True:
            idata.append(np.sum(np.array(i).min(1)))
            gdata.append(np.sum(np.array(g).max(1)))
        storeSimOutput(data, v, vD, idata, gdata, r=0, ca=ca, vSec=vsec)
    data.taxis = taxis


#----------------------------------------------------------------------------
# Data saving object
data = sc.emptyObject()


def main(args=None):
    """Main"""

    # Simulation general parameters
    data.dt = 0.1
    lb.h.dt = data.dt
    lb.h.steps_per_ms = 1.0 / lb.h.dt
    data.st_onset = 200.0
    data.st_duration = 200.
    data.TSTOP = 600
    data.TRIALS = 5
    data.Egmax = 1
    data.Igmax = 1
コード例 #4
0
def save_sim(data, out_binary=False, out_vdend=False, out_pickle=False, outdir='data', rate='0', omega='0', iAMP='0'):
    if not os.path.exists(outdir):
        os.makedirs(outdir)

    modelData = sc.emptyObject()
    lb.props(modelData)
    description = 'Simulation type:'+data.simType+'. Fixed patterns,  distributed.'

    if data.NMDA:
        data.Ntype='NMDA'
    else:
        data.Ntype='AMPA'
    if data.NMDAkinetic:
        data.Ntype='NMDAk'
        
    if data.ACTIVE:
        if data.ACTIVEdend:
            data.act='Adend'
        else :
            data.act='Asoma'
    else:
        data.act='passive'


    if (data.stimType == 'allDend'): 
        filename=data.Ntype+'_ApN'+str(data.ApN)+'_'+data.locBias+'_'+data.act+'_r'+str(rate)+'_o'+str(omega)+'_g'
    elif (data.stimType == 'mixedori'): 
        filename=data.Ntype+'_ApN'+str(data.ApN)+'_'+data.locBias+'_'+data.act+'_r'+str(rate)+'_o'+str(omega)+'_i'+str(iAMP)+'_g'
        filename = filename + '_b' + str(data.inburstrate)
    elif (data.stimType == 'orientations'): 
        filename=data.Ntype+'_ApN'+str(data.ApN)+'_'+data.locBias+'_'+data.act+'_r'+str(rate)+'_o'+str(omega)+'_i'+str(iAMP)+'_g'
    elif (data.stimType == 'minis'): 
        filename=data.Ntype+'_ApN'+str(data.ApN)+'_'+data.locBias+'_'+data.act+'_r'+str(rate)+'_o'+str(omega)+'_i'+str(iAMP)+'_g'
    else :
        filename=data.Ntype+'_NAR'+str(data.NAR)+'_'+data.locBias+'_'+data.act+'_r'+str(rate)+'_o'+str(omega)+'_i'+str(iAMP)+'_g'
    #filename='temp'

    if out_pickle:
        dataList = [data, modelData]
        fname = './'+outdir+'/'+filename+'.pkl'
        f = open(fname, 'wb')
        pickle.dump(dataList, f)
        f.close()


    if out_binary:
        #---------------------------------------------
        # WRITE the response in a binary file to read it with R
        mat = np.array(data.vdata)
        bfname = './'+outdir+'/vdata_'+filename+'.bin'
        print bfname
        # create a binary file
        binfile = file(bfname, 'wb')
        # and write out two integers with the row and column dimension
        header = struct.pack('2I', mat.shape[0], mat.shape[1])
        binfile.write(header)
        # then loop over columns and write each
        for i in range(mat.shape[1]):
            ddata = struct.pack('%id' % mat.shape[0], *mat[:,i])
            binfile.write(ddata)
        binfile.close()

        if out_vdend:
            # WRITE the dendritic response
            nRep = len(data.vDdata)
            mat = np.array(data.vDdata[0])
            for i in range(1, nRep):
                mat = np.hstack((mat, data.vDdata[i]))
            
            bfname = './'+outdir+'/vDdata_'+filename+'.bin'
            # create a binary file
            binfile = file(bfname, 'wb')
            # and write out two integers with the row and column dimension
            header = struct.pack('2I', mat.shape[0], mat.shape[1])
            binfile.write(header)
            # then loop over columns and write each
            for i in range(mat.shape[1]):
                ddata = struct.pack('%id' % mat.shape[0], *mat[:,i])
                binfile.write(ddata)
            binfile.close()
        

        #---------------------------------------------
        # WRITE the location of the synapses        
        if (data.SYN):
            if (data.GABA) :
                Ilocs = np.array(data.Ilocs) 
                Ilocs[:,1] = 1 + Ilocs[:,1] # code that these are inhibitory synapses
                Elocs = np.array(data.Elocs)
                Locs = np.row_stack((Elocs, Ilocs))
            else :
                Locs = np.array(data.Elocs)

            bfname = './'+outdir+'/synlocs_'+filename+'.bin'
            # create a binary file
            binfile = file(bfname, 'wb')
            # and write out two integers with the row and column dimension
            header = struct.pack('2I', Locs.shape[0], Locs.shape[1])
            binfile.write(header)
            # then loop over columns and write each
            for i in range(Locs.shape[1]):
                ddata = struct.pack('%id' % Locs.shape[0], *Locs[:,i])
                binfile.write(ddata)
            binfile.close()

        #---------------------------------------------
        # Write the input spike train
        if (len(data.stim)>0):
            stim = data.stim
            bfname = './'+outdir+'/stim_'+filename+'.bin'
            # create a binary file
            binfile = file(bfname, 'wb')
            # and write out two integers with the row and column dimension
            header = struct.pack('2I', stim.shape[0], stim.shape[1])
            binfile.write(header)
            # then loop over columns and write each
            for i in range(stim.shape[1]):
                ddata = struct.pack('%id' % stim.shape[0], *stim[:,i])
                binfile.write(ddata)
            binfile.close()