CASM  1.1.0
A Clusters Approach to Statistical Mechanics
CanonicalForm.cc
Go to the documentation of this file.
2 
3 #include <set>
4 
9 
10 namespace CASM {
11 namespace xtal {
12 // This is a helper function that isn't part of the Niggli interface, and is
13 // defined in Niggli.cc
14 std::set<Eigen::Matrix3d, StandardOrientationCompare> _niggli_set(
15  const Lattice &in_lat, double compare_tol, bool keep_handedness);
16 
17 namespace canonical {
26 std::pair<Lattice, Index> _equivalent_lattice_and_index(
27  const Lattice &in_lat, const SymOpVector &point_grp, double compare_tol) {
28  auto lat_set = _niggli_set(in_lat, compare_tol, true);
29  if (lat_set.empty())
30  throw std::runtime_error(
31  "In _canonical_equivalent_lattice(), did not find any niggli "
32  "representations of provided lattice.");
33  bool first = true;
34  Eigen::Matrix3d most_canonical_lat_mat, trans_lat_mat;
35  Index to_canonical_ix = 0;
36 
37  // The niggli cell is based purely on the metric tensor, and so is invariant
38  // cartesian rotation (i.e., the niggli cell uniquely orders lattice
39  // parameters and angles but does not uniquely specify orientation) We find
40  // all niggli representations for 'in_lat', and then loop over point group
41  // operations. For each point group operation, reorient all the niggli
42  // representations, keeping track of which orientation is 'most' canonical,
43  // according to casm standard orientation
44  Index ix = 0;
45  for (auto it = point_grp.begin(); it != point_grp.end(); ++it, ++ix) {
46  // Skip operations that change the handedness of the lattice
47  if (get_matrix(*it).determinant() <= 0.0) {
48  continue;
49  }
50 
51  for (Eigen::MatrixXd const &lat_mat : lat_set) {
52  trans_lat_mat = get_matrix(*it) * lat_mat;
53  assert(is_niggli(lat_mat, compare_tol) &&
54  "Result of 'niggli()' is not a Niggli cell");
55 
56  if (first || standard_orientation_compare(most_canonical_lat_mat,
57  trans_lat_mat, compare_tol)) {
58  first = false;
59  most_canonical_lat_mat = trans_lat_mat;
60  to_canonical_ix = ix;
61  }
62  }
63  }
64 
65  return std::make_pair(Lattice(most_canonical_lat_mat, in_lat.tol()),
66  to_canonical_ix);
67 }
68 
69 Lattice equivalent(const Lattice &in_lat, const SymOpVector &point_grp,
70  double compare_tol) {
71  return _equivalent_lattice_and_index(in_lat, point_grp, compare_tol).first;
72 }
73 
74 Lattice equivalent(const Lattice &lat, SymOpVector const &g) {
75  return canonical::equivalent(lat, g, lat.tol());
76 }
77 
78 Lattice equivalent(const Lattice &lat, double compare_tol) {
79  return canonical::equivalent(lat, make_point_group(lat, compare_tol));
80 }
81 
82 Lattice equivalent(const Lattice &lat) {
83  return canonical::equivalent(lat, make_point_group(lat, lat.tol()),
84  lat.tol());
85 }
86 
87 bool check(const Lattice &lat, SymOpVector const &g) {
88  return almost_equal(lat.lat_column_mat(),
90  lat.tol());
91 }
92 
93 bool check(const Lattice &lat) {
94  return canonical::check(lat, make_point_group(lat));
95 }
96 
97 Index operation_index(const Lattice &in_lat, const SymOpVector &point_grp,
98  double compare_tol) {
99  return _equivalent_lattice_and_index(in_lat, point_grp, compare_tol).second;
100 }
101 
102 Index operation_index(const Lattice &lat, SymOpVector const &g) {
103  return canonical::operation_index(lat, g, lat.tol());
104 }
105 
106 } // namespace canonical
107 
108 } // namespace xtal
109 } // namespace CASM
const Eigen::Matrix3d & lat_column_mat() const
3x3 matrix with lattice vectors as its columne
Definition: Lattice.hh:110
double tol() const
Definition: Lattice.hh:195
Lattice equivalent(Lattice const &in_lat, SymOpVector const &point_grp, double compare_tol)
std::pair< Lattice, Index > _equivalent_lattice_and_index(const Lattice &in_lat, const SymOpVector &point_grp, double compare_tol)
Index operation_index(const Lattice &lat, SymOpVector const &g)
bool check(const Lattice &lat)
bool is_niggli(const Eigen::Matrix3d &test_lat_mat, double compare_tol)
Definition: Niggli.cc:271
Eigen::Matrix3d const & get_matrix(MappingNode const &_node)
External accessor for isometry, to provide xtal::SymOp adaptability.
std::set< Eigen::Matrix3d, StandardOrientationCompare > _niggli_set(const Lattice &in_lat, double compare_tol, bool keep_handedness)
Definition: Niggli.cc:284
std::vector< SymOp > make_point_group(Lattice const &_lat)
Populate.
Definition: SymTools.cc:113
std::vector< SymOp > SymOpVector
bool standard_orientation_compare(const Eigen::Matrix3d &low_score_lat_mat, const Eigen::Matrix3d &high_score_lat_mat, double compare_tol)
Determine whether high_score has a more standard format than low_score.
Definition: Niggli.cc:427
Main CASM namespace.
Definition: APICommand.hh:8
bool almost_equal(ClusterInvariants const &A, ClusterInvariants const &B, double tol)
Check if ClusterInvariants are equal.
Eigen::MatrixXd MatrixXd
Eigen::Matrix3d Matrix3d
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39