Esempio n. 1
0
def test_get_intensities_params(default_structure):
    latt = default_structure.lattice
    reciprocal_lattice = latt.reciprocal()
    reciprocal_radius = 0.2
    unique_hkls, multiplicites, g_hkls = get_intensities_params(
        reciprocal_lattice, reciprocal_radius)
    np.testing.assert_equal(multiplicites, ([1.0]))
    np.testing.assert_equal(g_hkls, [0.0])
    np.testing.assert_array_equal(unique_hkls, [[-0.0, -0.0, 0.0]])
Esempio n. 2
0
def test_get_kinematical_intensities(default_structure):
    latt = default_structure.lattice
    reciprocal_lattice = latt.reciprocal()
    reciprocal_radius = 0.2
    unique_hkls, multiplicites, g_hkls = get_intensities_params(
        reciprocal_lattice, reciprocal_radius)
    g_hkls_array = np.asarray(g_hkls)
    i_hkls = get_kinematical_intensities(
        default_structure,
        g_indices=unique_hkls,
        g_hkls_array=g_hkls_array,
        debye_waller_factors={"Al": 1},
        prefactor=multiplicites,
        scattering_params="lobato",
    )
    np.testing.assert_array_almost_equal(i_hkls, ([43.0979]), decimal=4)
Esempio n. 3
0
    def calculate_profile_data(
        self,
        structure,
        reciprocal_radius=1.0,
        minimum_intensity=1e-3,
        debye_waller_factors={},
    ):
        """Calculates a one dimensional diffraction profile for a
        structure.

        Parameters
        ----------
        structure : diffpy.structure.structure.Structure
            The structure for which to calculate the diffraction profile.
        reciprocal_radius : float
            The maximum radius of the sphere of reciprocal space to
            sample, in reciprocal angstroms.
        minimum_intensity : float
            The minimum intensity required for a diffraction peak to be
            considered real. Deals with numerical precision issues.
        debye_waller_factors : dict of str:value pairs
            Maps element names to their temperature-dependent Debye-Waller factors.

        Returns
        -------
        diffsims.sims.diffraction_simulation.ProfileSimulation
            The diffraction profile corresponding to this structure and
            experimental conditions.
        """
        wavelength = self.wavelength
        latt = structure.lattice

        # Obtain crystallographic reciprocal lattice points within range
        recip_latt = latt.reciprocal()
        spot_indices, _, spot_distances = get_points_in_sphere(
            recip_latt, reciprocal_radius
        )

        ##spot_indicies is a numpy.array of the hkls allowd in the recip radius
        g_indices, multiplicities, g_hkls = get_intensities_params(
            recip_latt, reciprocal_radius
        )

        i_hkl = get_kinematical_intensities(
            structure,
            g_indices,
            np.asarray(g_hkls),
            prefactor=multiplicities,
            scattering_params=self.scattering_params,
            debye_waller_factors=debye_waller_factors,
        )

        if is_lattice_hexagonal(latt):
            # Use Miller-Bravais indices for hexagonal lattices.
            g_indices = (
                g_indices[0],
                g_indices[1],
                -g_indices[0] - g_indices[1],
                g_indices[2],
            )

        hkls_labels = ["".join([str(int(x)) for x in xs]) for xs in g_indices]

        peaks = {}
        for l, i, g in zip(hkls_labels, i_hkl, g_hkls):
            peaks[l] = [i, g]

        # Scale intensities so that the max intensity is 100.

        max_intensity = max([v[0] for v in peaks.values()])
        x = []
        y = []
        hkls = []
        for k in peaks.keys():
            v = peaks[k]
            if v[0] / max_intensity * 100 > minimum_intensity and (k != "000"):
                x.append(v[1])
                y.append(v[0])
                hkls.append(k)

        y = np.asarray(y) / max(y) * 100

        return ProfileSimulation(x, y, hkls)