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_apply_transform():
'''non-random transform'''
from molgrid import Transform, Quaternion, float3, MGrid2f, Grid2f
from math import sqrt
q = Quaternion(sqrt(0.5),0,0,sqrt(0.5)) # //z 90
nr = Transform(q, float3(0,1,1), float3(2,0,-3))
#random
r = Transform(float3(0,1,1), 10.0, True)
coord_data = [ [0,0,0],
[1,0,0],
[0,1,0],
[0,0,1],
[-1,.5,3],
[1,1,1],
[0,1,1],
[.333,.75,-9] ]
coords = MGrid2f(8,3)
coords2 = MGrid2f(8,3)
def test_coordset_from_array():
coords = np.array([[1,0,-1],[1,3,-1],[1,0,-1]],np.float32)
types = np.array([3,2,1],np.float32)
radii = np.array([1.5,1.5,1.0],np.float32)
c = molgrid.CoordinateSet(coords, types, radii, 4)
oldcoordr = c.coords.tonumpy()
#simple translate
t = molgrid.Transform(molgrid.Quaternion(), (0,0,0), (-1,0,1))
t.forward(c,c)
newcoord = c.coords.tonumpy()
assert c.coords[1,1] == 3.0
assert np.sum(newcoord) == approx(3.0)
c2 = c.clone()
c2.coords[1,1] = 0
assert c.coords[1,1] == 3.0
def test_numpy_apply_transform():
'''non-random transform'''
from molgrid import Transform, Quaternion, float3, MGrid2f, Grid2f
from math import sqrt
import numpy as np
q = Quaternion(sqrt(0.5),0,0,sqrt(0.5)) # //z 90
nr = Transform(q, float3(0,1,1), float3(2,0,-3))
#random
r = Transform(float3(0,1,1), 10.0, True)
coord_data = [ [0,0,0],
[1,0,0],
[0,1,0],
[0,0,1],
[-1,.5,3],
[1,1,1],
[0,1,1],
[.333,.75,-9] ]
coords = np.array(coord_data,np.float32)
coords2 = np.zeros((8,3),np.float32)