NMODL Compile Error: Assertion failed!

NMODL and the Channel Builder.
Post Reply
Darshan
Posts: 40
Joined: Tue Jul 02, 2013 5:11 am

NMODL Compile Error: Assertion failed!

Post by Darshan »

Hi,

I was trying to translate this code given here:
https://www.math.fsu.edu/~bertram/softw ... JTB_04.ode
for pancreatic beta-cells, published by Wierschem and Bertram, J. Theor. Biol., 228:513-521, 2004. Here is the nmodl code I made:

Code: Select all

TITLE weirshem and Bertram 2004

UNITS {
	(molar) = (1/liter)
	(mM)	= (millimolar)
	(S)  	= (siemens)
	(mA) 	= (milliamp)
	(mV) 	= (millivolt)
	(um) 	= (micron)
	: (ms)    = (millisecond) already known unit
}

NEURON {
	SUFFIX camech
	USEION k READ ek WRITE ik
	USEION ca READ eca WRITE ica, cai VALENCE 2
	: USEION atp READ atpi VALENCE 1
	: USEION adp READ adpi VALENCE 1
	USEION atp READ atpi WRITE atpi VALENCE 1
	USEION adp READ adpi WRITE adpi VALENCE 1
	RANGE  gca, ica
	RANGE  gk, gkca, gatp, ik, ikchan, ikca, ikatp
	RANGE nu, eta, tauc, f
}

PARAMETER {
	f = 0.0013  (1)					: unitless
	alpha = 2.25e3  (mM/mA-ms) 		:2.25e-6 uM/fA-ms
									:2.25e-6 (uM/fA-ms) = 2.25e-6*1e9 (mM/mA-ms)
	kc = 0.1 	(1)					: unitless
	
	vca=25 (mV)				: mV also declared in hoc
	: eca=25 (mV)	eca changes with cai. hence, fixed.	: mV also declared in hoc
	ek=-75	(mV)		    : mV also declared in hoc

	
	: Channel Parameters
	sm=12 (mV)				:mV
	sn=5.6 	(mV)			:mV
	vm=-20 	(mV)			:mV
	vn=-16 	(mV)			:mV
	kd=0.3e-3 (mM)			:0.3 uM
	taun=16 (ms)			:ms
	
	: initialized in hoc
	: gca=(1200e-4)/area 	: pS. pS/area to 1e-4 S/cm2 -> 1e-4 :units
	: gk= (3000e-4)/area 	: pS. pS/area to 1e-4 S/cm2 -> 1e-4 :units
	: gatp=(357e-4)/area 	: pS. pS/area --> 1e-4 S/cm2
	: gkca=(300e-4)/area 	: pS
	
	: # substrate (ATP) influx rate
	nu=10 (1): 10. See Fig 2 text: nu and eta are dimensionless parameter
	
	: # product (ADP) removal rate
	eta=188 (1): 188. See Fig 2 text: nu and eta are dimensionless parameter
	
	: # ratio k_2/k_(-2)
	k=20 (1):(Unit Assumed) 20. 
	: # time scale parameter (in sec)
	tauc=1200e3 (ms): 1200 sec 
}

STATE{
	n (1)
	cai(mM)
	atpi(mM)
	adpi(mM)
}

ASSIGNED {
	: atpi (mM)		: uM also declared in hoc
	: adpi (mM)		: uM also declared in hoc

	v   		(mV)
	ik			(mA/cm2)
	ikchan 		(mA/cm2)
	ikca 		(mA/cm2)
	ikatp 		(mA/cm2)
	ica			(mA/cm2)
	
	minf (1)
	ninf (1)
	omega (1)
	
	gca (S/cm2)
	gk (S/cm2)
	gatp (S/cm2)
	gkatp (S/cm2-mM)
	gkca (S/cm2)
	
	area (um2)
}

BREAKPOINT {
	minf =1/(1+exp((vm-v)/sm))
	ninf =1/(1+exp((vn-v)/sn))
	SOLVE states METHOD derivimplicit :cnexp 
	:Used derivimplicit as mentioned here https://www.neuron.yale.edu/phpBB/viewtopic.php?f=28&t=592
	
	omega = 1/(1+(kd/cai))
	gkatp = gatp/atpi : CHECK 

	: # Ionic currents
	ica = gca*minf*(v-vca) : (v-eca)
	ikchan  = gk*n*(v-ek)
	ikca = gkca*omega*(v-ek)
	ikatp = gkatp*(v-ek)
	ik = ikchan+ikca+ikatp
}

INITIAL {
	minf =1/(1+exp((vm-v)/sm))
	ninf =1/(1+exp((vn-v)/sn))
	omega = 1/(1+(kd/cai))
	
	: atpi = 2.4e-3 (mM)		: uM also declared in hoc
	: adpi = 0.05e-3 (mM)		: uM also declared in hoc
	cai = 0.17e-3 (mM)		: uM also declared in hoc
}

DERIVATIVE states {
	n'=(ninf-n)/taun
	cai' = -f*(alpha*ica + kc*cai)
	
	:fun(ADP,ATP)=ATP*(1+k*ADP)^2. Used within the expression
	atpi' = (nu - atpi*(1+k*adpi)^2)/tauc
	adpi' = (atpi*(1+k*adpi)^2 - eta*adpi)/tauc
}

While compiling I get the following error:

Code: Select all

warning: return type defaults to 'int' [-Wimplicit-int]
modl_reg()[
nocmodl camech
Translating camech.mod into camech.c
Assertion failed.

Code: Select all

***[/cygdrive/c/nrn/lib/mknrndll.mak.23: camech.c] Error 3
I am using NEURON version 7.6.2 on Windows 7.

Questions:
1. On commenting the last 2 lines in DERIVATIVE (adpi' and atpi' expressions) and STATE block adpi and atpi terms along with changes in their respective USEION statements, I was able to compile the code. But not with those expressions present. What would be the error in code?

2. [Not related to error] Since, the XPP code in the link has units for terms in pS, fA etc., and not in per unit area as used for Distributed mechanisms, what is the best approach to covert such code to NEURON nmodl or rxd and to make it work? I am using 'area' in mod file and area(0.5) in hoc for area conversions.

3. [a silly question] I am not able to copy mknrndll output from command prompt (cmd.exe) to clipboard. Same is true for neuron.exe interpreter text. For Linux based systems this is not an issue. Any solutions/workarounds recommended for this?

Thanks,
Darshan
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: NMODL Compile Error: Assertion failed!

Post by ted »

On commenting the last 2 lines in DERIVATIVE (adpi' and atpi' expressions) and STATE block adpi and atpi terms along with changes in their respective USEION statements, I was able to compile the code. But not with those expressions present.
Try expanding the expressions so instead of
(const + var)^2
they read like this
const + k*var + var^2
Did that help?
Since, the XPP code in the link has units for terms in pS, fA etc., and not in per unit area
Where density units are required, assume specific membrane capacitance is 1 uf/cm2 and use that to figure out what the surface area of the original model was. Then figure out the channel and current densities by dividing the absolute conductances and currents by the surface area. Use scale factors as needed to ensure that all parameter and variable units are in NEURON's preferred units (mA/cm2, S/cm2).
I am not able to copy mknrndll output from command prompt (cmd.exe) to clipboard. Same is true for neuron.exe interpreter text.
If you're running mknrndll from a dos box, use the old awkward dos-style select and copy method. If you're running it from NEURON's own "rxvt" or "terminal" program, I'd expect Linux-style "select with left mouse button down, paste with middle mouse button" should work.
Darshan
Posts: 40
Joined: Tue Jul 02, 2013 5:11 am

Re: NMODL Compile Error: Assertion failed!

Post by Darshan »

Thank you Ted for your prompt reply!

1. I expanded the terms for adpi' and atpi' expressions:

Code: Select all

atpi' = ((nu - atpi* (1+(k2^2)*(adpi^2)+2*k2*adpi))/tauc)
adpi' = ((atpi*(1+(k2^2)*(adpi^2)+2*k2*adpi) - eta*adpi)/tauc)
and also changed the "k" which I declared as constant earlier to "k2". Forgot that "k" represents the potassium ion. But I am still getting the same error. I also tried changing the SOLVE METHOD from cnexp to derivimplicit

2. Thanks for pointing out the surface area. I will use it to find corresponding unit area parameter values in the model.

3. I am using NEURON terminal. I found out another way. On right clicking in the terminal or on the title bar of the terminal, it gives an option to "mark" (With title bar right click, go to edit->mark), select the text by scrolling then right click again on title and select edit->copy. The usual Ctrl+C in the terminal after "mark"-ing does not work most of time on my system.

Best Wishes,
Darshan
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: NMODL Compile Error: Assertion failed!

Post by ted »

With regard to copying text--you're right, regardless of whether one starts NEURON by double clicking on a hoc file, double clicking on the nrngui shortcut icon, or by starting the bash terminal, it is necessary to right click the window's drag bar, then select (drag cursor to highlight) the text to be copied. At that point, as you note, ^C does not copy the text to the clipboard. However, simply pressing the Return key will do it.

With regard to the equations in your mod file, with your original formulation I get a somewhat different message:

Code: Select all

nocmodl: diffeq.y:218: difeq_yyerror: Assertion `0' failed.
make: *** [foo.lo] Aborted (core dumped)
Let's see if anyone else has a suggestion that might be useful.
Darshan
Posts: 40
Joined: Tue Jul 02, 2013 5:11 am

Re: NMODL Compile Error: Assertion failed!

Post by Darshan »

Thanks. This shortcut for copying text works perfectly fine. I guess the key assigned for copy was changed to 'return' in newer NEURON versions.

I will also post here if I find a solution/workaround to the compilation error.

Best Wishes,
Darshan
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: NMODL Compile Error: Assertion failed!

Post by hines »

I'm afraid that the parser that analyzes the right hand side of ode's for derivimplicit does not allow the power operation. You can write the relevant
ode's as

Code: Select all

        atpi' = (nu - atpi*(1+k*adpi)*(1+k*adpi))/tauc
        adpi' = (atpi*(1+k*adpi)*(1+k*adpi) - eta*adpi)/tauc
The syntax of an expression e for derivimplicit must recursively satisfy the rules (the normal associativity and precedence applies)
e: name
e: name(args)
e: (e)
e: -e
e: e+e
e: e-e
e: e*e
e: e/e
Unfortunately I never implemented
e: e^e

If repeated evalueatio bothers you, you can use a function or a LOCAL. eg
fn = (1 + k*adpi)*(1 + k*adpi)
and use that in the two odes. (Please verify you get the same results to make sure I'm not mistaken)

By the way I would move

Code: Select all

        minf =1/(1+exp((vm-v)/sm))
        ninf =1/(1+exp((vn-v)/sn))
from the beginning of the BREAKPOINT to the beginning of the DERIVATIVE states block.
Also uncomment the eca declaration and move it into the ASSIGNED block.
Darshan
Posts: 40
Joined: Tue Jul 02, 2013 5:11 am

Re: NMODL Compile Error: Assertion failed!

Post by Darshan »

Thank you Michael. Using the recursive multiplication approach works for these expressions when using derivimplicit.

I also tried using function and LOCAL. It gave me the same results both of them (though not desirable). I have to fix the parameter values. I will use functions for greater power values (>2) in expressions.
By the way I would move

Code: Select all

minf =1/(1+exp((vm-v)/sm))
ninf =1/(1+exp((vn-v)/sn))
from the beginning of the BREAKPOINT to the beginning of the DERIVATIVE states block.
Thanks for pointing that out. Is it advisable to write the expression which are not differential equations in the DERIVATIVE instead of BREAKPOINT?
I should also make them into a FUNCTION/PROCEDURE as they are also being called in the INITIAL block.
Also uncomment the eca declaration and move it into the ASSIGNED block.
That was the other error which came up after solving the above. In the original XPP implementation of the code, it is a fixed value so I commented it and used a fixed value 'vca' but forgot remove it from USEION statement.
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: NMODL Compile Error: Assertion failed!

Post by hines »

Is it advisable to write the expression which are not differential equations in the DERIVATIVE instead of BREAKPOINT?
For models that compute current, the only assignment statements that should be in the BREAKPOINT block are statements that aid in computing
the current under the assumption that the states are correct at the time the block is called. Generally when the current is calculated, all these
statements are executed twice so that the stabilizing jacobian elements (conductance) can be numerically computed. With variable time step
methods, the current might be computed a half dozen times during a time step (with the values of t not even being montonic and work on a
step being thrown away for a retry with a smaller time step to satisfy the error tolerance). The recent addition of the CONDUCTANCE keyword
allows the breakpoint body to be executed only once when currents are computed.

It was partly a mistake on my part to have the SOLVE statement in the BREAKPOINT (synonym available is CURRENT) block. It is a legacy from
the SCoP simulator for which MODL was developed. The ancient https://www.neuron.yale.edu/neuron/stat ... nmodl.html has the fragment
BREAKPOINT
Description:
This is the main computation block of the model. Any states are integrated by a SOLVE statement. Currents are set with assignment statements at the end of this block. Think of this block as making sure that on exit, all variables are consistent at time, t. The reason this block is named BREAKPOINT is because in SCoP it was called for each value of the INDEPENDENT variable at which the user desired to plot something. It was responsible for making all variables consistent at that value of the INDEPENDENT variable (which usually required integrating states from their values at the previous call using SOLVE statements). In NMODL, this block is usually called twice every time step (with voltage equal to v+.001 and voltage equal to v) in order to calculate the conductance from the currents. Often, errors result if one computes values for states in this block. All states depending explicitly or implicitly on time should only be changed in a block called by a SOLVE statement.
Darshan
Posts: 40
Joined: Tue Jul 02, 2013 5:11 am

Re: NMODL Compile Error: Assertion failed!

Post by Darshan »

Thanks again for the elaborate explanation.

So, if those statements (minf, ninf) are in BREAKPOINT, are they undergoing unnecessary recalculations? I guess by moving them to the DERIVATIVE block will save some simulation time which might be more evident in long or large-scale simulations,

Also, I could not find the documentation for CONDUCTANCE keyword. Has it been added to the latest NEURON release?

Best Wishes,
Darshan
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: NMODL Compile Error: Assertion failed!

Post by hines »

if those statements (minf, ninf) are in BREAKPOINT, are they undergoing unnecessary recalculations?
Yes. And for the fixed step method with secondorder=2, BREAKPOINT and DERIVATIVE blocks are called at different values of t so that voltages
are different.

CONDUCTANCE is suitable for ohmic currents. ie. not suitable for ghk equations.
An example of the use of CONDUCTANCE for an hh.mod model is

Code: Select all

BREAKPOINT {
        CONDUCTANCE gna USEION na
        CONDUCTANCE gk USEION k
        CONDUCTANCE gl
        SOLVE states METHOD cnexp
        gna = gnabar*m*m*m*h
        ina = gna*(v - ena)
        gk = gkbar*n*n*n*n
        ik = gk*(v - ek)
        il = gl*(v - el)
}
I apologize that this remains so far undocumented.
Darshan
Posts: 40
Joined: Tue Jul 02, 2013 5:11 am

Re: NMODL Compile Error: Assertion failed!

Post by Darshan »

Thanks for the prompt reply and example of CONDUCTANCE keyword.
Post Reply