Esempio n. 1
0
def rt2tr(translation, rotation):
    """Change the transformation order from 1T2R to 1R2T.
    """
    from pytom.tools.maths import TransformationMatrix
    from pytom.angles.angleFnc import matToZXZ
    m = TransformationMatrix(rotation, [0, 0, 0]) * TransformationMatrix(
        [0, 0, 0], translation)
    return (matToZXZ(m.getRotationMatrix()).toList(), m.getTranslation())
Esempio n. 2
0
    def nextRotation(self):
        """
        nextRotation : 
        @return: [z1 z2 x] for the next rotation or [None,None,None] after all rotations were sampled
        @author: Friedrich Foerster
        @change: Local Rotation had a bug causing too large rotations in Phi
        @date: 07/07/2014
        """

        if self._finished:
            return [None, None, None]

        from math import sin, ceil, pi, sqrt, atan2  #,modf
        from pytom.basic.structures import Rotation
        from pytom.angles.angleFnc import matToZXZ

        phi = self._currentZ1
        if self._currentX == 0:
            npsi = 1
            dpsi = 360.
        else:
            dpsi = self._increment / sin(
                float(self._currentX * self._increment) / 180. * pi)
            npsi = ceil(360. / dpsi)
            #make dpsi equidistant again
            dpsi = 360. / npsi

        localRotation = Rotation(z1=phi - self._currentZ2 * dpsi,
                                 z2=self._currentZ2 * dpsi,
                                 x=self._currentX * self._increment,
                                 paradigm='ZXZ')

        globalMatrix = localRotation.toMatrix() * self._startMatrix

        [phi, psi, theta] = matToZXZ(globalMatrix)

        if self._currentZ2 >= npsi - 1:
            self._currentZ2 = 0
            if self._currentX >= ceil(self._shells / 2):
                self._currentX = 0
                if self._currentZ1 >= self._shells * self._increment:
                    self._finished = True
                    return [self._startZ1, self._startZ2, self._startX]
                else:
                    self._currentZ1 = self._currentZ1 + self._increment
            else:
                self._currentX = self._currentX + 1
        else:
            self._currentZ2 = self._currentZ2 + 1

        return [phi % 360, psi % 360, theta % 360]
Esempio n. 3
0
 def matPoleTest1(self):
     """
     check that conversion to angle from matrix works for x == 0
     """
     z1 = 9
     z2 = 360. - 114
     x = 0.
     self.rot1 = Rotation(z1=z1, z2=z2, x=x)
     self.rot2 = Rotation(z1=0., z2=0., x=0.)
     newrot = self.rot2 * self.rot1
     [nz1, nz2, nx] = matToZXZ(newrot.toMatrix(), inRad=False)
     self.assertTrue(nx == 0.0, 'Pole Test 1 failed: wrong x-angle')
     self.assertTrue(
         abs(nz2 + nz1 - z2 - z1) < 0.00001,
         'Pole Test 2 failed: wrong assignment z1 and z2')
Esempio n. 4
0
 def matTestQ4(self):
     """
     test that matToZXZ works for 180<z2<360
     """
     z1 = 169.
     z2 = 190.
     x = 10.
     self.rot1 = Rotation(z1=z1, z2=z2, x=x)
     self.rot2 = Rotation(z1=0., z2=0., x=0.)
     newrot = self.rot2 * self.rot1
     [nz1, nz2, nx] = matToZXZ(newrot.toMatrix(), inRad=False)
     self.assertTrue(abs(nx - x) < self.eps, 'matTestQ3: nx and x differ')
     self.assertTrue(
         abs(nz1 - z1) < self.eps, 'matTestQ3: nz1 and z1 differ')
     self.assertTrue(
         abs(nz2 - z2) < self.eps, 'matTestQ3: nz2 and z2 differ')
Esempio n. 5
0
 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')
Esempio n. 6
0
 def matPoleTest2(self):
     """
     check that conversion to angle from matrix works for x == 180
     """
     z1 = 9
     z2 = -114
     x = 180.
     self.rot1 = Rotation(z1=z1, z2=z2, x=x)
     self.rot2 = Rotation(z1=0., z2=0., x=0.)
     newrot = self.rot2 * self.rot1
     [nz1, nz2, nx] = matToZXZ(newrot.toMatrix(), inRad=False)
     self.assertTrue(nx == 180.0, 'Pole Test 2 failed: wrong x-angle')
     self.assertTrue(
         abs(
             modf((nz2 - nz1 + 360.) / 360.)[0] * 360 -
             modf((z2 - z1 + 360.) / 360.)[0] * 360) < 0.00001,
         'Pole Test 2 failed: z2 z1 not correct')
Esempio n. 7
0
    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)