Exemplo n.º 1
0
def xmippCtfModelToEmx(ctfModel, micrograph):
    mdCTF = RowMetaData(ctfModel)
    ctf = CTF()
    # Set the variables in the dict
    for var, label in CTF.ctfVarLabels.iteritems():
        setattr(ctf, var, mdCTF.getValue(label))
        
    ctf.defocusU /= 10.
    ctf.defocusV /= 10.

    while ctf.defocusUAngle < 0:
        ctf.defocusUAngle += 180.
    
    while ctf.defocusUAngle > 180.:
        ctf.defocusUAngle -= 180.; 
    #this must be ordered
    for var in CTF.ctfVarLabels.keys():
        micrograph.set(var, getattr(ctf, var))           
def createMicroscope(log, microscopeFn, Voltage, SphericalAberration, SamplingRate, AmplitudeContrast):
    md = RowMetaData()
    md.setValue(MDL_CTF_VOLTAGE, float(Voltage))    
    md.setValue(MDL_CTF_CS, float(SphericalAberration))    
    md.setValue(MDL_CTF_SAMPLING_RATE, float(SamplingRate))
    md.setValue(MDL_CTF_Q0, float(AmplitudeContrast))
    #md.setValue(MDL_MAGNIFICATION, 60000.0)
    md.write(microscopeFn)
def createAcquisition(log, acqFn, SamplingRate):
        # Create the acquisition info file
    mdAcq = RowMetaData()
    mdAcq.setValue(MDL_SAMPLINGRATE, float(SamplingRate))
    mdAcq.write(acqFn)
def createMicroscope(log, fnOut, Voltage, SphericalAberration, SamplingRate):
    md = RowMetaData()
    md.setValue(xmipp.MDL_CTF_VOLTAGE, float(Voltage))    
    md.setValue(xmipp.MDL_CTF_CS, float(SphericalAberration))    
    md.setValue(xmipp.MDL_CTF_SAMPLING_RATE, float(SamplingRate))
    md.setValue(xmipp.MDL_MAGNIFICATION, 60000.0)
    md.write(fnOut)
def createAcquisition(log, fnOut, SamplingRate):
        # Create the acquisition info file
    mdAcq = RowMetaData()
    mdAcq.setValue(xmipp.MDL_SAMPLINGRATE, float(SamplingRate))
    mdAcq.write(fnOut)
Exemplo n.º 6
0
def emxCTFToXmipp(emxData, 
                   outputFileName=MICFILE, 
                   filesPrefix='', #dirname
                   ctfRoot='', 
                   _voltage=None,
                   _sphericalAberration=None,
                   _samplingRate=None,
                   _amplitudeContrast=None
                   ):
    """ This function will iterate over the EMX micrographs and create
    a file .ctfparam for each micrograph.
    """
    hasCTFMicro = False
    hasCTFParticle = False
    if emxData.objLists[PARTICLE] and (emxData.objLists[PARTICLE][0]).get('defocusU') is not None:
        hasCTFParticle = True
        objectClass = PARTICLE

    if (emxData.objLists[MICROGRAPH][0]).get('defocusU') is not None:
        hasCTFMicro = True
        objectClass = MICROGRAPH

    if not (hasCTFParticle or hasCTFMicro):
        print "No CTF information available"
        return # no ctf info

    #fill metadata with CTF info
    #objMd = MetaData()
    for object in emxData.iterClasses(objectClass):
        objIndex = object.get(INDEX)
        objFileName = object.get(FILENAME)
        if objFileName is None:
            raise Exception("emxCTFToXmipp: Xmipp doesn't support Objects without filename")
        elif objIndex is not None:
            objFileName = join(filesPrefix, "%06d@%s"%(int(objIndex),objFileName))
        else:
            objFileName = join(filesPrefix, "%s"%(objFileName))

        ctfModelFileName = join(ctfRoot, replaceBasenameExt(objFileName, CTFENDING))
        ctf = CTFDEFOCUS()
        # Set the variables in the dict
        for var in CTF.ctfVarLabels.keys():
            setattr(ctf, var, object.get(var))

    if not ctfRoot:# is None:
        ctfRoot = dirname(outputFileName)

    for micrograph in emxData.iterClasses(MICROGRAPH):
        micIndex = micrograph.get(INDEX)
        micFileName = micrograph.get(FILENAME)

    samplingRate = 0.
    voltage      = 0.
    cs           = 0.
    amplitudeContrast = 0.
    
    oldSamplingRate = -1.
    oldVoltage      = -1.
    oldCs           = -1.
    oldAmplitudeContrast = -1.0
    for micrograph in emxData.iterClasses(MICROGRAPH):
        micIndex    = micrograph.get(INDEX)
        micFileName = micrograph.get(FILENAME)

        if micFileName is None:
            raise Exception("emxMicsToXmipp: Xmipp doesn't support Micrograph without filename")
#        if micFileName is None:
#            raise Exception("emxCTFToXmipp: Xmipp doesn't support Objects without filename")
        elif micIndex is not None:
            objFileName = join(filesPrefix, "%06d@%s"%(int(micIndex),micFileName))
        else:
            objFileName = join(filesPrefix, "%s"%(micFileName))

        ctfModelFileName = join(ctfRoot, replaceBasenameExt(micFileName, CTFENDING))

        ctf = CTF()
        ctf.pixelSpacing__Y = micrograph.get('pixelSpacing__Y')
        
        # Set the variables in the dict
        for var in CTF.ctfVarLabels.keys():
            setattr(ctf, var, micrograph.get(var))

        # Now do some adjusments to vars        
        if ctf.defocusU is not None:
            ctf.defocusU *= 10.
        
        if ctf.defocusV is None:
            ctf.defocusV = ctf.defocusU
            ctf.defocusUAngle = 0.
        else:
            ctf.defocusV *= 10.
            
        if ctf.pixelSpacing__Y is not None:
            if ctf.pixelSpacing__X != ctf.pixelSpacing__Y:
                raise Exception ('pixelSpacingX != pixelSpacingY. Xmipp does not support it')
            
        if ctf.pixelSpacing__X is not None:
            samplingRate    = ctf.pixelSpacing__X
            if (oldSamplingRate > -1):
                if oldSamplingRate != samplingRate:
                    raise Exception ('Xmipp emx import cannot import emx files with different samplingRate') 
            oldSamplingRate = samplingRate

        if ctf.acceleratingVoltage is not None:
            voltage         = ctf.acceleratingVoltage
            if (oldVoltage > -1):
                if oldVoltage != voltage:
                    raise Exception ('Xmipp emx import cannot import emx files with different voltage') 
            oldVoltage      = voltage

        if ctf.cs is not None:
            cs              = ctf.cs
            if (oldCs > -1):
                if oldCs != cs:
                    raise Exception ('Xmipp emx import cannot import emx files with different cs') 
            oldCs           = cs
            
        if ctf.amplitudeContrast is not None:
            amplitudeContrast              = ctf.amplitudeContrast
            if (oldAmplitudeContrast > -1):
                if oldAmplitudeContrast != amplitudeContrast:
                    raise Exception ('Xmipp emx import cannot import emx files with different amplitudeContrast') 
            oldAmplitudeContrast           = amplitudeContrast
            
        # Create the .ctfparam, replacing the micrograph name
        #write only if ctf information is available
        if (ctf.acceleratingVoltage is not None and
            ctf.cs is not None and
            ctf.amplitudeContrast is not None
            ):
            mdCtf = RowMetaData()
            
            for var, label in CTF.ctfVarLabels.iteritems():
                v = getattr(ctf, var)
                if v is not None:
                    mdCtf.setValue(label, float(v))

            mdCtf.setValue(MDL_CTF_K, 1.0)
            mdCtf.write(ctfModelFileName)

    # Sort metadata by micrograph name
    #mdMic.sort(MDL_MICROGRAPH)
    # Write micrographs metadata
    #mdMic.write('Micrographs@' + outputFileName)
    return voltage, cs, samplingRate