Crystallographic metric matrix (source code)

= Crystallographic metric matrix

The \b[crystallographic metric matrix] is the <Gram matrix> of the three <unit cell> basis vectors. If $A$ has Cartesian columns $\mathbf a,\mathbf b,\mathbf c$, then
$$
G=A^TA=
\begin{pmatrix}
a^2&ab\cos\gamma&ac\cos\beta\\
ab\cos\gamma&b^2&bc\cos\alpha\\
ac\cos\beta&bc\cos\alpha&c^2
\end{pmatrix}.
$$
Here $\alpha,\beta,\gamma$ are the angles between $\mathbf b,\mathbf c$; $\mathbf a,\mathbf c$; and $\mathbf a,\mathbf b$, respectively. The matrix converts <fractional crystallographic coordinate> differences into physical lengths: a fractional displacement $\mathbf u$ has squared length $\mathbf u^TG\mathbf u$.<Metric tensor in the IUCr Online Dictionary of Crystallography>[Definition, direct-basis components and scalar products]{ref}

For an original oblique cell, choose $a=2$, $b=3$, $c=4$ angstroms, $\gamma=60^\circ$ and $\alpha=\beta=90^\circ$. Then
$$
G=\begin{pmatrix}4&3&0\\3&9&0\\0&0&16\end{pmatrix}
\,\mathrm{\mathring A^2}.
$$
For $\mathbf u=(1/2,-1/2,0)^T$,
$$
|A\mathbf u|^2=\frac{4+9-2(3)}4
=\frac74\,\mathrm{\mathring A^2}.
$$
Ignoring the off-diagonal entries would instead give $13/4$, overestimating this distance. The cross terms encode the cell angles.

The <reciprocal crystallographic metric matrix> is $G^{-1}$ when the reciprocal basis has dot products $\mathbf a_i^*\cdot\mathbf a_j=\delta_{ij}$, with no factor of $2\pi$. Thus the plane spacing for a nonzero <Miller index> column $\mathbf h$ satisfies
$$
\frac1{d_{\mathbf h}^2}=\mathbf h^TG^{-1}\mathbf h.
$$
A basis change $A'=AP$ gives $G'=P^TGP$ and fractional coordinates $\mathbf u'=P^{-1}\mathbf u$, preserving $\mathbf u'^TG'\mathbf u'=\mathbf u^TG\mathbf u$. Distances do not change when the same <crystal structure> is described in another basis.<Metric tensor in the IUCr Online Dictionary of Crystallography>[Reciprocal-space components and Change of basis]{ref}