def test_appropriate_scaling(self, diffraction_calculator: DiffractionGenerator): """Tests that doubling the unit cell halves the pattern spacing.""" si = pmg.Element("Si") lattice = pmg.Lattice.cubic(5.431) big_lattice = pmg.Lattice.cubic(10.862) silicon = pmg.Structure.from_spacegroup("Fd-3m", lattice, [si], [[0, 0, 0]]) big_silicon = pmg.Structure.from_spacegroup("Fd-3m", big_lattice, [si], [[0, 0, 0]]) diffraction = diffraction_calculator.calculate_ed_data(structure=silicon, reciprocal_radius=5.) big_diffraction = diffraction_calculator.calculate_ed_data(structure=big_silicon, reciprocal_radius=5.) indices = [tuple(i) for i in diffraction.indices] big_indices = [tuple(i) for i in big_diffraction.indices] assert (2, 2, 0) in indices assert (2, 2, 0) in big_indices coordinates = diffraction.coordinates[indices.index((2, 2, 0))] big_coordinates = big_diffraction.coordinates[big_indices.index((2, 2, 0))] assert np.allclose(coordinates, big_coordinates * 2)
def test_appropriate_scaling(self, diffraction_calculator: DiffractionGenerator): """Tests that doubling the unit cell halves the pattern spacing.""" silicon = make_structure(5) big_silicon = make_structure(10) diffraction = diffraction_calculator.calculate_ed_data( structure=silicon, reciprocal_radius=5.) big_diffraction = diffraction_calculator.calculate_ed_data( structure=big_silicon, reciprocal_radius=5.) indices = [tuple(i) for i in diffraction.indices] big_indices = [tuple(i) for i in big_diffraction.indices] assert (2, 2, 0) in indices assert (2, 2, 0) in big_indices coordinates = diffraction.coordinates[indices.index((2, 2, 0))] big_coordinates = big_diffraction.coordinates[big_indices.index( (2, 2, 0))] assert np.allclose(coordinates, big_coordinates * 2)
def test_strain_mapping_affine_transform(): latt = diffpy.structure.lattice.Lattice(3, 3, 3, 90, 90, 90) atom = diffpy.structure.atom.Atom(atype='Zn', xyz=[0, 0, 0], lattice=latt) structure = diffpy.structure.Structure(atoms=[atom], lattice=latt) ediff = DiffractionGenerator(300., 0.025) affines = [[[1, 0, 0], [0, 1, 0], [0, 0, 1]], [[1.04, 0, 0], [0, 1, 0], [0, 0, 1]], [[1.08, 0, 0], [0, 1, 0], [0, 0, 1]], [[1.12, 0, 0], [0, 1, 0], [0, 0, 1]]] data = [] for affine in affines: # same coords as used for latt above latt_rot = diffpy.structure.lattice.Lattice(3, 3, 3, 90, 90, 90, baserot=affine) structure.placeInLattice(latt_rot) diff_dat = ediff.calculate_ed_data(structure, 2.5) dpi = diff_dat.as_signal(64, 0.02, 2.5) data.append(dpi.data) data = np.array(data) dp = ElectronDiffraction(data.reshape((2, 2, 64, 64))) m = dp.create_model() ref = ScalableReferencePattern(dp.inav[0, 0]) m.append(ref) m.multifit() disp_grad = ref.construct_displacement_gradient() assert disp_grad.data.shape == np.asarray(affines).reshape(2, 2, 3, 3).shape
def diffraction_calculator(): return DiffractionGenerator(300., 0.02)
def diffraction_calculator(request): return DiffractionGenerator(*request.param)
def check_pattern_equivilance(p1, p2, coords_only=False): assert np.allclose(p1.coordinates, p2.coordinates) if not coords_only: assert np.allclose(p1.indices, p2.indices) assert np.allclose(p1.intensities, p2.intensities) # Becuase of the slight differences between each of the structures, the # explictily named, ugly pathway has been taken Cl = pmg.Element("Cl") Ar = pmg.Element("Ar") cubic_lattice = pmg.Lattice.cubic(5) Mscope = DiffractionGenerator(300, 5e-2) #a 300kev EM formal_cubic_I = pmg.Structure.from_spacegroup("I23", cubic_lattice, [Cl], [[0, 0, 0]]) casual_cubic_I = pmg.Structure.from_spacegroup(195, cubic_lattice, [Cl, Cl], [[0, 0, 0], [0.5, 0.5, 0.5]]) fake_cubic_I = pmg.Structure.from_spacegroup(195, cubic_lattice, [Cl, Ar], [[0, 0, 0], [0.5, 0.5, 0.5]]) larger_cubic_I = pmg.Structure.from_spacegroup("I23", cubic_lattice, [Cl], [[0, 0, 0]]) larger_cubic_I.make_supercell([2, 4, 2]) formal_pattern = get_pattern(Mscope, formal_cubic_I) casual_pattern = get_pattern(Mscope, casual_cubic_I) fake_pattern = get_pattern(Mscope, fake_cubic_I) larger_pattern = get_pattern(Mscope, larger_cubic_I)
def test_invalid_scattering_params(): scattering_param = '_empty' generator = DiffractionGenerator(300, 0.2, None, scattering_params=scattering_param)
def test_param_check(scattering_param): generator = DiffractionGenerator(300, 0.2, None, scattering_params=scattering_param)