def createOutputStep(self): outVolFn = self._getExtraPath("inputVolumeAligned.mrc") Ts = self.inputVolume.get().getSamplingRate() self.runJob("xmipp_image_header", "-i %s --sampling_rate %f" % (outVolFn, Ts)) outVol = Volume() outVol.setLocation(outVolFn) #set transformation matrix fhInputTranMat = self._getExtraPath('transformation-matrix.txt') transMatFromFile = np.loadtxt(fhInputTranMat) transformationMat = np.reshape(transMatFromFile, (4, 4)) transform = Transform() transform.setMatrix(transformationMat) outVol.setTransform(transform) outVol.setSamplingRate(Ts) outputArgs = {'outputVolume': outVol} self._defineOutputs(**outputArgs) self._defineSourceRelation(self.inputVolume, outVol) #particles.... outParticlesFn = self._getExtraPath('outputParticles.xmd') outputParticles = self._createSetOfParticles() outputParticles.copyInfo(self.inputParticles.get()) outputParticles.setAlignmentProj() readSetOfParticles(outParticlesFn, outputParticles) outputArgs = {'outputParticles': outputParticles} self._defineOutputs(**outputArgs) self._defineSourceRelation(self.inputParticles, outputParticles)
def createOutputStep(self): cleanPattern(self._getExtraPath('*.stk')) cleanPattern(self._getExtraPath('projectionsCudaCorr*')) inputParticles = self.inputSet.get() fnOutputParticles = self._getExtraPath('outConesParticles.xmd') outputSetOfParticles = self._createSetOfParticles() outputSetOfParticles.copyInfo(inputParticles) outputSetOfParticles.setAlignmentProj() Xdim = inputParticles.getXDim() newXdim = readInfoField(self._getExtraPath(), "size", emlib.MDL_XSIZE) Ts = readInfoField(self._getExtraPath(), "sampling", emlib.MDL_SAMPLINGRATE) if newXdim != Xdim: self.scaleFactor = Ts / inputParticles.getSamplingRate() self.iterMd = md.iterRows(fnOutputParticles, emlib.MDL_ITEM_ID) self.lastRow = next(self.iterMd) outputSetOfParticles.copyItems(inputParticles, updateItemCallback=self._updateItem) else: readSetOfParticles(fnOutputParticles, outputSetOfParticles) self._defineOutputs(outputParticles=outputSetOfParticles)
def _checkNewOutput(self): if getattr(self, 'finished', False): return self.finished = self.streamClosed and \ self.outputSize == self.inputSize streamMode = Set.STREAM_CLOSED if self.finished else Set.STREAM_OPEN newData = os.path.exists(self.fnOutputMd) lastToClose = self.finished and hasattr(self, 'outputParticles') if newData or lastToClose: outSet = self._loadOutputSet(SetOfParticles, 'outputParticles.sqlite') if newData: partsSet = self._createSetOfParticles() readSetOfParticles(self.fnOutputMd, partsSet) outSet.copyItems(partsSet) for item in partsSet: self._calculateSummaryValues(item) self._store() writeSetOfParticles(outSet.iterItems(orderBy='_xmipp_zScore'), self._getPath("images.xmd"), alignType=ALIGN_NONE) cleanPath(self.fnOutputMd) self._updateOutputSet('outputParticles', outSet, streamMode) if self.finished: # Unlock createOutputStep if finished all jobs outputStep = self._getFirstJoinStep() if outputStep and outputStep.isWaiting(): outputStep.setStatus(cons.STATUS_NEW)
def createOutput(self): imgSetOut = self._createSetOfAverages() imgSetOut.setSamplingRate(self.inputVolume.get().getSamplingRate()) imgSetOut.setAlignmentProj() readSetOfParticles(self._getPath("images.xmd"), imgSetOut) self._defineOutputs(outputReprojections=imgSetOut) self._defineSourceRelation(self.inputVolume, imgSetOut)
def createOutputStep(self): """create scipion output data from metadata""" outputSet = self._createSetOfParticles() imgSet = self.inputSet.get() outputSet.copyInfo(imgSet) readSetOfParticles(self._getExtraPath('output_imgs.xmd'), outputSet, extraLabels=[emlib.MDL_CTF_DEFOCUS_CHANGE]) self._defineOutputs(outputParticles=outputSet) self._defineSourceRelation(self.inputSet, outputSet)
def createOutputStep(self): """create output with the new particles""" self.ix = 0 inputParticles = self.inputParticles.get() outputSet = self._createSetOfParticles() outputSet.copyInfo(inputParticles) if self.boxSizeBool.get(): outputmd = self._getExtraPath("center_particles.xmd") else: outputmd = self._getExtraPath("crop_particles.xmd") readSetOfParticles(outputmd, outputSet) self._defineOutputs(outputParticles=outputSet) self._defineOutputs(shiftX=pwobj.Float(self.x), shiftY=pwobj.Float(self.y), shiftZ=pwobj.Float(self.z)) self._defineSourceRelation(inputParticles, outputSet)
def createOutputStep(self): # PARTICLES cleanPattern(self._getPath("*.sqlite")) partSet = self._createSetOfParticles() readSetOfParticles(self._getPath("particles.xmd"), partSet) inputSampling = self.inputCoordinates[0].get().getMicrographs( ).getSamplingRate() partSet.setSamplingRate(self._getDownFactor() * inputSampling) boxSize = self._getBoxSize() # COORDINATES writeSet = False if self.checkIfPrevRunIsCompatible("coords_"): writeSet = True if not "OR" in self.coordinatesDict: self.loadCoords(self._getExtraPath( self.CONSENSUS_COOR_PATH_TEMPLATE % 'TRUE'), 'OR', writeSet=False) coordSet = SetOfCoordinates( filename=self._getPath("coordinates.sqlite")) coordSet.copyInfo(self.coordinatesDict['OR']) coordSet.setBoxSize(boxSize) coordSet.setMicrographs(self.coordinatesDict['OR'].getMicrographs()) downFactor = self._getDownFactor() for part in partSet: coord = part.getCoordinate().clone() coord.scale(downFactor) deepZscoreLabel = '_xmipp_%s' % xmipp.label2Str( MD.MDL_ZSCORE_DEEPLEARNING1) setattr(coord, deepZscoreLabel, getattr(part, deepZscoreLabel)) coordSet.append(coord) coordSet.write() partSet.write() self._defineOutputs(outputCoordinates=coordSet) self._defineOutputs(outputParticles=partSet) for inSetOfCoords in self.inputCoordinates: self._defineSourceRelation(inSetOfCoords.get(), coordSet) self._defineSourceRelation(inSetOfCoords.get(), partSet)
def updateOutputs(mdFn, suffix): newData = os.path.exists(mdFn) lastToClose = getattr(self, 'finished', False) and \ hasattr(self, '%sParticles'%suffix) if newData or lastToClose: outSet = self._loadOutputSet(em.SetOfParticles, '%sParticles.sqlite' % suffix) if newData: partsSet = self._createSetOfParticles("AUX") readSetOfParticles(mdFn, partsSet) outSet.copyItems(partsSet, updateItemCallback=self._updateParticle, itemDataIterator=md.iterRows( mdFn, sortByLabel=md.MDL_ITEM_ID)) self.outputSize = self.outputSize + len(partsSet) self._updateOutputSet('%sParticles' % suffix, outSet, streamMode) cleanPath(mdFn)
def _checkNewInput(self): # Check if there are new particles to process from the input set partsFile = self.inputParticles.get().getFileName() partsSet = SetOfParticles(filename=partsFile) partsSet.loadAllProperties() self.SetOfParticles = [m.clone() for m in partsSet] self.streamClosed = partsSet.isStreamClosed() partsSet.close() partsSet = self._createSetOfParticles() readSetOfParticles(self._getExtraPath("allDone.xmd"), partsSet) newParts = any(m.getObjId() not in partsSet for m in self.SetOfParticles) outputStep = self._getFirstJoinStep() if newParts: fDeps = self._insertNewPartsSteps(self.insertedDict, self.SetOfParticles) if outputStep is not None: outputStep.addPrerequisites(*fDeps) self.updateSteps()
def updateOutputs(mdFn, suffix): """ Common use for accepted and discarded output. """ newData = os.path.exists(mdFn) # new data if partial out exists lastToClose = ( getattr(self, 'finished', False) and # last if fisished hasattr(self, '%sParticles' % suffix)) # and exists if newData or lastToClose: outSet = self._loadOutputSet(SetOfParticles, '%sParticles.sqlite' % suffix) if newData: partsSet = self._createSetOfParticles("AUX") readSetOfParticles(mdFn, partsSet) outSet.copyItems(partsSet, updateItemCallback=self._updateParticle, itemDataIterator=md.iterRows( mdFn, sortByLabel=md.MDL_ITEM_ID)) self.outputSize = self.outputSize + len(partsSet) self._updateOutputSet('%sParticles' % suffix, outSet, streamMode) cleanPath(mdFn)
def createOutputStep(self): inputParticles = self.inputParticles.get() inputClassName = str(inputParticles.getClassName()) key = 'output' + inputClassName.replace('SetOf', '') + '%02d' if not self.doGoldStandard.get(): fnDeformedParticles = self._getExtraPath('deformed_particles.xmd') outputSetOfParticles = self._createSetOfParticles() outputSetOfParticles.copyInfo(inputParticles) readSetOfParticles(fnDeformedParticles, outputSetOfParticles) self._defineOutputs(outputParticles=outputSetOfParticles) else: fnDeformedParticlesHalf1 = self._getExtraPath( 'deformed_particles_half1.xmd') outputSetOfParticlesHalf1 = self._createSetOfParticles(suffix="1") outputSetOfParticlesHalf1.copyInfo(inputParticles) readSetOfParticles(fnDeformedParticlesHalf1, outputSetOfParticlesHalf1) self._defineOutputs(**{key % 1: outputSetOfParticlesHalf1}) self._defineTransformRelation(inputParticles, outputSetOfParticlesHalf1) fnDeformedParticlesHalf2 = self._getExtraPath( 'deformed_particles_half2.xmd') outputSetOfParticlesHalf2 = self._createSetOfParticles(suffix="2") outputSetOfParticlesHalf2.copyInfo(inputParticles) readSetOfParticles(fnDeformedParticlesHalf2, outputSetOfParticlesHalf2) self._defineOutputs(**{key % 2: outputSetOfParticlesHalf2}) self._defineTransformRelation(inputParticles, outputSetOfParticlesHalf2)
def updateOutputs(mdFn, suffix): lastToClose = getattr(self, 'finished', False) and \ hasattr(self, '%sClasses' % suffix) newData = os.path.exists(mdFn) enableOut = {} if newData or lastToClose: outSet = self._loadOutputSet(SetOfAverages, '%sAverages.sqlite' % suffix) if newData: # if new data, we read it partsSet = self._createSetOfParticles("AUX") readSetOfParticles(mdFn, partsSet) # updating the enableCls dictionary # print(" - %s Averages:" % ("ACCEPTED" if suffix == 'output' else "DISCARTDED")) for part in partsSet: partId = part.getObjId() if partId not in self.enableCls: # this happends when a classifier give an empty class continue # - accept if we are in accepted and the current is accepted # - discard if we are in the discarted scope and any currentStatus = self.enableCls[partId] decision = suffix == 'output' and currentStatus == ACCEPTED enableOut[partId] = ACCEPTED if decision else DISCARDED # print("%d: %s -> %s" % (partId, currentStatus, decision)) # updating the Averages set outSet.copyItems(partsSet, updateItemCallback=self._updateParticle, itemDataIterator=md.iterRows( mdFn, sortByLabel=md.MDL_ITEM_ID)) self.outputSize = self.outputSize + len(partsSet) self._updateOutputSet('%sAverages' % suffix, outSet, streamMode) cleanPath(mdFn) return enableOut
def _checkNewOutput(self): if getattr(self, 'finished', False): return # Load previously done items (from text file) doneList = self._readDoneList() # Check for newly done items partsSet = self._createSetOfParticles() readSetOfParticles(self._getExtraPath("allDone.xmd"), partsSet) newDone = [ m.clone() for m in self.SetOfParticles if int(m.getObjId()) not in doneList ] self.finished = self.streamClosed and (len(doneList) == len(partsSet)) if newDone: self._writeDoneList(newDone) elif not self.finished: # If we are not finished and no new output have been produced # it does not make sense to proceed and updated the outputs # so we exit from the function here return if self.finished: # Unlock createOutputStep if finished all jobs outputStep = self._getFirstJoinStep() if outputStep and outputStep.isWaiting(): outputStep.setStatus(cons.STATUS_NEW)
def volumeAlignmentStep(self, inputVol, referenceVol, inputPartsMD, fnInputToRefLocal, fnInPartsNewAng): '''The input vol is modified towards the reference vol first by a global alignment and then by a local one''' '''The particles orientations are changed accordingly''' fnTransformMatGlobal = self._getExtraPath( 'transformation-matrix-Global.txt') fnTransformMatLocal = self._getExtraPath( 'transformation-matrix-Local.txt') alignArgsGlobal = "--i1 %s --i2 %s --dontScale --copyGeo %s" % ( referenceVol, inputVol, fnTransformMatGlobal) if (self.dofrm): alignArgsGlobal += " --frm --show_fit " else: alignArgsGlobal += " --rot 0.000000 360.000000 5.000000 --tilt 0.000000 180.000000 5.000000 --psi 0.000000 360.000000 5.000000 -x 0.000000 0.000000 1.000000 -y 0.000000 0.000000 1.000000 -z 0.000000 0.000000 1.000000" self.runJob('xmipp_volume_align', alignArgsGlobal, numberOfMpi=1, numberOfThreads=1) transMatFromFileFF = np.loadtxt(fnTransformMatGlobal) transformationArrayFF = np.reshape(transMatFromFileFF, (4, 4)) transformMatrixFF = np.matrix(transformationArrayFF) shifts, angles = geometryFromMatrix(transformMatrixFF, False) print("Global transformation to be applied: ") print(transformMatrixFF) print("Shifts and angles to be applied: ") print(shifts, angles) print("\n ") #We calculate one local alignment alignArgsLocal = "--i1 %s --i2 %s --apply %s --show_fit --local --dontScale --copyGeo %s " % ( referenceVol, inputVol, fnInputToRefLocal, fnTransformMatLocal) alignArgsLocal += "--rot %s --tilt %s --psi %s -x %s -y %s -z %s" % ( angles[0], angles[1], angles[2], shifts[0], shifts[1], shifts[2]) self.runJob('xmipp_volume_align', alignArgsLocal, numberOfMpi=1) transMatFromFileLocal = np.loadtxt(fnTransformMatLocal) transformationArrayLocal = np.reshape(transMatFromFileLocal, (4, 4)) transformMatrixLocal = np.matrix(transformationArrayLocal) shifts, angles = geometryFromMatrix(transformMatrixLocal, False) print(shifts, angles) print("\n ") #We calculate another local alignment alignArgsLocal = "--i1 %s --i2 %s --apply %s --show_fit --local --dontScale --copyGeo %s " % ( referenceVol, inputVol, fnInputToRefLocal, fnTransformMatLocal) alignArgsLocal += "--rot %s --tilt %s --psi %s -x %s -y %s -z %s" % ( angles[0], angles[1], angles[2], shifts[0], shifts[1], shifts[2]) self.runJob('xmipp_volume_align', alignArgsLocal, numberOfMpi=1) transMatFromFileLocal = np.loadtxt(fnTransformMatLocal) transformationArrayLocal = np.reshape(transMatFromFileLocal, (4, 4)) transformMatrixLocal = np.matrix(transformationArrayLocal) shifts, angles = geometryFromMatrix(transformMatrixLocal, False) print(shifts, angles) print("\n ") #And one more. alignArgsLocal = "--i1 %s --i2 %s --apply %s --show_fit --local --dontScale --copyGeo %s " % ( referenceVol, inputVol, fnInputToRefLocal, fnTransformMatLocal) alignArgsLocal += "--rot %s --tilt %s --psi %s -x %s -y %s -z %s" % ( angles[0], angles[1], angles[2], shifts[0], shifts[1], shifts[2]) self.runJob('xmipp_volume_align', alignArgsLocal, numberOfMpi=1) transMatFromFileLocal = np.loadtxt(fnTransformMatLocal) transformationArrayLocal = np.reshape(transMatFromFileLocal, (4, 4)) transformMatrixLocal = np.matrix(transformationArrayLocal) shifts, angles = geometryFromMatrix(transformMatrixLocal, False) print(shifts, angles) print("Local transformation to be applied: ") print(transformMatrixLocal) print("Shifts and angles to be applied: ") print(shifts, angles) print("\n ") inputParts = SetOfParticles(filename=':memory:') inputParts.copyInfo(self.inputParticles.get()) readSetOfParticles(inputPartsMD, inputParts) outputSet = SetOfParticles(filename=':memory:') for part in inputParts.iterItems(): part.getTransform().composeTransform( np.matrix(transformMatrixLocal)) outputSet.append(part) outputSet.copyInfo(inputParts) writeSetOfParticles(outputSet, fnInPartsNewAng)
def monitorStep(self): self._runPrerequisites = [] manager = Manager() project = manager.loadProject(self.getProject().getName()) percentage = [1.14, 2.29, 3.44, 5.74, 9.19, 14.94, 24.13, 39.08] numGlobalIters = len(percentage) + 2 self.consecutiveBimodal = 2 self.listConsecutiveBimodal = [] targetResolution = self.minimumTargetResolution.get() #Global iterations for i in range(numGlobalIters): self.convertInputStep(percentage, i) print("Target resolution - group %s: %f " % (chr(65 + i), float(targetResolution))) sys.stdout.flush() if i == 0: previousProtVol = self namePreviousVol = 'outputVolumesInit' else: previousProtVol = newHighRes namePreviousVol = 'outputVolume' newHighRes = project.newProtocol( XmippProtReconstructHighRes, objLabel='HighRes - group %s' % chr(65 + i), symmetryGroup=self.symmetryGroup.get(), numberOfIterations=1, particleRadius=self.particleRadius.get(), maximumTargetResolution=targetResolution, alignmentMethod=XmippProtReconstructHighRes.GLOBAL_ALIGNMENT, angularMaxShift=self.maxShift.get(), angularMinTilt=self.angularMinTilt.get(), angularMaxTilt=self.angularMaxTilt.get(), postAdHocMask=self.postAdHocMask.get(), postSymmetryWithinMask=self.postSymmetryWithinMask.get(), postSymmetryWithinMaskType=self.postSymmetryWithinMaskType.get( ), postSymmetryWithinMaskMask=self.postSymmetryWithinMaskMask.get( ), postSymmetryHelical=self.postSymmetryHelical.get(), postSymmetryHelicalRadius=self.postSymmetryHelicalRadius.get(), postSymmetryHelicalDihedral=self.postSymmetryHelicalDihedral. get(), postSymmetryHelicalMinRot=self.postSymmetryHelicalMinRot.get(), postSymmetryHelicalMaxRot=self.postSymmetryHelicalMaxRot.get(), postSymmetryHelicalMinZ=self.postSymmetryHelicalMinZ.get(), postSymmetryHelicalMaxZ=self.postSymmetryHelicalMaxZ.get(), postScript=self.postScript.get(), postSignificantDenoise=self.postSignificantDenoise.get(), postFilterBank=self.postFilterBank.get(), postLaplacian=self.postLaplacian.get(), postDeconvolve=self.postDeconvolve.get(), postSoftNeg=self.postSoftNeg.get(), postSoftNegK=self.postSoftNegK.get(), postDifference=self.postDifference.get(), numberOfMpi=self.numberOfMpi.get(), useGpu=self.useGpu.get(), gpuList=self.gpuList.get()) previousProtPart = self namePreviousParticles = 'outputParticles%s' % chr(65 + i) newHighRes.inputParticles.set(previousProtPart) newHighRes.inputParticles.setExtended(namePreviousParticles) newHighRes.inputVolumes.set(previousProtVol) newHighRes.inputVolumes.setExtended(namePreviousVol) project.scheduleProtocol(newHighRes) # Next schedule will be after this one self._runPrerequisites.append(newHighRes.getObjId()) self.childs.append(newHighRes) finishedIter = False while finishedIter == False: time.sleep(15) newHighRes = self._updateProtocol(newHighRes) if newHighRes.isFailed() or newHighRes.isAborted(): raise Exception('XmippProtReconstructHighRes has failed') if newHighRes.isFinished(): finishedIter = True fnDir = newHighRes._getExtraPath("Iter%03d" % 1) fnFSCs = open(self._getExtraPath('fnFSCs.txt'), 'a') fnFSCs.write(join(fnDir, "fsc.xmd") + " \n") fnFSCs.close() targetResolution = self.checkOutputsStep(newHighRes, i, False) targetResolution = max(targetResolution, self.maximumTargetResolution.get()) if i >= 7: #We are in the last three iterations #Check the output particles and remove all the disabled ones fnOutParticles = newHighRes._getPath('angles.xmd') params = '-i %s --query select "enabled==1"' % (fnOutParticles) self.runJob("xmipp_metadata_utilities", params, numberOfMpi=1) fnFinal = self._getExtraPath('inputLocalHighRes1.xmd') if i == 7: copy(fnOutParticles, fnFinal) else: params = ' -i %s --set union %s -o %s' % ( fnFinal, fnOutParticles, fnFinal) self.runJob("xmipp_metadata_utilities", params, numberOfMpi=1) if i == 9: outputinputSetOfParticles = self._createSetOfParticles( ) outputinputSetOfParticles.copyInfo( self.inputParticles.get()) readSetOfParticles(fnFinal, outputinputSetOfParticles) self._defineOutputs( outputParticlesLocal1=outputinputSetOfParticles) self._store(outputinputSetOfParticles) #Local iterations numLocalIters = 5 for i in range(numLocalIters): if i > 2: minPrevRes = prevTargetResolution if targetResolution > minPrevRes: print("Target resolution is stuck") sys.stdout.flush() break prevTargetResolution = targetResolution print("Target resolution - INPUT local %d: %f " % ((i + 1), float(targetResolution))) sys.stdout.flush() previousProtVol = newHighRes namePreviousVol = 'outputVolume' #calling highres local with the new input set newHighRes = project.newProtocol( XmippProtReconstructHighRes, objLabel='HighRes - local %d' % (i + 1), symmetryGroup=self.symmetryGroup.get(), numberOfIterations=1, particleRadius=self.particleRadius.get(), maximumTargetResolution=targetResolution, alignmentMethod=XmippProtReconstructHighRes.LOCAL_ALIGNMENT, angularMaxShift=self.maxShift.get(), angularMinTilt=self.angularMinTilt.get(), angularMaxTilt=self.angularMaxTilt.get(), postAdHocMask=self.postAdHocMask.get(), postSymmetryWithinMask=self.postSymmetryWithinMask.get(), postSymmetryWithinMaskType=self.postSymmetryWithinMaskType.get( ), postSymmetryWithinMaskMask=self.postSymmetryWithinMaskMask.get( ), postSymmetryHelical=self.postSymmetryHelical.get(), postSymmetryHelicalRadius=self.postSymmetryHelicalRadius.get(), postSymmetryHelicalDihedral=self.postSymmetryHelicalDihedral. get(), postSymmetryHelicalMinRot=self.postSymmetryHelicalMinRot.get(), postSymmetryHelicalMaxRot=self.postSymmetryHelicalMaxRot.get(), postSymmetryHelicalMinZ=self.postSymmetryHelicalMinZ.get(), postSymmetryHelicalMaxZ=self.postSymmetryHelicalMaxZ.get(), postScript=self.postScript.get(), postSignificantDenoise=self.postSignificantDenoise.get(), postFilterBank=self.postFilterBank.get(), postLaplacian=self.postLaplacian.get(), postDeconvolve=self.postDeconvolve.get(), postSoftNeg=self.postSoftNeg.get(), postSoftNegK=self.postSoftNegK.get(), postDifference=self.postDifference.get(), numberOfMpi=self.numberOfMpi.get(), useGpu=self.useGpu.get(), gpuList=self.gpuList.get()) newHighRes.inputParticles.set(self) namePreviousParticles = 'outputParticlesLocal%d' % (i + 1) newHighRes.inputParticles.setExtended(namePreviousParticles) newHighRes.inputVolumes.set(previousProtVol) newHighRes.inputVolumes.setExtended(namePreviousVol) project.scheduleProtocol(newHighRes, self._runPrerequisites) # Next schedule will be after this one self._runPrerequisites.append(newHighRes.getObjId()) self.childs.append(newHighRes) finishedIter = False while finishedIter == False: time.sleep(15) newHighRes = self._updateProtocol(newHighRes) if newHighRes.isFailed() or newHighRes.isAborted(): raise Exception('XmippProtReconstructHighRes has failed') if newHighRes.isFinished(): finishedIter = True fnDir = newHighRes._getExtraPath("Iter%03d" % 1) fnFSCs = open(self._getExtraPath('fnFSCs.txt'), 'a') fnFSCs.write(join(fnDir, "fsc.xmd") + " \n") fnFSCs.close() targetResolution = self.checkOutputsStep(newHighRes, numGlobalIters + i, True) targetResolution = max(targetResolution, self.maximumTargetResolution.get()) #Check the output particles and remove all the disabled ones fnOutParticles = newHighRes._getPath('angles.xmd') params = '-i %s --query select "enabled==1"' % (fnOutParticles) self.runJob("xmipp_metadata_utilities", params, numberOfMpi=1) fnFinal = self._getExtraPath('inputLocalHighRes%d.xmd' % (i + 2)) copy(fnOutParticles, fnFinal) if i > 1: #including the number of particles as stoppping criteria mdFinal = emlib.MetaData(fnFinal) Nfinal = mdFinal.size() Ninit = self.inputParticles.get().getSize() if Nfinal < Ninit * 0.3: print("Image set size too small", Nfinal, Ninit) sys.stdout.flush() break outputinputSetOfParticles = self._createSetOfParticles() outputinputSetOfParticles.copyInfo(self.inputParticles.get()) readSetOfParticles(fnFinal, outputinputSetOfParticles) result = { 'outputParticlesLocal%d' % (i + 2): outputinputSetOfParticles } self._defineOutputs(**result) self._store(outputinputSetOfParticles) #self = self._updateProtocol(self) self.createOutputStep(project)
def createOutputStep(self): fnTilted = self._getExtraPath("images_tilted.xmd") fnUntilted = self._getExtraPath("images_untilted.xmd") # Create outputs SetOfParticles both for tilted and untilted imgSetU = self._createSetOfParticles(suffix="Untilted") imgSetU.copyInfo(self.uMics) imgSetT = self._createSetOfParticles(suffix="Tilted") imgSetT.copyInfo(self.tMics) sampling = self.getMicSampling() if self._micsOther( ) else self.getCoordSampling() if self._doDownsample(): sampling *= self.downFactor.get() imgSetU.setSamplingRate(sampling) imgSetT.setSamplingRate(sampling) # set coords from the input, will update later if needed imgSetU.setCoordinates( self.inputCoordinatesTiltedPairs.get().getUntilted()) imgSetT.setCoordinates( self.inputCoordinatesTiltedPairs.get().getTilted()) # Read untilted and tilted particles on a temporary object (also disabled particles) imgSetAuxU = SetOfParticles(filename=':memory:') imgSetAuxU.copyInfo(imgSetU) readSetOfParticles(fnUntilted, imgSetAuxU, removeDisabled=False) imgSetAuxT = SetOfParticles(filename=':memory:') imgSetAuxT.copyInfo(imgSetT) readSetOfParticles(fnTilted, imgSetAuxT, removeDisabled=False) # calculate factor for coords scaling factor = 1 / self.samplingFactor if self._doDownsample(): factor /= self.downFactor.get() coordsT = self.getCoords().getTilted() # For each untilted particle retrieve micId from SetOfCoordinates untilted for imgU, coordU in izip(imgSetAuxU, self.getCoords().getUntilted()): # FIXME: Remove this check when sure that objIds are equal id = imgU.getObjId() if id != coordU.getObjId(): raise Exception( 'ObjIds in untilted img and coord are not the same!!!!') imgT = imgSetAuxT[id] coordT = coordsT[id] # If both particles are enabled append them if imgU.isEnabled() and imgT.isEnabled(): if self._micsOther() or self._doDownsample(): coordU.scale(factor) coordT.scale(factor) imgU.setCoordinate(coordU) imgSetU.append(imgU) imgT.setCoordinate(coordT) imgSetT.append(imgT) if self.doFlip: imgSetU.setIsPhaseFlipped(self.ctfUntilt.hasValue()) imgSetU.setHasCTF(self.ctfUntilt.hasValue()) imgSetT.setIsPhaseFlipped(self.ctfTilt.hasValue()) imgSetT.setHasCTF(self.ctfTilt.hasValue()) imgSetU.write() imgSetT.write() # Define output ParticlesTiltPair outputset = ParticlesTiltPair( filename=self._getPath('particles_pairs.sqlite')) outputset.setTilted(imgSetT) outputset.setUntilted(imgSetU) for imgU, imgT in izip(imgSetU, imgSetT): outputset.append(TiltPair(imgU, imgT)) outputset.setCoordsPair(self.inputCoordinatesTiltedPairs.get()) self._defineOutputs(outputParticlesTiltPair=outputset) self._defineSourceRelation(self.inputCoordinatesTiltedPairs, outputset)