Ejemplo n.º 1
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
Ejemplo n.º 2
0
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