Example #1
0
def synapse_vclamp_test(label, syntype, cell, w, v_holding, v_init, indexes,
                        section):

    vv = h.Vector()
    vv.append(0, 0, 0, 0, 0, 0)

    se = h.SEClamp(cell.sections[section](0.5))

    h('objref synlst')
    h.synlst = h.List()
    for i in indexes:
        h.synlst.append(cell.syns.o(i))
    if syntype == syn_type_excitatory:
        v = cell.syntest_exc(h.synlst, se, w, v_holding, v_init)
    else:
        v = cell.syntest_inh(h.synlst, se, w, v_holding, v_init)

    vv = vv.add(v)

    amp = vv.x[0]
    t_10_90 = vv.x[1]
    t_20_80 = vv.x[2]
    t_all = vv.x[3]
    t_50 = vv.x[4]
    t_decay = vv.x[5]

    print("%s synapse: \n" % label)
    print("  Amplitude %f\n" % amp)
    print("  10-90 Rise Time %f\n" % t_10_90)
    print("  20-80 Rise Time %f\n" % t_20_80)
    print("  Decay Time Constant %f\n" % t_decay)
Example #2
0
    def __init__(self, mechname):
        #set variables in case of exception so that __del__ still works.
        self.nc = None
        self.stim = None
        self.syn = None
        self.vc = None
        self.s = None

        self.mechname = mechname
        constructor = h.__getattribute__(mechname)
        self.soma = h.Section(name='soma')
        s = self.soma
        s.L = 10.
        s.diam = 10. / h.PI
        s.insert('pas')
        seg = s(0.5)
        seg.e_pas = -65.0
        seg.g_pas = 0.0001

        self.syn = constructor(seg)
        self.stim = h.NetStim()
        self.stim.number = 2
        self.stim.interval = 5
        self.stim.start = 1

        self.nc = h.NetCon(self.stim, self.syn)
        self.nc.delay = 1
        self.nc.weight[0] = .001

        if use_voltage_clamp:
            self.vc = h.SEClamp(seg)
            self.vc.amp1 = -65.0
            self.vc.dur1 = 1e9
Example #3
0
    def run(self, vcrange, cell, dt=0.025):
        """
        Run voltage-clamp I/V curve.

        Parameters:
        vmin : float
            Minimum voltage step value
        vmax :
            Maximum voltage step value
        vstep :
            Voltage difference between steps
        cell :
            The Cell instance to test.
        """
        self.reset()
        self.cell = cell
        try:
            (vmin, vmax, vstep) = vcrange  # unpack the tuple...
        except:
            raise TypeError(
                "run_iv argument 1 must be a tuple (imin, imax, istep)")

        vstim = h.SEClamp(0.5, cell.soma)  # set up a single-electrode clamp
        vstim.dur1 = 50.0
        vstim.amp1 = -60
        vstim.dur2 = 500.0
        vstim.amp2 = -60.0
        vstim.dur3 = 400
        vstim.amp3 = -60.0
        vstim.rs = 0.01
        cell.soma.cm = 0.001  # reduce capacitative transients (cap compensation)
        self.durs = [vstim.dur1, vstim.dur2, vstim.dur3]
        self.amps = [vstim.amp1, vstim.amp2, vstim.amp3]
        self.voltage_cmd = []
        tend = 900.0
        iv_nstepv = int(np.ceil((vmax - vmin) / vstep))
        iv_minv = vmin
        iv_maxv = vmax
        vstep = (iv_maxv - iv_minv) / iv_nstepv
        for i in range(iv_nstepv):
            self.voltage_cmd.append(float(i * vstep) + iv_minv)
        nreps = iv_nstepv
        h.dt = dt
        self.dt = h.dt
        for i in range(nreps):
            # Connect recording vectors
            self['v_soma'] = cell.soma(0.5)._ref_v
            self['i_inj'] = vstim._ref_i
            self['time'] = h._ref_t
            vstim.amp2 = self.voltage_cmd[i]
            custom_init(v_init=-60.)
            h.tstop = tend
            self.cell.check_all_mechs()
            while h.t < h.tstop:
                h.fadvance()
            self.voltage_traces.append(self['v_soma'])
            self.current_traces.append(self['i_inj'])
            self.time_values = np.array(self['time'])
Example #4
0
 def addVClamp(self, loc, e_c, dur):
     loc = MorphLoc(loc, self)
     # add the voltage clamp
     vclamp = h.SEClamp(self.sections[loc['node']](loc['x']))
     vclamp.rs = 0.01
     vclamp.dur1 = dur
     vclamp.amp1 = e_c
     # store the vclamp
     self.vclamps.append(vclamp)
Example #5
0
 def __init__(self):
     self.soma = h.Section(name="soma", cell=self)
     self.soma.diam = 10.0
     self.soma.L = 10.0
     self.soma.insert("na_ion")  # can use nai as transfer source
     # can use POINT_PROCESS range variable as targets
     self.ic = h.IClamp(self.soma(0.5))
     self.vc = h.SEClamp(self.soma(0.5))
     self.vc.rs = 1e9  # no voltage clamp current
     self.hgap = [None for _ in range(2)]  # filled by mkgaps
Example #6
0
 def placeVoltageClamp(self, sec, D):
     """Put a voltage clamp at a specific location"""
     print('....adding a voltage clamp electrode')
     self.settings.v_init = self.settings.Hold1
     self.vClamp = h.SEClamp(sec(D))
     self.vClamp.dur1 = self.settings.ChangeClamp
     self.vClamp.dur2 = self.settings.tstop - self.settings.ChangeClamp
     self.vClamp.amp1 = self.settings.Hold1
     self.vClamp.amp2 = self.settings.Hold2
     self.recordings['iClamp'] = h.Vector().record(self.vClamp._ref_i)
    def get_synapse_iv(self,
                       synpase_type='ampa',
                       p_conc=0,
                       ampa_gmax=5000,
                       nmda_gmax=5000,
                       t_rel=40.0,
                       vc_range=np.arange(-90.0, 50.0, 5.0),
                       nmda_mech='h.NMDA_Mg_T',
                       vshift=None):
        '''

        Method for generating large IV curves... Not sure if best, use synapse __ref__i
        '''

        self.clamp = h.SEClamp(0.5, sec=self.root)
        self.clamp.dur1 = 10
        self.clamp.dur2 = 60
        self.clamp.dur3 = 10
        self.clamp.amp1 = -70
        self.clamp.amp2 = -70
        self.clamp.amp3 = -70
        self.clamp.rs = 0.0001

        pre = h.Section()
        pre.diam = 1.0
        pre.L = 1.0
        pre.insert('rel')
        pre.dur_rel = 0.5
        pre.amp_rel = 3.0
        pre.del_rel = t_rel

        if synpase_type.lower() == 'ampa':
            print('running simulation of AMPAR IV with', p_conc,
                  'µM polyamines')

            cpampa = h.cpampa12st(0.5, sec=self.root)
            cpampa.pconc = p_conc
            cpampa.gmax = ampa_gmax

            h.setpointer(pre(0.5).rel._ref_T, 'C', cpampa)

        if synpase_type.lower() == 'nmda':
            print('running simulation of NMDA IV')
            nmda = eval(nmda_mech + '(0.5,sec=self.root)')
            print('inserted: ' + nmda_mech + '(0.5,sec=self.root)')
            #nmda = h.NMDA_Mg_T(0.5,sec=self.root)
            if vshift:
                print('vshift: ' + str(vshift))
                nmda.vshift = vshift
            nmda.gmax = nmda_gmax
            h.setpointer(pre(0.5).rel._ref_T, 'C', nmda)

        v, i, t = self.run_vclamp(vc_range, tstop=80)
        i_list, v_list = self.calc_iv_relationship(v, i, t)
        return i_list, v_list,
Example #8
0
    def add_vclamp(self):
        clamp = h.SEClamp(0.5, sec=self.soma)
        clamp.dur1 = 10
        clamp.dur2 = 10
        clamp.dur3 = 10
        clamp.amp1 = -70
        clamp.amp2 = -70
        clamp.amp3 = -70
        clamp.rs = 0.0001

        self.clamp = clamp
Example #9
0
def setup_dynamic_clamp(sec, pos, vm, t, dt=h.dt):
    """Create a dynamic clamp on section `sec` at position `pos` and play
    the voltage `vm` over time `t`. The sample points are selected at
    `dt` interval.

    """
    clamp = h.SEClamp(sec(pos))
    clamp.rs = 1e-3
    clamp.dur1 = 1e9
    vsample = np.interp(np.arange(t[0], t[-1], dt), t, vm)
    vplay = h.Vector(vsample)
    vplay.play(clamp._ref_amp1, dt)
    return clamp, vplay
Example #10
0
    def attach_current(self, cell):
        self._stim = h.SEClamp(cell.hobj.soma[0](0.5))
        self._stim.dur1 = self._seclamp_durs[0]
        self._stim.dur2 = self._seclamp_durs[1]
        self._stim.dur3 = self._seclamp_durs[2]

        self._stim.amp1 = self._seclamp_amps[0]
        self._stim.amp2 = self._seclamp_amps[1]
        self._stim.amp3 = self._seclamp_amps[2]

        if self._seclamp_rs != None:
            self._stim.rs = self._seclamp_rs

        return self._stim
        
Example #11
0
def vclamp_seg(seg, durs, amps, rs=None):
    clamp = SEClamp(amps, durs, rs=rs)

    clamp._stim = h.SEClamp(seg) 
    clamp._stim.dur1 = durs[0]
    clamp._stim.dur2 = durs[1]
    clamp._stim.dur3 = durs[2]

    clamp._stim.amp1 = amps[0]
    clamp._stim.amp2 = amps[1]
    clamp._stim.amp3 = amps[2]

    if rs != None:
        clamp._stim.rs = rs

    return clamp
Example #12
0
    def inject_SEClamp(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: [ {"amp1": 0.0, "dur1": 50.0, "rs": 1E-6},             |
        |                |         {"amp2": 10.0, "dur2": 100.0},                       |
        |                |         {"amp3": 20.0, "dur3": 150.0} ]                      |
        |                |**NOTE** There is no "amp>3" (therefore no "dur>3")           |
        |                | - To add the electrode/pipette resistance do it just once    |
        |                | with key "rs". This should be the same for all because its   |
        |                | the same setup, just the amplitudes differ.                  |
        |                | - Since "Clamp is on at time 0, off at time dur1+dur2+dur3"  |
        |                |if you don't want to start the simulation with it just set    |
        |                |"amp1": 0.0                                                   |
        +----------------+--------------------------------------------------------------+
        | ``injectsite`` | ``neuron`` ``section``, for e.g., ``cell.soma``              |
        +----------------+--------------------------------------------------------------+

        **Returned values:** list of currents where each element is a ``hoc`` object ``h.SEClamp``.

        **NOTE:**

        - The ``h.SEClamp`` function is available in NEURON as `SEClamp <https://neuron.yale.edu/neuron/static/new_doc/modelspec/programmatic/mechanisms/mech.html#SEClamp>`_ by default.
        - By default the electrode resistance (Re but SEClamp attribute is ``rs``) 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.SEClamp(0.5, sec=injectsite)
        clampingvoltages.rs = 1E-6
        for i in range(no_of_voltages):
            for key, value in parameters[i].items():
                if key in clampingvoltages.__dict__:
                    setattr(clampingvoltages, key, value)
                else:
                    raise AttributeError(key +
                                         " is not an attribute in h.SEClamp.")
        return clampingvoltages
Example #13
0
    def get_iv(self,
               synpase_type='ampa',
               p_conc=0,
               ampa_gmax=5000,
               nmda_gmax=5000,
               t_rel=40.0):

        self.clamp = h.SEClamp(0.5, sec=self.root)
        self.clamp.dur1 = 10
        self.clamp.dur2 = 60
        self.clamp.dur3 = 10
        self.clamp.amp1 = -70
        self.clamp.amp2 = -70
        self.clamp.amp3 = -70
        self.clamp.rs = 0.0001

        pre = h.Section()
        pre.diam = 1.0
        pre.L = 1.0
        pre.insert('rel')
        pre.dur_rel = 0.5
        pre.amp_rel = 3.0
        pre.del_rel = t_rel

        if synpase_type.lower() == 'ampa':
            print('running simulation of AMPAR IV with', p_conc,
                  'µM polyamines')

            cpampa = h.cpampa12st(0.5, sec=self.root)
            cpampa.pconc = p_conc
            cpampa.gmax = ampa_gmax

            h.setpointer(pre(0.5).rel._ref_T, 'C', cpampa)

        if synpase_type.lower() == 'nmda':
            print('running simulation of NMDA IV')

            nmda = h.NMDA_Mg_T(0.5, sec=self.root)
            nmda.gmax = nmda_gmax
            h.setpointer(pre(0.5).rel._ref_T, 'C', nmda)

        vc_range = np.arange(-90.0, 50.0, 10.0)
        v, i, t = self.run_vclamp(vc_range, tstop=80)
        i_list, v_list = self.calc_iv_relationship(v, i, t)
        return i_list, v_list
Example #14
0
    def voltage_clamp(self, voltages, series_resistance=1e-3):
        """
        Clamps the voltage of a segment

        Parameters
        ----------
        voltage : neo.AnalogSignal (voltage)
            The voltages to clamp the segment to
        series_resistance : float (??)
            The series resistance of the voltage clamp
        """
        seclamp = h.SEClamp(0.5, sec=self._sec)
        seclamp.rs = series_resistance
        seclamp.dur1 = 1e12
        seclamp_amps = h.Vector(pq.Quantity(voltages, 'mV'))
        seclamp_times = h.Vector(voltages.times.rescale(pq.ms))
        seclamp_amps.play(seclamp._ref_amp, seclamp_times)
        self._inputs['seclamp'] = seclamp
        self._input_auxs.extend((seclamp_amps, seclamp_times))
Example #15
0
    def get_nmda_ampa_ratio(self,
                            p_conc,
                            ampa_gmax,
                            nmda_gmax,
                            t_rel=40.0,
                            vc_range=[-60, 60]):

        self.clamp = h.SEClamp(0.5, sec=self.root)
        self.clamp.dur1 = 10
        self.clamp.dur2 = 150
        self.clamp.dur3 = 10
        self.clamp.amp1 = -70
        self.clamp.amp2 = -70
        self.clamp.amp3 = -70
        self.clamp.rs = 0.0001

        pre = h.Section()
        pre.diam = 1.0
        pre.L = 1.0
        pre.insert('rel')
        pre.dur_rel = 0.5
        pre.amp_rel = 3.0
        pre.del_rel = t_rel

        syn_list = []
        locs = np.linspace(0, 1, 35)
        for l in locs:
            cpampa = h.cpampa12st(l, sec=self.root)
            cpampa.pconc = p_conc
            cpampa.gmax = ampa_gmax

            h.setpointer(pre(0.5).rel._ref_T, 'C', cpampa)

            nmda = h.NMDA_Mg_T(l, sec=self.root)
            nmda.gmax = nmda_gmax
            h.setpointer(pre(0.5).rel._ref_T, 'C', nmda)

            syn_list.append((nmda, cpampa))

        v, i, t = self.run_vclamp(vc_range, tstop=170)

        return v, i, t
Example #16
0
def run_sim(h, section_name, v_peak, tau_raise, tau_fall, onset=100):
    tstop = 500
    h.dt = dt = 0.1
    h.load_file("stdrun.hoc")
    soma, sec = fetch_soma_sec(section_name)
    v_rest = -75.711  # find_vrest(h, section_name)
    h.init()
    h.cvode.re_init()
    s_v, a_v = fetch_soma_apic_pots()
    vv = voltage_clamp(tstop, dt, v_rest, v_peak, tau_raise, tau_fall, onset)
    vc = h.SEClamp(sec(0.5))
    vc.rs = 0.001
    vc.dur1 = tstop
    vamp = h.Vector(vv)
    vamp.play(vc._ref_amp1, h.dt)
    t_vec, soma_vm, sec_vm = record(soma, sec)
    h.execute('tstop = ' + str(tstop))
    h.run()
    diff_v = np.array(a_v) - np.array(s_v)
    return t_vec, soma_vm, sec_vm, diff_v, vv
Example #17
0
    def addVClamp(self, loc, e_c, dur):
        """
        Adds a voltage clamp at a given location

        Parameters
        ----------
        loc: dict, tuple or :class:`neat.MorphLoc`
            The location of the conductance.
        e_c: float
            The clamping voltage (mV)
        dur: float, ms
            The duration of the voltage clamp
        """
        loc = MorphLoc(loc, self)
        # add the voltage clamp
        vclamp = h.SEClamp(self.sections[loc['node']](loc['x']))
        vclamp.rs = 0.01
        vclamp.dur1 = dur
        vclamp.amp1 = e_c
        # store the vclamp
        self.vclamps.append(vclamp)
Example #18
0
    def addVoltageClamp(self, weightMap, dur):
        # WeightMap is (treeNum, Sec, Seg):weight
        # treeNum specifies apical or basal, 0 is apical, 1 is basal
        # inds is an array of tuples of (sectionNum, segNum)

        # Window for stimulus inputs
        tstart = self.stimStart
        tstop = self.stimStop
        for tuple in weightMap:
            print tuple
            loc = tuple[0]
            synapseWeight = tuple[1]
            treeNum = loc[0]
            tree = self.trees[treeNum]
            section = tree[loc[1]]
            segLoc = self.getSegLoc(loc)
            clamp = h.SEClamp(segLoc, sec=section)
            clamp.dur1 = dur
            clamp.amp1 = synapseWeight
            clamp.rs = 0.00000001
            self.SEClamps[loc] = clamp
Example #19
0
def vclamp(v, t, sec, celsius):

    # create SEClamp
    v_clamp = h.Vector()
    v_clamp.from_python(v)
    t_clamp = h.Vector()
    t_clamp.from_python(np.concatenate(
        (np.array([0]),
         t)))  # shifted because membrane potential lags behind vclamp
    clamp = h.SEClamp(0.5, sec=sec)
    clamp.rs = 1e-15  # series resistance should be as small as possible
    clamp.dur1 = 1e9
    v_clamp.play(clamp._ref_amp1, t_clamp)

    # simulate
    h.celsius = celsius
    dt = t[1] - t[0]
    h.tstop = t[-1]
    h.steps_per_ms = 1 / dt
    h.dt = dt
    h.v_init = v[0]
    h.run()
Example #20
0
def run_democlamp(cell, dend, vsteps=[-60,-70,-60], tsteps=[10,50,100]):
    """
    Does some stuff.
    
    """
    f1 = pylab.figure(1)
    gs = GS.GridSpec(2, 2,
                       width_ratios=[1, 1],
                       height_ratios=[1, 1])

    # note numbering for insets goes from 1 (upper right) to 4 (lower right)
    # counterclockwise
    pA = f1.add_subplot(gs[0])
    pAi = INSETS.inset_axes(pA, width="66%", height="40%", loc=2)
    pB = f1.add_subplot(gs[1])
    pBi = INSETS.inset_axes(pB, width="66%", height="40%", loc=4)
    pC = f1.add_subplot(gs[2])
    pCi = INSETS.inset_axes(pC, width="66%", height="40%", loc=2)
    pD = f1.add_subplot(gs[3])
    pDi = INSETS.inset_axes(pD, width="66%", height="40%", loc=1)
    #h.topology()
    
    Ld = 0.5
    Ld2 = 1.0
    
    VClamp = h.SEClamp(0.5, cell)
    VClamp.dur1 = tsteps[0]
    VClamp.amp1 = vsteps[0]
    VClamp.dur2 = tsteps[1]
    VClamp.amp2 = vsteps[1]
    VClamp.dur3 = tsteps[2]
    VClamp.amp3 = vsteps[2]
    Rs0 = 10.
    VClamp.rs = Rs0
    compensation = [0., 70., 95.]
    cms = [cell.cm*(100.-c)/100. for c in compensation]
    
    vrec = h.iStim(Ld, sec=dend[0])
    vrec.delay = 0
    vrec.dur = 1e9 # these actually do not matter...
    vrec.iMax = 0.0
    vrec2 = h.iStim(Ld2, sec=dend[0])
    vrec2.delay = 0
    vrec2.dur = 1e9 # these actually do not matter...
    vrec2.iMax = 0.0

    stim = {}
    stim['NP'] = 1
    stim['Sfreq'] = 20 # stimulus frequency
    stim['delay'] = tsteps[0]
    stim['dur'] = tsteps[1]
    stim['amp'] = vsteps[1]
    stim['PT'] = 0.0
    stim['hold'] = vsteps[0]
#    (secmd, maxt, tstims) = make_pulse(stim)
    tend = 79.5
    linetype = ['-', '-', '-']
    linethick = [0.5, 0.75, 1.25]
    linecolor = [[0.66, 0.66, 0.66], [0.4, 0.4, 0.3], 'k'] 
    n = 0
    vcmds = [-70, -20]
    vplots = [(pA, pAi, pC, pCi), (pB, pBi, pD, pDi)]
    for m,  VX in enumerate(vcmds):
        stim['amp'] = VX
        pl = vplots[m]
        print m, VX
        (secmd, maxt, tstims) = make_pulse(stim)
        for n, rsc in enumerate(compensation):
            vec={}
            for var in ['VCmd', 'i_inj', 'time', 'Vsoma', 'Vdend',
                        'Vdend2', 'VCmdR']:
                vec[var] = h.Vector()
            VClamp.rs = Rs0*(100.-rsc)/100.
            cell.cm = cms[n]
           # print VClamp.rs, cell.cm, VClamp.rs*cell.cm
            vec['VCmd'] = h.Vector(secmd)
            vec['Vsoma'].record(cell(0.5)._ref_v, sec=cell)
            vec['Vdend'].record(dend[0](Ld)._ref_v, sec=dend[0])
            vec['time'].record(h._ref_t)
            vec['i_inj'].record(VClamp._ref_i, sec=cell)

            vec['VCmdR'].record(VClamp._ref_vc, sec=cell)
            VClamp.amp2 = VX
            #            vec['VCmd'].play(VClamp.amp2, h.dt, 0, sec=cell)

            h.tstop = tend
            h.init()
            h.finitialize(-60)
            h.run()
            vc = np.asarray(vec['Vsoma'])
            tc = np.asarray(vec['time'])
            
            # now plot the data, raw and as insets
            for k in [0, 1]:
                pl[k].plot(vec['time'], vec['i_inj'], color=linecolor[n], linestyle = linetype[n], linewidth=linethick[n])
                yl = pl[k].get_ylim()
                if k == 0:
                    pass
                    #pl[k].set_ylim([1.5*yl[0], -1.5*yl[1]])
                else:
                    pass
            
            for k in [2,3]:
                pl[k].plot(vec['time'], vec['Vsoma'], color=linecolor[n], linestyle = linetype[n], linewidth=linethick[n])
                pl[k].plot(vec['time'], vec['VCmdR'], color=linecolor[n], linestyle = '--', linewidth=1, dashes=(1,1))
                pl[k].plot(vec['time'], vec['Vdend'], color=linecolor[n], linestyle = linetype[n], linewidth=linethick[n], dashes=(3,3))
                if VX < vsteps[0]:
                    pl[k].set_ylim([-72, -40])
                else:
                    pl[k].set_ylim([-62,VX+30])

    ptx = 10.8
    pBi.set_xlim([9.8, ptx])
    pAi.set_xlim([9.8, ptx])
    PH.setX(pAi, pCi)
    PH.setX(pBi, pDi)
    pD.set_ylim([-65, 10])
#    PH.setY(pC, pCi) # match Y limits
    PH.cleanAxes([pA, pAi, pB, pBi, pC, pCi, pD, pDi])
    PH.formatTicks([pA, pB, pC, pD], axis='x', fmt='%d')
    PH.formatTicks([pC, pD], axis='y', fmt='%d')
    PH.calbar(pAi, [ptx-1, 0, 0.2, 2.])
    PH.calbar(pCi, [ptx-1, -50., 0.2, 10])
    PH.calbar(pBi, [ptx-1, 0, 0.2, 10])
    PH.calbar(pDi, [ptx-1, -50., 0.2, 20])
    pylab.draw()
    pylab.show()    
Example #21
0
    def get_nmda_iv_2017(self,
                         nmda_gmax,
                         vc_range=[-60, 60],
                         tstop=220,
                         t_rel=40.0):
        self.clamp = h.SEClamp(0.5, sec=self.root)
        self.clamp.dur1 = 10
        self.clamp.dur2 = 200
        self.clamp.dur3 = 10
        self.clamp.amp1 = -70
        self.clamp.amp2 = -70
        self.clamp.amp3 = -70
        self.clamp.rs = 0.0001

        pre = h.Section()
        pre.diam = 1.0
        pre.L = 1.0
        pre.insert('rel')
        pre.dur_rel = 0.5
        pre.amp_rel = 3.0
        pre.del_rel = t_rel

        nmda = h.NMDA_Mg_T(0.5, sec=self.root)
        # overwriting briefly... testing difference before  changing to ampa properly 2017_05_26
        # also for comapring presyantuic glutamte
        #print('overwritten for glu!')
        #nmda = h.cpampa12st(0.5,sec=self.root)
        #nmda.pconc = 0
        nmda.gmax = nmda_gmax

        h.setpointer(pre(0.5).rel._ref_T, 'C', nmda)

        h.load_file('stdrun.hoc')
        rec = {}
        for label in 't', 'v', 'i_nmda', 'g_nmda':
            rec[label] = h.Vector()

        rec['t'].record(h._ref_t)
        rec['i_nmda'].record(nmda._ref_i)
        rec['g_nmda'].record(nmda._ref_g)
        rec['v'].record(self.root(0.5)._ref_v)

        v_list, i_list, t_list, g_list = [], [], [], []
        h.tstop = tstop
        h.celsius = 32.0
        for vc in vc_range:
            h.init()
            #h.finitialize(v_init)
            self.clamp.amp2 = vc
            h.run()
            i = rec['i_nmda'].to_python()
            g = rec['g_nmda'].to_python()
            v = rec['v'].to_python()
            t = rec['t'].to_python()
            v_list.append(v)
            i_list.append(i)
            t_list.append(t)
            g_list.append(g)

        v = np.array(v_list).transpose()
        i = np.array(i_list).transpose() * 1000  # for pA
        t = np.array(t_list).transpose()
        g = np.array(g_list).transpose()

        return t, i, v, g  # in pA
Example #22
0
    def get_ampa_iv_2017(self,
                         ampa_gmax,
                         p_conc=0,
                         vc_range=[-60, 60],
                         tstop=220,
                         t_rel=40.0):
        self.clamp = h.SEClamp(0.5, sec=self.root)
        self.clamp.dur1 = 10
        self.clamp.dur2 = 200
        self.clamp.dur3 = 10
        self.clamp.amp1 = -70
        self.clamp.amp2 = -70
        self.clamp.amp3 = -70
        self.clamp.rs = 0.0001

        pre = h.Section()
        pre.diam = 1.0
        pre.L = 1.0
        pre.insert('rel')
        pre.dur_rel = 0.5
        pre.amp_rel = 3.0
        pre.del_rel = t_rel
        print('amp 3')

        cpampa = h.cpampa12st(0.5, sec=self.root)
        cpampa.pconc = p_conc
        cpampa.gmax = ampa_gmax

        h.setpointer(pre(0.5).rel._ref_T, 'C', cpampa)

        h.load_file('stdrun.hoc')
        rec = {}
        for label in 't', 'v', 'i_ampa', 'g_ampa':
            rec[label] = h.Vector()

        rec['t'].record(h._ref_t)
        rec['i_ampa'].record(cpampa._ref_i)
        rec['g_ampa'].record(cpampa._ref_g)
        rec['v'].record(self.root(0.5)._ref_v)

        v_list, i_list, t_list, g_list = [], [], [], []
        h.tstop = tstop
        h.celsius = 32.0

        for vc in vc_range:
            h.init()
            #h.finitialize(v_init)
            self.clamp.amp2 = vc
            h.run()
            i = rec['i_ampa'].to_python()
            g = rec['g_ampa'].to_python()
            v = rec['v'].to_python()
            t = rec['t'].to_python()
            v_list.append(v)
            i_list.append(i)
            t_list.append(t)
            g_list.append(g)

        v = np.array(v_list).transpose()
        i = np.array(i_list).transpose() * 1000  # for pA
        t = np.array(t_list).transpose()
        g = np.array(g_list).transpose(
        ) * 1 * 10**6  # this is defined as microSiemens in the mod file: 1000000, so for pico 1e-6

        return t, i, v, g  # in pA
# icc1.L = 5000
# icc1.diam=1
# icc1.connect(icc(1))
# icc1.cm=25
v_e = h.Vector()
v_e1 = h.Vector()
v_e2 = h.Vector()
v_e3 = h.Vector()
v_e4 = h.Vector()
v_e.record(icc(0.6)._ref_v)
v_e1.record(icc(0.7)._ref_v)
v_e2.record(icc(.8)._ref_v)
v_e3.record(icc(.9)._ref_v)
v_e4.record(icc(1)._ref_v)

vclamp = h.SEClamp(icc(0.5))
vclamp.dur1 = tstop
vclamp.amp1 = -50.0
vclamp.rs = .00001
h.v_init = -80

run_and_record(icc, *variables)

t = np.array(t.to_python())
ina = h.area(0.5) * 10 * np.array(ina.to_python())
ik = h.area(0.5) * 10 * np.array(ik.to_python())
ik_ERG = h.area(0.5) * 10 * np.array(ik_ERG.to_python())
ik_Kb = h.area(0.5) * 10 * np.array(ik_Kb.to_python())
ik_kv11 = h.area(0.5) * 10 * np.array(ik_kv11.to_python())
ica_vddr = h.area(0.5) * 10 * np.array(ica_vddr.to_python())
ik_bk = h.area(0.5) * 10 * np.array(ik_bk.to_python())
Example #24
0
def measure_psc(gid,
                pop_name,
                presyn_name,
                env,
                v_init,
                v_holding,
                load_weights=False,
                cell_dict={}):

    biophys_cell = init_biophys_cell(env,
                                     pop_name,
                                     gid,
                                     register_cell=False,
                                     load_weights=load_weights,
                                     cell_dict=cell_dict)
    hoc_cell = biophys_cell.hoc_cell

    h.dt = env.dt

    stimdur = 1000.0
    tstop = stimdur
    tstart = 0.

    soma = list(hoc_cell.soma)[0]
    se = h.SEClamp(soma(0.5))
    se.rs = 10
    se.dur = stimdur
    se.amp1 = v_holding

    h('objref nil, tlog, ilog, Vlog')

    h.tlog = h.Vector()
    h.tlog.record(h._ref_t)

    h.Vlog = h.Vector()
    h.Vlog.record(soma(0.5)._ref_v)

    h.ilog = h.Vector()
    ilog.record(se._ref_i)

    h.tstop = tstop

    neuron_utils.simulate(v_init, 0., stimdur)

    vec_i = h.ilog.to_python()
    vec_v = h.Vlog.to_python()
    vec_t = h.tlog.to_python()

    idx = np.where(vec_t > tstart)[0]
    vec_i = vec_i[idx]
    vec_v = vec_v[idx]
    vec_t = vec_t[idx]

    t_holding = vec_t[0]
    i_holding = vec_i[0]

    i_peak = np.max(np.abs(vec_i[1:]))
    peak_index = np.where(np.abs(vec_i) == i_peak)[0][0]
    t_peak = vec_t[peak_index]

    logger.info("measure_psc: t_peak = %f i_holding = %f i_peak = %f" %
                (t_peak, i_holding, i_peak))

    amp_i = abs(i_peak - i_holding) * 1000

    logger.info("measure_psc: amp_i = %f" % amp_i)

    return amp_i
Example #25
0
def runsim_vclamp(
    tstop=15.0,
    dt=0.01,
    temp=21.0,
    dur1=5.0,
    dur2=5.0,
    dur3=5.0,
    amp1=-70.0,
    amp2=0.0,
    amp3=-70.0,
    tea=False,
    ttx=False,
):
    Soma = h.Section()
    Soma.L = 15
    Soma.nseg = 7
    Soma.diam = 15
    area = np.pi * 15.0 * 15.0  #in µm²
    Soma.insert("hh")
    Soma.ena = 50
    if ttx:
        Soma.gnabar_hh = 1e-9
    else:
        Soma.gnabar_hh = 0.12
    if tea:
        Soma.gkbar_hh = 1e-9
    else:
        Soma.gkbar_hh = 0.023
    # GENERAL SETTINGS
    h.dt = dt  # simulation (or "sampling") rate
    h.celsius = temp  # simulation global temperature
    SEC = h.SEClamp(Soma(0.5))
    SEC.rs = 0.1
    SEC.dur1 = dur1
    SEC.dur2 = dur2
    SEC.dur3 = dur3
    SEC.amp1 = amp1
    SEC.amp2 = amp2
    SEC.amp3 = amp3
    Vm = h.Vector()
    Vm.record(Soma(0.5)._ref_v)
    INa = h.Vector()
    IK = h.Vector()
    IL = h.Vector()
    INa.record(Soma(0.5)._ref_ina)
    IK.record(Soma(0.5)._ref_ik)
    IL.record(Soma(0.5)._ref_il_hh)
    Ie = h.Vector()
    Ie.record(SEC._ref_i)
    hhm = h.Vector()
    hhm.record(Soma(0.5)._ref_m_hh)
    hhn = h.Vector()
    hhn.record(Soma(0.5)._ref_n_hh)
    hhh = h.Vector()
    hhh.record(Soma(0.5)._ref_h_hh)
    Im = h.Vector()
    Im.record(SEC._ref_i)
    nrngo(tstop, -70.0)
    # PACK AND EXPORT DATA
    t = np.linspace(0, tstop - dt, int(np.round(tstop / dt)))
    Vm = np.array(Vm)
    Im = np.array(INa) + np.array(IK) + np.array(IL)
    #mA/cm2 be multiplied by (area in µm² * 0.01) to get nA
    Im = Im * (area * 0.01)
    Ie = np.array(Ie)
    hhm = np.array(hhm)
    hhn = np.array(hhn)
    hhh = np.array(hhh)
    return (t, Im, Ie, Vm, hhm, hhn, hhh)
Example #26
0
dend.insert('pas')
dend.g_pas = 0.001  # Passive conductance in S/cm2
dend.e_pas = -65  # Leak reversal potential mV

# Change the maximum sodium conductance of the middle segment of the soma to 0.13
soma(0.5).hh.gnabar = 0.13

# Change the equilibrium potential of the passive mechanism in the middle segment of the dend to -65
dend(0.5).pas.e = -65

for sec in h.allsec():
    for seg in sec:
        for mech in seg:
            print sec.name(), seg.x, mech.name()

vstim = h.SEClamp(dend(1.0))
vstim.dur1 = 2
vstim.amp1 = -30

# add synapse (custom channel)
syn = h.AlphaSynapse(dend(1.0))
syn.e = 0  # equilibrium potential in mV
syn.onset = 20  # turn on after this time in ms
syn.gmax = 0.1  # set conductance in uS
syn.tau = 0.1  # set time constant

# add current clamp stimulus
stim = h.IClamp(dend(1.0))
stim.amp = 0.3  # input current in nA
stim.delay = 40  # turn on after this time in ms
stim.dur = 1  # duration of 1 ms
Example #27
0
from neuron import h
import matplotlib.pyplot as plt
import numpy as np

h.load_file('init_models_with_ca/init_model2.hoc')
h.delete_section(sec=h.axon)
h.delete_section(sec=h.iseg)
h.delete_section(sec=h.hillock)

# Set up stimulus
stim = h.SEClamp(h.apical(1))
stim.amp1 = -70
stim.amp2 = -40
stim.amp3 = -70
stim.dur1 = 500

stim.dur3 = 100

# Set up recording vectors
apical_end_v_vec = h.Vector()
apical_end_v_vec.record(h.apical(1)._ref_v)
tuft_v_vec = h.Vector()
tuft_v_vec.record(h.tuft(.5)._ref_v)
t_vec = h.Vector()
t_vec.record(h._ref_t)

# Simulation parameters
dt = 0.025
h.tstop = 1000 - dt
h.tuft.gbar_sca = 0
Example #28
0
 def test_is_point_process(self):
     section = h.Section()
     clamp = h.SEClamp(section(0.5))
     assert simulator.is_point_process(clamp)
     section.insert('hh')
     assert not simulator.is_point_process(section(0.5).hh)
Example #29
0
soma = h.Section()
soma.insert('hh')
soma.insert('pas')
#soma.insert('hcno')
soma.L = 20
soma.diam = 20
soma(0.5).pas.g = 2e-5
#soma(0.5).hcno.gbar = 15e-4

ic = h.IClamp(soma(0.5))
ic.dur = 1e9
ic.delay = 0
icRec = h.Vector()
icRec.record(soma(0.5)._ref_v)

vc = h.SEClamp(soma(0.5))
vc.dur1 = 1e9
vc.rs = 5  # Rs, in megohms
#vc.amp1 = 0
#vc.dur2 = 1e9
vcrs = vc.rs
vcRec = h.Vector()
vcRec.record(vc._ref_i)

# add an alpha synapse, reversal -7 mV
# note that synaptic current will appear in the SEClamp or IClamp
syn = h.AlphaSynapse(soma(0.5))

t = 0

Example #30
0
def simulate(tau_facil,
             tau_rec,
             stim_freq,
             celltype,
             tau_1=0.3,
             tau_2=0.6,
             u0=0.078,
             sampling_interval=0.5,
             v_clamp=-70.42,
             sec='proxd'):
    """Simulates a frequency stimulation of the tmgexp2syn meachnism onto a
    neuron and measure the conductance at the soma.

    Parameters
    ----------
    tau_facil : numeric
        facilitation time constant of the tmgexp2syn mechanism
        
    tau_rec : numeric
        recovery time constant of the tmgexp2syn mechanism
        
    stim_freq : numeric
        stimulation frequency in Hz
        
    celltype : ouropy.GenNeuron
        A class that inherits from ouropy.GenNeuron
        
    tau_1 : numeric
        Synaptic rise time
        
    tau_2 : numeric
        Synaptic decay time
        
    u0 : float
        The u0 parameters as specified in tmgexp2syn
        
    sampling_interval : numeric
        The sampling interval in ms
        
    v_clamp : numeric
        Holding potential of the
        
    Returns
    -------
    peaks_norm : ndarray
        Peak conductances normalized to first peak
    
    garr_norm : ndarray
        Conductance array normalized to first peak
    """
    # Resolve simulation hyperparameters
    left_pad, right_pad = 50, 100  # in ms
    simdur = left_pad + right_pad + 10 * (1000 / stim_freq)
    # Create cell
    mycell = celltype()
    # Create synapse
    syn = h.tmgexp2syn(mycell.get_segs_by_name(sec)[0](0.5))
    syn.tau_1 = tau_1
    syn.tau_2 = tau_2
    syn.tau_facil = tau_facil
    syn.tau_rec = tau_rec
    syn.u0 = u0
    syn.e = 0
    # Create stimulation
    stim_period_ms = 1000 / stim_freq
    stim = h.NetStim()
    stim.interval = stim_period_ms
    stim.start = left_pad
    stim.number = 10
    nc = h.NetCon(stim, syn)
    nc.weight[0] = 0.001
    # Create voltage clamp
    c = h.SEClamp(mycell.soma(0.5))
    c.dur1 = simdur
    c.amp1 = v_clamp
    c.rs = 0.1
    # Create recording vector
    ivec = h.Vector()
    ivec.record(c._ref_i)
    # Start simulation
    sample_period_ms = sampling_interval
    h.cvode.active(0)
    h.finitialize(-70.42)
    h.t = -2000
    h.secondorder = 0
    h.dt = 10
    while h.t < -100:
        h.fadvance()
    h.secondorder = 0
    h.t = 0
    h.dt = sample_period_ms
    h.steps_per_ms = 1.0 / h.dt
    h.frecord_init()  # Necessary after changing t to restart the vectors
    while h.t < simdur:
        h.fadvance()
    # Get Peaks from output

    iarr = np.array(ivec)
    garr = (iarr - iarr[0:50].mean()) / v_clamp
    stim_dtp = int(np.around(stim.interval / sampling_interval))
    pad_dtp = int(left_pad / sampling_interval)
    t_stim = np.arange(pad_dtp, stim_dtp * 11 + pad_dtp, stim_dtp)
    #dtp_stim = np.array(t_stim / sampling_interval, dtype=np.int)
    dtp_stim = np.array(t_stim, dtype=np.int)
    gvec_split = np.array(np.split(garr, dtp_stim)[1:-1])

    peaks = gvec_split.max(axis=1)
    peaks_norm = peaks / peaks[0]
    garr_norm = garr / peaks[0]

    return peaks_norm, garr_norm