Mod file compiles in v6.2 but doesn't in v7.0

NMODL and the Channel Builder.
Post Reply
Nefeli
Posts: 12
Joined: Fri Jul 27, 2007 10:55 am

Mod file compiles in v6.2 but doesn't in v7.0

Post by Nefeli »

Hi,

I've noticed that the following mod file does not compile in v7.0 although it used to compile and run perfeclty fine in v6.2.

The only thing that seems to fix the problem is when any one of the non-constant terms of the following ODE in the DERIVATIVES block is deleted

V' = ( -gL*(V-VL) - gNa*minf(V)*minf(V)*minf(V)*h*(V-VNa) - gK*n*n*n*n*(V-VK)
- (gisynabar*(V-visyna)*gia + gisynbbar*(V-visynb)*gib + gesynsbar*(V-vesyns)*ges
+ gsynDGbar*(V-vDG)*gDG + gsynSNicbar*(V-vSNic)*gSNic + gsynSMusbar*(V-vSMus)*gSMus
+ gsynECbar*(V-vEC)*gEC + gsynSabar*(V-vSa)*gSa + gsynSbbar*(V-vSb)*gSb + Igap-I) )/Cm

For example deleting either
gK*n*n*n*n*(V-VK)
or
(gisynabar*(V-visyna)*gia
seems to make this mod file compile in v7.0

Any ideas why this is happening?

Code: Select all

TITLE Wang Buzsaki Model

NEURON { 
        
        POINT_PROCESS WBtest1
        RANGE 	I, gesyns, vesyns, gisyna, visyna, gisynb, visynb, TAUE, Iexc, Iinha, Iinhb, event, inh, exc, 
				nspike, Drive, iV, ih, in, gpre, gpost, INIC, IMUS, IEC, ISA, ISB, gsynEC, vEC,  
				 gsynSNic, vSNic, gsynSMus, vSMus, gsynSa ,vSa, gsynSb, vSb, EC,  SNic, SMus, Sa, Sb, 
				 Igap,IDG,gsynDG,vDG,DG, totinpE, IK, INA, nPG
        GLOBAL 	Cm, gL, gNa, gK, VNa, VK, VL, aib, aia, refrac, aSa, aSMus, aSNic
	    POINTER Vpre, Vpost
}

UNITS {
(uA)= (microamp)
(mV)= (millivolt)
(uF)= (microfarad)
(mS)= (millisiemens)
}



PARAMETER {
refrac=0
:APPLIED CURRENTS
I=0.1     (uA/cm2)

Cm=1  
Phi=5

:MAXIMAL CONDUCTANCES
gL=0.1         (mS/cm2) 
gNa=35         (mS/cm2)
gK=9           (mS/cm2)


:REVERSAL POTENTIALS
VL=-65        (mV)
VNa=55        (mV)
VK=-90        (mV)


:SYNAPTIC PARAMETERS-RECURRENT
gesyns=0.001    : 0.01 :1
vesyns=0
gisyna=0.001    : 0.01 :1
visyna=-80
gisynb=0.001    :0.01 :1
visynb=-80
TAUE=10:20

:use only aplha and single exp to normalize using /tau and a/exp(1)
aib=0.005 :0.02 :0.01          :0.05	same for gabab recurrent and septal
aia=0.2          
aSa=0.2                 
aSMus=0.05
aSNic=0.1	

:INPUT
gsynEC=0.001    :1
vEC=0
gsynDG=0.001    :1
vDG=0
gsynSNic=0.005  :1 SHOULD BE 5 TIMES MORE THAN PYR
vSNic=0
gsynSMus=0.001  :1
vSMus=0
gsynSa=0.001    :1
vSa=-80
gsynSb=0.001    :1 :0
vSb=-80
TAU=10

:Initial values
iV=-68
ih=0
in=0

:Gaps
gpre=0
gpost=0

}

ASSIGNED {

refractory 
event
inh 
exc
nspike
Drive
Vpre
Vpost

EC
DG
SNic
SMus
Sa
Sb

PG
nPG
}

STATE { V h n  gia sia sib gib ges Iexc Iinha Iinhb gisynabar gisynbbar gesynsbar  INIC IMUS INICd ISA ISB gEC gDG sSNic 
gSNic sSMus gSMus sSa gSa sSb gSb gsynDGbar gsynSNicbar gsynSMusbar gsynECbar gsynSabar gsynSbbar Igap IEC IDG 
totinpE IK INA 
} 

BREAKPOINT {
SOLVE states METHOD runge

Igap=gpre*(V-Vpre)+gpost*(V-Vpost)

gesynsbar=TAUE*gesyns
gisynbbar=gisynb/(aib/2.7182818)
gisynabar=gisyna/(aia/2.7182818)              

gsynDGbar=TAU*gsynDG
gsynECbar=TAU*gsynEC
gsynSNicbar=gsynSNic/(aSNic/2.7182818)        
gsynSMusbar=gsynSMus/(aSMus/2.7182818)        
gsynSabar=gsynSa/(aSa/2.7182818)              
gsynSbbar=gsynSb/(aib/2.7182818)

Iexc=gesynsbar*(V-vesyns)*ges 
Iinha=gisynabar*(V-visyna)*gia
Iinhb=gisynbbar*(V-visynb)*gib

IDG=gsynDGbar*(V-vDG)*gDG 
INIC=gsynSNicbar*(V-vSNic)*gSNic
IMUS=gsynSMusbar*(V-vSMus)*gSMus

IEC=gsynECbar*(V-vEC)*gEC 
ISA=gsynSabar*(V-vSa)*gSa
ISB=gsynSbbar*(V-vSb)*gSb

INA=gNa*minf(V)*minf(V)*minf(V)*h*(V-VNa) 
IK=gK*n*n*n*n*(V-VK)

totinpE=gesynsbar*ges + gsynSNicbar*gSNic + gsynSMusbar*gSMus + gsynDGbar*gDG+gsynECbar*gEC
}

INITIAL {
V=iV        :-68 :-60  -80     (mV)    
h=ih          :0
n=in          :0

gia=0
sia=0
gib=0
sib=0

ges=0

event=0
inh=0
exc=0
nspike=0

Iexc=0
Iinha=0
Iinhb=0

IDG=0
INIC=0
IMUS=0

IEC=0
INICd=0
ISA=0
ISB=0

gEC=0
gDG=0
sSNic=0
gSNic=0
sSMus=0
gSMus=0
sSa=0
gSa=0
sSb=0
gSb=0

EC=0
DG=0
SNic=0
SMus=0
Sa=0
Sb=0
Drive=0

IK=0
INA=0
Igap=0

PG=0
nPG=0
}


DERIVATIVE states {

:CELL
V' = ( -gL*(V-VL) - gNa*minf(V)*minf(V)*minf(V)*h*(V-VNa) - gK*n*n*n*n*(V-VK)
- (gisynabar*(V-visyna)*gia + gisynbbar*(V-visynb)*gib + gesynsbar*(V-vesyns)*ges 
+ gsynDGbar*(V-vDG)*gDG + gsynSNicbar*(V-vSNic)*gSNic + gsynSMusbar*(V-vSMus)*gSMus 
+ gsynECbar*(V-vEC)*gEC + gsynSabar*(V-vSa)*gSa + gsynSbbar*(V-vSb)*gSb + Igap-I) )/Cm


h'=Phi*((1-h)*ah(V)-h*bh(V))
n'=Phi*((1-n)*an(V)-n*bn(V))


:SYN
ges'=-ges/TAUE

sia'=-2*aia*sia - aia*aia*gia
gia'=sia

sib'=-2*aib*sib - aib*aib*gib
gib'=sib

:INPUT SYN
gEC'=-gEC/TAU
gDG'=-gDG/TAU

sSNic'=-2*aSNic*sSNic - aSNic*aSNic*gSNic
gSNic'=sSNic

sSMus'=-2*aSMus*sSMus - aSMus*aSMus*gSMus
gSMus'=sSMus

sSa'=-2*aSa*sSa - aSa*aSa*gSa
gSa'=sSa

sSb'=-2*aib*sSb - aib*aib*gSb
gSb'=sSb
}

FUNCTION minf(V (mV)) (/ms) {
LOCAL am, bm, Tm
UNITSOFF
am=0.1*(V+35) / ( 1-exp(-0.1*(V+35)))
bm=4*exp(-(V+60)/18)
minf=am/(am+bm)
UNITSON
}

FUNCTION ah(V (mV)) (/ms) {
UNITSOFF
ah=0.07*exp(-(V+58)/20)
UNITSON
}

FUNCTION bh(V (mV)) (/ms) {
UNITSOFF
bh= 1 / ( exp(-0.1*(V+28)) + 1 )
UNITSON
}

FUNCTION an(V (mV)) (/ms)  {
UNITSOFF
an=0.01*(V+34) / ( 1- exp(-0.1*(V+34)) )
UNITSON
}

FUNCTION bn(V (mV)) (/ms)  {
UNITSOFF
bn=0.125*exp(-(V+44)/80)
UNITSON
}

NET_RECEIVE (w) {

if (w==-1)        { sia=sia+aia*aia
                    inh=t
                    :printf("%g\t%g\t%g\t%g\t\n", t , w , Vs, inh)   
                  }

if (w==-2)        { sib=sib+aib*aib
                    inh=t
                  }

if (w==-11)       { gEC=gEC+1/TAU
                    EC=t
                  }

if (w==-12)       { gDG=gDG+1/TAU
                    DG=t  
                  }

if (w==-13)       { sSNic=sSNic+aSNic*aSNic
                    SNic=t   
                  }

if (w==-14)       { sSMus=sSMus+aSMus*aSMus
                    SMus=t
                  }

if (w==-15)       { sSa=sSa+aSa*aSa
                    Sa=t 
                  }

if (w==-16)       { sSb=sSb+aib*aib
                    Sb=t 
                  }
   
if (w==1)         { ges=ges+1/TAUE
                    exc=t
                  } 

if (w==17)        { event=t
                    net_event(t+refrac)
                    nspike = nspike + 1      
                  }
				 
}


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

Re: Mod file compiles in v6.2 but doesn't in v7.0

Post by ted »

I suspect there's a bug in 7.0's nrnivmodl. I find that it issues a segmentation error, but if I then run vi and exit vi without doing anything, I can then run nrnivmodl and it compiles your NMODL code successfully. Try the latest alpha version of NEURON and see if that doesn't work for you. It's likely to contain a fix for this problem, and, aside from miscellaneous bug fixes, most of the relatively "new" code in it will probably be related to Python or multithreaded execution.

A few suggestions:
1. runge is not the integrator to use with NEURON. Use cnexp.
SOLVE states METHOD cnexp
2. Most of the declared STATEs don't appear on the LHS of one of the ODEs in your BREAKPOINT block. So they're not really STATEs--they're merely assigned variables (i.e. calculated by simple algebra rather than numerical integration). I wonder if declaring them in the ASSIGNED block would reduce storage requirements or run time.
Nefeli
Posts: 12
Joined: Fri Jul 27, 2007 10:55 am

Re: Mod file compiles in v6.2 but doesn't in v7.0

Post by Nefeli »

Many thanks for the suggestions for optimising the code.

I'm afraid the segmentation fault comes out also with the alpha version.

May I ask what is "vi" that you used to succesfully compile it?
ted
Site Admin
Posts: 6384
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Mod file compiles in v6.2 but doesn't in v7.0

Post by ted »

vi is a program for editing text files. It is not a compiler. Discovering that nrnivmodl could compile the mod file after I started and exited vi was entirely accidental. The observation suggests that the state of some register or memory location, prior to launching nrnivmodl, determines the success or failure of compilation. This is not desirable program behavior and suggests there is a bug.
hines
Site Admin
Posts: 1710
Joined: Wed May 18, 2005 3:32 pm

Re: Mod file compiles in v6.2 but doesn't in v7.0

Post by hines »

There is a problem with functions in derivative equations. Work around with
DERIVATIVE states {
LOCAL minfv
minfv = minf(V)
and substitute for the minf(V) in the two places it is used.
Do NOT use METHOD cnexp
since the V' equation is not linear and involves states other than V. Some of the others
are in a form that would invalidate usage of cnexp as well. The
best method in this case is derivimplicit.

As for editing, not changing, and rerunning nrnivmodl successfully. This was an artifact of the first nrnivmodl leaving a 0 length .c file which
was more recent than the .mod file, thus defeating "make". I'll fix that but til then, when the nmodl translator fails one needs to manually
remove the .c file. Typically, one fixes the problem in the mod file though which makes it more recent than the .c file.
Nefeli
Posts: 12
Joined: Fri Jul 27, 2007 10:55 am

Re: Mod file compiles in v6.2 but doesn't in v7.0

Post by Nefeli »

Many thanks for that, with the new definition of minf there is no problem with the compiling anymore.

Also thanks for the clarification regarding the METHODS.
Post Reply