Debian Codegraph @

avogadro/core/crystaltools.h

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #ifndef AVOGADRO_CORE_CRYSTALTOOLS_H
7 #define AVOGADRO_CORE_CRYSTALTOOLS_H
8
9 #include "avogadrocoreexport.h"
10
11 #include "array.h"
12 #include "avogadrocore.h"
13 #include "matrix.h"
14 #include "vector.h"
15
16 namespace Avogadro::Core {
17 class Molecule;
18 class UnitCell;
19
20 /**
21 * @class CrystalTools crystaltools.h <avogadro/core/crystaltools.h>
22 * @brief The CrystalTools class contains a collection of static functions
23 * that perform common crystallographic operations on a Core::Molecule.
24 */
25 class AVOGADROCORE_EXPORT CrystalTools
26 {
27 public:
28 /**
29 * @brief The Option enum provides bitwise option flags for the various
30 * algorithms.
31 */
32 enum Option
33 {
34 /** No options specified. */
35 None = 0x0,
36 /** Transform atoms along with the unit cell. */
37 TransformAtoms = 0x1,
38 /** Enforce right-handed system */
39 RightHanded = 0x2
40 };
41 using Options = int;
42
43 /**
44 * Adjust the atomic positions in @a molecule so that the fractional (lattice)
45 * coordinates of all atoms are in the range [0, 1].
46 * @return True on success, false otherwise.
47 */
48 static bool wrapAtomsToUnitCell(Molecule& molecule);
49
50 /**
51 * This function will rotate the input molecule so that the unit cell's 'a'
52 * vector is aligned to the x-axis, and the 'b' axis is in the xy-plane. It
53 * does not use trig functions or the cell parameters, since such
54 * implementations are fragile and cannot handle negative cell angles. The
55 * derivation of this algorithm can be found at
56 * http://xtalopt.openmolecules.net/misc/rotateToStdOrientation.pdf.
57 *
58 * @param opts If TransformAtoms is specified, the atoms in @a molecule are
59 * rotated along with the unit cell.
60 * @return True on success, false otherwise.
61 */
62 static bool rotateToStandardOrientation(Molecule& molecule,
63 Options opts = None);
64
65 /**
66 * Isotropically scale the volume of the unit cell in @a molecule to @a
67 * newVolume (in cubic angstrom).
68 * @param opts If TransformAtoms is specified, the atoms in @a molecule are
69 * adjusted so that their fractional (lattice) coordinates are preserved.
70 * @return True on success, false on failure.
71 */
72 static bool setVolume(Molecule& molecule, Real newVolume,
73 Options opts = None);
74
75 /**
76 * Perform a Niggli reduction on @a molecule's unit cell. This produces a
77 * canonical unit cell representation that strives to be as cubic as possible.
78 * @note Implements the niggli reduction algorithm detailed in:
79 * Grosse-Kunstleve RW, Sauter NK, Adams PD. Numerically stable
80 * algorithms for the computation of reduced unit cells. Acta
81 * Crystallographica Section A Foundations of
82 * Crystallography. 2003;60(1):1-6.
83 * @param opts If TransformAtoms is specified, the atom positions are modified
84 * to ensure that the same extended atomic structure from the input is
85 * represented by the output.
86 * @return True on success, false on failure.
87 */
88 static bool niggliReduce(Molecule& molecule, Options opts = None);
89
90 /**
91 * Return true if the unit cell in @a molecule is already Niggli-reduced. This
92 * method checks the conditions listed in the paper Gruber B.. Acta Cryst. A.
93 * 1973;29(4):433-440.
94 */
95 static bool isNiggliReduced(const Molecule& mol);
96
97 /**
98 * Build a supercell by expanding upon the unit cell of @a molecule. It will
99 * only return false if the molecule does not have a unit cell or if a, b, or
100 * c is set to zero.
101 * @param a The number of units along lattice vector a for the supercell
102 * @param b The number of units along lattice vector b for the supercell
103 * @param c The number of units along lattice vector c for the supercell
104 * @return True on success, false on failure.
105 */
106 static bool buildSupercell(Molecule& molecule, unsigned int a, unsigned int b,
107 unsigned int c);
108
109 /**
110 * Set the unit cell in @a molecule to represent the real-space column-vector
111 * unit cell description in @a newCellColMatrix. A unit cell is created if
112 * needed.
113 * @param opt If TransformAtoms is specified, the atoms in @a molecule are
114 * adjusted so that their fractional (lattice) coordinates are preserved. This
115 * option is ignored if the input molecule has no unit cell.
116 * @return True on success, false otherwise.
117 */
118 static bool setCellMatrix(Molecule& molecule, const Matrix3& newCellColMatrix,
119 Options opt = None);
120
121 /**
122 * Populate the @a frac vector with the fractional representation of the
123 * cartesian coordinates in @a cart, using @a unitCell to perform the
124 * coordinate transformation.
125 * @return True on success, false otherwise.
126 */
127 static bool fractionalCoordinates(const UnitCell& unitCell,
128 const Array<Vector3>& cart,
129 Array<Vector3>& frac);
130
131 /**
132 * Populate the @a coords vector with the fractional coordinates of the atoms
133 * in @a molecule, using the unit cell of @a molecule to perform the
134 * coordinate transformation. Coordinates are ordered the same as the
135 * Molecule::atomPositions3d() result.
136 * @return True on success, false otherwise.
137 */
138 static bool fractionalCoordinates(const Molecule& molecule,
139 Array<Vector3>& coords);
140
141 /**
142 * Set the atomic positions of @a molecule to the fractional coordinates in
143 * @a coords, using the unit cell of @a molecule to perform the coordinate
144 * transformation.
145 */
146 static bool setFractionalCoordinates(Molecule& molecule,
147 const Array<Vector3>& coords);
148
149 private:
150 CrystalTools(); // not implemented
151 ~CrystalTools(); // not implemented
152 };
153
154 } // namespace Avogadro::Core
155
156 #endif // AVOGADRO_CORE_CRYSTALTOOLS_H