Esempio n. 1
0
 def hh_cell(name):
     cell = Cell(name=f"cell_{name}")
     soma = cell.add_sec("soma", diam=20, l=20, nseg=10)
     cell.add_sec("apic", diam=2, l=50, nseg=100)
     cell.insert("hh")
     cell.connect_secs(child="apic", parent="soma", child_loc=0, parent_loc=1)
     cell.make_spike_detector(soma(0.5))
     return cell
Esempio n. 2
0
    def test_remove_new_cell_with_no_ref(self):
        """
        deletion of cell, when all its sections have no reference outside - deletes all its
        sections as well
        """
        cell = Cell(name="cell")
        soma = cell.add_sec("soma")
        dend1 = cell.add_sec("dend1")
        dend2 = cell.add_sec("dend2")
        cell.connect_secs(child=dend1, parent=soma, child_loc=0, parent_loc=0.1)
        cell.connect_secs(child=dend2, parent=soma, child_loc=0, parent_loc=0.9)

        soma = None
        dend1 = None
        dend2 = None

        self.assertEqual(6, _get_secs())
        cell.remove_immediate_from_neuron()
        self.assertEqual(3, _get_secs())
Esempio n. 3
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
Esempio n. 4
0
    def test_remove_new_cell_with_remove_immediate(self):
        """
        remove immediate removes each section immediate only if there is no reference to the HOC
        object of this section outside the Sec object.
        """
        cell = Cell(name="cell")
        soma = cell.add_sec("soma")
        dend1 = cell.add_sec("dend1")
        dend2 = cell.add_sec("dend2")
        cell.connect_secs(child=dend1, parent=soma, child_loc=0, parent_loc=0.1)
        cell.connect_secs(child=dend2, parent=soma, child_loc=0, parent_loc=0.9)

        self.assertEqual(6, _get_secs())

        soma.remove_immediate_from_neuron()
        dend1.remove_immediate_from_neuron()
        dend2.remove_immediate_from_neuron()

        self.assertEqual(3, _get_secs())
        cell.remove_immediate_from_neuron()
Esempio n. 5
0
    def test_remove_new_cell_with_del_ref(self):
        """
        deletion of cell, when all its outside references are deletes - deletes all its
        sections as well. But deletion of single soma won't delete section soma since its reference
        is still in Cell
        """
        cell = Cell(name="cell")
        soma = cell.add_sec("soma")
        dend1 = cell.add_sec("dend1")
        dend2 = cell.add_sec("dend2")
        cell.connect_secs(child=dend1, parent=soma, child_loc=0, parent_loc=0.1)
        cell.connect_secs(child=dend2, parent=soma, child_loc=0, parent_loc=0.9)

        del soma
        del dend1
        del dend2

        self.assertEqual(6, _get_secs())
        cell.remove_immediate_from_neuron()
        self.assertEqual(3, _get_secs())
Esempio n. 6
0
class TestSection(unittest.TestCase):
    def setUp(self):
        self.cell = Cell(name="cell")
        self.soma = self.cell.add_sec("soma", diam=10, l=10, nseg=10)
        self.dend1 = self.cell.add_sec("dend1", diam=1, l=10, nseg=10)
        self.dend2 = self.cell.add_sec("dend2", diam=1, l=10, nseg=10)
        self.cell.connect_secs(child=self.dend1, parent=self.soma, child_loc=0, parent_loc=0.1)
        self.cell.connect_secs(child=self.dend2, parent=self.soma, child_loc=0, parent_loc=0.9)

    def tearDown(self):
        self.soma.remove_immediate_from_neuron()
        self.dend1.remove_immediate_from_neuron()
        self.dend2.remove_immediate_from_neuron()
        self.cell.remove_immediate_from_neuron()

        all_sec_num = _get_secs()
        if all_sec_num != 0:
            raise RuntimeError("Not all section have been removed after teardown. "
                               "Sections left: %s" % all_sec_num)

    def test_remove_synapse(self):
        """
        Removal of the parent section doesn't remove child sections
        """
        dend3 = self.cell.add_sec("dend3", diam=1, l=10, nseg=10)
        self.cell.connect_secs(child=dend3, parent=self.soma, child_loc=0, parent_loc=0.5)

        syn = self.cell.add_synapse(source=None, mod_name="Exp2Syn", seg=dend3(0.5))

        dend3 = None
        self.assertEqual(4, _get_secs())

        syn.remove_immediate_from_neuron()
        self.assertEqual(4, _get_secs())

    def test_remove_point_process(self):
        """
        Immediate removal of Point Process in outside reference makes
        that Point Process inside synapse also delete
        """
        syn = self.cell.add_synapse(source=None, mod_name="Exp2Syn", seg=self.dend2(0.5))
        syn.point_process.remove_immediate_from_neuron()
        self.assertEqual(0, len(self.cell.syns[0].point_process.__dict__))

    def test_remove_synapse2(self):
        """
        Remove outside reference and inside (Cell's) reference deletes section from NEURON
        """
        dend3 = self.cell.add_sec("dend3", diam=1, l=10, nseg=10)
        self.cell.connect_secs(child=dend3, parent=self.soma, child_loc=0, parent_loc=0.5)

        dend3 = None
        self.assertEqual(4, _get_secs())

        self.cell.secs = self.cell.secs[:3]
        self.assertEqual(3, len(self.cell.secs))
        self.assertEqual(3, _get_secs())

    def test_remove_synapse3(self):
        """
        Remove outside reference and inside (Cell's) reference doesn't delete section if it has
        reference inside the synapse
        """
        dend3 = self.cell.add_sec("dend3", diam=1, l=10, nseg=10)
        self.cell.connect_secs(child=dend3, parent=self.soma, child_loc=0, parent_loc=0.5)

        syn = self.cell.add_synapse(source=None, mod_name="Exp2Syn", seg=dend3(0.5))

        dend3 = None
        self.assertEqual(4, _get_secs())

        self.cell.secs = self.cell.secs[:3]
        self.assertEqual(3, len(self.cell.secs))
        self.assertEqual(4, _get_secs())

        syn.remove_immediate_from_neuron()
        self.assertEqual(3, _get_secs())

    def test_remove_soma(self):
        """
        Removal of the parent section doesn't remove child sections
        """
        self.soma.remove_immediate_from_neuron()
        self.assertEqual(2, _get_secs())

    def test_removal_sec_from_cell_object(self):
        """
        removal section by cell object - removes it from the cell object's self.secs list
        """
        self.cell.add_sec("dend3", diam=10, l=10, nseg=10)
        self.cell.remove_secs("dend3")
        self.assertEqual(3, _get_secs())
        self.assertEqual(3, len(self.cell.secs))

    def test_removal_sec_outside_cell_object(self):
        """
        removal section by itself - removes it from the cell object's self.secs list
        """
        dend3 = self.cell.add_sec("dend3", diam=10, l=10, nseg=10)
        dend3.remove_immediate_from_neuron()
        self.assertEqual(4, len(self.cell.secs))

    def test_removal_sec_outside_cell_object_clear_secs_manual(self):
        """
        removal section from secs clear also the object dend3
        """
        dend3 = self.cell.add_sec("dend3", diam=10, l=10, nseg=10)
        self.cell.secs.remove(dend3)
        self.assertEqual(3, len(self.cell.secs))

    def test_remove_dend1(self):
        """
        Removal of the parent section doesn't remove child sections
        """
        self.dend1.remove_immediate_from_neuron()
        self.assertEqual(2, _get_secs())

    def test_remove_dend1_soma(self):
        """
        Removal of the parent section doesn't remove child sections
        """
        self.soma.remove_immediate_from_neuron()
        self.dend1.remove_immediate_from_neuron()
        self.assertEqual(1, _get_secs())

    def test_remove_cell(self):
        """
        Removal of cell only doesn't remove any sections since their references are valid
        """
        self.cell.remove_immediate_from_neuron()
        self.assertEqual(3, _get_secs())

    def test_remove_sec_with_hoc_ref(self):
        """
        Immediate removal of Section doesn't remove it from NEURON if there is outside reference to
        the HOC object        that Point Process inside synapse also delete
        """
        hoc_soma = self.soma.hoc
        self.soma.remove_immediate_from_neuron()
        self.assertEqual(3, _get_secs())
        
    def test_remove_new_cell_with_no_ref(self):
        """
        deletion of cell, when all its sections have no reference outside - deletes all its
        sections as well
        """
        cell = Cell(name="cell")
        soma = cell.add_sec("soma")
        dend1 = cell.add_sec("dend1")
        dend2 = cell.add_sec("dend2")
        cell.connect_secs(child=dend1, parent=soma, child_loc=0, parent_loc=0.1)
        cell.connect_secs(child=dend2, parent=soma, child_loc=0, parent_loc=0.9)

        soma = None
        dend1 = None
        dend2 = None

        self.assertEqual(6, _get_secs())
        cell.remove_immediate_from_neuron()
        self.assertEqual(3, _get_secs())

    def test_remove_new_cell_with_del_ref(self):
        """
        deletion of cell, when all its outside references are deletes - deletes all its
        sections as well. But deletion of single soma won't delete section soma since its reference
        is still in Cell
        """
        cell = Cell(name="cell")
        soma = cell.add_sec("soma")
        dend1 = cell.add_sec("dend1")
        dend2 = cell.add_sec("dend2")
        cell.connect_secs(child=dend1, parent=soma, child_loc=0, parent_loc=0.1)
        cell.connect_secs(child=dend2, parent=soma, child_loc=0, parent_loc=0.9)

        del soma
        del dend1
        del dend2

        self.assertEqual(6, _get_secs())
        cell.remove_immediate_from_neuron()
        self.assertEqual(3, _get_secs())

    def test_remove_new_cell_with_remove_immediate(self):
        """
        remove immediate removes each section immediate only if there is no reference to the HOC
        object of this section outside the Sec object.
        """
        cell = Cell(name="cell")
        soma = cell.add_sec("soma")
        dend1 = cell.add_sec("dend1")
        dend2 = cell.add_sec("dend2")
        cell.connect_secs(child=dend1, parent=soma, child_loc=0, parent_loc=0.1)
        cell.connect_secs(child=dend2, parent=soma, child_loc=0, parent_loc=0.9)

        self.assertEqual(6, _get_secs())

        soma.remove_immediate_from_neuron()
        dend1.remove_immediate_from_neuron()
        dend2.remove_immediate_from_neuron()

        self.assertEqual(3, _get_secs())
        cell.remove_immediate_from_neuron()

    def test_removal_sec_after_synapse_remove(self):
        """
        Removing synapse allows to remove section as well
        """
        dend3 = self.cell.add_sec("dend3", diam=10, l=10, nseg=10)
        syn = self.cell.add_synapse(source=None, mod_name="Exp2Syn", seg=dend3(0.5))
        syn.remove_immediate_from_neuron()
        self.soma.remove_immediate_from_neuron()
        self.assertEqual(3, _get_secs())

    def test_removal_sec_as_part_of_synapse(self):
        """
        Removal of Sec which is a part of a Synapse won't delete the Section in NEURON as long as
        Synapse exists.
        """
        dend3 = self.cell.add_sec("dend3", diam=10, l=10, nseg=10)
        syn = self.cell.add_synapse(source=None, mod_name="Exp2Syn", seg=dend3(0.5))
        dend3.remove_immediate_from_neuron()
        self.assertEqual(4, _get_secs())

    def test_removal_sec_before_synapse_remove(self):
        """
        Removing section before removing synapse - makes that section is not removed. It is because
        we remove dend3 section, but self.cell still holds the reference to the synapse.
        """
        dend3 = self.cell.add_sec("dend3", diam=10, l=10, nseg=10)
        self.cell.add_synapse(source=None, mod_name="Exp2Syn", seg=dend3(0.5))
        dend3.remove_immediate_from_neuron()
        self.assertEqual(4, _get_secs())

    def test_removal_cell_before_synapse_remove(self):
        """
        Removing whole cell after none of its content's reference is stored out of the cell - makes
        all its content and synapses removal.
        """
        cell2 = Cell(name="cell2")
        dend3 = cell2.add_sec("dend3", diam=10, l=10, nseg=10)
        cell2.add_synapse(source=None, mod_name="Exp2Syn", seg=dend3(0.5))
        dend3 = None

        cell2.remove_immediate_from_neuron()
        self.assertEqual(3, _get_secs())
Esempio n. 7
0
class TestSection(unittest.TestCase):
    def setUp(self):
        self.cell = Cell(name="cell")

    def tearDown(self):
        self.cell.remove_immediate_from_neuron()

        l = len(list(h.allsec()))
        if len(list(h.allsec())) != 0:
            raise RuntimeError("Not all section have been removed after teardown. "
                               "Sections left: %s" % l)

    def test_default_name(self):
        """
        If the name exists it will add a number starting from 2 to the proposed name.
        """
        pat = re.compile("[1-9]")

        for i in range(10):
            self.cell.add_sec("dend")

        for i, dend in enumerate(self.cell.filter_secs(name="dend")):
            res = pat.search(dend.name)
            if i == 0:
                self.assertIsNone(res)
            else:
                self.assertEqual(i + 1, int(dend.name.replace("dend", "")))
            dend.remove_immediate_from_neuron()

    def test_regex_search(self):
        for i in range(10):
            self.cell.add_sec("dend")

        for i, dend in enumerate(self.cell.filter_secs("regex:dend[1-9]")):
            self.assertEqual(i + 2, int(dend.name.replace("dend", "")))

        for d in self.cell.secs:
            d.remove_immediate_from_neuron()

    def test_connections(self):
        soma = self.cell.add_sec(name="soma", l=10, nseg=10)
        dend = self.cell.add_sec(name="dend", l=100, nseg=10)
        self.cell.connect_secs(child=dend, parent=soma, child_loc=0, parent_loc=0.7)

        self.assertEqual(0, dend.orientation)
        self.assertEqual(0.7, dend.parent_loc)
        self.assertIsNone(soma.parent_loc)

    def test_allseg(self):
        soma = self.cell.add_sec(name="soma", diam=1, l=10, nseg=20)
        dend = self.cell.add_sec(name="dend", diam=1, l=100, nseg=200)
        self.assertEqual(22, len(soma.segs))
        self.assertEqual(202, len(dend.segs))

    def test_area1(self):
        soma = self.cell.add_sec(name="soma", diam=1, l=10, nseg=20)
        dend = self.cell.add_sec(name="dend", diam=1, l=100, nseg=200)

        self.assertEqual(0, soma.segs[0].area)
        self.assertEqual(0, soma.segs[-1].area)
        self.assertEqual(0, dend.segs[0].area)
        self.assertEqual(0, dend.segs[-1].area)

        for s in soma.segs[1:-1]:
            self.assertEqual(1.5708, round(s.area, 4))
        for s in dend.segs[1:-1]:
            self.assertEqual(1.5708, round(s.area, 4))

    def test_area2(self):
        apic = self.cell.add_sec(name="apic", diam=10, l=10, nseg=4)
        for s in apic.segs[1:-1]:
            self.assertEqual(78.5398, round(s.area, 4))
Esempio n. 8
0
from neuronpp.utils.simulation import Simulation

from neuronpp.cells.cell import Cell
from neuronpp.utils.record import Record
from neuronpp.core.cells.netstim_cell import NetStimCell

path = os.path.dirname(os.path.abspath(__file__))
model_path1 = os.path.join(path, "..", "commons/mods/ebner2019")
model_path2 = os.path.join(path, "..", "commons/morphologies/swc/my.swc")

# Prepare cell
cell = Cell(name="cell", compile_paths=model_path1)
cell.load_morpho(filepath=model_path2)
cell.add_sec("dend[1]", diam=10, l=10, nseg=10)
cell.connect_secs(source="dend[1]", target="soma")
cell.insert("pas")
cell.insert("hh")

# Two examples of synapses with NetStim:
stim_cell = NetStimCell("stim_cell")
stim = stim_cell.make_netstim(start=250, number=30, interval=1)
soma = cell.filter_secs("soma")

# 1) Hoc-style synapse
pp = cell.add_point_process(mod_name="ExpSyn", seg=soma(0.5))
cell.add_netcon(source=stim, point_process=pp, netcon_weight=0.01, delay=1)

# 2) Recommended synapse
syn1 = cell.add_synapse(source=stim,
                        seg=soma(0.5),
Esempio n. 9
0
from neuronpp.utils.simulation import Simulation

from neuronpp.cells.cell import Cell
from neuronpp.utils.record import Record
from neuronpp.core.cells.netstim_cell import NetStimCell

path = os.path.dirname(os.path.abspath(__file__))
model_path1 = os.path.join(path, "..", "commons/mods/ebner2019")
model_path2 = os.path.join(path, "..", "commons/morphologies/swc/my.swc")

# Prepare cell
cell = Cell(name="cell", compile_paths=model_path1)
cell.load_morpho(filepath=model_path2)
cell.add_sec("dend[1]", diam=10, l=10, nseg=10)
cell.connect_secs(child="dend[1]", parent="soma")
cell.insert("pas")
cell.insert("hh")

# Two examples of synapses with NetStim:
stim_cell = NetStimCell("stim_cell")
stim = stim_cell.add_netstim(start=250, number=30, interval=1)
soma = cell.filter_secs("soma")

# 1) Hoc-style synapse
pp = cell.add_point_process(mod_name="ExpSyn", seg=soma(0.5))
cell.add_netcon(source=stim, point_process=pp, netcon_weight=0.01, delay=1)

# 2) Recommended synapse
syn1 = cell.add_synapse(source=stim,
                        seg=soma(0.5),