Import or conversion of ChannelML(NeuronML-1.8) for NEURON

NMODL and the Channel Builder.
Post Reply
dilawar
Posts: 13
Joined: Mon May 26, 2014 9:12 am
Location: NCBS Bangalore

Import or conversion of ChannelML(NeuronML-1.8) for NEURON

Post by dilawar » Tue Apr 28, 2015 9:02 am

A few channel-mechanism I have are in channelML format. Is there a way to directly import them into NEURON (version 7.4)? Or any program which can convert these XML file to NEURON format?

PS: There is one here: http://www.neuroml.org/neuron_tools , but it doesn't seem to work. Header generated by this script causing synatx-error in NEURON.

Code: Select all

?  This is a NEURON mod file generated from a ChannelML file

?  Unit system of original ChannelML file: Physiological Units

COMMENT
    ChannelML file containing a single Channel description
ENDCOMMENT

TITLE Channel: kdr

COMMENT
    Delayed rectifier K channel. Comment from original mod: K-DR channel, from Klee Ficker and Heinemann,
        modified to account for Dax et al., M.Migliore 1997
ENDCOMMENT


UNITS {
    (mA) = (milliamp)
    (mV) = (millivolt)
    (S) = (siemens)
    (um) = (micrometer)
    (molar) = (1/liter)
    (mM) = (millimolar)
    (l) = (liter)
}


    
NEURON {

    SUFFIX kdr
    USEION k READ ek WRITE ik VALENCE 1  ? reversal potential of ion is read, outgoing current is written
           
        
    RANGE gmax, gion
    
    RANGE ninf, ntau
    
}

PARAMETER { 

    gmax = 0.01 (S/cm2)  ? default value, should be overwritten when conductance placed on cell
    
}



ASSIGNED {

    v (mV)
    
    celsius (degC)
    
    ? Reversal potential of k
    ek (mV)
    ? The outward flow of ion: k calculated by rate equations...
    ik (mA/cm2)
    
    
    gion (S/cm2)
    ninf
    ntau (ms)
    
}

BREAKPOINT { 
                        
    SOLVE states METHOD cnexp
        
    gion = gmax * ((1*n)^1)
    ik = gion*(v - ek)
            

}



INITIAL {
    
    ek = -90
        
    rates(v)
    n = ninf
        
    
}
    
STATE {
    n
    
}



DERIVATIVE states {
    rates(v)
    n' = (ninf - n)/ntau
            

}

PROCEDURE rates(v(mV)) {  
    
    ? Note: not all of these may be used, depending on the form of rate equations
    LOCAL  alpha, beta, tau, inf, gamma, zeta, temp_adj_n
    
    TABLE ninf, ntau DEPEND celsius FROM -100 TO 100 WITH 2000
    
    UNITSOFF
    temp_adj_n = 1
    
        
    ?      ***  Adding rate equations for gate: n  ***
         
    ? Found a generic form of the rate equation for alpha, using expression: (exp ( (1e-3 * -3 * (v - 13) * 9.648e4) / (8.315*(273.16 + (celsius) )) ))
    alpha = (exp ( (1e-3 * -3 * (v - 13) * 9.648e4) / (8.315*(273.16 + (celsius) )) ))
        
     
    ? Found a generic form of the rate equation for beta, using expression: (exp ( (1e-3 * -3 * 0.7 * (v - 13) * 9.648e4) / (8.315*(273.16 + (celsius) ))) )
    beta = (exp ( (1e-3 * -3 * 0.7 * (v - 13) * 9.648e4) / (8.315*(273.16 + (celsius) ))) )
        
     
    ? Found a generic form of the rate equation for tau, using expression: beta/(0.02 * (1 + alpha)) < 2 ? 2 : beta/(0.02 * (1 + alpha)) 
    
    
    if (beta/(0.02 * (1 + alpha)) < 2 ) {
        tau =  2 
    } else {
        tau =  beta/(0.02 * (1 + alpha)) 
    }
    ntau = tau/temp_adj_n
     
    ? Found a generic form of the rate equation for inf, using expression: 1/(1 + alpha)
    inf = 1/(1 + alpha)
        
    ninf = inf
    


    ?     *** Finished rate equations for gate: n ***
    

    
}


UNITSON

Code: Select all

nrngui -nogui  kad.mod 
NEURON -- VERSION 7.4 (1316:353c7c3ecd8d) 2015-04-03
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2015
See http://www.neuron.yale.edu/neuron/credits

/usr/local/nrn/x86_64/bin/nrniv: syntax error
 in kad.mod near line 2
 ?  This is a NEURON mod file generated from a ChannelML file
 ^
oc>
best,
Dilawar

ramcdougal
Posts: 96
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Medicine

Re: Import or conversion of ChannelML(NeuronML-1.8) for NEUR

Post by ramcdougal » Tue Apr 28, 2015 9:32 am

The basic sequence is:
  • start with a ChannelML model
  • run the converter script to generate an NMODL mechanism
  • compile the mechanism with: nrnivmodl
  • launch NEURON
  • insert the mechanism into a NEURON model
You're missing the third step.

When you launch NEURON after compiling the mechanism, you should see a message about loading membrane mechanisms. On my machine, it's:

Code: Select all

NEURON -- VERSION 7.4 (1322+:7286a7c1c3ab+) 2015-04-23
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2015
See http://www.neuron.yale.edu/neuron/credits

loading membrane mechanisms from /home/ramcdougal/channelml/x86_64/.libs/libnrnmech.so
Additional mechanisms from files
 kdr.mod

With your particular example, the mechanism is named kdr (this comes from the SUFFIX line of the NMODL, not the filename), so to insert that in the soma of a model (step 5) use:

For HOC:

Code: Select all

soma {insert kdr}
For Python:

Code: Select all

soma.insert('kdr')

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

Re: Import or conversion of ChannelML(NeuronML-1.8) for NEUR

Post by ted » Tue Apr 28, 2015 11:38 am

As ramcdougal points out, after you compile the mod files in a directory, if you then start NEURON in that directory, NEURON will automatically discover the compiled mechanisms and load them even before it tries to read whatever hoc or python file you named on the command line. If you tell NEURON to try to read an NMODL file, as this statement does
nrngui -nogui kad.mod
then NEURON will try to interpret it as a hoc file and will gag on the first statement it encounters that violates hoc syntax. And that's why the error message that you got was a "syntax error" message:

Code: Select all

/usr/local/nrn/x86_64/bin/nrniv: syntax error
in kad.mod near line 2
?  This is a NEURON mod file generated from a ChannelML file
Now a comment about translating code from ChannelML to NMODL. I see that this particular NMODL file contains a
USEION k READ ek . . .
statement, and that the INITIAL block contains the statement
ek = -90
What do you expect the potassium equilibrium potential will be?

To find out, insert this statement
printf("t %f ek %f\n", t, ek)
into the INITIAL and BREAKPOINT blocks of kad.mod, and recompile it. Then make a very simple single compartment model

Code: Select all

create soma
insert kdr
and then initialize your model and see what happens to ek

Code: Select all

oc>finitialize()
t 0.000000  ek -90.000000
t 0.000000  ek -77.000000
t 0.000000  ek -77.000000
Surprise! finitialize() first sets ek to -90 mV but then changes it back to -77 mV! That's because the value of ek comes from hoc, not from this mod file. If there is no mechanism that WRITEs ek, then ek is treated as a constant parameter, and the default value of ek is -77 mV in NEURON (same as in squid axon).

If you want to force ek in a section to have some other value, that section must either have a mechanism that WRITEs ek, or else you have to use a hoc statement to assign the value you want. Example:

Code: Select all

create soma, dend
forall insert kdr
finitialize()
forall print secname(), " ", ek // prints -77
soma ek = -90
finitialize()
forall print secname(), " ", ek // prints soma -90, dend -77
forall ek = -55
finitialize()
forall print secname(), " ", ek // prints soma -55, dend -55
This story has two morals:
1. Never trust that code will do what it seems to claim to do. Always test it to verify that you know what it does.
2. Never put your entire faith into "code translation" tools that claim to ensure "interoperability" between simulation environments. If the ChannelML-specified kdr mechanism was used in a model that needed ek to be -90 mV, and you tried to port that model to NEURON, you'd discover that the model wasn't working properly, and it might be quite a while before you found out that the reason was because ek wasn't correct.

dilawar
Posts: 13
Joined: Mon May 26, 2014 9:12 am
Location: NCBS Bangalore

Re: Import or conversion of ChannelML(NeuronML-1.8) for NEUR

Post by dilawar » Thu Apr 30, 2015 2:51 pm

Thank you ramcdougal and ted. After compiling mechanism and loading them into nrnpython using `nrn_load_dll``, I managed to insert these mechanisms.

Unfortunately I have to code platform specific path e.g. `nrn_load_dll('./i686/.lib/xxx')` or `nrn_load_dll('x86_64/.lib/xxx'). Is there a more portable way to code this in nrnpython.

best,
Dilawar

ramcdougal
Posts: 96
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Medicine

Re: Import or conversion of ChannelML(NeuronML-1.8) for NEUR

Post by ramcdougal » Thu Apr 30, 2015 3:13 pm

Did you try running without the nrn_load_dll?

If you import neuron from a script in the folder with x86_64, i686, or whatever it should automatically find and load the compiled mechanisms. If that doesn't just work, can you tell us what platform you're running on?

dilawar
Posts: 13
Joined: Mon May 26, 2014 9:12 am
Location: NCBS Bangalore

Re: Import or conversion of ChannelML(NeuronML-1.8) for NEUR

Post by dilawar » Fri May 01, 2015 1:34 am

Yes. It loads them without loading the .so file. I was using a snippet from some thread on the forum without reading the context carefully.

Thanks for all your help. I really appreciate quick response I get on this forum.

- D

Post Reply