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): lastIter = self.getLastIteration(1) Ts = self.inputSet.get().getSamplingRate() # To recover the original size of the volume if it was changed fnVol = self.getIterVolume(lastIter) Xdim = self.inputSet.get().getDimensions()[0] if self.useMaxRes and self.newXdim != Xdim: self.runJob('xmipp_image_resize', "-i %s --fourier %d" % (fnVol, Xdim), numberOfMpi=1) fnMrc = fnVol.replace(".vol", ".mrc") self.runJob("xmipp_image_convert", "-i %s -o %s -t vol" % (fnVol, fnMrc), numberOfMpi=1) cleanPath(fnVol) self.runJob("xmipp_image_header", "-i %s --sampling_rate %f" % (fnMrc, Ts), numberOfMpi=1) vol = Volume() vol.setObjComment('significant volume 1') vol.setLocation(fnMrc) vol.setSamplingRate(Ts) self._defineOutputs(outputVolume=vol) self._defineSourceRelation(self.inputSet, vol)
def projectZStep(self): input = self.input.get() x, y, z = input.getDim() dir = self.dirParam.get() if self.rangeParam.get() == 1: cropParam = self.cropParam.get() fnProj = self._getExtraPath("projections.mrcs") lib.createEmptyFile(fnProj, x, y, 1, input.getSize()) for i, subtomo in enumerate(input.iterItems()): fn = subtomo.getLocation() if fn[1].endswith('.mrc'): fn = list(fn) fn[1] += ':mrc' fn = tuple(fn) subtomo.setFileName(fn[1]) vol = Volume() vol.setLocation('%d@%s' % fn) vol = ih().read(vol.getLocation()) img = ih().createImage() if self.radAvg.get(): img = vol.radialAverageAxis() else: volData = vol.getData() proj = np.empty([x, y]) if dir == 0: if self.rangeParam.get() == 1: volData = volData[:, :, int(x/2 - cropParam):int(x/2 + cropParam):1] for zi in range(z): for yi in range(y): proj[zi, yi] = np.sum(volData[zi, yi, :]) elif dir == 1: if self.rangeParam.get() == 1: volData = volData[:, int(x/2 - cropParam):int(x/2 + cropParam):1, :] for zi in range(z): for xi in range(x): proj[zi, xi] = np.sum(volData[zi, :, xi]) elif dir == 2: if self.rangeParam.get() == 1: volData = volData[int(x/2 - cropParam):int(x/2 + cropParam):1, :, :] for xi in range(x): for yi in range(y): proj[xi, yi] = np.sum(volData[:, yi, xi]) img.setData(proj) img.write('%d@%s' % (i+1, fnProj))
def createOutputStep(self): vol = Volume() vol.setLocation(self._getOutputVol()) sampling = self.inputVolumes.get().getSamplingRate() vol.setSamplingRate(sampling) # ccp4header = Ccp4Header(self._getOutputVol(), readHeader=True) t = Transform() x, y, z = ccp4header.getOrigin() # origin output vol # coordinates t.setShifts(x, y, z) vol.setOrigin(t) # self._defineOutputs(outputVolume=vol) self._defineSourceRelation(self.inputVolumes, self.outputVolume)
def createOutputStep(self): volumesSet = self._createSetOfVolumes() volumesSet.setSamplingRate(self.inputVolume.get().getSamplingRate()) for i in range(self.iteration): vol = Volume() vol.setOrigin(self.inputVolume.get().getOrigin(True)) if (self.iteration > (i + 1)): vol.setLocation( i, self._getExtraPath('sharpenedMap_%d.mrc' % (i + 1))) vol.setObjComment("Sharpened Map, \n Epoch %d" % (i + 1)) else: vol.setLocation(i, self._getExtraPath('sharpenedMap_last.mrc')) vol.setObjComment("Sharpened Map, \n Epoch last") volumesSet.append(vol) self._defineOutputs(outputVolumes=volumesSet) self._defineSourceRelation(self.inputVolume, volumesSet)
def createOutputStep(self): Ts = self.inputReference.get().getSamplingRate() vols = [] idx = 1 for vol in self._iterInputVolumes(): outVol = Volume() fnOutVol = self._getExtraPath("vol%02d.mrc" % idx) outVol.setLocation(fnOutVol) outVol.setObjComment(vol.getObjComment()) #set transformation matrix fhInputTranMat = self._getExtraPath( 'transformation-matrix_vol%06d.txt' % idx) transMatFromFile = np.loadtxt(fhInputTranMat) transformationMat = np.reshape(transMatFromFile, (4, 4)) transform = Transform() transform.setMatrix(transformationMat) outVol.setTransform(transform) vols.append(outVol) # Set the sampling rate in the mrc header self.runJob("xmipp_image_header", "-i %s --sampling_rate %f" % (fnOutVol, Ts)) idx += 1 if len(vols) > 1: volSet = self._createSetOfVolumes() volSet.setSamplingRate(Ts) for vol in vols: volSet.append(vol) outputArgs = {'outputVolumes': volSet} else: vols[0].setSamplingRate(Ts) outputArgs = {'outputVolume': vols[0]} self._defineOutputs(**outputArgs) if len(vols) > 1: for pointer in self.inputVolumes: self._defineSourceRelation(pointer, outputArgs['outputVolumes']) else: for pointer in self.inputVolumes: self._defineSourceRelation(pointer, outputArgs['outputVolume'])
def createOutputStep(self): if self.targetResolution.get() != 3.0: correctionFactor = self.targetResolution.get() / 3.0 with open(self._getExtraPath('Volumes_clnm.txt'), 'r') as fid: lines = fid.readlines() basisParams = np.fromstring(lines[0], sep=' ') if self.Rmax.get() != 0: basisParams[2] = self.Rmax.get() else: basisParams[2] = self.refVolume.get().getDim()[0] / 2 clnm = np.fromstring(lines[1], sep=' ') * correctionFactor with open(self._getExtraPath('Volumes_clnm.txt'), 'w') as fid: fid.write(' '.join(map(str, basisParams)) + "\n") fid.write(' '.join(map(str, clnm)) + "\n") vol = Volume() vol.setLocation(self._getFileName('fnOutVol')) vol.setSamplingRate(self.newTs) self._defineOutputs(outputVolume=vol) self._defineSourceRelation(self.inputVolume, vol)
def createOutput(self): inputParticles = self.directionalClasses.get() Ts = inputParticles.getSamplingRate() volumesSet = self._createSetOfVolumes() volumesSet.setSamplingRate(Ts) for i in range(2): vol = Volume() fnVol = self._getExtraPath("split_v%d.vol" % (i + 1)) fnMrc = self._getExtraPath("split_v%d.mrc" % (i + 1)) self.runJob("xmipp_image_convert", "-i %s -o %s -t vol" % (fnVol, fnMrc), numberOfMpi=1) self.runJob("xmipp_image_header", "-i %s --sampling_rate %f" % (fnMrc, Ts), numberOfMpi=1) cleanPath(fnVol) vol.setLocation(1, fnMrc) volumesSet.append(vol) self._defineOutputs(outputVolumes=volumesSet) self._defineSourceRelation(inputParticles, volumesSet)
def _defineOutputVol(name, fn): vol = Volume() vol.copyInfo(self.inputVolume.get()) vol.setLocation(fn) self._defineOutputs(**{name: vol}) self._defineTransformRelation(self.inputVolume, vol)
def createOutputStep(self): inputParticles = self.inputParticles.get() if not self._useSeveralClasses(): newTs = inputParticles.getSamplingRate() else: newTs = readInfoField(self._getExtraPath(), "sampling", emlib.MDL_SAMPLINGRATE) self.mdClasses = emlib.MetaData(self._getDirectionalClassesFn()) self.mdImages = emlib.MetaData(self._getDirectionalImagesFn()) classes2D = self._createSetOfClasses2D(inputParticles) classes2D.getImages().setSamplingRate(newTs) self.averageSet = self._createSetOfAverages() self.averageSet.copyInfo(inputParticles) self.averageSet.setAlignmentProj() self.averageSet.setSamplingRate(newTs) # Let's use a SetMdIterator because it should be less particles # in the metadata produced than in the input set iterator = md.SetMdIterator(self.mdImages, sortByLabel=md.MDL_ITEM_ID, updateItemCallback=self._updateParticle, skipDisabled=True) fnHomogeneous = self._getExtraPath("images_homogeneous.xmd") if exists(fnHomogeneous): homogeneousSet = self._createSetOfParticles() homogeneousSet.copyInfo(inputParticles) homogeneousSet.setSamplingRate(newTs) homogeneousSet.setAlignmentProj() self.iterMd = md.iterRows(fnHomogeneous, md.MDL_PARTICLE_ID) self.lastRow = next(self.iterMd) homogeneousSet.copyItems( inputParticles, updateItemCallback=self._updateHomogeneousItem) self._defineOutputs(outputHomogeneous=homogeneousSet) self._defineSourceRelation(self.inputParticles, homogeneousSet) classes2D.classifyItems(updateItemCallback=iterator.updateItem, updateClassCallback=self._updateClass) self._defineOutputs(outputClasses=classes2D) self._defineOutputs(outputAverages=self.averageSet) self._defineSourceRelation(self.inputParticles, classes2D) self._defineSourceRelation(self.inputParticles, self.averageSet) if self.splitVolume and self.directionalClasses.get() > 1: volumesSet = self._createSetOfVolumes() volumesSet.setSamplingRate(newTs) for i in range(2): fnVol = self._getExtraPath("split_v%d.vol" % (i + 1)) fnMrc = self._getExtraPath("split_v%d.mrc" % (i + 1)) self.runJob("xmipp_image_convert", "-i %s -o %s -t vol" % (fnVol, fnMrc), numberOfMpi=1) self.runJob("xmipp_image_header", "-i %s --sampling_rate %f" % (fnMrc, newTs), numberOfMpi=1) cleanPath(fnVol) vol = Volume() vol.setLocation(1, fnMrc) volumesSet.append(vol) self._defineOutputs(outputVolumes=volumesSet) self._defineSourceRelation(inputParticles, volumesSet)
def createOutputStep(self): inputParticles = self.inputParticles.get() # if not self._useSeveralClasses(): # newTs = inputParticles.getSamplingRate() # else: # newTs = readInfoField(self._getExtraPath(), "sampling", # xmipp.MDL_SAMPLINGRATE) self.mdClasses = emlib.MetaData(self._getDirectionalClassesFn()) self.mdImages = emlib.MetaData(self._getDirectionalImagesFn()) origTs = inputParticles.getSamplingRate() lastTs = readInfoField(self._getExtraPath(), "sampling", emlib.MDL_SAMPLINGRATE) if origTs != lastTs: newXdim = inputParticles.getXDim() self.runJob( "xmipp_image_resize", "-i %s -o %s --save_metadata_stack %s --fourier %d" % (self._getDirectionalClassesFn(), self._getPath("aux_directional_local_classes.stk"), self._getPath("aux_directional_classes.xmd"), newXdim), numberOfMpi=1) from shutil import copy copy(self._getPath("aux_directional_local_classes.stk"), self._getPath("directional_local_classes.stk")) copy(self._getPath("aux_directional_classes.xmd"), self._getPath("directional_classes.xmd")) cleanPattern(self._getPath("aux_directional*")) classes2D = self._createSetOfClasses2D(inputParticles) #classes2D.getImages().setSamplingRate(newTs) classes2D.getImages().setSamplingRate(origTs) self.averageSet = self._createSetOfAverages() self.averageSet.copyInfo(inputParticles) self.averageSet.setAlignmentProj() #self.averageSet.setSamplingRate(newTs) self.averageSet.setSamplingRate(origTs) # Let's use a SetMdIterator because it should be less particles # in the metadata produced than in the input set iterator = md.SetMdIterator(self.mdImages, sortByLabel=md.MDL_ITEM_ID, updateItemCallback=self._updateParticle, skipDisabled=True) fnHomogeneous = self._getExtraPath("images_homogeneous.xmd") if exists(fnHomogeneous): if origTs != lastTs: newXdim = inputParticles.getXDim() self.runJob("xmipp_image_resize", "-i %s --dim %d" % (fnHomogeneous, newXdim), numberOfMpi=1) homogeneousSet = self._createSetOfParticles() homogeneousSet.copyInfo(inputParticles) #homogeneousSet.getImages().setSamplingRate(newTs) homogeneousSet.getImages().setSamplingRate(origTs) homogeneousSet.setAlignmentProj() self.iterMd = md.iterRows(fnHomogeneous, md.MDL_PARTICLE_ID) self.lastRow = next(self.iterMd) homogeneousSet.copyItems( inputParticles, updateItemCallback=self._updateHomogeneousItem) self._defineOutputs(outputHomogeneous=homogeneousSet) self._defineSourceRelation(self.inputParticles, homogeneousSet) #AJ testing #AJ por que desaparece una clase que tiene imagenes asignadas listRefId = [] for row in md.iterRows(self.mdClasses, emlib.MDL_REF2): refId = row.getValue(emlib.MDL_REF2, row.getObjId()) if len(listRefId) > 0 and refId != listRefId[-1] + 1: whereEnd = listRefId[-1] + 1 for i in range(refId - whereEnd): rowNew = row rowNew.setValue(emlib.MDL_REF2, listRefId[-1] + i + 1) rowNew.setValue(emlib.MDL_IMAGE, 'None') rowNew.setValue(emlib.MDL_IMAGE1, 'None') rowNew.addToMd(self.mdClasses) listRefId.append(listRefId[-1] + i + 1) listRefId.append(refId) else: listRefId.append(refId) self.mdClasses.write(self._getDirectionalClassesFn()) self.mdClasses = emlib.MetaData(self._getDirectionalClassesFn()) #END AJ classes2D.classifyItems(updateItemCallback=iterator.updateItem, updateClassCallback=self._updateClass) self._defineOutputs(outputClasses=classes2D) self._defineOutputs(outputAverages=self.averageSet) self._defineSourceRelation(self.inputParticles, classes2D) self._defineSourceRelation(self.inputParticles, self.averageSet) if self.splitVolume and self.directionalClasses.get() > 1: volumesSet = self._createSetOfVolumes() #volumesSet.setSamplingRate(newTs) volumesSet.setSamplingRate(origTs) for i in range(2): vol = Volume() fnVol = self._getExtraPath("split%d.vol" % (i + 1)) if origTs != lastTs: newXdim = inputParticles.getXDim() self.runJob("xmipp_image_resize", "-i %s --dim %d" % (fnVol, newXdim), numberOfMpi=1) fnMrc = self._getExtraPath("split%d.mrc" % (i + 1)) self.runJob("xmipp_image_convert", "-i %s -o %s -t vol" % (fnVol, fnMrc), numberOfMpi=1) self.runJob("xmipp_image_header", "-i %s --sampling_rate %f" % (fnMrc, origTs), numberOfMpi=1) cleanPath(fnVol) vol.setLocation(1, fnMrc) volumesSet.append(vol) self._defineOutputs(outputVolumes=volumesSet) self._defineSourceRelation(inputParticles, volumesSet)
def createOutputStep(self): classListProtocols = [] classListIds = [] classListSizes = [] fnOutFile = self.inputMetaProt.get()._getExtraPath('auxOutputFile.txt') outFile = open(fnOutFile, 'r') nameRead = outFile.readline() while nameRead != '': nameRead = nameRead[:-1] for i, item in enumerate(self.inputSignifProts): if nameRead == self.inputSignifProts[i].get()._objLabel: classListProtocols.append(self.inputSignifProts[i].get()) idRead = outFile.readline() classListIds.append(int(idRead)) sizeRead = outFile.readline() classListSizes.append(int(sizeRead)) break nameRead = outFile.readline() # print(classListProtocols) # print(classListIds) # print(classListSizes) inputVolume = self.inputMetaProt.get().inputVolume myVolList = [] # outputVolumes = self._createSetOfVolumes('Def') # outputVolumes.setDim(inputVolume.get().getDim()) # outputVolumes.setSamplingRate(inputVolume.get().getSamplingRate()) origDim = inputVolume.get().getDim()[0] for i, prot in enumerate(classListProtocols): # print("createOutputStep ", i) classItem = prot.outputClasses[classListIds[i]] volFn = str(classItem._representative._filename) volFnOut = self._getExtraPath('outVol%d.mrc' % (i + 1)) volDim = classItem._representative.getDim()[0] if volDim != origDim: self.runJob("xmipp_image_resize", "-i %s -o %s --fourier %d" % (volFn, volFnOut, origDim), numberOfMpi=self.numberOfMpi.get() * self.numberOfThreads.get()) else: copy(volFn, volFnOut) vol = Volume() vol.setLocation(volFnOut) vol.setSamplingRate(inputVolume.get().getSamplingRate()) myVolList.append(vol) # outputVolumes.append(vol) # self._defineOutputs(** {'outputVolumesDef': outputVolumes}) # self._store(outputVolumes) inputParticles = self.inputMetaProt.get().inputParticles outputDefClasses = self._createSetOfClasses3D(inputParticles.get(), 'Def') for i, prot in enumerate(classListProtocols): classItem = prot.outputClasses[classListIds[i]] signifInputParts = inputParticles.get() partIds = classItem.getIdSet() newClass = Class3D() newClass.copyInfo(signifInputParts) newClass.setAcquisition(signifInputParts.getAcquisition()) newClass.setRepresentative(myVolList[i]) outputDefClasses.append(newClass) enabledClass = outputDefClasses[newClass.getObjId()] enabledClass.enableAppend() for itemId in partIds: enabledClass.append(signifInputParts[itemId]) outputDefClasses.update(enabledClass) self._defineOutputs(**{'outputClasses3DDef': outputDefClasses}) self._store(outputDefClasses)