예제 #1
0
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
예제 #2
0
def identify_diagonal_maxima(phi_start, phi_end, phi_width,
                             wavelength, lattice, matrix):
    '''Find phi rotation values where the diagonals of the matrix
    [R][U] are maximised - logically this will maximise the derivative
    of the spot positions as a function of the cell axes.'''

    cell, A, U = parse_matrix(matrix)

    # transform U matrix to xia2 coordinate frame

    u1, u2, u3 = mat2vec(U)
    ux1 = mosflm_to_xia2(u1)
    ux2 = mosflm_to_xia2(u2)
    ux3 = mosflm_to_xia2(u3)
    UX = vec2mat((ux1, ux2, ux3))

    # print the new U matrix
    print 'UX Matrix:'
    print '%.4f %.4f %.4f' % (UX[0], UX[1], UX[2])
    print '%.4f %.4f %.4f' % (UX[3], UX[4], UX[5])
    print '%.4f %.4f %.4f' % (UX[6], UX[7], UX[8])

    # set up the rotations

    phi = phi_start + 0.5 * phi_width

    # initialize search variables

    phi_a = phi_start
    phi_b = phi_start
    phi_c = phi_start

    ru_a = 0.0
    ru_b = 0.0
    ru_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.0

    while phi < phi_end:
        RX = rot_x(phi)
        # RX = rot_y(phi)

        RXU = matmul(RX, UX)

        if math.fabs(RXU[0]) > ru_a:
            ru_a = math.fabs(RXU[0])
            phi_a = phi
            ia = i

        if math.fabs(RXU[4]) > ru_b:
            ru_b = math.fabs(RXU[4])
            phi_b = phi
            ib = i

        if math.fabs(RXU[8]) > ru_c:
            ru_c = math.fabs(RXU[8])
            phi_c = phi
            ic = i

        phi += phi_width
        i += 1

    # return the closest positions and the angular offset from
    # perpendicularity...


    return phi_a, phi_b, phi_c, ru_a, ru_b, ru_c, ia, ib, ic
예제 #3
0
def write_dot_reciprocal_axes(phi_start, phi_end, phi_width,
                              wavelength, lattice, matrix):

    a, b, c = get_reciprocal_space_primitive_matrix(lattice, matrix)

    # calculate the cross terms
    ab = (0.5 * (a[0] + b[0]),
          0.5 * (a[1] + b[1]),
          0.5 * (a[2] + b[2]))

    bc = (0.5 * (b[0] + c[0]),
          0.5 * (b[1] + c[1]),
          0.5 * (b[2] + c[2]))

    ca = (0.5 * (c[0] + a[0]),
          0.5 * (c[1] + a[1]),
          0.5 * (c[2] + a[2]))

    phi = phi_start + 0.5 * phi_width
    i = 0

    dot_a = 0.0
    dot_b = 0.0
    doc_c = 0.0

    dot_ab = 0.0
    dot_bc = 0.0
    doc_ca = 0.0

    fout = open('dot_recl.txt', 'w')

    while phi < phi_end:

        i += 1

        RX = rot_x(phi)

        RXa = matvecmul(RX, a)
        RXb = matvecmul(RX, b)
        RXc = matvecmul(RX, c)

        dot_a = math.fabs(RXa[2])
        dot_b = math.fabs(RXb[2])
        dot_c = math.fabs(RXc[2])

        RXab = matvecmul(RX, ab)
        RXbc = matvecmul(RX, bc)
        RXca = matvecmul(RX, ca)

        dot_ab = math.fabs(RXab[2])
        dot_bc = math.fabs(RXbc[2])
        dot_ca = math.fabs(RXca[2])

        fout.write('%d %.2f %.4f %.4f %.4f %.4f %.4f %.4f\n' %
                   (i, phi, dot_a, dot_b, dot_c, dot_ab, dot_bc, dot_ca))

        phi += phi_width

    fout.close()

    return
예제 #4
0
def identify_parallel_reciprocal_axes(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

    a, b, c = get_reciprocal_space_primitive_matrix(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 = 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_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
            ia = i

        if math.fabs(RXb[2]) > dot_b:
            dot_b = math.fabs(RXb[2])
            phi_b = phi
            ib = i

        if math.fabs(RXc[2]) > dot_c:
            dot_c = math.fabs(RXc[2])
            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