Exemplo n.º 1
0
def main():
    # create 13 sections: s[0] -- s[12]
    s = [h.Section(name='s[%d]' % i) for i in xrange(13)]

    """
        Create the tree
        
              s0
        s1    s2         s3
        s4           s5      s6
        s7         s8 s9       s10 
    """
    for p, c in [[0, 1], [0, 2], [0, 3], [1, 4], [4, 7], [3, 5], [3, 6], [5, 8], [5, 9], [6, 10]]:
        s[c].connect(s[p])
    
    """
    and now s11 and s12, connected at the 0 ends
    """
    s[11].connect(s[12](0))
    
    # have NEURON print the topology
    h.topology()
    # now try it our way
    morph = MorphologyDB()
    for sec in s:
        print sec.name() + ':'
        print '  children:', ', '.join(child.name() for child in morph.children(sec))
        print '  parent:', morph.parent(sec).name() if morph.parent(sec) is not None else 'None'
    
    conns = morph.connections([s[i] for i in [2, 3, 4, 5, 6, 7, 9, 10, 11, 12]])
    for p1, p2 in conns:
        print '%s(%g)    %s(%g)' % (p1[0].name(), p1[1], p2[0].name(), p2[1])
    return 0
Exemplo n.º 2
0
def run_step(amplitude=0.4):
    parameters = {'scaling': 0.5,
                  'soma': {'Cm': 1., 'Ra': 100., 'El': -70., 'Rm': 10e3, 'area': 1500},
                  'proximal': {'Ra': 500., 'El': -70., 'L': 500., 'diam': 5.},
                  'distal': {'Ra': 500., 'El': -70., 'L': 200., 'area': 1500.},
                  'basal': {'Ra': 500., 'El': -70., 'L': 300., 'diam': 5.}}
    # the passive properties of the axon are the same as the soma
    parameters['axon'] = parameters['soma'].copy()
    # fast sodium current
    with_axon = True
    #parameters['nat'] = {'gbar_soma': 50, 'gbar_distal': 5, 'lambda': 50, 'dend_mode': 'exponential'}
    parameters['nat'] = {'gbar_soma': 100, 'dend_mode': 'linear'}
    #parameters['nat'] = {'gbar_soma': 100, 'scaling_dend': 0.2, 'dend_mode': 'constant'}
    #parameters['nat'] = {'gbar_soma': 100, 'dend_mode': 'passive'}
    if with_axon:
        parameters['nat']['gbar_hillock'] = 1000
        parameters['nat']['gbar_ais'] = 2500
    # delayed rectifier potassium
    #parameters['kdr'] = {'gbar_soma': 50, 'gbar_distal': 20, 'lambda': 50, 'dend_mode': 'exponential'}
    parameters['kdr'] = {'gbar_soma': 20, 'dend_mode': 'linear'}
    # persistent sodium
    #parameters['nap'] = {'gbar': 1e-4}
    # muscarinic potassium
    #parameters['km'] = {'gbar': 20}
    # ahp potassium
    #parameters['kahp'] = {'gbar': 300}
    # K-D
    #parameters['kd'] = {'gbar': 1e-4}
    # A-type potassium
    #parameters['kap'] = {'gbar': 10}
    # Ih current
    #parameters['ih'] = {'gbar_soma': 1e-2, 'scaling_dend': 10., 'half_dist': 100., 'lambda': 30., 'dend_mode': 'sigmoidal'}

    n = SimplifiedNeuron(parameters,with_axon=with_axon)
    #n = AThornyNeuron(parameters,with_axon=True)
    #n = ThornyNeuron(parameters,with_axon=True)
    #n = SWCNeuron(parameters,with_axon=False,convert_to_3pt_soma=False)
    #n.save_properties()
    h.topology()
    rec = make_voltage_recorders(n)
    stim = h.IClamp(n.soma[0](0.5))
    stim.delay = 200
    stim.amp = amplitude
    stim.dur = 500
    run(tend=1000,V0=-70)
    import pylab as p
    p.plot(rec['t'],rec['vsoma'],'k',label='Soma')
    p.plot(rec['t'],rec['vproximal'],'r',label='Proximal')
    p.plot(rec['t'],rec['vdistal'],'g',label='Distal')
    p.plot(rec['t'],rec['vbasal'],'b',label='Basal')
    if n.has_axon:
        p.plot(rec['t'],rec['vhillock'],'c',label='Hillock')
        p.plot(rec['t'],rec['vais'],'m',label='AIS')
        p.plot(rec['t'],rec['vaxon'],'y',label='Axon')
    p.xlabel('Time (ms)')
    p.ylabel('Membrane voltage (mV)')
    p.legend(loc='best')
    p.show()
Exemplo n.º 3
0
 def show_topology(self, id):
     if id < 0:
         for i in range(int(self.pc.nhost())):
             if(i==pc.id()):
                 h.topology()
             sys.stdout.flush()
             self.pc.barrier()
     else:
         if(id == self.pc.id()):
             h.topology()
Exemplo n.º 4
0
def run_synaptic_activation():
    n = CellA(El=-70., Rm=10e3, dend_scaling=0.5, with_synapses=True)
    rate = 2
    tend = 1000
    c = 0.5
    spike_times_c = syn.generate_poisson_spike_times(rate*c, tend*1e-3)[0]
    presynaptic_spike_times = []
    for synapse in n.synapses:
        if np.random.uniform() < 0.: # correlated
            spike_times_i = syn.generate_poisson_spike_times(rate*(1-c), tend*1e-3)[0]
            spike_times = np.sort(np.append(spike_times_i,spike_times_c))
        else: # uncorrelated
            spike_times = syn.generate_poisson_spike_times(rate, tend*1e-3)[0]
        synapse.set_presynaptic_spike_times(spike_times*1e3)
        presynaptic_spike_times.append(spike_times)
    h.topology()
    rec = make_recorders(n)
    for lbl in 'gampa','iampa':
        rec[lbl] = h.Vector()
    rec['gampa'].record(n.synapses[0].syn._ref_g)
    #rec['gnmda'].record(n.synapses[0].syn._ref_gnmda)
    rec['iampa'].record(n.synapses[0].syn._ref_i)
    #rec['inmda'].record(n.synapses[0].syn._ref_inmda)
    nu,edges,count = psth(presynaptic_spike_times,0.05,[0,tend*1e-3])

    run_model(tend)

    #ax = p.subplot(3,1,1)
    hndl = p.figure()
    p.plot(rec['t'],rec['vsoma'],'k',label='Soma')
    p.plot(1e3*(edges[:-1]+edges[1:])/2,nu*10,'m',label='Rate*10')
    #p.plot([0,tend],[rate,rate],'m')
    #p.plot([0,tend],[np.mean(nu)*10,np.mean(nu)*10],'b')
    p.plot(rec['t'],rec['vapical'],'r',label='Apical')
    p.plot(rec['t'],rec['vbasal'],'g',label='Basal')
    p.ylabel('Membrane voltage (mV)')
    p.legend(loc='best')
    #p.subplot(3,1,2,sharex=ax)
    #p.plot(rec['t'],np.array(rec['gampa'])*1e3,'k',label='AMPA')
    #p.plot(rec['t'],np.array(rec['gnmda'])*1e3,'r',label='NMDA')
    #p.legend(loc='best')
    #p.ylabel('Conductance (nS)')
    #p.subplot(3,1,3,sharex=ax)
    #p.plot(rec['t'],np.array(rec['iampa']),'k',label='AMPA')
    #p.plot(rec['t'],np.array(rec['inmda']),'r',label='NMDA')
    #p.legend(loc='best')
    p.xlabel('Time (ms)')
    #p.ylabel('Current (nA)')
    p.savefig('uncorrelated.pdf')
    p.show()
Exemplo n.º 5
0
    def fix_singlets(self, h):
        badsecs = []
        for sec in h.allsec():
            if sec.n3d() == 1:
                badsecs.append(sec)
                print(f'Fixing Singlet Section: {str(sec):s}')
                # print(dir(sec))
                parent = sec.trueparentseg()
                print(f'    Section has parent {str(parent):s} ')
                nparentseg = parent.sec.n3d() - 1
                x = parent.sec.x3d(nparentseg)
                y = parent.sec.y3d(nparentseg)
                z = parent.sec.z3d(nparentseg)
                d = parent.sec.diam3d(nparentseg)
                h.pt3dinsert(0, x, y, z, d, sec=sec)
                # print(dir(sec))  # could also get a child section, but if there are multiple, what do you do?
                # child = sec.children()
                # print('children: ', child)
                # print(f'    Section has child: {str(child):s}')
                # for c in child:
                #     print(c.x3d(0))
                # exit()
                # x = child.sec.x3d(0)
                # y = child.sec.y3d(0)
                # z = child.sec.z3d(0)
                # d = child.sec.diam3d(0)
                # h.pt3dadd(x, y, z, d, sec=sec)

        badsecs = []
        print('fn: ', self.fn)
        for sec in h.allsec():
            if sec.n3d() == 1:
                badsecs.append(sec)
                print('badsec: ', sec)   
        if len(badsecs) == 0:
            print('no more bad sections')
        h.topology()
def setup_sections(mc):
    tree = mc.comp1.tree
    pc = h.ParallelContext()

    ##############################################################
    # show mechanisms
    h.chk_mcomplex()

    ##############################################################
    # set up sections
    sections = []
    section_def_template = 'create %s[%d]'
    h(section_def_template % (mc.comp1.name, len(tree)))
    for sec in h.allsec():
        sections.append(sec)
    #for i in range(len(tree)):
    #    sections.append(h.Section(mc.comp1.name+'['+str(i)+']'))


    ##############################################################
    # connect sections
    for i,sec in enumerate(sections):
        parent = tree[i]
        #print "%d to %d" % (i, tree[i])
        if(parent != 0):
            sec.connect(sections[parent-1], 1, 0)

    ##############################################################
    # insert phisiology
    for i,sec in enumerate(sections):
        sec.insert('hh')
        #print mc.comp1.domain(i)
        #if(mc.comp1.mapping[1][i]==0):
        #    sec.insert('hh')
        #else:
        #    sec.insert('pas')

    ##############################################################
    # show topology    
    if(pc.id()==0):
        print tree
        h.topology()


    ##############################################################
    # test split
    cplx = h.multisplit()
    num_cmp = 0
    for sec in h.allsec():
        num_cmp += 1


    ##############################################################
    # show topology and result
    setup_time = 0
    calc_time = 0
    if(pc.id()==0):
        print "\n##############################################################"
        print "# setup time = %.2f sec" % setup_time
        print "# calc time = %.2f sec" % calc_time
        print "#"


    for i in range(int(pc.nhost())):
        pc.barrier()
        if(i==pc.id()):
            print "# %d/%d : %d compartment (%d)" % (pc.id(), pc.nhost(), num_cmp, cplx)

    print "#"
    for i in range(int(pc.nhost())):
        pc.barrier()
        if(i==pc.id()):
            h.topology()
nseg=80


axon1.nseg=nseg

ax1dia=500
L=10 #mm
axon1.L=L*1000  #um
axon1.diam=500 #um


axon1.insert('hhrx')

stim2=h.Ipulse2(0,sec=axon1)

h.topology()


temperature=np.genfromtxt('nerve_data_1_6s.csv',delimiter='	')
vec={}
vec['t']=h.Vector()	
vec['t'].record(h._ref_t)
for i in range(1,nseg):  # recording voltage traces at each node
	var='v%d'%i
	vec[var]=h.Vector()
	vec[var].record(axon1(i/nseg)._ref_v)

h.init()
h.dt=0.025
h.tstop=1600
post.L=10000
post.diam=dia
post.nseg=99


axon1.insert('hh')    #control section having HH kinetics, no heat dependence
axon2.insert('hhrx')  #modified section having modified HH kinetic for heat dependence


post.insert('hh')
#axon1.localtemp_hhrx=6.3
axon2.localtemp_hhrx=6.3  #in case the temperature is constant along axon2

#axon2.ek=-20 #changes potassium nernst potential of axon2 
h.topology()  #prints the topology of the geometry


#temp=np.genfromtxt('temp.csv',delimiter=',') #in case temperature of axon2 is custom defined- say gaussian

#for x in range(1,nseg):
#	axon2(x/nseg).hhrx.localtemp=temp[x]

# stimulation current injection

stim1=h.IClamp(0,sec=axon1)
stim1.delay=0.1+20 #ms
stim1.dur=1 #ms
stim1.amp=2000 #nA

tstop=50
Exemplo n.º 9
0
def print_report():
    
    for sec in h.allsec():
        print h.psection()
    print h.topology()