File: test_empty_regions.py

package info (click to toggle)
neuron 8.2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,760 kB
  • sloc: cpp: 149,571; python: 58,465; ansic: 50,329; sh: 3,510; xml: 213; pascal: 51; makefile: 35; sed: 5
file content (101 lines) | stat: -rw-r--r-- 2,986 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import pytest
from testutils import compare_data, tol


@pytest.fixture
def empty_regions_model(neuron_instance):
    """A model with an empty region"""

    h, rxd, data, save_path = neuron_instance
    sec = h.Section()
    sec.L = 100
    sec.diam = 1
    sec.nseg = 100
    cells = []
    cyt = rxd.Region(cells, name="cyt", nrn_region="i")
    mem = rxd.Region(cells, name="mem", geometry=rxd.membrane)
    ecs = rxd.Extracellular(-5, -5, -5, 5, 5, 5, dx=5)
    k = rxd.Species(
        [ecs, cyt],
        name="k",
        d=0,
        charge=1,
        initial=lambda nd: 140 if hasattr(nd, "x") else 3,
    )

    model = (sec, cyt, mem, ecs, k)
    yield (neuron_instance, model)


def test_empty_region_no_rate(empty_regions_model):
    """Test a rate that should do nothing with an empty region"""

    neuron_instance, model = empty_regions_model
    h, rxd, data, save_path = neuron_instance
    sec, cyt, mem, ecs, k = model
    kcyt = k[cyt]
    react = rxd.Rate(kcyt, -10 * kcyt)
    h.finitialize(-70)
    h.continuerun(10)
    if not save_path:
        max_err = compare_data(data)
        assert max_err < tol


def test_empty_region_ecs_rate(empty_regions_model):
    """Test a rate that should change the ECS with an empty region"""

    neuron_instance, model = empty_regions_model
    h, rxd, data, save_path = neuron_instance
    sec, cyt, mem, ecs, k = model
    react = rxd.Rate(k, -10 * k)
    h.finitialize(-70)
    h.continuerun(10)
    if not save_path:
        max_err = compare_data(data)
        assert max_err < tol


def test_empty_region_no_reaction(empty_regions_model):
    """Test a reaction that should change the ECS with an empty region"""

    neuron_instance, model = empty_regions_model
    h, rxd, data, save_path = neuron_instance
    sec, cyt, mem, ecs, k = model
    react = rxd.Reaction(2 * k, k, 10, regions=[cyt])
    h.finitialize(-70)
    h.continuerun(10)
    if not save_path:
        max_err = compare_data(data)
        assert max_err < tol


def test_empty_region_ecs_reaction(empty_regions_model):
    """Test a reaction that should change the ECS with an empty region"""

    neuron_instance, model = empty_regions_model
    h, rxd, data, save_path = neuron_instance
    sec, cyt, mem, ecs, k = model
    react = rxd.Reaction(2 * k, k, 10)
    h.finitialize(-70)
    h.continuerun(10)
    if not save_path:
        max_err = compare_data(data)
        assert max_err < tol


def test_empty_region_multicompartment_reaction(empty_regions_model):
    """Test a reaction that should change the ECS with an empty region"""

    neuron_instance, model = empty_regions_model
    h, rxd, data, save_path = neuron_instance
    sec, cyt, mem, ecs, k = model
    kcyt, kecs = k[cyt], k[ecs]
    react = rxd.MultiCompartmentReaction(
        kcyt, kecs, 1e5, 0, membrane=mem, membrane_flux=False
    )
    h.finitialize(-70)
    h.continuerun(10)
    if not save_path:
        max_err = compare_data(data)
        assert max_err < tol