Example #1
0
def setVClamp(seg, durs, amps):
    ## VClamp as vstim
    amps = [x if isinstance(x, (int, float)) else h.v_init for x in amps]
    vstim = h.VClamp(seg)
    vstim.dur[0], vstim.dur[1], vstim.dur[2] = durs[0], durs[1], durs[2]
    vstim.amp[0], vstim.amp[1], vstim.amp[2] = amps[0], amps[1], amps[2]
    return vstim
def setVClamp(seg, durs, amps):
## VClamp as vstim
    amps = [x if isinstance(x, (int, float, complex)) else h.v_init for x in amps]
    vstim = h.VClamp(seg)
    vstim.dur[0], vstim.dur[1], vstim.dur[2] = durs[0], durs[1], durs[2]
    vstim.amp[0], vstim.amp[1], vstim.amp[2] = amps[0], amps[1], amps[2]
## SEClamp as vstim
#    vstim = h.SEClamp(csomas[cell].drgsoma(0.5))
#    vstim.dur1, vstim.dur2, vstim.dur3 = durs[0], durs[1], durs[2]
#    vstim.amp1, vstim.amp2, vstim.amp3 = amps[0], amps[1], amps[2]
    return vstim
Example #3
0
    def inject_VClamp(parameters, injectsite):
        """Injects SEClamp for `NEURON <https://neuron.yale.edu/neuron/>`_

        **Keyword Arguments:**

        +----------------+--------------------------------------------------------------+
        | Keys           | Value type                                                   |
        +================+==============================================================+
        | ``parameters`` | - list such that each element is a dictionary [ {}, {}, {} ] |
        |                | - Eg: [ {"amp": 0.0, "dur": 50.0},                           |
        |                |         {"amp": 10.0, "dur": 100.0},                         |
        |                |         {"amp": 20.0, "dur": 150.0} ]                        |
        |                |**NOTE** There is no amp[>2] (therefore no dur[>2])           |
        |                | - To change clamp parameters  with keys "gain", "rstim",     |
        }                |"tau1" and "tau2", do it just once. They should be the same   |
        |                |for all because its the same setup, just the amplitude changes|
        |                | - Since "Clamp is on at 0, off at time dur[0]+dur[1]+dur[2]" |
        |                |if you don't want to start the simulation with it just set the|
        |                | first "amp": 0.0                                             |
        +----------------+--------------------------------------------------------------+
        | ``injectsite`` | ``neuron`` ``section``, for e.g., ``cell.soma``              |
        +----------------+--------------------------------------------------------------+

        **Returned values:** a ``hoc`` object ``h.VClamp``.

        **NOTE:**

        - The ``h.VClamp`` function is available in NEURON as `VClamp <https://neuron.yale.edu/neuron/static/new_doc/modelspec/programmatic/mechanisms/mech.html#VClamp>`_ by default. 
        - By default the electrode resistance (Re but VClamp attribute is ``rstim``) is made very small ``1E-6``. This is because the input resistance (Rin) for the voltmeter (i.e, the measuring circuit) must be very large (i.e, infinite resistance) so that the voltage drop across the voltmeter (given by the voltage divider equation, the resistance is Rin/(Rin+Re)) is as close as possible to the membrane voltage it is supposed to be clamping. By making the electrode resistance very small it is the same as infinite Rin. 

        """
        # NOTE: Do not insert several instances of this model at the same location
        # to make level changes. That is equivalent to independent clamps and they
        # will have incompatible internal state values.
        no_of_voltages = len(parameters)
        clampingvoltages = h.VClamp(0.5, sec=injectsite)
        clampingvoltages.rstim = 1E-6
        for i in range(no_of_voltages):
            for key, value in parameters[i].items():
                if key in clampingvoltages.__dict__:
                    if key in ["gain", "rstim", "tau1", "tau2"]:
                        setattr(clampingvoltages, key, value)
                    else:
                        clampattr = getattr(clampingvoltages, key)
                        clampattr[i] = value
                else:
                    raise AttributeError(key +
                                         " is not an attribute in h.VClamp.")
        return clampingvoltages
Example #4
0
    def run(self, pre_sec, post_sec, n_synapses, temp=34.0, dt=0.025, 
            vclamp=40.0, iterations=1, tstop=240.0, stim_params=None, synapsetype='multisite', **kwds):
        """ 
        Basic synapse test. Connects sections of two cells with *n_synapses*.
        The cells are allowed to negotiate the details of the connecting 
        synapse. The presynaptic soma is then driven with a pulse train
        followed by a recovery pulse of varying delay.
        
        *stim_params* is an optional dictionary with keys 'NP', 'Sfreq', 'delay',
        'dur', 'amp'.
        
        Analyses:
        
        * Distribution of PSG amplitude, kinetics, and latency
        * Synaptic depression / facilitation and recovery timecourses
        """
        Protocol.run(self, **kwds)
        
        pre_cell = cells.cell_from_section(pre_sec)
        post_cell = cells.cell_from_section(post_sec)
        synapses = []
        for i in range(n_synapses):
            synapses.append(pre_cell.connect(post_cell, type=synapsetype))
        
        self.synapses = synapses
        self.pre_sec = synapses[0].terminal.section
        self.post_sec = synapses[0].psd.section
        self.pre_cell = pre_cell
        self.post_cell = post_cell
        self.plots={}  # store plot information here
        #
        # voltage clamp the target cell
        #
        clampV = vclamp
        vccontrol = h.VClamp(0.5, sec=post_cell.soma)
        vccontrol.dur[0] = 10.0
        vccontrol.amp[0] = clampV
        vccontrol.dur[1] = 100.0
        vccontrol.amp[1] = clampV
        vccontrol.dur[2] = 20.0
        vccontrol.amp[2] = clampV

        #
        # set up stimulation of the presynaptic axon/terminal
        #
        
        istim = h.iStim(0.5, sec=pre_cell.soma)
        stim = {
            'NP': 10,
            'Sfreq': 100.0,
            'delay': 10.0,
            'dur': 0.5,
            'amp': 10.0,
            'PT': 0.0,
            'dt': dt,
        }
        if stim_params is not None:
            stim.update(stim_params)
        (secmd, maxt, tstims) = util.make_pulse(stim)
        self.stim = stim

        if tstop is None:
            tstop = len(secmd) * dt
        
        istim.delay = 0
        istim.dur = 1e9 # these actually do not matter...
        istim.iMax = 0.0

        # istim current pulse train
        i_stim_vec = h.Vector(secmd)
        i_stim_vec.play(istim._ref_i, dt, 0)

        # create hoc vectors for each parameter we wish to monitor and display
        synapse = synapses[0]
        self.all_psd = []
        if isinstance(synapses[0].psd, GlyPSD) or isinstance(synapses[0].psd, GluPSD):
            for syn in synapses:
                self.all_psd.extend(syn.psd.all_psd)
        elif isinstance(synapses[0].psd, Exp2PSD):
            for syn in synapses:
                self.all_psd.append(syn)

        #for i, cleft in enumerate(synapse.psd.clefts):
            #self['cleft_xmtr%d' % i] = cleft._ref_CXmtr
            #self['cleft_pre%d' % i] = cleft._ref_pre
            #self['cleft_xv%d' % i] = cleft._ref_XV
            #self['cleft_xc%d' % i] = cleft._ref_XC
            #self['cleft_xu%d' % i] = cleft._ref_XU

        #
        # Run simulation
        #
        h.tstop = tstop # duration of a run
        h.celsius = temp
        h.dt = dt
        self.temp = temp
        self.dt = dt
        self.isoma = []
        self.currents = {'ampa': [], 'nmda': []}
        self.all_releases = []
        self.all_release_events = []
        start_time = timeit.default_timer()
        for nrep in xrange(iterations): # could do multiple runs.... 
            self.reset()
            self['v_pre'] = pre_cell.soma(0.5)._ref_v
            self['t'] = h._ref_t
            self['v_soma'] = pre_cell.soma(0.5)._ref_v
            if not isinstance(synapse.psd, Exp2PSD):
                self['relsite_xmtr'] = synapse.terminal.relsite._ref_XMTR[0]

            if isinstance(synapse.psd, GluPSD):
                # make a synapse monitor for each release zone
                self.all_nmda = []
                self.all_ampa = []
                for syn in synapses:
                    # collect all PSDs across all synapses
                    self.all_ampa.extend(syn.psd.ampa_psd)
                    self.all_nmda.extend(syn.psd.nmda_psd)
                    
                    # Record current through all PSDs individually
                    syn.psd.record('i', 'g', 'Open')
            
                #for k,p in enumerate(self.all_nmda):
                    #self['iNMDA%03d' % k] = p._ref_i
                    #self['opNMDA%03d' % k] = p._ref_Open
                #for k,p in enumerate(self.all_ampa):
                    #self['iAMPA%03d' % k] = p._ref_i
                    #self['opAMPA%03d' % k] = p._ref_Open
        
            elif isinstance(synapse.psd, GlyPSD):
                #  Record current through all PSDs individually
                for k,p in enumerate(self.all_psd):
                    self['iGLY%03d' % k] = p._ref_i
                    self['opGLY%03d' % k] = p._ref_Open
                
                psd = self.all_psd
                if synapse.psd.psdType == 'glyslow':
                    nstate = 7
                    self['C0'] = psd[0]._ref_C0
                    self['C1'] = psd[0]._ref_C1
                    self['C2'] = psd[0]._ref_C2
                    self['O1'] = psd[0]._ref_O1
                    self['O2'] = psd[0]._ref_O2
                    self['D1'] = psd[0]._ref_D1
                    #self['D3'] = psd[0]._ref_D3
                    #self['O1'] = psd[0]._ref_O1
                elif synapse.psd.psdType == 'glyfast':
                    nstate = 7
                    self['C0'] = psd[0]._ref_C0
                    self['C1'] = psd[0]._ref_C1
                    self['C2'] = psd[0]._ref_C2
                    self['C3'] = psd[0]._ref_C3
                    self['O1'] = psd[0]._ref_O1
                    self['O2'] = psd[0]._ref_O2
            elif isinstance(synapse.psd, Exp2PSD):
                self['iPSD'] = self.all_psd[0].psd.syn._ref_i

            if not isinstance(synapse.psd, Exp2PSD):
                for i, s in enumerate(synapses):
                    s.terminal.relsite.rseed = util.random_seed.current_seed() + nrep
            util.custom_init()
            h.run()

            # add up psd current across all runs
            if isinstance(synapse.psd, GluPSD):
                iampa = np.zeros_like(synapse.psd.get_vector('ampa', 'i'))
                inmda = iampa.copy()
                for syn in self.synapses:
                    for i in range(syn.psd.n_psd):
                        iampa += syn.psd.get_vector('ampa', 'i', i)
                        inmda += syn.psd.get_vector('nmda', 'i', i)
                isoma = iampa + inmda
                self.currents['ampa'].append(iampa)
                self.currents['nmda'].append(inmda)
            elif isinstance(synapse.psd, GlyPSD):
                isoma = np.zeros_like(self['iGLY000'])
                for k in range(len(self.all_psd)):
                    isoma += self['iGLY%03d'%k]
            elif isinstance(synapse.psd, Exp2PSD):
                 isoma = self['iPSD']
            self.isoma.append(isoma)
            self.all_releases.append(self.release_timings())
            self.all_release_events.append(self.release_events())

        elapsed = timeit.default_timer() - start_time
        print 'Elapsed time for %d Repetions: %f' % (iterations, elapsed)
Example #5
0
        #        self.ap_dend.nseg = 23
        #        self.ap_dend.insert('hh')
        #        self.ap_dend.gnabar_hh = 0.012
        #        self.ap_dend.gkbar_hh = 0.0036
        #        self.ap_dend.gl_hh = 0.00003
        #        self.ap_dend.connect(self.soma, 1.0, 0)

        # synaptic input
        self.esyn = h.Exp2Syn(0.5, sec=self.soma)  #syn points to ap_dend,0.5


# end of class HHneuron

# cells
hh_neuron = [HHneuron() for i in range(1)]
vcl = h.VClamp()
vcl = h.VClamp(0.5, sec=hh_neuron[0].soma)

# synapse
stim = h.NetStim(0.5)
stim.interval = 50.0
stim.number = 2
stim.start = 50.0
stim.noise = 0

# connections
nclist = []
nclist.append(h.NetCon(stim, hh_neuron[0].esyn, 0.0, 0, 0.005))

tstop = 200
dt = 0.01
Example #6
0
import toolbox as tb

from neuron import h
from neuron import gui

h.nrn_load_dll('$i386/')

gocs = Goc(np.array([0.,0.,0.]),record_all=1)

# stim = h.IClamp(.5, sec=gocs[0][1][1].soma)
# stim.amp = -0.015
# stim.dur = 200

gocs.createsyn(ngoc=1,record_all=1)

vc = h.VClamp(0.5)
vc.amp[0] = 0
vc.dur[0] = 200

stim = h.NetStim(0.5)
stim.number = 1
stim.interval = 10
stim.start = 20

# print gocs.GRC_L[0].postsyns.keys()
# print gocs.PF_L[0].postsyns.keys()

nc1 = h.NetCon(stim,gocs.GOC_L[0].input,0,0,1)

# v = h.Vector()
# nc.record(v)
import toolbox as tb

from neuron import h
from neuron import gui

h.nrn_load_dll('$i386/')

gocs = Goc(np.array([0., 0., 0.]), record_all=1)

# stim = h.IClamp(.5, sec=gocs[0][1][1].soma)
# stim.amp = -0.015
# stim.dur = 200

gocs.createsyn(naa=1, record_all=1)

vc = h.VClamp(0.5, sec=gocs.soma)
vc.amp[0] = -70
vc.dur[0] = 10000

# cc = h.IClamp(0.5)
# cc.amp = -0.065
# cc.dur = 2000
# cc.delay = 0

stim = h.NetStim(0.5)
stim.number = 1
stim.interval = 10
stim.start = 2000

nc_mf = [h.NetCon(stim, goc.input, 0, 0, 1) for goc in gocs.GRC_AA_L]
Example #8
0
    def run(self,
            pre_sec,
            post_sec,
            temp=34.0,
            dt=0.025,
            vclamp=-65.0,
            iterations=1,
            tstop=200.0,
            stim_params=None,
            **kwds):
        """ 
        """
        Protocol.run(self, **kwds)

        pre_cell = cells.cell_from_section(pre_sec)
        post_cell = cells.cell_from_section(post_sec)
        synapse = pre_cell.connect(post_cell, type='simple')

        self.synapse = synapse
        self.pre_sec = synapse.terminal.section
        self.post_sec = synapse.psd.section
        self.pre_cell = pre_cell
        self.post_cell = post_cell

        #
        # voltage clamp the target cell
        #
        vccontrol = h.VClamp(0.5, sec=post_cell.soma)
        vccontrol.dur[0] = tstop
        vccontrol.amp[0] = vclamp
        #vccontrol.dur[1] = 100.0
        #vccontrol.amp[1] = clampV
        #vccontrol.dur[2] = 20.0
        #vccontrol.amp[2] = clampV

        #
        # set up stimulation of the presynaptic axon/terminal
        #

        istim = h.iStim(0.5, sec=pre_cell.soma)
        stim = {
            'NP': 10,
            'Sfreq': 100.0,
            'delay': 10.0,
            'dur': 0.5,
            'amp': 10.0,
            'PT': 0.0,
            'dt': dt,
        }
        if stim_params is not None:
            stim.update(stim_params)
        (secmd, maxt, tstims) = util.make_pulse(stim)
        self.stim = stim

        if tstop is None:
            tstop = len(secmd) * dt

        istim.delay = 0
        istim.dur = 1e9  # these actually do not matter...
        istim.iMax = 0.0

        # istim current pulse train
        i_stim_vec = h.Vector(secmd)
        i_stim_vec.play(istim._ref_i, dt, 0)

        #
        # Run simulation
        #
        h.tstop = tstop  # duration of a run
        h.celsius = temp
        h.dt = dt
        self.temp = temp
        self.dt = dt
        for nrep in xrange(iterations):  # could do multiple runs....
            self.reset()
            self['v_pre'] = pre_cell.soma(0.5)._ref_v
            self['t'] = h._ref_t
            self['v_soma'] = post_cell.soma(0.5)._ref_v
            self['i_soma'] = vccontrol._ref_i
            util.custom_init()
            h.run()