CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
UnitCellCoord.hh
Go to the documentation of this file.
1 #ifndef UNITCELLCOORD_HH
2 #define UNITCELLCOORD_HH
3 
4 #include <iostream>
5 
6 #include "casm/external/Eigen/Dense"
7 
9 
11 
13 
14 namespace CASM {
15 
20  class UnitCell : public Eigen::Vector3l {
26  public:
27 
28  UnitCell(void) : Eigen::Vector3l() {}
29 
30  UnitCell(Index a, Index b, Index c) : Eigen::Vector3l(a, b, c) {}
31 
32  // This constructor allows you to construct MyVectorType from Eigen expressions
33  template<typename OtherDerived>
34  UnitCell(const Eigen::MatrixBase<OtherDerived> &other) :
35  Eigen::Vector3l(other) {}
36 
37  // This method allows you to assign Eigen expressions to MyVectorType
38  template<typename OtherDerived>
39  UnitCell &operator=(const Eigen::MatrixBase <OtherDerived> &other) {
40  this->Eigen::Vector3l::operator=(other);
41  return *this;
42  }
43  };
44 
45  /* -- UnitCellCoord Declarations ------------------------------------- */
46 
51  class UnitCellCoord {
52 
53  public:
54 
56 
57  UnitCellCoord(Index _sublat, const UnitCell &_unitcell);
58 
59  UnitCellCoord(Index _sublat, Index i, Index j, Index k);
60 
62  template<typename CoordType, typename StrucType>
63  UnitCellCoord(CoordType coord, const StrucType &struc, double tol);
64 
65  UnitCell &unitcell();
66  const UnitCell &unitcell() const;
67 
68  Index &unitcell(Index i);
69  const Index &unitcell(Index i) const;
70 
71  Index &sublat();
72  const Index &sublat() const;
73 
75  const Index &operator[](Index i) const;
76 
78 
80 
81 
82  private:
83 
86 
87  };
88 
89  inline std::ostream &operator<<(std::ostream &sout, const UnitCellCoord &site) {
90  return sout << site.sublat() << ", " << site.unitcell().transpose();
91  }
92 
94  inline UnitCellCoord operator+(UnitCell frac, UnitCellCoord site);
95 
97  inline UnitCellCoord operator+(UnitCellCoord site, UnitCell frac);
98 
100  inline UnitCellCoord operator-(UnitCellCoord site, UnitCell frac);
101 
103  inline bool operator<(const UnitCellCoord &A, const UnitCellCoord &B);
104 
106  inline bool operator>(const UnitCellCoord &A, const UnitCellCoord &B);
107 
109  inline bool operator<=(const UnitCellCoord &A, const UnitCellCoord &B);
110 
112  inline bool operator>=(const UnitCellCoord &A, const UnitCellCoord &B);
113 
115  inline bool operator==(const UnitCellCoord &A, const UnitCellCoord &B);
116 
118  inline bool operator!=(const UnitCellCoord &A, const UnitCellCoord &B);
119 
121  jsonParser &to_json(const UnitCellCoord &ucc_val, jsonParser &fill_json);
122 
124  void from_json(UnitCellCoord &fill_value, const jsonParser &read_json);
125 
126 
127  /* -- UnitCellCoord Definitions ------------------------------------- */
128 
129  inline UnitCellCoord::UnitCellCoord(Index _sublat, const UnitCell &_unitcell) :
130  m_unitcell(_unitcell),
131  m_sublat(_sublat) {}
132 
134  m_unitcell(i, j, k),
135  m_sublat(_sublat) {}
136 
138  template<typename CoordType, typename StrucType>
139  UnitCellCoord::UnitCellCoord(CoordType coord, const StrucType &struc, double tol) {
140  for(Index b = 0; b < struc.basis.size(); ++b) {
141  //auto diff = coord - struc.basis[b];
142  //if(is_integer(diff.const_frac(), tol)) { // <-- doesn't work if sites are coincident
143  if(struc.basis[b].compare(coord, tol)) {
144  *this = UnitCellCoord(b, lround((coord - struc.basis[b]).const_frac()));
145  return;
146  }
147  }
148 
149  throw std::runtime_error(
150  "Error in 'UnitCellCoord(CoordType coord, const StrucType& struc, double tol)'\n"
151  " No matching basis site found.");
152  }
153 
155  return m_unitcell;
156  }
157 
158  inline const UnitCell &UnitCellCoord::unitcell() const {
159  return m_unitcell;
160  }
161 
163  return m_unitcell[i];
164  }
165 
166  inline const Index &UnitCellCoord::unitcell(Index i) const {
167  return m_unitcell[i];
168  }
169 
171  return m_sublat;
172  }
173 
174  inline const Index &UnitCellCoord::sublat() const {
175  return m_sublat;
176  }
177 
179  if(i == 0) {
180  return m_sublat;
181  }
182  return unitcell(i - 1);
183  }
184 
185  inline const Index &UnitCellCoord::operator[](Index i) const {
186  if(i == 0) {
187  return m_sublat;
188  }
189  return unitcell(i - 1);
190  }
191 
193  m_unitcell += frac;
194  return *this;
195  }
196 
198  m_unitcell -= frac;
199  return *this;
200  }
201 
204  return site += frac;
205  }
206 
209  return site += frac;
210  }
211 
214  return site -= frac;
215  }
216 
218  inline bool operator<(const UnitCellCoord &A, const UnitCellCoord &B) {
219  for(Index i = 0; i < 3; i++) {
220  if(A.unitcell()(i) < B.unitcell()(i)) {
221  return true;
222  }
223  if(A.unitcell()(i) > B.unitcell()(i)) {
224  return false;
225  }
226  }
227  if(A.sublat() < B.sublat()) {
228  return true;
229  }
230 
231  return false;
232  }
233 
235  inline bool operator>(const UnitCellCoord &A, const UnitCellCoord &B) {
236  return B < A;
237  }
238 
240  inline bool operator<=(const UnitCellCoord &A, const UnitCellCoord &B) {
241  return !(A > B);
242  }
243 
245  inline bool operator>=(const UnitCellCoord &A, const UnitCellCoord &B) {
246  return !(A < B);
247  }
248 
249  inline bool operator==(const UnitCellCoord &A, const UnitCellCoord &B) {
250  return A.unitcell()(0) == B.unitcell()(0) &&
251  A.unitcell()(1) == B.unitcell()(1) &&
252  A.unitcell()(2) == B.unitcell()(2) &&
253  A.sublat() == B.sublat();
254  }
255 
257  inline bool operator!=(const UnitCellCoord &A, const UnitCellCoord &B) {
258  return !(A == B);
259  }
260 
261 
263  inline jsonParser &to_json(const UnitCellCoord &ucc_val, jsonParser &fill_json) {
264  fill_json.put_array();
265  fill_json.push_back(ucc_val.sublat());
266  fill_json.push_back(ucc_val.unitcell()(0));
267  fill_json.push_back(ucc_val.unitcell()(1));
268  fill_json.push_back(ucc_val.unitcell()(2));
269 
270  return fill_json;
271  }
272 
274  inline void from_json(UnitCellCoord &fill_value, const jsonParser &read_json) {
275 
276  fill_value.sublat() = read_json[0].get<Index>();
277  fill_value.unitcell()(0) = read_json[1].get<Index>();
278  fill_value.unitcell()(1) = read_json[2].get<Index>();
279  fill_value.unitcell()(2) = read_json[3].get<Index>();
280 
281  return;
282  }
283 
285 }
286 #endif
287 
288 
289 
290 
291 
void from_json(ClexDescription &desc, const jsonParser &json)
Matrix< long int, 3, 1 > Vector3l
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
UnitCellCoord & operator+=(UnitCell frac)
bool operator>(const UnitCellCoord &A, const UnitCellCoord &B)
Compare UnitCellCoord.
bool operator<(const ClexDescription &A, const ClexDescription &B)
Compare using name strings: A.name < B.name.
Unit Cell Coordinates.
bool operator<=(const UnitCellCoord &A, const UnitCellCoord &B)
Compare UnitCellCoord.
Main CASM namespace.
Definition: complete.cpp:8
Index & operator[](Index i)
Unit Cell Indices.
UnitCell(const Eigen::MatrixBase< OtherDerived > &other)
bool operator>=(const UnitCellCoord &A, const UnitCellCoord &B)
Compare UnitCellCoord.
GenericCluster< CoordType > operator+(const GenericCluster< CoordType > &LHS, const Coordinate &RHS)
create translated cluster
T get(Args...args) const
Get data from json, using one of several alternatives.
Definition: jsonParser.hh:729
bool operator!=(const UnitCellCoord &A, const UnitCellCoord &B)
Compare UnitCellCoord.
GenericCluster< CoordType > operator-(const GenericCluster< CoordType > &LHS, const Coordinate &RHS)
create translated cluster
double tol
std::ostream & operator<<(std::ostream &_stream, const FormattedPrintable &_formatted)
bool operator==(const UnitCellCoord &A, const UnitCellCoord &B)
Compare UnitCellCoord.
UnitCell(Index a, Index b, Index c)
EigenIndex Index
For long integer indexing:
UnitCellCoord & operator-=(UnitCell frac)
Eigen::CwiseUnaryOp< decltype(std::ptr_fun(boost::math::lround< typename Derived::Scalar >)), const Derived > lround(const Eigen::MatrixBase< Derived > &val)
Round Eigen::MatrixXd to Eigen::MatrixXl.
UnitCell & operator=(const Eigen::MatrixBase< OtherDerived > &other)
UnitCell & unitcell()
jsonParser & push_back(const T &value)
Puts new valued element at end of array of any type T for which 'jsonParser& to_json( const T &value...
Definition: jsonParser.hh:696
jsonParser & put_array()
Puts new empty JSON array.
Definition: jsonParser.hh:285