pymatgen.analysis.diffraction.tem module

This module implements a TEM pattern calculator.

class TEMCalculator(symprec: float = None, voltage: float = 200, beam_direction: Tuple[int, int, int] = 0, 0, 1, camera_length: int = 160, debye_waller_factors: Dict[str, float] = None, cs: float = 1)[source]

Bases: pymatgen.analysis.diffraction.core.AbstractDiffractionPatternCalculator

Computes the TEM pattern of a crystal structure for multiple Laue zones. Code partially inspired from XRD calculation implementation. X-ray factor to electron factor

conversion based on the International Table of Crystallography.

#TODO: Could add “number of iterations”, “magnification”, “critical value of beam”,

“twin direction” for certain materials, “sample thickness”, and “excitation error s”

Parameters
  • symprec (float) – Symmetry precision for structure refinement. If set to 0, no refinement is done. Otherwise, refinement is performed using spglib with provided precision.

  • voltage (float) – The wavelength is a function of the TEM microscope’s voltage. By default, set to 200 kV. Units in kV.

  • beam_direction (tuple) – The direction of the electron beam fired onto the sample. By default, set to [0,0,1], which corresponds to the normal direction of the sample plane.

  • camera_length (int) – The distance from the sample to the projected diffraction pattern. By default, set to 160 cm. Units in cm.

  • ({element symbol (debye_waller_factors) – float}): Allows the specification of Debye-Waller factors. Note that these factors are temperature dependent.

  • cs (float) – the chromatic aberration coefficient. set by default to 1 mm.

bragg_angles(interplanar_spacings: Dict[Tuple[int, int, int], float]) → Dict[Tuple[int, int, int], float][source]

Gets the Bragg angles for every hkl point passed in (where n = 1). :param interplanar_spacings: dictionary of hkl to interplanar spacing :type interplanar_spacings: dict

Returns

dict of hkl plane (3-tuple) to Bragg angle in radians (float)

cell_intensity(structure: pymatgen.core.structure.Structure, bragg_angles: Dict[Tuple[int, int, int], float]) → Dict[Tuple[int, int, int], float][source]

Calculates cell intensity for each hkl plane. For simplicity’s sake, take I = |F|**2. :param structure: The input structure. :type structure: Structure :param bragg_angles: The Bragg angles for each hkl plane. :type bragg_angles: dict of 3-tuple to float

Returns

dict of hkl plane to cell intensity

cell_scattering_factors(structure: pymatgen.core.structure.Structure, bragg_angles: Dict[Tuple[int, int, int], float]) → Dict[Tuple[int, int, int], int][source]

Calculates the scattering factor for the whole cell. :param structure: The input structure. :type structure: Structure :param bragg_angles: The Bragg angles for each hkl plane. :type bragg_angles: dict of 3-tuple to float

Returns

dict of hkl plane (3-tuple) to scattering factor (in angstroms).

electron_scattering_factors(structure: pymatgen.core.structure.Structure, bragg_angles: Dict[Tuple[int, int, int], float]) → Dict[str, Dict[Tuple[int, int, int], float]][source]

Calculates atomic scattering factors for electrons using the Mott-Bethe formula (1st order Born approximation). :param structure: The input structure. :type structure: Structure :param bragg_angles: The Bragg angles for each hkl plane. :type bragg_angles: dict of 3-tuple to float

Returns

dict from atomic symbol to another dict of hkl plane to factor (in angstroms)

generate_points(coord_left: int = - 10, coord_right: int = 10) → numpy.ndarray[source]

Generates a bunch of 3D points that span a cube. :param coord_left: The minimum coordinate value. :type coord_left: int :param coord_right: The maximum coordinate value. :type coord_right: int

Returns

Numpy 2d array

get_first_point(structure: pymatgen.core.structure.Structure, points: list) → Dict[Tuple[int, int, int], float][source]

Gets the first point to be plotted in the 2D DP, corresponding to maximum d/minimum R. :param structure: The input structure. :type structure: Structure :param points: All points to be checked. :type points: list

Returns

dict of a hkl plane to max interplanar distance.

get_interplanar_angle(structure: pymatgen.core.structure.Structure, p1: Tuple[int, int, int], p2: Tuple[int, int, int]) → float[source]

Returns the interplanar angle (in degrees) between the normal of two crystal planes. Formulas from International Tables for Crystallography Volume C pp. 2-9. :param structure: The input structure. :type structure: Structure :param p1: plane 1 :type p1: 3-tuple :param p2: plane 2 :type p2: 3-tuple

Returns

float

get_interplanar_spacings(structure: pymatgen.core.structure.Structure, points: List[Tuple[int, int, int]]) → Dict[Tuple[int, int, int], float][source]
Parameters
  • structure (Structure) – the input structure.

  • points (tuple) – the desired hkl indices.

Returns

Dict of hkl to its interplanar spacing, in angstroms (float).

get_pattern(structure: pymatgen.core.structure.Structure, scaled: bool = None, two_theta_range: Tuple[float, float] = None) → pandas.core.frame.DataFrame[source]

Returns all relevant TEM DP info in a pandas dataframe. :param structure: The input structure. :type structure: Structure :param scaled: Required value for inheritance, does nothing in TEM pattern :type scaled: boolean :param two_theta_range: Required value for inheritance, does nothing in TEM pattern :type two_theta_range: Tuple

Returns

PandasDataFrame

get_plot_2d(structure: pymatgen.core.structure.Structure) → plotly.graph_objs._figure.Figure[source]

Generates the 2D diffraction pattern of the input structure. :param structure: The input structure. :type structure: Structure

Returns

Figure

get_plot_2d_concise(structure: pymatgen.core.structure.Structure) → plotly.graph_objs._figure.Figure[source]

Generates the concise 2D diffraction pattern of the input structure of a smaller size and without layout. Does not display. :param structure: The input structure. :type structure: Structure

Returns

Figure

get_plot_coeffs(p1: Tuple[int, int, int], p2: Tuple[int, int, int], p3: Tuple[int, int, int]) → numpy.ndarray[source]

Calculates coefficients of the vector addition required to generate positions for each DP point by the Moore-Penrose inverse method. :param p1: The first point. Fixed. :type p1: 3-tuple :param p2: The second point. Fixed. :type p2: 3-tuple :param p3: The point whose coefficients are to be calculted. :type p3: 3-tuple

Returns

Numpy array

get_positions(structure: pymatgen.core.structure.Structure, points: list) → Dict[Tuple[int, int, int], list][source]

Calculates all the positions of each hkl point in the 2D diffraction pattern by vector addition. Distance in centimeters. :param structure: The input structure. :type structure: Structure :param points: All points to be checked. :type points: list

Returns

dict of hkl plane to xy-coordinates.

get_s2(bragg_angles: Dict[Tuple[int, int, int], float]) → Dict[Tuple[int, int, int], float][source]

Calculates the s squared parameter (= square of sin theta over lambda) for each hkl plane. :param bragg_angles: The bragg angles for each hkl plane. :type bragg_angles: Dict

Returns

Dict of hkl plane to s2 parameter, calculates the s squared parameter

(= square of sin theta over lambda).

is_parallel(structure: pymatgen.core.structure.Structure, plane: Tuple[int, int, int], other_plane: Tuple[int, int, int]) → bool[source]

Checks if two hkl planes are parallel in reciprocal space. :param structure: The input structure. :type structure: Structure :param plane: The first plane to be compared. :type plane: 3-tuple :param other_plane: The other plane to be compared. :type other_plane: 3-tuple

Returns

boolean

normalized_cell_intensity(structure: pymatgen.core.structure.Structure, bragg_angles: Dict[Tuple[int, int, int], float]) → Dict[Tuple[int, int, int], float][source]

Normalizes the cell_intensity dict to 1, for use in plotting. :param structure: The input structure. :type structure: Structure :param bragg_angles: The Bragg angles for each hkl plane. :type bragg_angles: dict of 3-tuple to float

Returns

dict of hkl plane to normalized cell intensity

tem_dots(structure: pymatgen.core.structure.Structure, points: list) → list[source]

Generates all TEM_dot as named tuples that will appear on the 2D diffraction pattern. :param structure: The input structure. :type structure: Structure :param points: All points to be checked. :type points: list

Returns

list of TEM_dots

wavelength_rel() → float[source]
Calculates the wavelength of the electron beam with relativistic kinematic effects taken

into account.

Parameters

none

Returns

Relativistic Wavelength (in angstroms)

x_ray_factors(structure: pymatgen.core.structure.Structure, bragg_angles: Dict[Tuple[int, int, int], float]) → Dict[str, Dict[Tuple[int, int, int], float]][source]

Calculates x-ray factors, which are required to calculate atomic scattering factors. Method partially inspired by the equivalent process in the xrd module. :param structure: The input structure. :type structure: Structure :param bragg_angles: Dictionary of hkl plane to Bragg angle. :type bragg_angles: Dict

Returns

dict of atomic symbol to another dict of hkl plane to x-ray factor (in angstroms).

zone_axis_filter(points: numpy.ndarray, laue_zone: int = 0) → List[Tuple[int, int, int]][source]

Filters out all points that exist within the specified Laue zone according to the zone axis rule. :param points: The list of points to be filtered. :type points: np.ndarray :param laue_zone: The desired Laue zone. :type laue_zone: int

Returns

list of 3-tuples