File: test_reinit.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 (77 lines) | stat: -rw-r--r-- 2,356 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
import pytest


@pytest.fixture
def simple_model(neuron_instance):
    """A simple rxd model with species and regions and reactions."""

    h, rxd, data, save_path = neuron_instance
    dend = h.Section(name="dend")
    dend.diam = 2
    dend.nseg = 5
    dend.L = 5
    cyt = rxd.Region(dend, name="cyt", nrn_region="i")
    k = rxd.Species([cyt], name="k", d=1, charge=1, initial=140)
    paramA = rxd.Parameter([cyt], name="paramA", initial=1)
    paramB = rxd.Parameter([cyt], initial=0)
    decay = rxd.Rate(k, -0.1 * k)
    model = (dend, cyt, k, paramA, paramB, decay)
    yield (neuron_instance, model)


def test_reinit(simple_model):
    """Test rxd.re_init updates node values from NEURON values"""

    neuron_instance, model = simple_model
    h, rxd, data, save_path = neuron_instance
    dend, cyt, k, paramA, paramB, decay = model
    h.finitialize(-65)
    dend(0.5).ki = 0
    rxd.re_init()
    assert k[cyt].nodes(dend(0.5)).value[0] == 0


def test_reinit_cvode(simple_model):
    """Test rxd.re_init updates node values from NEURON values with CVode"""

    neuron_instance, model = simple_model
    h, rxd, data, save_path = neuron_instance
    dend, cyt, k, paramA, paramB, decay = model
    h.finitialize(-65)
    h.CVode().active(True)
    dend(0.5).ki = 0
    rxd.re_init()
    assert k[cyt].nodes(dend(0.5)).value[0] == 0


def test_reinit_3d(simple_model):
    """Test rxd.re_init updates node values from NEURON values in 3D"""

    neuron_instance, model = simple_model
    h, rxd, data, save_path = neuron_instance
    dend, cyt, k, paramA, paramB, decay = model
    rxd.set_solve_type(dimension=3)
    # check changing the units after initialization
    h.finitialize(-65)
    dend(0.5).ki = 0
    rxd.re_init()
    for nd in k[cyt].nodes(dend(0.5)):
        assert nd.value == 0


def test_reinit_3d_cvode(simple_model):
    """Test rxd.re_init updates node values from NEURON values in 3D with
    CVode"""

    neuron_instance, model = simple_model
    h, rxd, data, save_path = neuron_instance
    dend, cyt, k, paramA, paramB, decay = model
    rxd.set_solve_type(dimension=3)
    h.CVode().active(True)
    # check changing the units after initialization
    h.finitialize(-65)
    dend(0.5).ki = 0
    rxd.species._has_1d = False
    rxd.re_init()
    for nd in k[cyt].nodes(dend(0.5)):
        assert nd.value == 0