def test_angle_with_directions(self): (a, b, c) = (1.022, 0.596, 0.481) olivine = Lattice.orthorhombic(a, b, c) (h1, k1, l1) = (1., 1., 1.) (h2, k2, l2) = (3., 3., 2.) d1 = HklDirection(h1, k1, l1, olivine) d2 = HklDirection(h2, k2, l2, olivine) # compare with formula in orthorhombic lattice, angle must be 6.589 degrees angle = np.arccos( ((h1 * h2 * a**2) + (k1 * k2 * b**2) + (l1 * l2 * c**2)) / (np.sqrt(a**2 * h1**2 + b**2 * k1**2 + c**2 * l1**2) * np.sqrt(a**2 * h2**2 + b**2 * k2**2 + c**2 * l2**2))) self.assertAlmostEqual(d1.angle_with_direction(d2), angle)
def test_gnomonic_projection_point(self): """Verify that the gnomonic projection of two diffracted points on a detector give access to the angle between the lattice plane normals.""" olivine = Lattice.orthorhombic( 1.022, 0.596, 0.481) # nm Barret & Massalski convention orientation = Orientation.cube() p1 = HklPlane(2, 0, -3, olivine) p2 = HklPlane(3, -1, -3, olivine) detector = RegArrayDetector2d(size=(512, 512), u_dir=[0, -1, 0], v_dir=[0, 0, -1]) detector.pixel_size = 0.200 # mm, 0.1 mm with factor 2 binning detector.ucen = 235 detector.vcen = 297 detector.ref_pos = np.array([131., 0., 0.]) + \ (detector.size[0] / 2 - detector.ucen) * detector.u_dir * detector.pixel_size + \ (detector.size[1] / 2 - detector.vcen) * detector.v_dir * detector.pixel_size # mm angle = 180 / np.pi * np.arccos(np.dot(p1.normal(), p2.normal())) # test the gnomonic projection for normal and not normal X-ray incidence for ksi in [0.0, 1.0]: # deg Xu = np.array( [np.cos(ksi * np.pi / 180), 0., np.sin(ksi * np.pi / 180)]) OC = detector.project_along_direction( Xu ) # C is the intersection of the direct beam with the detector K1 = diffracted_vector(p1, orientation, Xu=Xu) K2 = diffracted_vector(p2, orientation, Xu=Xu) R1 = detector.project_along_direction(K1, origin=[0., 0., 0.]) R2 = detector.project_along_direction(K2, origin=[0., 0., 0.]) OP1 = gnomonic_projection_point(R1, OC=OC)[0] OP2 = gnomonic_projection_point(R2, OC=OC)[0] hkl_normal1 = OP1 / np.linalg.norm(OP1) hkl_normal2 = (OP2 / np.linalg.norm(OP2)) # the projection must give the normal to the diffracting plane for i in range(3): self.assertAlmostEqual(hkl_normal1[i], p1.normal()[i], 6) self.assertAlmostEqual(hkl_normal2[i], p2.normal()[i], 6) angle_gp = 180 / np.pi * np.arccos(np.dot(hkl_normal1, hkl_normal2)) self.assertAlmostEqual(angle, angle_gp, 6)