#  1.a
    #       Read a CellML file into a std.string.
    with open(model_file) as f:
        content = f.read()

    #  1.b
    #       Create a Parser item.
    parser = Parser()

    #  1.c
    #       Use the parser to deserialise the contents of the string you've read and return the model.
    model = parser.parseModel(content)

    #  1.d
    #       Print the parsed model to the terminal for viewing.
    print_model(model, False)

    #  end 1

    print('----------------------------------------------------------')
    print('   STEP 2: Resolve the imports and flatten                ')
    print('----------------------------------------------------------')

    import_path = os.path.dirname(model_file)
    #  2.a
    #      Create an Importer instance and use it to resolve the imports in your model.
    importer = Importer()
    importer.resolveImports(model, import_path)

    #  2.b
    #      Check that the importer has not raised any issues.
Example #2
0
    #  1.a
    #      Read a CellML file into a string.
    read_file = open("sodiumChannelModel_broken.cellml")

    #  1.b
    #      Create a Parser item.
    parser = Parser()

    #  1.c
    #      Use the parser to deserialise the contents of the string you've read and return the model.
    model = parser.parseModel(read_file.read())

    #  1.d
    #      Print the parsed model to the terminal for viewing.
    print_model(model, False)

    #  end 1

    print('----------------------------------------------------------')
    print('   STEP 2: Validate the parsed model                      ')
    print('----------------------------------------------------------')

    #  2.a
    #      Create a Validator item and validate the model.
    validator = Validator()
    validator.validateModel(model)

    #  end 2.a

    #      Each Validator issue contains:
    #  1.a
    #      Read the contents of the tutorial2.cellml file into a string.
    print(f"Opening the CellML file: \"{os.path.basename(model_file)}\"")
    with open(model_file) as f:
        content = f.read()

    #  1.b
    #      Create a Parser instance, and submit your string for serialisation
    #      into a new model.
    parser = Parser()
    model = parser.parseModel(content)

    #  1.c
    #      Use the print_model utility function to display the contents of the
    #      parsed model in the terminal.
    print_model(model, True)

    #  end 1

    print('----------------------------')
    print(' STEP 2: Validate the model')
    print('----------------------------')

    #  2.a
    #      Create a Validator and pass the model into it.
    validator = Validator()
    validator.validateModel(model)

    #  2.b
    #      Check the number of issues returned from the validator.
    num_validation_issues = validator.issueCount()
Example #4
0
    print("-------------------------------------------------------------")

    #  1.a
    #      Create a Model and name it.
    model = Model()
    model.setName("tutorial3_model")

    #  1.b
    #      Create a component to use as an integrator, set its attributes and
    #      add it to the model.
    component = Component()
    component.setName("component")
    model.addComponent(component)

    #  Checking that it worked
    print_model(model)

    #  1.c
    #      Create the MathML2 string representing the governing equations.
    equation1 = \
        "  <apply><eq/>"\
        "    <ci>c</ci>"\
        "    <apply><plus/>"\
        "      <ci>a</ci>"\
        "      <cn>2.0</cn>"\
        "    </apply>"\
        "  </apply>"

    #  1.d
    equation2 = \
        "  <apply><eq/>"\