예제 #1
0
 def remove_projection_direction(self, coords, prev_point):
     prev_point = np.copy(prev_point)
     rot_matrix = euler_matrix(self.M[0], self.M[1], self.M[2], 'szyx')
     prev_point_rot = np.dot(rot_matrix, np.hstack([prev_point, 1]))
     new_point = np.dot(rot_matrix, np.hstack([coords, 1]))
     new_point[0] = prev_point_rot[0]
     coords = np.dot(np.linalg.inv(rot_matrix), new_point)
     return coords
예제 #2
0
    def compute_matrix(self):
        """ Compute rotation matrix to align Z axis to this vector. """

        if abs(self.vector[0]) < 0.00001 and abs(self.vector[1]) < 0.00001:
            rot = math.radians(0.00)
            tilt = math.radians(0.00)
        else:
            rot = math.atan2(self.vector[1], self.vector[0])
            tilt = math.acos(self.vector[2])

        psi = 0
        self.matrix = euler_matrix(-rot, -tilt, -psi, 'szyz')
def matrixFromGeometry(shifts, angles, inverseTransform):
    """ Create the transformation matrix from a given
    2D shifts in X and Y...and the 3 euler angles.
    """
    radAngles = -np.deg2rad(angles)
    M = tfs.euler_matrix(radAngles[0], radAngles[1], radAngles[2], 'szyz')
    if inverseTransform:
        M[:3, 3] = -shifts[:3]
        M = np.linalg.inv(M)
    else:
        M[:3, 3] = shifts[:3]

    return M
예제 #4
0
def matrixFromGeometry(shifts, angles):
    """ Create the transformation matrix from given
    2D shifts in X and Y and the 3 euler angles.
    :param shifts: input list of shifts
    :param angles: input list of angles
    :return matrix
    """
    radAngles = -np.deg2rad(angles)

    M = transformations.euler_matrix(radAngles[0], radAngles[1], radAngles[2],
                                     'szyz')
    M[:3, 3] = -shifts[:3]
    M = np.linalg.inv(M)

    return M
예제 #5
0
    def __setParticleTransform2D(self, particle, row):
        angles = self._angles
        shifts = self._shifts
        ips = self._invPixelSize

        def _get(label):
            return float(getattr(row, label, 0.))

        shifts[0] = _get('rlnOriginX') * ips
        shifts[1] = _get('rlnOriginY') * ips
        angles[2] = -_get('rlnAnglePsi')
        radAngles = -np.deg2rad(angles)
        M = tfs.euler_matrix(radAngles[0], radAngles[1], radAngles[2], 'szyz')
        M[:3, 3] = shifts[:3]
        particle.getTransform().setMatrix(M)
예제 #6
0
def matrixFromGeometry(shifts, angles, inverseTransform):
    """ Create the transformation matrix from a given
    2D shifts in X and Y...and the 3 euler angles.
    """
    from pwem.convert.transformations import euler_matrix
    from numpy import deg2rad
    radAngles = -deg2rad(angles)

    M = euler_matrix(radAngles[0], radAngles[1], radAngles[2], 'szyz')
    if inverseTransform:
        from numpy.linalg import inv
        M[:3, 3] = -shifts[:3]
        M = inv(M)
    else:
        M[:3, 3] = shifts[:3]

    return M
예제 #7
0
def _getTransformMatrix(row, invert):
    shiftx = row.get(SHIFTX, 0)
    shifty = row.get(SHIFTY, 0)
    shiftz = row.get(SHIFTZ, 0)
    tilt = row.get(TILT, 0)
    psi = row.get(PSI, 0)
    rot = row.get(ROT, 0)
    shifts = (float(shiftx), float(shifty), float(shiftz))
    angles = (float(rot), float(tilt), float(psi))
    radAngles = -np.deg2rad(angles)
    M = tfs.euler_matrix(radAngles[0], radAngles[1], radAngles[2], 'szyz')
    if invert:
        M[0, 3] = -shifts[0]
        M[1, 3] = -shifts[1]
        M[2, 3] = -shifts[2]
        M = np.linalg.inv(M)
    else:
        M[0, 3] = shifts[0]
        M[1, 3] = shifts[1]
        M[2, 3] = shifts[2]

    return M
예제 #8
0
    def __setParticleTransformProj(self, particle, row):
        angles = self._angles
        shifts = self._shifts
        ips = self._invPixelSize

        def _get(label):
            return float(getattr(row, label, 0.))

        shifts[0] = _get('rlnOriginX') * ips
        shifts[1] = _get('rlnOriginY') * ips
        shifts[2] = _get('rlnOriginZ') * ips

        angles[0] = _get('rlnAngleRot')
        angles[1] = _get('rlnAngleTilt')
        angles[2] = _get('rlnAnglePsi')

        radAngles = -np.deg2rad(angles)

        # TODO: jmrt: Maybe we should test performance and consider if keeping
        # TODO: the matrix and not creating one everytime will make things faster
        M = tfs.euler_matrix(radAngles[0], radAngles[1], radAngles[2], 'szyz')
        M[:3, 3] = -shifts[:3]
        M = np.linalg.inv(M)
        particle.getTransform().setMatrix(M)
    def createPhantomsStep(self):
        mwfilter = self.mwfilter.get()
        rotmin = self.rotmin.get()
        rotmax = self.rotmax.get()
        tiltmin = self.tiltmin.get()
        tiltmax = self.tiltmax.get()
        psimin = self.psimin.get()
        psimax = self.psimax.get()

        fnVol = self._getExtraPath("phantom000.vol")
        if self.option.get() == 0:
            inputVol = self.inputVolume.get()
            fnInVol = inputVol.getLocation()[1]
            dim = inputVol.getDim()
            if mwfilter:
                mwangle = self.mwangle.get()
                self.runJob(
                    "xmipp_transform_filter",
                    " --fourier wedge -%d %d 0 0 0 -i %s -o %s" %
                    (mwangle, mwangle, fnInVol, fnVol))
            else:
                self.runJob("xmipp_image_convert",
                            " -i %s -o %s" % (fnInVol, fnVol))
        else:
            desc = self.create.get()
            fnDescr = self._getExtraPath("phantom.descr")
            fhDescr = open(fnDescr, 'w')
            fhDescr.write(desc)
            fhDescr.close()
            dim = [desc.split()[0], desc.split()[1], desc.split()[2]]
            self.runJob("xmipp_phantom_create",
                        " -i %s -o %s" % (fnDescr, fnVol))
            if mwfilter:
                mwangle = self.mwangle.get()
                self.runJob(
                    "xmipp_transform_filter",
                    " --fourier wedge -%d %d 0 0 0 -i %s -o %s" %
                    (mwangle, mwangle, fnVol, fnVol))

        self.outputSet = self._createSetOfSubTomograms(
            self._getOutputSuffix(SetOfSubTomograms))
        self.outputSet.setDim(dim)
        self.outputSet.setSamplingRate(self.sampling.get())

        coordsBool = self.coords.get()
        if coordsBool:
            tomos = self.tomos.get()
            tomo = tomos.getFirstItem()
            tomoDim = tomo.getDim()
            self.coords = self._createSetOfCoordinates3D(tomos)

        subtomobase = SubTomogram()
        acq = TomoAcquisition()
        subtomobase.setAcquisition(acq)
        subtomobase.setLocation(fnVol)
        subtomobase.setSamplingRate(self.sampling.get())
        transformBase = Transform()
        transformBase.setMatrix(np.identity(4))
        subtomobase.setTransform(transformBase)
        if coordsBool:
            coor = Coordinate3D()
            coor.setVolume(tomo)
            coor.setX(np.random.randint(0, tomoDim[0]),
                      const.BOTTOM_LEFT_CORNER)
            coor.setY(np.random.randint(0, tomoDim[1]),
                      const.BOTTOM_LEFT_CORNER)
            coor.setZ(np.random.randint(0, tomoDim[2]),
                      const.BOTTOM_LEFT_CORNER)
            subtomobase.setCoordinate3D(coor)
            subtomobase.setVolName(tomo.getFileName())
            self.coords.append(coor)
            self.coords.setBoxSize(subtomobase.getDim()[0])
        self.outputSet.append(subtomobase)

        for i in range(int(self.nsubtomos.get()) - 1):
            fnPhantomi = self._getExtraPath("phantom%03d.vol" % int(i + 1))
            rot = np.random.randint(rotmin, rotmax)
            tilt = np.random.randint(tiltmin, tiltmax)
            psi = np.random.randint(psimin, psimax)
            self.runJob(
                "xmipp_transform_geometry",
                " -i %s -o %s --rotate_volume euler %d %d %d " %
                (fnVol, fnPhantomi, rot, tilt, psi))

            if mwfilter:
                self.runJob(
                    "xmipp_transform_filter",
                    " --fourier wedge -%d %d 0 0 0 -i %s -o %s" %
                    (mwangle, mwangle, fnPhantomi, fnPhantomi))

            subtomo = SubTomogram()
            subtomo.setAcquisition(acq)
            subtomo.setLocation(fnPhantomi)
            subtomo.setSamplingRate(self.sampling.get())
            A = euler_matrix(np.deg2rad(psi), np.deg2rad(tilt),
                             np.deg2rad(rot), 'szyz')
            transform = Transform()
            transform.setMatrix(A)
            subtomo.setTransform(transform)
            if coordsBool:
                coor = Coordinate3D()
                coor.setVolume(tomo)
                coor.setX(np.random.randint(0, tomoDim[0]),
                          const.BOTTOM_LEFT_CORNER)
                coor.setY(np.random.randint(0, tomoDim[1]),
                          const.BOTTOM_LEFT_CORNER)
                coor.setZ(np.random.randint(0, tomoDim[2]),
                          const.BOTTOM_LEFT_CORNER)
                subtomo.setCoordinate3D(coor)
                subtomo.setVolName(tomo.getFileName())
                self.coords.append(coor)
            self.outputSet.append(subtomo)
        if coordsBool:
            self.outputSet.setCoordinates3D(self.coords)