BhallaLab / moose-core

C++ basecode and python scripting interface
https://moose.ncbs.res.in
GNU General Public License v3.0
15 stars 26 forks source link

isinstance for neutral object returning false #402

Open dilawar opened 4 years ago

dilawar commented 4 years ago

Script is attached. Reported by @hrani over email

n = moose.Neutral('/r') 
print isinstance(n,Neutral) 

moose-core commit "ec9e209b" when I am checking a Neutral object's isinstance it print out 'True' (ofcourse if its Neutral object)

But

moose-core commit "9489b" it print out 'False'

Also

when I query moose.le('/'), I am not sure if this is change from moose to _moose.moose but do check.

Let me know if I am doing any wrong

File "../test.py", line 14, in print moose.le('/r') AttributeError: 'module' object has no attribute 'le'

Sample code is attached

test.py.txt

dilawar commented 4 years ago

This is being caused because you've mixed moose and _moose togther using this line.

import moose._moose as moose                                                    
from moose import wildcardFind,element,PoolBase,CplxEnzBase,ReacBase,EnzBase,Annotator,exists,Neutral,ConcChan,le

Note that moose.Neutral is really _moose.Neutral and you are testing it against Neutral which is from moose.py and wrapper.py (and not from _moose.so). If you really must do it this way then I need to refactor the code.

Ideally the user should just import moose. This script works:

import moose

n = moose.Neutral('/r')
c = moose.CubeMesh('/r/dend')
p = moose.Pool('/r/dend/Tiam1')
r = moose.Reac('/r/dend/CaM_GEF3_Reac')

grp = moose.Neutral('/r/dend/Ras_gr')
par = moose.Pool('/r/dend/Ras_gr/CaM_GEF')
e = moose.Enz('/r/dend/Ras_gr/CaM_GEF/CaM_GEF_RAC_GDP_GTP_enz')
print(n.className)
#print moose.le('/r')

print("##########")
print(isinstance(n, moose.Neutral))
print(isinstance(p, moose.PoolBase))
print(isinstance(r, moose.ReacBase))
print(isinstance(e, moose.EnzBase))

Another way of handling it:

import moose
import moose._moose as _moose

n = _moose.Neutral('/r')
c = _moose.CubeMesh('/r/dend')
p = _moose.Pool('/r/dend/Tiam1')
r = _moose.Reac('/r/dend/CaM_GEF3_Reac')

grp = _moose.Neutral('/r/dend/Ras_gr')
par = _moose.Pool('/r/dend/Ras_gr/CaM_GEF')
e = _moose.Enz('/r/dend/Ras_gr/CaM_GEF/CaM_GEF_RAC_GDP_GTP_enz')
print(n.className)
#print moose.le('/r')

print("##########")
print(isinstance(n, _moose.Neutral))
print(isinstance(p, _moose.PoolBase))
print(isinstance(r, _moose.ReacBase))
print(isinstance(e, _moose.EnzBase))
dilawar commented 4 years ago

Reopening this issue. The new test script received from @hrani is attached.

test.py.txt

dilawar commented 4 years ago

Thanks @hrani for the scripts. It was really helpful. I could reproduce it and it is a bug. The patch will be in a PR shortly with technical details.