Skip to content
Snippets Groups Projects
Select Git revision
  • 349abe7e0132111737153bf2d4b1692d091b5ea8
  • master default protected
  • github/fork/hrani/master
  • github/fork/dilawar/master
  • chamcham
  • chhennapoda
  • wheel
  • 3.2.0-pre0
  • v3.1.3
  • 3.1.2
  • 3.1.1
  • chamcham-3.1.1
  • 3.1.0
  • ghevar_3.0.2_pre2
  • ghevar_3.0.2
15 results

vclamp.py

Blame
  • user avatar
    HarshaRani authored
    7318878 cleanups
    9b83291 Merge branch 'master' of github.com:BhallaLab/moose-examples
    2f46ad0 Convert u'ABCD' to 'ABCD' to probably fix the python3 issue on travis. Works fine with python3 on ubuntu 16.04/Debian8.
    6232b3a Send email to malav if build fails.
    4a92db2 Merge branch 'master' of github.com:BhallaLab/moose-examples
    4800cd6 Adding python-libsbml to dependencies.
    c045972 Fixed second script as well.
    e927a88 Merge branch 'master' of github.com:BhallaLab/moose-examples
    626afb8 Added a hack to make this script work with both python3 and python2.
    24fdc9e Indentation for python3
    e9e5d92  Using force-yes with -y
    3c60a82 Upi fix the assert error
    ca2d409 Upi cleaned up the file
    a9ddced Merge branch 'master' of https://github.com/BhallaLab/moose-examples
    b4715d0 First commit.
    2c4fa33 This is removed b'cos Rdesignuer does the job
    4ca1f6d missing closing braces
    d120484 small correction for input eval with is str
    18990fd enter key replaced to zero, as function \'input\' with \'enter\' key give SyntaxError: unexpected EOF while parsing
    0db144c Ready for put into demo #15.
    39aa6e4 Closed docstring.
    f2dc6be Merge commit '07ef36e1'
    
    git-subtree-dir: moose-examples
    git-subtree-split: 731887849ac227fa304780406ff913c69af425ca
    0e491aa4
    History
    vclamp.py 4.38 KiB
    # vclamp.py ---
    #
    # Filename: vclamp.py
    # Description:
    # Author:Subhasis Ray
    # Maintainer:
    # Created: Sat Feb  2 19:16:54 2013 (+0530)
    # Version:
    # Last-Updated: Tue Jun 11 17:35:20 2013 (+0530)
    #           By: subha
    #     Update #: 178
    # URL:
    # Keywords:
    # Compatibility:
    #
    #
    
    # Commentary:
    #
    #
    #
    #
    
    # Change log:
    #
    #
    #
    #
    # This program is free software; you can redistribute it and/or
    # modify it under the terms of the GNU General Public License as
    # published by the Free Software Foundation; either version 3, or
    # (at your option) any later version.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    # General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License
    # along with this program; see the file COPYING.  If not, write to
    # the Free Software Foundation, Inc., 51 Franklin Street, Fifth
    # Floor, Boston, MA 02110-1301, USA.
    #
    #
    
    # Code:
    
    import sys
    sys.path.append('../../python')
    import moose
    sys.path.append('../squid')
    from squid import SquidAxon
    from pylab import *
    
    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()
    
    def main():
        """
    This snippet is to demonstrate modelling of voltage clamping.
        """
        vclamp_demo()
    
    if __name__ == '__main__':
        main()
    
    #
    # vclamp.py ends here