def test_positive_intensity(self): """ Test that potential_synthesis raises an error if diffraction intensity is not positive """ aR1, aR2, aR3 = self.crystal.lattice_vectors extent = np.arange(0, 5, 0.1) with suppress_warnings(): plane = plane_mesh(aR3, aR1 + aR2, x1=extent) self.intensities[0] = self.intensities[0] * -1 with self.assertRaises(ValueError): potmap = potential_synthesis(self.reflections, self.intensities, self.crystal, plane)
def test_trivial(self): """ Test that potential_synthesis calculated from zero intensity is zero everywhere """ aR1, aR2, aR3 = self.crystal.lattice_vectors extent = np.arange(0, 10, 0.1) with suppress_warnings(): plane = plane_mesh(aR3, aR1 + aR2, x1=extent) potmap = potential_synthesis(self.reflections, np.zeros_like(self.intensities), self.crystal, plane) self.assertTrue(np.allclose(potmap, 0))
def test_shape(self): """ Test that potential_synthesis returns a map with the same shape as the mesh """ aR1, aR2, aR3 = self.crystal.lattice_vectors extent = np.arange(0, 5, 0.1) with suppress_warnings(): plane = plane_mesh(aR3, aR1 + aR2, x1=extent) potmap = potential_synthesis(self.reflections, self.intensities, self.crystal, plane) xx, yy, zz = plane for arr in plane: self.assertTupleEqual(potmap.shape, arr.shape)
def test_potential_synthesis_positive_intensity(): """ Test that potential_synthesis raises an error if diffraction intensity is not positive """ crystal = Crystal.from_database("C") reflections = list(combinations_with_replacement(range(-3, 4), 3)) intensities = [ np.abs(structure_factor(crystal, *reflection))**2 for reflection in reflections ] aR1, aR2, aR3 = crystal.lattice_vectors extent = np.arange(0, 5, 0.1) with suppress_warnings(): plane = plane_mesh(aR3, aR1 + aR2, x1=extent) intensities[0] = intensities[0] * -1 with pytest.raises(ValueError): potmap = potential_synthesis(reflections, intensities, crystal, plane)
def test_potential_synthesis_trivial(): """ Test that potential_synthesis calculated from zero intensity is zero everywhere """ crystal = Crystal.from_database("C") reflections = list(combinations_with_replacement(range(-3, 4), 3)) intensities = [ np.abs(structure_factor(crystal, *reflection))**2 for reflection in reflections ] aR1, aR2, aR3 = crystal.lattice_vectors extent = np.arange(0, 10, 0.1) with suppress_warnings(): plane = plane_mesh(aR3, aR1 + aR2, x1=extent) potmap = potential_synthesis(reflections, np.zeros_like(intensities), crystal, plane) assert np.allclose(potmap, 0)
def test_potential_synthesis_shape(): """ Test that potential_synthesis returns a map with the same shape as the mesh """ crystal = Crystal.from_database("C") reflections = list(combinations_with_replacement(range(-3, 4), 3)) intensities = [ np.abs(structure_factor(crystal, *reflection))**2 for reflection in reflections ] aR1, aR2, aR3 = crystal.lattice_vectors extent = np.arange(0, 5, 0.1) with suppress_warnings(): plane = plane_mesh(aR3, aR1 + aR2, x1=extent) potmap = potential_synthesis(reflections, intensities, crystal, plane) xx, yy, zz = plane for arr in plane: assert potmap.shape == arr.shape