How to use diffsims - 6 common examples

To help you get started, we’ve selected a few diffsims examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyxem / pyxem / pyxem / generators / indexation_generator.py View on Github external
rhklss = np.rint(hklss)
        ehklss = np.abs(hklss - rhklss)

        return ehklss

    ai, aj, ak = mat2euler(solution.rotation_matrix)

    params = lmfit.Parameters()
    params.add("center_x", value=solution.center_x, vary=vary_center)
    params.add("center_y", value=solution.center_y, vary=vary_center)
    params.add("ai", value=ai, vary=vary_angles)
    params.add("aj", value=aj, vary=vary_angles)
    params.add("ak", value=ak, vary=vary_angles)
    params.add("scale", value=solution.scale, vary=vary_scale, min=0.8, max=1.2)

    wavelength = get_electron_wavelength(accelarating_voltage)
    camera_length = camera_length * 1e10
    args = k_xy, lattice_recip, wavelength, camera_length

    res = lmfit.minimize(objfunc, params, args=args, method=method)

    if verbose:  # pragma: no cover
        lmfit.report_fit(res)

    p = res.params

    ai, aj, ak = p["ai"].value, p["aj"].value, p["ak"].value
    scale = p["scale"].value
    center_x = params["center_x"].value
    center_y = params["center_y"].value

    rotation_matrix = euler2mat(ai, aj, ak)
github pyxem / pyxem / pyxem / signals / diffraction_vectors.py View on Github external
def calculate_cartesian_coordinates(self, accelerating_voltage, camera_length,
                                        *args, **kwargs):
        """Get cartesian coordinates of the diffraction vectors.

        Parameters
        ----------
        accelerating_voltage : float
            The acceleration voltage with which the data was acquired.
        camera_length : float
            The camera length in meters.
        """
        # Imported here to avoid circular dependency
        from diffsims.utils.sim_utils import get_electron_wavelength
        wavelength = get_electron_wavelength(accelerating_voltage)
        self.cartesian = self.map(detector_to_fourier,
                                  wavelength=wavelength,
                                  camera_length=camera_length * 1e10,
                                  inplace=False,
                                  parallel=False,  # TODO: For testing
                                  *args, **kwargs)
        transfer_navigation_axes(self.cartesian, self)
github pyxem / pyxem / pyxem / utils / indexation_utils.py View on Github external
peaks : array
        Coordinates of peaks in the matching results object in calibrated units.
    """
    best_fit = get_nth_best_solution(single_match_result, rank=rank)

    phase_names = list(library.keys())
    phase_index = int(best_fit[0])
    phase = phase_names[phase_index]
    try:
        simulation = library.get_library_entry(
            phase=phase,
            angle=tuple(best_fit[1]))['Sim']
    except ValueError:
        structure = library.structures[phase_index]
        rotation_matrix = euler2mat(*np.deg2rad(best_fit[1]), 'rzxz')
        simulation = simulate_rotated_structure(
            library.diffraction_generator,
            structure,
            rotation_matrix,
            library.reciprocal_radius,
            library.with_direct_beam)

    peaks = simulation.coordinates[:, :2]  # cut z
    return peaks
github pyxem / pyxem / pyxem / utils / indexation_utils.py View on Github external
Diffraction library containing the phases and rotations
    rank : int
        Get peaks from nth best orientation (default: 0, best vector match)

    Returns
    -------
    peaks : ndarray
        Coordinates of peaks in the matching results object in calibrated units.
    """
    best_fit = get_nth_best_solution(single_match_result, rank=rank)
    phase_index = best_fit.phase_index

    rotation_matrix = best_fit.rotation_matrix
    # Don't change the original
    structure = library.structures[phase_index]
    sim = simulate_rotated_structure(
        library.diffraction_generator,
        structure,
        rotation_matrix,
        library.reciprocal_radius,
        with_direct_beam=False)

    # Cut z
    return sim.coordinates[:, :2]
github pyxem / pyxem / pyxem / components / scattering_fit_component_xtables.py View on Github external
An additive constant to the fit.

        References
        ----------
        [1] Prince, E. (2004). International tables for crystallography.
        Vol. C, table 4.3.2.3.

        """
        Component.__init__(self, ['N', 'C'])
        self._whitelist['elements'] = ('init,sig', elements)
        self._whitelist['fracs'] = ('init,sig', fracs)
        self.elements = elements
        self.fracs = fracs
        params = []
        for e in elements:
            params.append(ATOMIC_SCATTERING_PARAMS[e])
        self.params = params
        self.N.value = N
        self.C.value = C
github pyxem / pyxem / pyxem / components / scattering_fit_component_lobato.py View on Github external
References
        ----------
        [1] Lobato, I., & Van Dyck, D. (2014). An accurate parameterization for
        scattering factors, electron densities and electrostatic potentials for
        neutral atoms that obey all physical constraints. Acta Crystallographica
        Section A: Foundations and Advances, 70(6), 636-649.

        """
        Component.__init__(self, ['N', 'C'])
        self._whitelist['elements'] = ('init,sig', elements)
        self._whitelist['fracs'] = ('init,sig', fracs)
        self.elements = elements
        self.fracs = fracs
        params = []
        for e in elements:
            params.append(ATOMIC_SCATTERING_PARAMS_LOBATO[e])
        self.params = params
        self.N.value = N
        self.C.value = C