コード例 #1
0
def geometryFromMatrix(matrix):
    from pwem.convert.transformations import euler_from_matrix

    matrix = inv(matrix)
    angles = -rad2deg(euler_from_matrix(matrix, axes='szyz'))

    return angles
コード例 #2
0
    def prepareObj(self, index, halfString, doAlign, objType):

        shiftX, shiftY, shiftZ, rotMatrix = self.readVector(index)
        rot, tilt, psi = np.rad2deg(
            euler_from_matrix(rotMatrix.transpose(), 'szyz'))

        # Window the sub-volume to the output volume size
        objWin = self._getFileName(objType, 'windowed', index + 1, halfString)
        if objType == 'mask':
            objMasked = self._getFileName('mask', index + 1)
        else:
            objMasked = self._getFileName(objType, 'masked', index + 1,
                                          halfString)

        program = 'xmipp_transform_window'
        args = '-i %s --size %d -o %s' % (objMasked, self.outDim, objWin)
        self.runJob(program, args)

        # If sub-particles are aligned along z
        if doAlign:
            program = 'xmipp_transform_geometry'
            args = '-i %s --rotate_volume euler %f %f %f -o %s' \
                   % (objWin, -rot, -tilt, -psi, objWin)
            self.runJob(program, args)

        # Shift the sub-volume to its center in the volume
        objShifted = self._getFileName(objType, 'shifted', index + 1,
                                       halfString)
        program = 'xmipp_transform_geometry'
        args = (
            '-i %s --shift %f %f %f -o %s --dont_wrap --interp %s' %
            (objWin, shiftX, shiftY, shiftZ, objShifted, self.interpString))
        self.runJob(program, args)
コード例 #3
0
 def _align2DToRow(self, alignment, row):
     matrix = alignment.getMatrix()
     shifts = tfs.translation_from_matrix(matrix)
     shifts *= self._pixelSize
     angles = -np.rad2deg(tfs.euler_from_matrix(matrix, axes='szyz'))
     row['rlnOriginXAngst'], row['rlnOriginYAngst'] = shifts[:2]
     row['rlnAnglePsi'] = -(angles[0] + angles[2])
コード例 #4
0
 def _alignProjToRow(self, alignment, row):
     matrix = np.linalg.inv(alignment.getMatrix())
     shifts = -tfs.translation_from_matrix(matrix)
     shifts *= self._pixelSize
     angles = -np.rad2deg(tfs.euler_from_matrix(matrix, axes='szyz'))
     row['rlnOriginXAngst'], row['rlnOriginYAngst'], row[
         'rlnOriginZAngst'] = shifts
     row['rlnAngleRot'], row['rlnAngleTilt'], row['rlnAnglePsi'] = angles
コード例 #5
0
def geometryFromMatrix(matrix, inverseTransform):
    if inverseTransform:
        matrix = numpy.linalg.inv(matrix)
        shifts = -transformations.translation_from_matrix(matrix)
    else:
        shifts = transformations.translation_from_matrix(matrix)
    angles = -numpy.rad2deg(
        transformations.euler_from_matrix(matrix, axes='szyz'))
    return shifts, angles
コード例 #6
0
def geometryFromMatrix(matrix, inverseTransform):
    from pwem.convert.transformations import translation_from_matrix, euler_from_matrix
    if inverseTransform:
        from numpy.linalg import inv
        matrix = inv(matrix)
        shifts = -translation_from_matrix(matrix)
    else:
        shifts = translation_from_matrix(matrix)
    angles = -numpy.rad2deg(euler_from_matrix(matrix, axes='szyz'))
    return shifts, angles
コード例 #7
0
 def convertInputStep(self):
     inputParts = self.inputParticles.get()
     self.rotDict, self.tiltDict, self.psiDict = {}, {}, {}
     for part in inputParts:
         alignment = part.getTransform()
         matrix = np.linalg.inv(alignment.getMatrix())
         angles = -np.rad2deg(tfs.euler_from_matrix(matrix, axes='szyz'))
         self.rotDict[part.getObjId()] = angles[0]
         self.tiltDict[part.getObjId()] = angles[1]
         self.psiDict[part.getObjId()] = angles[2]
コード例 #8
0
def geometryFromMatrix(matrix):
    """ Convert the transformation matrix to shifts and angles.
    :param matrix: input matrix
    :return: two lists, shifts and angles
    """
    matrix = np.linalg.inv(matrix)
    shifts = -transformations.translation_from_matrix(matrix)
    angles = -np.rad2deg(transformations.euler_from_matrix(matrix,
                                                           axes='szyz'))

    return shifts, angles
コード例 #9
0
def geometryFromMatrix(matrix, inverseTransform):
    """ Convert the transformation matrix to shifts and angles.
    :param matrix: input matrix
    :return: two lists, shifts and angles
    """
    from pwem.convert.transformations import translation_from_matrix, euler_from_matrix
    if inverseTransform:
        from numpy.linalg import inv
        matrix = inv(matrix)
        shifts = -translation_from_matrix(matrix)
    else:
        shifts = translation_from_matrix(matrix)
    angles = -numpy.rad2deg(euler_from_matrix(matrix, axes='szyz'))
    return shifts, angles
コード例 #10
0
    def _getTransformInfoFromSubtomo(subtomo, calcInv=True):
        angles = [0, 0, 0]
        shifts = [0, 0, 0]
        T = subtomo.getTransform()

        if T:  # Alignment performed before
            M = subtomo.getTransform().getMatrix()
            shifts = translation_from_matrix(M)
            if calcInv:
                shifts = -shifts
                M = np.linalg.inv(M)

            angles = -np.rad2deg(euler_from_matrix(M, axes='szyz'))

        return angles, shifts
コード例 #11
0
def geometryFromMatrix(matrix):
    from pwem.convert.transformations import translation_from_matrix, euler_from_matrix

    shifts = -1.0 * translation_from_matrix(matrix)
    angles = -1.0 * np.ones(3) * euler_from_matrix(matrix, axes='szyz')
    return shifts, angles
コード例 #12
0
def create_subparticles(particle, symmetry_matrices, subparticle_vector_list,
                        part_image_size, randomize, subparticles_total,
                        align_subparticles, handness, angpix):
    """ Obtain all subparticles from a given particle and set
    the properties of each such subparticle. """

    # Euler angles that take particle to the orientation of the model
    matrix_particle = inv(particle.getTransform().getMatrix())
    shifts, angles = geometryFromMatrix(matrix_particle)

    subparticles = []
    subparticles_total += 1
    symmetry_matrix_ids = range(1, len(symmetry_matrices) + 1)

    if randomize:
        # randomize the order of symmetry matrices, prevents preferred views
        random.shuffle(symmetry_matrix_ids)

    for subparticle_vector in subparticle_vector_list:
        matrix_from_subparticle_vector = subparticle_vector.get_matrix()

        for symmetry_matrix_id in symmetry_matrix_ids:
            # symmetry_matrix_id can be later written out to find out
            # which symmetry matrix created this subparticle
            symmetry_matrix = np.array(symmetry_matrices[symmetry_matrix_id -
                                                         1][0:3, 0:3])

            subpart = particle.clone()
            m = np.matmul(
                matrix_particle[0:3, 0:3],
                (np.matmul(symmetry_matrix.transpose(),
                           matrix_from_subparticle_vector.transpose())))
            angles_org = -1.0 * np.ones(3) * euler_from_matrix(m, 'szyz')
            if align_subparticles:
                angles = -1.0 * np.ones(3) * euler_from_matrix(m, 'szyz')
            else:
                m2 = np.matmul(matrix_particle[0:3, 0:3],
                               symmetry_matrix.transpose())
                angles = -1.0 * np.ones(3) * euler_from_matrix(m2, 'szyz')

            # subparticle origin
            d = subparticle_vector.get_length()
            x = -m[0, 2] * d + shifts[0]
            y = -m[1, 2] * d + shifts[1]
            z = -m[2, 2] * d

            # save the subparticle coordinates (integer part) relative to the
            # user given image size and as a small shift in the origin (decimal part)
            x_d, x_i = math.modf(x)
            y_d, y_i = math.modf(y)

            alignment = em.objects.data.Transform()
            alignmentOrg = em.objects.data.Transform()
            M = matrixFromGeometry(np.array([x_d, y_d, 0]), angles, True)
            MOrg = matrixFromGeometry(np.array([x_d, y_d, 0]), angles_org,
                                      True)
            alignment.setMatrix(M)
            alignmentOrg.setMatrix(MOrg)
            subpart._transorg = alignmentOrg.clone()
            subpart.setTransform(alignment)
            coord = Coordinate()
            coord.setObjId(None)
            coord.setX(int(part_image_size / 2) - x_i)
            coord.setY(int(part_image_size / 2) - y_i)
            coord.setMicId(particle.getObjId())

            if subpart.hasCTF():
                # Pixel to Angstrom
                z_ang = z * angpix
                if not handness:
                    z_ang *= -1
                ctf = subpart.getCTF()
                ctf.setDefocusU(subpart.getCTF().getDefocusU() + z_ang)
                ctf.setDefocusV(subpart.getCTF().getDefocusV() + z_ang)

            subpart.setCoordinate(coord)
            coord._subparticle = subpart.clone()
            subparticles.append(subpart)

    return subparticles