Mantid
Loading...
Searching...
No Matches
PointGroup.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#include "MantidKernel/System.h"
12
13#include <algorithm>
14#include <boost/algorithm/string.hpp>
15#include <memory>
16#include <set>
17
18namespace Mantid::Geometry {
20using Kernel::V3D;
21
38std::vector<V3D> PointGroup::getEquivalents(const V3D &hkl) const {
39 auto equivalents = getAllEquivalents(hkl);
40
41 std::sort(equivalents.begin(), equivalents.end(), std::greater<V3D>());
42
43 equivalents.erase(std::unique(equivalents.begin(), equivalents.end()), equivalents.end());
44
45 return equivalents;
46}
47
62 auto equivalents = getAllEquivalents(hkl);
63
64 return *std::max_element(equivalents.begin(), equivalents.end());
65}
66
68PointGroup::PointGroup(const std::string &symbolHM, const Group &group, const std::string &description)
69 : Group(group), m_symbolHM(symbolHM), m_name(symbolHM + " (" + description + ")") {
72}
73
75std::string PointGroup::getSymbol() const { return m_symbolHM; }
76
77bool PointGroup::isEquivalent(const Kernel::V3D &hkl, const Kernel::V3D &hkl2) const {
78 auto hklEquivalents = getAllEquivalents(hkl);
79
80 return (std::find(hklEquivalents.cbegin(), hklEquivalents.cend(), hkl2) != hklEquivalents.end());
81}
82
97std::vector<V3D> PointGroup::getAllEquivalents(const Kernel::V3D &hkl) const {
98 std::vector<V3D> equivalents;
99 equivalents.reserve(m_allOperations.size());
100 std::transform(m_allOperations.cbegin(), m_allOperations.cend(), std::back_inserter(equivalents),
101 [&hkl](const auto &operation) { return operation.transformHKL(hkl); });
102 return equivalents;
103}
104
117 std::map<std::string, std::set<V3D>> symbolMap;
118
119 for (const auto &operation : m_allOperations) {
120 SymmetryElementWithAxis_sptr element = std::dynamic_pointer_cast<SymmetryElementWithAxis>(
121 SymmetryElementFactory::Instance().createSymElement(operation));
122
123 if (element) {
124 std::string symbol = element->hmSymbol();
125 V3D axis = element->getAxis();
126
127 symbolMap[symbol].insert(axis);
128 }
129 }
130
131 if (symbolMap["3"].size() == 4) {
133 }
134
135 if (symbolMap["6"].size() == 1 || symbolMap["-6"].size() == 1) {
137 }
138
139 if (symbolMap["3"].size() == 1) {
141 }
142
143 if (symbolMap["4"].size() == 1 || symbolMap["-4"].size() == 1) {
145 }
146
147 if (symbolMap["2"].size() == 3 || (symbolMap["2"].size() == 1 && symbolMap["m"].size() == 2)) {
149 }
150
151 if (symbolMap["2"].size() == 1 || symbolMap["m"].size() == 1) {
153 }
154
156}
157
171 switch (crystalSystem) {
184 default: {
187 }
188
190 }
191 }
192}
193
195std::vector<PointGroup_sptr> getAllPointGroups() {
196 auto &pointGroupFactory = PointGroupFactory::Instance();
197 std::vector<std::string> allSymbols = pointGroupFactory.getAllPointGroupSymbols();
198 std::vector<PointGroup_sptr> out;
199 out.reserve(allSymbols.size());
200 std::transform(allSymbols.cbegin(), allSymbols.cend(), std::back_inserter(out),
201 [&pointGroupFactory](const auto &symbol) { return pointGroupFactory.createPointGroup(symbol); });
202 return out;
203}
204
208
209 std::vector<PointGroup_sptr> pointGroups = getAllPointGroups();
210
211 for (auto &pointGroup : pointGroups) {
212 map.emplace(pointGroup->crystalSystem(), pointGroup);
213 }
214
215 return map;
216}
217
219std::string getCrystalSystemAsString(const PointGroup::CrystalSystem &crystalSystem) {
220 switch (crystalSystem) {
222 return "Cubic";
224 return "Tetragonal";
226 return "Hexagonal";
228 return "Trigonal";
230 return "Orthorhombic";
232 return "Monoclinic";
233 default:
234 return "Triclinic";
235 }
236}
237
240PointGroup::CrystalSystem getCrystalSystemFromString(const std::string &crystalSystem) {
241 std::string crystalSystemLC = boost::algorithm::to_lower_copy(crystalSystem);
242
243 if (crystalSystemLC == "cubic") {
245 } else if (crystalSystemLC == "tetragonal") {
247 } else if (crystalSystemLC == "hexagonal") {
249 } else if (crystalSystemLC == "trigonal") {
251 } else if (crystalSystemLC == "orthorhombic") {
253 } else if (crystalSystemLC == "monoclinic") {
255 } else if (crystalSystemLC == "triclinic") {
257 } else {
258 throw std::invalid_argument("Not a valid crystal system: '" + crystalSystem + "'.");
259 }
260}
261
263std::string getLatticeSystemAsString(const PointGroup::LatticeSystem &latticeSystem) {
264 switch (latticeSystem) {
266 return "Cubic";
268 return "Tetragonal";
270 return "Hexagonal";
272 return "Rhombohedral";
274 return "Orthorhombic";
276 return "Monoclinic";
277 default:
278 return "Triclinic";
279 }
280}
281
284PointGroup::LatticeSystem getLatticeSystemFromString(const std::string &latticeSystem) {
285 std::string latticeSystemLC = boost::algorithm::to_lower_copy(latticeSystem);
286
287 if (latticeSystemLC == "cubic") {
289 } else if (latticeSystemLC == "tetragonal") {
291 } else if (latticeSystemLC == "hexagonal") {
293 } else if (latticeSystemLC == "rhombohedral") {
295 } else if (latticeSystemLC == "orthorhombic") {
297 } else if (latticeSystemLC == "monoclinic") {
299 } else if (latticeSystemLC == "triclinic") {
301 } else {
302 throw std::invalid_argument("Not a valid lattice system: '" + latticeSystem + "'.");
303 }
304}
305
307 const PointGroup::CrystalSystem &rhs) const {
308 return static_cast<int>(lhs) < static_cast<int>(rhs);
309}
310
312std::ostream &operator<<(std::ostream &stream, const PointGroup &self) {
313 stream << "Point group with:\n"
314 << "Lattice system: " << getLatticeSystemAsString(self.latticeSystem()) << "\n"
315 << "Crystal system: " << getCrystalSystemAsString(self.crystalSystem()) << "\n"
316 << "Symbol: " << self.getSymbol();
317 return stream;
318}
319
320} // namespace Mantid::Geometry
const std::vector< double > & rhs
The class Group represents a set of symmetry operations (or symmetry group).
Definition: Group.h:135
CoordinateSystem getCoordinateSystem() const
Returns the axis system of the group (either orthogonal or hexagonal).
Definition: Group.cpp:37
std::vector< SymmetryOperation > m_allOperations
Definition: Group.h:173
A class containing the Point Groups for a crystal.
Definition: PointGroup.h:31
PointGroup(const std::string &symbolHM, const Group &group, const std::string &description="")
Protected constructor - can not be used directly.
Definition: PointGroup.cpp:68
bool isEquivalent(const Kernel::V3D &hkl, const Kernel::V3D &hkl2) const
Return true if the hkls are in same group.
Definition: PointGroup.cpp:77
std::string getSymbol() const
Hermann-Mauguin symbol.
Definition: PointGroup.cpp:75
LatticeSystem getLatticeSystemFromCrystalSystemAndGroup(const CrystalSystem &crystalSystem) const
Returns the LatticeSystem of the point group, using the crystal system.
Definition: PointGroup.cpp:170
LatticeSystem latticeSystem() const
Definition: PointGroup.h:44
std::vector< Kernel::V3D > getEquivalents(const Kernel::V3D &hkl) const
Returns a vector with all equivalent hkls.
Definition: PointGroup.cpp:38
CrystalSystem getCrystalSystemFromGroup() const
Returns the CrystalSystem determined from symmetry elements.
Definition: PointGroup.cpp:116
CrystalSystem m_crystalSystem
Definition: PointGroup.h:62
std::vector< Kernel::V3D > getAllEquivalents(const Kernel::V3D &hkl) const
Generates a set of hkls.
Definition: PointGroup.cpp:97
LatticeSystem m_latticeSystem
Definition: PointGroup.h:63
CrystalSystem crystalSystem() const
Definition: PointGroup.h:43
Kernel::V3D getReflectionFamily(const Kernel::V3D &hkl) const
Returns the same hkl for all equivalent hkls.
Definition: PointGroup.cpp:61
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Class for 3D vectors.
Definition: V3D.h:34
MANTID_GEOMETRY_DLL PointGroup::LatticeSystem getLatticeSystemFromString(const std::string &latticeSystem)
Returns the lattice system enum that corresponds to the supplied string or throws an invalid_argument...
Definition: PointGroup.cpp:284
std::multimap< PointGroup::CrystalSystem, PointGroup_sptr, CrystalSystemComparator > PointGroupCrystalSystemMap
Definition: PointGroup.h:91
std::shared_ptr< SymmetryElementWithAxis > SymmetryElementWithAxis_sptr
MANTID_GEOMETRY_DLL std::string getLatticeSystemAsString(const PointGroup::LatticeSystem &latticeSystem)
Returns the supplied LatticeSystem as a string.
Definition: PointGroup.cpp:263
MANTID_GEOMETRY_DLL std::ostream & operator<<(std::ostream &stream, const PointGroup &self)
Returns a streamed representation of the PointGroup object.
Definition: PointGroup.cpp:312
MANTID_GEOMETRY_DLL PointGroup::CrystalSystem getCrystalSystemFromString(const std::string &crystalSystem)
Returns the crystal system enum that corresponds to the supplied string or throws an invalid_argument...
Definition: PointGroup.cpp:240
MANTID_GEOMETRY_DLL std::string getCrystalSystemAsString(const PointGroup::CrystalSystem &crystalSystem)
Return a human-readable string for the given crystal system.
Definition: PointGroup.cpp:219
MANTID_GEOMETRY_DLL std::vector< PointGroup_sptr > getAllPointGroups()
Definition: PointGroup.cpp:195
MANTID_GEOMETRY_DLL PointGroupCrystalSystemMap getPointGroupsByCrystalSystem()
Returns a multimap with crystal system as key and point groups as values.
Definition: PointGroup.cpp:206
Mantid::Kernel::Matrix< int > IntMatrix
Definition: Matrix.h:207
bool operator()(const PointGroup::CrystalSystem &lhs, const PointGroup::CrystalSystem &rhs) const
Definition: PointGroup.cpp:306