def test_conversion(self, phi1=0, psi1=0, the1=0, phi2=90, psi2=90, the2=90): from pytom.angles.angleFnc import zxzToMat m = zxzToMat(phi1, psi1, the1, False) self.assertTrue(m.trace() == 3.0, msg='trace of matrix is wrong') self.assertTrue( m.getRow(0)[0] == 1.0 and m.getRow(1)[1] == 1.0 and m.getRow(2)[2] == 1.0) m = zxzToMat(phi2, psi2, the2, False) from pytom.angles.angleFnc import matToZXZ a = matToZXZ(m) self.assertTrue(a[0] == phi2 and a[1] == psi2 and a[2] == the2)
def getConstraintVolume(self, bw): if self._cv is None or self._bw != bw: cv = np.zeros((2 * bw, 2 * bw, 2 * bw), dtype='double') if self.nearby > 0: # get an array of axes nearby the = np.array(range( 1, int(self.nearby * bw / 90.) + 1)) * (90. / bw) the = np.append(the, self.nearby) phi = range(0, 360, int(round(180. / bw))) the, phi = np.meshgrid(the, phi) the = the.reshape((the.size, )) * np.pi / 180 phi = phi.reshape((phi.size, )) * np.pi / 180 xx = np.cos(phi) * np.sin(the) yy = np.sin(phi) * np.sin(the) zz = np.cos(the) # rotate all the vectors from pytom.angles.angleFnc import vector2euler, zxzToMat m = zxzToMat(vector2euler([self.x, self.y, self.z])) mat = np.matrix(np.zeros((3, 3))) mat[0, 0] = m[0, 0] mat[0, 1] = m[0, 1] mat[0, 2] = m[0, 2] mat[1, 0] = m[1, 0] mat[1, 1] = m[1, 1] mat[1, 2] = m[1, 2] mat[2, 0] = m[2, 0] mat[2, 1] = m[2, 1] mat[2, 2] = m[2, 2] coord = mat * np.matrix(np.vstack((xx, yy, zz))) axes = coord.swapaxes(0, 1) else: axes = np.matrix([[self.x, self.y, self.z]]) # here we make the angular sampling as 2 degree from pytom.angles.angleFnc import axisAngleToZXZ for axis in axes: axis = [axis[0, 0], axis[0, 1], axis[0, 2]] for ang in range(0, 360, 2): euler_ang = axisAngleToZXZ(axis, ang) i, j, k = frm_angle2idx(bw, euler_ang.getPhi(), euler_ang.getPsi(), euler_ang.getTheta()) # set the cv cv[i, j, k] = 1 self._cv = cv self._bw = bw return self._cv
def zxzToMatToZXZ_T(self, z1, z2, x): from pytom.angles.angleFnc import zxzToMat, matToZXZ m = zxzToMat(z1=z1, z2=z2, x=x) r = matToZXZ(m) self.assertAlmostEqual(first=r.getZ1(), second=z1, places=3, msg='numerical issue in z1') self.assertAlmostEqual(first=r.getZ2(), second=z2, places=3, msg='numerical issue in z2') self.assertAlmostEqual(first=r.getX(), second=x, places=3, msg='numerical issue in x')