def simulate(self, current_base, current_rebound):

        sim = self.env.Simulation(**self.sim_kwargs)
        cell = self.cell_functor(sim=sim)

        soma_loc = cell.get_location('soma')

        cc1 = sim.create_currentclamp(name="cclamp", amp=current_base, dur="100:ms", delay="50:ms", cell_location=soma_loc)
        cc2 = sim.create_currentclamp(name="cclamp2", amp=-1*current_rebound, dur="5:ms", delay="80:ms", cell_location=soma_loc)
        cc3 = sim.create_currentclamp(name="cclamp3", amp=-1*current_rebound, dur="5:ms", delay="120:ms", cell_location=soma_loc)

        sim.record(cc1, name="Current1",      what=CurrentClamp.Recordables.Current,  description="CurrentClampCurrent")
        sim.record(cc2, name="Current2",      what=CurrentClamp.Recordables.Current,  description="CurrentClampCurrent")
        sim.record(cc3, name="Current3",      what=CurrentClamp.Recordables.Current,  description="CurrentClampCurrent")

        sim.record(cell, name="SomaVoltage", cell_location=soma_loc,  what=Cell.Recordables.MembraneVoltage,  description="Response to iInj1=%s iInj2=%s"%(current_base, current_rebound))

        res = sim.run()


        #SimulationSummariser(res, "/home/michael/Desktop/ForRoman.pdf")

        i = res.get_trace('Current1').convert_to_fixed(qty("0.5:ms")) + res.get_trace('Current2').convert_to_fixed(qty("0.5:ms")) + res.get_trace('Current3').convert_to_fixed(qty("0.5:ms"))

        i = TraceConverter.rebase_to_fixed_dt(res.get_trace('Current1'
               ), dt=qty('0.5:ms')) \
            + TraceConverter.rebase_to_fixed_dt(res.get_trace('Current2'
               ), dt=qty('0.5:ms')) \
            + TraceConverter.rebase_to_fixed_dt(res.get_trace('Current3'
               ), dt=qty('0.5:ms'))
        i.tags = [StandardTags.Current]
        return (res.get_trace('SomaVoltage'), i)
 def make_cell(sim, cell_name, cell_chl_functor):
     m1 = mf.MorphologyBuilder.get_single_section_soma(area=mf.qty("1:um2"))
     cell = sim.create_cell(name=cell_name, morphology=m1)
     for chl in cell_chl_functor():
         cell.apply_channel( chl, parameter_multipliers={'gmax':random.uniform(0.9, 1.1)})
     cell.set_passive( mf.PassiveProperty.SpecificCapacitance, mf.qty('4:pF/um2'))
     return cell
 def build_trigger( env, cell):
     return env.SynapticTrigger(
                 mfc.SynapticTriggerByVoltageThreshold,
                 cell_location = cell.soma,
                 voltage_threshold = mf.qty("0:mV"),
                 delay = mf.qty("1:ms"),
                 #,
                )
 def load_ka_channel():
     ka_param_names = """
     ka_gmax ka_erev
     ka_m_a1 ka_m_a2 ka_m_a3 ka_m_a4 ka_m_a5
     ka_m_b1 ka_m_b2 ka_m_b3 ka_m_b4 ka_m_b5
     ka_h_a1 ka_h_a2 ka_h_a3 ka_h_a4 ka_h_a5
     ka_h_b1 ka_h_b2 ka_h_b3 ka_h_b4 ka_h_b5
     """
 
     ka_param_units = """
     nS/um2; mV;
     ms-1; mV-1 ms-1; ;mV; mV;
     ms-1; mV-1 ms-1; ;mV; mV;
     ms-1; mV-1 ms-1; ;mV; mV;
     ms-1; mV-1 ms-1; ;mV; mV;
     """
     ka_param_str = """
     30   -80
     12.025   0   0.5 -10.01  -12.56
     14.325   0   1    -8.01    9.69
     0.0001   0   1    15.88   26.0
     10.000   0   500 -22.09  -10.21
     """
 
     nrn_params = dict([(p, mf.qty("%s:%s"%(v, u.strip()))) for (p, u, v) in zip(ka_param_names.split(), ka_param_units.split(';'), ka_param_str.split())])
     nrn_params_ka = extract_params(nrn_params, prefix='ka_')
     print nrn_params_ka
     eqnsetka = mf.neurounits.NeuroUnitParser.Parse9MLFile(ka_eqnset_txt.replace("sautois", "saut2")).get_component()
     kaChls = mfc.Neuron_NeuroUnitEqnsetMechanism(name="Chl5", eqnset=eqnsetka,  default_parameters = nrn_params_ka)
     return kaChls
 def test_cell_current(cell_name, cell_chl_functor, current):
     sim = mf.NEURONEnvironment().Simulation()
 
     m1 = mf.MorphologyBuilder.get_single_section_soma(area=mf.qty("1:um2"))
     cell = sim.create_cell(name=cell_name, morphology=m1)
     cc = sim.create_currentclamp(name="CC1", delay=100*mf.ms, dur=400*mf.ms, amp=current * mf.pA, cell_location=cell.soma)
 
     for chl in cell_chl_functor():
         mf.cell.apply_channel( chl)
 
     mf.cell.set_passive( mf.PassiveProperty.SpecificCapacitance, mf.qty('4:pF/um2'))
 
     sim.record(cell, what=mf.Cell.Recordables.MembraneVoltage)
     sim.record(cc, what=mf.CurrentClamp.Recordables.Current)
 
     res =sim.run()
     return res
    def plot_iv_curve(self, ax=None):
        # pylint: disable=E1103
        title = '%s: IV Curve' % (self.cell_description or None)
        if not ax:
            f = QuantitiesFigure()
            f.suptitle(title)
            ax = f.add_subplot(1, 1, 1)
            ax.set_xlabel('Injected Current')
            ax.set_ylabel('SteadyStateVoltage')

        V_in_mV = [self.get_iv_point_steaddy_state(c).rescale('mV').magnitude for c in self.currents]
        v = np.array(V_in_mV) * units.mV
        i = morphforge.units.factorise_units_from_list(self.currents)

        low_v = V_in_mV < self.v_regressor_limit if self.v_regressor_limit else range( len(V_in_mV))



        print 'i[low_v]', i[low_v]
        print 'v[low_v]', v[low_v]
        ax.plot(i[low_v], v[low_v], )
        ax.plot(i[np.logical_not(low_v)], v[np.logical_not(low_v)], )
        ax.plot(i[np.logical_not(low_v)], v[np.logical_not(low_v)], )

        # Plot the regressor:
        i_units = qty('1:pA').units
        v_units = qty('1:mV').units
        iv = np.vstack((i.rescale(i_units).magnitude,
                       v.rescale(v_units).magnitude)).T

        if not len(iv[low_v, 0]):
            return
        import scipy.stats as stats
        (a_s, b_s, r, tt, stderr) = stats.linregress(iv[low_v, 0], iv[low_v, 1])
        input_resistance = (a_s * (v_units / i_units)).rescale('MOhm')
        reversal_potential = b_s * v_units

        self.input_resistance = input_resistance
        self.reversal_potential = reversal_potential

        ax.plot(i, i*input_resistance + reversal_potential,'o-', label = "Fit: [V(mV) = %2.3f * I(pA)  + %2.3f]"%(a_s, b_s) + " \n[Input Resistance: %2.2fMOhm  Reversal Potential: %2.2f mV"%(input_resistance, reversal_potential)  )
        ax.legend()

        PM.save_figure(figname=title)
示例#7
0
    def get_cell(self, env, sim):
        m1 = mf.MorphologyBuilder.get_single_section_soma(area=float(self.area) * mf.units.um2)

        morph_functor = mf.MorphologyLibrary.get_morphology_functor(
            modelsrc=Model.Hull12SWithAxon, celltype=CellType.dIN
        )
        m1 = morph_functor(axonDiam=0.4)

        myCell = sim.create_cell(name="Cell1", morphology=m1)
        myCell.set_passive(mf.PassiveProperty.SpecificCapacitance, mf.qty("%f:uF/cm2" % self.capacitance))
        return myCell
    def __init__(self, cell_functor, currents, cell_description=None, sim_functor=None, v_regressor_limit=None, sim_kwargs=None, plot_all=False):
        self.cell_functor = cell_functor
        self.v_regressor_limit = v_regressor_limit
        self.fig=None
        #Previously = qty("-30:mV")

        self.sim_kwargs = sim_kwargs or {}

        self.tCurrentInjStart = qty('50:ms')
        self.tCurrentInjStop = qty('200:ms')

        self.tSteaddyStateStart = qty('100:ms')
        self.tSteaddyStateStop = qty('151:ms')

        self.traces = {}

        self.currents = currents
        self.cell_description = cell_description or 'Unknown Cell'

        self.input_resistance = qty('-1:MOhm')

        if plot_all:
            self.plot_all()
 def load_std_channels(param_str):
     nrn_params = dict([(p, mf.qty("%s:%s"%(v, u.strip()))) for (p, u, v) in zip(param_names.split(), param_units.split(';'), param_str.split())])
     nrn_params_na = extract_params(nrn_params, prefix='na_')
     nrn_params_lk = extract_params(nrn_params, prefix='lk_')
     nrn_params_ks = extract_params(nrn_params, prefix='ks_', replace_prefix='k_')
     nrn_params_kf = extract_params(nrn_params, prefix='kf_', replace_prefix='k_')
     nrn_params_ks = remap_keys(nrn_params_ks, {'k_gmax':'gmax', 'k_erev':'erev'})
     nrn_params_kf = remap_keys(nrn_params_kf, {'k_gmax':'gmax', 'k_erev':'erev'})
     eqnsetna = mf.neurounits.NeuroUnitParser.Parse9MLFile(na_eqnset_txt).get_component()
     eqnsetlk = mf.neurounits.NeuroUnitParser.Parse9MLFile(lk_eqnset_txt).get_component()
     eqnsetk = mf.neurounits.NeuroUnitParser.Parse9MLFile(k_eqnset_txt).get_component()
 
     na_chl = mfc.Neuron_NeuroUnitEqnsetMechanism(name="Chl1", eqnset=eqnsetna, default_parameters = nrn_params_na)
     lk_chl = mfc.Neuron_NeuroUnitEqnsetMechanism(name="Chl2", eqnset=eqnsetlk, default_parameters = nrn_params_lk)
     ksChls = mfc.Neuron_NeuroUnitEqnsetMechanism(name="Chl3", eqnset=eqnsetk,  default_parameters = nrn_params_ks)
     kfChls = mfc.Neuron_NeuroUnitEqnsetMechanism(name="Chl4", eqnset=eqnsetk,  default_parameters = nrn_params_kf)
 
     chls =  [na_chl, lk_chl, ksChls, kfChls]
     return chls
示例#10
0
 def getInputStimulus(self, sim, cell):
     somaLoc = cell.get_location("soma")
     s1 = sim.create_currentclamp(
         name="Stim1",
         amp=mf.qty("%2.2f:pA" % self.amp1),
         dur=mf.qty("%f:ms" % self.dur1),
         delay=mf.qty("%f:ms" % self.delay1),
         cell_location=somaLoc,
     )
     s2 = sim.create_currentclamp(
         name="Stim2",
         amp=mf.qty("%2.2f:pA" % self.amp2),
         dur=mf.qty("%f:ms" % self.dur2),
         delay=mf.qty("%f:ms" % self.delay2),
         cell_location=somaLoc,
     )
     return None
示例#11
0



import morphforge.stdimports as mf
from mhlibs.quantities_plot import QuantitiesFigure
import pylab

from morphforge.stdimports import qty, reduce_to_variable_dt_trace


t1 = mf.TraceGenerator.generate_flat(value='1:mV')
#t2 = mf.TraceGenerator.generate_flat(value='0.0015:V')
t2 = mf.TraceGenerator.generate_ramp(value_start='0.0015:V', value_stop='2.5:mV', npoints=20)



f = QuantitiesFigure()
ax = f.add_subplot(111)
ax.plotTrace(t1, marker='x')
ax.plotTrace(t2, marker='o')
ax.plotTrace(t1+t2, marker='<')
ax.plotTrace((t2+t2)*3.0+qty('0.03:V'), marker='<')

t1 = mf.fixed_to_variable_dt_trace(t1, '0.01:mV')
ax.plotTrace(t1, marker='>')
ax.legend()

pylab.show()