def compute_something(phi_start, phi_end, phi_width, wavelength, lattice, matrix): # compute the P1 real-space cell axes a, b, c = mosflm_a_matrix_to_real_space(wavelength, lattice, matrix) # compute rotations of these and find minimum for axis.Z - that is the # Z component of the rotated axis... check workings and definitions! phi = phi_start + 0.5 * phi_width # initialize search variables phi_a = phi_start phi_b = phi_start phi_c = phi_start dot_a = 100.0 dot_b = 100.0 dot_c = 100.0 while phi < phi_end: RX = rot_x(phi) RXa = matvecmul(RX, a) RXb = matvecmul(RX, b) RXc = matvecmul(RX, c) if math.fabs(RXa[2]) < dot_a: dot_a = math.fabs(RXa[2]) phi_a = phi if math.fabs(RXb[2]) < dot_b: dot_b = math.fabs(RXb[2]) phi_b = phi if math.fabs(RXc[2]) < dot_c: dot_c = math.fabs(RXc[2]) phi_c = phi phi += phi_width length_a = math.sqrt(dot(a, a)) length_b = math.sqrt(dot(b, b)) length_c = math.sqrt(dot(c, c)) pi = 4.0 * math.atan(1.0) angle_a = 0.5 * pi - math.acos(dot_a / length_a) angle_b = 0.5 * pi - math.acos(dot_b / length_b) angle_c = 0.5 * pi - math.acos(dot_c / length_c) return phi_a, phi_b, phi_c, angle_a, angle_b, angle_c
def identify_parallel_reciprocal_axes2(phi_start, phi_end, phi_width, wavelength, lattice, matrix): '''Find phi values which present the primitive reciprocal unit cell axes as near as possible to being perpendicular to the beam vector.''' # FIXME should add a test in here that the mosflm orientation matrix # corresponds to the asserted lattice... # find thee P1 reciprocal-space cell axes - note well am doing this # for the matrix in whatever setting cell, A, U = parse_matrix(matrix) a, b, c = mat2vec(A) # compute rotations of these and find minimum for axis.Z - that is the # Z component of the rotated axis... check workings and definitions! phi = phi_start + 0.5 * phi_width # initialize search variables phi_a = phi_start phi_b = phi_start phi_c = phi_start dot_a = 0.0 dot_b = 0.0 dot_c = 0.0 ia = 0 ib = 0 ic = 0 i = 0 # only consider the first 180 degrees of data... if phi_end - phi_start > 180: phi_end = phi_start + 180 while phi < phi_end: RX = rot_z(phi) RXa = matvecmul(RX, a) RXb = matvecmul(RX, b) RXc = matvecmul(RX, c) if math.fabs(RXa[0]) > dot_a: dot_a = math.fabs(RXa[0]) phi_a = phi ia = i if math.fabs(RXb[0]) > dot_b: dot_b = math.fabs(RXb[0]) phi_b = phi ib = i if math.fabs(RXc[0]) > dot_c: dot_c = math.fabs(RXc[0]) phi_c = phi ic = i phi += phi_width i += 1 length_a = math.sqrt(dot(a, a)) length_b = math.sqrt(dot(b, b)) length_c = math.sqrt(dot(c, c)) rtod = 180.0 / math.pi angle_a = math.fabs(rtod * math.acos(dot_a / length_a)) angle_b = math.fabs(rtod * math.acos(dot_b / length_b)) angle_c = math.fabs(rtod * math.acos(dot_c / length_c)) # return the closest positions and the angular offset from # perpendicularity... return phi_a, phi_b, phi_c, angle_a, angle_b, angle_c, ia, ib, ic