Mantid
Loading...
Searching...
No Matches
Group.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 +
10
11#include <algorithm>
12#include <boost/python/class.hpp>
13#include <boost/python/copy_const_reference.hpp>
14#include <boost/python/enum.hpp>
15#include <boost/python/list.hpp>
16#include <boost/python/make_constructor.hpp>
17#include <boost/python/register_ptr_to_python.hpp>
18#include <boost/python/scope.hpp>
19#include <boost/python/stl_iterator.hpp>
20
21using namespace Mantid::Geometry;
24using namespace boost::python;
25
27
28namespace {
29std::vector<std::string> getSymmetryOperationStrings(const Group &self) {
30 const auto &symOps = self.getSymmetryOperations();
31
32 std::vector<std::string> pythonSymOps;
33 pythonSymOps.reserve(symOps.size());
34 std::transform(symOps.cbegin(), symOps.cend(), std::back_inserter(pythonSymOps),
35 [](const auto &symOp) { return symOp.identifier(); });
36
37 return pythonSymOps;
38}
39
40Group_sptr constructGroupFromString(const std::string &initializerString) {
41 return std::const_pointer_cast<Group>(GroupFactory::create<Group>(initializerString));
42}
43
44Group_sptr constructGroupFromVector(const std::vector<SymmetryOperation> &symOps) {
45 return std::const_pointer_cast<Group>(GroupFactory::create<Group>(symOps));
46}
47
48Group_sptr constructGroupFromPythonList(const boost::python::list &symOpList) {
49 std::vector<SymmetryOperation> operations;
50
51 for (int i = 0; i < len(symOpList); ++i) {
52 operations.emplace_back(boost::python::extract<SymmetryOperation>(symOpList[i]));
53 }
54
55 return std::const_pointer_cast<Group>(GroupFactory::create<Group>(operations));
56}
57
58bool isInvariantDefault(const Group &self, const boost::python::object &tensor) {
59 return self.isInvariant(PyObjectToMatrix(tensor)());
60}
61
62bool isInvariantTolerance(const Group &self, const boost::python::object &tensor, double tolerance) {
63 return self.isInvariant(PyObjectToMatrix(tensor)(), tolerance);
64}
65} // namespace
66
68
69 register_ptr_to_python<std::shared_ptr<Group>>();
70
71 enum_<Group::CoordinateSystem>("CoordinateSystem")
72 .value("Orthogonal", Group::Orthogonal)
73 .value("Hexagonal", Group::Hexagonal);
74
75 enum_<Group::GroupAxiom>("GroupAxiom")
76 .value("Closure", Group::Closure)
77 .value("Identity", Group::Identity)
78 .value("Inversion", Group::Inversion)
79 .value("Associativity", Group::Associativity);
80
81 class_<Group, boost::noncopyable>("Group", no_init)
82 .def("__init__",
83 make_constructor(&constructGroupFromString, default_call_policies(), (arg("symmetryOperationString"))),
84 "Construct a group from the provided initializer string.")
85 .def("__init__",
86 make_constructor(&constructGroupFromVector, default_call_policies(), (arg("symmetryOperationVector"))),
87 "Construct a group from the provided symmetry operation list.")
88 .def("__init__",
89 make_constructor(&constructGroupFromPythonList, default_call_policies(), (arg("symmetryOperationList"))),
90 "Construct a group from a python generated symmetry operation list.")
91 .def("getOrder", &Group::order, arg("self"), "Returns the order of the group.")
92 .def("getCoordinateSystem", &Group::getCoordinateSystem, arg("self"),
93 "Returns the type of coordinate system to distinguish groups with "
94 "hexagonal system definition.")
95 .def("getSymmetryOperations", &Group::getSymmetryOperations, arg("self"),
96 return_value_policy<copy_const_reference>(), "Returns the symmetry operations contained in the group.")
97 .def("getSymmetryOperationStrings", &getSymmetryOperationStrings, arg("self"),
98 "Returns the x,y,z-strings for the contained symmetry operations.")
99 .def("containsOperation", &Group::containsOperation, (arg("self"), arg("operation")),
100 "Checks whether a SymmetryOperation is included in Group.")
101
102 .def("isInvariant", &isInvariantDefault, (arg("self"), arg("tensor")),
103 "Returns true if the tensor is not changed by the group's symmetry "
104 "operations with a tolerance of 1e-8.")
105 .def("isInvariant", &isInvariantTolerance, (arg("self"), arg("tensor"), arg("tolerance")),
106 "Returns true if the tensor is not changed by the group's symmetry "
107 "operations with the given tolerance.")
108 .def("isGroup", &Group::isGroup, arg("self"),
109 "Checks whether the contained symmetry "
110 "operations fulfill the group axioms.")
111 .def("fulfillsAxiom", &Group::fulfillsAxiom, (arg("self"), arg("axiom")),
112 "Checks if the contained symmetry operations fulfill the specified "
113 "group axiom.");
114}
#define GET_POINTER_SPECIALIZATION(TYPE)
Definition GetPointer.h:17
void export_Group()
Definition Group.cpp:67
double tolerance
The class Group represents a set of symmetry operations (or symmetry group).
Definition Group.h:135
bool isGroup() const
Returns whether the group fulfills the four group axioms.
Definition Group.cpp:161
bool isInvariant(const Kernel::DblMatrix &tensor, double tolerance=1e-8) const
Returns true if the tensor is invariant under the group operations.
Definition Group.cpp:117
const std::vector< SymmetryOperation > & getSymmetryOperations() const
Returns a vector with all symmetry operations.
Definition Group.cpp:40
CoordinateSystem getCoordinateSystem() const
Returns the axis system of the group (either orthogonal or hexagonal).
Definition Group.cpp:37
bool fulfillsAxiom(GroupAxiom axiom) const
Checks whether a certain group axiom is fulfilled, can be used as a more fine-grained alternative to ...
Definition Group.cpp:135
bool containsOperation(const SymmetryOperation &operation) const
Returns true if the group contains the supplied operation.
Definition Group.cpp:43
size_t order() const
Returns the order of the group, which is the number of symmetry operations.
Definition Group.cpp:34
Crystallographic symmetry operations are composed of a rotational component, which is represented by ...
std::shared_ptr< Group > Group_sptr
Definition Group.h:178
Takes a Python object and if it supports indexing and is two dimensional it attempts to convert it to...