def extractDeformations(log, WorkingDir):
    MD = MetaData(os.path.join(WorkingDir, "images.xmd"))
    deformations = MD.getColumnValues(MDL_NMA)
    fnDef = os.path.join(WorkingDir, "extra/deformations.txt")
    fhDef = open(fnDef, "w")
    for deformation in deformations:
        for coef in deformation:
            fhDef.write("%f " % coef)
        fhDef.write("\n")
    fhDef.close()
Exemple #2
0
def computeCutoff(WorkingDir, fnHist, RcPercentage):
    MDhist=MetaData(fnHist)
    distances=MDhist.getColumnValues(MDL_X)
    distanceCount=MDhist.getColumnValues(MDL_COUNT)
    
    # compute total number of distances
    Ncounts=0
    for count in distanceCount:
        Ncounts+=count
    
    # Compute threshold
    NcountThreshold=Ncounts*RcPercentage/100.0
    Ncounts=0
    for i in range(len(distanceCount)):
        Ncounts+=distanceCount[i]
        if Ncounts>NcountThreshold:
            Rc=distances[i]
            break
    print("Cut-off distance="+str(Rc)+" A")
    fhWarning=open(os.path.join(WorkingDir,"warnings.xmd"),'w')
    fhWarning.write("Cut-off distance="+str(Rc)+" A\n")
    fhWarning.close()
    return Rc
Exemple #3
0
def coocurenceMatrix(log,RemainingClasses,WorkingDirStructure,NumVolumes,nI,CorePercentile,CorrThresh):
    import numpy
    mdRemaining = MetaData(RemainingClasses)
    Nimgs=mdRemaining.size()
    allNames=mdRemaining.getColumnValues(MDL_IMAGE)
    matrixTotal = numpy.zeros([Nimgs,Nimgs])
    for n in range(NumVolumes):
        fnBase='proposedVolume%05d'%n
        fnRoot=os.path.join(WorkingDirStructure,fnBase)
        
        md = MetaData(fnRoot+".xmd")
        size = md.size()
        
        num=[]
        corr=[]
        for objId in md:
            name = md.getValue(MDL_IMAGE, objId)
            if name in allNames:
                num.append(allNames.index(name))
                corr.append(md.getValue(MDL_MAXCC, objId))
            else:
                print "Cannot find ",name      
        if size!=len(num):
            print "Error when processing: ",fnRoot+".xmd"
            aaa
        
        matrix = numpy.zeros([Nimgs,Nimgs])
        for i in range(size):
            for j in range(size):
                matrix[num[i],num[j]]=((corr[i]+corr[j])/2)
        
        #numpy.savetxt(os.path.join(WorkingDirStructure,'coocurrenceMatrix_%05d.txt'%n), matrix) 
        matrixTotal=matrixTotal+matrix
    matrixTotal=matrixTotal/NumVolumes
    numpy.savetxt(os.path.join(WorkingDirStructure,'coocurrenceMatrix.txt'),matrixTotal)
    largestComponent=procCoocurenceMatrix(matrixTotal,CorePercentile,CorrThresh)

    md = MetaData()
    for idx in largestComponent:
        id=md.addObject()
        md.setValue(MDL_IMAGE,allNames[idx],id)
    md.write(os.path.join(WorkingDirStructure+"_core","imagesCore.xmd"))
    if md.size()==0:
        print "There are no images in the core"
        aaa
Exemple #4
0
def extendCore(log,WorkingDirStructureCore,WorkingDirStructureExtended,NumVolumes,RemainingClasses,ComplementaryClasses,AngularSampling,\
               SymmetryGroup,CorrThresh,NumberOfMpi):
    from protlib_projmatch import projMatch
    
    fnCore=os.path.join(WorkingDirStructureCore,"imagesCore.xmd")
    fnComplementary=os.path.join(WorkingDirStructureExtended,"imagesComplementary.xmd")
    runJob(log,"xmipp_metadata_utilities","-i %s --set subtraction %s image image -o %s"%(RemainingClasses,fnCore,fnComplementary))
    runJob(log,"xmipp_metadata_utilities","-i %s --operate keep_column image"%fnComplementary)
    if ComplementaryClasses!="":
        fnAux=os.path.join(WorkingDirStructureExtended,"aux.xmd")
        runJob(log,"xmipp_metadata_utilities","-i %s -o %s --operate keep_column image"%(ComplementaryClasses,fnAux))
        runJob(log,"xmipp_metadata_utilities", "-i %s  --set union %s image image"%(fnComplementary,fnAux))
        deleteFile(log,fnAux)
        runJob(log,"xmipp_metadata_utilities", "-i %s  --set subtraction %s image image"%(fnComplementary,fnCore))
        
    for i in range(NumVolumes):
        # Projection matching with the complementary images
        fnVolume=os.path.join(WorkingDirStructureCore,"proposedVolume%05d.vol"%i)
        fnAngles=os.path.join(WorkingDirStructureExtended,"anglesComplementary%05d.xmd"%i)
        projMatch(log,fnVolume,AngularSampling,SymmetryGroup,fnComplementary,WorkingDirStructureExtended,fnAngles,NumberOfMpi)
        
        # Calculate minimum correlation
        fnInliers=fnVolume=os.path.join(WorkingDirStructureCore,"proposedVolume%05d.xmd"%i)
        md=MetaData(fnInliers)
        cc=md.getColumnValues(MDL_MAXCC)
        cc.sort()
        minCC=min(cc[0],CorrThresh)
        
        # Choose those complementary images whose correlation is larger than the minimum
        fnAnglesChosen=os.path.join(WorkingDirStructureExtended,"anglesComplementaryChosen%05d.xmd"%i)
        runJob(log,"xmipp_metadata_utilities",'-i %s --query select "maxCC>%f" -o %s'%(fnAngles,minCC,fnAnglesChosen))
        fnExtended=os.path.join(WorkingDirStructureExtended,"proposedVolume%05d.xmd"%i)
        runJob(log,"xmipp_metadata_utilities",'-i %s --set union %s -o %s'%(fnInliers,fnAnglesChosen,fnExtended))
        deleteFile(log,fnAngles)
        deleteFile(log,fnAnglesChosen)
        fnOutOfCore=os.path.join(WorkingDirStructureExtended,"imagesOutOfCore%05d.xmd"%i)
        runJob(log,"xmipp_metadata_utilities",'-i %s --set subtraction %s -o %s'%(RemainingClasses,fnExtended,fnOutOfCore))
        runJob(log,"xmipp_metadata_utilities",'-i %s --operate sort'%fnOutOfCore)
        runJob(log,"xmipp_metadata_utilities",'-i %s --operate drop_column scale'%fnOutOfCore)
        runJob(log,"xmipp_metadata_utilities",'-i %s --operate sort'%fnExtended)
    
    deleteFile(log,os.path.join(WorkingDirStructureExtended,"gallery.stk"))
Exemple #5
0
    def validate(self):
        errors = []
        
        md = mdFirstRow(self.ImgMd)
        if md.containsLabel(MDL_IMAGE):
            # If using reference check that have same size as images:
            if not self.DoGenerateReferences:
                from protlib_xmipp import validateInputSize
                mdRef = MetaData(self.RefMd)
                references = mdRef.getColumnValues(MDL_IMAGE)
                validateInputSize(references, self.ImgMd, errors)
        else:
            errors.append("Input metadata <%s> doesn't contains image label" % self.ImgMd)

        if self.acquisionInfo is None:
            errors.append("Acquisition info was not found relative to image location")
        if (self.NumberOfThreads > 1  and self.DoMlf):
            errors.append("""WARNING: Threads are not implemented for MLF, 
set number of threads to 1 and consider to  
increment the number of MPI processes """)     
        return errors