Nektar++
Loading...
Searching...
No Matches
example_script.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
7
8import myokit
9import myokit.formats.cellml as cellml
10import myokit.lib.guess as guess
11import myokit.lib.hh as hh
12import nektar
13
14# Create importer for CellML file
15importer = cellml.CellMLImporter()
16
17# Create exporter to Nektar
19
20# The model is first imported into Myokit
21model = importer.model('courtemanche_ramirez_nattel_1998.cellml')
22
23# At this point, it can be manipulated as a Myokit model before
24# exporting (see Myokit docs)
25# Note that it may be necessary to remove any embedded protocol
26# at either this step or before loading the CellML model
27_ = guess.remove_embedded_protocol(model)
28
29# The exporter takes 4 arguments:
30# Name of the directory in which to save the source and header
31# The Myokit model to export
32# A Myokit protocol which for the Nektar exporter will be ignored
33# A dictionary of variants (not required, see example)
34# A dictionary of initial states (not required, see example)
35
36# The below code will export the model without any variant information
37exporter.runnable('example', model, None)
38
39# If instead we want to include two variants of the courtemanche model
40# we can include that information for it to be included in the model
41variants = {'Original': {'transient_outward_K_current.g_to': 0.1652,
42 'L_type_Ca_channel.g_Ca_L': 0.12375},
43 'AF': {'transient_outward_K_current.g_to':0.0826,
44 'L_type_Ca_channel.g_Ca_L': 0.037125}}
45exporter.runnable('example_variants', model, None, variants)
46
47# Including different initial conditions by running to steady state in Myokit
48initial_states = {}
49for variant_name, parameter_dict in variants.items():
50 # Set parameters in variant
51 for p_name, p_val in parameter_dict.items():
52 model.set_value(p_name, p_val)
53 # Create simulation and run to steady-state
54 sim = myokit.Simulation(model)
55 sim.pre(100e3)
56 # Set state to end-state and store Equations
57 model.set_initial_values(sim.state())
58 initial_states[variant_name] = list(model.inits())
59exporter.runnable('example_initial_states', model, None, variants, initial_states)