Kinematic diffraction#

Kinematic diffraction module is designed to handle kinematic simulation data. It is composed of Point, Line and Disk class objects.

class pyemaps.kdiffs.Point(p=(0.0, 0.0))#

Bases: object

A 2-D point (x, y) in a kinematic diffraction pattern.

__init__(p=(0.0, 0.0))#
Parameters:

p (tuple of float, optional) – the coordinates (x, y).

Raises:

PointError – if a coordinate isn’t numeric.

property x#

The x coordinate.

property y#

The y coordinate.

class pyemaps.kdiffs.Line(pt1=None, pt2=None, intensity=0, type=1)#

Bases: object

A line in a kinematic diffraction pattern: a Kikuchi line or a HOLZ line.

__init__(pt1=None, pt2=None, intensity=0, type=1)#
Parameters:
  • pt1 (Point, optional) – one end point.

  • pt2 (Point, optional) – the other end point.

  • intensity (int or float, optional) – the line’s intensity, stored as an integer.

  • type (int, optional) – 1 for a Kikuchi line, 2 for a HOLZ line.

Raises:

LineError – if an end point isn’t a Point, or intensity or type is invalid.

property pt1#

One end point, a Point.

property pt2#

The other end point, a Point.

property type#

The line type: 1 for a Kikuchi line, 2 for a HOLZ line.

property intensity#

The line’s intensity, as an integer.

calOpacity(l, h)#

Calculate the opacity to draw the line with, scaled linearly by its intensity: 0.2 at the lowest intensity l and 0.35 at the highest h.

Parameters:
  • l – lowest line intensity in the pattern.

  • h – highest line intensity in the pattern.

Returns:

the opacity, from 0.2 to 0.35. If l equals h, 0.35.

Return type:

float

to_dict()#

Return the line as a dictionary: {'pt1': (x1, y1), 'pt2': (x2, y2), 'int': intensity}.

class pyemaps.kdiffs.Index(I0=(0, 0, 0))#

Bases: object

The Miller indices (h, k, l) of a diffracted beam.

__init__(I0=(0, 0, 0))#
Parameters:

I0 (tuple of int, optional) – the three indices.

Raises:

PIndexError – if an index isn’t an integer.

property I1#

The first Miller index, h.

property I2#

The second Miller index, k.

property I3#

The third Miller index, l.

class pyemaps.kdiffs.Disk(c=None, r=0.0, i=None)#

Bases: object

A diffracted beam in a kinematic diffraction pattern: its center, radius and Miller indices.

__init__(c=None, r=0.0, i=None)#
Parameters:
  • c (Point, optional) – the center.

  • r (float, optional) – the radius.

  • i (Index, optional) – the Miller indices.

Raises:

DiskError – if c, r or i is invalid.

property c#

The center of the diffracted beam, a Point.

property r#

The radius of the diffracted beam.

property idx#

The Miller indices of the diffracted beam, an Index.

to_dict()#

Return the disk as a dictionary: {'c': (x, y), 'idx': (h, k, l), 'r': radius}.

class pyemaps.kdiffs.diffPattern(diff_dict)#

Bases: object

A kinematic diffraction pattern: its Kikuchi lines, HOLZ lines and diffracted beams.

generateDP() returns one, and showDif() displays it. Its coordinates are shifted by shift. For drawing it with other tools, see Using results in other tools.

__init__(diff_dict)#
Parameters:

diff_dict (dict, required) – the raw pattern data from a kinematic simulation. Create diffraction patterns with generateDP() rather than directly.

Raises:

DPError – if diff_dict is missing data or has invalid values.

property klines#

The Kikuchi lines, a list of Line.

property hlines#

The HOLZ lines, a list of Line. Only CBED patterns have them.

property disks#

The diffracted beams, a list of Disk.

property name#

The crystal’s name.

property shift#

The shift applied to the pattern’s coordinates, a Point.

property nklines#

The number of Kikuchi lines.

property nhlines#

The number of HOLZ lines.

property ndisks#

The number of diffracted beams.

to_dict()#

Return the pattern as a dictionary of lists: {'klines': [...], 'hlines': [...], 'disks': [...]}. Each Kikuchi or HOLZ line is a dictionary from Line.to_dict(), and each disk one from Disk.to_dict().

class pyemaps.kdiffs.Diffraction(name, mode=DEF_MODE)#

Bases: object

A list of kinematic diffraction patterns (available as DPList), each paired with the microscope controls it was simulated with. showDif() displays one.

from pyemaps import Crystal, DPList

si = Crystal.from_builtin('Silicon')
dpl = DPList('Silicon')
emc, dp = si.generateDP()
dpl.add(emc, dp)

for emc, dp in dpl:
    print(emc.zone, dp.ndisks)
__init__(name, mode=DEF_MODE)#
Parameters:
  • name (str, required) – the crystal’s name.

  • mode (int, optional) – 1 for normal patterns, 2 for CBED.

Raises:

DPListError – if name is empty or mode isn’t 1 or 2.

property name#

The crystal’s name.

property mode#

The diffraction mode: 1 for normal, 2 for CBED.

property diffList#

The patterns, as a list of (controls, pattern) tuples.

add(emc, diffP)#

Add a diffraction pattern, with the controls it was simulated with.

Parameters:
  • emc (EMControl, required) – the controls.

  • diffP (diffPattern, required) – the diffraction pattern.

Raises:

DPListError – if diffP isn’t a diffPattern.

sort()#

Sort the patterns by their controls.

clear()#

Remove all patterns from the list.