radtools.niggli#

radtools.niggli(a=1, b=1, c=1, alpha=90, beta=90, gamma=90, eps_rel=1e-05, verbose=False, return_cell=False, max_iter=10000)[source]#

Computes Niggli matrix form.

Parameters:
afloat, default 1

Length of the \(a_1\) vector.

bfloat, default 1

Length of the \(a_2\) vector.

cfloat, default 1

Length of the \(a_3\) vector.

alphafloat, default 90

Angle between vectors \(a_2\) and \(a_3\). In degrees.

betafloat, default 90

Angle between vectors \(a_1\) and \(a_3\). In degrees.

gammafloat, default 90

Angle between vectors \(a_1\) and \(a_2\). In degrees.

eps_relfloat, default 1e-5

Relative epsilon as defined in [2].

verbosebool, default False

Whether to print the steps of an algorithm.

return_cellbool, default False

Whether to return cell parameters instead of Niggli matrix form.

max_iterint, default 100000

Maximum number of iterations.

Returns:
result(3,2) numpy.ndarray

Niggli matrix form as defined in [1]:

\[\begin{split}\begin{pmatrix} A & B & C \\ \xi/2 & \eta/2 & \zeta/2 \end{pmatrix}\end{split}\]

If return_cell == True, then return Niggli cell: (a, b, c, alpha, beta, gamma).

Raises:
ValueError

If the niggli cell is not found in max_iter iterations.

ValueError

If the provided cell`s volume is zero.

References

[1] (1,2)

Křivý, I. and Gruber, B., 1976. A unified algorithm for determining the reduced (Niggli) cell. Acta Crystallographica Section A: Crystal Physics, Diffraction, Theoretical and General Crystallography, 32(2), pp.297-298.

[2]

Grosse-Kunstleve, R.W., Sauter, N.K. and Adams, P.D., 2004. Numerically stable algorithms for the computation of reduced unit cells. Acta Crystallographica Section A: Foundations of Crystallography, 60(1), pp.1-6.

Examples

Example from [1] (parameters are reproducing \(A=9\), \(B=27\), \(C=4\), \(\xi\) = -5, \(\eta\) = -4, \(\zeta = -22\)):

>>> import radtools as rad
>>> from radtools.constants import TODEGREES
>>> from math import acos, sqrt
>>> a = 3
>>> b = sqrt(27)
>>> c = 2
>>> print(f"{a} {b:.3f} {c}")
3 5.196 2
>>> alpha = acos(-5 / 2 / b / c) * TODEGREES
>>> beta = acos(-4 / 2 / a / c) * TODEGREES
>>> gamma = acos(-22 / 2 / a / b) * TODEGREES
>>> print(f"{alpha:.2f} {beta:.2f} {gamma:.2f}")
103.92 109.47 134.88
>>> niggli_matrix_form = rad.niggli(a, b, c, alpha, beta, gamma, verbose=True)
               A         B         C        xi        eta      zeta
start:       9.00000  27.00000   4.00000  -5.00000  -4.00000 -22.00000
2 appl. to   9.00000  27.00000   4.00000  -5.00000  -4.00000 -22.00000
1 appl. to   9.00000   4.00000  27.00000  -5.00000 -22.00000  -4.00000
4 appl. to   4.00000   9.00000  27.00000 -22.00000  -5.00000  -4.00000
5 appl. to   4.00000   9.00000  27.00000 -22.00000  -5.00000  -4.00000
4 appl. to   4.00000   9.00000  14.00000  -4.00000  -9.00000  -4.00000
6 appl. to   4.00000   9.00000  14.00000  -4.00000  -9.00000  -4.00000
4 appl. to   4.00000   9.00000   9.00000  -8.00000  -1.00000  -4.00000
7 appl. to   4.00000   9.00000   9.00000  -8.00000  -1.00000  -4.00000
3 appl. to   4.00000   9.00000   9.00000  -9.00000  -1.00000   4.00000
5 appl. to   4.00000   9.00000   9.00000   9.00000   1.00000   4.00000
3 appl. to   4.00000   9.00000   9.00000  -9.00000  -3.00000   4.00000
result:      4.00000   9.00000   9.00000   9.00000   3.00000   4.00000
>>> niggli_matrix_form
array([[4. , 9. , 9. ],
       [4.5, 1.5, 2. ]])