CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
Lattice.hh
Go to the documentation of this file.
1 #ifndef LATTICE_HH
2 #define LATTICE_HH
3 
4 #include <iostream>
5 #include <cmath>
6 
11 
12 namespace CASM {
13  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15  class SymGroup;
16  class SymOp;
17  class ScelEnumProps;
18 
31  class Lattice : public Comparisons<Lattice> {
32  public:
33  typedef Eigen::Matrix3d::ColXpr LatVec;
34  typedef Eigen::Matrix3d::ConstColXpr ConstLatVec;
35 
36  Lattice(const Eigen::Vector3d &vec1, const Eigen::Vector3d &vec2,
37  const Eigen::Vector3d &vec3);
38 
41  Lattice(const Eigen::Ref<const Eigen::Matrix3d> &lat_mat = Eigen::Matrix3d::Identity());
42 
44  static Lattice fcc();
45 
47  static Lattice bcc();
48 
50  static Lattice cubic();
51 
53  static Lattice hexagonal();
54 
56  LatVec operator[](Index i) {
57  return m_lat_mat.col(i);
58  }
59 
61  ConstLatVec operator[](Index i)const {
62  return m_lat_mat.col(i);
63  }
64 
65  std::tuple<LatVec, LatVec, LatVec> vectors() {
66  return std::make_tuple(m_lat_mat.col(0), m_lat_mat.col(1), m_lat_mat.col(2));
67  }
68 
69  std::tuple<ConstLatVec, ConstLatVec, ConstLatVec> vectors() const {
70  return std::make_tuple(m_lat_mat.col(0), m_lat_mat.col(1), m_lat_mat.col(2));
71  }
72 
74  Lattice scaled_lattice(double scale) const;
75 
77  double angle(Index i)const;
78 
80  double length(Index i)const;
81 
83  double vol()const {
84  return lat_column_mat().determinant();
85  }
86 
90  Eigen::MatrixXd const &voronoi_table() const {
91  if(!m_voronoi_table.size()) {
93  }
94  return m_voronoi_table;
95  }
96 
98  double inner_voronoi_radius() const {
99  voronoi_table();
100  return m_inner_voronoi_radius;
101  }
102 
105  return m_lat_mat;
106  }
107 
114  return m_inv_lat_mat;
115  }
116 
119  Array<int> calc_kpoints(Array<int> prim_kpoints, Lattice prim_lat);
120 
122  Lattice get_reciprocal() const;
123 
128  void generate_point_group(SymGroup &point_group, double pg_tol = TOL) const;
129 
131  template<typename SymOpIterator, typename SymOpOutputIterator>
132  SymOpOutputIterator find_invariant_subgroup(SymOpIterator begin, SymOpIterator end, SymOpOutputIterator result, double pg_tol = TOL) const;
133 
136  void find_invariant_subgroup(const SymGroup &super_group, SymGroup &sub_group, double pg_tol = TOL) const;
137 
138 
140  bool is_canonical(double tol = TOL) const;
141 
143  bool is_canonical(const SymGroup &pg, double tol = TOL) const;
144 
146  SymOp to_canonical(double tol = TOL) const;
147 
149  SymOp to_canonical(const SymGroup &pg, double tol = TOL) const;
150 
152  SymOp from_canonical(double tol = TOL) const;
153 
155  SymOp from_canonical(const SymGroup &pg, double tol = TOL) const;
156 
158  Lattice canonical_form(double tol = TOL) const;
159 
161  Lattice canonical_form(const SymGroup &pg, double tol = TOL) const;
162 
163 
168  void generate_supercells(Array<Lattice> &supercell, const SymGroup &effective_pg, const ScelEnumProps &enum_props) const;
169 
172  template <typename T>
173  Lattice make_supercell(const Eigen::Matrix<T, 3, 3> &trans_mat) const;
174 
177  Lattice get_reduced_cell() const;
178 
179  void print_voronoi_table(std::ostream &stream) const;
180 
182  double min_voronoi_radius() const;
183 
189  double max_voronoi_measure(const Eigen::Vector3d &pos, Eigen::Vector3d &lattice_trans) const;
190 
195  int voronoi_number(const Eigen::Vector3d &pos) const;
196 
199  Eigen::Vector3i enclose_sphere(double radius) const;
200 
202  // ***This should live somewhere else
203  template<typename CoordType, typename CoordType2>
204  Array<CoordType> gridstruc_build(double max_radius, double min_radius, Array<CoordType> basis, CoordType2 lat_point);
205 
206  void read(std::istream &stream);
207  void print(std::ostream &stream, int _prec = 8) const;
208 
210  bool is_equivalent(const Lattice &RHS, double tol) const;
211 
213  bool operator<(const Lattice &RHS) const;
214 
216  //Eigen::Matrix3d operator/(const Lattice &RHS);
217 
218  //John G 121212
220  bool is_supercell_of(const Lattice &tile, Eigen::Matrix3d &multimat, double _tol = TOL) const;
221  bool is_supercell_of(const Lattice &tile, const Array<SymOp> &symlist, Eigen::Matrix3d &multimat, double _tol = TOL) const;
222 
224  bool is_supercell_of(const Lattice &tile, double _tol = TOL) const;
225  bool is_supercell_of(const Lattice &tile, const Array<SymOp> &symlist, double _tol = TOL) const;
226 
228  Lattice box(const Lattice &prim, const Lattice &scel, bool verbose = false) const;
229 
232 
234  bool is_right_handed() const;
235 
237  Eigen::Vector3i get_millers(Eigen::Vector3d plane_normal, double tolerance = TOL) const;
238 
240  Lattice get_lattice_in_plane(Eigen::Vector3i millers, int max_vol = 20) const; //John G 121030
241 
242  Array<double> pg_converge(double large_tol);
243  void pg_converge(double small_tol, double large_tol, double increment);
244 
246  void symmetrize(const SymGroup &relaxed_pg);
247 
249  void symmetrize(double _tol);
250 
251  private:
252 
254 
256  bool _eq(const Lattice &RHS) const;
257 
259  void _generate_voronoi_table() const;
260 
261  mutable double m_inner_voronoi_radius;
263 
264  //Coordinate Conversion Matrices
265  //0 is fractional to cartesion; 1 is cartesian to fractional
266  //use FRAC and CART globals to index
267  //e.g., coord[CART]=coord_trans[FRAC]*coord[FRAC]; //converts frac to cart
268  //Word to the wise: coord_trans[FRAC] is the matrix with columns equal to the lattice vectors
270 
271  //int periodicity_dim; //dimension of periodicity
272  //int periodicity_axis; //index of lattice vector that is non-periodic (2d) or periodic (1d)
273 
274  };
275 
276 
277  // write Lattice in json as array of vectors
278  jsonParser &to_json(const Lattice &lat, jsonParser &json);
279  void from_json(Lattice &lat, const jsonParser &json);
280 
281 
282  /* never write a Matrix*Lattice operator, PLEASE
283 
284  template <class T>
285  Lattice operator*(const Matrix3<T> &LHS, const Lattice &RHS);
286 
287  Lattice operator*(const Eigen::Matrix3d &LHS, const Lattice &RHS);
288  */
289 
291  double volume(const Lattice &lat);
292 
294  Lattice &apply(const SymOp &op, Lattice &lat);
295 
297  Lattice copy_apply(const SymOp &op, const Lattice &lat);
298 
300  Lattice make_supercell(const Lattice &lat, const Eigen::Matrix3i &transf_mat);
301 
303  std::pair<bool, Eigen::MatrixXi> is_supercell(const Lattice &scel, const Lattice &unit, double tol);
304 
307  template<typename Object, typename OpIterator>
308  std::pair<OpIterator, Eigen::MatrixXi> is_supercell(
309  const Object &scel,
310  const Object &unit,
311  OpIterator begin,
312  OpIterator end,
313  double tol);
314 
315  std::istream &operator>>(std::istream &in, const Lattice &lattice_in);
316 
318  Lattice superdupercell(const Lattice &lat1, const Lattice &lat2);
319 
321  template<typename LatIterator, typename SymOpIterator>
322  Lattice superdupercell(LatIterator begin,
323  LatIterator end,
324  SymOpIterator op_begin = SymOpIterator(),
325  SymOpIterator op_end = SymOpIterator());
326 
327  Lattice replace_vector(const Lattice &lat, const Eigen::Vector3d &new_vector, double tol);
328 
329 
330 
331 
332  //********************************************************************
340  inline
341  Eigen::Matrix3d cart2frac(const Eigen::Ref<const Eigen::Matrix3d> &cart_mat, const Lattice &lat) {
342  return lat.inv_lat_column_mat() * cart_mat * lat.lat_column_mat();
343  }
344 
345  //********************************************************************
353  inline
354  Eigen::Matrix3d frac2cart(const Eigen::Ref<const Eigen::Matrix3d> &frac_mat, const Lattice &lat) {
355  return lat.lat_column_mat() * frac_mat * lat.inv_lat_column_mat();
356  }
357 
358  //********************************************************************
359  // A column of trans_mat specifies a lattice vector of the supercell in terms of the
360  // lattice vectors of (*this) lattice.
361  template <typename T>
362  Lattice Lattice::make_supercell(const Eigen::Matrix<T, 3, 3> &trans_mat) const {
363  return Lattice(lat_column_mat() * trans_mat);
364  }
365 
372  inline double volume(const Lattice &lat) {
373  return lat.lat_column_mat().determinant();
374  }
375 
377  inline Lattice make_supercell(const Lattice &lat, const Eigen::Matrix3i &transf_mat) {
378  return Lattice(Eigen::Matrix3d(lat.lat_column_mat()) * transf_mat.cast<double>());
379  }
380 
383 }
384 #endif
Eigen::MatrixXd MatrixXd
void _generate_voronoi_table() const
populate voronoi information.
Definition: Lattice.cc:563
Eigen::Matrix3d m_inv_lat_mat
Definition: Lattice.hh:269
bool is_canonical(double tol=TOL) const
Check if Lattice is in the canonical form.
Definition: Lattice.cc:235
Eigen::Matrix3d::ConstColXpr ConstLatVec
Definition: Lattice.hh:34
Lattice superdupercell(const Lattice &lat1, const Lattice &lat2)
returns Lattice that is smallest possible supercell of both input Lattice
Definition: Lattice.cc:1161
ConstLatVec operator[](Index i) const
Get i'th lattice vector as column expression.
Definition: Lattice.hh:61
void from_json(ClexDescription &desc, const jsonParser &json)
Implements other comparisons in terms of '<'.
Definition: Comparisons.hh:23
void generate_point_group(SymGroup &point_group, double pg_tol=TOL) const
Populate.
Definition: Lattice.cc:304
std::tuple< ConstLatVec, ConstLatVec, ConstLatVec > vectors() const
Definition: Lattice.hh:69
Array< double > pg_converge(double large_tol)
Definition: Lattice.cc:351
double length(Index i) const
Return length of i'th lattice vector.
Definition: Lattice.cc:93
static Lattice hexagonal()
Construct cubic primitive cell of unit volume.
Definition: Lattice.cc:75
bool _eq(const Lattice &RHS) const
Are lattice vectors identical for two lattices, within TOL.
Definition: Lattice.cc:1024
bool is_equivalent(const Lattice &RHS, double tol) const
Are two lattices the same, even if they have different lattice vectors.
Definition: Lattice.cc:1002
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
Data structure for holding supercell enumeration properties.
Object copy_apply(const Transform &f, Object obj, Args &&...args)
Eigen::Matrix3d cart2frac(const Eigen::Ref< const Eigen::Matrix3d > &cart_mat, const Lattice &lat)
Returns 'frac_mat' which is transformation of 'cart_mat' if cart_vec_after = cart_mat*cart_vec then f...
Definition: Lattice.hh:341
Eigen::MatrixXd const & voronoi_table() const
Return voronoi table, which specifies outward-pointing normals of Lattice Voronoi cell...
Definition: Lattice.hh:90
Lattice make_supercell(const Lattice &lat, const Eigen::Matrix3i &transf_mat)
Returns a super Lattice.
Definition: Lattice.hh:377
Lattice get_reduced_cell() const
Find the lattice vectors which give most compact unit cell Compactness is measured by how close lat_c...
Definition: Lattice.cc:442
Main CASM namespace.
Definition: complete.cpp:8
void print(std::ostream &stream, int _prec=8) const
Definition: Lattice.cc:129
static Lattice bcc()
Construct BCC primitive cell of unit volume.
Definition: Lattice.cc:57
const double TOL
const Eigen::Matrix3d & lat_column_mat() const
3x3 matrix with lattice vectors as its columne
Definition: Lattice.hh:104
Eigen::Matrix3d::ColXpr LatVec
Definition: Lattice.hh:33
Lattice make_supercell(const Eigen::Matrix< T, 3, 3 > &trans_mat) const
make a supercell of this lattice. Equivalent to Lattice(lat_column_mat()*trans_mat) ...
Definition: Lattice.hh:362
Lattice get_lattice_in_plane(Eigen::Vector3i millers, int max_vol=20) const
Generates a lattice with vectors a and b parallel to the plane described by the miller indeces...
Definition: Lattice.cc:717
double m_inner_voronoi_radius
Definition: Lattice.hh:261
SymGroup is a collection of symmetry operations that satisfy the group property The symmetry operatio...
Definition: SymGroup.hh:33
double tol
Eigen::MatrixXd m_voronoi_table
Definition: Lattice.hh:262
const Eigen::Matrix3d & inv_lat_column_mat() const
Inverse of Lattice::lat_column_mat() It is the transformation matrix 'C2F', such that f = C2F * c whe...
Definition: Lattice.hh:113
Lattice(const Eigen::Vector3d &vec1, const Eigen::Vector3d &vec2, const Eigen::Vector3d &vec3)
Definition: Lattice.cc:27
static Lattice cubic()
Construct simple cubic primitive cell of unit volume.
Definition: Lattice.cc:69
SymOp is the Coordinate representation of a symmetry operation it keeps fraction (FRAC) and Cartesian...
Definition: SymOp.hh:28
LatVec operator[](Index i)
Get i'th lattice vector as column expression.
Definition: Lattice.hh:56
Array< CoordType > gridstruc_build(double max_radius, double min_radius, Array< CoordType > basis, CoordType2 lat_point)
Make a grid of lattice sites such that min_radius <= distance <= max_radius from. ...
Definition: Lattice_impl.hh:15
void read(std::istream &stream)
Definition: Lattice.cc:116
EigenIndex Index
For long integer indexing:
SymOp to_canonical(double tol=TOL) const
Returns the operation that applied to *this returns the canonical form.
Definition: Lattice.cc:249
Lattice canonical_form(double tol=TOL) const
Returns the canonical equivalent Lattice, using the point group of the Lattice.
Definition: Lattice.cc:289
bool is_supercell_of(const Lattice &tile, Eigen::Matrix3d &multimat, double _tol=TOL) const
Matrix that relates two lattices (e.g., strain or slat)
Definition: Lattice.cc:655
double min_voronoi_radius() const
Radius of largest sphere that totally fits inside the voronoi cell.
Eigen::Vector3i get_millers(Eigen::Vector3d plane_normal, double tolerance=TOL) const
Given a normal vector, a Vector3 containing the miller indeces for the lattice is generated...
Definition: Lattice.cc:694
void print_voronoi_table(std::ostream &stream) const
double vol() const
Return signed volume of this lattice.
Definition: Lattice.hh:83
std::tuple< LatVec, LatVec, LatVec > vectors()
Definition: Lattice.hh:65
Lattice box(const Lattice &prim, const Lattice &scel, bool verbose=false) const
Return a lattice with diagonal matrix that fits around starting lattice.
SymOpOutputIterator find_invariant_subgroup(SymOpIterator begin, SymOpIterator end, SymOpOutputIterator result, double pg_tol=TOL) const
Output the SymOp that leave this lattice invariant.
Definition: Lattice_impl.hh:77
std::istream & operator>>(std::istream &_in, std::vector< T > &vec)
Lattice scaled_lattice(double scale) const
Return scaled copy of this lattice (Note: Volume will be scaled by scale^3)
Definition: Lattice.cc:87
bool operator<(const Lattice &RHS) const
Compare two Lattice.
Definition: Lattice.cc:1013
Eigen::Matrix3d Matrix3d
Lattice get_reciprocal() const
Return reciprocal lattice.
Definition: Lattice.cc:149
bool is_right_handed() const
Check if the lattice is right handed.
Definition: Lattice.cc:1096
double inner_voronoi_radius() const
Radius of the largest sphere that fits wholly within the voronoi cell.
Definition: Lattice.hh:98
Eigen::Vector3i enclose_sphere(double radius) const
Definition: Lattice.cc:626
double max_voronoi_measure(const Eigen::Vector3d &pos, Eigen::Vector3d &lattice_trans) const
Definition: Lattice.cc:530
void symmetrize(const SymGroup &relaxed_pg)
Force this lattice to have symmetry of group.
Definition: Lattice.cc:1038
Lattice & make_right_handed()
Flip c vector if it's on the wrong side of a-b plane – return (*this)
Definition: Lattice.cc:681
std::pair< bool, Eigen::MatrixXi > is_supercell(const Lattice &scel, const Lattice &unit, double tol)
Check if scel is a supercell of unitcell unit and some integer transformation matrix T...
Definition: Lattice.cc:1196
double volume(const Lattice &lat)
Returns the volume of a Lattice.
Definition: Lattice.hh:372
Array< int > calc_kpoints(Array< int > prim_kpoints, Lattice prim_lat)
Definition: Lattice.cc:161
Eigen::Matrix3d frac2cart(const Eigen::Ref< const Eigen::Matrix3d > &frac_mat, const Lattice &lat)
Returns 'cart_mat' which is transformation of 'frac_mat' if cart_vec_after = cart_mat*cart_vec then f...
Definition: Lattice.hh:354
double angle(Index i) const
Return angle between lattice vectors (*this)[(i+1)%3] and (*this)[(i+2)%3], in degrees.
Definition: Lattice.cc:99
Lattice replace_vector(const Lattice &lat, const Eigen::Vector3d &new_vector, double tol)
SymOp from_canonical(double tol=TOL) const
Returns the operation that applied to the canonical form returns *this.
Definition: Lattice.cc:273
static Lattice fcc()
Construct FCC primitive cell of unit volume.
Definition: Lattice.cc:45
Object & apply(const Transform &f, Object &obj, Args &&...args)
Eigen::Matrix3d m_lat_mat
Definition: Lattice.hh:269
int voronoi_number(const Eigen::Vector3d &pos) const
Definition: Lattice.cc:541
void generate_supercells(Array< Lattice > &supercell, const SymGroup &effective_pg, const ScelEnumProps &enum_props) const
Populate.
Definition: Lattice.cc:410