The subtleties of generating random unit cells are discussed.
Keywords: lattice ‘unit cells’
Abstract
Methods of generating random unit-cell data for testing software are discussed. Working within the space S 6 appears to be the most expeditious.
1. Introduction
Niggli (1928 ▸) ▸ and Delaunay (1932 ▸) ▸ first described the solutions to the problem of recognizing the appropriate Bravais lattice type of a particular unit cell. Practical methods of computationally determining that relationship for a particular cell continue to be of recurring interest [see, for example, Larsen et al. (2020 ▸) ▸]. In some cases, perturbations past boundaries into regions of unreduced cells may be useful, but in many cases reduction of the perturbed cells is necessary for further analysis. We describe the generation of random reduced and unreduced unit cells for testing such methods.
Methods for Bravais lattice determination of experimental unit cells continue to be described, including by Larsen et al. (2020 ▸). Andrews & Bernstein (2014 ▸) listed some of the metric methods that have been described (and gave a formal introduction of space G 6, already discussed in 1988 ▸). A repeating aspect of all of these studies is a distinct lack of any indication of extensive testing. In general, a few cases from the literature are cited and shown to produce the correct Bravais lattice type. Typically only a few types are tested (or at least described), and no indications of sensitivity are available. Leroy et al. (2021 ▸) described the frequent lack of software engineering practices in the development of scientific software, especially the lack of unit tests.
To support the development of a new method of Bravais lattice determination (Andrews et al., 2019a ▸), methods for generating random unit cells were investigated. Three uses for random unit-cell creation will be discussed here: generation of random unit cells, random unit cells of a particular Bravais type and randomly perturbed unit cells. In each case pseudo-random numbers, as opposed to truly stochastic numbers, are needed so that test cases can be reproduced (Knuth, 1973 ▸). It is best to include the source code of the random-number generator with the test-case generator to avoid differences among and biases in system-provided random-number generators.
2. Types of random cells
The first division of types is valid versus invalid unit cells. While care can be exercised during the assignment of random values, the final test is whether a valid unit cell corresponds to the input.
The second division is for valid unit cells, distinguishing between reduced versus unreduced unit cells. The same algorithms that are used for unit-cell reduction can be used to check for validity. In the case of Niggli reduction, the basic algorithm was published by Gruber (1973 ▸) and written as pseudo-code by Andrews & Bernstein (1988 ▸; first use of G 6, which was named only in 2014 ▸). For the case of Selling (Delone) reduction, a simple pseudo-code was published by Andrews et al. (2019b ▸), together with a discussion of the lower complexity of Selling reduction.
3. Generating examples from randomly chosen lattices
There are four obvious ways of generating a random unit cell: (i) generate three vectors, (ii) create the cell as a vector in G 6, (iii) create the cell as a vector in S 6 or (iv) generate it directly as the cell parameters of the cell, a, b, c, α, β, γ.
3.1. Random unit cell
Directly generating a random unit cell suffers from the obvious fact that the edge lengths and interaxial angles are not commensurate types. Generating three random edge lengths is simple. Angles must sum to less than 360°, and they must obey the triangle inequality. However, methods for uniformly perturbing a chosen cell by a given amount are not apparent.
3.2. Random G 6
Labeling the unit-cell edge vectors as a, b, c, a vector in G 6 (Andrews & Bernstein, 2014 ▸) is defined as
Unlike the case above, the six scalars now all have commensurate unit measure (Å2). Although that is an improvement, only the last three scalars contain information about the angles.
Six random values can be assigned to the scalars and the six-vector scaled to any desired length. Because the angle values are not directly addressed and because the last three scalars interact with the first three, the validity of the resulting cell must be verified.
3.3. Random S 6
Labeling the unit-cell edge vectors as a, b, c and adding d (
), the scalars of S
6 [Andrews et al. (2019c
▸) introduce the space S
6 and also C
3] are
Here, the scalars are fully commensurate (Å2), an advantage over the two preceding methods. Further, the fundamental unit in S 6 is the all-negative orthant. All points within that orthant correspond to valid Selling-reduced unit cells; any S 6 vector of six negative values corresponds to a valid cell. Further, every possible crystal lattice is represented by at least four points in that orthant; each triclinic lattice is represented by 24 such points (Andrews et al., 2019c ▸). If reduced unit cells are desired, then no further validity checking is necessary.
If non-reduced cells are desired, then the validity of the generated cells must be verified. Most, but not all, S 6 vectors with three zero scalars are valid, and many with three positive scalars are valid.
3.4. Three random vectors
Finally, there is the possibility of generating unit cells by choosing three non-coplanar vectors in Euclidean three-space. In general, the generated cells will not be reduced. Control over angles between base vectors becomes complex. Similarly, control over the changing relationships of the base vectors upon perturbation will be difficult. Again, the sum of the interaxial angles must be less than 360°, and any pair must sum to less than 120°.
4. Generating Bravais lattice examples
4.1. Random unit cell and three random vectors
The primitive lattice types are rather simple to generate. The centered lattices have more complex relationships (Burzlaff et al., 2016 ▸), which are described in terms of the metric tensor elements (components of G 6) or the Selling scalars (Burzlaff et al., 2016 ▸) (the components of S 6). Alternatively, the above relationships among scalars can be described as projectors in the appropriate vector space (S 6 or G 6).
4.2. G 6 and S 6
G 6 and S 6 are linear vector spaces, so we use the tools of linear algebra. Projectors for the 42 non-triclinic Niggli/Bravais lattice types were provided by Paciorek & Bonin (1992 ▸) ▸. Projectors for the 24 Delone/Bravais types are given in Appendix A .
Consider a simple example: primitive orthorhombic (oP), type O5 in Delone’s system.
![]() |
As an example, we choose a unit cell with a, b, c, α, β, γ = 10, 20, 30, 80, 70, 60 (Å, °); the corresponding S 6 vector is
Selling reduction gives
Multiplying the reduced S 6 vector by the projector yields the S 6 vector
which is invalid. The Selling-reduced vector is only one of 24 possible Selling-reduced reflections (Andrews et al., 2019c ▸). Another reflection must be used with the provided projector [because Delaunay (1932 ▸) ▸ only chose one particular reflection]. Niggli reduction gives the G 6 vector
Selling-reducing that vector gives the S 6 vector
Multiplying by the above projector gives the S 6 vector
The corresponding unit cell is
accomplishing the original goal of finding the nearest oP unit cell.
5. Perturbation
Finally, we come to perturbation, which is generally, but not limited to, small or modest modification of a particular datum. Perturbation can be done in any of the four schemes discussed above. The lengths and angles of a unit cell can be changed, the three cell-edge vectors can have their components changed, and the scalars of G 6 and S 6 can be modified. G 6 has the same potential problems cited above – the scalars affected by angles are separate from those that are purely length dependent. Once again, the uniformity of S 6 is an advantage.
Another consideration for perturbing a known cell is whether the perturbation should be random or in a direction normal to the starting vector. For many purposes (including Bravais lattice determination), having a component of change parallel to the vector gives no important change. In that case, it is more effective to make all of the change orthogonal to the input (this is the way that the program CmdPerturb works; see the code availability in Section 7 below).
A first attempt using S 6 to create perturbations led to less than optimal results. An S 6 vector for a valid unit cell was created, and a small orthogonal perturbation vector was added to it. For the test, a primitive cubic cell was used, so the initial angles were 90°; the character is (000, rrr). Two hundred perturbed samples were generated, but the result was unsatisfactory. The distribution of the signs of the unit-cell angle cosines was very unequal (see Table 1 ▸, columns A). Changing to create a perturbing vector with random signs improved the distribution (Table 1 ▸, columns B).
Table 1. Sign distributions of perturbed cP cells.
| A | B | ||
|---|---|---|---|
| − | 28 | − | 15 |
| −+, −+−, +− | 50 | −+, −+−, +− | 35 |
| −++, +−+, ++− | 17 | −++, +−+, ++− | 39 |
| +++ | 3 | +++ | 11 |
The improved distribution comes with the cost that the validity of the resulting unit cell must be verified if the perturbations are not small and the original vector is not a Selling-reduced cell.
For a concrete example, consider the case of primitive orthorhombic, 10, 20, 20, 90, 90, 90.
Three perturbed outputs are
![]() |
The same perturbed outputs in S 6 are
![]() |
6. Conclusions
We have reviewed four strategies for generating unit-cell data for unit testing of crystallographic software. In general, it seems that working with the space S 6 gives the most straightforward and uniform process. The three alternative strategies tend to deal with the angular and length components of cells separately, resulting in more complex algorithmic structures. S 6 has the advantage that the six scalars are commensurate and the fundamental unit (Selling-reduced) is convex.
7. Availability of code
Code for generating and perturbing unit cells is available on GitHub as follows.
For unit-cell generation: https://github.com/duck10/RandomCells
For perturbing unit cells: https://github.com/duck10/CmdPerturb
Both programs have constants to set in the function main.
For random cell generation, the desired number of output cells can be set. The type of Bravais lattice is also specified. To generate cells of all Bravais types, either leave the type blank or set it to triclinic (‘a’).
For perturbing cells, the output of generation can be used as input. The number of desired perturbations is set in the funtion main. Input (from standard input) is begun by the lattice centering, or by ‘G’ for G 6 input or by ‘S’ for S 6 input.
Acknowledgments
Careful copy editing by Sarah J. O’Brien and Frances C. Bernstein is gratefully acknowledged.
Appendix A. S 6 projectors for Bravais lattice type
The 24 variations of 14 Bravais lattice types are described by Delaunay (1932 ▸), Delone et al. (1975 ▸) and Andrews et al. (2019b ▸). Here we present the projectors of each of those types in the space S 6. Each matrix projects S 6 vectors into the manifold of the corresponding Bravais type. The numbering of the types is as they are in the two Delaunay/Delone references. The names (such as C1) were modified by Andrews et al. (2019b ▸) to follow modern conventions: for cubic ‘K’ becomes ‘C’, for tetragonal ‘Q’ becomes ‘T’, and for triclinic (anorthic) ‘T’ becomes ‘A’.
The ‘character’ field describes the properties of each manifold. Letters represent negative values (because all Selling-reduced scalars are non-positive), and zeroes represent required zero-value scalars. If a letter appears more than once, its values in the evaluated character are all equal. For instance, for type T1 with character (rrs rrs), a possible S 6 vector might be (−100 −100 −200 −100 −100 −200).
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Funding Statement
Work by HJB funded in part by NIGMS (grant No. 5P30GM133893-03 to Brookhaven National Laboratory, subaward to the Ronin Institute).
References
- Andrews, L. C. & Bernstein, H. J. (1988). Acta Cryst. A44, 1009–1018.
- Andrews, L. C. & Bernstein, H. J. (2014). J. Appl. Cryst. 47, 346–359. [DOI] [PMC free article] [PubMed]
- Andrews, L. C., Bernstein, H. J., Diaz, J., Sauter, N. K., Soares, A. & Wlodek, M. R. (2019a). Acta Cryst. A75, a168.
- Andrews, L. C., Bernstein, H. J. & Sauter, N. K. (2019b). Acta Cryst. A75, 115–120. [DOI] [PMC free article] [PubMed]
- Andrews, L. C., Bernstein, H. J. & Sauter, N. K. (2019c). Acta Cryst. A75, 593–599. [DOI] [PMC free article] [PubMed]
- Burzlaff, H., Grimmer, H., Gruber, B., de Wolff, P. & Zimmermann, H. (2016). Crystal Lattices, pp. 698–719. Wiley Online Library.
- Delaunay, B. N. (1932). Z. Krist. 84, 109–149.
- Delone, B. N., Galiulin, R. V. & Shtogrin, M. I. (1975). J. Math. Sci. 4, 79–156.
- Gruber, B. (1973). Acta Cryst. A29, 433–440.
- Knuth, D. E. (1973). Sorting and Searching. The Art of Computer Programming, Vol. 3. Reading: Addison Wesley.
- Larsen, P. M., Pang, E. L., Parrilo, P. A. & Jacobsen, K. W. (2020). Phys. Rev. Res. 2, 013077.
- Leroy, D., Sallou, J., Bourcier, J. & Combemale, B. (2021). Computer, 54, 60–71.
- Niggli, P. (1928). Krystallographische und Strukturtheoretische Grundbegriffe. Handbuch der Experimentalphysik, Vol. 7, Part 1. Leipzig: Akademische Verlagsgesellschaft.
- Paciorek, W. A. & Bonin, M. (1992). J. Appl. Cryst. 25, 632–637.



























