示例#1
0
def make_vclamp( name = 'Vclamp', parent = '/library' ):
    if moose.exists( '/library/' + name ):
        return
    vclamp = moose.VClamp( parent + '/' + name )
    vclamp.mode = 0     # Default. could try 1, 2 as well
    vclamp.tau = 0.2e-3 # lowpass filter for command voltage input
    vclamp.ti = 20e-6   # Integral time
    vclamp.td = 5e-6    # Differential time. Should it be >= dt?
    vclamp.gain = 0.00005   # Gain of vclamp ckt.

    # Connect voltage clamp circuitry
    addmsg1 = moose.Mstring( vclamp.path + '/addmsg1' )
    addmsg1.value = '.  currentOut  ..  injectMsg'
    addmsg2 = moose.Mstring( vclamp.path + '/addmsg2' )
    addmsg2.value = '.. VmOut . sensedIn'

    return vclamp
示例#2
0
 def testVClamp(self):
     clamp = moose.VClamp('%s/vclamp' % (self.model_container.path))
     moose.connect(clamp, 'currentOut', self.cell.soma, 'injectMsg')
     moose.connect(self.cell.soma, 'VmOut', clamp, 'sensedIn')
     self.pulsegen.delay[0] = 1e9 # disable current clamp
     self.pulsegen = moose.PulseGen('%s/vclampCommand' % (self.model_container.path))
     self.pulsegen.delay[0] = 100e-3
     self.pulsegen.width[0] = 100e-3
     self.pulsegen.level[0] = -10e-3
     moose.connect(self.pulsegen, 'outputOut', clamp, 'set_command')
     tab = moose.Table('%s/command' % (self.data_container.path))
     moose.connect(tab, 'requestData', clamp, 'get_command')
     for ii in moose.wildcardFind('/##[TYPE=VClamp]'):
         print ii.path
     self.runsim(simtime)
     print tab, len(tab.vec)
     pylab.plot(pylab.linspace(0, simtime, len(tab.vec)), tab.vec, 'kx')
     self.plot_vm()
示例#3
0
文件: vclamp.py 项目: tdeuling/moose
def vclamp_demo(simtime=50.0, dt=1e-2):
    ## It is good practice to modularize test elements inside a
    ## container
    container = moose.Neutral('/vClampDemo')
    ## Create a compartment with properties of a squid giant axon
    comp = SquidAxon('/vClampDemo/axon')
    # Create and setup the voltage clamp object
    clamp = moose.VClamp('/vClampDemo/vclamp')
    ## The defaults should work fine
    # clamp.mode = 2
    # clamp.tau = 10*dt
    # clamp.ti = dt
    # clamp.td = 0
    # clamp.gain = comp.Cm / dt
    ## Setup command voltage time course
    command = moose.PulseGen('/vClampDemo/command')
    command.delay[0] = 10.0
    command.width[0] = 20.0
    command.level[0] = 50.0
    command.delay[1] = 1e9
    moose.connect(command, 'output', clamp, 'commandIn')
    ## Connect the Voltage Clamp to the compartemnt
    moose.connect(clamp, 'currentOut', comp, 'injectMsg')
    moose.connect(comp, 'VmOut', clamp, 'sensedIn')
    ## setup stimulus recroding - this is the command pulse
    stimtab = moose.Table('/vClampDemo/vclamp_command')
    moose.connect(stimtab, 'requestOut', command, 'getOutputValue')
    ## Set up Vm recording
    vmtab = moose.Table('/vClampDemo/vclamp_Vm')
    moose.connect(vmtab, 'requestOut', comp, 'getVm')
    ## setup command potential recording - this is the filtered input
    ## to PID controller
    commandtab = moose.Table('/vClampDemo/vclamp_filteredcommand')
    moose.connect(commandtab, 'requestOut', clamp, 'getCommand')
    ## setup current recording
    Imtab = moose.Table('/vClampDemo/vclamp_inject')
    moose.connect(Imtab, 'requestOut', clamp, 'getCurrent')
    # Scheduling
    moose.setClock(0, dt)
    moose.setClock(1, dt)
    moose.setClock(2, dt)
    moose.setClock(3, dt)
    moose.useClock(0, '%s/##[TYPE=Compartment]' % (container.path), 'init')
    moose.useClock(0, '%s/##[TYPE=PulseGen]' % (container.path), 'process')
    moose.useClock(1, '%s/##[TYPE=Compartment]' % (container.path), 'process')
    moose.useClock(2, '%s/##[TYPE=HHChannel]' % (container.path), 'process')
    moose.useClock(2, '%s/##[TYPE=VClamp]' % (container.path), 'process')
    moose.useClock(3, '%s/##[TYPE=Table]' % (container.path), 'process')
    moose.reinit()
    print(('RC filter in VClamp:: tau:', clamp.tau))
    print(('PID controller in VClamp:: ti:', clamp.ti, 'td:', clamp.td,
           'gain:', clamp.gain))
    moose.start(simtime)
    print(('Finished simulation for %g seconds' % (simtime)))
    tseries = linspace(0, simtime, len(vmtab.vector))
    subplot(211)
    title('Membrane potential and clamp voltage')
    plot(tseries, vmtab.vector, 'g-', label='Vm (mV)')
    plot(tseries, commandtab.vector, 'b-', label='Filtered command (mV)')
    plot(tseries, stimtab.vector, 'r-', label='Command (mV)')
    xlabel('Time (ms)')
    ylabel('Voltage (mV)')
    legend()
    # print len(commandtab.vector)
    subplot(212)
    title('Current through clamp circuit')
    # plot(tseries, stimtab.vector, label='stimulus (uA)')
    plot(tseries, Imtab.vector, label='injected current (uA)')
    xlabel('Time (ms)')
    ylabel('Current (uA)')
    legend()
    show()
示例#4
0
def vclamptest(compartment,
               vclamp,
               duration=50e-3,
               delay=150e-3,
               solver='ee',
               vhold=None,
               mc=None,
               dc=None,
               simdt=1e-5,
               plotdt=0.25e-3):
    """Do a series of voltage clamp experiemnts on compartment.

    parameters:
    
    compartment: Compartment object to be voltage clamped

    vclamp: array of clamping voltage values.

    duration: duration of each clamp

    delay: delay between successive application of clamping voltages

    vhold: holding voltage, If None, the Em of the
    compartment is used.

    mc: model container, the vclamp object will be created inside
    mc/electronics. If None, we use compartment.parent.parent

    dc: data container, the data recording tables will be created
    inside it. If None, we use compartment.parent.parent
    """
    if vhold is None:
        vhold = compartment.Em
    if mc is None:
        mc = compartment.parent.parent
    if dc is None:
        dc = compartment.parent.parent
    electronics = moose.Neutral('%s/electronics' % (mc.path))
    command = moose.PulseGen('%s/command_source' % (electronics.path))
    clamp = moose.VClamp('%s/vclamp' % (electronics.path))
    moose.connect(command, 'output', clamp, 'commandIn')
    moose.connect(compartment, 'VmOut', clamp, 'sensedIn')
    moose.connect(clamp, 'currentOut', compartment, 'injectMsg')
    simtime = 0
    command.count = len(vclamp)
    command.baseLevel = vhold
    for ii, clamping_voltage in enumerate(vclamp):
        simtime += delay + duration
        command.delay[ii] = delay
        command.width[ii] = duration
        command.level[ii] = clamping_voltage
    injected = moose.Table('%s/Iinject' % (dc.path))
    moose.connect(injected, 'requestData', clamp, 'getCurrent')
    voltage = moose.Table('%s/Vcommand' % (dc.path))
    moose.connect(voltage, 'requestData', command, 'getOutputValue')
    vm = moose.Table('%s/Vm' % (dc.path))
    moose.connect(vm, 'requestData', compartment, 'getVm')
    utils.resetSim([mc.path, dc.path], simdt, plotdt, simmethod=solver)
    moose.start(simtime)
    ivec = np.asarray(injected.vector)
    vvec = np.asarray(voltage.vector)
    vmvec = np.asarray(vm.vector)
    ts = np.linspace(0, simtime, len(vvec))
    sidx = np.nonzero(np.diff(vvec) > 0)[0]
    eidx = np.nonzero(np.diff(vvec) < 0)[0]
    iarrays = []
    for ii in range(len(vclamp)):
        iarrays.append(ivec[sidx[ii]:eidx[ii]].copy())
    return {
        "Vm": vmvec,
        "commandVoltage": vvec,
        "inject": ivec,
        "ts": ts,
        "injectArrays": iarrays
    }
示例#5
0
inputs = im.exampleClusteredDistal(model,nInputs = 1)
im.createTimeTables(inputs,model,n_per_syn=1)


#def vclamp_demo(simtime=50.0, dt=1e-2):
"""
Demonstration of voltage clamping in a neuron.
"""
simtime = 0.4#dt = 1e-2

## It is good practice to modularize test elements inside a container
container = moose.Neutral('/vClampDemo')
## Create a compartment with properties of a squid giant axon
comp = soma
# Create and setup the voltage clamp object
clamp = moose.VClamp('/vClampDemo/vclamp')
dt = model.param_sim.simdt
## The defaults should work fine
# clamp.mode = 2
clamp.tau = 10*dt
clamp.ti = dt
# clamp.td = 0
clamp.gain = comp.Cm / dt
## Setup command voltage time course
command = moose.PulseGen('/vClampDemo/command')
command.baseLevel = -80e-3
command.delay[0] = .25
command.width[0] = .2
command.level[0] = 40e-3#40e-3#50.0e-3
command.delay[1] = 1e9#.05
moose.connect(command, 'output', clamp, 'commandIn')