예제 #1
0
def writeSetOfMicrographsPairs(uSet, tSet, filename):
    """ This function will write a MicrographsTiltPair as Xmipp metadata.
    Params:
        uSet: the untilted set of micrographs to be written
        tSet: the tilted set of micrographs to be written
        filename: the filename where to write the metadata.
    """
    md = xmipp.MetaData()

    for micU, micT in izip(uSet, tSet):
        objId = md.addObject()
        pairRow = XmippMdRow()
        pairRow.setValue(xmipp.MDL_ITEM_ID, long(micU.getObjId()))
        pairRow.setValue(xmipp.MDL_MICROGRAPH, micU.getFileName())
        pairRow.setValue(xmipp.MDL_MICROGRAPH_TILTED, micT.getFileName())
        pairRow.writeToMd(md, objId)
        
    md.write(filename)   
예제 #2
0
def writeSetOfMicrographsPairs(uSet, tSet, filename):
    """ This function will write a MicrographsTiltPair as Xmipp metadata.
    Params:
        uSet: the untilted set of micrographs to be written
        tSet: the tilted set of micrographs to be written
        filename: the filename where to write the metadata.
    """
    md = xmipp.MetaData()

    for micU, micT in izip(uSet, tSet):
        objId = md.addObject()
        pairRow = XmippMdRow()
        pairRow.setValue(xmipp.MDL_ITEM_ID, long(micU.getObjId()))
        pairRow.setValue(xmipp.MDL_MICROGRAPH, micU.getFileName())
        pairRow.setValue(xmipp.MDL_MICROGRAPH_TILTED, micT.getFileName())
        pairRow.writeToMd(md, objId)
        
    md.write(filename)   
예제 #3
0
def writeSetOfCTFs(ctfSet, mdCTF):
    """ Write a ctfSet on metadata format. 
    Params:
        ctfSet: the SetOfCTF that will be read.
        mdCTF: The file where metadata should be written.
    """
    md = xmipp.MetaData()
            
    for ctfModel in ctfSet:
        objId = md.addObject()
        ctfRow = XmippMdRow()
        ctfRow.setValue(xmipp.MDL_MICROGRAPH, ctfModel.getMicFile())
        if ctfModel.getPsdFile():
            ctfRow.setValue(xmipp.MDL_PSD, ctfModel.getPsdFile())
        ctfModelToRow(ctfModel, ctfRow)
        ctfRow.writeToMd(md, objId)
        
    md.write(mdCTF)
    ctfSet._xmippMd = String(mdCTF)
예제 #4
0
def writeSetOfCTFs(ctfSet, mdCTF):
    """ Write a ctfSet on metadata format. 
    Params:
        ctfSet: the SetOfCTF that will be read.
        mdCTF: The file where metadata should be written.
    """
    md = xmipp.MetaData()
            
    for ctfModel in ctfSet:
        objId = md.addObject()
        ctfRow = XmippMdRow()
        ctfRow.setValue(xmipp.MDL_MICROGRAPH, ctfModel.getMicFile())
        if ctfModel.getPsdFile():
            ctfRow.setValue(xmipp.MDL_PSD, ctfModel.getPsdFile())
        ctfModelToRow(ctfModel, ctfRow)
        ctfRow.writeToMd(md, objId)
        
    md.write(mdCTF)
    ctfSet._xmippMd = String(mdCTF)
예제 #5
0
def writeSetOfDefocusGroups(defocusGroupSet, fnDefocusGroup): # also metadata
    """ Write a defocuGroupSet on metadata format. 
    Params:
        defocusGroupSet: the SetOfDefocus that will be read.
        fnDefocusGroup: The file where defocusGroup should be written.
    """
    md = xmipp.MetaData()
            
    for defocusGroup in defocusGroupSet:
        objId = md.addObject()
        defocusGroupRow = XmippMdRow()
        defocusGroupSetToRow(defocusGroup, defocusGroupRow)
        defocusGroupRow.setValue(xmipp.MDL_CTF_GROUP, defocusGroup.getObjId())
        defocusGroupRow.setValue(xmipp.MDL_MIN, defocusGroup.getDefocusMin())
        defocusGroupRow.setValue(xmipp.MDL_MAX, defocusGroup.getDefocusMax())
        defocusGroupRow.setValue(xmipp.MDL_AVG, defocusGroup.getDefocusAvg())
        defocusGroupRow.writeToMd(md, objId)
        
    md.write(fnDefocusGroup)
    defocusGroupSet._xmippMd = String(fnDefocusGroup)
예제 #6
0
def writeSetOfDefocusGroups(defocusGroupSet, fnDefocusGroup): # also metadata
    """ Write a defocuGroupSet on metadata format. 
    Params:
        defocusGroupSet: the SetOfDefocus that will be read.
        fnDefocusGroup: The file where defocusGroup should be written.
    """
    md = xmipp.MetaData()
            
    for defocusGroup in defocusGroupSet:
        objId = md.addObject()
        defocusGroupRow = XmippMdRow()
        defocusGroupSetToRow(defocusGroup, defocusGroupRow)
        defocusGroupRow.setValue(xmipp.MDL_CTF_GROUP, defocusGroup.getObjId())
        defocusGroupRow.setValue(xmipp.MDL_MIN, defocusGroup.getDefocusMin())
        defocusGroupRow.setValue(xmipp.MDL_MAX, defocusGroup.getDefocusMax())
        defocusGroupRow.setValue(xmipp.MDL_AVG, defocusGroup.getDefocusAvg())
        defocusGroupRow.writeToMd(md, objId)
        
    md.write(fnDefocusGroup)
    defocusGroupSet._xmippMd = String(fnDefocusGroup)
    def _appendRctImages(self, particles):

        blockMd = "class%06d_images@%s" % (particles.getObjId(), self.rctClassesFn)
        
        classMd = xmipp.MetaData()
        
        uImages = self.inputParticlesTiltPair.get().getUntilted()
        tImages = self.inputParticlesTiltPair.get().getTilted()
        sangles = self.inputParticlesTiltPair.get().getCoordsPair().getAngles()

        uMics = self.inputParticlesTiltPair.get().getCoordsPair().getMicsPair().getUntilted()
        tMics = tImages.getCoordinates().getMicrographs()
        
        scaleFactor = uImages.getSamplingRate()/particles.getSamplingRate()
        
        for img in particles:
            imgId = img.getObjId()
                       
            uImg = uImages[imgId]
            tImg = tImages[imgId]
            objId = classMd.addObject()
            pairRow = XmippMdRow()
            pairRow.setValue(xmipp.MDL_IMAGE, getImageLocation(uImg))
            uCoord = uImg.getCoordinate()
            micId = uCoord.getMicId()
            uMic = uMics[micId]
            angles = sangles[micId]
            pairRow.setValue(xmipp.MDL_MICROGRAPH, uMic.getFileName())
            pairRow.setValue(xmipp.MDL_XCOOR, uCoord.getX())
            pairRow.setValue(xmipp.MDL_YCOOR, uCoord.getY())
            pairRow.setValue(xmipp.MDL_ENABLED, 1)
            pairRow.setValue(xmipp.MDL_ITEM_ID, long(imgId))
            pairRow.setValue(xmipp.MDL_REF, 1)

            alignment = img.getTransform()

            # Scale alignment by scaleFactor
            alignment.scale(scaleFactor)
            alignmentToRow(alignment, pairRow, alignType=ALIGN_2D)
                               
            pairRow.setValue(xmipp.MDL_IMAGE_TILTED, getImageLocation(tImg))
            tMic = tMics[micId]
            pairRow.setValue(xmipp.MDL_MICROGRAPH_TILTED, tMic.getFileName())
            (angleY, angleY2, angleTilt) = angles.getAngles()
            pairRow.setValue(xmipp.MDL_ANGLE_Y, float(angleY))
            pairRow.setValue(xmipp.MDL_ANGLE_Y2, float(angleY2))
            pairRow.setValue(xmipp.MDL_ANGLE_TILT, float(angleTilt))
            
            pairRow.writeToMd(classMd, objId)
            classMd.write(blockMd, xmipp.MD_APPEND)
예제 #8
0
    def _appendRctImages(self, particles):

        blockMd = "class%06d_images@%s" % (particles.getObjId(),
                                           self.rctClassesFn)

        classMd = xmipp.MetaData()

        uImages = self.inputParticlesTiltPair.get().getUntilted()
        tImages = self.inputParticlesTiltPair.get().getTilted()
        sangles = self.inputParticlesTiltPair.get().getCoordsPair().getAngles()

        uMics = self.inputParticlesTiltPair.get().getCoordsPair().getMicsPair(
        ).getUntilted()
        tMics = tImages.getCoordinates().getMicrographs()

        scaleFactor = uImages.getSamplingRate() / particles.getSamplingRate()

        for img in particles:
            imgId = img.getObjId()

            uImg = uImages[imgId]
            tImg = tImages[imgId]

            if uImg is None or tImg is None:
                print ">>> Warning, for id %d, tilted or untilted particle was not found. Ignored." % imgId
            else:
                objId = classMd.addObject()
                pairRow = XmippMdRow()
                pairRow.setValue(xmipp.MDL_IMAGE, getImageLocation(uImg))
                uCoord = uImg.getCoordinate()
                micId = uCoord.getMicId()
                uMic = uMics[micId]
                angles = sangles[micId]
                pairRow.setValue(xmipp.MDL_MICROGRAPH, uMic.getFileName())
                pairRow.setValue(xmipp.MDL_XCOOR, uCoord.getX())
                pairRow.setValue(xmipp.MDL_YCOOR, uCoord.getY())
                pairRow.setValue(xmipp.MDL_ENABLED, 1)
                pairRow.setValue(xmipp.MDL_ITEM_ID, long(imgId))
                pairRow.setValue(xmipp.MDL_REF, 1)

                alignment = img.getTransform()

                # Scale alignment by scaleFactor
                alignment.scale(scaleFactor)
                alignmentToRow(alignment, pairRow, alignType=ALIGN_2D)

                pairRow.setValue(xmipp.MDL_IMAGE_TILTED,
                                 getImageLocation(tImg))
                tMic = tMics[micId]
                pairRow.setValue(xmipp.MDL_MICROGRAPH_TILTED,
                                 tMic.getFileName())
                (angleY, angleY2, angleTilt) = angles.getAngles()
                pairRow.setValue(xmipp.MDL_ANGLE_Y, float(angleY))
                pairRow.setValue(xmipp.MDL_ANGLE_Y2, float(angleY2))
                pairRow.setValue(xmipp.MDL_ANGLE_TILT, float(angleTilt))

                pairRow.writeToMd(classMd, objId)

        classMd.write(blockMd, xmipp.MD_APPEND)