Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'Grid' object has no attribute 'grid' #59

Closed
StefanGIT opened this issue Jan 23, 2019 · 6 comments · Fixed by #67
Closed

AttributeError: 'Grid' object has no attribute 'grid' #59

StefanGIT opened this issue Jan 23, 2019 · 6 comments · Fixed by #67

Comments

@StefanGIT
Copy link

StefanGIT commented Jan 23, 2019

Hi ,
while trying to multiply two grids, i get the following error:

  File "multipipsa/multipipsa.py", line 501, in runApbs
    visualizeGrid = potentialGrid * accesibilityGrid
  File "/exports/scratch/ana3/envs/mypipsa/lib/python2.7/site-packages/gridData/core.py", line 539, in __mul__
    return Grid(self.grid * _grid(other), edges=self.edges)
AttributeError: 'Grid' object has no attribute 'grid'

The relevant code lines are:

            potentialGrid = Grid(self.__data_dir+"/"+i+".dx")
            accesibilityGrid =Grid(self.__data_dir+"/"+i+".surf.dx")
            print(potentialGrid)
            print(accesibilityGrid)
            visualizeGrid = potentialGrid * accesibilityGrid

The error happens in the multiply?

@StefanGIT
Copy link
Author

StefanGIT commented Jan 23, 2019

If i do the following:

            potentialGrid = Grid()
            potentialGrid.load(self.__data_dir+"/"+i+".dx")
            accesibilityGrid =Grid()
            accesibilityGrid.load(self.__data_dir+"/"+i+"_surf.dx")
            visualizeGrid = accesibilityGrid * potentialGrid

it works. Is there an issue with the Grid(filename) constructor?

@richardjgowers
Copy link
Member

Hey @StefanGIT this line should make loading with a filename equivalent to your two step approach, but I think it's not working.

If you do potentialGrid = Grid(str(self.__data_dir+"/"+i+".dx")) does it make a difference?

@StefanGIT
Copy link
Author

Thanks, the str(...) works as well!

@richardjgowers
Copy link
Member

@StefanGIT what is your self.__data_dir object in this case? A pathlib object?

@StefanGIT
Copy link
Author

might be:
cwd=os.getcwd()
apbs = ApbsRun(dataDir=cwd+"/example/pdbs",
temp=298.15,ios=0.100, structures=ingrp+outgrp)

@orbeckst
Copy link
Member

orbeckst commented Apr 8, 2019

The whole input autodetection code

if type(grid) is str:
self.load(grid)
elif not (grid is None or edges is None):
# set up from histogramdd-type data
self.grid = numpy.asanyarray(grid)
self.edges = edges
self._update()
elif not (grid is None or origin is None or delta is None):
# setup from generic data
origin = numpy.asanyarray(origin)
delta = numpy.asanyarray(delta)
if len(origin) != grid.ndim:
raise TypeError(
"Dimension of origin is not the same as grid dimension.")
if delta.shape == () and numpy.isreal(delta):
delta = numpy.ones(grid.ndim) * delta
elif delta.ndim > 1:
raise NotImplementedError(
"Non-rectangular grids are not supported.")
elif len(delta) != grid.ndim:
raise TypeError("delta should be scalar or array-like of"
"len(grid.ndim)")
# note that origin is CENTER so edges must be shifted by -0.5*delta
self.edges = [origin[dim] +
(numpy.arange(m + 1) - 0.5) * delta[dim]
for dim, m in enumerate(grid.shape)]
self.grid = numpy.asanyarray(grid)
self._update()
else:
# empty, must manually populate with load()
# print "Setting up empty grid object. Use Grid.load(filename)."
pass
is pretty fragile and could do with a rework. At a minimum, we should not pass silently...

orbeckst added a commit that referenced this issue May 15, 2019
- use try/except to load anything vaguely file like
  (now seems to work with path objects)
- raise ValueError if incorrect combination of input data supplied
- added tests
- fixed bug reading pickle files with suffix .pkl
- close #59
- update CHANGELOG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants