Mantid
Loading...
Searching...
No Matches
PointGroupFactory.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
11
12#include <algorithm>
13#include <boost/algorithm/string.hpp>
14#include <utility>
15
16namespace Mantid::Geometry {
17
20 if (!isSubscribed(hmSymbol)) {
21 throw std::invalid_argument("Point group with symbol '" + hmSymbol + "' is not registered.");
22 }
23
24 return constructFromPrototype(getPrototype(hmSymbol));
25}
26
28 return createPointGroupFromSpaceGroup(*spaceGroup);
29}
30
32 std::string pointGroupSymbol = pointGroupSymbolFromSpaceGroupSymbol(spaceGroup.hmSymbol());
33
34 try {
35 PointGroup_sptr pointGroup = createPointGroup(pointGroupSymbol);
36
37 // If the crystal system is trigonal, we need to do more.
38 if (pointGroup->crystalSystem() == PointGroup::CrystalSystem::Trigonal) {
39 throw std::invalid_argument("Trigonal space groups need to be processed differently.");
40 }
41
42 return pointGroup;
43 } catch (const std::invalid_argument &) {
45 pointGroupSymbol.append(" r");
46 }
47
48 return createPointGroup(pointGroupSymbol);
49 }
50}
51
52bool PointGroupFactoryImpl::isSubscribed(const std::string &hmSymbol) const {
53 return m_generatorMap.find(hmSymbol) != m_generatorMap.end();
54}
55
57std::vector<std::string> PointGroupFactoryImpl::getAllPointGroupSymbols() const {
58 std::vector<std::string> pointGroups;
59 pointGroups.reserve(m_generatorMap.size());
60 std::transform(m_generatorMap.cbegin(), m_generatorMap.cend(), std::back_inserter(pointGroups),
61 [](const auto &generator) { return generator.first; });
62 return pointGroups;
63}
64
67std::vector<std::string> PointGroupFactoryImpl::getPointGroupSymbols(const PointGroup::CrystalSystem &crystalSystem) {
68 std::vector<std::string> pointGroups;
69
70 for (auto &generator : m_generatorMap) {
71 PointGroup_sptr pointGroup = getPrototype(generator.first);
72
73 if (pointGroup->crystalSystem() == crystalSystem) {
74 pointGroups.emplace_back(generator.first);
75 }
76 }
77
78 return pointGroups;
79}
80
81void PointGroupFactoryImpl::subscribePointGroup(const std::string &hmSymbol, const std::string &generatorString,
82 const std::string &description) {
83 if (isSubscribed(hmSymbol)) {
84 throw std::invalid_argument("Point group with this symbol is already registered.");
85 }
86
87 PointGroupGenerator_sptr generator = std::make_shared<PointGroupGenerator>(hmSymbol, generatorString, description);
88
89 subscribe(generator);
90}
91
109std::string PointGroupFactoryImpl::pointGroupSymbolFromSpaceGroupSymbol(const std::string &spaceGroupSymbol) const {
110 std::string noOriginChoice = boost::regex_replace(spaceGroupSymbol, m_originChoiceRegex, "");
111 std::string noScrews = boost::regex_replace(noOriginChoice, m_screwAxisRegex, "\\1");
112 std::string noGlides = boost::regex_replace(noScrews, m_glidePlaneRegex, "m");
113 std::string noCentering = boost::regex_replace(noGlides, m_centeringRegex, "");
114
115 std::string noSpaces = boost::algorithm::erase_all_copy(noCentering, " ");
116
117 if (noSpaces.substr(0, 1) == "1" && noSpaces.size() > 2 && noSpaces.substr(noSpaces.size() - 1, 1) == "1") {
118 noSpaces = noSpaces.substr(1, noSpaces.size() - 2);
119 }
120
121 return noSpaces;
122}
123
125 PointGroupGenerator_sptr generator = m_generatorMap.find(hmSymbol)->second;
126
127 if (!generator) {
128 throw std::runtime_error("No generator for symbol '" + hmSymbol + "'");
129 }
130
131 return generator->getPrototype();
132}
133
135 if (!generator) {
136 throw std::runtime_error("Cannot register null-generator.");
137 }
138
139 m_generatorMap.emplace(generator->getHMSymbol(), generator);
140}
141
143 return std::make_shared<PointGroup>(*prototype);
144}
145
148 : m_generatorMap(), m_crystalSystemMap(), m_screwAxisRegex("(2|3|4|6)[1|2|3|4|5]"),
149 m_glidePlaneRegex("a|b|c|d|e|g|n"), m_centeringRegex("[A-Z]"), m_originChoiceRegex(":(1|2|r)") {
151}
152
153PointGroupGenerator::PointGroupGenerator(std::string hmSymbol, std::string generatorInformation,
154 std::string description)
155 : m_hmSymbol(std::move(hmSymbol)), m_generatorString(std::move(generatorInformation)),
156 m_description(std::move(description)) {}
157
159 if (!hasValidPrototype()) {
161 }
162
163 return m_prototype;
164}
165
167 Group_const_sptr generatingGroup = GroupFactory::create<ProductOfCyclicGroups>(m_generatorString);
168
169 if (!generatingGroup) {
170 throw std::runtime_error("Could not create group from supplied symmetry operations.");
171 }
172
173 return std::make_shared<PointGroup>(m_hmSymbol, *generatingGroup, m_description);
174}
175
176DECLARE_POINTGROUP("1", "x,y,z", "Triclinic")
177DECLARE_POINTGROUP("-1", "-x,-y,-z", "Triclinic")
178DECLARE_POINTGROUP("2", "-x,y,-z", "Monoclinic, unique axis b")
179DECLARE_POINTGROUP("112", "-x,-y,z", "Monoclinic, unique axis c")
180DECLARE_POINTGROUP("m", "x,-y,z", "Monoclinic, unique axis b")
181DECLARE_POINTGROUP("11m", "x,y,-z", "Monoclinic, unique axis c")
182DECLARE_POINTGROUP("2/m", "-x,y,-z; -x,-y,-z", "Monoclinic, unique axis b")
183DECLARE_POINTGROUP("112/m", "-x,-y,z; x,y,-z", "Monoclinic, unique axis c")
184DECLARE_POINTGROUP("222", "-x,-y,z; x,-y,-z", "Orthorhombic")
185DECLARE_POINTGROUP("mm2", "-x,-y,z; -x,y,z", "Orthorhombic")
186DECLARE_POINTGROUP("2mm", "x,-y,-z; x,-y,z", "Orthorhombic")
187DECLARE_POINTGROUP("m2m", "-x,y,-z; x,y,-z", "Orthorhombic")
188DECLARE_POINTGROUP("mmm", "-x,-y,-z; -x,-y,z; x,-y,-z", "Orthorhombic")
189DECLARE_POINTGROUP("4", "-y,x,z", "Tetragonal")
190DECLARE_POINTGROUP("-4", "y,-x,-z", "Tetragonal")
191DECLARE_POINTGROUP("4/m", "-y,x,z; -x,-y,-z", "Tetragonal")
192DECLARE_POINTGROUP("422", "-y,x,z; x,-y,-z", "Tetragonal")
193DECLARE_POINTGROUP("4mm", "-y,x,z; -x,y,z", "Tetragonal")
194DECLARE_POINTGROUP("-42m", "y,-x,-z; x,-y,-z", "Tetragonal")
195DECLARE_POINTGROUP("-4m2", "y,-x,-z; y,x,-z", "Tetragonal")
196DECLARE_POINTGROUP("4/mmm", "-y,x,z; x,y,-z; x,-y,-z", "Tetragonal")
197
198DECLARE_POINTGROUP("3", "-y,x-y,z", "Trigonal - Hexagonal")
199DECLARE_POINTGROUP("-3", "y,y-x,-z", "Trigonal - Hexagonal")
200DECLARE_POINTGROUP("321", "-y,x-y,z; x-y,-y,-z", "Trigonal - Hexagonal")
201DECLARE_POINTGROUP("32", "-y,x-y,z; x-y,-y,-z", "Trigonal - Hexagonal")
202DECLARE_POINTGROUP("312", "-y,x-y,z; x,x-y,-z", "Trigonal - Hexagonal")
203DECLARE_POINTGROUP("3m1", "-y,x-y,z; y-x,y,z", "Trigonal - Hexagonal")
204DECLARE_POINTGROUP("3m", "-y,x-y,z; y-x,y,z", "Trigonal - Hexagonal")
205DECLARE_POINTGROUP("31m", "-y,x-y,z; -x,y-x,z", "Trigonal - Hexagonal")
206DECLARE_POINTGROUP("-3m1", "y,y-x,-z; x-y,-y,-z", "Trigonal - Hexagonal")
207DECLARE_POINTGROUP("-3m", "y,y-x,-z; x-y,-y,-z", "Trigonal - Hexagonal")
208DECLARE_POINTGROUP("-31m", "y,y-x,-z; x,x-y,-z", "Trigonal - Hexagonal")
209
210DECLARE_POINTGROUP("3 r", "z,x,y", "Trigonal - Rhombohedral")
211DECLARE_POINTGROUP("-3 r", "-z,-x,-y", "Trigonal - Rhombohedral")
212DECLARE_POINTGROUP("32 r", "z,x,y; -y,-x,-z", "Trigonal - Rhombohedral")
213DECLARE_POINTGROUP("3m r", "z,x,y; y,x,z", "Trigonal - Rhombohedral")
214DECLARE_POINTGROUP("-3m r", "-z,-x,-y; y,x,z", "Trigonal - Rhombohedral")
215
216DECLARE_POINTGROUP("6", "x-y,x,z", "Hexagonal")
217DECLARE_POINTGROUP("-6", "y-x,-x,-z", "Hexagonal")
218DECLARE_POINTGROUP("6/m", "x-y,x,z; -x,-y,-z", "Hexagonal")
219DECLARE_POINTGROUP("622", "x-y,x,z; x-y,-y,-z", "Hexagonal")
220DECLARE_POINTGROUP("6mm", "x-y,x,z; y-x,y,z", "Hexagonal")
221DECLARE_POINTGROUP("-62m", "y-x,-x,-z; x-y,-y,-z", "Hexagonal")
222DECLARE_POINTGROUP("-6m2", "y-x,-x,-z; y-x,y,z", "Hexagonal")
223DECLARE_POINTGROUP("6/mmm", "x-y,x,z; x-y,-y,-z; -x,-y,-z", "Hexagonal")
224
225DECLARE_POINTGROUP("23", "z,x,y; -x,-y,z; x,-y,-z", "Cubic")
226DECLARE_POINTGROUP("m-3", "-z,-x,-y; -x,-y,z; x,-y,-z", "Cubic")
227DECLARE_POINTGROUP("432", "z,x,y; -y,x,z; x,-y,-z", "Cubic")
228DECLARE_POINTGROUP("-43m", "z,x,y; y,-x,-z; -y,-x,z", "Cubic")
229DECLARE_POINTGROUP("m-3m", "-z,-x,-y; -y,x,z; y,x,-z", "Cubic")
230
231} // namespace Mantid::Geometry
#define DECLARE_POINTGROUP(hmSymbol, generators, description)
CoordinateSystem getCoordinateSystem() const
Returns the axis system of the group (either orthogonal or hexagonal).
Definition: Group.cpp:37
PointGroupFactoryImpl()
Private default constructor.
bool isSubscribed(const std::string &hmSymbol) const
void subscribePointGroup(const std::string &hmSymbol, const std::string &generatorString, const std::string &description)
PointGroup_sptr createPointGroupFromSpaceGroup(const SpaceGroup_const_sptr &spaceGroup)
void subscribe(const PointGroupGenerator_sptr &generator)
std::map< std::string, PointGroupGenerator_sptr > m_generatorMap
PointGroup_sptr createPointGroup(const std::string &hmSymbol)
Creates a PointGroup object from its Hermann-Mauguin symbol.
std::string pointGroupSymbolFromSpaceGroupSymbol(const std::string &spaceGroupSymbol) const
Returns the point group symbol from a given space group symbol.
PointGroup_sptr constructFromPrototype(const PointGroup_sptr &prototype) const
std::vector< std::string > getAllPointGroupSymbols() const
Returns the Hermann-Mauguin symbols of all registered point groups.
std::vector< std::string > getPointGroupSymbols(const PointGroup::CrystalSystem &crystalSystem)
Returns the Hermann-Mauguin symbols of all point groups that belong to a certain crystal system.
PointGroup_sptr getPrototype(const std::string &hmSymbol)
PointGroupGenerator(std::string hmSymbol, std::string generatorInformation, std::string description)
A class for representing space groups, inheriting from Group.
Definition: SpaceGroup.h:46
std::string hmSymbol() const
Returns the stored Hermann-Mauguin symbol.
Definition: SpaceGroup.cpp:34
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< PointGroupGenerator > PointGroupGenerator_sptr
std::shared_ptr< PointGroup > PointGroup_sptr
Shared pointer to a PointGroup.
Definition: PointGroup.h:67
std::shared_ptr< const SpaceGroup > SpaceGroup_const_sptr
Definition: SpaceGroup.h:82
std::shared_ptr< const Group > Group_const_sptr
Definition: Group.h:179
STL namespace.