示例#1
0
 def _getOutParam(self):
     if getVersion() == "1.3" or getVersion() == "1.4":
         outParam = '--o '
     else:
         outParam = '--operate_out '
     
     outParam += self._getFileName("preprocess_particles_preffix")
     return outParam
示例#2
0
    def _getOutParam(self):
        if getVersion() == "1.3" or getVersion() == "1.4":
            outParam = '--o '
        else:
            outParam = '--operate_out '

        outParam += self._getFileName("preprocess_particles_preffix")
        return outParam
示例#3
0
    def _setArgs(self, args):
        from pyworkflow.em.packages.relion.convert import getVersion
        particles = self._sampleParticles()

        if self.maskDiameterA <= 0:
            maskDiameter = particles.getSamplingRate() * particles.getXDim()
        else:
            maskDiameter = self.maskDiameterA.get()

        args.update({
            '--i': self._getFileName('input_particles'),
            '--particle_diameter': maskDiameter,
            '--angpix': particles.getSamplingRate(),
            '--min_z': self.minZ.get()
        })

        if getVersion() == "2.0":
            args['--o'] = self._getFileName('output_star')
        else:
            args['--o'] = 'sorted'

        #if inputReferences is a volume, convert it to mrc here
        if self.isInputAutoRefine():
            args['--ref'] = self._getFileName('input_refvol')
        else:
            args['--ref'] = self._getFileName('input_refs')

        if self.doInvert:
            args['--invert'] = ''

        if self.ignoreCTFUntilFirstPeak:
            args['--ctf_intact_first_peak'] = ''

        if self.doCTF:
            args['--ctf'] = ''
    def testProtRelionRefine(self):
        from pyworkflow.em.packages.relion.convert import getVersion

        relNorm = self.newProtocol(ProtRelionPreprocessParticles)
        relNorm.inputParticles.set(self.protImport.outputParticles)
        relNorm.doNormalize.set(True)
        self.launchProtocol(relNorm)

        def _runRelionRefine(doGpu=False, label=''):

            print label
            relionRefine = self.newProtocol(ProtRelionRefine3D,
                                            doCTF=False,
                                            runMode=1,
                                            memoryPreThreads=1,
                                            maskDiameterA=340,
                                            symmetryGroup="d6",
                                            numberOfMpi=3,
                                            numberOfThreads=2)
            relionRefine.setObjLabel(label)
            relionRefine.inputParticles.set(relNorm.outputParticles)
            relionRefine.referenceVolume.set(self.protImportVol.outputVolume)

            if getVersion() == "2.0":
                relionRefine.doGpu.set(doGpu)

            self.launchProtocol(relionRefine)
            return relionRefine

        def _checkAsserts(relionProt):
            relionProt._initialize()  # Load filename templates
            dataSqlite = relionProt._getIterData(3)
            outImgSet = em.SetOfParticles(filename=dataSqlite)

            self.assertIsNotNone(relionNoGpu.outputVolume,
                                 "There was a problem with Relion autorefine")
            self.assertAlmostEqual(
                outImgSet[1].getSamplingRate(),
                relNorm.outputParticles[1].getSamplingRate(),
                "The sampling rate is wrong",
                delta=0.00001)

            self.assertAlmostEqual(outImgSet[1].getFileName(),
                                   relNorm.outputParticles[1].getFileName(),
                                   "The particles filenames are wrong")

        if getVersion() == "2.0":
            relionNoGpu = _runRelionRefine(False, "Relion auto-refine No GPU")
            _checkAsserts(relionNoGpu)

            environ = Environ(os.environ)
            cudaPath = environ.getFirst(('RELION_CUDA_LIB', 'CUDA_LIB'))

            if cudaPath is not None and os.path.exists(cudaPath):
                relionGpu = _runRelionRefine(True, "Relion auto-refine GPU")
                _checkAsserts(relionGpu)
        else:
            relionProt = _runRelionRefine(label="Run Relion auto-refine")
            _checkAsserts(relionProt)
    def testProtRelionClassify3D(self):
        from pyworkflow.em.packages.relion.convert import getVersion

        relionNormalize = self.newProtocol(ProtRelionPreprocessParticles)
        relionNormalize.inputParticles.set(self.protImport.outputParticles)
        relionNormalize.doNormalize.set(True)
        self.launchProtocol(relionNormalize)

        def _runRelionClassify3D(doGpu=False, label=''):

            print label
            relion3DClass = self.newProtocol(ProtRelionClassify3D,
                                             numberOfClasses=3,
                                             numberOfIterations=4,
                                             doCTF=False,
                                             runMode=1,
                                             maskDiameterA=320,
                                             numberOfMpi=2,
                                             numberOfThreads=2)

            relion3DClass.setObjLabel(label)
            relion3DClass.inputParticles.set(relionNormalize.outputParticles)
            relion3DClass.referenceVolume.set(self.protImportVol.outputVolume)

            if getVersion() == "2.0":
                relion3DClass.doGpu.set(doGpu)

            self.launchProtocol(relion3DClass)
            return relion3DClass

        def _checkAsserts(relionProt):
            self.assertIsNotNone(
                relionProt.outputClasses, "There was a "
                "problem with "
                "Relion 3D classify")

            for class3D in relionProt.outputClasses:
                self.assertTrue(class3D.hasAlignmentProj())

        if getVersion() == "2.0":
            relionNoGpu = _runRelionClassify3D(False,
                                               "Relion classify3D No GPU")
            _checkAsserts(relionNoGpu)

            environ = Environ(os.environ)
            cudaPath = environ.getFirst(('RELION_CUDA_LIB', 'CUDA_LIB'))

            if cudaPath is not None and os.path.exists(cudaPath):
                relionGpu = _runRelionClassify3D(True, "Relion classify3D GPU")
                _checkAsserts(relionGpu)
        else:
            relionProt = _runRelionClassify3D(label="Run Relion classify3D")
            _checkAsserts(relionProt)
    def testRelion2D(self):
        from pyworkflow.em.packages.relion.convert import getVersion

        def _runRelionClassify2D(doGpu=False, label=''):
            prot2D = self.newProtocol(ProtRelionClassify2D,
                                      doCTF=False,
                                      maskDiameterA=340,
                                      numberOfMpi=4,
                                      numberOfThreads=1)
            prot2D.numberOfClasses.set(4)
            prot2D.numberOfIterations.set(3)
            prot2D.inputParticles.set(self.protNormalize.outputParticles)
            prot2D.setObjLabel(label)

            if getVersion() == "2.0":
                prot2D.doGpu.set(doGpu)

            self.launchProtocol(prot2D)
            return prot2D

        def _checkAsserts(relionProt):

            self.assertIsNotNone(
                relionProt.outputClasses, "There was a problem with "
                "Relion 2D classify")

            partsPixSize = self.protNormalize.outputParticles.getSamplingRate()
            classsesPixSize = relionProt.outputClasses.getImages(
            ).getSamplingRate()
            self.assertAlmostEquals(
                partsPixSize, classsesPixSize,
                "There was a problem with the sampling rate "
                "of the particles")
            for class2D in relionProt.outputClasses:
                self.assertTrue(class2D.hasAlignment2D())

        if getVersion() == "2.0":
            relionNoGpu = _runRelionClassify2D(False,
                                               "Relion classify2D No GPU")
            _checkAsserts(relionNoGpu)

            environ = Environ(os.environ)
            cudaPath = environ.getFirst(('RELION_CUDA_LIB', 'CUDA_LIB'))

            if cudaPath is not None and os.path.exists(cudaPath):
                relionGpu = _runRelionClassify2D(True, "Relion classify2D GPU")
                _checkAsserts(relionGpu)
        else:
            relionProt = _runRelionClassify2D(label="Run Relion classify2D")
            _checkAsserts(relionProt)
        def _runRelionClassify2D(doGpu=False, label=''):
            prot2D = self.newProtocol(ProtRelionClassify2D,
                                      doCTF=False,
                                      maskDiameterA=340,
                                      numberOfMpi=4,
                                      numberOfThreads=1)
            prot2D.numberOfClasses.set(4)
            prot2D.numberOfIterations.set(3)
            prot2D.inputParticles.set(self.protNormalize.outputParticles)
            prot2D.setObjLabel(label)

            if getVersion() == "2.0":
                prot2D.doGpu.set(doGpu)

            self.launchProtocol(prot2D)
            return prot2D
        def _runRelionRefine(doGpu=False, label=''):

            print label
            relionRefine = self.newProtocol(ProtRelionRefine3D,
                                            doCTF=False,
                                            runMode=1,
                                            memoryPreThreads=1,
                                            maskDiameterA=340,
                                            symmetryGroup="d6",
                                            numberOfMpi=3,
                                            numberOfThreads=2)
            relionRefine.setObjLabel(label)
            relionRefine.inputParticles.set(relNorm.outputParticles)
            relionRefine.referenceVolume.set(self.protImportVol.outputVolume)

            if getVersion() == "2.0":
                relionRefine.doGpu.set(doGpu)

            self.launchProtocol(relionRefine)
            return relionRefine
        def _runRelionClassify3D(doGpu=False, label=''):

            print label
            relion3DClass = self.newProtocol(ProtRelionClassify3D,
                                             numberOfClasses=3,
                                             numberOfIterations=4,
                                             doCTF=False,
                                             runMode=1,
                                             maskDiameterA=320,
                                             numberOfMpi=2,
                                             numberOfThreads=2)

            relion3DClass.setObjLabel(label)
            relion3DClass.inputParticles.set(relionNormalize.outputParticles)
            relion3DClass.referenceVolume.set(self.protImportVol.outputVolume)

            if getVersion() == "2.0":
                relion3DClass.doGpu.set(doGpu)

            self.launchProtocol(relion3DClass)
            return relion3DClass