Making nmodl files CVode Compatible

NMODL and the Channel Builder.
Post Reply
afc
Posts: 23
Joined: Tue Jul 08, 2014 1:31 pm

Making nmodl files CVode Compatible

Post by afc » Tue Nov 25, 2014 11:15 am

Dear all,

to the best of my knowledge when using the impedance class, the default calculation of the different transfer impedances does not take into account the impedance contributions of gating state differential equations. The calculation is currently limited to systems that can be solved with the CVode method, but unfortunately many mechanisms found in the literature, particularly ion channels models, are not compatible with CVode, and when one wants to analyze the morphoelectrotonic structure of a cell that has those ion channels, one is limited to analyse the passive electrotonic structure of the cell that may greatly differ from the “real” electrotonic structure of the cell.

To overcome this situation:

1) I would like to know if there is a systematic procedure to “generalize” the older/not-CVode-compatible ion channels nmodl files.

or,

2) If this generalization has to be done on a case by case basis, I would like to know where can I find some hints on how to do accomplish that.


Thank you all for the availability!

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

Re: Making nmodl files CVode Compatible

Post by ted » Tue Nov 25, 2014 2:58 pm

This is discussed in the Programmer's Reference--see
http://www.neuron.yale.edu/neuron/stati ... tionissues
et seq..

As I re-examine that material, I see the discussion of at_time but no mention of using self-events and the NET_RECEIVE block to achieve similar results. at_time does work and it has the particular advantage of working with density mechanisms. However, the NET_RECEIVE block--a feature available only to point processes--facilitates construction of state machines that can implement quite complex stimulus protocols and parameter changes in the course of a simulation.

afc
Posts: 23
Joined: Tue Jul 08, 2014 1:31 pm

Re: Making nmodl files CVode Compatible

Post by afc » Wed Nov 26, 2014 11:25 pm

Dr. Carnevale,

thank you for the prompt response! For what I indent to do, I will need a large number of CVode compatible ion channels nmodl files for different single neuron models, and probably it will be time consuming. Are you aware of some CVode compatible ion channels nmodl files that I can add to my list? I will start by “generalize” Mainen ZF, Sejnowski TJ (1996) (http://senselab.med.yale.edu/modeldb/sh ... model=2488), but I would like to have a more eclectic set of nmodl files for my simulations.

Looking forward for your response,
Thank you Professor!

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

Re: Making nmodl files CVode Compatible

Post by ted » Sat Nov 29, 2014 6:29 pm

I can only suggest that you examine the models in ModelDB, and whatever may be available from Channelpedia http://channelpedia.epfl.ch/. Be sure to check each mechanism with modlunit, and fix whatever problem(s) you find. Also, make sure that you use each model at its appropriate operating temperature; that can only be discovered by examining the mod file and reading the associated paper. Note in particular that the mod files used in

Mainen ZF, Sejnowski TJ (1996)
Influence of dendritic structure on firing pattern in model neocortical neurons.
Nature 382:363-6
ModelDB accession number 2488

were written in such a way as to work properly at 37 deg C.

afc
Posts: 23
Joined: Tue Jul 08, 2014 1:31 pm

Re: Making nmodl files CVode Compatible

Post by afc » Tue Jan 20, 2015 3:04 pm

Dear Ted,

I followed your advice and I examined the mod files from Mainen ZF, Sejnowski TJ (1996), but I got surprised when I ran some simulations (while using the mod files from that model) I realized that those mod files are CVode compatible. When I change the numerical method in the Tools menu from the nrngui to CVode, there was no error warning after the simulations, and the results from the voltage traces measured at the soma and the time course of the axial current reaching the soma were the same for CVode and for the Implicit fixed step (but the real time of the simulations was much faster with CVode). Then I found this in every mod file of the model:
26 Ago 2002 Modification of original channel to allow
variable time step and to correct an initialization error.
Done by Michael Hines(michael.hines@yale.e) and
Ruggero Scorcioni(rscorcio@gmu.edu) at EU Advance Course
in Computational Neuroscience. Obidos, Portugal
However, when I try to calculate the electrotonic distance while taking into account the impedance contributions of gating state differential equations of the same cell's models, the following error appears on the terminal:
/usr/local/nrn/x86_64/bin/nrniv: Segmentation violation
near line 1
{draw()}
^
Impedance[0].compute(0, 1)
LogAvsX[0].compute(0)
LogAvsX[0].draw()
Segmentation fault (core dumped)
But I thought the only requirement to take the impedance contributions of gating state differential equations into account, was that the mechanisms had to be compatible with CVode. What am I missing?

Thank you all for the availability once more!

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

Re: Making nmodl files CVode Compatible

Post by ted » Tue Jan 20, 2015 11:57 pm

afc wrote:I found this in every mod file of the model:
26 Ago 2002 Modification of original channel to allow
variable time step and to correct an initialization error. . .
It is always a good idea to read source code that one gets from others.
I thought the only requirement to take the impedance contributions of gating state differential equations into account, was that the mechanisms had to be compatible with CVode. What am I missing?
Possibly this statement in the Programmer's Reference documentation of the Impedance class's compute() method
"Note that the extended impedance calculation may involve a singular matrix because of the negative resistance contributions of excitable channels."
If that's what happened here, it would be nice if NEURON complained of a singular matrix instead of a segmentation violation, but I suspect that the latter is all one can expect. If a singular matrix is what's happening, reducing the conductance density of voltage-gated sodium and/or calcium channels BEFORE the first impedance calculation "with dstate/dt contribution" should make it go away.

By the way, I don't recall reading a statement to the effect that "the only requirement to take the impedance contributions of gating state differential equations into account, was that the mechanisms had to be compatible with CVode." Where did you find it? (not in something that I wrote, I hope . . . )

afc
Posts: 23
Joined: Tue Jul 08, 2014 1:31 pm

Re: Making nmodl files CVode Compatible

Post by afc » Wed Jan 21, 2015 3:34 pm

Dear Ted,
I followed your advice and I further analyzed the mod files from Mainen ZF, Sejnowski TJ (1996), I found out two "problems":

1) the cad.mod was modified to allow variable time step, but then afterwards the cnexp was replaced with derivimplicit. But i read in http://www.neuron.yale.edu/neuron/stati ... tionissues that one has to replace the SOLVE statement in the BREAKPOINT block with SOLVE states METHOD cnexp. However, even when I did not include this mod file in my models the same error continued to appear.

2) when I checked the kca.mod mechanism with modlunit, an error occurred:
Need declaration in UNITS block of the form:
(mM) (units)
Cannot recognize the units: mM at line 54 in file kca.mod
and when I declared it at the UNITS block, the following error appeared:
Checking units of kca.mod
1 /m3
The previous expression is not dimensionless at line 129 in file kca.mod
a = Ra * cai^caix<<ERROR>>
but since this mod file is extensively used in the literature, I assumed that the the absence of the (mM) in the UNITS block was on purpose for some reason.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If a singular matrix is what's happening, reducing the conductance density of voltage-gated sodium and/or calcium channels BEFORE the first impedance calculation "with dstate/dt contribution" should make it go away.
I reduced the conductance density of these channels, first one by one, and then both at the same time, and the same error appeared.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
By the way, I don't recall reading a statement to the effect that "the only requirement to take the impedance contributions of gating state differential equations into account, was that the mechanisms had to be compatible with CVode." Where did you find it? (not in something that I wrote, I hope . . . )
At this thread: https://www.neuron.yale.edu/phpBB2/viewtopic.php?t=771 there is a comment in a chunk of code that says the following:
zz.compute(FREQ, 1) // takes the impedance contributions of
// gating state differential equations into account
// but requires mechanisms to be compatible with CVODE
from this I assumed that the generalization of the mod files of the channels would be a sufficient condition to enable one to compute the electrotonic distance of the cell taking into account the influence of those channels. But so far, all the mod files from this model are CVode compatible, but I can not compute the electrotonic distance of the cells when they have these active conductances, so I guess I misinterpreted that statement.

Thank you once more!!

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

Re: Making nmodl files CVode Compatible

Post by ted » Wed Jan 21, 2015 5:07 pm

afc wrote:I followed your advice and I further analyzed the mod files from Mainen ZF, Sejnowski TJ (1996), I found out two "problems":

1) the cad.mod was modified to allow variable time step, but then afterwards the cnexp was replaced with derivimplicit.
This is not a problem. derivimplicit, like cnexp, is compatible with adaptive integration ("cvode"). To learn more about NEURON's integration methods, and why derivimplicit is sometimes used, see
Integration methods for SOLVE statements
in the Hot topics area of the NEURON Forum.
i read in http://www.neuron.yale.edu/neuron/stati ... tionissues that one has to replace the SOLVE statement in the BREAKPOINT block with SOLVE states METHOD cnexp.
That is true in the context of that discussion because the mechanisms that were being addressed in that discussion are HH-style channel descriptions, that is, descriptions of voltage-gated channels that are couched as families of ordinary differential equations, in which the state variables are limited to the range 0..1. derivimplicit is used for accumulation mechanisms, in which one wants to avoid the nonsense result of having a concentration become negative.
even when I did not include this mod file in my models the same error continued to appear.
That's a good test.
2) when I checked the kca.mod mechanism with modlunit, an error occurred:
Need declaration in UNITS block of the form:
(mM) (units)
Cannot recognize the units: mM at line 54 in file kca.mod
modlunit tests for two different things: consistency of units, and NMODL syntax. A report that some units are not defined, or that some inconsistency was discovered, is only a warning and not a report of an error. The code will still compile and run, but the user is advised to verify that any necessary scale factors have been applied so that the results will not be garbage.

When modlunit reports a syntax error, that's a serious problem that should be fixed. Syntax errors generally produce code that doesn't even run.
when I declared it at the UNITS block
What statement did you insert?

Not to say that consistency of units is unimportant, but none of this is relevant to the impedance calculation problem.
since this mod file is extensively used in the literature, I assumed that the the absence of the (mM) in the UNITS block was on purpose for some reason.
Not at all. Common practice is often entirely accidental and arbitrary. In particular, much source code written by scientists rather than experienced programmers is riddled with minor oddities, many of which serve no useful purpose and are neither deliberate nor harmful.
If a singular matrix is what's happening, reducing the conductance density of voltage-gated sodium and/or calcium channels BEFORE the first impedance calculation "with dstate/dt contribution" should make it go away.
I reduced the conductance density of these channels, first one by one, and then both at the same time, and the same error appeared.
Yes, I just did the same myself with
oc>forall if(ismembrane("na")) for (x,0) gbar_na(x) = 0
oc>forall if(ismembrane("ca")) for (x,0) gbar_ca(x) = 0
and it had no useful effect. This will take some further investigation.
At this thread: https://www.neuron.yale.edu/phpBB2/viewtopic.php?t=771 there is a comment in a chunk of code that says the following:

Code: Select all

 zz.compute(FREQ, 1) // takes the impedance contributions of 
                      // gating state differential equations into account
                      // but requires mechanisms to be compatible with CVODE
from this I assumed that the generalization of the mod files of the channels would be a sufficient condition to enable one to compute the electrotonic distance of the cell taking into account the influence of those channels.
Just because something is necessary does not mean that it is also sufficient.

But I wonder where the problem with the impedance calculation lies.

hines
Site Admin
Posts: 1590
Joined: Wed May 18, 2005 3:32 pm

Re: Making nmodl files CVode Compatible

Post by hines » Thu Jan 22, 2015 1:39 am

I'd like to reproduce the problem. Can you send me al the hoc,ses,mod files needed in a zip file to michael dot hines at yale dot edu along with instructions
as to how to see the error?

hines
Site Admin
Posts: 1590
Joined: Wed May 18, 2005 3:32 pm

Re: Making nmodl files CVode Compatible

Post by hines » Thu Jan 22, 2015 1:54 am

Nevermind. I downloaded the 2488 model, selected "Figure 1 demo" and then "L3 Aspiny" and "Init&Run".
Then popped up a NEURONMainMenu/Tools/Impedance/Frequency . On selecting
"include dstate/dt contribution" I get the message:
Graph:: presently invalid expression: input(f)
and pressing "Redraw" givse the segmentation violation.
I'll look into this and get back to you.

hines
Site Admin
Posts: 1590
Joined: Wed May 18, 2005 3:32 pm

Re: Making nmodl files CVode Compatible

Post by hines » Thu Jan 22, 2015 4:37 am

The Impedance dstate/dt contribution calculation had a bug when the BREAKPOINT block involved a thread instance variable. ie. in ca.mod the statement
gca = tadj*gbar*m*m*h
used tadj.
http://www.neuron.yale.edu/hg/neuron/nr ... e217f4738e
fixes the problem.
You might want to be sceptical of nonlinear impedance results until you have experimented with situations where you know or can intuit the proper behavior from other independent
considerations. At least experiment with different dt if you are looking at movies of the impedance. There seem to be occasional transient singularities in the frequency plot of the
impedance ratio during recovery of the ap for the L3 Aspiny for both fixed and variable step methods. It would probably take days to investigate some of them using small sinusoidal current
sitmuli.

afc
Posts: 23
Joined: Tue Jul 08, 2014 1:31 pm

Re: Making nmodl files CVode Compatible

Post by afc » Thu Jan 22, 2015 9:16 am

Thank you so much for your prompt response!!

But just to be sure, How/Where should I add the extra line of code?

Thank you!

hines
Site Admin
Posts: 1590
Joined: Wed May 18, 2005 3:32 pm

Re: Making nmodl files CVode Compatible

Post by hines » Thu Jan 22, 2015 10:02 am

Did you build NEURON from sources? Or did you use an installer. If the latter which installer did you use?

afc
Posts: 23
Joined: Tue Jul 08, 2014 1:31 pm

Re: Making nmodl files CVode Compatible

Post by afc » Fri Jan 23, 2015 6:47 am

I used an installer, particularly the Debian/Ubuntu for 64 bit (amd86/x86_64) (version 7.3).

hines
Site Admin
Posts: 1590
Joined: Wed May 18, 2005 3:32 pm

Re: Making nmodl files CVode Compatible

Post by hines » Fri Jan 23, 2015 10:01 am

Try
http://www.neuron.yale.edu/ftp/neuron/v ... x86_64.deb
If you have a problem launching due to "No module named site" then do an
export PYTHONHOME=/usr
and launch again.

Post Reply