Ejemplo n.º 1
0
    def test_variable(self):
        from libcellml import Component, Variable

        # VariablePtr variable(size_t index)
        c = Component()
        v = Variable()
        name = 'green'
        v.setName(name)
        self.assertIsNone(c.variable(0))
        self.assertIsNone(c.variable(1))
        self.assertIsNone(c.variable(-1))
        c.addVariable(v)
        self.assertIsNone(c.variable(1))
        self.assertIsNone(c.variable(-1))
        self.assertIsNotNone(c.variable(0))
        self.assertEqual(c.variable(0).name(), name)
        del [c, v, name]

        # VariablePtr variable(const std::string &name)
        c = Component()
        v = Variable()
        name = 'green'
        v.setName(name)
        self.assertIsNone(c.variable(name))
        c.addVariable(v)
        self.assertIsNone(c.variable('red'))
        self.assertIsNotNone(c.variable(name))
        self.assertEqual(c.variable(name).name(), name)
    ms = Units('ms')
    ms.addUnit('second', 'milli')

    mM = Units('mM')
    mM.addUnit('mole', 'milli')

    model.addUnits(ms)
    model.addUnits(mV)
    model.addUnits(mM)
    model.addUnits(microA_per_cm2)
    model.addUnits(mS_per_cm2)

    #  2.g 
    #      Set the units on each of the variables.  
    #      Call the validator again, and expect there to be no errors.
    k_channel_equations.variable('E_K').setUnits(mV)
    k_channel_equations.variable('i_K').setUnits(microA_per_cm2)
    k_channel_equations.variable('g_K').setUnits(mS_per_cm2)
    k_channel_equations.variable('V').setUnits(mV)
    k_channel_equations.variable('t').setUnits(ms)
    k_channel_equations.variable('n').setUnits('dimensionless')

    validator.validateModel(model)
    print_issues(validator)

    #  end 2

    print('------------------------------------------------------------')
    print('   STEP 3: Create the n_gate and n_gate_equations components   ')
    print('------------------------------------------------------------')
Ejemplo n.º 3
0
        t.setName("t")
        t.setUnits("ms")
        environment.addVariable(t)

    #  4.c Add the new component to the model and validate
    model.addComponent(environment)

    validator.validateModel(model)
    print_errors_to_terminal(validator)

    print("-----------------------------------------------")
    print("  STEP 5: Connecting variables and components")
    print("-----------------------------------------------")

    #  5.a Connecting the equivalent variables between all the components
    Variable.addEquivalence(environment.variable("t"), sodium_channel.variable("t"))
    Variable.addEquivalence(sodium_channel.variable("t"), mGate.variable("t"))
    Variable.addEquivalence(sodium_channel.variable("t"), hGate.variable("t"))
    environment.variable("t").setInterfaceType("public")
    sodium_channel.variable("t").setInterfaceType("public_and_private")
    mGate.variable("t").setInterfaceType("public")
    hGate.variable("t").setInterfaceType("public")

    Variable.addEquivalence(environment.variable("V"), sodium_channel.variable("V"))
    Variable.addEquivalence(sodium_channel.variable("V"), mGate.variable("V"))
    Variable.addEquivalence(sodium_channel.variable("V"), hGate.variable("V"))
    environment.variable("V").setInterfaceType("public")
    sodium_channel.variable("V").setInterfaceType("public_and_private")
    mGate.variable("V").setInterfaceType("public")
    hGate.variable("V").setInterfaceType("public")
    per_ms = Units('per_ms')

    #  5.b
    #      Add Unit items to the units you created to define them.
    ms.addUnit('second', 'milli')
    per_ms.addUnit('second', 'milli', -1)

    #  5.c
    #      Add the Units to the model (not the component) so that other components can make
    #      use of them too.
    model.addUnits(ms)
    model.addUnits(per_ms)

    #  5.d
    #      Use the setUnits function to associate them with the appropriate variables.
    gateEquations.variable('t').setUnits(ms)
    gateEquations.variable('alpha_X').setUnits(per_ms)
    gateEquations.variable('beta_X').setUnits(per_ms)
    gateEquations.variable('X').setUnits('dimensionless')

    #  5.e
    #      Validate again, and expect no errors.
    validator.validateModel(model)
    print_issues(validator)

    #  end 5

    print('----------------------------------------------------------')
    print('   STEP 6: Analyse the model  ')
    print('----------------------------------------------------------')
        t.setUnits("ms")
        environment.addVariable(t)

    #  5.c Add the new component to the model and validate
    validator.validateModel(model)
    print_errors_to_terminal(validator)

    print("\n-----------------------------------------------")
    print("   STEP 6: Connect the equivalent variables")
    print("-----------------------------------------------")

    #  6.a Connecting the membrane to its sibling environment, and the channels to their
    #      parent membrane component.
    Variable.addEquivalence(membrane.variable("t"), sodium_channel.variable("t"))
    Variable.addEquivalence(membrane.variable("t"), potassium_channel.variable("t"))
    Variable.addEquivalence(environment.variable("t"), membrane.variable("t"))
    Variable.addEquivalence(membrane.variable("V"), sodium_channel.variable("V"))
    Variable.addEquivalence(membrane.variable("V"), potassium_channel.variable("V"))
    Variable.addEquivalence(membrane.variable("V"), leakage_current.variable("V"))
    Variable.addEquivalence(environment.variable("V"), membrane.variable("V"))

    #  6.b Setting the interface types for those which haven't been inherited already
    environment.variable("t").setInterfaceType("public")
    membrane.variable("t").setInterfaceType("public_and_private")
    environment.variable("V").setInterfaceType("public")
    membrane.variable("V").setInterfaceType("public_and_private")

    validator.validateModel(model)
    print_errors_to_terminal(validator)

    print("\n-----------------------------------------------")