Dynamically accessing vectors in python (_ref_x)
Posted: Thu Jan 09, 2020 2:10 am
Pythonisti (!)
I am reworking a software bridge that we have created some 10 years ago that allows running code in Neuron being controlled by IGOR which has nice display and printing abilities. The actual bridge is coded in python3 - and has been working fine. However, even though it is in python, it actually mostly passes hoc commands. To future-proof this code base, I thought to have as much as possible in python.
One thing that I cannot get my head around is how to setup the Vectors that allow monitoring of variables during the simulation. Since we run several simulations with recoding sites mostly on the soma, but also on axon and dendrite, I need to have the python statements right - which I don't seem to have. Using the old hoc code, vectors for example for the somatic K conductance were set up like this (simply pythonised string handling):
h('objref soma_gk')
h('soma_gk = new Vector()')
h('soma_gk.record(&gk_kv(0.5)')
I want this to be in elegant python, instead. I know that I can create the respective vector at the soma as
soma_gk = h.Vector().record(soma(0.5)._ref_gk_kv)
The issue is that this statement should be dynamic as within the bridge a python function is called that returns the function name plus inArgs something along
setupVector(soma_gk soma 0.5 gk_kv) // note that we use spaces to separate the inArgs consisting of vector name, section, loc, and variable name
This is then internally taken apart and from the individual elements, I should be able to create a python statement that links the Vector with the variable. Now this needs to be dynamic as sometimes, the location may not be at the soma, but say axon[6] or dend[32], the segment location may be 0.5 or 1.0 (as it is distance dependent in µm) and the variables to watch are either v, gna_na, ina, ik, etc. I also appreciate that I can get the section name plus location again using h.Section(sec=soma) - but the casting around ._ref_x is not trivial.
I appreciate that somehow there is a way to use setpointer() together with some list handling - but I really don't quite get how to cast that statement correctly. No matter what I have tried, I have received run-time errors. I am sure that my inexperience with python may well explain this...
Any code snippet much appreciated.
I am reworking a software bridge that we have created some 10 years ago that allows running code in Neuron being controlled by IGOR which has nice display and printing abilities. The actual bridge is coded in python3 - and has been working fine. However, even though it is in python, it actually mostly passes hoc commands. To future-proof this code base, I thought to have as much as possible in python.
One thing that I cannot get my head around is how to setup the Vectors that allow monitoring of variables during the simulation. Since we run several simulations with recoding sites mostly on the soma, but also on axon and dendrite, I need to have the python statements right - which I don't seem to have. Using the old hoc code, vectors for example for the somatic K conductance were set up like this (simply pythonised string handling):
h('objref soma_gk')
h('soma_gk = new Vector()')
h('soma_gk.record(&gk_kv(0.5)')
I want this to be in elegant python, instead. I know that I can create the respective vector at the soma as
soma_gk = h.Vector().record(soma(0.5)._ref_gk_kv)
The issue is that this statement should be dynamic as within the bridge a python function is called that returns the function name plus inArgs something along
setupVector(soma_gk soma 0.5 gk_kv) // note that we use spaces to separate the inArgs consisting of vector name, section, loc, and variable name
This is then internally taken apart and from the individual elements, I should be able to create a python statement that links the Vector with the variable. Now this needs to be dynamic as sometimes, the location may not be at the soma, but say axon[6] or dend[32], the segment location may be 0.5 or 1.0 (as it is distance dependent in µm) and the variables to watch are either v, gna_na, ina, ik, etc. I also appreciate that I can get the section name plus location again using h.Section(sec=soma) - but the casting around ._ref_x is not trivial.
I appreciate that somehow there is a way to use setpointer() together with some list handling - but I really don't quite get how to cast that statement correctly. No matter what I have tried, I have received run-time errors. I am sure that my inexperience with python may well explain this...
Any code snippet much appreciated.