Molassembler  1.0.0
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
PointGroupElements.h
Go to the documentation of this file.
1 
8 #ifndef INCLUDE_MOLASSEMBLER_SHAPES_POINT_GROUP_ELEMENTS_H
9 #define INCLUDE_MOLASSEMBLER_SHAPES_POINT_GROUP_ELEMENTS_H
10 
12 
13 #include <Eigen/Core>
14 #include "boost/optional/optional_fwd.hpp"
16 
17 #include <vector>
18 #include <unordered_map>
19 #include <memory>
20 
21 namespace Scine {
22 namespace Molassembler {
23 namespace Shapes {
24 
26 namespace Elements {
27 
29 struct MASM_EXPORT SymmetryElement {
30  using Vector = Eigen::Vector3d;
31  using Matrix = Eigen::Matrix3d;
32  using Ptr = std::unique_ptr<SymmetryElement>;
33 
34  virtual ~SymmetryElement() = default;
35 
37  virtual Matrix matrix() const = 0;
39  virtual boost::optional<Vector> vector() const = 0;
41  virtual std::string name() const = 0;
42 };
43 
45 struct MASM_EXPORT Identity final : public SymmetryElement {
46  static Identity E();
47 
48  Matrix matrix() const final;
49  boost::optional<Vector> vector() const final;
50  std::string name() const final;
51 };
52 
54 struct MASM_EXPORT Inversion final : public SymmetryElement {
55  static Inversion i();
56 
57  Matrix matrix() const final;
58  boost::optional<Vector> vector() const final;
59  std::string name() const final;
60 };
61 
63 struct MASM_EXPORT Rotation final : public SymmetryElement {
64  Rotation(
65  const Eigen::Vector3d& passAxis,
66  unsigned passN,
67  unsigned passPower,
68  bool passReflect
69  );
70 
72  static Rotation Cn(const Eigen::Vector3d& axis, unsigned n, unsigned power = 1);
73  static inline Rotation Cn_z(const unsigned n, const unsigned power = 1) {
74  return Cn(Eigen::Vector3d::UnitZ(), n, power);
75  }
77  static Rotation Sn(const Eigen::Vector3d& axis, unsigned n, unsigned power = 1);
78 
80  Rotation operator * (const Rotation& rhs) const;
81 
82  Matrix matrix() const final;
83  boost::optional<Vector> vector() const final;
84  std::string name() const final;
85 
87  Eigen::Vector3d axis;
89  unsigned n;
91  unsigned power;
93  bool reflect;
94 
95  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
96 };
97 
99 struct MASM_EXPORT Reflection final : public SymmetryElement {
100  Reflection(const Eigen::Vector3d& passNormal);
101 
102  static Reflection sigma_xy();
103  static Reflection sigma_xz();
104  static Reflection sigma_yz();
105 
106  Matrix matrix() const final;
107  boost::optional<Vector> vector() const final;
108  std::string name() const final;
109 
111  Eigen::Vector3d normal;
112 
113  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
114 };
115 
116 /* Mixed operators (WARNING: Can only handle case for which rotation axis is
117  * collinear with reflection plane normal)
118  */
119 MASM_EXPORT Rotation operator * (const Rotation& rot, const Reflection& reflection);
120 MASM_EXPORT Rotation operator * (const Reflection& reflection, const Rotation& rot);
121 
123 using ElementsList = std::vector<std::unique_ptr<SymmetryElement>>;
124 
138 PURITY_WEAK MASM_EXPORT ElementsList symmetryElements(PointGroup group) noexcept;
139 
141 PURITY_STRONG MASM_EXPORT unsigned order(PointGroup group);
142 
143 struct MASM_EXPORT ElementGrouping {
144  using ElementIndexGroups = std::vector<std::vector<unsigned>>;
145 
146  Eigen::Vector3d probePoint;
147  ElementIndexGroups groups;
148 
149  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
150 };
151 
158 using NpGroupingsMapType = std::unordered_map<
159  unsigned,
160  std::vector<ElementGrouping>,
161  std::hash<unsigned>,
162  std::equal_to<>,
163  Eigen::aligned_allocator<std::pair<const unsigned, std::vector<ElementGrouping>>>
164 >;
165 
174 MASM_EXPORT NpGroupingsMapType npGroupings(const ElementsList& elements);
175 
176 } // namespace Elements
177 } // namespace Shapes
178 } // namespace Molassembler
179 } // namespace Scine
180 
181 #endif
unsigned n
Rotation order.
Definition: PointGroupElements.h:89
#define PURITY_WEAK
Definition: Preprocessor.h:36
unsigned power
Power of the symmetry element (i.e. C3^2 is a rotation by 240°)
Definition: PointGroupElements.h:91
Eigen::Vector3d axis
Axis of rotation.
Definition: PointGroupElements.h:87
Point group enum.
PURITY_STRONG unsigned order(PointGroup group)
Returns the number of symmetry elements in a point group.
Base class for symmetry elements.
Definition: PointGroupElements.h:29
PointGroup
Point groups.
Definition: PointGroups.h:20
NpGroupingsMapType npGroupings(const ElementsList &elements)
Generate all groupings of symmetry elements for those points in space for which some symmetry element...
Defines a set of useful preprocessor macros.
PURITY_WEAK ElementsList symmetryElements(PointGroup group) noexcept
Lists all symmetry elements for a point group.
i symmetry element
Definition: PointGroupElements.h:54
Abstraction of Cn and Sn symmetry elements.
Definition: PointGroupElements.h:63
E symmetry element.
Definition: PointGroupElements.h:45
bool reflect
Proper rotations reflect, improper rotations do not.
Definition: PointGroupElements.h:93
Definition: PointGroupElements.h:143
std::vector< std::unique_ptr< SymmetryElement >> ElementsList
Heterogeneous list of symmetry elements.
Definition: PointGroupElements.h:123
#define PURITY_STRONG
Definition: Preprocessor.h:65
std::unordered_map< unsigned, std::vector< ElementGrouping >, std::hash< unsigned >, std::equal_to<>, Eigen::aligned_allocator< std::pair< const unsigned, std::vector< ElementGrouping >>> > NpGroupingsMapType
Definition: PointGroupElements.h:164
const std::string & name(const Shape shape)
Fetch the string name of a shape.
Eigen::Vector3d normal
Normal of the reflection plane.
Definition: PointGroupElements.h:111
Reflection by a plane symmetry element.
Definition: PointGroupElements.h:99