CASM  1.1.0
A Clusters Approach to Statistical Mechanics
OrbitGeneration_impl.hh
Go to the documentation of this file.
1 #ifndef CASM_OrbitGeneration_impl
2 #define CASM_OrbitGeneration_impl
3 
6 
7 namespace CASM {
8 
9 template <typename _OrbitType>
11  const SymCompareType &_sym_compare)
12  : group(_group),
13  sym_compare(_sym_compare),
14  m_element_compare(sym_compare),
15  m_generate_canonical(group, sym_compare),
16  elements(m_element_compare) {}
17 
19 template <typename _OrbitType>
20 std::pair<typename OrbitGeneratorSet<_OrbitType>::iterator, bool>
22  return elements.insert(m_generate_canonical(test));
23 }
24 
26 template <typename _OrbitType>
27 std::pair<typename OrbitGeneratorSet<_OrbitType>::iterator, bool>
29  return elements.insert(test);
30 }
31 
33 template <typename _OrbitType>
34 template <typename OrbitOutputIterator>
36  OrbitOutputIterator result) {
37  for (const auto &e : elements) {
38  *result++ = OrbitType(e, group, sym_compare);
39  }
40  return result;
41 }
42 
43 // /// \brief Construct Orbit from all generating elements, including PrimClex
44 // /// pointer
45 // template <typename _OrbitType>
46 // template <typename OrbitOutputIterator>
47 // OrbitOutputIterator OrbitGenerators<_OrbitType>::make_orbits(
48 // OrbitOutputIterator result, const PrimClex &primclex) {
49 // for (const auto &e : elements) {
50 // *result++ = OrbitType(e, group, sym_compare, &primclex);
51 // }
52 // return result;
53 // }
54 
55 template <typename SymCompareType>
56 std::vector<Orbit<SymCompareType>> generate_orbits(
57  std::vector<typename SymCompareType::Element> const &generating_elements,
58  SymGroup const &generating_group, SymCompareType const &sym_compare) {
59  typedef Orbit<SymCompareType> OrbitType;
60  OrbitGenerators<OrbitType> generators(generating_group, sym_compare);
61  for (auto const &el : generating_elements) {
62  generators.insert(el);
63  }
64  std::vector<Orbit<SymCompareType>> orbits;
65  orbits.reserve(generating_elements.size());
66  generators.make_orbits(std::back_inserter(orbits));
67  return orbits;
68 }
69 
70 // --- template<typename _OrbitType> class OrbitGeneratorCompare ---
71 
72 template <typename _OrbitType>
74  const SymCompareType &_sym_compare)
75  : sym_compare(_sym_compare) {}
76 
77 template <typename _OrbitType>
79  const Element &B) const {
80  auto A_invariants = sym_compare.make_invariants(A);
81  auto B_invariants = sym_compare.make_invariants(B);
82  return sym_compare.inter_orbit_compare(A, A_invariants, B, B_invariants);
83 }
84 
85 // --- template<typename _OrbitType> class CanonicalGenerator ---
86 
87 template <typename _OrbitType>
89  const std::vector<SymOp> &_generating_group,
90  const SymCompareType &_sym_compare)
91  : generating_group(_generating_group),
92  sym_compare(_sym_compare),
93  m_to_canonical(nullptr) {}
94 
96 template <typename _OrbitType>
99  Element result = sym_compare.prepare(e);
100  for (const auto &op : generating_group) {
101  auto test = sym_compare.prepare(sym_compare.copy_apply(op, e));
102  if (sym_compare.compare(result, test)) {
103  result = test;
104  m_to_canonical = &op;
105  }
106  }
107  return result;
108 }
109 
111 template <typename _OrbitType>
113  return *m_to_canonical;
114 }
115 
117 template <typename _OrbitType>
119  return to_canonical().inverse();
120 }
121 
122 // // --- template<typename _SymCompareType> class PermuteCanonicalGenerator ---
123 //
124 // template<typename _SymCompareType>
125 // PermuteCanonicalGenerator<_SymCompareType>::PermuteCanonicalGenerator(
126 // PermuteIterator _permute_begin,
127 // PermuteIterator _permute_end,
128 // SymCompareType const &_sym_compare) :
129 // permute_begin(_permute_begin),
130 // permute_end(_permute_end),
131 // sym_compare(_sym_compare),
132 // m_to_canonical(nullptr) {}
133 //
134 // /// \brief Applies symmetry to return an equivalent Element in a canonical
135 // form template<typename _SymCompareType> typename
136 // PermuteCanonicalGenerator<_SymCompareType>::Element
137 // PermuteCanonicalGenerator<_SymCompareType>::operator()(Element const &e)
138 // const {
139 // Element result = sym_compare.prepare(e);
140 // for(auto permute_it = permute_begin; permute_it != permute_end;
141 // ++permute_it) {
142 // auto test =
143 // sym_compare.prepare(sym_compare.copy_apply(permute_it.sym_op(), e));
144 // if(sym_compare.compare(result, test)) {
145 // result = test;
146 // m_to_canonical = &permute_it;
147 // }
148 // }
149 // return result;
150 // }
151 //
152 // /// \brief After using call operator, this can be checked
153 // template<typename _SymCompareType>
154 // PermuteIterator const
155 // &PermuteCanonicalGenerator<_SymCompareType>::to_canonical() const {
156 // return *m_to_canonical;
157 // }
158 //
159 // /// \brief After using call operator, this can be checked
160 // template<typename _SymCompareType>
161 // PermuteIterator const
162 // &PermuteCanonicalGenerator<_SymCompareType>::from_canonical() const {
163 // return to_canonical().inverse();
164 // }
165 
166 // --- template<typename _OrbitType> class IsCanonical<_OrbitType> ---
167 
168 template <typename _OrbitType>
170  const std::vector<SymOp> &_generating_group,
171  const SymCompareType &_sym_compare)
172  : generating_group(_generating_group), sym_compare(_sym_compare) {}
173 
175 template <typename _OrbitType>
177  return std::none_of(
178  generating_group.begin(), generating_group.end(), [&](const SymOp &op) {
179  auto test = sym_compare.prepare(sym_compare.copy_apply(op, e));
180  return sym_compare.compare(e, test);
181  });
182 }
183 
184 } // namespace CASM
185 
186 #endif
An Orbit of Element.
Definition: Orbit.hh:43
SymGroup is a collection of symmetry operations that satisfy the group property The symmetry operatio...
Definition: SymGroup.hh:42
SymOp is the Coordinate representation of a symmetry operation it keeps fraction (FRAC) and Cartesian...
Definition: SymOp.hh:28
SymOp inverse() const
get the inverse of this SymOp
Definition: SymOp.cc:87
Main CASM namespace.
Definition: APICommand.hh:8
std::vector< Orbit< SymCompareType > > generate_orbits(std::vector< typename SymCompareType::Element > const &generating_elements, SymGroup const &generating_group, SymCompareType const &sym_compare)
Construct orbits from a vector of generating elements.
const SymOp & from_canonical() const
After using call operator, this can be checked.
OrbitType::Element Element
const SymOp & to_canonical() const
After using call operator, this can be checked.
CanonicalGenerator(const std::vector< SymOp > &_generating_group, const SymCompareType &_sym_compare)
OrbitType::SymCompareType SymCompareType
Element operator()(const Element &e) const
Applies symmetry to return an equivalent Element in a canonical form.
OrbitType::SymCompareType SymCompareType
OrbitType::Element Element
IsCanonical(const std::vector< SymOp > &_generating_group, const SymCompareType &_sym_compare)
bool operator()(const Element &e) const
Applies symmetry to check if any Element is greater than e.
OrbitGeneratorCompare(const SymCompareType &_sym_compare)
OrbitType::Element Element
bool operator()(const Element &A, const Element &B) const
OrbitType::SymCompareType SymCompareType
Data structure that holds canonical generating elements and can then make sorted orbits.
OrbitOutputIterator make_orbits(OrbitOutputIterator result)
Construct Orbit from all generating elements.
std::pair< typename OrbitGeneratorSet< OrbitType >::iterator, bool > insert(const Element &test)
Try inserting an element, after generating the canonical form.
OrbitType::SymCompareType SymCompareType
OrbitGenerators(const SymGroup &_group, const SymCompareType &_sym_compare)
std::pair< typename OrbitGeneratorSet< OrbitType >::iterator, bool > insert_canonical(const Element &test)
Try inserting an element, assuming it is in canonical form.
OrbitType::Element Element