def _updateParticle(self, particle, row):
        #fn = particle.getFileName()
        # fnOut = self.getFileNameNoisyStk()
        # particle.setFileName(fnOut)

        index, filename = xmippToLocation(row.getValue(md.MDL_IMAGE))
        particle.setLocation(index, filename)
    def _updateClass(self, item):
        classId = item.getObjId()
        classRow = findRow(self.mdClasses, xmippLib.MDL_REF2, classId)

        representative = item.getRepresentative()
        representative.setTransform(rowToAlignment(classRow, ALIGN_PROJ))
        representative.setLocation(xmippToLocation(classRow.getValue(xmippLib.MDL_IMAGE)))
        setXmippAttributes(representative, classRow, xmippLib.MDL_ANGLE_ROT)
        setXmippAttributes(representative, classRow, xmippLib.MDL_ANGLE_TILT)
        setXmippAttributes(representative, classRow, xmippLib.MDL_CLASS_COUNT)

        self.averageSet.append(representative)

        reprojection = Image()
        reprojection.setLocation(xmippToLocation(classRow.getValue(xmippLib.MDL_IMAGE1)))
        item.reprojection = reprojection
Exemple #3
0
    def performNmaStep(self, atomsFn, modesFn):
        sampling = self.inputParticles.get().getSamplingRate()
        discreteAngularSampling = self.discreteAngularSampling.get()
        trustRegionScale = self.trustRegionScale.get()
        odir = self._getTmpPath()
        imgFn = self.imgsFn

        args = "-i %(imgFn)s --pdb %(atomsFn)s --modes %(modesFn)s --sampling_rate %(sampling)f "
        args += "--discrAngStep %(discreteAngularSampling)f --odir %(odir)s --centerPDB "
        args += "--trustradius_scale %(trustRegionScale)d --resume "

        if self.getInputPdb().getPseudoAtoms():
            args += "--fixed_Gaussian "

        if self.alignmentMethod == NMA_ALIGNMENT_PROJ:
            args += "--projMatch "

        self.runJob("xmipp_nma_alignment", args % locals())

        cleanPath(self._getPath('nmaTodo.xmd'))

        inputSet = self.inputParticles.get()
        mdImgs = md.MetaData(self.imgsFn)
        for objId in mdImgs:
            imgPath = mdImgs.getValue(md.MDL_IMAGE, objId)
            index, fn = xmippToLocation(imgPath)
            # Conside the index is the id in the input set
            particle = inputSet[index]
            mdImgs.setValue(md.MDL_IMAGE, getImageLocation(particle), objId)
            mdImgs.setValue(md.MDL_ITEM_ID, long(particle.getObjId()), objId)
        mdImgs.write(self.imgsFn)
    def _fillClasses(self, outputClasses):
        """ Create the SetOfClasses2D """
        inputSet = self.inputClasses.get().getImages()
        myRep = md.MetaData('classes@' + self._getExtraPath(
            'final_classes.xmd'))

        for row in md.iterRows(myRep):
            fn = row.getValue(md.MDL_IMAGE)
            rep = Particle()
            rep.setLocation(xmippToLocation(fn))
            repId = row.getObjId()
            newClass = Class2D(objId=repId)
            newClass.setAlignment2D()
            newClass.copyInfo(inputSet)
            newClass.setAcquisition(inputSet.getAcquisition())
            newClass.setRepresentative(rep)
            outputClasses.append(newClass)

        i=1
        mdBlocks = md.getBlocksInMetaDataFile(self._getExtraPath(
            'final_classes.xmd'))
        for block in mdBlocks:
            if block.startswith('class00'):
                mdClass = md.MetaData(block + "@" + self._getExtraPath(
                                      'final_classes.xmd'))
                imgClassId = i
                newClass = outputClasses[imgClassId]
                newClass.enableAppend()
                for row in md.iterRows(mdClass):
                    part = rowToParticle(row)
                    newClass.append(part)
                i+=1
                newClass.setAlignment2D()
                outputClasses.update(newClass)
Exemple #5
0
 def _loadClassesInfo(self, filename, blockId):
     """ Read some information about the produced 2D classes
     from the metadata file.
     """
     self._classesInfo = {}  # store classes info, indexed by class id
     mdClasses = md.MetaData(filename)
     for classNumber, row in enumerate(md.iterRows(mdClasses)):
         index, fn = xmippToLocation(row.getValue(md.MDL_IMAGE))
         self._classesInfo[blockId] = (index, fn, row.clone())
Exemple #6
0
 def __setXmippImage(label):
     attr = '_xmipp_' + xmippLib.label2Str(label)
     if not hasattr(particle, attr):
         img = Image()
         setattr(particle, attr, img)
         img.setSamplingRate(particle.getSamplingRate())
     else:
         img = getattr(particle, attr)
     img.setLocation(xmippToLocation(row.getValue(label)))
Exemple #7
0
 def _updateItem(self, item, row):
     """ Implement this function to do some
     update actions over each single item
     that will be stored in the output Set.
     """
     # By default update the item location (index, filename)
     # with the new binary data location (after preprocessing)
     newFn = row.getValue(md.MDL_IMAGE)
     newLoc = xmippToLocation(newFn)
     item.setLocation(newLoc)
 def _updateItem(self, item, row):
     """ Implement this function to do some
     update actions over each single item
     that will be stored in the output Set.
     """
     # By default update the item location (index, filename) with the new binary data location
     newFn = row.getValue(md.MDL_IMAGE)
     newLoc = xmippToLocation(newFn)
     item.setLocation(newLoc)
     # Also remove alignment info
     item.setTransform(None)
Exemple #9
0
    def _loadClassesInfo(self):
        """ Read some information about the produced 2D classes
        from the metadata file.
        """
        self._classesInfo = {}  # store classes info, indexed by class id

        for classNumber, row in enumerate(md.iterRows(self.mdOut)):
            index, fn = xmippToLocation(row.getValue(md.MDL_IMAGE))
            c = row.getValue(md.MDL_DIMRED)
            # Store info indexed by id, we need to store the row.clone() since
            # the same reference is used for iteration
            self._classesInfo[classNumber + 1] = (index, fn, row.clone(), c)
Exemple #10
0
 def copyDeformationsStep(self, deformationMd):
     copyFile(deformationMd, self.imgsFn)
     # We need to update the image name with the good ones
     # and the same with the ids.
     inputSet = self.inputParticles.get()
     mdImgs = md.MetaData(self.imgsFn)
     for objId in mdImgs:
         imgPath = mdImgs.getValue(md.MDL_IMAGE, objId)
         index, fn = xmippToLocation(imgPath)
         # Conside the index is the id in the input set
         particle = inputSet[index]
         mdImgs.setValue(md.MDL_IMAGE, getImageLocation(particle), objId)
         mdImgs.setValue(md.MDL_ITEM_ID, long(particle.getObjId()), objId)
     mdImgs.write(self.imgsFn)
    def readPartsFromMics(self, micList, outputParts):
        """ Read the particles extract for the given list of micrographs
        and update the outputParts set with new items.
        """
        p = Particle()
        for mic in micList:
            # We need to make this dict because there is no ID in the .xmd file
            coordDict = {}
            for coord in self.coordDict[mic.getObjId()]:
                pos = self._getPos(coord)
                if pos in coordDict:
                    print(
                        "WARNING: Ignoring duplicated coordinate: %s, id=%s" %
                        (coord.getObjId(), pos))
                coordDict[pos] = coord

            added = set()  # Keep track of added coords to avoid duplicates
            fnMicXmd = self._getMicXmd(mic)
            if exists(fnMicXmd):
                for row in md.iterRows(fnMicXmd):
                    pos = (row.getValue(md.MDL_XCOOR),
                           row.getValue(md.MDL_YCOOR))
                    coord = coordDict.get(pos, None)
                    if coord is not None and coord.getObjId() not in added:
                        # scale the coordinates according to particles dimension.
                        coord.scale(self.getBoxScale())
                        p.copyObjId(coord)
                        p.setLocation(
                            xmippToLocation(row.getValue(md.MDL_IMAGE)))
                        p.setCoordinate(coord)
                        p.setMicId(mic.getObjId())
                        p.setCTF(mic.getCTF())
                        # adding the variance and Gini coeff. value of the mic zone
                        setXmippAttributes(p, row, md.MDL_SCORE_BY_VAR)
                        setXmippAttributes(p, row, md.MDL_SCORE_BY_GINI)
                        if row.containsLabel(md.MDL_ZSCORE_DEEPLEARNING1):
                            setXmippAttributes(p, row,
                                               md.MDL_ZSCORE_DEEPLEARNING1)

                        # disabled particles (in metadata) should not add to the
                        # final set
                        if row.getValue(md.MDL_ENABLED) > 0:
                            outputParts.append(p)
                            added.add(coord.getObjId())

            # Release the list of coordinates for this micrograph since it
            # will not be longer needed
            del self.coordDict[mic.getObjId()]
Exemple #12
0
    def _processRow(self, particle, row):
        def __setXmippImage(label):
            attr = '_xmipp_' + xmippLib.label2Str(label)
            if not hasattr(particle, attr):
                img = Image()
                setattr(particle, attr, img)
                img.setSamplingRate(particle.getSamplingRate())
            else:
                img = getattr(particle, attr)
            img.setLocation(xmippToLocation(row.getValue(label)))

        particle.setLocation(xmippToLocation(row.getValue(xmippLib.MDL_IMAGE)))
        #__setXmippImage(xmippLib.MDL_IMAGE)
        #__setXmippImage(xmippLib.MDL_IMAGE_REF)

        setXmippAttributes(particle, row, xmippLib.MDL_IMAGE_ORIGINAL,
                           xmippLib.MDL_IMAGE_REF)
Exemple #13
0
 def _updateItemAlign(self, item, row):
     newFn = row.getValue(md.MDL_IMAGE)
     newLoc = xmippToLocation(newFn)
     item.setLocation(newLoc)
     item.setTransform(None)
Exemple #14
0
    def _processMovie(self, movie):
        movId = movie.getObjId()
        x, y, n = movie.getDim()
        iniFrame, lastFrame, _ = movie.getFramesRange()
        frame0, frameN = self._getRange(movie)
        boxSize = self.boxSize.get()

        if movie.hasAlignment() and self.applyAlignment:
            shiftX, shiftY = movie.getAlignment().getShifts()  # lists.
        else:
            shiftX = [0] * (lastFrame - iniFrame + 1)
            shiftY = shiftX

        stkIndex = 0
        movieStk = self._getMovieName(movie, '.stk')
        movieMdFile = self._getMovieName(movie, '.xmd')
        movieMd = md.MetaData()
        frameMd = md.MetaData()
        frameMdImages = md.MetaData()
        frameRow = md.Row()

        if self._hasCoordinates(movie):
            imgh = ImageHandler()

            for frame in range(frame0, frameN + 1):
                indx = frame - iniFrame
                frameName = self._getFnRelated('frameMic', movId, frame)
                frameMdFile = self._getFnRelated('frameMdFile', movId, frame)
                coordinatesName = self._getFnRelated('frameCoords', movId,
                                                     frame)
                frameImages = self._getFnRelated('frameImages', movId, frame)
                frameStk = self._getFnRelated('frameStk', movId, frame)

                self._writeXmippPosFile(movie, coordinatesName, shiftX[indx],
                                        shiftY[indx])

                self.info("Writing frame: %s" % frameName)
                # TODO: there is no need to write the frame and then operate
                # the input of the first operation should be the movie
                movieName = imgh.fixXmippVolumeFileName(movie)
                imgh.convert((frame, movieName), frameName)

                if self.doRemoveDust:
                    self.info("Removing Dust")
                    self._runNoDust(frameName)

                self.info("Extracting particles")
                args = '-i %(frameName)s --pos %(coordinatesName)s ' \
                       '-o %(frameImages)s --Xdim %(boxSize)d' % locals()

                if self.doInvert:
                    args += " --invert"

                if self.doBorders:
                    args += " --fillBorders"

                args += " --downsampling %f " % self.getBoxScale()
                self.runJob('xmipp_micrograph_scissor', args)
                cleanPath(frameName)

                self.info("Combining particles into one stack.")

                frameMdImages.read(frameMdFile)
                frameMd.read('particles@%s' % coordinatesName)
                frameMd.merge(frameMdImages)

                for objId in frameMd:
                    stkIndex += 1
                    frameRow.readFromMd(frameMd, objId)
                    location = xmippToLocation(frameRow.getValue(md.MDL_IMAGE))
                    newLocation = (stkIndex, movieStk)
                    imgh.convert(location, newLocation)

                    # Fix the name to be accessible from the Project directory
                    # so we know that the movie stack file will be moved
                    # to final particles folder
                    newImageName = '%d@%s' % newLocation
                    frameRow.setValue(md.MDL_IMAGE, newImageName)
                    frameRow.setValue(md.MDL_MICROGRAPH_ID, long(movId))
                    frameRow.setValue(md.MDL_MICROGRAPH, str(movId))
                    frameRow.setValue(md.MDL_FRAME_ID, long(frame))
                    frameRow.setValue(md.MDL_PARTICLE_ID,
                                      frameRow.getValue(md.MDL_ITEM_ID))
                    frameRow.writeToMd(movieMd, movieMd.addObject())
                movieMd.addItemId()
                movieMd.write(movieMdFile)
                cleanPath(frameStk)

            if self.doNormalize:
                numberOfFrames = frameN - frame0 + 1
                self._runNormalize(movieStk, numberOfFrames)
 def _updateLocation(self, item, row):
     index, filename = xmippToLocation(row.getValue(md.MDL_IMAGE))
     item.setLocation(index, filename)
Exemple #16
0
 def _updateItem(self, item, row):
     # By default update the item location (index, filename) with the new binary data location
     newFn = row.getValue(md.MDL_IMAGE)
     newLoc = xmippToLocation(newFn)
     item.setLocation(newLoc)
     item.setTransform(None)
Exemple #17
0
 def _preprocessClass(self, classItem, classRow):
     classItem.average = Particle()
     classItem.average.setLocation(
         xmippToLocation(classRow.getValue(emlib.MDL_IMAGE2)))
 def _processRow(self, particle, row):
     particle.setLocation(xmippToLocation(row.getValue(xmippLib.MDL_IMAGE)))
     if self.model.get() == ITER_TRAIN:
         setXmippAttributes(particle, row,
                            xmippLib.MDL_CORR_DENOISED_PROJECTION)