Units errors in mod files Morgan/Santhakumar 2007 model

Discussions of particular models.

Moderator: tom_morse

Post Reply
kfolw
Posts: 6
Joined: Tue Dec 30, 2014 1:22 pm

Units errors in mod files Morgan/Santhakumar 2007 model

Post by kfolw » Fri Feb 06, 2015 10:00 pm

When checking the units of the mod files in this model through the neuron GUI, 5 of the mod files came back with errors: tca, LcaMig, CaBK, bgka, ppsyn. Is there a way to fix these errors? I am using Windows 7. Specific errors listed below:

For CaBK.mod:

Code: Select all

model   1.1.1.1   1994/10/12 17:22:51
Checking units of ./CaBK.mod
ncai must have the units, milli/liter, instead of mV.
 at line 16 in file ./CaBK.mod
NEURON<<ERROR>> {

Press Return key to exit

For tca.mod:

Code: Select all

model   1.1.1.1   1994/10/12 17:22:51
Checking units of ./tca.mod
Need declaration in UNITS block of the form:
        (mM)    (units)
Cannot recognize the units: mM at line 18 in file ./tca.mod
        cai (mM)<<ERROR>>

Press Return key to exit

for ppsyn.mod:

Code: Select all

model   1.1.1.1   1994/10/12 17:22:51
Checking units of ./ppsyn.mod

units:  1-09 sec2-coul2/m2-kg

units:  1-06 sec-coul2/m2-kg
The units of the previous two expressions are not conformable
 at line 40 in file ./ppsyn.mod
gs=gsbar * on<<ERROR>>

Press Return key to exit
For bgka.mod:

Code: Select all

model   1.1.1.1   1994/10/12 17:22:51
Checking units of ./bgka.mod

units:  10000 sec-coul2/m4-kg

units:  1
The units of the previous two expressions are not conformable
 at line 53 in file ./bgka.mod
        gka = gkabar*n*l<<ERROR>>

Press Return key to exit
For LcaMig.mod:

Code: Select all

model   1.1.1.1   1994/10/12 17:22:51
Checking units of ./LcaMig.mod
Need declaration in UNITS block of the form:
        (DegC)  (units)
Cannot recognize the units: DegC at line 75 in file ./LcaMig.mod
FUNCTION KTF(celsius (DegC)<<ERROR>>) (mV) {

Press Return key to exit


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

Re: Units errors in mod files Morgan/Santhakumar 2007 model

Post by ted » Sun Feb 08, 2015 8:55 pm

modlunit is very fastidious about checking for two things:
inconsistency of units, and syntax errors.
It has two shortcomings:
1. After it finds one thing to complain about, it stops checking for anything else that may bother it.
2. Its error messages may seem unclear, but they're really not.

So, given any mod file, you need to

Code: Select all

REPEAT
  check the file with modlunit
  fix any error that it finds
UNTIL it finds nothing more to complain about
Most often the units inconsistencies that it discovers are only "apparent" inconsistencies and not real errors; that is, the mod file will generate numerically correct results without requiring you to insert any numerical scale factors. Typically this happens when the units of a variable are not declared, or when the code contains a name of a unit that modlunit doesn't understand.

But sometimes the units declared for a variable just don't make sense. Example: in ppsyn.mod, modlunit complains

Code: Select all

units:	1-09 sec2-coul2/m2-kg
units:	1-06 sec-coul2/m2-kg
The units of the previous two expressions are not conformable
 at line 40 in file ppsyn.mod
gs=gsbar * on<<ERROR>>
so look at the units declared for gs, gsbar, and on. gs and gsbar are both in umho (microsiemens), so "on" should have no units at all. However, for reasons known only to the person who wrote the file, "on" is declared as having units of ms (milliseconds). Further examination of the code shows that "on" isn't supposed to have any units--it's supposed to be a dimensionless number. So change the declaration of "on" from
on (ms)
to
on (1)
("(1)" is just a reminder to the person who reads the file that "on" is supposed to be dimensionless), and run modlunit again. Presto! modlunit is happy.

A side comment: this file does some silly things, like declare "on" to be a PARAMETER (it is not--its value appears on the left hand side of an assignment statement, so it really should be declared in the ASSIGNED block if you want to be picky about it). Actually, to be really picky, v isn't a parameter either, and it's just sloppy to have two PARAMETER blocks, and there's no need for the INDEPENDENT statement (doesn't do anything useful in NMODL code). But none of these things will cause problems.

Now that you know a bit, see what you can do with bgka.mod, and if you run into problems, ask more questions!

kfolw
Posts: 6
Joined: Tue Dec 30, 2014 1:22 pm

Re: Units errors in mod files Morgan/Santhakumar 2007 model

Post by kfolw » Mon Feb 09, 2015 11:18 am

Thank you that helped resolve some of my errors! However, I keep running into this next error:

Code: Select all

model   1.1.1.1   1994/10/12 17:22:51
Checking units of ./LcaMig.mod
Need declaration in UNITS block of the form:
        (DegC)  (units)
Cannot recognize the units: DegC at line 75 in file ./LcaMig.mod
FUNCTION KTF(celsius (DegC)<<ERROR>>) (mV) {

Press Return key to exit

However, if I insert (DegC) = (celsius) into the Units block, I get another error. Am I using the correct syntax?

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

Re: Units errors in mod files Morgan/Santhakumar 2007 model

Post by ted » Mon Feb 09, 2015 12:10 pm

I'd suggest changing every occurrence of
DegC
which modlunit doesn't recognize
to
degC
which it will recognize because it is a standard unit name, known to all versions of UNIX/Linux/OS X (sorry, MSWin users).

"Seems very arbitrary. How can I discover these magic names for myself?"

One quick way is to look at a mod file that modlunit doesn't complain about. If you get the gzipped tar file that contains NEURON's source code, expand it, then look in
nrn/src/nrnoc
you'll find a bunch of mod files. One of them is hh.mod, which contains lots of clues.

This "tutorial" on units is quite informative
http://www.neuron.yale.edu/neuron/stati ... units.html

And if you want a ton of information about the names of all kinds of units, including much strange sounding stuff, check out the units.dat file that comes with many Linux versions--here's an example that's a few years old, but most of it is still valid:
http://www.neuron.yale.edu/neuron/stati ... /units.dat

kfolw
Posts: 6
Joined: Tue Dec 30, 2014 1:22 pm

Re: Units errors in mod files Morgan/Santhakumar 2007 model

Post by kfolw » Wed Feb 18, 2015 10:08 am

Thank you for the explanations, however after comparing to some of the other files I still am having trouble debugging.

for example in the LcaMig.mod file, after fixing DegC to be degC, I get the following error:
model 1.1.1.1 1994/10/12 17:22:51
Checking units of ./LcaMig.mod

units: 1 K

units: 0.001 m2-kg/sec2-coul
The units of the previous two expressions are not conformable
at line 76 in file ./LcaMig.mod
KTF = ((25./293.15)*(celsius + 273.15))<<ERROR>>

Press Return key to exit

So then looking at that line of code:

Code: Select all

FUNCTION KTF(celsius (degC)) (mV) {
        KTF = ((25./293.15)*(celsius + 273.15))
}
I thought that KTF didn't need the mV units so I deleted that statement. However the next error that occurred was:
Checking units of ./LcaMig.mod
0.001 m2-kg/sec2-coul
The previous expression is not dimensionless at line 72 in file ./LcaMig.mod
ghk=-f*(1. - (ci/co)*exp(nu<<ERROR>>))*efun(nu)

Press Return key to exit
and the corresponding code is :

Code: Select all

FUNCTION ghk(v(mV), ci(mM), co(mM)) (mV) {
        LOCAL nu,f

        f = KTF(celsius)/2
        nu = v/f
        ghk=-f*(1. - (ci/co)*exp(nu))*efun(nu)
}
So I'm assuming nu has to be dimensionless, but am unsure how to make it so in this section of code. Did deleting (mV) to make the previous error disappear create this error?

Thank you.

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

Re: Units errors in mod files Morgan/Santhakumar 2007 model

Post by ted » Wed Feb 18, 2015 1:01 pm

I thought that KTF didn't need the mV units
Wrong guess. All you did was allow modlunit to skip over the guts of FUNCTION KTF and start finding fault with other statements.

Look at modlunit's message:

Code: Select all

units:	1 K
units:	0.001 m2-kg/sec2-coul
The units of the previous two expressions are not conformable
 at line 77 in file LcaMig.mod
        KTF = ((25./293.15)*(celsius + 273.15))<<ERROR>>
It's all about the statement that assigns a value to KTF. KTF is supposed to get a numerical result that is in units of mV. Nothing on the right hand side (RHS) of the assignment statement has units of mV. The only thing that is associated with any particular units is celsius, and its units are degC. modlunit will complain if you try to add anything to celsius that isn't also in degC, so clearly it is necessary to change
(celsius + 273.15)
to
(celsius + 273.15 (degC)).
The (degC) notation tells modlunit that the thing to its left has units of degC.

Doing that makes the RHS into a product of a dimensionless value and something that has units of degC. Clearly the denominator in
(25./293.15)
has units of degC, and its numerator has units of mV (if that isn't so clear, stare at and think about the Nernst equation for a while).

So the completely repaired assignment statement is
KTF = ((25. (mV)/293.15 (degC))*(celsius + 273.15 (degC)))

By the way, notice that none of these changes affects the numerical value that is returned by FUNCTION KTF. They just make modlunit's complaints go away. You'll see a lot of code that uses UNITSOFF...UNITSON because an experienced programmer can write a lot of code that is numerically correct by inspection but which modlunit will complain endlessly about until you insert so many units declarations as to make the code rather unreadable. This happens especially with code that computes transition rates, or time constants and steady state values of gating state variables. Sacrificing readability for the sake of satisfying a finicky program like modlunit is not a good tradeoff.

On the other hand, there are times when it is not so obvious that a numerical conversion factor is not required, or when a statement is algebraically so complex that it contains a serious syntax error, and those are times when it really is useful to insert units declarations and test until modlunit is happy.

Now back to your next problem.
I'm assuming nu has to be dimensionless, but am unsure how to make it so
Really, you brought this one on yourself. First look at how its value is calculated
nu = v/f
where the units of v are mV (as declared in the FUNCTION ghk line) and the units of f are the same as the units of FUNCTION KTF. Oh, wait. If FUNCTION KTF returns a value whose units are nothing, then f will have units of nothing, and v/f will have units of mV. Maybe it's not such a bad thing for the value returned by FUNCTION KTF to be in mV.

It is all very satisfying when these things work out properly, but I should mention again that--so far--none of these changes does anything at all to the numerical values that are generated by the calculations specified in LcaMig.mod. Of course that's isn't to say that the next time you run modlunit, it won't find some units error that can only be fixed by including a numerical scale factor. And that's exactly the kind of error that can really mess up simulation results, because code will run--not crash--and yet results will be way off.

kfolw
Posts: 6
Joined: Tue Dec 30, 2014 1:22 pm

Re: Units errors in mod files Morgan/Santhakumar 2007 model

Post by kfolw » Wed Feb 18, 2015 4:23 pm

Ah, I understand now and it worked to fix all my mod files! Thank you for a very clear and detailed explanation.

Now however, when I go to compile these mod files, there appears to be a mystery file in the same directory called ~$bgka.mod that causes an error. It's not part of the original model code and I'm not sure how it got put into. This file doesn't show up in my Windows directory folder but it does show up when I list the files in this directory folder using the cygwin terminal. When I go to remove it with cygwin however, it says:
$ rm ~$bgka.mod
rm: cannot remove ‘~.mod’: No such file or directory
It seems to not be able to recognize it because of the $, so how can I delete it?

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

Re: Units errors in mod files Morgan/Santhakumar 2007 model

Post by ted » Wed Feb 18, 2015 5:23 pm

It's relentless, isn't it? As soon as you fix one thing, something else rears its ugly head.

Maybe cygwin's shell (similar in purpose to the command line interpreter that an MSWindows "cmd window" uses to deal with user-entered commands) is treating the $ as a "variable substitution flag", that is, it reacts to ~$bgka.mod as if bgka is a shell variable. If you haven't already used a command to assign a value to bgka, such as
bgka=foo
where foo is a string or numeric value, then
~$bgka.mod
will be interpreted as the concatenation of "~", nothing, and ".mod". If that's what is happening, this

Code: Select all

rm ~\$bgka.mod
(i.e. "escaping" the $) should work, and you might want to read more about "quoting" characters and escape characters
http://tldp.org/LDP/Bash-Beginners-Guid ... 03_03.html
and perhaps also about special characters (especially $)
http://tldp.org/LDP/abs/html/special-chars.html

Post Reply