Nektar++
Loading...
Searching...
No Matches
convert.py
Go to the documentation of this file.
1# Python environment with the myokit installed is required.
2# To compile the resulting C++ code, need libsundials-dev package.
3
4# A conda environment with the correct dependencies can be create to
5# run the converter using the `environment.yml` file:
6# conda env create -f environment.yml
7import os
8import argparse
9import myokit
10import myokit.formats.cellml as cellml
11import myokit.lib.guess as guess
12import myokit.lib.hh as hh
13import nektar
14
15# Parse command-line arguments
16parser = argparse.ArgumentParser(description='Optional app description')
17parser.add_argument('-n','--name',
18 help='Override the CellML model name used as class name.')
19parser.add_argument('-o','--outputpath', default='.',
20 help='Specify the output directory for the generated model.')
21parser.add_argument('filename',
22 help='CellML model to convert')
23args = parser.parse_args()
24
25# Create importer for CellML file
26importer = cellml.CellMLImporter()
27
28# Create exporter to Nektar
30
31# The model is first imported into Myokit
32#model = importer.model('courtemanche_ramirez_nattel_1998.cellml')
33model = importer.model(args.filename)
34
35# Get model name
36model_name = args.name if args.name is not None else model.name();
37
38# At this point, it can be manipulated as a Myokit model before
39# exporting (see Myokit docs)
40# Note that it may be necessary to remove any embedded protocol
41# at either this step or before loading the CellML model
42_ = guess.remove_embedded_protocol(model)
43
44# The exporter takes 4 arguments:
45# Name of the directory in which to save the source and header
46# The Myokit model to export
47# A Myokit protocol which for the Nektar exporter will be ignored
48# A name for the generated model class (not required)
49# A dictionary of variants (not required, see example)
50# A dictionary of initial states (not required, see example)
51
52# The below code will export the model without any variant information
53exporter.runnable(args.outputpath, model, None, args.name)
54os.rename(args.outputpath + "/model.cpp",
55 args.outputpath + "/" + model_name + ".cpp")
56os.rename(args.outputpath + "/model.h",
57 args.outputpath + "/" + model_name + ".h")