Beispiel #1
0
  def initialize():
      global Epas
      h.celsius = celsius
      for sec in h.soma:
          h.distance()    
 
      for sec in h.allsec():
          sec.v = Epas
          sec.e_pas = Epas
  
          sec.insert("pas")
          sec.e_pas = Epas
          sec.g_pas = 1/Rm
          sec.Ra = rall
          sec.cm = cap
          sec.gnabar_hh2 = 0 
          sec.gkbar_hh2 = 0
          dist = h.distance(0.5)
          # sec.gcabar_it2 = gcat_func(dist)
          sec.gcabar_it2 = gcat
      for sec in h.soma:
          sec.gnabar_hh2 = gna 
          sec.gkbar_hh2 = gkdr
          # sec.gcabar_it2 = 0.1054*gcat
          sec.gcabar_it2 = gcat
                                                                           
      h.finitialize()       
      h.fcurrent()     
      cvode.re_init()
def simulate(pool, tstop=1000, vinit=-55):
    ''' simulation control 
    Parameters
    ----------
    cell: NEURON cell
        cell for simulation
    tstop: int (ms)
        simulation time
    vinit: int (mV)
        initialized voltage
    '''
    h.finitialize(vinit)
    for i in pool:
        cell = pc.gid2cell(i)
        balance(cell)
    if h.cvode.active():
        h.cvode.active()
    else:
        h.fcurrent()
    h.frecord_init()
    h.tstop = tstop
    h.v_init = vinit
    pc.set_maxstep(0.5)
    h.stdinit()
    pc.psolve(tstop)
Beispiel #3
0
  def initialize(Tdist):
      global Epas
      h.celsius = celsius
      for sec in h.soma:
          h.distance()    
 
      for sec in h.allsec():
          sec.v = Epas
          sec.e_pas = Epas
          sec.insert("pas")
          sec.e_pas = Epas
          sec.g_pas = 1/Rm
          sec.Ra = rall
          sec.cm = cap
          sec.gnabar_hh2 = 0 
          sec.gkbar_hh2 = 0
          for seg in sec:
              if Tdist == 1:
                  seg.gcabar_it2 = gcat
              if Tdist == 2:
                  seg.gcabar_it2 = gcat * (1 + 0.04 * (h.distance(0) + sec.L * seg.x)) * 0.10539397661220173
              
      for sec in h.soma:
          sec.gnabar_hh2 = gna 
          sec.gkbar_hh2 = gkdr
          if Tdist == 1:
              seg.gcabar_it2 = gcat
          if Tdist == 2:
              seg.gcabar_it2 = gcat * 0.10539397661220173
                                                                           
      h.finitialize()       
      h.fcurrent()     
      cvode.re_init()
 def initialise(self, vrest=-65):
     """
     Initialise the model, to launch before each simulations
     """
     for sec in h.allsec():
         h.finitialize(vrest, sec)
         h.fcurrent(sec)
     h.frecord_init()
Beispiel #5
0
def run_single_simulation(config, interactive):
    axon = Axon(config)
    axon.insert_stim(config['stim_position'], config['stim_amplitude'],
            config['stim_start_time'], config['stim_duration'])

    # set up recording vectors for python plots and the csv file
    t = h.Vector()
    t.record(h._ref_t)

    num_v_traces = config['num_v_traces']
    v_traces = []
    for i in range(num_v_traces):
        v = h.Vector()
        v.record(axon.section_at_f(
            # record at num_v_traces points along the axon, equally spaced
            # from eachother and from the end points (since we don't care
            # about things like the impedance mismatch at the ends)
            (i + 1) * 1.0 / (num_v_traces + 1))
            (Axon.middle)._ref_v)
        v_traces.append(v)

    # set up NEURON plotting code (if we're in an interactive session)
    if interactive:
        g = h.Graph()
        g.size(0, config['integration_time'], -80, 55)
        for i in range(num_v_traces):
            g.addvar('v(0.5)',
                    sec=axon.section_at_f((i+1) * 1.0 / (num_v_traces + 1)))

    # initialize the simulation
    h.dt = config['max_time_step']
    tstop = config['integration_time']
    h.finitialize(config['initial_membrane_potential'])
    h.fcurrent()

    # run the simulation
    if interactive:
        g.begin()
        while h.t < tstop:
            h.fadvance()
            g.plot(h.t)
        g.flush()
    else:
        while h.t < tstop:
            h.fadvance()

    # save the data as a csv
    with open(config['csv_filename'], 'w') as csv_file:
        # start with a header of the form "t_ms, V0_mV, V1_mv, V2_mV,..."
        csv_file.write(", ".join(
            ["t_ms"] + ["V{0}_mV".format(i) for i in range(num_v_traces)]
            ) + "\n")

        # write the time and each of the recorded voltages at that time
        for row in zip(t, *v_traces):
            csv_file.write(", ".join([str(x) for x in row]) + "\n")
Beispiel #6
0
 def init(self):
     """Set the vm_init from the spin button and prepare the simulator"""
     
     if not self.manager.refs.has_key('VecRef') :
         message = "No vector Created. Create at least one vector to run the simulation"
         logger.info(message)
         self.ui.statusbar.showMessage(message, 3500)
         return False
     else:
         v_init = self.ui.vSpinBox.value()
         # Set the v_init
         h.v_init = v_init
         h.finitialize(v_init)
         h.fcurrent()
     
         # Reset the time in the GUI
         self.ui.time_label.setNum(h.t)
         return True
    def min_sim(self, TSTOP=100):
        """
        Launch a minimal simulation to test the model and determine its resting potential empirically
        """
        vrec = h.Vector()
        vrec.record(self.soma(0.5)._ref_v)

        for sec in h.allsec():
            h.finitialize(-65, sec)
            h.fcurrent(sec)
        h.frecord_init()

        while h.t < TSTOP: #Launch a simulation
            h.fadvance()

        vrest = np.array(vrec)[-1]

        return vrest
Beispiel #8
0
def is_blocked(axon):
    v = h.Vector()
    v.record(axon.section_at_x(axon.config['block_test_position'])
        (Axon.middle)._ref_v)

    # initialize the simulation
    h.dt = axon.config['max_time_step']
    tstop = axon.config['integration_time']
    v_init = axon.config['initial_membrane_potential']
    h.finitialize(v_init)
    h.fcurrent()

    # run the simulation
    while h.t < tstop:
        h.fadvance()

    if max(v) >= axon.config['block_test_threshold']:
        return False
    else:
        return True
def simulate(cell, tstop=1500, vinit=-55):
    ''' simulation control 
    Parameters
    ----------
    cell: NEURON cell
        cell for simulation
    tstop: int (ms)
        simulation time
    vinit: int (mV)
        initialized voltage
    '''
    h.finitialize(vinit)
    balance(cell)
    if h.cvode.active():
        h.cvode.active()
    else:
        h.fcurrent()
    h.frecord_init()
    h.tstop = tstop
    h.v_init = vinit
    h.run()
Beispiel #10
0
for i_syn in range(N_RHESYN):
	print i_syn
	h(DEND_IDS[i_syn]+' ActiveDendrites.append()') # fill in the section list
	h('RHESYN['+str(i_syn)+'] = new Spine()') # instantiation of the Spine template
	h('RHESYN['+str(i_syn)+'].neck RHESpines.append()') # neck added to the section list
	h('RHESYN['+str(i_syn)+'].spine RHESpines.append()') # spine added to the section list
	h(DEND_IDS[i_syn]+' connect RHESYN['+str(i_syn)+'].neck(1), '+RHESYN_POSITIONS[i_syn]+' ') # connection to the dendrite
	h('RHESYN['+str(i_syn)+'].spine I_RHESYN['+str(i_syn)+'] = new IClamp(0)') # instatiation of the IClamp
	h('I_RHESYN['+str(i_syn)+'].del = 0') # always on
	h('I_RHESYN['+str(i_syn)+'].dur = 1e12') # never stops
          
#initialization of neuron
h.dt =stepsize
h('Vrest = -74.25')
h.finitialize(h.Vrest)
h.fcurrent()

now=time.localtime(time.time())
filename="NRN"+time.strftime("%y%m%d%H%M",now) + ".dat"
file =open(filename,'w')

ct = 0

plotA = False
# plot branches
if (plotA):
	h('objref s')
	h('s = new Shape()')
	h('s = fast_flush_list.object(fast_flush_list.count()-1)')
#	h('fast_flush_list.append(s)')
	h('s.view(-50,-150,500,550,1680,0,840,1050) //view(mleft, mbottom, mwidth, mheight, sleft, stop,swidth, sheight)')
def initialize():
	h.finitialize()
	h.fcurrent()
def initialize(v):
	h.finitialize(v)
	h.fcurrent()
def initialize_rest():
	h.finitialize(-65)
	h.fcurrent()
Beispiel #14
0
def pythonsim(simid, rundir, inputdir, modeldir, outputdir, currentstr, vinitstr, delaystr, stimdurationstr, timestepstr, simstopstr, recordintervalstr):
	import neuron
	from neuron import h
	Section = h.Section

	# All the mods are in the simulator directory
	# Apparently this is already done by  the import, if we use the "-dll" 
	# option in the call to nrniv. Since the import behavior seems to be 
	# inconsistent without the "-dll" option, we do it this way.
	#neuron.load_mechanisms(".")  # NOT USING LOAD_MECHANISMS HERE
	# local auto-modified version for no gui and control over certain ion 
	#  channels is in the run dir
	h.xopen(rundir + '/' + simid + '.hoc') 

	timefilepath = outputdir + '/' + 'timedata.txt'
	timefile = h.File()
	timefile.wopen(timefilepath, 'w')
	
	voltagefilepath = outputdir + '/' + 'voltagedata.txt'
	voltagefile = h.File()
	voltagefile.wopen(voltagefilepath, 'w')

	current = float(currentstr)
	vinit = float(vinitstr)
	delay = float(delaystr)
	stimduration = float(stimdurationstr)
	timestep = float(timestepstr)
	simstop = float(simstopstr)
	recordinterval = float(recordintervalstr)
	
	# ----- Current Injection
	stim = h.IClamp(0.5, sec=h.soma)
	stim.amp = current  # nA
	stim.delay = delay  # msec
	stim.dur = stimduration # msec

	# ----- Simulation Control (now mostly done through input arguments)
	h.dt = timestep

	# Preallocate record vectors for speed
	# Requires recordinterval to be an exact multiple of tstep.
	recordlength = simstop/recordinterval + 1
	testt = h.Vector(recordlength)
	testv = h.Vector(recordlength)

    # Recording at the soma
	testt.record(h._ref_t, recordinterval)
	testv.record(h.soma(0.5)._ref_v, recordinterval)

	# Initialize
	h.finitialize(vinit)
	h.fcurrent()

	# Integrate
	while h.t <= simstop:
		v = h.soma.v
		h.fadvance()

	# Shutdown
	testt.printf(timefile, '%f\n')
	testv.printf(voltagefile, '%f\n')
	timefile.close()
	voltagefile.close()
	return(0)