def test_cell_intensity(self): # Test that bcc structure gives lower intensity for h + k + l != even. c = TEMCalculator() latt = Lattice.cubic(4.209) cubic = Structure(latt, ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]) point = [(2, 1, 0)] point2 = [(2, 2, 0)] spacings = c.get_interplanar_spacings(cubic, point) spacings2 = c.get_interplanar_spacings(cubic, point2) angles = c.bragg_angles(spacings) angles2 = c.bragg_angles(spacings2) cellint = c.cell_intensity(cubic, angles) cellint2 = c.cell_intensity(cubic, angles2) self.assertGreater(cellint2[(2, 2, 0)], cellint[(2, 1, 0)])
def test_normalized_cell_intensity(self): # Test that the method correctly normalizes a value. c = TEMCalculator() latt = Lattice.cubic(4.209) cubic = Structure(latt, ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]) point = [(2, 0, 0)] spacings = c.get_interplanar_spacings(cubic, point) angles = c.bragg_angles(spacings) cellint = c.normalized_cell_intensity(cubic, angles) self.assertAlmostEqual(cellint[(2, 0, 0)], 1)
def test_x_ray_factors(self): c = TEMCalculator() latt = Lattice.cubic(4.209) cubic = Structure(latt, ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]) point = [(-10, 3, 0)] spacings = c.get_interplanar_spacings(cubic, point) angles = c.bragg_angles(spacings) x_ray = c.x_ray_factors(cubic, angles) self.assertAlmostEqual(x_ray["Cs"][(-10, 3, 0)], 14.42250869579648) self.assertAlmostEqual(x_ray["Cl"][(-10, 3, 0)], 2.7804915737999103)
def test_cell_scattering_factors(self): # Test that fcc structure gives 0 intensity for mixed even, odd hkl. c = TEMCalculator() nacl = Structure.from_spacegroup("Fm-3m", Lattice.cubic(5.692), ["Na", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]) point = [(2, 1, 0)] spacings = c.get_interplanar_spacings(nacl, point) angles = c.bragg_angles(spacings) cellscatt = c.cell_scattering_factors(nacl, angles) self.assertAlmostEqual(cellscatt[(2, 1, 0)], 0)
def test_get_s2(self): # Tests that the appropriate s2 factor is returned. c = TEMCalculator() latt = Lattice.cubic(4.209) cubic = Structure(latt, ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]) point = [(-10, 3, 0)] spacings = c.get_interplanar_spacings(cubic, point) angles = c.bragg_angles(spacings) s2 = c.get_s2(angles) for p in s2: self.assertAlmostEqual(s2[p], 1.5381852947115047)
def test_electron_scattering_factors(self): # Test the electron atomic scattering factor, values approximate with # international table of crystallography volume C. Rounding error when converting hkl to sin(theta)/lambda. # Error increases as sin(theta)/lambda is smaller. c = TEMCalculator() latt = Lattice.cubic(4.209) cubic = Structure(latt, ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]) nacl = Structure.from_spacegroup("Fm-3m", Lattice.cubic(5.692), ["Na", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]]) point = [(2, 1, 3)] point_nacl = [(4, 2, 0)] spacings = c.get_interplanar_spacings(cubic, point) spacings_nacl = c.get_interplanar_spacings(nacl, point_nacl) angles = c.bragg_angles(spacings) angles_nacl = c.bragg_angles(spacings_nacl) elscatt = c.electron_scattering_factors(cubic, angles) elscatt_nacl = c.electron_scattering_factors(nacl, angles_nacl) self.assertAlmostEqual(elscatt["Cs"][(2, 1, 3)], 2.890, places=1) self.assertAlmostEqual(elscatt["Cl"][(2, 1, 3)], 1.138, places=1) self.assertAlmostEqual(elscatt_nacl["Na"][(4, 2, 0)], 0.852, places=1) self.assertAlmostEqual(elscatt_nacl["Cl"][(4, 2, 0)], 1.372, places=1)