def test_vector_sum_types(): fname = datadir + "/ligonly.types" e = molgrid.ExampleProvider(data_root=datadir + "/structs", make_vector_types=True) e.populate(fname) batch_size = 10 b = e.next_batch(batch_size) sum = molgrid.MGrid2f(batch_size, e.num_types()) b.sum_types(sum) sum2 = np.zeros(sum.shape, np.float32) b.sum_types(sum2) sum3 = torch.empty(sum.shape, dtype=torch.float32, device='cuda') b.sum_types(sum3) np.testing.assert_allclose(sum.tonumpy(), sum3.detach().cpu().numpy(), atol=1e-5) np.testing.assert_allclose(sum.tonumpy(), sum2, atol=1e-5) np.testing.assert_allclose(sum[0].tonumpy(), [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 2., 3., 0., 0., 0., 0., 0., 0., 2., 2., 1., 0., 0., 0. ], atol=1e-5) e = molgrid.ExampleProvider(molgrid.NullIndexTyper(), molgrid.defaultGninaLigandTyper, data_root=datadir + "/structs", make_vector_types=True) e.populate(fname) b = e.next_batch(batch_size) sum = molgrid.MGrid2f(batch_size, e.num_types()) b.sum_types(sum) np.testing.assert_allclose( sum[0].tonumpy(), [2., 3., 0., 0., 0., 0., 0., 0., 2., 2., 1., 0., 0., 0.], atol=1e-5)
def test_make_vector_types_ex_provider(capsys): fname = datadir + "/ligonly.types" e = molgrid.ExampleProvider(molgrid.NullIndexTyper(), molgrid.defaultGninaLigandTyper, data_root=datadir + "/structs", make_vector_types=True) e.populate(fname) batch_size = 10 b = e.next_batch(batch_size) gmaker = molgrid.GridMaker(dimension=23.5, radius_type_indexed=True) shape = gmaker.grid_dimensions(molgrid.defaultGninaLigandTyper.num_types()) mgrid = molgrid.MGrid5f(batch_size, *shape) c = b[0].merge_coordinates() tv = c.type_vector.tonumpy() assert tv.shape == (10, 14) assert tv[0].sum() == 1.0 assert tv[0][8] == 1.0 e2 = molgrid.ExampleProvider(data_root=datadir + "/structs", make_vector_types=True) e2.populate(fname) b2 = e2.next_batch(batch_size) c2 = b2[0].merge_coordinates(unique_index_types=True) tv2 = c2.type_vector.tonumpy() assert tv2.shape == (10, 28) gmaker.forward(b, mgrid) assert b[0].coord_sets[0].has_vector_types() assert b[0].coord_sets[1].has_vector_types() assert b[0].num_types() == 14
def test_nulltyping(): m = pybel.readstring('smi', 'c1ccccc1CO') m.addh() t = molgrid.NullIndexTyper() typs = [t.get_atom_type_index(a.OBAtom) for a in m.atoms] assert t.num_types() == 0 for t, r in typs: assert t == -1 assert r == 0.0