diffpy.structure.lattice

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

Module variables:
cartesian – constant instance of Lattice, default Cartesian system
cosd(x)

Return the cosine of x (measured in degrees). Avoid round-off errors for exact cosine values.

sind(x)

Return the sine of x (measured in degrees). Avoid round-off errors for exact sine values.

class Lattice(a=None, b=None, c=None, alpha=None, beta=None, gamma=None, baserot=None, base=None)

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:ndarray
base

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

Type:ndarray
stdbase

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

Type:ndarray
baserot

The rotation matrix for the base.

Type:ndarray
recbase

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

Type:ndarray
normbase

The base vectors scaled by magnitudes of reciprocal cell lengths.

Type:ndarray
recnormbase

The inverse of the normbase matrix.

Type: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: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)
a

The unit cell length a.

b

The unit cell length b.

c

The unit cell length c.

alpha

The cell angle alpha in degrees.

beta

The cell angle beta in degrees.

gamma

The cell angle gamma in degrees.

unitvolume

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

volume

The unit cell volume.

ar

The cell length a of the reciprocal lattice.

br

The cell length b of the reciprocal lattice.

cr

The cell length c of the reciprocal lattice.

alphar

The reciprocal cell angle alpha in degrees.

betar

The reciprocal cell angle beta in degrees

gammar

The reciprocal cell angle gamma in degrees

ca

The cosine of the cell angle alpha.

cb

The cosine of the cell angle beta.

cg

The cosine of the cell angle gamma.

sa

The sine of the cell angle alpha.

sb

The sine of the cell angle beta.

sg

The sine of the cell angle gamma.

car

The cosine of the reciprocal angle alpha.

cbr

The cosine of the reciprocal angle beta.

cgr

The cosine of the reciprocal angle gamma.

sar

The sine of the reciprocal angle alpha.

sbr

Sine of the reciprocal angle beta.

Type:flot
sgr

The sine of the reciprocal angle gamma.

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

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.

setLatBase(base)

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.
abcABG()
Returns:A tuple of (a, b, c, alpha, beta, gamma).
reciprocal()
Returns:Lattice – The reciprocal lattice of the current lattice.
cartesian(u)

Transform lattice vector to Cartesian coordinates.

Parameters:u (array_like) – Vector of lattice coordinates or an Nx3 array of lattice vectors.
Returns:rc (ndarray) – Cartesian coordinates of the u vector.
fractional(rc)

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 (ndarray) – Fractional coordinates of the Cartesian vector rc.
dot(u, v)

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:

float or ndarray – The dot product of lattice vectors u, v.

norm(xyz)

Calculate norm of a lattice vector.

Parameters:xyz (array_like) – A vector or an Nx3 array of fractional coordinates.
Returns:float or ndarray – The magnitude of the lattice vector xyz.
rnorm(hkl)

Calculate norm of a reciprocal vector.

Parameters:hkl (array_like) – A vector or an Nx3 array of reciprocal coordinates.
Returns:float or ndarray – The magnitude of the reciprocal vector hkl.
dist(u, v)

Calculate distance between 2 points in lattice coordinates.

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

Note

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

Returns:float or ndarray – The distance between lattice points u and v.
angle(u, v)

Calculate angle between 2 lattice vectors in degrees.

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

float – The angle between lattice vectors u and v in degrees.

isanisotropic(umx)

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:bool – True when umx is anisotropic by more than a round-off error.