def _relionTomoStar2Subtomograms(prot, outputSubTomogramsSet, tomoTable, invert):
    ih = ImageHandler()
    samplingRate = outputSubTomogramsSet.getSamplingRate()
    for row, inSubtomo in zip(tomoTable, prot.inputSubtomos.get()):
        subtomo = SubTomogram()
        coordinate3d = Coordinate3D()
        transform = Transform()
        origin = Transform()

        volname = row.get(TOMO_NAME, FILE_NOT_FOUND)
        subtomoFn = row.get(SUBTOMO_NAME, FILE_NOT_FOUND)

        subtomo.setVolName(managePath4Sqlite(volname))
        subtomo.setTransform(transform)
        subtomo.setAcquisition(TomoAcquisition())
        subtomo.setClassId(row.get('rlnClassNumber', 0))
        subtomo.setSamplingRate(samplingRate)
        subtomo.setCoordinate3D(coordinate3d)  # Needed to get later the tomogram pointer via getCoordinate3D()

        x = row.get(COORD_X, 0)
        y = row.get(COORD_Y, 0)
        z = row.get(COORD_Z, 0)
        tiltPrior = row.get(TILT_PRIOR, 0)
        psiPrior = row.get(PSI_PRIOR, 0)
        # ctf3d = row.get(CTF_MISSING_WEDGE, FILE_NOT_FOUND)
        coordinate3d = subtomo.getCoordinate3D()
        coordinate3d.setX(float(x), BOTTOM_LEFT_CORNER)
        coordinate3d.setY(float(y), BOTTOM_LEFT_CORNER)
        coordinate3d.setZ(float(z), BOTTOM_LEFT_CORNER)
        coordinate3d._3dcftMrcFile = inSubtomo.getCoordinate3D()._3dcftMrcFile  # Used for the ctf3d in Relion 3.0 (tomo)
        M = _getTransformMatrix(row, invert)
        transform.setMatrix(M)
        subtomo.setCoordinate3D(coordinate3d)
        subtomo._tiltPriorAngle = Float(tiltPrior)
        subtomo._psiPriorAngle = Float(psiPrior)

        # Set the origin and the dimensions of the current subtomogram
        x, y, z, n = ih.getDimensions(subtomoFn)
        zDim, _ = manageIhDims(subtomoFn, z, n)
        origin.setShifts(x / -2. * samplingRate, y / -2. * samplingRate, zDim / -2. * samplingRate)
        subtomo.setOrigin(origin)

        subtomo.setFileName(managePath4Sqlite(subtomoFn))
        # if subtomo is in a vesicle
        if 'tid_' in subtomoFn:
            vesicleId = subtomoFn.split('tid_')[1]
            vesicleId = vesicleId[0]
            scoor = subtomo.getCoordinate3D()
            scoor.setGroupId(vesicleId)
            subtomo.setCoordinate3D(scoor)

        # Add current subtomogram to the output set
        outputSubTomogramsSet.append(subtomo)
Exemple #2
0
def rowToAlignment(alignmentList, alignType):
    """
    is2D == True-> matrix is 2D (2D images alignment)
            otherwise matrix is 3D (3D volume alignment or projection)
    invTransform == True  -> for xmipp implies projection
        """
    # use all angles in 2D since we might have mirrors
    # is2D = alignType == em.ALIGN_2D
    inverseTransform = alignType == emcts.ALIGN_PROJ

    alignment = Transform()
    angles = numpy.zeros(3)
    shifts = numpy.zeros(3)
    shifts[0] = alignmentList[3]
    shifts[1] = alignmentList[4]
    shifts[2] = 0
    angles[0] = alignmentList[0]
    angles[1] = alignmentList[1]
    angles[2] = alignmentList[2]

    matrix = matrixFromGeometry(shifts, angles, inverseTransform)
    alignment.setMatrix(matrix)

    return alignment
    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)