def testCompare(self): # Test the compare method pos1 = VliegPosition(1, 2, 3, 4, 5, 6) pos2 = VliegPosition(1.1, 2.1, 3.1, 4.1, 5.1, 6.1) assert pos1 == pos1 assert pos1 != pos2
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}
def decode_reflection(ref_dict, geometry): h, k, l = eval(ref_dict['hkl']) time = ref_dict['time'] and gt(ref_dict['time']) pos_tuple = eval(ref_dict['pos']) try: position = geometry.create_position(*pos_tuple) except AttributeError: position = VliegPosition(*pos_tuple) return _Reflection(h, k, l, position, ref_dict['energy'], str(ref_dict['tag']), repr(time))
def edit_reflection(self, num, h, k, l, position, energy, tag, time): """num starts at 1""" if type(position) in (list, tuple): position = VliegPosition(*position) try: self._reflist[num - 1] = _Reflection(h, k, l, position, energy, tag, time.__repr__()) except IndexError: raise DiffcalcException("There is no reflection " + repr(num) + " to edit.")
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}
def add_reflection(self, h, k, l, position, energy, tag, time): """adds a reflection, position in degrees """ if type(position) in (list, tuple): try: position = self._geometry.create_position(*position) except AttributeError: position = VliegPosition(*position) self._reflist += [ _Reflection(h, k, l, position, energy, tag, time.__repr__()) ]
def testPhysicalAnglesToInternalPosition(self): pos = [1, 2, 3, 4, 5, 6] expected = self.geometry.physical_angles_to_internal_position(pos) assert VliegPosition(*pos) == expected
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
def testInternalPositionToPhysicalAngles(self): pos = VliegPosition(1, 2, 3, 4, 5, 6) result = self.geometry.internal_position_to_physical_angles(pos) mneq_(matrix([pos.totuple()]), matrix([result]), 4)
def testClone(self): pos = VliegPosition(1, 2, 3, 4., 5., 6.) copy = pos.clone() assert pos == copy pos.alpha = 10 pos.omega = 4.1
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)
def testInternalPositionToPhysicalAngles(self): pos = VliegPosition(0, 0, 0, 0, 0, 0) result = self.geometry.internal_position_to_physical_angles(pos) self.assert_(norm(matrix([pos.totuple()]) - matrix([result])) < 0.001)
def testInternalPositionToPhysicalAngles(self): pos = VliegPosition(0, 0, 0, 0, 0, 0) result = self.geometry.internal_position_to_physical_angles(pos) assert norm(matrix([pos.totuple()]) - matrix([result])) < 0.001
def testInternalPositionToPhysicalAngles(self): result = self.geometry.internal_position_to_physical_angles( VliegPosition(0, 2, 0, 4, 5, 6)) assert (norm(matrix([[2, 4, 5, 6]]) - matrix([list(result)])) < 0.001)
def testPhysicalAnglesToInternalPosition(self): expected = self.geometry.physical_angles_to_internal_position( (2, 4, 5, 6)) assert VliegPosition(0, 2, 0, 4, 5, 6) == expected