def test_example_merge(): m = pybel.readstring('smi', 'c1ccccc1CO') m.addh() m.make3D() c = molgrid.CoordinateSet(m, molgrid.ElementIndexTyper()) c2 = molgrid.CoordinateSet(m) c2.make_vector_types() #this should not screw up index types ex = molgrid.Example() ex.coord_sets.append(c) ex.coord_sets.append(c2) assert ex.type_size() == (c.max_type + c2.max_type) assert ex.coordinate_size() == (c.coord.dimension(0) + c2.type_index.size()) c3 = ex.merge_coordinates() assert c3.coord.tonumpy().shape == (24, 3) t = np.concatenate( [c.type_index.tonumpy(), c2.type_index.tonumpy() + c.max_type]) assert np.array_equal(t, c3.type_index.tonumpy()) #test merging without unique types, which makes no sense c4 = ex.merge_coordinates(0, False) assert c4.coord.tonumpy().shape == (24, 3) t = np.concatenate([c.type_index.tonumpy(), c2.type_index.tonumpy()]) assert np.array_equal(t, c4.type_index.tonumpy()) #test sliced merging c5 = ex.merge_coordinates(1, False) assert c5.coord.tonumpy().shape == (8, 3) #no hydrogens in this slice
def test_elementtyping(): m = pybel.readstring('smi', 'c1ccccc1CO') m.addh() t = molgrid.ElementIndexTyper(17) assert t.num_types() == 17 names = list(t.get_type_names()) assert names[2] == 'Helium' typs = [t.get_atom_type_index(a.OBAtom) for a in m.atoms] assert len(typs) == 16 ccnt = 0 ocnt = 0 hcnt = 0 for t, r in typs: if names[t] == 'Carbon': ccnt += 1 assert r == approx(.76) if names[t] == 'Oxygen': ocnt += 1 assert r == approx(.66) if names[t] == 'Hydrogen': hcnt += 1 assert r == approx(.31) assert ccnt == 7 assert ocnt == 1 assert hcnt == 8
def test_custom_typer_example_provider(): fname = datadir + "/small.types" t = molgrid.ElementIndexTyper(80) e = molgrid.ExampleProvider(t, data_root=datadir + "/structs") e.populate(fname) batch = e.next_batch(10) c = batch[0].coord_sets[0] assert c.max_type == 80
def test_cached_with_typer_example_provider(): fname = datadir + "/ligonly.types" t = molgrid.ElementIndexTyper(80) e = molgrid.ExampleProvider(t, ligmolcache=datadir + '/lig.molcache2') e.populate(fname) batch = e.next_batch(10) c = batch[0].coord_sets[1] assert c.max_type == 80 assert c.type_index[0] == 7
def test_coordset_from_mol(): m = pybel.readstring('smi','c1ccccc1CO') m.addh() m.make3D() c = molgrid.CoordinateSet(m,molgrid.ElementIndexTyper()) oldcoord = c.coords.tonumpy() #simple translate t = molgrid.Transform(molgrid.Quaternion(), (0,0,0), (1,1,1)) t.forward(c,c) newcoord = c.coords.tonumpy() assert np.sum(newcoord-oldcoord) == approx(48)
def test_examplevec(): m = pybel.readstring('smi','c1ccccc1CO') m.addh() m.make3D() c = molgrid.CoordinateSet(m,molgrid.ElementIndexTyper()) c2 = molgrid.CoordinateSet(m) c2.make_vector_types() #this should not screw up index types ex = molgrid.Example() ex.coord_sets.append(c) ex.labels.append(0) ex2 = molgrid.Example() ex2.coord_sets.append(c2) ex2.labels.append(1) evec = molgrid.ExampleVec([ex,ex2])
def test_coordset_merge(): m = pybel.readstring('smi','c1ccccc1CO') m.addh() m.make3D() c = molgrid.CoordinateSet(m,molgrid.ElementIndexTyper()) c2 = molgrid.CoordinateSet(m) c3 = molgrid.CoordinateSet(c,c2) c4 = molgrid.CoordinateSet(c,c2,False) assert c3.max_type == (c.max_type + c2.max_type) assert c3.coords.dimension(0) == (c.coords.dimension(0)+c2.type_index.size()) assert c4.max_type == max(c.max_type,c2.max_type) assert c4.coords.dimension(0) == (c.coords.dimension(0)+c2.type_index.size()) t = np.concatenate([c.type_index.tonumpy(),c2.type_index.tonumpy()+c.max_type]) assert np.array_equal(t, c3.type_index.tonumpy()) #test merging without unique types, which makes no sense assert c4.coords.tonumpy().shape == (24,3) t = np.concatenate([c.type_index.tonumpy(),c2.type_index.tonumpy()]) assert np.array_equal(t, c4.type_index.tonumpy())