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/enum.hpp>
14#include <boost/python/list.hpp>
15#include <boost/python/make_constructor.hpp>
16#include <boost/python/register_ptr_to_python.hpp>
17#include <boost/python/scope.hpp>
18#include <boost/python/stl_iterator.hpp>
19
20using namespace Mantid::Geometry;
23using namespace boost::python;
24
26
27namespace {
28std::vector<std::string> getSymmetryOperationStrings(const Group &self) {
29 const auto &symOps = self.getSymmetryOperations();
30
31 std::vector<std::string> pythonSymOps;
32 pythonSymOps.reserve(symOps.size());
33 std::transform(symOps.cbegin(), symOps.cend(), std::back_inserter(pythonSymOps),
34 [](const auto &symOp) { return symOp.identifier(); });
35
36 return pythonSymOps;
37}
38
39Group_sptr constructGroupFromString(const std::string &initializerString) {
40 return std::const_pointer_cast<Group>(GroupFactory::create<Group>(initializerString));
41}
42
43Group_sptr constructGroupFromVector(const std::vector<SymmetryOperation> &symOps) {
44 return std::const_pointer_cast<Group>(GroupFactory::create<Group>(symOps));
45}
46
47Group_sptr constructGroupFromPythonList(const boost::python::list &symOpList) {
48 std::vector<SymmetryOperation> operations;
49
50 for (int i = 0; i < len(symOpList); ++i) {
51 operations.emplace_back(boost::python::extract<SymmetryOperation>(symOpList[i]));
52 }
53
54 return std::const_pointer_cast<Group>(GroupFactory::create<Group>(operations));
55}
56
57bool isInvariantDefault(const Group &self, const boost::python::object &tensor) {
58 return self.isInvariant(PyObjectToMatrix(tensor)());
59}
60
61bool isInvariantTolerance(const Group &self, const boost::python::object &tensor, double tolerance) {
62 return self.isInvariant(PyObjectToMatrix(tensor)(), tolerance);
63}
64} // namespace
65
67
68 register_ptr_to_python<std::shared_ptr<Group>>();
69
70 enum_<Group::CoordinateSystem>("CoordinateSystem")
71 .value("Orthogonal", Group::Orthogonal)
72 .value("Hexagonal", Group::Hexagonal);
73
74 enum_<Group::GroupAxiom>("GroupAxiom")
75 .value("Closure", Group::Closure)
76 .value("Identity", Group::Identity)
77 .value("Inversion", Group::Inversion)
78 .value("Associativity", Group::Associativity);
79
80 class_<Group, boost::noncopyable>("Group", no_init)
81 .def("__init__",
82 make_constructor(&constructGroupFromString, default_call_policies(), (arg("symmetryOperationString"))),
83 "Construct a group from the provided initializer string.")
84 .def("__init__",
85 make_constructor(&constructGroupFromVector, default_call_policies(), (arg("symmetryOperationVector"))),
86 "Construct a group from the provided symmetry operation list.")
87 .def("__init__",
88 make_constructor(&constructGroupFromPythonList, default_call_policies(), (arg("symmetryOperationList"))),
89 "Construct a group from a python generated symmetry operation list.")
90 .def("getOrder", &Group::order, arg("self"), "Returns the order of the group.")
91 .def("getCoordinateSystem", &Group::getCoordinateSystem, arg("self"),
92 "Returns the type of coordinate system to distinguish groups with "
93 "hexagonal system definition.")
94 .def("getSymmetryOperations", &Group::getSymmetryOperations, arg("self"),
95 "Returns the symmetry operations contained in the group.")
96 .def("getSymmetryOperationStrings", &getSymmetryOperationStrings, arg("self"),
97 "Returns the x,y,z-strings for the contained symmetry operations.")
98 .def("containsOperation", &Group::containsOperation, (arg("self"), arg("operation")),
99 "Checks whether a SymmetryOperation is included in Group.")
100
101 .def("isInvariant", &isInvariantDefault, (arg("self"), arg("tensor")),
102 "Returns true if the tensor is not changed by the group's symmetry "
103 "operations with a tolerance of 1e-8.")
104 .def("isInvariant", &isInvariantTolerance, (arg("self"), arg("tensor"), arg("tolerance")),
105 "Returns true if the tensor is not changed by the group's symmetry "
106 "operations with the given tolerance.")
107 .def("isGroup", &Group::isGroup, arg("self"),
108 "Checks whether the contained symmetry "
109 "operations fulfill the group axioms.")
110 .def("fulfillsAxiom", &Group::fulfillsAxiom, (arg("self"), arg("axiom")),
111 "Checks if the contained symmetry operations fulfill the specified "
112 "group axiom.");
113}
#define GET_POINTER_SPECIALIZATION(TYPE)
Definition: GetPointer.h:17
void export_Group()
Definition: Group.cpp:66
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
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...