예제 #1
0
    def _appendRctImages(self, particles):

        blockMd = "class%06d_images@%s" % (particles.getObjId(),
                                           self.rctClassesFn)

        classMd = xmipp.MetaData()

        uImages = self.inputParticlesTiltPair.get().getUntilted()
        tImages = self.inputParticlesTiltPair.get().getTilted()
        sangles = self.inputParticlesTiltPair.get().getCoordsPair().getAngles()

        uMics = self.inputParticlesTiltPair.get().getCoordsPair().getMicsPair(
        ).getUntilted()
        tMics = tImages.getCoordinates().getMicrographs()

        scaleFactor = uImages.getSamplingRate() / particles.getSamplingRate()

        for img in particles:
            imgId = img.getObjId()

            uImg = uImages[imgId]
            tImg = tImages[imgId]

            if uImg is None or tImg is None:
                print ">>> Warning, for id %d, tilted or untilted particle was not found. Ignored." % imgId
            else:
                objId = classMd.addObject()
                pairRow = XmippMdRow()
                pairRow.setValue(xmipp.MDL_IMAGE, getImageLocation(uImg))
                uCoord = uImg.getCoordinate()
                micId = uCoord.getMicId()
                uMic = uMics[micId]
                angles = sangles[micId]
                pairRow.setValue(xmipp.MDL_MICROGRAPH, uMic.getFileName())
                pairRow.setValue(xmipp.MDL_XCOOR, uCoord.getX())
                pairRow.setValue(xmipp.MDL_YCOOR, uCoord.getY())
                pairRow.setValue(xmipp.MDL_ENABLED, 1)
                pairRow.setValue(xmipp.MDL_ITEM_ID, long(imgId))
                pairRow.setValue(xmipp.MDL_REF, 1)

                alignment = img.getTransform()

                # Scale alignment by scaleFactor
                alignment.scale(scaleFactor)
                alignmentToRow(alignment, pairRow, alignType=ALIGN_2D)

                pairRow.setValue(xmipp.MDL_IMAGE_TILTED,
                                 getImageLocation(tImg))
                tMic = tMics[micId]
                pairRow.setValue(xmipp.MDL_MICROGRAPH_TILTED,
                                 tMic.getFileName())
                (angleY, angleY2, angleTilt) = angles.getAngles()
                pairRow.setValue(xmipp.MDL_ANGLE_Y, float(angleY))
                pairRow.setValue(xmipp.MDL_ANGLE_Y2, float(angleY2))
                pairRow.setValue(xmipp.MDL_ANGLE_TILT, float(angleTilt))

                pairRow.writeToMd(classMd, objId)

        classMd.write(blockMd, xmipp.MD_APPEND)
예제 #2
0
    def _appendRctImages(self, particles):
        blockMd = "class%06d_images@%s" % (particles.getObjId(),
                                           self.rctClassesFn)
        classMd = xmipp.MetaData()

        partPairs = self.inputParticlesTiltPair.get()
        uImages = partPairs.getUntilted()
        tImages = partPairs.getTilted()
        sangles = partPairs.getCoordsPair().getAngles()

        micPairs = partPairs.getCoordsPair().getMicsPair()
        uMics = micPairs.getUntilted()
        tMics = micPairs.getTilted()
        
        scaleFactor = uImages.getSamplingRate() / particles.getSamplingRate()
        
        for img in particles:
            imgId = img.getObjId()
                       
            uImg = uImages[imgId]
            tImg = tImages[imgId]
            
            if uImg is None or tImg is None:
                print (">>> Warning, for id %d, tilted or untilted particle "
                       "was not found. Ignored." % imgId)
            else:
                objId = classMd.addObject()
                pairRow = XmippMdRow()
                pairRow.setValue(xmipp.MDL_IMAGE, getImageLocation(uImg))
                uCoord = uImg.getCoordinate()
                micId = uCoord.getMicId()
                uMic = uMics[micId]
                angles = sangles[micId]
                pairRow.setValue(xmipp.MDL_MICROGRAPH, uMic.getFileName())
                pairRow.setValue(xmipp.MDL_XCOOR, uCoord.getX())
                pairRow.setValue(xmipp.MDL_YCOOR, uCoord.getY())
                pairRow.setValue(xmipp.MDL_ENABLED, 1)
                pairRow.setValue(xmipp.MDL_ITEM_ID, long(imgId))
                pairRow.setValue(xmipp.MDL_REF, 1)
    
                alignment = img.getTransform()
    
                # Scale alignment by scaleFactor
                alignment.scale(scaleFactor)
                alignmentToRow(alignment, pairRow, alignType=ALIGN_2D)
                                   
                pairRow.setValue(xmipp.MDL_IMAGE_TILTED, getImageLocation(tImg))
                tMic = tMics[micId]
                pairRow.setValue(xmipp.MDL_MICROGRAPH_TILTED, tMic.getFileName())
                (angleY, angleY2, angleTilt) = angles.getAngles()
                pairRow.setValue(xmipp.MDL_ANGLE_Y, float(angleY))
                pairRow.setValue(xmipp.MDL_ANGLE_Y2, float(angleY2))
                pairRow.setValue(xmipp.MDL_ANGLE_TILT, float(angleTilt))
                
                pairRow.writeToMd(classMd, objId)
        
        classMd.write(blockMd, xmipp.MD_APPEND)
예제 #3
0
    def _applyBfactor(self, e=None):
        bFactorFile = self.protocol._getPath('bfactor.txt')
        f = open(bFactorFile)
        values = map(float, f.readline().split())
        f.close()
        self.protocol.setStepsExecutor() # set default execution
        vol = self.protocol.inputVolume.get()
        volPath = getImageLocation(vol)
        maxres = 1. / sqrt(values[2])
        args = '-i %s ' % volPath
        pixelSize = vol.getSamplingRate()
        args += '--sampling %f ' % pixelSize
        args += '--maxres %f ' % maxres
        args += '--adhoc %f ' % -values[4]
        volName = os.path.basename(volPath)
        volOut = self.protocol._getPath(volName) 
        args += '-o %s ' % volOut
        self.protocol.runJob('xmipp_volume_correct_bfactor', args)
        
        #args = '-i %s -o %s' % (volPath, self.protocol._getPath(volName))
        #self.protocol.runJob('xmipp_image_convert', args)
        volSet = self.protocol._createSetOfVolumes()
        volSet.setSamplingRate(pixelSize)
        newVol = vol.clone()
        newVol.setObjId(None)
        newVol.setLocation(volOut)
        volSet.append(newVol)
        volSet.write()

        self.objectView(volSet).show()
예제 #4
0
    def _applyBfactor(self, e=None):
        bFactorFile = self.protocol._getPath('bfactor.txt')
        f = open(bFactorFile)
        values = map(float, f.readline().split())
        f.close()
        self.protocol.setStepsExecutor()  # set default execution
        vol = self.protocol.inputVolume.get()
        volPath = getImageLocation(vol)
        maxres = 1. / sqrt(values[2])
        args = '-i %s ' % volPath
        pixelSize = vol.getSamplingRate()
        args += '--sampling %f ' % pixelSize
        args += '--maxres %f ' % maxres
        args += '--adhoc %f ' % -values[4]
        volName = os.path.basename(volPath)
        volOut = self.protocol._getPath(volName)
        args += '-o %s ' % volOut
        self.protocol.runJob('xmipp_volume_correct_bfactor', args)

        #args = '-i %s -o %s' % (volPath, self.protocol._getPath(volName))
        #self.protocol.runJob('xmipp_image_convert', args)
        volSet = self.protocol._createSetOfVolumes()
        volSet.setSamplingRate(pixelSize)
        newVol = vol.clone()
        newVol.setObjId(None)
        newVol.setLocation(volOut)
        volSet.append(newVol)
        volSet.write()

        self.objectView(volSet).show()
    def _reconstructImages(self, particles, deps):
        """ Function to insert the step needed to reconstruct a class (or setOfParticles) """

        classNo = particles.getObjId()
        blockMd = "class%06d_images@%s" % (classNo, self.rctClassesFn)
                                                      
        classNameIn = blockMd
        classNameOut = self._getExtraPath("rct_images_%06d.xmd" % classNo)
        classVolumeOut = self._getPath("rct_%06d.vol" % classNo)
        
        if particles.hasRepresentative():
            classImage = getImageLocation(particles.getRepresentative())
        else:
            classImage = None
        
        reconStep = self._insertFunctionStep('reconstructClass', classNameIn, classNameOut, classImage, classVolumeOut, prerequisites=[deps])
        
        return reconStep        
    def _reconstructImages(self, particles, deps):
        """ Function to insert the step needed to reconstruct a
        class (or setOfParticles) """
        classNo = particles.getObjId()
        blockMd = "class%06d_images@%s" % (classNo, self.rctClassesFn)
        classNameIn = blockMd
        classNameOut = self._getExtraPath("rct_images_%06d.xmd" % classNo)
        classVolumeOut = self._getPath("rct_%06d.vol" % classNo)

        if particles.hasRepresentative():
            classImage = getImageLocation(particles.getRepresentative())
        else:
            classImage = None

        reconStep = self._insertFunctionStep('reconstructClass',
                                             classNameIn,
                                             classNameOut,
                                             classImage,
                                             classVolumeOut,
                                             prerequisites=[deps])
        return reconStep
예제 #7
0
    def _insertAllSteps(self):
        """ Mainly prepare the command line for call cl2d align program"""
        
        # Convert input images if necessary
        self.imgsFn = self._getExtraPath('images.xmd') 
        self._insertFunctionStep('convertInputStep')
        
        # Prepare arguments to call program: xmipp_classify_CL2D
        self._params = {'imgsFn': self.imgsFn, 
                        'extraDir': self._getExtraPath(),
                        'maxshift': self.maximumShift.get(),
                        'iter': self.numberOfIterations.get(),
                        }
        args = '-i %(imgsFn)s --odir %(extraDir)s --nref 1 --iter %(iter)d --maxShift %(maxshift)d'
        
        if self.useReferenceImage:
            args += " --ref0 " + getImageLocation(self.referenceImage.get())
        else:
            args += " --nref0 1"
        self._insertRunJobStep("xmipp_classify_CL2D", args % self._params)

        self._insertFunctionStep('createOutputStep')        
예제 #8
0
    def _insertAllSteps(self):
        """ Mainly prepare the command line for call cl2d align program"""
        
        # Convert input images if necessary
        self.imgsFn = self._getExtraPath('images.xmd') 
        self._insertFunctionStep('convertInputStep')
        
        # Prepare arguments to call program: xmipp_classify_CL2D
        self._params = {'imgsFn': self.imgsFn, 
                        'extraDir': self._getExtraPath(),
                        'maxshift': self.maximumShift.get(),
                        'iter': self.numberOfIterations.get(),
                        }
        args = '-i %(imgsFn)s --odir %(extraDir)s --nref 1 --iter %(iter)d --maxShift %(maxshift)d'
        
        if self.useReferenceImage:
            args += " --ref0 " + getImageLocation(self.referenceImage.get())
        else:
            args += " --nref0 1"
        self._insertRunJobStep("xmipp_classify_CL2D", args % self._params)

        self._insertFunctionStep('createOutputStep')