Example #1
0
    def split(self, i):
        from pyworkflow.em.metadata.utils import getSize
        from math import ceil
        from random import randint
        from time import sleep
        sleep(randint(1, 10))
        fnDirCurrent = self._getExtraPath("Iter001")
        fnAngles = self._getExtraPath("Iter001/angles.xmd")
        fnSplit = self._getExtraPath('split%05d.xmd' % i)
        Nimages = getSize(fnAngles)
        Nsplit = ceil(Nimages * self.splitFraction.get())
        self.runJob("xmipp_metadata_utilities",
                    "-i %s -o %s --operate random_subset %d" %
                    (fnAngles, fnSplit, Nsplit),
                    numberOfMpi=1)

        fnVol = self._getExtraPath('split%05d.vol' % i)
        args = "-i %s -o %s --sym %s --weight" % (fnSplit, fnVol,
                                                  self.symmetryGroup)
        row = getFirstRow(fnAngles)
        if row.containsLabel(xmipp.MDL_CTF_DEFOCUSU) or row.containsLabel(
                xmipp.MDL_CTF_MODEL):
            TsCurrent = self.readInfoField(fnDirCurrent, "sampling",
                                           xmipp.MDL_SAMPLINGRATE)
            args += " --useCTF --sampling %f" % TsCurrent
            if self.phaseFlipped:
                args += " --phaseFlipped"
        self.runJob("xmipp_reconstruct_fourier", args, numberOfMpi=1)
        self.runJob(
            "xmipp_image_operate",
            "-i %s --minus %s" % (fnVol, join(fnDirCurrent, "volume.vol")))
    def reconstruct(self):
        iteration=1
        fnDirCurrent=self._getExtraPath("Iter%03d"%iteration)
        TsCurrent=self.readInfoField(fnDirCurrent,"sampling",xmipp.MDL_SAMPLINGRATE)
        fnAngles=join(fnDirCurrent,"angles.xmd")
        fnVol=join(fnDirCurrent,"volume.vol")

        args="-i %s -o %s --sym %s --weight"%(fnAngles,fnVol,self.symmetryGroup)
        row=getFirstRow(fnAngles)
        if row.containsLabel(xmipp.MDL_CTF_DEFOCUSU) or row.containsLabel(xmipp.MDL_CTF_MODEL):
            args+=" --useCTF --sampling %f"%TsCurrent
            if self.phaseFlipped:
                args+=" --phaseFlipped"
        self.runJob("xmipp_reconstruct_fourier",args)
Example #3
0
    def reconstruct(self):
        iteration = 1
        fnDirCurrent = self._getExtraPath("Iter%03d" % iteration)
        TsCurrent = self.readInfoField(fnDirCurrent, "sampling",
                                       xmipp.MDL_SAMPLINGRATE)
        fnAngles = join(fnDirCurrent, "angles.xmd")
        fnVol = join(fnDirCurrent, "volume.vol")

        args = "-i %s -o %s --sym %s --weight" % (fnAngles, fnVol,
                                                  self.symmetryGroup)
        row = getFirstRow(fnAngles)
        if row.containsLabel(xmipp.MDL_CTF_DEFOCUSU) or row.containsLabel(
                xmipp.MDL_CTF_MODEL):
            args += " --useCTF --sampling %f" % TsCurrent
            if self.phaseFlipped:
                args += " --phaseFlipped"
        self.runJob("xmipp_reconstruct_fourier", args)
 def split(self,i):
     from pyworkflow.em.metadata.utils import getSize
     from math import ceil
     from random import randint
     from time import sleep
     sleep(randint(1,10))
     fnDirCurrent=self._getExtraPath("Iter001")
     fnAngles=self._getExtraPath("Iter001/angles.xmd")
     fnSplit=self._getExtraPath('split%05d.xmd'%i)
     Nimages=getSize(fnAngles)
     Nsplit=ceil(Nimages*self.splitFraction.get())
     self.runJob("xmipp_metadata_utilities","-i %s -o %s --operate random_subset %d"%(fnAngles,fnSplit,Nsplit),numberOfMpi=1)
 
     fnVol=self._getExtraPath('split%05d.vol'%i)
     args="-i %s -o %s --sym %s --weight"%(fnSplit,fnVol,self.symmetryGroup)
     row=getFirstRow(fnAngles)
     if row.containsLabel(xmipp.MDL_CTF_DEFOCUSU) or row.containsLabel(xmipp.MDL_CTF_MODEL):
         TsCurrent=self.readInfoField(fnDirCurrent,"sampling",xmipp.MDL_SAMPLINGRATE)
         args+=" --useCTF --sampling %f"%TsCurrent
         if self.phaseFlipped:
             args+=" --phaseFlipped"
     self.runJob("xmipp_reconstruct_fourier",args,numberOfMpi=1)
     self.runJob("xmipp_image_operate","-i %s --minus %s"%(fnVol,join(fnDirCurrent,"volume.vol")))
Example #5
0
    def globalAssignment(self):
        iteration = 1
        fnDirCurrent = self._getExtraPath("Iter%03d" % iteration)
        makePath(fnDirCurrent)

        fnGlobal = join(fnDirCurrent, "globalAssignment")
        makePath(fnGlobal)

        targetResolution = self.significantMaxResolution.get()
        TsCurrent = max(self.TsOrig, targetResolution / 3)
        self.prepareImages(fnGlobal, TsCurrent)
        self.prepareReferences(fnGlobal, TsCurrent, targetResolution)

        # Calculate angular step at this resolution
        ResolutionAlignment = targetResolution
        newXdim = self.readInfoField(fnGlobal, "size", xmipp.MDL_XSIZE)
        angleStep = self.calculateAngStep(newXdim, TsCurrent,
                                          ResolutionAlignment)
        self.writeInfoField(fnGlobal, "angleStep", xmipp.MDL_ANGLE_DIFF,
                            float(angleStep))

        # Significant alignment
        alpha = 1 - 0.01 * self.significantSignificance.get()
        fnDirSignificant = join(fnGlobal, "significant")
        fnImgs = join(fnGlobal, "images.xmd")
        makePath(fnDirSignificant)

        # Create defocus groups
        row = getFirstRow(fnImgs)
        if row.containsLabel(xmipp.MDL_CTF_MODEL) or row.containsLabel(
                xmipp.MDL_CTF_DEFOCUSU):
            self.runJob("xmipp_ctf_group","--ctfdat %s -o %s/ctf:stk --pad 2.0 --sampling_rate %f --phase_flipped  --error 0.1 --resol %f"%\
                        (fnImgs,fnDirSignificant,TsCurrent,targetResolution),numberOfMpi=1)
            moveFile("%s/ctf_images.sel" % fnDirSignificant,
                     "%s/ctf_groups.xmd" % fnDirSignificant)
            cleanPath("%s/ctf_split.doc" % fnDirSignificant)
            md = xmipp.MetaData("numberGroups@%s" %
                                join(fnDirSignificant, "ctfInfo.xmd"))
            fnCTFs = "%s/ctf_ctf.stk" % fnDirSignificant
            numberGroups = md.getValue(xmipp.MDL_COUNT, md.firstObject())
            ctfPresent = True
        else:
            numberGroups = 1
            ctfPresent = False

        # Generate projections
        fnReferenceVol = join(fnGlobal, "volumeRef.vol")
        fnGallery = join(fnDirSignificant, "gallery.stk")
        fnGalleryMd = join(fnDirSignificant, "gallery.xmd")
        args="-i %s -o %s --sampling_rate %f --sym %s --min_tilt_angle %f --max_tilt_angle %f"%\
             (fnReferenceVol,fnGallery,angleStep,self.symmetryGroup,self.angularMinTilt.get(),self.angularMaxTilt.get())
        self.runJob("xmipp_angular_project_library", args)
        cleanPath(join(fnDirSignificant, "gallery_angles.doc"))
        moveFile(join(fnDirSignificant, "gallery.doc"), fnGalleryMd)

        fnAngles = join(fnGlobal, "anglesDisc.xmd")
        for j in range(1, numberGroups + 1):
            fnAnglesGroup = join(fnDirSignificant, "angles_group%02d.xmd" % j)
            if not exists(fnAnglesGroup):
                if ctfPresent:
                    fnGroup = "ctfGroup%06d@%s/ctf_groups.xmd" % (
                        j, fnDirSignificant)
                    fnGalleryGroup = join(fnDirSignificant,
                                          "gallery_group%06d.stk" % j)
                    fnGalleryGroupMd = join(fnDirSignificant,
                                            "gallery_group%06d.xmd" % j)
                    self.runJob("xmipp_transform_filter",
                                "-i %s -o %s --fourier binary_file %d@%s --save_metadata_stack %s --keep_input_columns"%\
                                (fnGalleryMd,fnGalleryGroup,j,fnCTFs,fnGalleryGroupMd))
                else:
                    fnGroup = fnImgs
                    fnGalleryGroupMd = fnGalleryMd
                args='-i %s --initgallery %s --odir %s --sym %s --iter 1 --alpha0 %f --alphaF %f --angularSampling %f --maxShift %d '\
                     '--minTilt %f --maxTilt %f --useImed --angDistance %f --dontReconstruct'%\
                     (fnGroup,fnGalleryGroupMd,fnDirSignificant,self.symmetryGroup,alpha,alpha,angleStep,\
                      round(self.angularMaxShift.get()*newXdim/100),self.angularMinTilt.get(),self.angularMaxTilt.get(),2*angleStep)
                self.runJob('xmipp_reconstruct_significant',
                            args,
                            numberOfMpi=self.numberOfThreads.get())
                moveFile(join(fnDirSignificant, "angles_iter001_00.xmd"),
                         join(fnDirSignificant, "angles_group%02d.xmd" % j))
                self.runJob("rm -f",
                            fnDirSignificant + "/images_*iter00?_*.xmd",
                            numberOfMpi=1)
                if j == 1:
                    copyFile(fnAnglesGroup, fnAngles)
                else:
                    self.runJob("xmipp_metadata_utilities",
                                "-i %s --set union %s" %
                                (fnAngles, fnAnglesGroup),
                                numberOfMpi=1)
        if ctfPresent:
            self.runJob("rm -f", fnDirSignificant + "/gallery*", numberOfMpi=1)
    def globalAssignment(self):
        iteration=1
        fnDirCurrent=self._getExtraPath("Iter%03d"%iteration)
        makePath(fnDirCurrent)

        fnGlobal=join(fnDirCurrent,"globalAssignment")
        makePath(fnGlobal)

        targetResolution=self.significantMaxResolution.get()
        TsCurrent=max(self.TsOrig,targetResolution/3)
        self.prepareImages(fnGlobal,TsCurrent)
        self.prepareReferences(fnGlobal,TsCurrent,targetResolution)

        # Calculate angular step at this resolution
        ResolutionAlignment=targetResolution
        newXdim=self.readInfoField(fnGlobal,"size",xmipp.MDL_XSIZE)
        angleStep=self.calculateAngStep(newXdim, TsCurrent, ResolutionAlignment)
        self.writeInfoField(fnGlobal,"angleStep",xmipp.MDL_ANGLE_DIFF,float(angleStep))
        
        # Significant alignment
        alpha=1-0.01*self.significantSignificance.get()
        fnDirSignificant=join(fnGlobal,"significant")
        fnImgs=join(fnGlobal,"images.xmd")
        makePath(fnDirSignificant)

        # Create defocus groups
        row=getFirstRow(fnImgs)
        if row.containsLabel(xmipp.MDL_CTF_MODEL) or row.containsLabel(xmipp.MDL_CTF_DEFOCUSU):
            self.runJob("xmipp_ctf_group","--ctfdat %s -o %s/ctf:stk --pad 2.0 --sampling_rate %f --phase_flipped  --error 0.1 --resol %f"%\
                        (fnImgs,fnDirSignificant,TsCurrent,targetResolution),numberOfMpi=1)
            moveFile("%s/ctf_images.sel"%fnDirSignificant,"%s/ctf_groups.xmd"%fnDirSignificant)
            cleanPath("%s/ctf_split.doc"%fnDirSignificant)
            md = xmipp.MetaData("numberGroups@%s"%join(fnDirSignificant,"ctfInfo.xmd"))
            fnCTFs="%s/ctf_ctf.stk"%fnDirSignificant
            numberGroups=md.getValue(xmipp.MDL_COUNT,md.firstObject())
            ctfPresent=True
        else:
            numberGroups=1
            ctfPresent=False

        # Generate projections
        fnReferenceVol=join(fnGlobal,"volumeRef.vol")
        fnGallery=join(fnDirSignificant,"gallery.stk")
        fnGalleryMd=join(fnDirSignificant,"gallery.xmd")
        args="-i %s -o %s --sampling_rate %f --sym %s --min_tilt_angle %f --max_tilt_angle %f"%\
             (fnReferenceVol,fnGallery,angleStep,self.symmetryGroup,self.angularMinTilt.get(),self.angularMaxTilt.get())
        self.runJob("xmipp_angular_project_library",args)
        cleanPath(join(fnDirSignificant,"gallery_angles.doc"))
        moveFile(join(fnDirSignificant,"gallery.doc"), fnGalleryMd)

        fnAngles=join(fnGlobal,"anglesDisc.xmd")
        for j in range(1,numberGroups+1):
            fnAnglesGroup=join(fnDirSignificant,"angles_group%02d.xmd"%j)
            if not exists(fnAnglesGroup):
                if ctfPresent:
                    fnGroup="ctfGroup%06d@%s/ctf_groups.xmd"%(j,fnDirSignificant)
                    fnGalleryGroup=join(fnDirSignificant,"gallery_group%06d.stk"%j)
                    fnGalleryGroupMd=join(fnDirSignificant,"gallery_group%06d.xmd"%j)
                    self.runJob("xmipp_transform_filter",
                                "-i %s -o %s --fourier binary_file %d@%s --save_metadata_stack %s --keep_input_columns"%\
                                (fnGalleryMd,fnGalleryGroup,j,fnCTFs,fnGalleryGroupMd))
                else:
                    fnGroup=fnImgs
                    fnGalleryGroupMd=fnGalleryMd
                args='-i %s --initgallery %s --odir %s --sym %s --iter 1 --alpha0 %f --alphaF %f --angularSampling %f --maxShift %d '\
                     '--minTilt %f --maxTilt %f --useImed --angDistance %f --dontReconstruct'%\
                     (fnGroup,fnGalleryGroupMd,fnDirSignificant,self.symmetryGroup,alpha,alpha,angleStep,\
                      round(self.angularMaxShift.get()*newXdim/100),self.angularMinTilt.get(),self.angularMaxTilt.get(),2*angleStep)
                self.runJob('xmipp_reconstruct_significant',args,numberOfMpi=self.numberOfThreads.get())
                moveFile(join(fnDirSignificant,"angles_iter001_00.xmd"),join(fnDirSignificant,"angles_group%02d.xmd"%j))
                self.runJob("rm -f",fnDirSignificant+"/images_*iter00?_*.xmd",numberOfMpi=1)
                if j==1:
                    copyFile(fnAnglesGroup, fnAngles)
                else:
                    self.runJob("xmipp_metadata_utilities","-i %s --set union %s"%(fnAngles,fnAnglesGroup),numberOfMpi=1)
        if ctfPresent:
            self.runJob("rm -f",fnDirSignificant+"/gallery*",numberOfMpi=1)