def _checkNewCTFs(self, micSet):
        """ Check for already computed CTF and update the output set. """
        newCTFs = []
        ctfDict = {}
        ctfSet = SetOfCTF(filename=self._getPath('ctfs.sqlite'))
        ctfSet.setMicrographs(self.inputMicrographs.get())

        for ctf in ctfSet:
            ctfDict[ctf.getObjId()] = True

        if ctfDict:  # it means there are previous ctfs computed
            ctfSet.loadAllProperties()
            if ctfSet.getSize():
                ctfSet.enableAppend()
        else:
            ctfSet.setStreamState(ctfSet.STREAM_OPEN)

        for micFn, micDir, mic in self._iterMicrographs(micSet):
            if (exists(self._getMicrographDone(micDir))
                    and not mic.getObjId() in ctfDict):
                ctf = self._createCtfModel(mic)
                ctfSet.append(ctf)
                newCTFs.append(mic.getObjId())

        return ctfSet, newCTFs
    def testCtfdiscrepancyWorkflow(self):
        # create one micrograph set
        fnMicSet = self.proj.getTmpPath("mics.sqlite")
        fnMic = self.proj.getTmpPath("mic.mrc")
        mic = Micrograph()
        mic.setFileName(fnMic)
        micSet = SetOfMicrographs(filename=fnMicSet)

        # create two CTFsets
        fnCTF1 = self.proj.getTmpPath("ctf1.sqlite")
        fnCTF2 = self.proj.getTmpPath("ctf2.sqlite")
        ctfSet1 = SetOfCTF(filename=fnCTF1)
        ctfSet2 = SetOfCTF(filename=fnCTF2)

        # create one fake micrographs image
        projSize = 32
        img = xmipp.Image()
        img.setDataType(xmipp.DT_FLOAT)
        img.resize(projSize, projSize)
        img.write(fnMic)

        # fill the sets
        for i in range(1, 4):
            mic = Micrograph()
            mic.setFileName(fnMic)
            micSet.append(mic)

            defocusU = 1000+10*i
            defocusV = 1000+i
            defocusAngle = i*10
            psdFile = "psd_1%04d" % i
            ctf = self._getCTFModel(defocusU,
                                    defocusV,
                                    defocusAngle,
                                    psdFile)
            ctf.setMicrograph(mic)
            ctfSet1.append(ctf)

            defocusU = 1000+20*i
            defocusV = 1000+i
            defocusAngle = i*20
            psdFile = "psd_2%04d" % i
            ctf = self._getCTFModel(defocusU,
                                    defocusV,
                                    defocusAngle,
                                    psdFile)
            ctf.setMicrograph(mic)
            ctfSet2.append(ctf)
        ctfSet1.write()
        ctfSet2.write()
        micSet.write()

        # import micrograph set
        args = {'importFrom': ProtImportMicrographs.IMPORT_FROM_SCIPION,
                'sqliteFile': fnMicSet,
                'amplitudConstrast': 0.1,
                'sphericalAberration': 2.,
                'voltage': 100,
                'samplingRate': 2.1
                }

        protMicImport = self.newProtocol(ProtImportMicrographs, **args)
        protMicImport.setObjLabel('import micrographs from sqlite ')
        self.launchProtocol(protMicImport)

        # import ctfsets
        protCTF1 = \
            self.newProtocol(ProtImportCTF,
                             importFrom=ProtImportCTF.IMPORT_FROM_SCIPION,
                             filesPath=fnCTF1)
        protCTF2 = \
            self.newProtocol(ProtImportCTF,
                             importFrom=ProtImportCTF.IMPORT_FROM_SCIPION,
                             filesPath=fnCTF2)
        protCTF1.inputMicrographs.set(protMicImport.outputMicrographs)
        protCTF2.inputMicrographs.set(protMicImport.outputMicrographs)
        protCTF1.setObjLabel('import ctfs from scipion_1 ')
        protCTF2.setObjLabel('import ctfs from scipion_2 ')
        self.launchProtocol(protCTF1)
        self.launchProtocol(protCTF2)

        # launch CTF discrepancy protocol
        protCtfDiscrepancy = self.newProtocol(XmippProtCTFDiscrepancy)
        protCtfDiscrepancy.inputCTF1.set(protCTF1.outputCTF)
        protCtfDiscrepancy.inputCTF2.set(protCTF2.outputCTF)
        protCtfDiscrepancy.setObjLabel('ctf discrepancy')
        self.launchProtocol(protCtfDiscrepancy)
        ctf0 = protCtfDiscrepancy.outputCTF.getFirstItem()
        resolution = int(ctf0.getResolution())
        defocusU = int(ctf0.getDefocusU())
        self.assertEqual(resolution, 2)
        self.assertEqual(defocusU, 1010)
Example #3
0
    def testCtfdiscrepancyWorkflow(self):
        # create one micrograph set
        fnMicSet = self.proj.getTmpPath("mics.sqlite")
        fnMic = self.proj.getTmpPath("mic.mrc")
        mic = Micrograph()
        mic.setFileName(fnMic)
        micSet = SetOfMicrographs(filename=fnMicSet)

        # create two CTFsets
        fnCTF1 = self.proj.getTmpPath("ctf1.sqlite")
        fnCTF2 = self.proj.getTmpPath("ctf2.sqlite")
        ctfSet1 = SetOfCTF(filename=fnCTF1)
        ctfSet2 = SetOfCTF(filename=fnCTF2)

        # create one fake micrographs image
        projSize = 32
        img = xmipp.Image()
        img.setDataType(xmipp.DT_FLOAT)
        img.resize(projSize, projSize)
        img.write(fnMic)

        # fill the sets
        for i in range(1, 4):
            mic = Micrograph()
            mic.setFileName(fnMic)
            micSet.append(mic)

            defocusU = 1000 + 10 * i
            defocusV = 1000 + i
            defocusAngle = i * 10
            psdFile = "psd_1%04d" % i
            ctf = self._getCTFModel(defocusU, defocusV, defocusAngle, psdFile)
            ctf.setMicrograph(mic)
            ctfSet1.append(ctf)

            defocusU = 1000 + 20 * i
            defocusV = 1000 + i
            defocusAngle = i * 20
            psdFile = "psd_2%04d" % i
            ctf = self._getCTFModel(defocusU, defocusV, defocusAngle, psdFile)
            ctf.setMicrograph(mic)
            ctfSet2.append(ctf)
        ctfSet1.write()
        ctfSet2.write()
        micSet.write()

        # import micrograph set
        args = {
            'importFrom': ProtImportMicrographs.IMPORT_FROM_SCIPION,
            'sqliteFile': fnMicSet,
            'amplitudConstrast': 0.1,
            'sphericalAberration': 2.,
            'voltage': 100,
            'samplingRate': 2.1
        }

        protMicImport = self.newProtocol(ProtImportMicrographs, **args)
        protMicImport.setObjLabel('import micrographs from sqlite ')
        self.launchProtocol(protMicImport)

        # import ctfsets
        protCTF1 = \
            self.newProtocol(ProtImportCTF,
                             importFrom=ProtImportCTF.IMPORT_FROM_SCIPION,
                             filesPath=fnCTF1)
        protCTF2 = \
            self.newProtocol(ProtImportCTF,
                             importFrom=ProtImportCTF.IMPORT_FROM_SCIPION,
                             filesPath=fnCTF2)
        protCTF1.inputMicrographs.set(protMicImport.outputMicrographs)
        protCTF2.inputMicrographs.set(protMicImport.outputMicrographs)
        protCTF1.setObjLabel('import ctfs from scipion_1 ')
        protCTF2.setObjLabel('import ctfs from scipion_2 ')
        self.launchProtocol(protCTF1)
        self.launchProtocol(protCTF2)

        # launch CTF discrepancy protocol
        protCtfDiscrepancy = self.newProtocol(XmippProtCTFDiscrepancy)
        protCtfDiscrepancy.inputCTF1.set(protCTF1.outputCTF)
        protCtfDiscrepancy.inputCTF2.set(protCTF2.outputCTF)
        protCtfDiscrepancy.setObjLabel('ctf discrepancy')
        self.launchProtocol(protCtfDiscrepancy)
        ctf0 = protCtfDiscrepancy.outputCTF.getFirstItem()
        resolution = int(ctf0.getResolution())
        defocusU = int(ctf0.getDefocusU())
        self.assertEqual(resolution, 2)
        self.assertEqual(defocusU, 1010)