First time here? Checkout the FAQ!
x
0 votes
by (300 points)
Hello, could someone assist me with converting Fenton-Karma model from CellML to EasyML.

CellML repo: https://models.cellml.org/e/5bc/fenton_karma_1998_BR.cellml/view

I tried to run with command:
/usr/local/lib/opencarp/share/openCARP/physics/limpet/src/python/cellml_converter.py --Vm=u --Istim=J_stim fenton_karma_1998_BR.cellml > fenton_karma_1998_BR.model

Fenton-Karma has u as transmembrane voltage, but later it also has this scaling of u to Vm (Vm=V_0+u(V_fi−V_0)) so I get lost with units and other variables later when translating to C. I would appreciate some support with that.

Thank you,

Jakub

2 Answers

0 votes
by (610 points)
selected ago by
 
Best answer

Hi Jakub,

I managed to compile a file that contains the FK-model for openCARP. While debugging, I checked the simple model files in the openCARP gitlab repository as reference. You can find the content of my .model file below.

This is what I changed to the original .model file after conversion with cellml_converter.py (with --Vm u):

  1. I removed the variables including I_stim;
  2. I set Vm as the state variable and defined a conversion from Vm to u instead of the other way around. This turned out the issue you report in your question. See yellow highlight below.
  3. I removed the lines with cvode;
  4. I made a distinction between constants and parameters;
  5. I renamed p and q to heaviside_u_c and heaviside_u_v, as p is used in the C code for the struct that stores the parameters.
  6. I added a reference header - just to make it look nicely.
I hope these fixes work for you as well.
Have a nice day,
Marie

group {
  #Authors ::= Fenton, F., Karma, A.
  #Year ::= 1998
  #Title ::= Vortex dynamics in three-dimensional continuous myocardium with fiber rotation: Filament instability and fibrillation
  #Journal ::= Chaos 8(1), 20-47
  #DOI ::= 10.1063/1.166311
} .reference();

#generated from: fenton_karma_1998_BR.cellml
Vm; .external(Vm); .nodal();
Iion; .external(); .nodal();

# Constants
Cm = 1; .units(uF/cm^2);
V_0 = -85; .units(mV);
V_fi = 15; .units(mV);

# model parameters
u_c = 0.13; .param(); .units(unitless);
u_v = 0.04; .param(); .units(unitless);
g_fi_max = 4; .param(); .units(mS/cm^2);
tau_v1_minus = 1250; .param(); .units(ms);
tau_v2_minus = 19.6; .param(); .units(ms);
tau_v_plus = 3.33; .param(); .units(ms);
tau_0 = 12.5; .param(); .units(ms);
tau_r = 33.33; .param(); .units(ms);
tau_si = 29; .param(); .units(ms);
u_csi = 0.85; .param(); .units(unitless);
k = 10; .param(); .units(unitless);
tau_w_minus = 41; .param(); .units(ms);
tau_w_plus = 870; .param(); .units(ms);

# Initial values
u_init = 0; .units(unitless);
v_init = 1; .units(unitless);
w_init = 1; .units(unitless);

#membrane
Vamp = V_fi - V_0;
u = (Vm - V_0) / Vamp; .units(unitless);
Iion = -(-(J_fi+J_so+J_si)); .units(uA/uF);

# heaviside_u_c
heaviside_u_c = ((u<u_c) ? 0. : 1.); .units(unitless);

# heaviside_u_v
heaviside_u_v = ((u<u_v) ? 0. : 1.); .units(unitless);

#fast_inward_current
tau_d = (Cm/g_fi_max); .units(ms);
J_fi = ((-v*heaviside_u_c*(1. - u)*(u - u_c))/tau_d); .units(unitless/ms);

#fast_inward_current_v_gate
tau_v_minus = ((heaviside_u_v*tau_v1_minus)+((1. - heaviside_u_v)*tau_v2_minus)); .units(ms);
diff_v = ((((1. - heaviside_u_c)*(1. - v))/tau_v_minus) - ((heaviside_u_c*v)/tau_v_plus)); .units(unitless/ms);

#slow_outward_current
J_so = (((u*(1. - heaviside_u_c))/tau_0)+(heaviside_u_c/tau_r)); .units(unitless/ms);

#slow_inward_current
J_si = ((-w*(1.+tanh((k*(u - u_csi)))))/(2.*tau_si)); .units(unitless/ms);

#slow_inward_current_w_gate
diff_w = ((((1. - heaviside_u_c)*(1. - w))/tau_w_minus) - ((heaviside_u_c*w)/tau_w_plus)); .units(unitless/ms);

 

ago by (300 points)
Thank you Marie, that works
0 votes
by (610 points)

Hi Jakub,

I am attempting exactly the same thing at the moment and also get stuck at the C-conversion. Do you also get the following AssertionError?

~/openCARP/physics/limpet/src/python/limpet_fe.py fenton_karma_1998_BR.model ~/openCARP/physics/limpet/models/imp_list.txt ~/openCARP/physics/limpet/src/imps_src/

WARNING: Model fenton_karma_1998_BR: MLIR code generation does not support CVODE integration method. Using original codegen...
Traceback (most recent call last):
  File "~/openCARP/physics/limpet/src/python/limpet_fe.py", line 2953, in <module>
    obj.printSource(out_dir)
  File "~/openCARP/physics/limpet/src/python/limpet_fe.py", line 1393, in printSource
    self.changeExternalUnits(1, out, complete_format)
  File "~/openCARP/physics/limpet/src/python/limpet_fe.py", line 353, in changeExternalUnits
    factor*log_diff(desired_unit,current_unit)))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/openCARP/physics/limpet/src/python/unit.py", line 111, in log_diff
    assert a.is_like(b)
AssertionError

It seems like the problematic part of the .model file is

u; .external(Vm); .nodal()

and more specifically the fact that u and Vm have different units, despite the conversion

Vm = (V_0+(u*(V_fi - V_0))); .units(mV)

later in the .model file.

I'll have a look at it and let you know if I find something helpful.

Kind regards,

Marie

Welcome to openCARP Q&A. Ask questions and receive answers from other members of the community. For best support, please use appropriate TAGS!
architecture, carputils, documentation, experiments, installation-containers-packages, limpet, slimfem, website, governance
...