def test_init_projection(self): cg = ftmc.from_pdb('test/forgi/threedee/data/2X1F.pdb') proj = fpp.Projection2D(cg, [1., 1., 1.]) self.assertTrue( ftuv.is_almost_colinear(proj.proj_direction, np.array([1., 1., 1.])), msg= "The projection direction was not stored correctly. Should be coliniar" " with {}, got {}".format(np.array([1., 1., 1.]), proj.proj_direction))
def test_create_orthonormal_basis(self): #Note: If the input vectors are not orthogonal, the result are 3 vectors that might not form a basis. basis1 = ftuv.create_orthonormal_basis(np.array([0.0, 0.0, 2.0])) self.assertTrue( ftuv.is_almost_colinear(basis1[0], np.array([0., 0., 2.]))) basis2 = ftuv.create_orthonormal_basis(np.array([0.0, 0.0, 2.0]), np.array([0.0, 3.6, 0.])) self.assertTrue( ftuv.is_almost_colinear(basis2[0], np.array([0., 0., 2.]))) self.assertTrue( ftuv.is_almost_colinear(basis2[1], np.array([0., 3.6, 0]))) basis3 = ftuv.create_orthonormal_basis(np.array([0.0, 0.0, 2.0]), np.array([0.0, 3.6, 0.]), np.array([1., 0, 0])) self.assertTrue( ftuv.is_almost_colinear(basis3[0], np.array([0., 0., 2.]))) self.assertTrue( ftuv.is_almost_colinear(basis3[1], np.array([0., 3.6, 0]))) self.assertTrue( ftuv.is_almost_colinear(basis3[2], np.array([1., 0, 0]))) for basis in [basis1, basis2, basis3]: self.assertAlmostEqual(np.dot(basis[0], basis[1]), 0) self.assertAlmostEqual(np.dot(basis[0], basis[2]), 0) self.assertAlmostEqual(np.dot(basis[2], basis[1]), 0) for b in basis: self.assertAlmostEqual(ftuv.magnitude(b), 1)
def test_create_orthonormal_basis(self): #Note: If the input vectors are not orthogonal, the result are 3 vectors that might not form a basis. basis1=ftuv.create_orthonormal_basis(np.array([0.0,0.0,2.0])) self.assertTrue( ftuv.is_almost_colinear(basis1[0], np.array([0.,0.,2.])) ) basis2=ftuv.create_orthonormal_basis(np.array([0.0,0.0,2.0]), np.array([0.0, 3.6, 0.])) self.assertTrue( ftuv.is_almost_colinear(basis2[0], np.array([0.,0.,2.])) ) self.assertTrue( ftuv.is_almost_colinear(basis2[1], np.array([0.,3.6,0])) ) basis3=ftuv.create_orthonormal_basis(np.array([0.0,0.0,2.0]), np.array([0.0, 3.6, 0.]), np.array([1,0,0])) self.assertTrue( ftuv.is_almost_colinear(basis3[0], np.array([0.,0.,2.])) ) self.assertTrue( ftuv.is_almost_colinear(basis3[1], np.array([0.,3.6,0])) ) self.assertTrue( ftuv.is_almost_colinear(basis3[2], np.array([1.,0,0])) ) for basis in [basis1, basis2, basis3]: self.assertAlmostEqual(np.dot(basis[0],basis[1]),0) self.assertAlmostEqual(np.dot(basis[0],basis[2]),0) self.assertAlmostEqual(np.dot(basis[2],basis[1]),0) for b in basis: self.assertAlmostEqual(ftuv.magnitude(b),1)
def test_get_alignment_matrix(self): vec1 = np.array([0.5, 0.7, 0.9]) vec2 = np.array([0.345, 3.4347, 0.55]) rotMat = ftuv.get_alignment_matrix(vec1, vec2) self.assertTrue(ftuv.is_almost_colinear(vec2, np.dot(vec1, rotMat))) self.assertTrue(ftuv.is_almost_colinear(np.dot(rotMat, vec2), vec1))
def test_is_almost_colinear(self): self.assertTrue( ftuv.is_almost_colinear(np.array([0, 0, 0]), np.array([0., 0., 0.]))) self.assertTrue( ftuv.is_almost_colinear(np.array([0, 0, 2]), np.array([0., 0., 3.]))) self.assertTrue( ftuv.is_almost_colinear(np.array([3, 6, 7]), np.array([9., 18., 21.]))) self.assertTrue( ftuv.is_almost_colinear(np.array([3, 6, 0]), np.array([9., 18., 0.]))) self.assertTrue( ftuv.is_almost_colinear(np.array([3, 0, 8]), np.array([9., 0., 24.]))) self.assertTrue( ftuv.is_almost_colinear(np.array([0, 0, 0]), np.array([0, 20, 0]))) self.assertTrue( ftuv.is_almost_colinear(np.array([0.0004, 0, 0]), np.array([0., 0., 0.]))) self.assertFalse( ftuv.is_almost_colinear(np.array([0, 0, 3]), np.array([2., 0, 0]))) self.assertFalse( ftuv.is_almost_colinear(np.array([1, 2, 3]), np.array([2., 4., -6.]))) self.assertFalse( ftuv.is_almost_colinear(np.array([1, 2, 3]), np.array([3., 4., 6.]))) self.assertFalse( ftuv.is_almost_colinear(np.array([1, 2, 3]), np.array([2., 5., 6.])))
def test_get_alignment_matrix(self): vec1=np.array([0.5,0.7,0.9]) vec2=np.array([0.345,3.4347,0.55]) rotMat=ftuv.get_alignment_matrix(vec1,vec2) self.assertTrue( ftuv.is_almost_colinear(vec2, np.dot(vec1, rotMat)) ) self.assertTrue( ftuv.is_almost_colinear(np.dot(rotMat, vec2), vec1) )
def test_is_almost_colinear(self): self.assertTrue(ftuv.is_almost_colinear(np.array([0,0,0]),np.array([0.,0.,0.]))) self.assertTrue(ftuv.is_almost_colinear(np.array([0,0,2]),np.array([0.,0.,3.]))) self.assertTrue(ftuv.is_almost_colinear(np.array([3,6,7]),np.array([9.,18.,21.]))) self.assertTrue(ftuv.is_almost_colinear(np.array([3,6,0]),np.array([9.,18.,0.]))) self.assertTrue(ftuv.is_almost_colinear(np.array([3,0,8]),np.array([9.,0.,24.]))) self.assertTrue(ftuv.is_almost_colinear(np.array([0,0,0]),np.array([0,20,0]))) self.assertTrue(ftuv.is_almost_colinear(np.array([0.0004,0,0]),np.array([0.,0.,0.]))) self.assertFalse(ftuv.is_almost_colinear(np.array([0,0,3]),np.array([2.,0,0]))) self.assertFalse(ftuv.is_almost_colinear(np.array([1,2,3]),np.array([2.,4.,-6.]))) self.assertFalse(ftuv.is_almost_colinear(np.array([1,2,3]),np.array([3.,4.,6.]))) self.assertFalse(ftuv.is_almost_colinear(np.array([1,2,3]),np.array([2.,5.,6.])))