Using external file to set parameter value in MOD file

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

Moderator: hines

Post Reply
Robert Claar
Posts: 23
Joined: Tue Jun 23, 2020 8:52 am

Using external file to set parameter value in MOD file

Post by Robert Claar »

Hello there,

I am creating a multicell model of pancreatic islet cells using NEURON+Python. In this model there are 4 parameters for ATP sensitive potassium channel conductances (gKATP) whose values are changed to model changes in glucose levels throughout the islet. Ideally what we would like to do is generate waveforms for glucose modulation (e.g., square waves, or square waves with smooth transitions in between) and then be able to pass that time-series glucose data into the mod files containing our gKATP variables so we can express them as functions of glucose and we can alter the glucose levels throughout our simulations. This could also be accomplished if it is possible to generate these waveforms inside the MOD files themselves.

We currently have it setup to where we specify in a configuration file when we would like to change glucose and to what level we would like to change it, we are using a fixed time-step so we "stop" the simulation at the timepoint where we want to change glucose, change the gKATP parameters (they are set as RANGE variables so we can overwrite their value using python), use fcurrent() to re-initialize the model, and then continue running it, but this seems clunky and I assume that there is a more "NEURON-native" or "NMODL-native" way to do this.

Thanks in advance for any help with this!
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Using external file to set parameter value in MOD file

Post by ted »

Interesting research project. And an interesting modeling problem. The latter has several possible solutions, only a few of which involve tinkering with NMODL. Python is bad enough, but at least it is easier to master than NMODL.

The modeling problem is actually a particular instance of "how to implement an experimental protocol in a computational model." One way to do this is with segmented simulations, as you are already doing. The best practice for implementing segmented simulations is with events; you're already doing this if your code uses cvode.event and FInitializeHandler. If you're not using cvode.event and FInitializeHandler, let me know and I'll cook up a quick example. The advantages of this approach are (1) clarity (it's very easy to write, understand, and maintain the necessary code), (2) elimination of the need to write your own simulation flow control code (which can become quite clunky), and (3) the resulting code is compatible with NEURON's adaptive integrators.

Another way to force parameter changes in the course of a simulation is with Vector.play. This allows you to force a variable to follow an arbitrary waveform. Vector.play with interpolation is particularly flexible because it enables relatively smooth emulation of waveforms sampled at regular intervals, and very compact representations of piecewise continuous functions (basically you need a t, value pair for every point at which slope changes). Easy to read, easy to write, and works well with adaptive integration. You'll find very pythonic examples in the Programmer's Reference https://nrn.readthedocs.io/en/8.2.2/pyt ... ector.play but it's even doable by those who eschew Python's temptation to be recondite.
a multicell model of pancreatic islet cells
If all cells are exposed to the same concentration of e.g. glucose, and you're simulating many cells at the same time, be sure to declare glucose concentration GLOBAL in the NEURON block of whatever mod file needs it, and then you will only have to use Vector.play to drive the glucose parameter that belongs to one instance of that particular mechanism in one model cell--and all the other model cells will "see" the same glucose concentration.
Robert Claar
Posts: 23
Joined: Tue Jun 23, 2020 8:52 am

Re: Using external file to set parameter value in MOD file

Post by Robert Claar »

Thank you for the response! I am not currently using cvode.event and FInitializeHandler, but I have the documentation flagged to look into it. If you could provide an example that would be great.

In the meantime I will look into Vector.play and all cells will be exposed to the same concentration of glucose so I will make sure to declare the glucose concentration as a global variable. That is a detail I would have likely missed so thanks for suggesting it. Many times while working on this project I have come close to "re-inventing the wheel" (i.e., creating tools in python that NEURON already has) so I am trying to avoid that as much as possible.

A related problem is that we would like to save the last timepoint values of our parameters for a previous simulation and then use those values to initialize a future simulation. This would enable us to, say, simulate an islet for a certain amount of time until is reaches a certain state, and then subject that islet to different experimental conditions and know that all the resulting islets under the different experimental conditions started in more or less the same state. Currently we are using frecord_init to get the last timepoint values and then we are writing those values to a file that we then try to read in to initialize our simulations, but when we compare the last timepoint values we are using for initialization to the starting values of the subsequent simulations, the results are meaningfully different. This is what made me start looking into FInitializeHandler. I know some of it is likely due to the stochastic nature of floating point numbers, etc., but I was also wondering if there was a NEURON-native way to do this. I have looked into SaveState but could not get a simple, workable example working. Any help with that would be appreciated. If it is too unrelated and would fit better in another post, let me know and I can do that.
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Using external file to set parameter value in MOD file

Post by ted »

we would like to save the last timepoint values of our parameters for a previous simulation and then use those values to initialize a future simulation.
For that you will want to use the SaveState class. This is documented in the programmers' reference--see https://nrn.readthedocs.io/en/8.2.2/pyt ... #savestate

If you run into problems with that, please open a new discussion thread.
Post Reply