def recons3d_4nnw_MPI( myid, prjlist, bckgdata, snr=1.0, sign=1, symmetry="c1", finfo=None, npad=2, xysize=-1, zsize=-1, mpi_comm=None, smearstep=0.0, fsc=None, ): """ recons3d_4nn_ctf - calculate CTF-corrected 3-D reconstruction from a set of projections using three Eulerian angles, two shifts, and CTF settings for each projeciton image Input stack: name of the stack file containing projection data, projections have to be squares prjlist: list of projections to be included in the reconstruction or image iterator bckgdata = [get_im("tsd.hdf"),read_text_file("data_stamp.txt")] snr: Signal-to-Noise Ratio of the data sign: sign of the CTF symmetry: point-group symmetry to be enforced, each projection will enter the reconstruction in all symmetry-related directions. """ pass # IMPORTIMPORTIMPORT from sp_utilities import reduce_EMData_to_root, pad pass # IMPORTIMPORTIMPORT from EMAN2 import Reconstructors pass # IMPORTIMPORTIMPORT from sp_utilities import iterImagesList, set_params_proj, model_blank pass # IMPORTIMPORTIMPORT from mpi import MPI_COMM_WORLD pass # IMPORTIMPORTIMPORT import types if mpi_comm == None: mpi_comm = mpi.MPI_COMM_WORLD if type(prjlist) == list: prjlist = sp_utilities.iterImagesList(prjlist) if not prjlist.goToNext(): sp_global_def.ERROR("empty input list", "recons3d_4nnw_MPI", 1) imgsize = prjlist.image().get_xsize() if prjlist.image().get_ysize() != imgsize: imgsize = max(imgsize, prjlist.image().get_ysize()) dopad = True else: dopad = False prjlist.goToPrev() # Do the FSC shtick. bnx = old_div(imgsize * npad, 2) + 1 if fsc: pass # IMPORTIMPORTIMPORT from math import sqrt pass # IMPORTIMPORTIMPORT from sp_utilities import reshape_1d t = [0.0] * len(fsc) for i in range(len(fsc)): t[i] = min(max(fsc[i], 0.0), 0.999) t = sp_utilities.reshape_1d(t, len(t), npad * len(t)) refvol = sp_utilities.model_blank(bnx, 1, 1, 0.0) for i in range(len(fsc)): refvol.set_value_at(i, t[i]) else: refvol = sp_utilities.model_blank(bnx, 1, 1, 1.0) refvol.set_attr("fudge", 1.0) fftvol = EMAN2_cppwrap.EMData() weight = EMAN2_cppwrap.EMData() if smearstep > 0.0: # if myid == 0: print " Setting smear in prepare_recons_ctf" ns = 1 smear = [] for j in range(-ns, ns + 1): if j != 0: for i in range(-ns, ns + 1): for k in range(-ns, ns + 1): smear += [ i * smearstep, j * smearstep, k * smearstep, 1.0 ] # Deal with theta = 0.0 cases prj = [] for i in range(-ns, ns + 1): for k in range(-ns, ns + 1): prj.append(i + k) for i in range(-2 * ns, 2 * ns + 1, 1): smear += [i * smearstep, 0.0, 0.0, float(prj.count(i))] # if myid == 0: print " Smear ",smear fftvol.set_attr("smear", smear) if xysize == -1 and zsize == -1: params = { "size": imgsize, "npad": npad, "snr": snr, "sign": sign, "symmetry": symmetry, "refvol": refvol, "fftvol": fftvol, "weight": weight, } r = EMAN2_cppwrap.Reconstructors.get("nn4_ctfw", params) else: if xysize != -1 and zsize != -1: rx = old_div(float(xysize), imgsize) ry = old_div(float(xysize), imgsize) rz = old_div(float(zsize), imgsize) elif xysize != -1: rx = old_div(float(xysize), imgsize) ry = old_div(float(xysize), imgsize) rz = 1.0 else: rx = 1.0 ry = 1.0 rz = old_div(float(zsize), imgsize) # There is an error here with sizeprojection PAP 10/22/2014 params = { "size": sizeprojection, "npad": npad, "snr": snr, "sign": sign, "symmetry": symmetry, "fftvol": fftvol, "weight": weight, "xratio": rx, "yratio": ry, "zratio": rz, } r = EMAN2_cppwrap.Reconstructors.get("nn4_ctf_rect", params) r.setup() # from utilities import model_blank, get_im, read_text_file # bckgdata = [get_im("tsd.hdf"),read_text_file("data_stamp.txt")] nnx = bckgdata[0].get_xsize() nny = bckgdata[0].get_ysize() bckgnoise = [] for i in range(nny): prj = sp_utilities.model_blank(nnx) for k in range(nnx): prj[k] = bckgdata[0].get_value_at(k, i) bckgnoise.append(prj) datastamp = bckgdata[1] if not (finfo is None): nimg = 0 while prjlist.goToNext(): prj = prjlist.image() try: stmp = old_div(nnx, 0) stmp = prj.get_attr("ptcl_source_image") except: try: stmp = prj.get_attr("ctf") stmp = round(stmp.defocus, 4) except: sp_global_def.ERROR( "Either ptcl_source_image or ctf has to be present in the header.", "recons3d_4nnw_MPI", 1, myid, ) try: indx = datastamp.index(stmp) except: sp_global_def.ERROR("Problem with indexing ptcl_source_image.", "recons3d_4nnw_MPI", 1, myid) if dopad: prj = sp_utilities.pad(prj, imgsize, imgsize, 1, "circumference") prj.set_attr("bckgnoise", bckgnoise[indx]) insert_slices(r, prj) if not (finfo is None): nimg += 1 finfo.write(" %4d inserted\n" % (nimg)) finfo.flush() del sp_utilities.pad if not (finfo is None): finfo.write("begin reduce\n") finfo.flush() sp_utilities.reduce_EMData_to_root(fftvol, myid, comm=mpi_comm) sp_utilities.reduce_EMData_to_root(weight, myid, comm=mpi_comm) if not (finfo is None): finfo.write("after reduce\n") finfo.flush() if myid == 0: dummy = r.finish(True) else: pass # IMPORTIMPORTIMPORT from sp_utilities import model_blank if xysize == -1 and zsize == -1: fftvol = sp_utilities.model_blank(imgsize, imgsize, imgsize) else: if zsize == -1: fftvol = sp_utilities.model_blank(xysize, xysize, imgsize) elif xysize == -1: fftvol = sp_utilities.model_blank(imgsize, imgsize, zsize) else: fftvol = sp_utilities.model_blank(xysize, xysize, zsize) return fftvol
def recons3d_4nn_ctf_MPI( myid, prjlist, snr=1.0, sign=1, symmetry="c1", finfo=None, npad=2, xysize=-1, zsize=-1, mpi_comm=None, smearstep=0.0, ): """ recons3d_4nn_ctf - calculate CTF-corrected 3-D reconstruction from a set of projections using three Eulerian angles, two shifts, and CTF settings for each projeciton image Input stack: name of the stack file containing projection data, projections have to be squares list_proj: list of projections to be included in the reconstruction or image iterator snr: Signal-to-Noise Ratio of the data sign: sign of the CTF symmetry: point-group symmetry to be enforced, each projection will enter the reconstruction in all symmetry-related directions. """ if mpi_comm == None: mpi_comm = mpi.MPI_COMM_WORLD if type(prjlist) == list: prjlist = sp_utilities.iterImagesList(prjlist) if not prjlist.goToNext(): sp_global_def.ERROR("empty input list", "recons3d_4nn_ctf_MPI", 1) imgsize = prjlist.image().get_xsize() if prjlist.image().get_ysize() != imgsize: imgsize = max(imgsize, prjlist.image().get_ysize()) dopad = True else: dopad = False prjlist.goToPrev() fftvol = EMAN2_cppwrap.EMData() if smearstep > 0.0: # if myid == 0: print " Setting smear in prepare_recons_ctf" ns = 1 smear = [] for j in range(-ns, ns + 1): if j != 0: for i in range(-ns, ns + 1): for k in range(-ns, ns + 1): smear += [ i * smearstep, j * smearstep, k * smearstep, 1.0 ] # Deal with theta = 0.0 cases prj = [] for i in range(-ns, ns + 1): for k in range(-ns, ns + 1): prj.append(i + k) for i in range(-2 * ns, 2 * ns + 1, 1): smear += [i * smearstep, 0.0, 0.0, float(prj.count(i))] # if myid == 0: print " Smear ",smear fftvol.set_attr("smear", smear) weight = EMAN2_cppwrap.EMData() if xysize == -1 and zsize == -1: params = { "size": imgsize, "npad": npad, "snr": snr, "sign": sign, "symmetry": symmetry, "fftvol": fftvol, "weight": weight, } r = EMAN2_cppwrap.Reconstructors.get("nn4_ctf", params) else: if xysize != -1 and zsize != -1: rx = old_div(float(xysize), imgsize) ry = old_div(float(xysize), imgsize) rz = old_div(float(zsize), imgsize) elif xysize != -1: rx = old_div(float(xysize), imgsize) ry = old_div(float(xysize), imgsize) rz = 1.0 else: rx = 1.0 ry = 1.0 rz = old_div(float(zsize), imgsize) # There is an error here with sizeprojection PAP 10/22/2014 params = { "size": sizeprojection, "npad": npad, "snr": snr, "sign": sign, "symmetry": symmetry, "fftvol": fftvol, "weight": weight, "xratio": rx, "yratio": ry, "zratio": rz, } r = EMAN2_cppwrap.Reconstructors.get("nn4_ctf_rect", params) r.setup() # if not (finfo is None): nimg = 0 while prjlist.goToNext(): prj = prjlist.image() if dopad: prj = sp_utilities.pad(prj, imgsize, imgsize, 1, "circumference") # if params: insert_slices(r, prj) if not (finfo is None): nimg += 1 finfo.write(" %4d inserted\n" % (nimg)) finfo.flush() del sp_utilities.pad if not (finfo is None): finfo.write("begin reduce\n") finfo.flush() sp_utilities.reduce_EMData_to_root(fftvol, myid, comm=mpi_comm) sp_utilities.reduce_EMData_to_root(weight, myid, comm=mpi_comm) if not (finfo is None): finfo.write("after reduce\n") finfo.flush() if myid == 0: dummy = r.finish(True) else: if xysize == -1 and zsize == -1: fftvol = sp_utilities.model_blank(imgsize, imgsize, imgsize) else: if zsize == -1: fftvol = sp_utilities.model_blank(xysize, xysize, imgsize) elif xysize == -1: fftvol = sp_utilities.model_blank(imgsize, imgsize, zsize) else: fftvol = sp_utilities.model_blank(xysize, xysize, zsize) return fftvol
def recons3d_4nn_MPI( myid, prjlist, symmetry="c1", finfo=None, snr=1.0, npad=2, xysize=-1, zsize=-1, mpi_comm=None, ): if mpi_comm == None: mpi_comm = mpi.MPI_COMM_WORLD if type(prjlist) == list: prjlist = sp_utilities.iterImagesList(prjlist) if not prjlist.goToNext(): sp_global_def.ERROR("empty input list", "recons3d_4nn_MPI", 1) imgsize = prjlist.image().get_xsize() if prjlist.image().get_ysize() != imgsize: imgsize = max(imgsize, prjlist.image().get_ysize()) dopad = True else: dopad = False prjlist.goToPrev() fftvol = EMAN2_cppwrap.EMData() weight = EMAN2_cppwrap.EMData() if xysize == -1 and zsize == -1: params = { "size": imgsize, "npad": npad, "symmetry": symmetry, "fftvol": fftvol, "weight": weight, "snr": snr, } r = EMAN2_cppwrap.Reconstructors.get("nn4", params) else: if xysize != -1 and zsize != -1: rx = old_div(float(xysize), imgsize) ry = old_div(float(xysize), imgsize) rz = old_div(float(zsize), imgsize) elif xysize != -1: rx = old_div(float(xysize), imgsize) ry = old_div(float(xysize), imgsize) rz = 1.0 else: rx = 1.0 ry = 1.0 rz = old_div(float(zsize), imgsize) params = { "sizeprojection": imgsize, "npad": npad, "symmetry": symmetry, "fftvol": fftvol, "weight": weight, "xratio": rx, "yratio": ry, "zratio": rz, } r = EMAN2_cppwrap.Reconstructors.get("nn4_rect", params) r.setup() if not (finfo is None): nimg = 0 while prjlist.goToNext(): prj = prjlist.image() if dopad: prj = sp_utilities.pad(prj, imgsize, imgsize, 1, "circumference") insert_slices(r, prj) if not (finfo is None): nimg += 1 finfo.write("Image %4d inserted.\n" % (nimg)) finfo.flush() if not (finfo is None): finfo.write("Begin reducing ...\n") finfo.flush() sp_utilities.reduce_EMData_to_root(fftvol, myid, comm=mpi_comm) sp_utilities.reduce_EMData_to_root(weight, myid, comm=mpi_comm) if myid == 0: dummy = r.finish(True) else: if xysize == -1 and zsize == -1: fftvol = sp_utilities.model_blank(imgsize, imgsize, imgsize) else: if zsize == -1: fftvol = sp_utilities.model_blank(xysize, xysize, imgsize) elif xysize == -1: fftvol = sp_utilities.model_blank(imgsize, imgsize, zsize) else: fftvol = sp_utilities.model_blank(xysize, xysize, zsize) return fftvol