def visualize(self):
     summaryFile = self.getFilename('micrographs')
     
     if not exists(summaryFile): # Try to create partial summary file
         summaryFile = summaryFile.replace(self.WorkingDir, self.TmpDir)
         buildSummaryMetadata(self.WorkingDir, self.Input['micrographs'], summaryFile, self.MDL_TYPE)
     
     if exists(summaryFile):
         self.regenerateSummary(summaryFile)
         runShowJ(summaryFile, extraParams = "--mode metadata --render psd psdEnhanced image1 image2 --order psd psdEnhanced image1 image2 --zoom 50")
     else:
         showWarning('Warning', 'There are not results yet',self.master)
def buildSummaryMetadata(WorkingDir,importMicrographs,summaryFile,MDL_TYPE):
    md = xmipp.MetaData()
    importMd = xmipp.MetaData(importMicrographs)
    importMd.removeDisabled()
    for id in importMd:
        inputFile = importMd.getValue(MDL_TYPE,id)
        micrographName = os.path.basename(inputFile)
        shortname = replaceFilenameExt(micrographName, '')
        micrographDir = join(WorkingDir, 'extra', shortname)                    
        
        objId = md.addObject()
        md.setValue(MDL_TYPE, inputFile, objId)
        ctfparam = _getFilename('ctfparam', micrographDir=micrographDir)
        labels = [xmipp.MDL_PSD, xmipp.MDL_PSD_ENHANCED, xmipp.MDL_CTF_MODEL,xmipp.MDL_IMAGE1, xmipp.MDL_IMAGE2]
        if exists(ctfparam): # Get filenames
            keys = ['psd', 'enhanced_psd', 'ctfparam', 'ctfmodel_quadrant', 'ctfmodel_halfplane']
            values = [_getFilename(key, micrographDir=micrographDir) for key in keys]
        else: # No files
            values = ['NA'] * len(labels)

        # Set values in metadata
        for label, value in zip(labels, values):
            md.setValue(label, value, objId)
    
    if not md.isEmpty():
        md.sort(MDL_TYPE)
        md.write(summaryFile)
def gatherResults(log, 
                  WorkingDir,
                  extraDir,
                  currProtMicrographClass,
                  currProtMicrograph,
                  currProtMicroscope,
                  currProtAcquisitionInfo,
                  prevProtMicrograph,
                  prevProtMicroscope,
                  prevProtAcquisitionInfo
                  ):
    
    import glob
    #fnList=glob.glob(os.path.join(extraDir,'*_aligned.spi'))
    copyFile(log,prevProtMicrograph,currProtMicrograph) 
    copyFile(log,prevProtMicroscope,currProtMicroscope) 
    copyFile(log,prevProtAcquisitionInfo,currProtAcquisitionInfo) 
    md=xmipp.MetaData(currProtMicrograph)
    for id  in md:
        inputMovie = md.getValue(xmipp.MDL_MICROGRAPH, id)
        movieNameList = os.path.basename(inputMovie)
        movieName = os.path.splitext(movieNameList)[0]
        file = _getFilename('movieAverage',movieDir=extraDir,baseName=movieName) 
        md.setValue(xmipp.MDL_MICROGRAPH,file,id)
        if exists(file):
            enabled = 1
        else:
            enabled = -1
        md.setValue(xmipp.MDL_ENABLED,enabled)

    md.sort(xmipp.MDL_MICROGRAPH)
    md.write(currProtMicrographClass,xmipp.MD_APPEND)
 def visualize(self):
     summaryFile = self.getFilename('micrographs')
     if exists(summaryFile):
         runShowJ(summaryFile, extraParams = "--mode metadata")
     else:
         showWarning('Warning', 'There are not results yet',self.master)