def convertInputStep(self):
        """ convert to Xmipp image model"""
        if not self._isSingleInput():
            writeSetOfVolumes(self.inputVolumes.get(), self.inputFn)

            if self.inputVolumes2.get() is not None:
                writeSetOfVolumes(self.inputVolumes2.get(),
                                  self._getSecondSetFn())
Ejemplo n.º 2
0
 def convertInputStep(self, outputFn):
     inputSet = self.inputSubtomograms.get()
     if inputSet.getFirstItem().getFileName().endswith('.mrc') or \
             inputSet.getFirstItem().getFileName().endswith('.map'):
         S = self._createSetOfSubTomograms()
         S.setSamplingRate(inputSet.getSamplingRate())
         for subtomo in self.inputSubtomograms.get():
             s = subtomo.clone()
             s.setFileName(subtomo.getFileName() + ':mrc')
             S.append(s)
         writeSetOfVolumes(S, outputFn, alignType=pwem.ALIGN_3D)
     else:
         writeSetOfVolumes(inputSet, outputFn, alignType=pwem.ALIGN_3D)
     return [outputFn]
Ejemplo n.º 3
0
    def createInputMd(self, vols):
        fnVols = self._getExtraPath('input_volumes.xmd')
        if self.copyAlignment:
            alignType = vols.getAlignment()
        else:
            alignType = ALIGN_NONE

        writeSetOfVolumes(vols, fnVols,
                          postprocessImageRow=self._postprocessVolumeRow,
                          alignType=alignType)
        if not vols.hasAlignment() or not self.copyAlignment:
            mdFn = md.MetaData(fnVols)
            mdFn.fillConstant(md.MDL_ANGLE_ROT, 0.)
            mdFn.fillConstant(md.MDL_ANGLE_TILT, 0.)
            mdFn.fillConstant(md.MDL_ANGLE_PSI, 0.)
            mdFn.fillConstant(md.MDL_SHIFT_X, 0.)
            mdFn.fillConstant(md.MDL_SHIFT_Y, 0.)
            mdFn.fillConstant(md.MDL_SHIFT_Z, 0.)
            mdFn.write(fnVols, md.MD_OVERWRITE)

        # set missing angles
        missType = ['wedge_y', 'wedge_x', 'pyramid', 'cone']
        missNum = self.missingDataType.get()
        missAng = self.missingAng.get()
        missDataFn = self._getExtraPath('wedges.xmd')
        missAngValues = str(missAng).strip().split()
        thetaY0, thetaYF, thetaX0, thetaXF = 0, 0, 0, 0
        mdFn = md.MetaData()

        if missNum == MISSING_WEDGE_X:
            thetaX0, thetaXF = missAngValues
        elif missNum == MISSING_WEDGE_Y:
            thetaY0, thetaYF = missAngValues
        elif missNum == MISSING_PYRAMID:
            thetaY0, thetaYF, thetaX0, thetaXF = missAngValues
        else:  # MISSING_CONE
            thetaY0 = missAngValues[0]

        for i in range(1, vols.getSize() + 1):
            row = md.Row()
            row.setValue(md.MDL_MISSINGREGION_NR, missNum + 1)
            row.setValue(md.MDL_MISSINGREGION_TYPE, missType[missNum])
            row.setValue(md.MDL_MISSINGREGION_THX0, float(thetaX0))
            row.setValue(md.MDL_MISSINGREGION_THXF, float(thetaXF))
            row.setValue(md.MDL_MISSINGREGION_THY0, float(thetaY0))
            row.setValue(md.MDL_MISSINGREGION_THYF, float(thetaYF))
            row.addToMd(mdFn)

        mdFn.write(missDataFn, md.MD_APPEND)
    def runCLTomo(self):
        fnVols = self._getPath('input_volumes.xmd')
        writeSetOfVolumes(self.inputVolumes.get(), fnVols)
        params= ' -i '            + fnVols + \
                ' --oroot '       + self._getExtraPath("results") + \
                ' --iter '        + str(self.numberOfIterations.get()) + \
                ' --nref '        + str(self.numberOfReferences.get()) + \
                ' --sym '         + self.symmetry.get() + \
                ' --maxFreq '     + str(self.maximumResolution.get()) + \
                ' --sparsity '    + str(self.sparsity.get()/100.0) + \
                ' --DWTsparsity ' + str(self.dwtSparsity.get()/100.0) + \
                ' --maxShiftX '   + str(self.maxShiftX.get()) + \
                ' --maxShiftY '   + str(self.maxShiftY.get()) + \
                ' --maxShiftZ '   + str(self.maxShiftZ.get()) + \
                ' --maxRot '      + str(self.maxRot.get()) + \
                ' --maxTilt '     + str(self.maxTilt.get()) + \
                ' --maxPsi '      + str(self.maxPsi.get())
        if self.doGenerateInitial.get():
            params += ' --nref0 ' + str(self.numberOfReferences0.get())
            if self.randomizeOrientation.get():
                params += ' --randomizeStartingOrientation'
        else:
            fnInitialVols = self._getExtraPath('intial_volumes.xmd')
            writeSetOfVolumes(self.referenceList.get(), fnInitialVols)
            params += ' --ref0 ' + fnInitialVols
        if self.inputMask.hasValue():
            params += ' --mask binary_file ' + self.inputMask.get(
            ).getLocation()
        if self.generateAligned.get():
            params += " --generateAlignedVolumes"
        if not self.align:
            params += " --dontAlign"

        self.runJob('xmipp_mpi_classify_CLTomo',
                    '%d %s' % (self.numberOfMpi.get(), params),
                    env=self.getCLTomoEnviron(),
                    numberOfMpi=1)
Ejemplo n.º 5
0
    def applyAlignStep(self):
        """Align subtomograms to be in the same orientation as the reference"""
        inputSet = self.inputSubtomos.get()
        outputFn = self._getExtraPath('input_subtomos.xmd')
        if inputSet.getFirstItem().getFileName().endswith('.mrc') or \
                inputSet.getFirstItem().getFileName().endswith('.map'):
            S = self._createSetOfSubTomograms()
            S.setSamplingRate(inputSet.getSamplingRate())
            for subtomo in inputSet:
                s = subtomo.clone()
                s.setFileName(subtomo.getFileName() + ':mrc')
                S.append(s)
            writeSetOfVolumes(S, outputFn, alignType=ALIGN_3D)
        else:
            writeSetOfVolumes(inputSet, outputFn, alignType=ALIGN_3D)

        # Window subtomograms twice their size
        windowedStk = self._getExtraPath('windowed_subtomograms.stk')
        self.runJob(
            'xmipp_transform_window',
            '-i %s -o %s --size %d --save_metadata_stack' %
            (outputFn, windowedStk, 2 * inputSet.getFirstItem().getDim()[0]),
            numberOfMpi=1)

        # Add input transform matrix to md generated by xmipp_transform_window
        mdWindow = md.MetaData(self._getExtraPath('windowed_subtomograms.xmd'))
        mdWindowTransform = md.MetaData()
        idList = list(inputSet.getIdSet())
        for row in md.iterRows(mdWindow):
            rowOut = md.Row()
            rowOut.copyFromRow(row)
            id = row.getValue(MDL_IMAGE)
            id = id.split('@')[0]
            id = id.strip('0')
            alignmentToRow(inputSet[(idList[int(id) - 1])].getTransform(),
                           rowOut, ALIGN_3D)
            rowOut.addToMd(mdWindowTransform)
        mdWindowTransform.write(
            self._getExtraPath("window_with_original_geometry.xmd"))

        # Align subtomograms
        self.runJob(
            'xmipp_transform_geometry',
            '-i %s -o %s --apply_transform --dont_wrap' %
            (self._getExtraPath("window_with_original_geometry.xmd"),
             self._getExtraPath('aligned_subtomograms.stk')))

        # Window subtomograms to their original size
        alignStk = self._getExtraPath('aligned_subtomograms.stk')
        outputStk = self._getExtraPath('output_subtomograms.stk')
        self.runJob('xmipp_transform_window',
                    '-i %s -o %s --size %d ' %
                    (alignStk, outputStk, inputSet.getFirstItem().getDim()[0]),
                    numberOfMpi=1)

        self.alignedSet = self._createSetOfSubTomograms()
        self.alignedSet.copyInfo(inputSet)
        inputMd = self._getExtraPath('output_subtomograms.stk')
        self.alignedSet.copyItems(inputSet,
                                  updateItemCallback=self._updateItemAlign,
                                  itemDataIterator=md.iterRows(
                                      inputMd, sortByLabel=md.MDL_ITEM_ID))
Ejemplo n.º 6
0
 def convertInputStep(self):
     """ convert if necessary"""
     if not self._isSingleInput():
         writeSetOfVolumes(self.inputVolumes.get(), self.inputFn)