diffpy.structure.lattice

Class Lattice stores properties and provides simple operations in lattice coordinate system.

diffpy.structure.lattice.cartesian

Constant instance of Lattice, default Cartesian system.

Type:

Lattice

class diffpy.structure.lattice.Lattice(a=None, b=None, c=None, alpha=None, beta=None, gamma=None, baserot=None, base=None)[source]

Bases: object

General coordinate system and associated operations.

Parameters:
  • a (float or Lattice, Optional) – The cell length a. When present, other cell parameters must be also specified. When of the Lattice type, create a duplicate Lattice.

  • b (float) – The cell length b.

  • c (float) – The cell length c.

  • alpha (float) – The angle between the b and c axes in degrees.

  • beta (float) – The angle between the b and c axes in degrees.

  • gamma (float) – The angle between the a and b axes in degrees.

  • baserot (array_like, Optional) – The 3x3 rotation matrix of the base vectors with respect to their standard setting.

  • base (array_like, Optional) – The 3x3 array of row base vectors. This must be the only argument when present.

metrics

The metrics tensor.

Type:

numpy.ndarray

base

The 3x3 matrix of row base vectors in Cartesian coordinates, which may be rotated, i.e., base = stdbase @ baserot.

Type:

numpy.ndarray

stdbase

The 3x3 matrix of row base vectors in standard orientation.

Type:

numpy.ndarray

baserot

The rotation matrix for the base.

Type:

numpy.ndarray

recbase

The inverse of the base matrix, where the columns give reciprocal vectors in Cartesian coordinates.

Type:

numpy.ndarray

normbase

The base vectors scaled by magnitudes of reciprocal cell lengths.

Type:

numpy.ndarray

recnormbase

The inverse of the normbase matrix.

Type:

numpy.ndarray

isotropicunit

The 3x3 tensor for a unit isotropic displacement parameters in this coordinate system. This is an identity matrix when this Lattice is orthonormal.

Type:

numpy.ndarray

Note

The array attributes are read-only. They get updated by changing some lattice parameters or by calling the setLatPar() or setLatBase() methods.

Examples

Create a Cartesian coordinate system:

>>> Lattice()

Create coordinate system with the cell lengths a, b, c and cell angles alpha, beta, gamma in degrees:

>>> Lattice(a, b, c, alpha, beta, gamma)

Create a duplicate of an existing Lattice lat:

>>> Lattice(lat)

Create coordinate system with the base vectors given by rows of the abc matrix:

>>> Lattice(base=abc)
property a

The unit cell length a.

abcABG()[source]

Return the cell parameters in the standard setting. :returns: A tuple of (a, b, c, alpha, beta, gamma). :rtype: tuple

property alpha

The cell angle alpha in degrees.

property alphar

The reciprocal cell angle alpha in degrees.

angle(u, v)[source]

Calculate angle between 2 lattice vectors in degrees.

Parameters:
  • u (array_like) – The first lattice vector.

  • v (array_like) – The second lattice vector.

Returns:

The angle between lattice vectors u and v in degrees.

Return type:

float

property ar

The cell length a of the reciprocal lattice.

property b

The unit cell length b.

property beta

The cell angle beta in degrees.

property betar

The reciprocal cell angle beta in degrees

property br

The cell length b of the reciprocal lattice.

property c

The unit cell length c.

property ca

The cosine of the cell angle alpha.

property car

The cosine of the reciprocal angle alpha.

cartesian(u)[source]

Transform lattice vector to Cartesian coordinates.

Parameters:

u (array_like) – Vector of lattice coordinates or an Nx3 array of lattice vectors.

Returns:

rc – Cartesian coordinates of the u vector.

Return type:

numpy.ndarray

property cb

The cosine of the cell angle beta.

property cbr

The cosine of the reciprocal angle beta.

property cg

The cosine of the cell angle gamma.

property cgr

The cosine of the reciprocal angle gamma.

property cr

The cell length c of the reciprocal lattice.

dist(u, v)[source]

Calculate distance between 2 points in lattice coordinates.

Parameters:
  • u (array_like) – A vector or an Nx3 matrix of fractional coordinates.

  • v (numpy.ndarray) – A vector or an Nx3 matrix of fractional coordinates.

Note

u and v must be of the same shape when matrices.

Returns:

The distance between lattice points u and v.

Return type:

float or numpy.ndarray

dot(u, v)[source]

Calculate dot product of 2 lattice vectors.

Parameters:
  • u (array_like) – The first lattice vector or an Nx3 array.

  • v (array_like) – The second lattice vector or an array of the same shape as u.

Returns:

The dot product of lattice vectors u, v.

Return type:

float or numpy.ndarray

fractional(rc)[source]

Transform Cartesian vector to fractional lattice coordinates.

Parameters:

rc (array_like) – A vector of Cartesian coordinates or an Nx3 array of Cartesian vectors.

Returns:

u – Fractional coordinates of the Cartesian vector rc.

Return type:

numpy.ndarray

property gamma

The cell angle gamma in degrees.

property gammar

The reciprocal cell angle gamma in degrees

isanisotropic(umx)[source]

True if displacement parameter matrix is anisotropic.

This checks if the specified matrix of anisotropic displacement parameters (ADP) differs from isotropic values for this lattice by more than a small round-off error.

Parameters:

umx (array_like) – The 3x3 matrix of displacement parameters.

Returns:

True when umx is anisotropic by more than a round-off error.

Return type:

bool

norm(xyz)[source]

Calculate norm of a lattice vector.

Parameters:

xyz (array_like) – A vector or an Nx3 array of fractional coordinates.

Returns:

The magnitude of the lattice vector xyz.

Return type:

float or numpy.ndarray

reciprocal()[source]

Return the reciprocal lattice of the current lattice. :returns: The reciprocal lattice of the current lattice. :rtype: Lattice

rnorm(hkl)[source]

Calculate norm of a reciprocal vector.

Parameters:

hkl (array_like) – A vector or an Nx3 array of reciprocal coordinates.

Returns:

The magnitude of the reciprocal vector hkl.

Return type:

float or numpy.ndarray

property sa

The sine of the cell angle alpha.

property sar

The sine of the reciprocal angle alpha.

property sb

The sine of the cell angle beta.

property sbr

The sine of the reciprocal angle beta.

setLatBase(base)[source]

Set new base vectors for this lattice.

This updates the cell lengths and cell angles according to the new base. The stdbase, baserot, and metrics attributes are also updated.

Parameters:

base (array_like) – The 3x3 matrix of row base vectors expressed in Cartesian coordinates.

setLatPar(a=None, b=None, c=None, alpha=None, beta=None, gamma=None, baserot=None)[source]

Set one or more lattice parameters.

This updates all attributes that depend on the lattice parameters.

Parameters:
  • a (float, Optional) – The new value of the cell length a.

  • b (float, Optional) – The new value of the cell length b.

  • c (float, Optional) – The new value of the cell length c.

  • alpha (float, Optional) – The new value of the cell angle alpha in degrees.

  • beta (float, Optional) – The new value of the cell angle beta in degrees.

  • gamma (float, Optional) – The new value of the cell angle gamma in degrees.

  • baserot (array_like, Optional) – The new 3x3 rotation matrix of the base vectors with respect to their standard setting in Cartesian coordinates.

Note

Parameters that are not specified will keep their initial values.

property sg

The sine of the cell angle gamma.

property sgr

The sine of the reciprocal angle gamma.

property unitvolume

The unit cell volume when a = b = c = 1.

property volume

The unit cell volume.

diffpy.structure.lattice.cosd(x)[source]

Return the cosine of x (measured in degrees).

Avoid round-off errors for exact cosine values.

Parameters:

x (float) – The angle in degrees.

Returns:

The cosine of the angle x.

Return type:

float

diffpy.structure.lattice.sind(x)[source]

Return the sine of x (measured in degrees).

Avoid round-off errors for exact sine values.

Parameters:

x (float) – The angle in degrees.

Returns:

The sine of the angle x.

Return type:

float