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_mol_example_provider(capsys):
fname = datadir+"/smallmol.types"
e = molgrid.ExampleProvider(data_root=datadir+"/structs")
e.populate(fname)
with capsys.disabled(): #bunch openbabel garbage
ex = e.next()
b = e.next_batch(10) #should wrap around
#with defaults, file should be read in order
assert ex.labels[0] == 1
assert ex.labels[1] == approx(3.3747)
assert ex.coord_sets[0].size() == 1289
assert ex.coord_sets[1].size() == 8
coords = ex.coord_sets[1].coords.tonumpy()
assert tuple(coords[0,:]) == approx((26.6450,6.1410,4.6680))
assert len(ex.coord_sets) == 2
l0 = [ex.labels[0] for ex in b]
l1 = [ex.labels[1] for ex in b]
def test_dx():
fname = datadir+"/small.types"
e = molgrid.ExampleProvider(data_root=datadir+"/structs")
e.populate(fname)
ex = e.next()
c = ex.coord_sets[1]
assert np.min(c.type_index.tonumpy()) >= 0
gmaker = molgrid.GridMaker()
dims = gmaker.grid_dimensions(e.num_types()) # this should be grid_dims or get_grid_dims
center = tuple(c.center())
mgridout = molgrid.MGrid4f(*dims)
gmaker.forward(center, c, mgridout.cpu())
molgrid.write_dx("tmp.dx", mgridout[0].cpu(), center, 0.5)
mgridin = molgrid.read_dx("tmp.dx")
def test_vector_types_mol():
'''Test vector types with a real molecule'''
fname = datadir+"/small.types"
e = molgrid.ExampleProvider(data_root=datadir+"/structs")
e.populate(fname)
ex = e.next()
ev = molgrid.ExampleProvider(data_root=datadir+"/structs",make_vector_types=True)
ev.populate(fname)
exv = ev.next()
assert exv.has_vector_types()
assert not ex.has_vector_types()
gmaker = molgrid.GridMaker()
dims = gmaker.grid_dimensions(ex.num_types()) # this should be grid_dims or get_grid_dims
mgridout = molgrid.MGrid4f(*dims)
mgridgpu = molgrid.MGrid4f(*dims)
mgridoutv = molgrid.MGrid4f(*dims)
mgridgpuv = molgrid.MGrid4f(*dims)
d = np.ones(dims,np.float32)
def test_copied_examples():
fname = datadir+"/ligonly.types"
e = molgrid.ExampleProvider(data_root=datadir+"/structs")
e.populate(fname)
batch_size = 10
b = e.next_batch(batch_size)
for i in range(1,batch_size):
sqsum = np.square(b[0].coord_sets[1].coords.tonumpy() - b[i].coord_sets[1].coords.tonumpy()).sum()
assert sqsum > 0
#now with duplicates
e = molgrid.ExampleProvider(data_root=datadir+"/structs",num_copies=batch_size)
e.populate(fname)
b = e.next_batch(batch_size)
for i in range(1,batch_size):
sqsum = np.square(b[0].coord_sets[1].coords.tonumpy() - b[i].coord_sets[1].coords.tonumpy()).sum()
assert sqsum == 0
#transforming one of the duplicates should not effect the others
def test_torch_gnina_example_provider():
datadir = os.path.dirname(__file__)+'/data'
fname = datadir+"/small.types"
e = molgrid.ExampleProvider(data_root=datadir+"/structs")
e.populate(fname)
batch_size = 100
batch = e.next_batch(batch_size)
#extract labels
nlabels = e.num_labels()
assert nlabels == 3
labels = labels = torch.zeros((batch_size,nlabels), dtype=torch.float32)
batch.extract_labels(labels)
label0 = torch.zeros(batch_size, dtype=torch.float32)
batch.extract_label(0, label0)
assert label0[0] == 1
assert labels[0,0] == 1
def test_vector_types_mol():
'''Test vector types with a real molecule'''
fname = datadir+"/small.types"
e = molgrid.ExampleProvider(data_root=datadir+"/structs")
e.populate(fname)
ex = e.next()
ev = molgrid.ExampleProvider(data_root=datadir+"/structs",make_vector_types=True)
ev.populate(fname)
exv = ev.next()
assert exv.has_vector_types()
assert not ex.has_vector_types()
gmaker = molgrid.GridMaker()
dims = gmaker.grid_dimensions(ex.num_types()) # this should be grid_dims or get_grid_dims
mgridout = molgrid.MGrid4f(*dims)
mgridgpu = molgrid.MGrid4f(*dims)
def test_gnina_example_provider():
fname = datadir+"/small.types"
e = molgrid.ExampleProvider(data_root=datadir+"/structs")
e.populate(fname)
batch_size = 100
batch = e.next_batch(batch_size)
#extract labels
nlabels = e.num_labels()
assert nlabels == 3
labels = molgrid.MGrid2f(batch_size,nlabels)
gpulabels = molgrid.MGrid2f(batch_size,nlabels)
batch.extract_labels(labels.cpu())
batch.extract_labels(gpulabels.gpu())
assert np.array_equal(labels.tonumpy(), gpulabels.tonumpy())
label0 = molgrid.MGrid1f(batch_size)
label1 = molgrid.MGrid1f(batch_size)
label2 = molgrid.MGrid1f(batch_size)
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