Finding available variables in each section

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

Moderator: hines

Post Reply
uri.cohen
Posts: 24
Joined: Wed Jul 20, 2011 9:14 am

Finding available variables in each section

Post by uri.cohen » Tue Dec 27, 2011 4:30 pm

I'm loading an existing hoc file into python and would like to list the available state variables in each compartment. For example, the soma has a variable 'v' in each location (available through h.soma(0.5).v). Is there a programmatic way to do so?
Thanks!

figoyouwei
Posts: 41
Joined: Sun Aug 08, 2010 11:09 am

Re: Finding available variables in each section

Post by figoyouwei » Thu Dec 29, 2011 10:43 pm

Hi Hines :

I have the same question ! Although it has been asked by another post by mattioni, which the indirect way is "loop and check" whether a variable exists, but ...

Is there any direct way, like <$ dir(soma)> function which automatically lists all the range variables accessible from a Section or a Segment ?

ideally, it shall be
when you call <$ dir(soma)>, it lists : .v .ek .ena
when you call <$ dir(soma(0.5))>, it lists : .v .gk .gna

Thanks !

hines
Site Admin
Posts: 1577
Joined: Wed May 18, 2005 3:32 pm

Re: Finding available variables in each section

Post by hines » Fri Dec 30, 2011 3:54 pm

you can try:

for sec in h.allsec():
for seg in sec:
for mech in seg:
for n in dir(mech):
if n.endswith(mech.name()):
print sec, seg, mech, n

hines
Site Admin
Posts: 1577
Joined: Wed May 18, 2005 3:32 pm

Re: Finding available variables in each section

Post by hines » Fri Dec 30, 2011 3:55 pm

looks like I need to show it in code since all the indentation was removed above

Code: Select all

for sec in h.allsec():  
  for seg in sec:    
    for mech in seg:    
      for n in dir(mech):
        if n.endswith(mech.name()):
          print sec, seg, mech, n 

figoyouwei
Posts: 41
Joined: Sun Aug 08, 2010 11:09 am

Re: Finding available variables in each section

Post by figoyouwei » Fri Jan 13, 2012 11:42 am

Thanks Hines ! The 'n' print is what I want :-)

Post Reply