How to change parameter used in NMODL for channel kinetics in hoc

NMODL and the Channel Builder.
Post Reply
zylittlep
Posts: 9
Joined: Sat Feb 16, 2019 6:36 pm

How to change parameter used in NMODL for channel kinetics in hoc

Post by zylittlep » Tue Feb 19, 2019 5:22 pm

Hi all,

I'm new to NEURON and trying to build a one segment model with different ion channels.
I'm wondering how to simultaneously change parameters used in mod files in hoc and view plots. As an example, I'd like to change parameters such as vhkv1ninf, kkv1ninf, etc. as in the mod file below. As for now, I can access these parameters but changing the values from hoc do not have any impact on the channel kinetics. Thank you very much!

Code: Select all

UNITS {
    (mV) = (millivolt)
    (mA) = (milliamp)
    (S) = (siemens)
}

NEURON {
    SUFFIX kv1
    USEION k READ ek WRITE ik
    RANGE gkv1bar, gkv1, ik
    GLOBAL vhkv1ninf, kkv1ninf, akv1ntaul, bkv1ntaul, ckv1ntaul, dkv1ntaul, akv1ntaur, bkv1ntaur, ckv1ntaur,dkv1ntaur
    GLOBAL akv1hinf, bkv1hinf, vhkv1hinf, kkv1hinf, akv1htaul, bkv1htaul, ckv1htaul, dkv1htaul, akv1htaur, bkv1htaur, ckv1htaur, dkv1htaur
}

PARAMETER{ 
    gkv1bar = 0.0015 (S/cm2):to adjust according to Pin's DRG recording
    ek = -99 (mV): From Pin paper check Figure4 legend
    vhkv1ninf = -61
    kkv1ninf = 14.3
    akv1ntaul = 0
    bkv1ntaul = 4.59
    ckv1ntaul = -56
    dkv1ntaul = 15.4
    akv1ntaur = 0.21
    bkv1ntaur = 5.6
    ckv1ntaur = -96
    dkv1ntaur = 19.6
    akv1hinf = 0.5
    bkv1hinf = 0.5
    vhkv1hinf = -58.5
    kkv1hinf = 7.5
    akv1htaul = 7.4
    bkv1htaul = 117
    ckv1htaul = -65
    dkv1htaul = 10.7
    akv1htaur = 2.5
    bkv1htaur = 109.5
    ckv1htaur = -36.8
    dkv1htaur = 6.3
}

ASSIGNED{
    v (mV)
    ik (mA/cm2)
    gkv1 (S/cm2)
    ninfkv1
    hinfkv1
    ntaukv1 (ms) 
    htaukv1 (ms)
    
}

STATE{
    nkv1 hkv1
}

BREAKPOINT{
    SOLVE states METHOD cnexp
    
    gkv1 = gkv1bar * nkv1^4 * hkv1
    ik = gkv1 * (v - ek)
}

UNITSOFF

INITIAL{
    settables(v)
    nkv1 = ninfkv1
    hkv1 = hinfkv1
}

DERIVATIVE states{
    settables(v)
    nkv1' = (ninfkv1-nkv1)/ntaukv1
    hkv1' = (hinfkv1-hkv1)/htaukv1
}

UNITSOFF

PROCEDURE settables(v (mV)){
    TABLE ninfkv1, ntaukv1, hinfkv1, htaukv1
    FROM -100 TO 100 WITH 200
    
    ninfkv1 = 1/(1+exp(-(v-vhkv1ninf)/kkv1ninf))
:   ninf = 1/(1+exp(-(v+61)/14.3))

if (v < -60){
         ntaukv1 = akv1ntaul+bkv1ntaul*(1/(1+exp(-(v-ckv1ntaul)/dkv1ntaul)))
:        ntau = 4.59*(1/(1+exp(-(v+56)/15.4)))
    }else{
         ntaukv1 = akv1ntaur+bkv1ntaur*(1/(1+exp((v-ckv1ntaur)/dkv1ntaur)))
:        ntau = 0.21+5.6*(1/(1+exp((v+96)/19.6)))
    }

    hinfkv1 = akv1hinf+bkv1hinf/(1+exp((v-vhkv1hinf)/kkv1hinf))
:   hinf = 0.5+0.5/(1+exp((v+58.5)/7.5))

if (v < -50){
         htaukv1 = akv1htaul+bkv1htaul*(1/(1+exp(-(v-ckv1htaul)/dkv1htaul)))
:        htau = 7.4+117*(1/(1+exp(-(v+65)/10.7)))
    }else{
         htaukv1 = akv1htaur+bkv1htaur*(1/(1+exp((v-ckv1htaur)/dkv1htaur)))
:        htau = 2.5+109.5*(1/(1+exp((v+36.8)/6.3)))
    }

}

UNITSON
/[code]

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

Re: How to change parameter used in NMODL for channel kinetics in hoc

Post by ted » Wed Feb 20, 2019 1:06 am

How do you know that you changed the value of any particular parameter. Pick one, show me the hoc statement(s) you used to change it, and show me the hoc statement(s) that confirm that you actually changed it.

zylittlep
Posts: 9
Joined: Sat Feb 16, 2019 6:36 pm

Re: How to change parameter used in NMODL for channel kinetics in hoc

Post by zylittlep » Wed Feb 20, 2019 11:57 am

Say I want to change akv1ntaur, I wrote a hoc file called channel_parameters.hoc which includes these parameters, for example

Code: Select all

//kv1 parameters
    gkv1bar = 0.0015 
    vhkv1ninf = -61
    kkv1ninf = 14.3
    
    akv1ntaul = 0
    bkv1ntaul = 4.59
    ckv1ntaul = -56
    dkv1ntaul = 15.4
    
    akv1ntaur = 0.21
    bkv1ntaur = 5.6
    ckv1ntaur = -96
    dkv1ntaur = 19.6
    
    akv1hinf = 0.5
    bkv1hinf = 0.5
    vhkv1hinf = -58.5
    kkv1hinf = 7.5
    
    akv1htaul = 7.4
    bkv1htaul = 117
    ckv1htaul = -65
    dkv1htaul = 10.7
    
    akv1htaur = 2.5
    bkv1htaur = 109.5
    ckv1htaur = -36.8
    dkv1htaur = 6.3
and I can change akv1ntaur to say 0.5, when I print the value of akv1ntaur in the terminal, it changed to 0.5, however when I give the neuron a voltage step, the current trace is exactly the same.

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

Re: How to change parameter used in NMODL for channel kinetics in hoc

Post by ted » Thu Feb 21, 2019 10:51 am

From the problem you're having, it's clear that you haven't read The NEURON Book, so let me start by suggesting two papers for you to read. One is
The NEURON simulation environment
which we published in Neural Computation (NOT the paper with the same title that was published in Arbib's book).
The other is
Expanding NEURON's repertoire of mechanisms with NMODL.
Both of these are downloadable from the page Key Papers, the link to which is in the left column of the Documentation page at NEURON's web site
Next, here is the answer to your problem, combined with a suggestion that will make your NMODL, hoc, and/or Python code more readable and easier to use and maintain. Note that the NMODL code that describes the properties of a density mechanism (AKA "distributed mechanism") has a NEURON block that declares the mechanism's SUFFIX. The SUFFIX becomes part of the hoc or Python name of every one of that mechanism's variables and parameters that are accessible from hoc or Python. For example, you may already have noticed that NEURON's built-in hh mechanism has sodium and potassium channel density parameters whose hoc names are gnabar_hh and gkbar_hh. That's because hh.mod's NEURON block declares SUFFIX hh.

Next notice that the hoc names of the channel densities aren't ghhnabar_hh and ghhkbar_hh. But guess what the hoc names of the variables of your kv1 mechanism will be. By declaring
RANGE gkv1bar, gkv1, and ik
in the NEURON block, you end up with the hoc names
gkv1bar_kv1, gkv1_kv1, and ik_kv1
Those are less readable, harder to type, and no more descriptive, than
gbar_kv1, g_kv1, and i_kv1
which is what you'd get if the declaration in the NEURON block was
RANGE gbar, g, i
The same can be said for all of those GLOBAL declarations.

So make life easier for yourself by eliminating useless redundancy. In the NMODL code that you use to specify the properties of a density mechanism, don't include that mechanism's SUFFIX in the name of any variable or parameter.

zylittlep
Posts: 9
Joined: Sat Feb 16, 2019 6:36 pm

Re: How to change parameter used in NMODL for channel kinetics in hoc

Post by zylittlep » Thu Feb 21, 2019 2:11 pm

Thank you for your response. But I don't think that's where the problem lies. Even when I add SUFFIX to the parameters except for gbar, the channel behaves the same.

zylittlep
Posts: 9
Joined: Sat Feb 16, 2019 6:36 pm

Re: How to change parameter used in NMODL for channel kinetics in hoc

Post by zylittlep » Thu Feb 21, 2019 7:01 pm

I figured it out. Just need to set usetable=0. Anyway, thank you very much!

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

Re: How to change parameter used in NMODL for channel kinetics in hoc

Post by ted » Fri Feb 22, 2019 12:23 pm

In this post I'm going to use sensible variable names (they'll leave out the redundant kv1).
zylittlep wrote:
Thu Feb 21, 2019 2:11 pm
Thank you for your response. But I don't think that's where the problem lies. Even when I add SUFFIX to the parameters except for gbar, the channel behaves the same.
On the contrary, it is a huge problem. The statements in channel_parameters.hoc are entirely useless in their present form, because they merely create new hoc variables that have nothing to do with the parameters used by the code in the NMODL file. And nothing you do to usetable will fix that.

But it's not the only problem. There is another one, and it has to do with the use of tables.
I figured it out. Just need to set usetable=0.
Yes. That's because the second problem is the use of tables for the voltage-dependent ninf, ntau, hinf, and htau. The TABLE statement makes NEURON create look-up tables for these voltage-dependent parameters. The overhead of setting up the tables is low, because they are created during model setup and are not recalculated after that. But after they have been created, the look-up tables allow simulations to run a bit faster than they would if ninf, ntau, hinf, and htau had to be recalculated at each time step. The speedup can be significant for a long simulation of a large network model.

But here you have a mod file in which the formulas for ninf, ntau, hinf, and htau involve many parameters that can be changed from hoc or Python. If you change any of those parameters, you also have to do something else: tell NEURON not to use the tables, or make NEURON recalculate the tables for ninf, ntau, hinf, and htau.

The statement
usetable_kv1 = 0
disables the kv1 mechanism's use of tables. That works, but at the cost of slightly slower simulations.

The alternative is to explicitly tell NMODL the names of those parameters that should trigger recalculation of the tables. This is done by adding a DEPEND clause to the TABLE statement. In your NMODL file for kv1, the TABLE statement is

Code: Select all

    TABLE ninf, ntau, hinf, htau
    FROM -100 TO 100 WITH 200
If vhhinf is the only parameter you wanted to change, just change the TABLE statement to

Code: Select all

    TABLE ninf, ntau, htau
    FROM -100 TO 100 WITH 200
    TABLE hinf
    DEPEND vhhinf
    FROM -100 TO 100 WITH 200
Why are there two TABLE statements? Because only the table for hinf depends on vhhinf. If you change vhhinf, there's no need to recalculate the tables for ninf, ntau, or htau.

Since your NMODL code for ninf, ntau, hinf, and htau is fully parameterized, you'll probably want to have four TABLE statements--one for each of the voltage-dependent parameters--and each one will have its own DEPEND clause that mentions only the parameters relevant to it. After you do that and recompile the mechanism, changing any parameters mentioned in the DEPEND clauses will trigger recalculation of the relevant tables.

zylittlep
Posts: 9
Joined: Sat Feb 16, 2019 6:36 pm

Re: How to change parameter used in NMODL for channel kinetics in hoc

Post by zylittlep » Sun Feb 24, 2019 4:54 pm

Thank you so much for the input! I'm revising my code now.

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

Re: How to change parameter used in NMODL for channel kinetics in hoc

Post by ted » Sun Feb 24, 2019 5:26 pm

It's easy to forget about the DEPEND clause, because most mod files use hard-coded numerical values in the formulas for voltage- or concentration-dependent rate constants, time constants, and steady-state variables, so TABLE statements in such a file don't need a DEPEND clause. Most often when you do see a DEPEND clause, it's because the rate or time constants are temperature dependent, so their formulas involve celsius. Since the value of celsius can be changed by a hoc or Python statement, TABLE statements for temperature-dependent rate or time constants need to include
DEPEND celsius
And for some reason or other, people tend to remember this particular detail.

But the same is true for any other parameter that affects rate or time constants or steady state values, if the value of that parameter can be changed from hoc or Python--TABLE statements for the affected rate or time constants, or steady state values, need to have a DEPEND clause. So easy to forget, and so puzzling when forgotten.

zylittlep
Posts: 9
Joined: Sat Feb 16, 2019 6:36 pm

Re: How to change parameter used in NMODL for channel kinetics in hoc

Post by zylittlep » Sun Feb 24, 2019 7:36 pm

Hi Ted,

When I modified the TABLE statement with DEPEND like

Code: Select all

 TABLE ninf, ntau, htau
    FROM -100 TO 100 WITH 200
    TABLE hinf
    DEPEND vhhinf
    FROM -100 TO 100 WITH 200


I get error message saying 'only one TABLE per function' . I'm wondering where the problem is.
Does it mean I should have four separate procedure blocks and each has only one table in them?

Thank you.

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

Re: How to change parameter used in NMODL for channel kinetics in hoc

Post by ted » Mon Feb 25, 2019 12:20 pm

What it means:
1. I was unaware of that limitation of NMODL's TABLE directive. Sorry. We both learned something new.
2. If you have to be able to use hoc or Python statements to change parameters that affect gating variables' time or rate constants or steady state values, you should probably just comment out the TABLE statement because it's worse than useless in its present form (the table will occupy RAM). After you do that, spend some time working on your real modeling project instead of editing NMODL code. If your simulations are running fast enough, then don't waste time tinkering with NMODL. If they're not, try factoring PROCEDURE settables() into 4 different PROCEDUREs and see if that makes much of a difference. My bet is that you won't get back the time that it took you to revise settables(). Remember, computer time is very cheap, human time is very valuable.

By the way, have you noticed that the Allen Institute's models (check ModelDB) don't have TABLE statements in their mod files? Not even in mod files with parameterized rate functions! Now, why do you suppose that is?

zylittlep
Posts: 9
Joined: Sat Feb 16, 2019 6:36 pm

Re: How to change parameter used in NMODL for channel kinetics in hoc

Post by zylittlep » Mon Feb 25, 2019 4:33 pm

I suppose it's because the computation is fast enough for their purpose. Not using lookup tables is still fast enough.

Post Reply