def test_calc_offset_for_hkl(self):
     NAME = 'test_calc_offset_for_hkl'
     self.ubcalc.start_new(NAME)
     self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)
     self.ubcalc.set_U_manually(x_rotation(0))
     for hklref, hkloff, pol_ref, az_ref, sc_ref in [
         ([0, 0, 1], [1, 1, 0], 90 * TORAD, -45 * TORAD, sqrt(2)),
         ([0, 0, 1], [-1, 0, 1], 45 * TORAD, 90 * TORAD, sqrt(2)),
         ([1, 0, 0], [1, 0, 2], atan2(2, 1), 90 * TORAD, sqrt(5)),
     ]:
         pol, az, sc = self.ubcalc.calc_offset_for_hkl(hkloff, hklref)
         matrixeq_(matrix([[pol_ref, az_ref, sc_ref]]),
                   matrix([[pol, az, sc]]))
 def test_calc_hkl_offset(self):
     NAME = 'test_calc_hkl_offset'
     self.ubcalc.start_new(NAME)
     self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)
     self.ubcalc.set_U_manually(x_rotation(0))
     hkloff_110 = self.ubcalc.calc_hkl_offset(0, 0, sqrt(2), 90. * TORAD,
                                              -45 * TORAD)
     hkloff_m101 = self.ubcalc.calc_hkl_offset(0, 0, sqrt(2), 45. * TORAD,
                                               90 * TORAD)
     alpha = atan2(2, 1)
     hkloff_102 = self.ubcalc.calc_hkl_offset(sqrt(5), 0, 0, alpha,
                                              90 * TORAD)
     matrixeq_(matrix('1 1 0'), matrix(hkloff_110))
     matrixeq_(matrix('-1 0 1'), matrix(hkloff_m101))
     matrixeq_(matrix('1 0 2'), matrix(hkloff_102))
Exemplo n.º 3
0
def calcNU(nu):
    return x_rotation(nu)
Exemplo n.º 4
0
def calcMU(mu_or_alpha):
    return x_rotation(mu_or_alpha)
Exemplo n.º 5
0
def calc_OMEGAH(omegah):
    return x_rotation(omegah)                                            # (41)
Exemplo n.º 6
0
def calc_DELTA(delta):
    return x_rotation(delta)                                             # (39)
Exemplo n.º 7
0
def calcMU(mu_or_alpha):
    return x_rotation(mu_or_alpha)
Exemplo n.º 8
0
def calcGAMMA(gamma):
    return x_rotation(gamma)
Exemplo n.º 9
0
def X(th_deg):
    return x_rotation(th_deg * TORAD)
Exemplo n.º 10
0
def calcGAMMA(gamma):
    return x_rotation(gamma)
Exemplo n.º 11
0
def calcALPHA(alpha):
    return x_rotation(alpha)
Exemplo n.º 12
0
def calc_OMEGAH(omegah):
    return x_rotation(omegah)  # (41)
Exemplo n.º 13
0
def calc_DELTA(delta):
    return x_rotation(delta)  # (39)
Exemplo n.º 14
0
    def _calc_sample_angles_given_two_sample_and_reference(
            self, samp_constraints, psi, theta, q_phi, n_phi):
        """Available combinations:
        chi, phi, reference
        mu, eta, reference,
        chi=90, mu=0, reference
        """

        N_phi = _calc_N(q_phi, n_phi)
        THETA = z_rotation(-theta)
        PSI = x_rotation(psi)

        if 'chi' in samp_constraints and 'phi' in samp_constraints:

            chi = samp_constraints['chi']
            phi = samp_constraints['phi']

            CHI = calcCHI(chi)
            PHI = calcPHI(phi)
            V = CHI * PHI * N_phi * PSI.T * THETA.T                     # (56)

            xi = atan2(-V[2, 0], V[2, 2])
            eta = atan2(-V[0, 1], V[1, 1])
            mu = atan2(-V[2, 1], sqrt(V[2, 2] ** 2 + V[2, 0] ** 2))

        elif 'mu' in samp_constraints and 'eta' in samp_constraints:

            mu = samp_constraints['mu']
            eta = samp_constraints['eta']

            V = N_phi * PSI.T * THETA.T                                  # (49)

            bot = sqrt(sin(eta) ** 2 * cos(mu) ** 2 + sin(mu) ** 2)
            chi_orig = (asin(-V[2, 1] / bot) -
                   atan2(sin(mu), (sin(eta) * cos(mu))))                 # (52)

            # Choose final chi solution here to obtain compatable xi and mu
            # TODO: This temporary solution works only for one case used on i07
            #       Return a list of possible solutions?
            if is_small(eta) and is_small(mu + pi / 2):
                for chi in _generate_transformed_values(chi_orig):
                    if  pi / 2 <= chi < pi:
                        break
            else:
                chi = chi_orig

            a = sin(chi) * cos(eta)
            b = sin(chi) * sin(eta) * sin(mu) - cos(chi) * cos(mu)
            xi = atan2(V[2, 2] * a + V[2, 0] * b,
                       V[2, 0] * a - V[2, 2] * b)                        # (54)

            a = sin(chi) * sin(mu) - cos(mu) * cos(chi) * sin(eta)
            b = cos(mu) * cos(eta)
            phi = atan2(V[1, 1] * a - V[0, 1] * b,
                        V[0, 1] * a + V[1, 1] * b)                       # (55)
#            if is_small(mu+pi/2) and is_small(eta) and False:
#                phi_general = phi
#                # solved in extensions_to_yous_paper.wxm
#                phi = atan2(V[1, 1], V[0, 1])
#                logger.info("phi = %.3f or %.3f (std)",
#                            phi*TODEG, phi_general*TODEG )

        elif 'chi' in samp_constraints and 'mu' in samp_constraints:
            # derived in extensions_to_yous_paper.wxm
            chi = samp_constraints['chi']
            mu = samp_constraints['mu']

            if not is_small(mu) and not is_small(chi - pi / 2):
                raise Exception('The fixed chi, mu, psi/alpha/beta modes only '
                                ' currently work with chi=90 and mu=0')
            V = N_phi * PSI.T * THETA.T
            eta = asin(-V[2, 1])
            xi = atan2(V[2, 2], V[2, 0])
            phi = -atan2(V[0, 1], V[1, 1])

        else:
            raise DiffcalcException(
                'No code yet to handle this combination of 2 sample '
                'constraints and one reference!:' + str(samp_constraints))
        return xi, psi, mu, eta, chi, phi
Exemplo n.º 15
0
def X(th_deg):
    return x_rotation(th_deg * TORAD)
Exemplo n.º 16
0
def calcNU(nu):
    return x_rotation(nu)
Exemplo n.º 17
0
    def _calc_sample_angles_given_two_sample_and_reference(
            self, samp_constraints, psi, theta, q_phi, n_phi):
        """Available combinations:
        chi, phi, reference
        mu, eta, reference,
        chi=90, mu=0, reference
        """

        N_phi = _calc_N(q_phi, n_phi)
        THETA = z_rotation(-theta)
        PSI = x_rotation(psi)

        if 'chi' in samp_constraints and 'phi' in samp_constraints:

            chi = samp_constraints['chi']
            phi = samp_constraints['phi']

            CHI = calcCHI(chi)
            PHI = calcPHI(phi)
            V = CHI * PHI * N_phi * PSI.T * THETA.T                     # (56)

            xi = atan2(-V[2, 0], V[2, 2])
            eta = atan2(-V[0, 1], V[1, 1])
            mu = atan2(-V[2, 1], sqrt(V[2, 2] ** 2 + V[2, 0] ** 2))

        elif 'mu' in samp_constraints and 'eta' in samp_constraints:

            mu = samp_constraints['mu']
            eta = samp_constraints['eta']

            V = N_phi * PSI.T * THETA.T                                  # (49)

            bot = sqrt(sin(eta) ** 2 * cos(mu) ** 2 + sin(mu) ** 2)
            chi_orig = (asin(-V[2, 1] / bot) -
                   atan2(sin(mu), (sin(eta) * cos(mu))))                 # (52)

            # Choose final chi solution here to obtain compatable xi and mu
            # TODO: This temporary solution works only for one case used on i07
            #       Return a list of possible solutions?
            if is_small(eta) and is_small(mu + pi / 2):
                for chi in _generate_transformed_values(chi_orig):
                    if  pi / 2 <= chi < pi:
                        break
            else:
                chi = chi_orig

            a = sin(chi) * cos(eta)
            b = sin(chi) * sin(eta) * sin(mu) - cos(chi) * cos(mu)
            xi = atan2(V[2, 2] * a + V[2, 0] * b,
                       V[2, 0] * a - V[2, 2] * b)                        # (54)

            a = sin(chi) * sin(mu) - cos(mu) * cos(chi) * sin(eta)
            b = cos(mu) * cos(eta)
            phi = atan2(V[1, 1] * a - V[0, 1] * b,
                        V[0, 1] * a + V[1, 1] * b)                       # (55)
#            if is_small(mu+pi/2) and is_small(eta) and False:
#                phi_general = phi
#                # solved in extensions_to_yous_paper.wxm
#                phi = atan2(V[1, 1], V[0, 1])
#                logger.info("phi = %.3f or %.3f (std)",
#                            phi*TODEG, phi_general*TODEG )

        elif 'chi' in samp_constraints and 'mu' in samp_constraints:
            # derived in extensions_to_yous_paper.wxm
            chi = samp_constraints['chi']
            mu = samp_constraints['mu']

            if not is_small(mu) and not is_small(chi - pi / 2):
                raise Exception('The fixed chi, mu, psi/alpha/beta modes only '
                                ' currently work with chi=90 and mu=0')
            V = N_phi * PSI.T * THETA.T
            eta = asin(-V[2, 1])
            xi = atan2(V[2, 2], V[2, 0])
            phi = -atan2(V[0, 1], V[1, 1])

        else:
            raise DiffcalcException(
                'No code yet to handle this combination of 2 sample '
                'constraints and one reference!:' + str(samp_constraints))
        return xi, psi, mu, eta, chi, phi
Exemplo n.º 18
0
def calcALPHA(alpha):
    return x_rotation(alpha)