def subtract(p1, submap_ft, refmap_ft, sx, sy, s, a, apix, def1, def2, angast, phase, kv, ac, cs, az, el, sk, xshift, yshift, coefs_method, r, nr, pfac): c = ctf.eval_ctf(s / apix, a, def1, def2, angast, phase, kv, ac, cs, bf=0, lp=2 * apix) orient = euler2rot(np.deg2rad(az), np.deg2rad(el), np.deg2rad(sk)) pshift = np.exp(-2 * np.pi * 1j * (-xshift * sx + -yshift * sy)) p2 = vop.interpolate_slice_numba(submap_ft, orient, pfac=pfac) p2 *= pshift if coefs_method < 1: # p1s = p1 - p2 * c p1s = p2 * c elif coefs_method == 1: p3 = vop.interpolate_slice_numba(refmap_ft, orient, pfac=pfac) p3 *= pshift frc = np.abs(algo.bincorr_nb(p1, p3 * c, r, nr)) coefs = np.take(frc, r) # p1s = p1 - p2 * c * coefs p1s = p2 * c * coefs return p1s
def project(f3d, p, s, sx, sy, a, apply_ctf=False, size=None, flip_phase=False): orient = util.euler2rot(np.deg2rad(p[star.Relion.ANGLEROT]), np.deg2rad(p[star.Relion.ANGLETILT]), np.deg2rad(p[star.Relion.ANGLEPSI])) pshift = np.exp( -2 * np.pi * 1j * (-p[star.Relion.ORIGINX] * sx + -p[star.Relion.ORIGINY] * sy)) f2d = vop.interpolate_slice_numba(f3d, orient, size=size) f2d *= pshift if apply_ctf or flip_phase: apix = star.calculate_apix(p) c = ctf.eval_ctf(s / apix, a, p[star.Relion.DEFOCUSU], p[star.Relion.DEFOCUSV], p[star.Relion.DEFOCUSANGLE], p[star.Relion.PHASESHIFT], p[star.Relion.VOLTAGE], p[star.Relion.AC], p[star.Relion.CS], bf=0, lp=2 * apix) if flip_phase: c = np.sign(c) f2d *= c return f2d
def particle_xcorr(ptcl, refmap_ft): r = util.euler2rot(*np.deg2rad(ptcl[star.Relion.ANGLES])) proj = vop.interpolate_slice_numba(refmap_ft, r) c = ctf.eval_ctf(s / apix, a, def1[i], def2[i], angast[i], phase[i], kv[i], ac[i], cs[i], bf=0, lp=2 * apix) pshift = np.exp(-2 * np.pi * 1j * (-xshift[i] * sx + -yshift * sy)) proj_ctf = proj * pshift * c with mrc.ZSliceReader(ptcl[star.Relion.IMAGE_NAME]) as f: exp_image_fft = rfft2(fftshift(f.read(i))) xcor_fft = exp_image_fft * proj_ctf xcor = fftshift(irfft2(xcor_fft)) return xcor