Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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_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.num_types() == (c.max_type + c2.max_type)
assert ex.num_coordinates() == (c.coords.dimension(0)+c2.type_index.size())
c3 = ex.merge_coordinates()
assert c3.coords.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())
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)
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_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':
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])