xpanel between python and hoc
Posted: Wed Jan 24, 2018 12:34 pm
I made an xpanel for my model so that I can demo it for my collaborators. I found the translation between Python and hoc not so smooth though so I wanted to see if I was missing something.
It seemed like all I would need to do is use "h.xvalue" to update constants, and then have my own initialization procedure so that the model would be reset before each run, using the updated parameters. Each of these (updating parameters, and running my own initialization) work on their own but there is some disconnect where my model is not correctly updating.
I wrote “myinit()” in Python and implement it using
Getting an xpanel up is also no problem. I follow the syntax shown here: https://www.neuron.yale.edu/neuron/stat ... tml#xvalue
As a detail, I have done this as a Python class when using action procedures in Python, and otherwise not as a class.
I include a print statement within “myinit” so I can see that a given value is at least updated in Python after changing it within my xpanel. If I print that value directly in terminal though, it is clear that it is not actually updated - I believe this means that it is not updated in hoc.
Here is an example:
For an IClamp in the soma, I have a parameter called "somastim_amp" which defines the hoc "IClamp.amp" parameter. If I increase "somastim_amp" from 0 to 1 nA using the xpanel, and print "somastim_amp" in terminal, it will indeed report a value of 1 nA (this is a Python variable). Within "myinit()", the update implementation looks like:
The print statement yields the same value for both. However, if I print "somastim_amp" and "stimIC.amp" in terminal directly, I get "somastim_amp = 1" and "stimIC.amp = 0", and it is clear from my voltage traces that the soma stimulus was not updated from 0 nA to 1 nA in the run.
I also tried using action procedures in Python in the manner indicated in the same above link. This ran fine but still didn't solve the problem.
What ultimately worked was to write hoc procedures for the update action procedures instead of in Python. So, following the same example, I have a short hoc procedure that reads:
and I have a similar procedure for every parameter, loaded in before I initialize and run the model. So I'm essentially running python code in hoc to make the updates go through.
This is a very longwinded post to just ask if there is a simpler, less clunky way to do this than what I am already doing. Am I just missing a step that ensures my "myinit" procedure gets run through hoc too? Thanks!
It seemed like all I would need to do is use "h.xvalue" to update constants, and then have my own initialization procedure so that the model would be reset before each run, using the updated parameters. Each of these (updating parameters, and running my own initialization) work on their own but there is some disconnect where my model is not correctly updating.
I wrote “myinit()” in Python and implement it using
Code: Select all
initnew = h.FInitializeHandler(0,myinit)
As a detail, I have done this as a Python class when using action procedures in Python, and otherwise not as a class.
I include a print statement within “myinit” so I can see that a given value is at least updated in Python after changing it within my xpanel. If I print that value directly in terminal though, it is clear that it is not actually updated - I believe this means that it is not updated in hoc.
Here is an example:
For an IClamp in the soma, I have a parameter called "somastim_amp" which defines the hoc "IClamp.amp" parameter. If I increase "somastim_amp" from 0 to 1 nA using the xpanel, and print "somastim_amp" in terminal, it will indeed report a value of 1 nA (this is a Python variable). Within "myinit()", the update implementation looks like:
Code: Select all
stimIC = h.IClamp(.5, sec = soma)
stimIC.amp = somastim_amp
print "stimIC.amp = “, stimIC.amp, " and somastim_amp = “, somastim_amp
I also tried using action procedures in Python in the manner indicated in the same above link. This ran fine but still didn't solve the problem.
What ultimately worked was to write hoc procedures for the update action procedures instead of in Python. So, following the same example, I have a short hoc procedure that reads:
Code: Select all
proc update_stim_amp() {
nrnpython("stimIC.amp = somastim_amp")
}
This is a very longwinded post to just ask if there is a simpler, less clunky way to do this than what I am already doing. Am I just missing a step that ensures my "myinit" procedure gets run through hoc too? Thanks!