Example #1
0
import os
from hack import metamodel_with_any_var
from textx.model import children_of_type


mm = metamodel_with_any_var(
    os.path.join(os.path.dirname(__file__), '../../grammar/breakpoint.tx'))


def test_breakpoint():
    s = """
    BREAKPOINT {
        SOLVE states
        ina = gnabar*m*h*(v - ena)
        ik = gkbar*n*(v - ek)
        il = gl*(v - el)
        ifa = forb*(whilec - ifd)
        x = expo(v)
    }
    """
    breakpoint = mm.model_from_str(s)
    solve, ina, ik, il, ifa, x = breakpoint.b.stmts
    assert solve.solve.name == 'states'
    assert children_of_type('VarRef', ina)[0].var.name == 'ina'
Example #2
0
import os
from hack import metamodel_with_any_var
from textx.model import children_of_type

mm = metamodel_with_any_var(
    os.path.join(os.path.dirname(__file__), '../../grammar/derivative.tx'))


def test_derivative():
    nrn = """
    DERIVATIVE states {
        trates(v+vshift)
        m' =  (minf-m)/mtau
        h' =  (hinf-h)/htau
        }
    """
    deriv = mm.model_from_str(nrn)
    assert (deriv.name == 'states')
    expr, mprime, hprime = deriv.b.stmts
    fcall = children_of_type('FuncCall', expr)[0]
    assert (fcall.func.user.name == 'trates')
    assert (mprime.variable == 'm')
Example #3
0
import os
from hack import metamodel_with_any_var
from textx.model import children_of_type

mm = metamodel_with_any_var(
    os.path.join(os.path.dirname(__file__), '../../grammar/kinetic.tx'))


def test_kinetic():
    s = """
    KINETIC kin {
    rates(v)
    ~ c1 <-> c2 (kf1, kb1)
    ~ c2 <-> o (kf2, kb2)
    CONSERVE c1 + c2 + o = 1
    }
    """
    kinetic = mm.model_from_str(s)
    rates, react1, react2, conserve = kinetic.statements
    assert kinetic.name == 'kin'
    assert [op.var.name for op in conserve.reactants.op] == ['c1', 'c2', 'o']
import os
from hack import metamodel_with_any_var
from textx.model import children_of_type

mm = metamodel_with_any_var(
    os.path.join(os.path.dirname(__file__), '../../grammar/solvable_block.tx'))


def test_solvableblock():
    s = """
    {
        SOLVE states
        ina = gnabar*m*h*(v - ena)
        ik = gkbar*n*(v - ek)
        il = gl*(v - el)
    }
    """
    block = mm.model_from_str(s)
    solve, ina, ik, il = block.stmts
    assert solve.solve.name == 'states'
    assert children_of_type('VarRef', ina)[0].var.name == 'ina'