Ejemplo n.º 1
0
    def test_record_before_sim(self):
        """
        Record created before simulation run is full of data
        """
        # Record
        rec = Record(self.soma(0.5))

        # IClamp to soma
        iclamp = IClamp(segment=self.soma(0.5))
        iclamp.stim(delay=25, dur=3, amp=3)

        # Run
        sim = Simulation(init_v=-70, warmup=20)
        sim.run(1)
        print(h.t)

        sim.run(100)
        r = rec.as_numpy(variable="v")

        # Make assertions
        self.assertEqual(4051, r.size)
        self.assertEqual(34.3815, round(r.records.max(), 4))
        self.assertEqual(-75.3247, round(r.records.min(), 4))

        self.assertEqual(330, r.records.argmax())
        # time in ms of max mV value
        self.assertEqual(28, round(r.time[r.records.argmax()], 4))
Ejemplo n.º 2
0
 def run_and_get_rec():
     rec = Record(self.soma(0.5))
     iclamp = IClamp(segment=self.soma(0.5))
     iclamp.stim(delay=25, dur=3, amp=3)
     sim = Simulation(init_v=-70, warmup=20)
     sim.run(100)
     return rec
Ejemplo n.º 3
0
    def _prepare_iclamp_protocol(self, iclamp: IClampProtocol, global_time):
        iclamp_obj = IClamp(iclamp.seg)
        current_time = global_time + iclamp.init

        for _ in range(iclamp.num):
            iclamp_obj.stim(delay=current_time, dur=iclamp.dur, amp=iclamp.amp)
            current_time += iclamp.int
        current_time = global_time
        current_time += iclamp.init

        self.iclamp.append(iclamp_obj)
        return current_time
Ejemplo n.º 4
0
def get_cell_with_iclamps_as_synapses(warmup, dur, name, input_size, low=0.08, high=0.1):
    # Create cell
    cell = Cell(name=name)
    soma = cell.add_sec("soma", diam=10, l=10, nseg=5)
    dend = cell.add_sec("dend", diam=5, l=100, nseg=50)
    cell.connect_secs(child=dend, parent=soma)
    cell.insert("hh")

    # Make synapses
    iclamp_syns = []
    for i in range(input_size):
        iclamp = IClamp(segment=dend(np.random.rand()))
        syn = iclamp.stim(delay=warmup, dur=dur, amp=UniformDist(low=low, high=high))
        iclamp_syns.append(syn)

    # Make recording
    rec = Record(elements=soma(0.5), variables='v')
    cell.make_spike_detector(seg=soma(0.5))
    return cell, iclamp_syns, rec
Ejemplo n.º 5
0
    def test_record_after_sim(self):
        """
        record created after simulation run is empty
        """
        # IClamp to soma
        iclamp = IClamp(segment=self.soma(0.5))
        iclamp.stim(delay=25, dur=3, amp=3)

        # Run
        sim = Simulation(init_v=-70, warmup=20)
        sim.run(1)
        print(h.t)

        # Record
        rec = Record(self.soma(0.5))

        sim.run(100)
        r = rec.as_numpy(variable="v")

        # Make assertion
        self.assertEqual(0, r.size)
Ejemplo n.º 6
0
    def test_iclamp_after_sim(self):
        """
        IClamp works in a regular way after simulation run. in this case (amplitude 3 pA)
        we have spike at the soma.

        However IClamp delay is in the absolute time.
        """
        # Record
        rec = Record(self.soma(0.5))

        # Run
        sim = Simulation(init_v=-70, warmup=20)
        sim.run(1)

        # IClamp to soma
        iclamp = IClamp(segment=self.soma(0.5))
        iclamp.stim(delay=25, dur=3, amp=3)

        sim.run(100)
        r = rec.as_numpy(variable="v")

        sim.remove_immediate_from_neuron()
        rec.remove_immediate_from_neuron()
        iclamp.remove_immediate_from_neuron()

        # Make assertions
        self.assertEqual(4051, r.size)
        self.assertEqual(34.3815, round(r.records.max(), 4))
        self.assertEqual(-75.3247, round(r.records.min(), 4))

        self.assertEqual(330, r.records.argmax())
        # time in ms of max mV value
        self.assertEqual(28, round(r.time[r.records.argmax()], 4))
Ejemplo n.º 7
0
cell.insert("hh")

# Create stim and synapses
ns_cell = NetStimCell("stim_cell")
ns = ns_cell.make_netstim(start=30, number=5, interval=10)

syns = cell.add_synapses_with_spine(source=ns,
                                    secs=cell.filter_secs("apic"),
                                    mod_name="ExpSyn",
                                    netcon_weight=0.01,
                                    delay=1,
                                    number=100)
soma = cell.filter_secs("soma")

# Create IClamp
ic = IClamp(segment=soma(0.5))
ic.stim(delay=100, dur=10, amp=0.1)

# prepare plots and spike detector
rec_v = Record(soma(0.5), variables="v")
cell.make_spike_detector(soma(0.5))

# run
sim = Simulation(init_v=-65,
                 warmup=20,
                 init_sleep=2,
                 with_neuron_gui=True,
                 shape_plots=[make_shape_plot()])
sim.run(runtime=200, stepsize=1, delay_between_steps=500)

# plot
Ejemplo n.º 8
0
    def make_protocol(self,
                      protocol: str,
                      start,
                      isi=1,
                      iti=1,
                      epsp_synapse: [Synapse, ComplexSynapse] = None,
                      i_clamp_section: Sec = None,
                      train_number=1,
                      copy_netconn_params=True):
        """
        Create an experimental protocol of EPSPs and APs.

        Each element of the experiment (EPSP or AP) is separated by isi (in ms).

        :param protocol:
            string eg. 3xEPSP[int=10,w=2.5,thr=5,del=2] 3xAP[int=10,dur=3,amp=1.6]

            Params ofr EPSP and AP:
            int - interval between in ms

            Params for EPSP only:
            w - weight for netconn (default is 1.0) -> used only when copy_netconn_params=False
            del - delay for netconn (default is 1.0) -> used only when copy_netconn_params=False
            thr - threshold for netconn (default is 10) -> used only when copy_netconn_params=False

            Params for AP only:
            dur - duration of AP in ms
            amp - amplitude in nA

        :param epsp_synapse:
            synapse to stimulate. Default is None if you don't want to stimulate synapse
        :param i_clamp_section:
            section to input IClamp. Default is None if you don't want to stimulate any section by electrode (eg. making AP)
            It is assumed that IClamp stimulate i_clamp_section(0.5) segment.
        :param start:
            start time of the first stimuli in ms, it is absolute time, so bear in mind warmup time.
        :param isi:
            Inter Stimulus Interval, eg. 3xEPSP,2xAP -isi- 3xEPSP,2xAP
        :param iti:
            Inter Train Interval eg. 3xEPSP,2xAP -isi- 3xEPSP,2xAP -iti- 3xEPSP,2xAP-isi-3xEPSP,2xAP
        :param train_number:
            number of trains. Default is 1
        :param copy_netconn_params:
            If copy_netconn_params=True it will copy NetConn params from the last NetConn added to the synapse.
        :return:
            tuple(NetStim, IClamp).
            If epsp_synapse is None NetStim will be None
            If i_clamp_section is None IClamp will be None
        """
        #if start < h.t:
        #    raise ValueError("Experimental protocol 'start' param must > h.t (time of the simulation), but your "
        #                     "start=%s and h.t=%s. Bear in mind that 'start' param is the absolute time" % (start, h.t))

        protocol = protocol.lower()
        protocols = protocol.split(" ")

        netstim = None
        if epsp_synapse:
            netstim = NetStimCell(name="stim")
            self.netstims.append(netstim)

        iclamp = None
        if i_clamp_section:
            iclamp = IClamp(i_clamp_section(0.5))
            self.iclamps.append(iclamp)

        event_time = start
        for train_no in range(train_number):

            for p in protocols:
                event_time = self._prepare_protocol(p, netstim, iclamp,
                                                    event_time, epsp_synapse,
                                                    copy_netconn_params)
                event_time += isi

            event_time += iti
            return netstim, iclamp
Ejemplo n.º 9
0
    cell.make_default_mechanisms()

    soma = cell.filter_secs("soma")

    # Netstim to synapse
    stim = NetStimCell("stim").add_netstim(start=WARMUP,
                                           number=REPS,
                                           interval=interval)
    syn = cell.add_synapse(source=stim,
                           netcon_weight=WEIGHT,
                           mod_name="Syn4P",
                           delay=1,
                           seg=cell.filter_secs('apic[1]')(0.5))

    # IClamp to soma
    iclamp = IClamp(segment=cell.filter_secs("soma")(0.5))
    for i in range(REPS):
        start_t = WARMUP + delta_t + i * interval
        iclamp.stim(delay=start_t, dur=DUR, amp=AMP)

    # Record
    rec = Record([s(0.5) for s in cell.filter_secs("apic[1],apic[50]")])

    # Run
    sim = Simulation(init_v=-70, warmup=WARMUP, dt=DT)
    total_time = REPS * interval + COOL_DOWN
    sim.run(total_time)

    # Plot
    rec.plot(position="merge")
    plt.show()