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

Grids are not centered when dimension is not divisible by resolution #57

Open
mattragoza opened this issue May 27, 2021 · 0 comments
Open
Labels
bug Something isn't working

Comments

@mattragoza
Copy link

mattragoza commented May 27, 2021

The centering of grids appears to depend on the dimension argument- the output grids are only centered at the provided center if dimension is divisible by resolution. See the following example:

import molgrid, torch

# single atom with radius=1.0 located at (0,0,0)
coords = torch.zeros((1, 3), device='cuda')
types = torch.ones((1, 1), device='cuda')
radii = torch.ones((1,), device='cuda')

# two grid makers with resolution=1.0 and center=(0,0,0)
#   with same size (# points) but different "dimensions"

gridder1 = molgrid.Coords2Grid(
    gmaker=molgrid.GridMaker(
        resolution=1.0,
        dimension=2.0,
    ),
    center=(0,0,0)
)
gridder2 = molgrid.Coords2Grid(
    gmaker=molgrid.GridMaker(
        resolution=1.0,
        dimension=1.9,
    ),
    center=(0,0,0)
)

grid1 = gridder1.forward(coords, types, radii)
grid2 = gridder2.forward(coords, types, radii)

print('grids have the same shape:', grid1.shape == grid2.shape)
print('grids have the same values:', (grid1 == grid2).all().item())

m = tuple(dim//2 for dim in grid1.shape) # midpoint index
print('grid1 is centered at (0,0,0):', (grid1[m] == 1.0).item())
print('grid2 is centered at (0,0,0):', (grid2[m] == 1.0).item())

def check_symmetry(grid):
    return (
        (grid == grid.flip(dims=(1,))).all() and
        (grid == grid.flip(dims=(2,))).all() and
        (grid == grid.flip(dims=(3,))).all()
    ).item()

print('grid1 is symmetric:', check_symmetry(grid1))
print('grid2 is symmetric:', check_symmetry(grid2))

Which produces this output:

grids have the same shape: True
grids have the same values: False
grid1 is centered at (0,0,0): True
grid2 is centered at (0,0,0): False
grid1 is symmetric: True
grid2 is symmetric: False
@mattragoza mattragoza added the bug Something isn't working label May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant