Пример #1
0
def prg(volume, params):
    """Given a volume, a set of projection angles, and Kaiser-Bessel
	   window parameters, use gridding to generate projection
	"""
    Mx = volume.get_xsize()
    My = volume.get_ysize()
    Mz = volume.get_zsize()
    if (Mx == Mz & My == Mz):
        volft, kb = prep_vol(volume)
        return prgs(volft, kb, params)
    else:
        volft, kbx, kby, kbz = prep_vol(volume)
        return prgs(volft, kbz, params, kbx, kby)
Пример #2
0
def generate_templates(volft, kb, x_half_size, y_half_size, psi_half_size,
                       projection_location):

    import numpy as np

    x_length = 2 * x_half_size + 1
    y_length = 2 * y_half_size + 1
    psi_length = 2 * psi_half_size + 1

    x = np.linspace(-x_half_size, x_half_size, x_length)
    y = np.linspace(-y_half_size, y_half_size, y_length)
    psi = np.linspace(-psi_half_size, psi_half_size, psi_length)

    all_templates = [[[None for i in range(psi_length)]
                      for j in range(y_length)] for k in range(x_length)]
    for x_i in range(x_length):
        # print "x_i", x_i
        for y_i in range(y_length):
            for psi_i in range(psi_length):
                projection_location_displacement = projection_location[:]
                projection_location_displacement[2] += psi[psi_i]
                projection_location_displacement[3] += x[x_i]
                projection_location_displacement[4] += y[y_i]
                # print "x_i, y_i, psi", x_i, y_i, psi_i
                all_templates[x_i][y_i][psi_i] = prgs(
                    volft, kb, projection_location_displacement)

    return all_templates
Пример #3
0
def prj(vol, params, stack=None):
    """
		Name
			prj - calculate a set of 2-D projection of a 3-D volume using gridding
		Input
			vol: input volume, all dimensions have to be the same (nx=ny=nz)
			params: a list of input parameters given as a list [i][phi, theta, psi, sx, sy], projection in calculated using the three Eulerian angles and then shifted by sx,sy
		Output
			proj
				either: an in-core stack of generated 2-D projections
			stack
	"""
    from sp_utilities import set_params_proj
    from sp_projection import prep_vol
    volft, kb = prep_vol(vol)
    for i in range(len(params)):
        proj = prgs(volft, kb, params[i])
        set_params_proj(proj, [
            params[i][0], params[i][1], params[i][2], -params[i][3],
            -params[i][4]
        ])
        proj.set_attr_dict({'ctf_applied': 0})

        if (stack):
            proj.write_image(stack, i)
        else:
            if (i == 0): out = []
            out.append(proj)
    if (stack): return
    else: return out
Пример #4
0
def prgq(volft, kb, nx, delta, ref_a, sym, MPI=False):
    """
	  Generate set of projections based on even angles
	  The command returns list of ffts of projections
	"""
    from sp_projection import prep_vol, prgs
    from sp_applications import MPI_start_end
    from sp_utilities import even_angles, model_blank
    from sp_fundamentals import fft
    # generate list of Eulerian angles for reference projections
    #  phi, theta, psi
    mode = "F"
    ref_angles = even_angles(delta,
                             symmetry=sym,
                             method=ref_a,
                             phiEqpsi="Minus")
    cnx = nx // 2 + 1
    cny = nx // 2 + 1
    num_ref = len(ref_angles)

    if MPI:
        from mpi import mpi_comm_rank, mpi_comm_size, MPI_COMM_WORLD
        myid = mpi_comm_rank(MPI_COMM_WORLD)
        ncpu = mpi_comm_size(MPI_COMM_WORLD)
    else:
        ncpu = 1
        myid = 0
    from sp_applications import MPI_start_end
    ref_start, ref_end = MPI_start_end(num_ref, ncpu, myid)

    prjref = [
    ]  # list of (image objects) reference projections in Fourier representation

    for i in range(num_ref):
        prjref.append(model_blank(
            nx,
            nx))  # I am not sure why is that necessary, why not put None's??

    for i in range(ref_start, ref_end):
        prjref[i] = prgs(
            volft, kb,
            [ref_angles[i][0], ref_angles[i][1], ref_angles[i][2], 0.0, 0.0])

    if MPI:
        from sp_utilities import bcast_EMData_to_all
        for i in range(num_ref):
            for j in range(ncpu):
                ref_start, ref_end = MPI_start_end(num_ref, ncpu, j)
                if i >= ref_start and i < ref_end: rootid = j
            bcast_EMData_to_all(prjref[i], myid, rootid)

    for i in range(len(ref_angles)):
        prjref[i].set_attr_dict({
            "phi": ref_angles[i][0],
            "theta": ref_angles[i][1],
            "psi": ref_angles[i][2]
        })

    return prjref
Пример #5
0
def generate_helimic(refvol,
                     outdir,
                     pixel,
                     CTF=False,
                     Cs=2.0,
                     voltage=200.0,
                     ampcont=10.0,
                     nonoise=False,
                     rand_seed=14567):

    from sp_utilities import model_blank, model_gauss, model_gauss_noise, pad, get_im
    from random import random
    from sp_projection import prgs, prep_vol
    from sp_filter import filt_gaussl, filt_ctf
    from EMAN2 import EMAN2Ctf

    if os.path.exists(outdir):
        ERROR(
            "Output directory exists, please change the name and restart the program"
        )
        return

    os.mkdir(outdir)
    seed(rand_seed)
    Util.set_randnum_seed(rand_seed)
    angles = []
    for i in range(3):
        angles.append([0.0 + 60.0 * i, 90.0 - i * 5, 0.0, 0.0, 0.0])

    nangle = len(angles)

    volfts = get_im(refvol)
    nx = volfts.get_xsize()
    ny = volfts.get_ysize()
    nz = volfts.get_zsize()
    volfts, kbx, kby, kbz = prep_vol(volfts)
    iprj = 0
    width = 500
    xstart = 0
    ystart = 0

    for idef in range(3, 6):
        mic = model_blank(2048, 2048)
        #defocus = idef*0.2
        defocus = idef * 0.6  ##@ming
        if CTF:
            #ctf = EMAN2Ctf()
            #ctf.from_dict( {"defocus":defocus, "cs":Cs, "voltage":voltage, "apix":pixel, "ampcont":ampcont, "bfactor":0.0} )
            from sp_utilities import generate_ctf
            ctf = generate_ctf(
                [defocus, 2, 200, 1.84, 0.0, ampcont, defocus * 0.2, 80]
            )  ##@ming   the range of astigmatism amplitude is between 10 percent and 22 percent. 20 percent is a good choice.
        i = idef - 4
        for k in range(1):
            psi = 90 + 10 * i
            proj = prgs(
                volfts, kbz,
                [angles[idef - 3][0], angles[idef - 3][1], psi, 0.0, 0.0], kbx,
                kby)
            proj = Util.window(proj, 320, nz)
            mic += pad(proj, 2048, 2048, 1, 0.0, 750 * i, 20 * i, 0)

        if not nonoise: mic += model_gauss_noise(30.0, 2048, 2048)
        if CTF:
            #apply CTF
            mic = filt_ctf(mic, ctf)

        if not nonoise:
            mic += filt_gaussl(model_gauss_noise(17.5, 2048, 2048), 0.3)

        mic.write_image("%s/mic%1d.hdf" % (outdir, idef - 3), 0)
Пример #6
0
def prepare_refrings(
    volft,
    kb,
    nz=-1,
    delta=2.0,
    ref_a="P",
    sym="c1",
    numr=None,
    MPI=False,
    phiEqpsi="Zero",
    kbx=None,
    kby=None,
    initial_theta=None,
    delta_theta=None,
    initial_phi=None,
):
    """
		Generate quasi-evenly distributed reference projections converted to rings
		ref_a can be a list of angles, in which case it is used instead of being generated
	"""

    # mpi communicator can be sent by the MPI parameter
    if type(MPI) is bool:
        if MPI:
            mpi_comm = mpi.MPI_COMM_WORLD
    else:
        mpi_comm = MPI
        MPI = True

    mode = "F"

    if type(ref_a) is list:
        # if ref_a is  list, it has to be a list of projection directions, use it
        ref_angles = ref_a
    else:
        # generate list of Eulerian angles for reference projections
        #  phi, theta, psi
        if initial_theta and initial_phi:
            ref_angles = sp_utilities.even_angles(
                delta,
                theta1=initial_theta,
                phi1=initial_phi,
                symmetry=sym,
                method=ref_a,
                phiEqpsi=phiEqpsi,
            )
        else:
            if initial_theta is None:
                if sym[:1] == "c" or sym[:1] == "d":
                    ref_angles = sp_utilities.even_angles(delta,
                                                          symmetry=sym,
                                                          method=ref_a,
                                                          phiEqpsi=phiEqpsi)
                else:
                    psp = sp_fundamentals.symclass(sym)
                    ref_angles = psp.even_angles(delta)
                    del psp
            else:
                if delta_theta is None:
                    delta_theta = 1.0
                ref_angles = sp_utilities.even_angles(
                    delta,
                    theta1=initial_theta,
                    theta2=delta_theta,
                    symmetry=sym,
                    method=ref_a,
                    phiEqpsi=phiEqpsi,
                )

    wr_four = ringwe(numr, mode)
    cnx = old_div(nz, 2) + 1
    cny = old_div(nz, 2) + 1
    num_ref = len(ref_angles)

    if MPI:
        myid = mpi.mpi_comm_rank(mpi_comm)
        ncpu = mpi.mpi_comm_size(mpi_comm)
    else:
        ncpu = 1
        myid = 0

    if nz < 1:
        sp_global_def.ERROR("Data size has to be given (nz)",
                            "prepare_refrings", 1, myid)

    ref_start, ref_end = sp_applications.MPI_start_end(num_ref, ncpu, myid)

    refrings = (
        []
    )  # list of (image objects) reference projections in Fourier representation

    sizex = numr[len(numr) - 2] + numr[len(numr) - 1] - 1

    for i in range(num_ref):
        prjref = EMAN2_cppwrap.EMData()
        prjref.set_size(sizex, 1, 1)
        refrings.append(prjref)

    if kbx is None:
        for i in range(ref_start, ref_end):
            prjref = sp_projection.prgs(
                volft,
                kb,
                [
                    ref_angles[i][0], ref_angles[i][1], ref_angles[i][2], 0.0,
                    0.0
                ],
            )
            cimage = EMAN2_cppwrap.Util.Polar2Dm(
                prjref, cnx, cny, numr, mode)  # currently set to quadratic....
            EMAN2_cppwrap.Util.Normalize_ring(cimage, numr, 0)
            EMAN2_cppwrap.Util.Frngs(cimage, numr)
            EMAN2_cppwrap.Util.Applyws(cimage, numr, wr_four)
            refrings[i] = cimage
    else:
        for i in range(ref_start, ref_end):
            prjref = sp_projection.prgs(
                volft,
                kb,
                [
                    ref_angles[i][0], ref_angles[i][1], ref_angles[i][2], 0.0,
                    0.0
                ],
                kbx,
                kby,
            )
            cimage = EMAN2_cppwrap.Util.Polar2Dm(
                prjref, cnx, cny, numr, mode)  # currently set to quadratic....
            EMAN2_cppwrap.Util.Normalize_ring(cimage, numr, 0)
            EMAN2_cppwrap.Util.Frngs(cimage, numr)
            EMAN2_cppwrap.Util.Applyws(cimage, numr, wr_four)
            refrings[i] = cimage

    if MPI:
        sp_utilities.bcast_compacted_EMData_all_to_all(refrings,
                                                       myid,
                                                       comm=mpi_comm)

    for i in range(len(ref_angles)):
        n1, n2, n3 = sp_utilities.getfvec(ref_angles[i][0], ref_angles[i][1])
        refrings[i].set_attr_dict({
            "phi": ref_angles[i][0],
            "theta": ref_angles[i][1],
            "psi": ref_angles[i][2],
            "n1": n1,
            "n2": n2,
            "n3": n3,
        })

    return refrings