Exemplo n.º 1
0
    def _hklToAnglesZaxisModes(self, h, k, l, wavelength):
        """
        Return VliegPosition and virtual angles in radians from h, k & l and
        wavelength in Angstroms for z-axis modes. The virtual angles are those
        fixed or generated while calculating the position: Bin, Bout, and
        2theta.
        """
        # Section 6:

        # Results in radians during calculations, returned in degreess
        pos = VliegPosition(None, None, None, None, None, None)

        # Normalise hkl
        wavevector = 2 * pi / wavelength
        hkl = matrix([[h], [k], [l]])
        hklNorm = hkl * (1.0 / wavevector)

        # Compute hkl in phi axis coordinate frame
        hklPhi = self._getUBMatrix() * hkl
        hklPhiNorm = self._getUBMatrix() * hklNorm

        # Determine Chi and Phi (Equation 29):
        pos.phi = -self._getTau() * TORAD
        pos.chi = -self._getSigma() * TORAD

        # Equation 30:
        [ALPHA, DELTA, GAMMA, OMEGA, CHI, PHI] = createVliegMatrices(
                None, None, None, None, pos.chi, pos.phi)
        del ALPHA, DELTA, GAMMA, OMEGA
        Hw = CHI * PHI * hklPhi

        # Determine Bin and Bout:
        (Bin, Bout) = self._determineBinAndBoutInZaxisModes(
            Hw[2, 0] / wavevector)

        # Determine Alpha and Gamma (Equation 32):
        pos.alpha = Bin
        pos.gamma = Bout

        # Determine Delta:
        (pos.delta, twotheta) = self._determineDelta(hklPhiNorm, pos.alpha,
                                                     pos.gamma)

        # Determine Omega:
        delta = pos.delta
        gamma = pos.gamma
        d1 = (Hw[1, 0] * sin(delta) * cos(gamma) - Hw[0, 0] *
              (cos(delta) * cos(gamma) - cos(pos.alpha)))
        d2 = (Hw[0, 0] * sin(delta) * cos(gamma) + Hw[1, 0] *
              (cos(delta) * cos(gamma) - cos(pos.alpha)))

        if fabs(d2) < 1e-30:
            pos.omega = sign(d1) * sign(d2) * pi / 2.0
        else:
            pos.omega = atan2(d1, d2)

        # Gather up the virtual angles calculated along the way
        return pos, {'2theta': twotheta, 'Bin': Bin, 'Bout': Bout}
Exemplo n.º 2
0
    def _hklToAnglesZaxisModes(self, h, k, l, wavelength):
        """
        Return VliegPosition and virtual angles in radians from h, k & l and
        wavelength in Angstroms for z-axis modes. The virtual angles are those
        fixed or generated while calculating the position: Bin, Bout, and
        2theta.
        """
        # Section 6:

        # Results in radians during calculations, returned in degreess
        pos = VliegPosition(None, None, None, None, None, None)

        # Normalise hkl
        wavevector = 2 * pi / wavelength
        hkl = matrix([[h], [k], [l]])
        hklNorm = hkl * (1.0 / wavevector)

        # Compute hkl in phi axis coordinate frame
        hklPhi = self._getUBMatrix() * hkl
        hklPhiNorm = self._getUBMatrix() * hklNorm

        # Determine Chi and Phi (Equation 29):
        pos.phi = -self._getTau() * TORAD
        pos.chi = -self._getSigma() * TORAD

        # Equation 30:
        [ALPHA, DELTA, GAMMA, OMEGA, CHI,
         PHI] = createVliegMatrices(None, None, None, None, pos.chi, pos.phi)
        del ALPHA, DELTA, GAMMA, OMEGA
        Hw = CHI * PHI * hklPhi

        # Determine Bin and Bout:
        (Bin,
         Bout) = self._determineBinAndBoutInZaxisModes(Hw[2, 0] / wavevector)

        # Determine Alpha and Gamma (Equation 32):
        pos.alpha = Bin
        pos.gamma = Bout

        # Determine Delta:
        (pos.delta, twotheta) = self._determineDelta(hklPhiNorm, pos.alpha,
                                                     pos.gamma)

        # Determine Omega:
        delta = pos.delta
        gamma = pos.gamma
        d1 = (Hw[1, 0] * sin(delta) * cos(gamma) - Hw[0, 0] *
              (cos(delta) * cos(gamma) - cos(pos.alpha)))
        d2 = (Hw[0, 0] * sin(delta) * cos(gamma) + Hw[1, 0] *
              (cos(delta) * cos(gamma) - cos(pos.alpha)))

        if fabs(d2) < 1e-30:
            pos.omega = sign(d1) * sign(d2) * pi / 2.0
        else:
            pos.omega = atan2(d1, d2)

        # Gather up the virtual angles calculated along the way
        return pos, {'2theta': twotheta, 'Bin': Bin, 'Bout': Bout}
Exemplo n.º 3
0
 def testClone(self):
     pos = VliegPosition(1, 2, 3, 4., 5., 6.)
     copy = pos.clone()
     assert pos == copy
     pos.alpha = 10
     pos.omega = 4.1
Exemplo n.º 4
0
    def _hklToAnglesFourAndFiveCirclesModes(self, h, k, l, wavelength):
        """
        Return VliegPosition and virtual angles in radians from h, k & l and
        wavelength in Angstrom for four and five circle modes. The virtual
        angles are those fixed or generated while calculating the position:
        Bin, Bout, 2theta and azimuth.
        """

        # Results in radians during calculations, returned in degreess
        pos = VliegPosition(None, None, None, None, None, None)

        # Normalise hkl
        wavevector = 2 * pi / wavelength
        hklNorm = matrix([[h], [k], [l]]) / wavevector

        # Compute hkl in phi axis coordinate frame
        hklPhiNorm = self._getUBMatrix() * hklNorm

        # Determine Bin and Bout
        if self._getMode().name == '4cPhi':
            Bin = Bout = None
        else:
            Bin, Bout = self._determineBinAndBoutInFourAndFiveCirclesModes(
                                                                    hklNorm)

        # Determine alpha and gamma
        if self._getMode().group == 'fourc':
            pos.alpha, pos.gamma = \
                self._determineAlphaAndGammaForFourCircleModes(hklPhiNorm)
        else:
            pos.alpha, pos.gamma = \
                self._determineAlphaAndGammaForFiveCircleModes(Bin, hklPhiNorm)
        if pos.alpha < -pi:
            pos.alpha += 2 * pi
        if pos.alpha > pi:
            pos.alpha -= 2 * pi

        # Determine delta
        (pos.delta, twotheta) = self._determineDelta(hklPhiNorm, pos.alpha,
                                                     pos.gamma)

        # Determine omega, chi & phi
        pos.omega, pos.chi, pos.phi, psi = \
            self._determineSampleAnglesInFourAndFiveCircleModes(
                hklPhiNorm, pos.alpha, pos.delta, pos.gamma, Bin)
        # (psi will be None in fixed phi mode)

        # Ensure that by default omega is between -90 and 90, by possibly
        # transforming the sample angles
        if self._getMode().name != '4cPhi':  # not in fixed-phi mode
            if pos.omega < -pi / 2 or pos.omega > pi / 2:
                pos = transformC.transform(pos)

        # Gather up the virtual angles calculated along the way...
        #   -pi<psi<=pi
        if psi is not None:
            if psi > pi:
                psi -= 2 * pi
            if psi < (-1 * pi):
                psi += 2 * pi

        v = {'2theta': twotheta, 'Bin': Bin, 'Bout': Bout, 'azimuth': psi}
        return pos, v
Exemplo n.º 5
0
    def _hklToAnglesFourAndFiveCirclesModes(self, h, k, l, wavelength):
        """
        Return VliegPosition and virtual angles in radians from h, k & l and
        wavelength in Angstrom for four and five circle modes. The virtual
        angles are those fixed or generated while calculating the position:
        Bin, Bout, 2theta and azimuth.
        """

        # Results in radians during calculations, returned in degreess
        pos = VliegPosition(None, None, None, None, None, None)

        # Normalise hkl
        wavevector = 2 * pi / wavelength
        hklNorm = matrix([[h], [k], [l]]) / wavevector

        # Compute hkl in phi axis coordinate frame
        hklPhiNorm = self._getUBMatrix() * hklNorm

        # Determine Bin and Bout
        if self._getMode().name == '4cPhi':
            Bin = Bout = None
        else:
            Bin, Bout = self._determineBinAndBoutInFourAndFiveCirclesModes(
                hklNorm)

        # Determine alpha and gamma
        if self._getMode().group == 'fourc':
            pos.alpha, pos.gamma = \
                self._determineAlphaAndGammaForFourCircleModes(hklPhiNorm)
        else:
            pos.alpha, pos.gamma = \
                self._determineAlphaAndGammaForFiveCircleModes(Bin, hklPhiNorm)
        if pos.alpha < -pi:
            pos.alpha += 2 * pi
        if pos.alpha > pi:
            pos.alpha -= 2 * pi

        # Determine delta
        (pos.delta, twotheta) = self._determineDelta(hklPhiNorm, pos.alpha,
                                                     pos.gamma)

        # Determine omega, chi & phi
        pos.omega, pos.chi, pos.phi, psi = \
            self._determineSampleAnglesInFourAndFiveCircleModes(
                hklPhiNorm, pos.alpha, pos.delta, pos.gamma, Bin)
        # (psi will be None in fixed phi mode)

        # Ensure that by default omega is between -90 and 90, by possibly
        # transforming the sample angles
        if self._getMode().name != '4cPhi':  # not in fixed-phi mode
            if pos.omega < -pi / 2 or pos.omega > pi / 2:
                pos = transformC.transform(pos)

        # Gather up the virtual angles calculated along the way...
        #   -pi<psi<=pi
        if psi is not None:
            if psi > pi:
                psi -= 2 * pi
            if psi < (-1 * pi):
                psi += 2 * pi

        v = {'2theta': twotheta, 'Bin': Bin, 'Bout': Bout, 'azimuth': psi}
        return pos, v
Exemplo n.º 6
0
 def testClone(self):
     pos = VliegPosition(1, 2, 3, 4., 5., 6.)
     copy = pos.clone()
     assert pos == copy
     pos.alpha = 10
     pos.omega = 4.1