How to use the molgrid.MGrid3d function in molgrid

To help you get started, we’ve selected a few molgrid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gnina / libmolgrid / test / test_numpy.py View on Github external
def test_numpy():
  mg3d = molgrid.MGrid3d(3,3,3)
  mg2f = molgrid.MGrid2f(2,4)
  
  a2f = np.arange(27).astype(np.float32).reshape(3,-1)
  a3d = np.arange(27).astype(np.float).reshape(3,3,-1)

  g2f = molgrid.Grid2f(a2f)
  g3d = molgrid.Grid3d(a3d)
  
  g2f[0,0] = 100
  g3d[0,0,0] = 101
        
  assert a2f[0,0] == 100
  assert a3d[0,0,0] == 101
  
  mg2f.copyFrom(g2f)
  mg3d.copyFrom(g3d)
github gnina / libmolgrid / test / test_torch.py View on Github external
def test_mgrid_copyfrom_tensor():
    mg2 = molgrid.MGrid2f(3,4)
    mg3 = molgrid.MGrid3d(3,4,2)
    t2 = torch.FloatTensor(3,4)
    t3 = torch.DoubleTensor(3,4,2)

    for i in range(3):
        for j in range(4):
            t2[i,j] = i*j+1
            for k in range(2):
                t3[i,j,k] = i*j+1+k



    mg2.copyFrom(t2)
    mg3.copyFrom(t3)

    for i in range(3):
        for j in range(4):
github gnina / libmolgrid / test / test_numpy.py View on Github external
def test_clear():
     g1 = molgrid.Grid1d(np.random.rand(20))
     mg = molgrid.MGrid3d(4,5,6)
     mg.copyFrom(np.random.rand(4,5,6))
     
     mg.fill_zero()
     g1.fill_zero()
     
     assert np.all(g1.tonumpy() == 0)
     assert np.all(mg.tonumpy() == 0)
github gnina / libmolgrid / test / test_torch.py View on Github external
def test_mgrid_copyto_tensor():
    mg2 = molgrid.MGrid2f(3,4)
    mg3 = molgrid.MGrid3d(3,4,2)
    for i in range(3):
        for j in range(4):
            mg2[i,j] = i*j+1
            for k in range(2):
                mg3[i,j,k] = i*j+1+k

    t2 = torch.FloatTensor(3,4)
    t3 = torch.DoubleTensor(3,4,2)

    mg2.copyTo(t2)
    mg3.copyTo(t3)

    for i in range(3):
        for j in range(4):
            assert t2[i,j] == i*j+1
            for k in range(2):
github gnina / libmolgrid / test / test_torch.py View on Github external
def test_mgrid_copyto_tensor_cuda():
    mg2 = molgrid.MGrid2f(3,4)
    mg3 = molgrid.MGrid3d(3,4,2)
    for i in range(3):
        for j in range(4):
            mg2[i,j] = i*j+1
            for k in range(2):
                mg3[i,j,k] = i*j+1+k

    t2 = torch.cuda.FloatTensor(3,4)
    t3 = torch.cuda.DoubleTensor(3,4,2)

    mg2.copyTo(t2)
    mg3.copyTo(t3)

    for i in range(3):
        for j in range(4):
            assert t2[i,j] == i*j+1
            for k in range(2):
github gnina / libmolgrid / test / test_torch.py View on Github external
def test_mgrid_copyfrom_tensor_cuda():
    mg2 = molgrid.MGrid2f(3,4)
    mg3 = molgrid.MGrid3d(3,4,2)
    t2 = torch.cuda.FloatTensor(3,4)
    t3 = torch.cuda.DoubleTensor(3,4,2)

    for i in range(3):
        for j in range(4):
            t2[i,j] = i*j+1
            for k in range(2):
                t3[i,j,k] = i*j+1+k

    mg2.copyFrom(t2)
    mg3.copyFrom(t3)

    for i in range(3):
        for j in range(4):
            assert mg2[i,j] == i*j+1
            for k in range(2):
github gnina / libmolgrid / test / test_numpy.py View on Github external
def test_numpy_conv():
  mg3d = molgrid.MGrid3d(3,3,3)
  mg2f = molgrid.MGrid2f(2,4)
  
  a2f = np.arange(27).astype(np.float32).reshape(3,-1)
  a3d = np.arange(27).astype(np.float).reshape(3,3,-1)

  a2f[0,0] = 100
  a3d[0,0,0] = 101        
  
  mg2f.copyFrom(a2f)
  mg3d.copyFrom(a3d)
  
  assert mg2f[1,3] == 7
  
  mg2f[1,3] = 200
  assert a2f[1,3] == 12
  mg2f.copyTo(a2f)