Accessing a variable from hoc that is not defined in NMODL

NMODL and the Channel Builder.
Post Reply
pascal
Posts: 62
Joined: Thu Apr 26, 2012 11:51 am

Accessing a variable from hoc that is not defined in NMODL

Post by pascal » Fri Feb 10, 2017 10:19 am

I am translating a hoc model (that I inherited) into Python, and I am having some trouble with a custom mod file. The hoc code references the mod file (which defines a mechanism named "IhPyrKop") in the following way:

Code: Select all

insert IhPyrKop
soma{
gh_IhPyrKop     =   0.1
v50_IhPyrKop    = -82
}
The only problem is, gh_IhPyrKop is not defined within the mod file...and yet the hoc code still runs without error. This presents a challenge to accurately translating the code to Python, because in Python the statement soma.gh_IhPyrKop = 0.1 generates the error 'nrn.Section' object has no attribute 'gh_IhPyrKop'. The fact that Python generates this error makes sense, since gh_IhPyrKop is not defined in the mod file. What I do not understand is why hoc runs the code without error. Perhaps there is something I am fundamentally not understanding about mod files.

Here is the mod file in question:

Code: Select all

NEURON {
	SUFFIX IhPyrKop
NONSPECIFIC_CURRENT i
	RANGE v50, gmax
}
	
UNITS {
	(mA) = (milliamp)
	(mV) = (millivolt)
	(mS) = (millisiemens)
}

PARAMETER {
    gmax =   0.0  (mS/cm2)
    eh   = -30.0  (mV)
    v50  =   0.0 (mV)
}
    
ASSIGNED { 

    v (mV)
    i (mA/cm2)
}

STATE { q }

INITIAL { q  = qinf(v) }

BREAKPOINT {

	SOLVE states METHOD cnexp
	
    i = (1e-3) * gmax * q * (v-eh)
}

DERIVATIVE states { q' = (qinf(v)-q)/qtau(v) }

FUNCTION qinf(v(mV))     { qinf = fun2(v, v50, 1.0, 10.5)*1.0(ms) }
FUNCTION qtau(v(mV))(ms) { qtau = 1.0(ms)/(exp((-14.59(mV)-0.086*v)/1.0(mV)) + exp((-1.87(mV)+0.0701*v)/1.0(mV))) }

INCLUDE "aux_fun.inc"
And here is aux_fun.inc:

Code: Select all

FUNCTION fun1(v(mV),V0(mV),A(/ms),B(mV))(/ms) {

	 fun1 = A*exp((v-V0)/B)
}

FUNCTION fun2(v(mV),V0(mV),A(/ms),B(mV))(/ms) {

	 fun2 = A/(exp((v-V0)/B)+1)
}

FUNCTION fun3(v(mV),V0(mV),A(/ms),B(mV))(/ms) {

    if(fabs((v-V0)/B)<1e-6) {
    :if(v==V0) {
        fun3 = A*B/1(mV) * (1- 0.5 * (v-V0)/B)
    } else {
        fun3 = A/1(mV)*(v-V0)/(exp((v-V0)/B)-1)
    }
}

FUNCTION min(x,y) { if (x<=y){ min = x }else{ min = y } }
FUNCTION max(x,y) { if (x>=y){ max = x }else{ max = y } }

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

Re: Accessing a variable from hoc that is not defined in NMO

Post by ted » Fri Feb 10, 2017 1:38 pm

pascal wrote:I am translating a hoc model (that I inherited) into Python
As punishment, or is there a sound reason for doing this? If the original hoc code works properly, it's usually best to just reuse the hoc model specification and write a bit of glue code that creates Python names that refer to whatever model properties are of interest.
The hoc code references the mod file
No it doesn't. It references names of variables and parameters that are presumed to exist as a consequence of compiling the mod file. There is no reference to the mod file itself--not that it matters for the question you ask.
gh_IhPyrKop is not defined within the mod file...and yet the hoc code still runs without error.
That's strange. And indeed
print gh_IhPyrKop
prints 0.1
But there's something special about this gh_IhPyrKop name, because executing this statement
gk_IhPyrKop = 0.1
produces an error message.

Suggest you comment out the hoc code's assignment statement
gh_IhPyrKop = 0.1
and see if that changes simulation results. If it doesn't, then just don't include that statement in your Python code.

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

Re: Accessing a variable from hoc that is not defined in NMO

Post by hines » Fri Feb 10, 2017 2:14 pm

problem is, gh_IhPyrKop is not defined within the mod file...and yet the hoc code still runs without error
That is proper program behavior. Just not meaningful from your point of view. That is, gh_IhPyrKop is justa new hoc scalar variable name that is created when the name appears on the left hand side of an assignment statement. It is NOT a previously existing RANGE variable associated with any variable that was declared in the IhPyrKop mechanism. I suspect the prefix should be gmax instead of gh because of the
declaration in the mod file of

Code: Select all

   RANGE v50, gmax
In your mod file, the default value for gmax is 0.0 and that is its value during the simulation. Replace

Code: Select all

gh_IhPyrKop     =   0.1
with

Code: Select all

gmax_IhPyrKop     =   0.1

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

Re: Accessing a variable from hoc that is not defined in NMO

Post by ted » Fri Feb 10, 2017 2:55 pm

Ah--the statement
gh_IhPyrKop = 0.1
was executed inside paired curly brackets, so the hoc interpreter didn't print its
"first instance of gh_IhPyrKop"
message, which would have revealed that gh_IhPyrKop really didn't belong to the IhPyrKop mechanism.

Now I have to go back through my tests to see how I went astray on what was happening.
I suspect the prefix should be gmax instead of gh
Maybe so, and maybe the original implementer meant to assign a nonzero value to gmax_IhPyrKop. But was this model used to generate published results? If yes, were those results generated with gmax_IhPyrKop left with its default value of 0? If so, the published results might be significantly different from what would have happened if this parameter were set to 0.1. That would present subsequent users of this model with the question of which value to use in their own work.

pascal
Posts: 62
Joined: Thu Apr 26, 2012 11:51 am

Re: Accessing a variable from hoc that is not defined in NMO

Post by pascal » Sat Feb 11, 2017 10:02 am

Oh I see, that explanation makes perfect sense. Thank you very much for the help. And yes, this model has been used to generate published results. I am currently going back and re-running with gmax_IhPyrKop = 0.1, and I will see whether this affects simulation results. Thank you both again for the help.

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

Re: Accessing a variable from hoc that is not defined in NMO

Post by ted » Sun Feb 12, 2017 3:56 pm

ModelDB has two entries that include NMODL source code for a mechanism called IhPyrKop:
https://senselab.med.yale.edu/ModelDB/S ... del=139421
https://senselab.med.yale.edu/ModelDB/S ... del=186768
The file is called ihpyrkop.mod

However searching the source code for these two model entries with
grep insert * | grep PyrKop
turns up no evidence that either model actually uses IhPyrKop, and there is no reference in hoc or Python to a variable called
gh_IhPyrKop
or
gmax_IhPyrKop

Sam Neymotin, coauthor of the two papers associated with these model archives, confirms that IhPyrKop isn't used in either of these models "or in any other models I know of."

So we don't have to be concerned about the value of gmax_IhPyrKop in either of those two models; the concern applies only to whatever was done with the source code that pascal inherited.

Post Reply