File: test_ics_currents.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 (70 lines) | stat: -rw-r--r-- 1,788 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
from math import pi

import pytest

from testutils import compare_data, tol


@pytest.fixture
def ics_example(neuron_instance):
    """A model to test 3D intracellular rxd is correctly handling NMODL
    currents.
    """

    h, rxd, data, save_path = neuron_instance
    rxd.set_solve_type(dimension=3)
    # create cell1 where `x` will be created and leak out
    cell1 = h.Section(name="cell1")
    cell1.pt3dclear()
    cell1.pt3dadd(-1, 0, 0, 1)
    cell1.pt3dadd(1, 0, 0, 1)
    cell1.nseg = 11
    cell1.insert("pump")

    # Where?
    # the intracellular spaces
    cyt = rxd.Region(h.allsec(), name="cyt", nrn_region="i", dx=1.0)

    model = (cell1, cyt)
    yield (neuron_instance, model)


def test_ics_currents(ics_example):
    """Test ics_example with fixed step methods"""

    (h, rxd, data, save_path), (cell1, cyt) = ics_example
    x = rxd.Species([cyt], name="x", d=1.0, charge=1, initial=0)
    h.finitialize(-65)
    h.continuerun(100)

    if not save_path:
        max_err = compare_data(data)
        assert max_err < tol


def test_ics_currents_cvode(ics_example):
    """Test ics_example with variable step methods"""

    (h, rxd, data, save_path), (cell1, cyt) = ics_example
    x = rxd.Species([cyt], name="x", d=1.0, charge=1, initial=0)
    h.CVode().active(True)

    h.finitialize(-65)
    h.continuerun(100)

    if not save_path:
        max_err = compare_data(data)
        assert max_err < tol


def test_ics_currents_initial(ics_example):
    """Test ics_example with initial values from NEURON"""

    (h, rxd, data, save_path), (cell1, cyt) = ics_example
    x = rxd.Species([cyt], name="x", d=1.0, charge=1)
    h.finitialize(-65)
    h.continuerun(100)

    if not save_path:
        max_err = compare_data(data)
        assert max_err < tol