Error recording channel current by passing string to Vector.record

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

Moderator: hines

Post Reply
Darshan
Posts: 38
Joined: Tue Jul 02, 2013 5:11 am

Error recording channel current by passing string to Vector.record

Post 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
ted
Site Admin
Posts: 5795
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

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

Post 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.
Darshan
Posts: 38
Joined: Tue Jul 02, 2013 5:11 am

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

Post by Darshan »

Thank you, Ted!
ramcdougal
Posts: 214
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

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

Post 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.
Post Reply