Page 1 of 1

Error recording channel current by passing string to Vector.record

Posted: Sat Jun 20, 2020 1:42 am
by Darshan
Hi,

I am trying to plot voltage clamp currents of multiple channels for different mod files. For this I use Vector.record(). As there as multiple channels, I am passing a string to Vector.record(). As a test case, I tried it with hh channels. 'hh2' is same as hh with ik made a RANGE variable.

Code: Select all

channelname='hh2'
ionname='k'
strname = 'soma(0.5)._ref_'+'i'+ionname+'_'+channelname
strname is a string:

Code: Select all

'soma(0.5)._ref_ik_hh2'
When I use to record I get this error:

Code: Select all

NEURON: interpreter stack type error
 near line 0
 ^
        Vector[21].record("soma(0.5)....")

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-12-21c21e1f2cbf> in <module>
     17     t_vec.record(h._ref_t)
     18     ik_vec = h.Vector()
---> 19     ik_vec.record(strname)
     20 
     21     h.run()

RuntimeError: hoc error
But when I use ik_vec.record(soma(0.5)._ref_ik_hh2), the code works. Do I have to convert strname to pointer using h.Pointer() or make pointer e.g. using p = h.Pointer(soma(0.5).ik_hh2) ?

Thanks,
Darshan

Re: Error recording channel current by passing string to Vector.record

Posted: Mon Jun 22, 2020 11:54 pm
by ted
The problem is that Vector.record doesn't accept a string as its argument--it wants something that the parser recognizes to be a recordable variable.
If you are determined to continue on this path, as an experiment you might see if
Vector.record(eval(somestring))
succeeds; if it doesn't, you could try using Python statements to construct the entire command string, starting with Vector and ending with )), then exec that string.

But that seems too clever by half. Why write multiple lines of code and fiddle around to get it to work, when you already know how to write a single line pf Python that works and is understood by all who view it.

Re: Error recording channel current by passing string to Vector.record

Posted: Sun Jun 28, 2020 2:05 pm
by Darshan
Thank you, Ted!

Re: Error recording channel current by passing string to Vector.record

Posted: Mon Jun 29, 2020 12:38 pm
by ramcdougal
Python provides a standard way of using a string to grab a property, namely the getattr function.

e.g. if you have a section called soma and you wanted to get a pointer to a specific variable var from the 0.5 location, you could do

Code: Select all

ptr = getattr(soma(0.5).hh, f'_ref_{var}')
Similarly, a second getattr could be used if the "hh" mechanism was to be selected based on a variable.