FUNCTION in NMODL (vtrap/SafeExp)

NMODL and the Channel Builder.
Post Reply
NatalieD

FUNCTION in NMODL (vtrap/SafeExp)

Post by NatalieD »

Hi,
I'm trying to modify a sodium channel mod file, and i keep getting error messages for the units. I was hoping that you could help me understand the following function. In the hh.mod file it is called vtrap, and it is similar, but in this specific mod file it is called SafeExp:

Code: Select all

FUNCTION SafeExp(x, y, Vm) {
   if(fabs(Vm) > 1e-6) {
        SafeExp = (x * Vm)/(exp(Vm/y) - 1)
   } else {
        SafeExp = x/((Vm/y/2) - 1)
   }
}

PROCEDURE settables(v (mV)) {
    TABLE malpha, mbeta, halpha, hbeta, minf, mtau, hinf, htau
	FROM -100 TO 100 WITH 200

    malpha = SafeExp(0.1,10,-(v+35))
    mbeta = 4*exp(-(v+60)/18)
The error message refers to the malpha line:

Code: Select all

units:  0.001 m2-kg/sec2-coul
The units of the previous two expressions are not conformable
 at line 74 in file ./SlowNa.mod
    malpha = SafeExp(0.1,10,-(v+35+MSHFT<<ERROR>>))
Thank you,
Natalie
ted
Site Admin
Posts: 6300
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

When does it make sense to disable units checking?

Post by ted »

Units checking is most useful for blocks with expressions that combine variables that
involve many different kinds of units that are often incommensurate. It is not uncommon to
find a BREAKPOINT, INITIAL, DERIVATIVE, or KINETIC block in which some variables
or parameters have length in um, others have area in cm2, and yet others have volume in
liters; variables with concentrations in micro- or nanomoles/liter side by side with others
in millimoles/liter; currents in nano- or picoamperes alongside currents in micro- or
milliamperes, etc.. That's when automated units checking is essential.

Units checking is not generally needed for FUNCTION blocks that compute voltage-
dependent time constants and steady state values, because the expressions tend to
be simpler, stereotyped, and involve variables and parameters that have commensurate
units. This makes it easy to detect and fix any inconsistencies manually. Testing such
FUNCTION blocks with automated units checking tends to generate a lot of "nuisance"
error messages becuase automated testing is so fastidious about syntax, especially
of arguments and returned values.

In your particular example, I suspect the complaint arises because you have not
specified the units of the numeric arguments 0.1, 10, and 35. They should be ms-1, mv,
and mv, respectively (assuming you have defined ms and mv in the UNITS block), but
unless you add special notation, modlunit interprets them all as dimensionless.

You may well ask "Why don't I just insert the extra notation?"

Fine. Do you like this better?

Code: Select all

malpha = SafeExp(0.1(/ms),10(mv),-(v+35(mv)))
Most programmers prefer not to destroy the (human) readability of their code, which
complicates debugging and code maintenance, even if it makes modlunit happy.

So it's a common practice to disable units checking in such FUNCTION blocks by
surrounding them with UNITSOFF . . . UNITSON, e.g.

Code: Select all

UNITSOFF
 . . . function blocks go here . . .
UNITSON
Post Reply