| 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_SPACE_GROUPS_H |
| 7 |
#define AVOGADRO_CORE_SPACE_GROUPS_H |
| 8 |
|
| 9 |
#include "avogadrocoreexport.h" |
| 10 |
|
| 11 |
#include "array.h" |
| 12 |
#include "vector.h" |
| 13 |
|
| 14 |
#include <string> |
| 15 |
|
| 16 |
namespace Avogadro::Core { |
| 17 |
|
| 18 |
class Molecule; |
| 19 |
|
| 20 |
/** |
| 21 |
* Enumeration of the crystal system. |
| 22 |
*/ |
| 23 |
enum CrystalSystem |
| 24 |
{ |
| 25 |
None, |
| 26 |
Triclinic, |
| 27 |
Monoclinic, |
| 28 |
Orthorhombic, |
| 29 |
Tetragonal, |
| 30 |
Trigonal, |
| 31 |
Rhombohedral, |
| 32 |
Hexagonal, |
| 33 |
Cubic |
| 34 |
}; |
| 35 |
|
| 36 |
/** |
| 37 |
* @class SpaceGroups spacegroups.h <avogadro/core/spacegroups.h> |
| 38 |
* @brief The Spacegroups class stores basic data about crystal spacegroups. |
| 39 |
* |
| 40 |
* The spacegroups class gives a simple interface to basic data about crystal |
| 41 |
* spacegroups. The data is generated from information in spglib. |
| 42 |
*/ |
| 43 |
|
| 44 |
class AVOGADROCORE_EXPORT SpaceGroups |
| 45 |
{ |
| 46 |
public: |
| 47 |
SpaceGroups() = default; |
| 48 |
~SpaceGroups() = default; |
| 49 |
|
| 50 |
/** |
| 51 |
* @return The hall number of the matching space group string or 0 if not |
| 52 |
* found |
| 53 |
*/ |
| 54 |
static unsigned short hallNumber(const std::string& spaceGroup); |
| 55 |
|
| 56 |
/** |
| 57 |
* @return an enum representing the crystal system for a given hall number. |
| 58 |
* If an invalid hall number is given, None will be returned. |
| 59 |
*/ |
| 60 |
static CrystalSystem crystalSystem(unsigned short hallNumber); |
| 61 |
|
| 62 |
/** |
| 63 |
* @return the international number for a given hall number. |
| 64 |
* If an invalid hall number is given, 0 will be returned. |
| 65 |
*/ |
| 66 |
static unsigned short internationalNumber(unsigned short hallNumber); |
| 67 |
|
| 68 |
/** |
| 69 |
* @return the Schoenflies symbol for a given hall number. |
| 70 |
* If an invalid hall number is given, an empty string will be returned. |
| 71 |
*/ |
| 72 |
static const char* schoenflies(unsigned short hallNumber); |
| 73 |
|
| 74 |
/** |
| 75 |
* @return the Hall symbol for a given hall number. '=' is used instead of |
| 76 |
* '"'. If an invalid hall number is given, an empty string will be returned. |
| 77 |
*/ |
| 78 |
static const char* hallSymbol(unsigned short hallNumber); |
| 79 |
|
| 80 |
/** |
| 81 |
* @return the international symbol for a given hall number. |
| 82 |
* If an invalid hall number is given, an empty string will be returned. |
| 83 |
*/ |
| 84 |
static const char* international(unsigned short hallNumber); |
| 85 |
|
| 86 |
/** |
| 87 |
* @return the full international symbol for a given hall number. |
| 88 |
* If an invalid hall number is given, an empty string will be returned. |
| 89 |
*/ |
| 90 |
static const char* internationalFull(unsigned short hallNumber); |
| 91 |
|
| 92 |
/** |
| 93 |
* @return the short international symbol for a given hall number. |
| 94 |
* If an invalid hall number is given, an empty string will be returned. |
| 95 |
*/ |
| 96 |
static const char* internationalShort(unsigned short hallNumber); |
| 97 |
|
| 98 |
/** |
| 99 |
* @return the setting for a given hall number. |
| 100 |
* If an invalid hall number is given, an empty string will be returned. |
| 101 |
* An empty string may also be returned if there are no settings for this |
| 102 |
* space group. |
| 103 |
*/ |
| 104 |
static const char* setting(unsigned short hallNumber); |
| 105 |
|
| 106 |
/** |
| 107 |
* @return the number of transforms for a given hall number. |
| 108 |
* If an invalid hall number is given, 0 will be returned. |
| 109 |
*/ |
| 110 |
static unsigned short transformsCount(unsigned short hallNumber); |
| 111 |
|
| 112 |
/** |
| 113 |
* @return an array of transforms for a given hall number and a vector v. |
| 114 |
* The vector should be in fractional coordinates. |
| 115 |
* If an invalid hall number is given, an empty array will be returned. |
| 116 |
*/ |
| 117 |
static Array<Vector3> getTransforms(unsigned short hallNumber, |
| 118 |
const Vector3& v); |
| 119 |
|
| 120 |
/** |
| 121 |
* Fill a crystal with atoms by using transforms from a hall number. |
| 122 |
* Nothing will be done if the molecule does not have a unit cell. |
| 123 |
* The cartesian tolerance is used to check if an atom is already |
| 124 |
* present at that location. If there is another atom within that |
| 125 |
* distance, the new atom will not be placed there. |
| 126 |
*/ |
| 127 |
static void fillUnitCell(Molecule& mol, unsigned short hallNumber, |
| 128 |
double cartTol = 1e-5, bool wrapToCell = true, |
| 129 |
bool allCopies = false); |
| 130 |
|
| 131 |
/** |
| 132 |
* Add translational copies of atoms on the unit cell boundary. |
| 133 |
* For atoms at fractional coordinate ~0, a copy is placed at ~1 and |
| 134 |
* vice versa, plus edge and corner combinations. |
| 135 |
* No symmetry operations are applied. |
| 136 |
*/ |
| 137 |
static void fillTranslationalCopies(Molecule& mol, double cartTol = 1e-5); |
| 138 |
|
| 139 |
/** |
| 140 |
* Reduce a cell to its asymmetric unit. |
| 141 |
* Nothing will be done if the molecule does not have a unit cell. |
| 142 |
* The cartesian tolerance is used to check if an atom is present |
| 143 |
* at a location within the tolerance distance. |
| 144 |
* If an atom is present, the atom gets removed. |
| 145 |
*/ |
| 146 |
static void reduceToAsymmetricUnit(Molecule& mol, unsigned short hallNumber, |
| 147 |
double cartTol = 1e-5); |
| 148 |
|
| 149 |
/** |
| 150 |
* Get indices of translationally unique atoms, filtering out duplicates. |
| 151 |
* Atoms with fractional coordinates near 1.0 that duplicate atoms near 0.0 |
| 152 |
* (due to periodic boundary conditions) are excluded. |
| 153 |
* @param mol The molecule with a unit cell |
| 154 |
* @param tolerance Fractional coordinate tolerance for duplicate detection |
| 155 |
* @return Array of atom indices to include (empty if no unit cell) |
| 156 |
*/ |
| 157 |
static Array<Index> translationalUniqueAtoms(const Molecule& mol, |
| 158 |
double tolerance = 0.001); |
| 159 |
|
| 160 |
private: |
| 161 |
/** |
| 162 |
* Get the transforms string stored in the database. |
| 163 |
*/ |
| 164 |
static const char* transformsString(unsigned short hallNumber); |
| 165 |
}; |
| 166 |
|
| 167 |
} // namespace Avogadro::Core |
| 168 |
|
| 169 |
#endif // AVOGADRO_CORE_SPACE_GROUPS_H |