Пример #1
0
def test_vector_types_duplicate():
    fname = datadir+"/smalldup.types"

    teste = molgrid.ExampleProvider(molgrid.GninaVectorTyper(),shuffle=False, duplicate_first=True,data_root=datadir+"/structs")
    teste.populate(fname)
    batch_size = 1
    gmaker = molgrid.GridMaker()
    dims = gmaker.grid_dimensions(molgrid.GninaVectorTyper().num_types()*4)
    
    tensor_shape = (batch_size,)+dims
    input_tensor_1 = torch.zeros(tensor_shape, dtype=torch.float32, device='cuda')
    
    batch_1 = teste.next_batch(batch_size)
    gmaker.forward(batch_1, input_tensor_1,random_translation=0.0, random_rotation=False)
    
    input_tensor_2 = torch.zeros(tensor_shape, dtype=torch.float32, device='cpu')
    
    gmaker.forward(batch_1, input_tensor_2,random_translation=0.0, random_rotation=False)   
    
    np.testing.assert_allclose(input_tensor_1.cpu().detach().numpy(),input_tensor_2.detach().numpy(),atol=1e-4)
    assert input_tensor_1.cpu().detach().numpy().max() < 75
Пример #2
0
def test_gninavector_typing():
    m = pybel.readstring('smi', 'C')
    m.addh()

    t = molgrid.GninaVectorTyper()
    typs = [t.get_atom_type_vector(a.OBAtom) for a in m.atoms]
    names = list(t.get_type_names())
    assert len(names) == 26
    assert names[-1] == 'OB_partialcharge'
    for tvec, r in typs:
        if r < 1:  #hydrogen
            assert r == approx(0.37)
            assert tvec[0] == 1
            assert np.sum(tvec[:17]) == 1
        else:  #carbon
            assert r == approx(1.9)
            assert tvec[1] == 1
            assert np.sum(tvec[:17]) == 1
            assert names[20] == "XS_hydrophobe"
            assert tvec[20] == 1