def test_invert3x3(self): q = rotations.random_q() mx = rotations.q2mx(q) mxi1 = invert3x3(mx) mxi2 = np.linalg.inv(mx) self.assertEqual(mxi1.shape, mxi2.shape) for v1, v2 in zip(mxi1.reshape(-1), mxi2.reshape(-1)): self.assertAlmostEqual(v1, v2, places=5)
def test_invert3x3(self): q = rotations.random_q() mx = rotations.q2mx(q) mxi1 = invert3x3(mx) mxi2 = np.linalg.inv(mx) self.assertEqual(mxi1.shape, mxi2.shape) for v1, v2 in izip(mxi1.reshape(-1), mxi2.reshape(-1)): self.assertAlmostEqual(v1, v2, places=5)
def test1(self): rot = q2mx(random_q()) x2 = self.x1.copy() self.transform.rotate(x2, rot) x1 = self.x1 dist, mx = self.findrot(x1, x2) self.assertLess(dist, 1e-4) self.transform.translate(x2, -self.measure.get_com(x2)) self.transform.rotate(x2, mx) self.transform.translate(x2, self.measure.get_com(x1)) assert_arrays_almost_equal(self, x1, x2)
def test(): # pragma: no cover natoms = 35 from pele.utils import rotations for i in xrange(100): xx1 = np.random.random(3 * natoms) * 5 xx1 = xx1.reshape([-1, 3]) mx = rotations.q2mx(rotations.random_q()) xx2 = -np.dot(mx, xx1.transpose()).transpose() xx2 += 2.0 * (np.random.random(xx2.shape) - 0.5) * 0.001 # xx2 = xx1.copy() tmp = xx2[1].copy() xx2[1] = xx2[4] xx2[4] = tmp print i, ExactMatchCluster()(xx1.flatten(), xx2.flatten())
def test2(self): rot = q2mx(random_q()) dx = .01 x2 = self.x1.copy() x2[0] += .01 self.transform.rotate(x2, rot) x1old = self.x1.copy() x2old = x2.copy() dist, mx = self.findrot(self.x1, x2) # check it didn't change the arrays assert_arrays_almost_equal(self, x1old, self.x1) assert_arrays_almost_equal(self, x2old, x2) self.assertLess(dist, dx)
def test(): # pragma: no cover natoms = 35 from pele.utils import rotations for i in range(100): xx1 = np.random.random(3 * natoms) * 5 xx1 = xx1.reshape([-1, 3]) mx = rotations.q2mx(rotations.random_q()) xx2 = -np.dot(mx, xx1.transpose()).transpose() xx2 += 2. * (np.random.random(xx2.shape) - 0.5) * 0.001 #xx2 = xx1.copy() tmp = xx2[1].copy() xx2[1] = xx2[4] xx2[4] = tmp print(i, ExactMatchCluster()(xx1.flatten(), xx2.flatten()))
def test(): natoms = 35 from pele.utils import rotations for i in xrange(100): xx1 = np.random.random(3*natoms)*5 xx1 = xx1.reshape([-1,3]) mx = rotations.q2mx(rotations.random_q()) xx2 = -np.dot(mx, xx1.transpose()).transpose() xx2 +=2.*(np.random.random(xx2.shape)-0.5)*0.001 #xx2 = xx1.copy() tmp = xx2[1].copy() xx2[1] = xx2[4] xx2[4] = tmp #dist, x1n, x2n = findBestPermutation(xx1.flatten(), xx2.flatten()) #print dist print i,ExactMatchCluster()(xx1.flatten(), xx2.flatten())
imin = np.argmin(eigs) eigmin = eigs[imin] #the minimum eigenvector Q2 = vecs[:,imin] #the eigenvector corresponding to the minimum eigenvalue if eigmin < 0.: if abs(eigmin) < 1e-6: eigmin = 0. else: print 'minDist> WARNING minimum eigenvalue is ',eigmin,' change to absolute value' eigmin = -eigmin dist = np.sqrt(eigmin) #this is the minimized distance between the two structures #print "dist from eigenvalue", dist #print "Q2", Q2, "norm", np.linalg.norm(Q2) #aa = rot.q2aa( Q2) #print "aa ", aa, "norm", np.linalg.norm(aa) return dist, rotations.q2mx(Q2) findrotation = findrotation_kearsley if __name__ == "__main__": from pele.utils import rotations x1 = np.random.random(24) mx = rotations.q2mx(rotations.random_q()) x2 = np.dot(mx,x1.reshape(-1,3).transpose()).transpose().reshape(-1) print x2-x1 print mx-findrotation_kabsch(x1,x2) print findrotation_kabsch(x1,x2) print findrotation_kearsley(x1,x2)[1]
def test_mx2aa(self): mx = rotations.q2mx(random_q()) p1 = mx2aa(mx) p2 = rotations.mx2aa(mx) self.arrays_equal(p1, p2)
eigmin = eigs[imin] # the minimum eigenvector Q2 = vecs[:, imin] # the eigenvector corresponding to the minimum eigenvalue if eigmin < 0.: if abs(eigmin) < 1e-6: eigmin = 0. else: print 'minDist> WARNING minimum eigenvalue is ', eigmin, ' change to absolute value' eigmin = -eigmin dist = np.sqrt( eigmin) # this is the minimized distance between the two structures Q2 = np.real_if_close(Q2, 1e-10) if np.iscomplexobj(Q2): raise ValueError("Q2 is complex") return dist, rotations.q2mx(Q2) findrotation = findrotation_kearsley if __name__ == "__main__": x1 = np.random.random(24) mx = rotations.q2mx(rotations.random_q()) x2 = np.dot(mx, x1.reshape(-1, 3).transpose()).transpose().reshape(-1) print x2 - x1 print mx - findrotation_kabsch(x1, x2) print findrotation_kabsch(x1, x2) print findrotation_kearsley(x1, x2)[1]
def rrot(self, x): q = rotations.random_q() mx = rotations.q2mx(q) self.transform.rotate(x, mx)