def testTransform(self): # first combine 2 translations coords = np.array([1., 2., 3., 4., 5., 6.]) coords2 = coords.copy() transform = TransformCluster3D().translate(np.array([1., 2, 3])) transform.transform(TransformCluster3D().translate(np.array([2., 3, 4]))) transform.apply(coords2) self.assertLess( np.linalg.norm(coords2 - np.array([4., 7., 10., 7., 10., 13.])), 1e-10) for i in xrange(100): dx1 = np.random.random(3) R1 = random_rotation() dx2 = np.random.random(3) R2 = random_rotation() transform = TransformCluster3D().translate(dx1) transform.transform(TransformCluster3D().rotate(R1)) transform.transform(TransformCluster3D().translate(dx2)) transform.transform(TransformCluster3D().rotate(R2)) x = np.random.random(3 * 20) x2 = x.reshape([-1, 3]).copy() x2 = np.dot(R1, (x2 + dx1).transpose()).transpose() x2 = np.dot(R2, (x2 + dx2).transpose()).transpose() transform.apply(x) self.assertLess(np.linalg.norm(x - x2.flatten()), 1e-10)
def testTransform(self): # first combine 2 translations coords = np.array([1., 2., 3., 4., 5., 6.]) coords2 = coords.copy() transform = TransformCluster3D().translate(np.array([1., 2, 3])) transform.transform(TransformCluster3D().translate(np.array([2., 3, 4]))) transform.apply(coords2) self.assertLess(np.linalg.norm(coords2 - np.array([4., 7., 10., 7., 10., 13.])), 1e-10) for i in xrange(100): dx1 = np.random.random(3) R1 = random_rotation() dx2 = np.random.random(3) R2 = random_rotation() transform = TransformCluster3D().translate(dx1) transform.transform(TransformCluster3D().rotate(R1)) transform.transform(TransformCluster3D().translate(dx2)) transform.transform(TransformCluster3D().rotate(R2)) x = np.random.random(3*20) x2 = x.reshape([-1,3]).copy() x2 = np.dot(R1, (x2+dx1).transpose()).transpose() x2 = np.dot(R2, (x2+dx2).transpose()).transpose() transform.apply(x) self.assertLess(np.linalg.norm(x - x2.flatten()), 1e-10)
def testRotate(self): for i in xrange(100): R = random_rotation() transform = TransformCluster3D().rotate(R) x = np.random.random(3*20) x2 = x.reshape([-1,3]).copy() x2 = np.dot(R, x2.transpose()).transpose() transform.apply(x) self.assertLess(np.linalg.norm(x - x2.flatten()), 1e-10)
def testRotate(self): for i in xrange(100): R = random_rotation() transform = TransformCluster3D().rotate(R) x = np.random.random(3 * 20) x2 = x.reshape([-1, 3]).copy() x2 = np.dot(R, x2.transpose()).transpose() transform.apply(x) self.assertLess(np.linalg.norm(x - x2.flatten()), 1e-10)
def testCombine(self): for i in xrange(100): dx1 = np.random.random(3) R1 = random_rotation() dx2 = np.random.random(3) R2 = random_rotation() transform = TransformCluster3D().translate(dx1) transform.rotate(R1) transform.translate(dx2) transform.rotate(R2) x = np.random.random(3*20) x2 = x.reshape([-1,3]).copy() x2 = np.dot(R1, (x2+dx1).transpose()).transpose() x2 = np.dot(R2, (x2+dx2).transpose()).transpose() transform.apply(x) self.assertLess(np.linalg.norm(x - x2.flatten()), 1e-10)
def testCombine(self): for i in xrange(100): dx1 = np.random.random(3) R1 = random_rotation() dx2 = np.random.random(3) R2 = random_rotation() transform = TransformCluster3D().translate(dx1) transform.rotate(R1) transform.translate(dx2) transform.rotate(R2) x = np.random.random(3 * 20) x2 = x.reshape([-1, 3]).copy() x2 = np.dot(R1, (x2 + dx1).transpose()).transpose() x2 = np.dot(R2, (x2 + dx2).transpose()).transpose() transform.apply(x) self.assertLess(np.linalg.norm(x - x2.flatten()), 1e-10)
def test2(self): """align two configurations that should match exactly """ x0 = _utils.random_configuration(3 * self.natoms) com = self.measure.get_com(x0) self.policy.translate(x0, -com) x1 = x0.copy() self.policy.rotate(x1, _utils.random_rotation()) self.basic_test(x0, x1) self.assertLess(np.abs(x0 - x1).max(), 1e-3)
def test2(self): """align two configurations that should match exactly """ x0 = _utils.random_configuration(3 * self.natoms) com = self.measure.get_com(x0) self.policy.translate(x0, -com) x1 = x0.copy() self.policy.rotate(x1, _utils.random_rotation()) self.basic_test(x0, x1) self.assertLess(np.abs(x0-x1).max(), 1e-3)
def test_apply_rotation(self): rot = _utils.random_rotation() _utils.rotate(self.x2, rot) self.tform.apply_rotation(self.x, rot) self.assertLess(np.abs(self.x - self.x2).max(), 1e-3)