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
|