Exemplo n.º 1
0
 def testNearlyEquals(self):
     pos1 = VliegPosition(1, 2, 3, 4, 5, 6)
     pos2 = VliegPosition(1.1, 2.1, 3.1, 4.1, 5.1, 6.1)
     assert pos1.nearlyEquals(pos2, 0.11)
     assert not pos1.nearlyEquals(pos2, 0.1)
Exemplo n.º 2
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