Пример #1
0
def create_ctf_list(current_ctf, def_search_range, def_step_size):
    """
	Creates a set of CTFs with different defoci based on a defocus search range arround the
	defocus of the current ctf estimate.

	:param current_ctf: Current ctf
	:param def_search_range: Defocus search range
	:param def_step_size: Defocus step size
	:return: Set of CTFs
	"""
    current_defocus = current_ctf.defocus
    ctfs = []
    lower_defocus = current_defocus - def_search_range
    if lower_defocus < 0:
        lower_defocus = 0

    upper_defocus = current_defocus + def_search_range + def_step_size

    for defocus in numpy.arange(lower_defocus, upper_defocus, def_step_size):
        ctf_parameter = EMAN2.EMAN2Ctf()
        removed_dict = dict([(key, value) for key , value in current_ctf.to_dict().items() if key not in ('background', 'snr')])
        ctf_parameter.from_dict(removed_dict)
        # ctf_parameter.from_dict(current_ctf.to_dict())
        ctf_parameter.defocus = defocus
        ctfs.append(ctf_parameter)

    return ctfs
Пример #2
0
def create_ctf_list(current_ctf, def_search_range, def_step_size):
	"""
	Creates a set of CTFs with different defoci based on a defocus search range arround the
	defocus of the current ctf estimate.

	:param current_ctf: Current ctf
	:param def_search_range: Defocus search range
	:param def_step_size: Defocus step size
	:return: Set of CTFs
	"""
	current_defocus = current_ctf.defocus
	ctfs = []
	lower_defocus = current_defocus - def_search_range
	if lower_defocus < 0:
		lower_defocus = 0

	upper_defocus = current_defocus + def_search_range + def_step_size

	for defocus in np.arange(lower_defocus, upper_defocus, def_step_size):
		ctf_parameter = EMAN2.EMAN2Ctf()
		ctf_parameter.from_dict(current_ctf.to_dict())
		ctf_parameter.defocus = defocus
		ctfs.append(ctf_parameter)

	return ctfs
Пример #3
0
def writeParticles():
    line = sys.stdin.readline()
    fnHdf = ""
    while line:
        objDict = json.loads(line)
        index = int(objDict['_index'])
        filename = str(objDict['_filename'])
        imageData = eman.EMData()
        imageData.read_image(filename, index)

        if '_ctfModel._defocusU' in objDict:
            ctf = eman.EMAN2Ctf()
            defU = objDict['_ctfModel._defocusU']
            defV = objDict['_ctfModel._defocusV']

            ctf.from_dict({"defocus": (defU + defV) / 20000.0,
                           "dfang": objDict['_ctfModel._defocusAngle'],
                           "dfdiff": (defU - defV) / 10000.0,
                           "voltage": objDict['_acquisition._voltage'],
                           "cs": max(objDict['_acquisition._sphericalAberration'], 0.0001),
                           "ampcont": objDict['_acquisition._amplitudeContrast'] * 100.0,
                           "apix": objDict['_samplingRate']})
            imageData.set_attr('ctf', ctf)

        imageData.set_attr('apix_x', objDict['_samplingRate'])
        imageData.set_attr('apix_y', objDict['_samplingRate'])

        transformation = None
        if '_angles' in objDict:
            # TODO: convert to vector not matrix
            angles = objDict['_angles']
            shifts = objDict['_shifts']
            transformation = eman.Transform({"type": "spider",
                                             "phi": angles[0],
                                             "theta": angles[1],
                                             "psi": angles[2],
                                             "tx": -shifts[0],
                                             "ty": -shifts[1],
                                             "tz": -shifts[2],
                                             "mirror": 0,  # TODO: test flip
                                             "scale": 1.0})

        if transformation is not None:
            imageData.set_attr('xform.projection', transformation)

        outputFile = str(objDict['hdfFn'])
        if outputFile != fnHdf:
            i = 0
            fnHdf = outputFile

        imageData.write_image(outputFile, i,
                              eman.EMUtil.ImageType.IMAGE_HDF, False)
        i += 1
        print("OK")  # it is necessary to add newline
        sys.stdout.flush()
        line = sys.stdin.readline()
Пример #4
0
def writeParticles():
    line = sys.stdin.readline()
    fnHdf = ""
    while line:
    #for line in sys.stdin:
        objDict=json.loads(line)
        ###imgId, index, filename = line.split()
        if '_index' in objDict.keys():
            index = int(objDict['_index'])
            
        if '_filename' in objDict.keys():
            filename = str(objDict['_filename'])
        else:
            raise Exception('ERROR (e2converter): Cannot process a particle without filename')
        imageData = eman.EMData()
        imageData.read_image(filename, index)
        
        ctf = None
        if '_ctfModel._defocusU' in objDict.keys():
            ctf = eman.EMAN2Ctf()
            
            defU = objDict['_ctfModel._defocusU']
            defV = objDict['_ctfModel._defocusV']
            
            ctf.from_dict({"defocus": (defU + defV)/20000.0,
                           "dfang": objDict['_ctfModel._defocusAngle'],
                           "dfdiff": (defU - defV)/10000.0,
                           "voltage": objDict['_acquisition._voltage'],
                           "cs": objDict['_acquisition._sphericalAberration'],
                           "ampcont": objDict['_acquisition._amplitudeContrast'] * 100.0,
                           "apix": objDict['_samplingRate']})
            imageData.set_attr('ctf', ctf)
        
        transformation = None
        if '_angles' in objDict.keys():
            #TODO: convert to vector not matrix
            angles = objDict['_angles']
            shifts = objDict['_shifts']
            transformation = eman.Transform({"type": "spider",
                                             "phi": angles[0],
                                             "theta": angles[1],
                                             "psi": angles[2],
                                             "tx": shifts[0],
                                             "ty": shifts[1],
                                             "tz": shifts[2],
                                             "mirror": 0,  ####TODO: test flip
                                             "scale": 1.0})
        
        if transformation is not None:
            imageData.set_attr('xform.projection', transformation)
        
        outputFile = str(objDict['hdfFn'])
        if outputFile != fnHdf:
            i = 0
            fnHdf = outputFile

        imageData.write_image(outputFile, i, eman.EMUtil.ImageType.IMAGE_HDF, False)
        i += 1
        print "OK"
        sys.stdout.flush()
        line = sys.stdin.readline()
    print "DONE"