Indexing reflections

Error types

class crystals.IndexingError

Bases: RuntimeError

Indexing has failed.

New in version 1.3.0.

Single-crystal indexing with the DirAx algorithm

crystals.index_dirax(reflections, initial=None, length_bounds=(2, 20))

Find the lattice associated with a list of reflections using the DirAx algorithm.

New in version 1.3.0.

Parameters
  • reflections (iterable of 3-tuple or ndarray, shape (N, 3)) – Iterable of reflections with their three-dimensional reciprocal space coordinates, or ndarray where each row is a reflections. Coordinates are in inverse Angstroms.

  • initial (Lattice or Crystal, optional) – Initial guess for a lattice. The DirAx algorithm does not need an initial guess, but it can certainly help when many reflections are missing.

  • length_bounds (2-tuple of floats, optional) – Minimum and maximum lattice vector lengths to consider, in Angstrom.

Returns

  • indexed (Lattice) – Lattice that best indexes reflections.

  • indices (ndarray, shape (N, 3)) – Miller indices associated with each vector in reflections, in order.

Raises

IndexingError – The indexing has failed.

Notes

This indexing routine is based on the reference below. The algorithm is well-suited to situations where reflections might be missing, or situations where the list of reflections contains “alien” reflections not associated with the lattice.

Examples

We generate reflections from a crystal structure and re-index it for demonstration purposes.

>>> from crystals import index_dirax, Crystal
>>> import numpy as np
>>> graphite = Crystal.from_database('C')
>>> # The list of reflections `qs` might be experimental measurements from either
>>> # x-ray or electron diffraction.
>>> qs = [graphite.scattering_vector(r) for r in graphite.bounded_reflections(bound=3.5)]
>>> lattice, hkls = index_dirax(qs)
>>> lattice 
< Lattice object with parameters 2.464Å, 2.464Å, 6.711Å, 90.00°, 90.00°, 120.00° >

References

A. J. M. Duisenberg, Indexing in Single-Crystal Diffractometry with an Obstinate List of Reflections (1992), J. Appl. Cryst vol. 25 pp. 92 - 96

Polychromatic indexing with pinkIndexer

crystals.index_pink(peaks, intensities, beam_energy, divergence_angle, non_monochromaticity, detector_distance: float, detector_radius: float, tolerance: float, reflection_radius: float, initial_guess: Lattice, considered_peaks_count: ConsideredPeaksCount = ConsideredPeaksCount.standard, angle_resolution: AngleResolution = AngleResolution.standard, refinement_type: RefinementType = RefinementType.first_fixed_then_variable_lattice_parameters, num_threads: int = 1) Tuple[Lattice, int]

Index reflections using pinkindexer, an indexing routine that can be used in a variety of contexts including measurements made with a monochromatic radiation source, a polychromatic source or with radiation of very short wavelength.

Some of the inputs below may not be known. In case, you may use the Geometry class to derive some of these inputs. See the user guide for an example.

New in version 1.7.0.

Parameters
  • peaks (ndarray, shape (N, 2)) – Each row represents a peak location [x, y] on the detector [m]

  • intensities (ndarray, shape (N,)) – Scattering intensity for each row in peaks [a.u.]

  • detector_distance (float) – Distance between the sample and detector [m]

  • beam_energy (float) – Radiation energy [eV]

  • divergence_angle (float) – Divergence angle [deg]

  • non_monochromaticity (float) – Bandwidth of the beam energy, as a fraction of the beam energy [a.u.].

  • detector_radius (float) – Detector radius, or half-width. [m]

  • tolerance (float) – Fractional tolerance for reflections to be considered indexed during refinement [a.u.].

  • reflection_radius (float) – Radius of a typical reflection [1/A]

  • initial_guess (Lattice) – Initial guess of the real-space lattice vectors of the crystal structure. This must represent a primitive lattice.

  • considered_peaks_count (crystals.indexing.pinkindexer.ConsideredPeaksCount, optional) – Controls the number of Bragg spots which are used to compute the indexing solution.

  • angle_resolution (crystals.indexing.pinkindexer.AngleResolution, optional) – Set the resolution of the rotogram in terms of number of voxels spanning \(-\arctan \pi/4\) to \(\arctan \pi/4\)

  • refinement_type (crystals.indexing.pinkindexer.RefinementType, optional) – Determines which type of refinement to perform after initial indexing.

  • num_threads (int, optional) – Number of threads to use for indexing.

Returns

  • indexed_lattice (Lattice) – Lattice that indexes peaks best.

  • num_indexed (int) – Number of reflections successfully indexed.

Raises

ValueError – If the number of peaks does not match the intensities provided. If the dimensions of the reciprocal lattice are not adequate.

References

Y. Gevorkov, A. Barty, W. Brehm, T. A. White, A. Tolstikova, M. O. Wiedorn, A. Meents R.-R. Grigat, H. N. Chapman and O. Yefanova, pinkIndexer - a universal indexer for pink-beam X-ray and electron diffraction snapshots (2020). Acta Cryst. A, vol 76, pages 121-132.

Extra options

The following enumerations may be used to control the indexing performed by index_pink. See the pinkindexer reference on what the various options do.

class crystals.indexing.pinkindexer.ConsideredPeaksCount(value)

This enumeration specifies the number of found Bragg spots that are used to compute the initial indexing in index_pink solution from the maximum of the rotogram. Regardless of this enumeration, all Bragg spots are considered during refinement.

class crystals.indexing.pinkindexer.AngleResolution(value)

This enumeration controls the resolution of the rotogram in terms of number of voxels spanning \(-\arctan \pi/4\) to \(\arctan \pi/4\)

Choosing larger voxels (lower resolution) leads to a faster calculation but lower precision in the initial step of determining the orientation from the rotogram.

class crystals.indexing.pinkindexer.RefinementType(value)

Refinement can be performed by a gradient descent method, fitting all parameters of the lattice or keeping the cell parameters constant and just refining the orientation.