def kirian_delta_vs_ewald_proximity(unit_cell, miller_indices, crystal_rotation_matrix, ewald_radius, d_min, detector_distance, detector_size, detector_pixels): from scitbx import matrix from libtbx.math_utils import nearest_integer cr = matrix.sqr(crystal_rotation_matrix) a_matrix = cr * matrix.sqr( unit_cell.fractionalization_matrix()).transpose() a_inv = a_matrix.inverse() dsx, dsy = detector_size dpx, dpy = detector_pixels deltas = [[] for _ in xrange(len(miller_indices))] h_lookup = {} for i, h in enumerate(miller_indices): h_lookup[h] = i for pi in xrange(dpx): for pj in xrange(dpy): cx = ((pi + 0.5) / dpx - 0.5) * dsx cy = ((pj + 0.5) / dpy - 0.5) * dsy lo = matrix.col((cx, cy, -detector_distance)) ko = lo.normalize() * ewald_radius ki = matrix.col((0, 0, -ewald_radius)) dk = ki - ko h_frac = a_inv * dk h = matrix.col([nearest_integer(_) for _ in h_frac]) if (h.elems == (0, 0, 0)): continue g_hkl = a_matrix * h delta = (dk - g_hkl).length() i = h_lookup.get(h.elems) if (i is None): assert unit_cell.d(h) < d_min else: deltas[i].append(delta) def ewald_proximity(h): # compare with code in image_simple.hpp rv = matrix.col(unit_cell.reciprocal_space_vector(h)) rvr = cr * rv rvre = matrix.col((rvr[0], rvr[1], rvr[2] + ewald_radius)) rvre_len = rvre.length() return abs(1 - rvre_len / ewald_radius) def write_xy(): fn_xy = "kirian_delta_vs_ewald_proximity.xy" print "Writing file:", fn_xy f = open(fn_xy, "w") print >> f, """\ @with g0 @ s0 symbol 1 @ s0 symbol size 0.1 @ s0 line type 0""" for h, ds in zip(miller_indices, deltas): if (len(ds) != 0): print >> f, min(ds), ewald_proximity(h) print >> f, "&" print write_xy() STOP()
def exercise_integer(): from libtbx.math_utils import iround, iceil, ifloor, nearest_integer assert iround(0) == 0 assert iround(1.4) == 1 assert iround(-1.4) == -1 assert iround(1.6) == 2 assert iround(-1.6) == -2 assert iceil(0) == 0 assert iceil(1.1) == 2 assert iceil(-1.1) == -1 assert iceil(1.9) == 2 assert iceil(-1.9) == -1 assert ifloor(0) == 0 assert ifloor(1.1) == 1 assert ifloor(-1.1) == -2 assert ifloor(1.9) == 1 assert ifloor(-1.9) == -2 for i in xrange(-3, 3 + 1): assert nearest_integer(i + 0.3) == i assert nearest_integer(i + 0.7) == i + 1
def exercise_integer(): from libtbx.math_utils import iround, iceil, ifloor, nearest_integer assert iround(0) == 0 assert iround(1.4) == 1 assert iround(-1.4) == -1 assert iround(1.6) == 2 assert iround(-1.6) == -2 assert iceil(0) == 0 assert iceil(1.1) == 2 assert iceil(-1.1) == -1 assert iceil(1.9) == 2 assert iceil(-1.9) == -1 assert ifloor(0) == 0 assert ifloor(1.1) == 1 assert ifloor(-1.1) == -2 assert ifloor(1.9) == 1 assert ifloor(-1.9) == -2 for i in xrange(-3,3+1): assert nearest_integer(i+0.3) == i assert nearest_integer(i+0.7) == i+1
def kirian_delta_vs_ewald_proximity( unit_cell, miller_indices, crystal_rotation_matrix, ewald_radius, d_min, detector_distance, detector_size, detector_pixels): from scitbx import matrix from libtbx.math_utils import nearest_integer cr = matrix.sqr(crystal_rotation_matrix) a_matrix = cr * matrix.sqr(unit_cell.fractionalization_matrix()).transpose() a_inv = a_matrix.inverse() dsx, dsy = detector_size dpx, dpy = detector_pixels deltas = [[] for _ in xrange(len(miller_indices))] h_lookup = {} for i,h in enumerate(miller_indices): h_lookup[h] = i for pi in xrange(dpx): for pj in xrange(dpy): cx = ((pi + 0.5) / dpx - 0.5) * dsx cy = ((pj + 0.5) / dpy - 0.5) * dsy lo = matrix.col((cx, cy, -detector_distance)) ko = lo.normalize() * ewald_radius ki = matrix.col((0,0,-ewald_radius)) dk = ki - ko h_frac = a_inv * dk h = matrix.col([nearest_integer(_) for _ in h_frac]) if (h.elems == (0,0,0)): continue g_hkl = a_matrix * h delta = (dk - g_hkl).length() i = h_lookup.get(h.elems) if (i is None): assert unit_cell.d(h) < d_min else: deltas[i].append(delta) def ewald_proximity(h): # compare with code in image_simple.hpp rv = matrix.col(unit_cell.reciprocal_space_vector(h)) rvr = cr * rv rvre = matrix.col((rvr[0], rvr[1], rvr[2]+ewald_radius)) rvre_len = rvre.length() return abs(1 - rvre_len / ewald_radius) def write_xy(): fn_xy = "kirian_delta_vs_ewald_proximity.xy" print "Writing file:", fn_xy f = open(fn_xy, "w") print >> f, """\ @with g0 @ s0 symbol 1 @ s0 symbol size 0.1 @ s0 line type 0""" for h, ds in zip(miller_indices, deltas): if (len(ds) != 0): print >> f, min(ds), ewald_proximity(h) print >> f, "&" print write_xy() STOP()