mechanisms written in python?

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
alexandrapierri
Posts: 41
Joined: Wed Jun 17, 2015 5:31 pm

mechanisms written in python?

Post by alexandrapierri »

Dear NEURON/Python community

Why is it that the synapse mechanisms or ion channels are traditionally written in NMODL (mod files) when the majority of the code is in python, and can I write those mechanisms as python classes? Any template examples where this is done?

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

Re: mechanisms written in python?

Post by ted »

Python is slow. NMODL code is compiled to produce binary libraries which execute orders of magnitude faster. Read
Hines, M.L. and Carnevale, N.T. Expanding NEURON's Repertoire of Mechanisms with NMODL. Neural Computation 12:995-1007, 2000.
or, better, download and read the "expanded preprint" https://neuron.yale.edu/neuron/static/p ... odl400.pdf
alexandrapierri
Posts: 41
Joined: Wed Jun 17, 2015 5:31 pm

Re: mechanisms written in python?

Post by alexandrapierri »

thank you Ted

is it in principle possible to have a network where some of my mechanisms are given as mod files while others are written in python?
One problem I encountered doing this is with the definition of my integration step. h.dt=0.5 (for my hoc code) but I also have derivatives to integrate in python where I need to define a dt=0.5. How can my code know that h.dt (for the mod files) and dt (for the python files) are the same?

I chose to write my GABA mechanisms in python because my postsynaptic GABA current depends on postsynaptic cell calcium concentration.
Any examples where a mod file variable depends on the variable of another mod file, and can I get away with using this mix scheme (python and mod) for my mechanisms, or do I have to convert everything to NMODL?

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

Re: mechanisms written in python?

Post by ted »

is it in principle possible to have a network where some of my mechanisms are given as mod files while others are written in python?
In principle, with software all things are possible. Do everything with Python. Or with C or C++. Or assembly language. Then you'll have complete liberty to do anything you want. If instead you want to work within the framework of a particular simulation environment, you have to work within what that environment enables and allows. Fortunately, NEURON enables and allows a lot, if you know how to take full advantage of it.
I chose to write my GABA mechanisms in python because my postsynaptic GABA current depends on postsynaptic cell calcium concentration.
This is quite doable with NMODL. There are plenty of NEURON models that involve calcium-gated potassium channels. Here's one:
modeldb.yale.edu/3509
Look at cagk.mod to see how it implements the effect of calcium on potassium conductance. If your conceptual model of calcium effect on synaptic conductance is different, e.g. instead of affecting the kinetics of channel gating it has an immediate direct effect on the conductance of calcium channels, you might express the current as
i = gkbar * f(cai) * o
where o is the fraction of channels that are open and f(cai) is a function whose value ranges from 0 to 1.
alexandrapierri
Posts: 41
Joined: Wed Jun 17, 2015 5:31 pm

Re: mechanisms written in python?

Post by alexandrapierri »

thanks, Ted

in the link you sent there is only one mod file and the calcium dynamics seem to be implemented within that one mod file.
Is there any example where a mod file reads a variable from another mod file? For example, I want my GABA current equations (GABA.mod) to take into consideration AG synthesis which is defined in the calcium generation dynamics (cal.mod).

I am not sure what would be the right syntax to import a variable from cal.mod to GABA.mod.

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

Re: mechanisms written in python?

Post by ted »

AG synthesis? arachidonoylglycerol? The best way to do this depends on the details of your conceptual model for what's going on. Presumably you have already expressed your conceptual model in the form of a reaction scheme or mathematical equations. My question at this point is: what aspects of your model should be implemented with NMODL and what aspects might be more easily implemented with NEURON's rxd (reaction-diffusion) module. To give you the best advice for how to do this in a way that is computationally efficient and easy to implement, maintain, and use, I will need to know more about what you have in mind. Perhaps it would be best to continue this discussion via email, which makes exchange of files etc. more convenient. You can contact me at carnevalet@protonmail.com.
Post Reply