CASM  1.1.0
A Clusters Approach to Statistical Mechanics
UnitCellCoord.cc
Go to the documentation of this file.
2 
8 
9 namespace CASM {
10 namespace xtal {
11 
12 // TODO: Make this take a tolerance
14  Eigen::Vector3l rounded_lattice_point = lround(lattice_point.const_frac());
15  Eigen::Vector3d round_error =
16  lattice_point.const_frac() - rounded_lattice_point.cast<double>();
17 
18  /* auto unscaled_round_error = lattice_point.const_frac() -
19  * rounded_lattice_point.cast<double>(); */
20  /* auto round_error =
21  * lattice_point.lattice().lat_column_mat()*unscaled_round_error; //scale the
22  * error proportionally to the length of the vector */
23 
24  double tol = lattice_point.lattice().tol();
25  if (!almost_zero(round_error(0), tol) || !almost_zero(round_error(1), tol) ||
26  !almost_zero(round_error(2), tol)) {
27  std::cerr << round_error << std::endl;
29  }
30 
31  return UnitCell(rounded_lattice_point);
32 }
33 
34 UnitCell UnitCell::from_cartesian(const Eigen::Vector3d &cartesian_coord,
35  const Lattice &tiling_unit) {
36  Coordinate as_coord(cartesian_coord, tiling_unit, CART);
37  return UnitCell::from_coordinate(as_coord);
38 }
39 
40 Coordinate UnitCell::coordinate(const Lattice &tiling_unit) const {
41  return Coordinate(this->cast<double>(), tiling_unit, FRAC);
42 }
43 
44 // TODO: Make this take a tolerance
45 UnitCell UnitCell::reset_tiling_unit(const Lattice &current_tiling_unit,
46  const Lattice &new_tiling_unit) const {
47  auto as_coord = this->coordinate(current_tiling_unit);
48  as_coord.set_lattice(new_tiling_unit, CART);
49  return UnitCell::from_coordinate(as_coord);
50 }
51 
52 //************************************************************************************************************//
53 
55  const Coordinate &coord,
56  double tol) {
57  Coordinate coord_in_prim(prim.lattice());
58  coord_in_prim.cart() = coord.cart();
59 
60  for (Index b = 0; b < prim.basis().size(); ++b) {
61  if (coord_in_prim.min_dist(prim.basis()[b]) < tol) {
62  UnitCell coord_unitcell(
63  lround(coord_in_prim.const_frac() - prim.basis()[b].const_frac()));
64  return UnitCellCoord(b, coord_unitcell);
65  }
66  }
67 
68  throw std::runtime_error(
69  "Error constructing UnitCellCoord. No basis site could be found within "
70  "the given tolerance.");
71 }
72 
75  return site(prim);
76 }
77 
79  return this->sublattice() < prim.basis().size();
80 }
81 
83  throw std::runtime_error(
84  "Error in UnitCellCoord. Sublattice index out of range.");
85 }
86 
88 Site UnitCellCoord::site(const PrimType &prim) const {
89  if (!this->_is_compatible_with_prim(prim)) {
91  }
92  return prim.basis()[this->sublattice()] +
93  this->unitcell().coordinate(prim.lattice());
94 }
95 
97 const Site &UnitCellCoord::sublattice_site(const PrimType &prim) const {
98  if (!this->_is_compatible_with_prim(prim)) {
100  }
101  return prim.basis()[sublattice()];
102 }
103 
105  const Lattice &tiling_unit,
106  const Lattice &superlattice) {
107  Coordinate tcoord = ijk.coordinate(tiling_unit);
108  tcoord.set_lattice(superlattice, CART);
109  return tcoord;
110 }
111 
113  const Superlattice &superlattice) {
114  return make_superlattice_coordinate(ijk, superlattice.prim_lattice(),
115  superlattice.superlattice());
116 }
117 } // namespace xtal
118 
119 } // namespace CASM
120 
121 namespace std {
123  const CASM::xtal::UnitCell &value) const {
124  std::size_t seed = value.size();
125  for (int i = 0; i < 3; ++i) {
126  seed ^= value(i) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
127  }
128  return seed;
129 }
130 
132  const CASM::xtal::UnitCellCoord &value) const {
133  const auto &uc = value.unitcell();
134  auto seed = std::hash<CASM::xtal::UnitCell>()(uc);
135  seed ^= value.sublattice() + 0x9e3779b9 + (seed << 6) + (seed >> 2);
136  return seed;
137 }
138 } // namespace std
BasicStructure specifies the lattice and atomic basis of a crystal.
const Lattice & lattice() const
const std::vector< Site > & basis() const
Represents cartesian and fractional coordinates.
Definition: Coordinate.hh:34
Coordinate_impl::CartCoordinate cart()
Set Cartesian coordinate vector and update fractional coordinate vector.
Definition: Coordinate.hh:562
void set_lattice(const Lattice &new_lat, COORD_TYPE mode)
Change the home lattice of the coordinate, selecting one representation (either CART or FRAC) that re...
Definition: Coordinate.cc:190
const Lattice & lattice() const
Access the home lattice of the coordinate.
Definition: Coordinate.hh:206
const vector_type & const_frac() const
user override to force const Access the fractional coordinate vector
Definition: Coordinate.hh:68
double min_dist(const Coordinate &neighbor) const
Returns distance (in Angstr) to nearest periodic image of neighbor.
Definition: Coordinate.cc:152
double tol() const
Definition: Lattice.hh:195
const Lattice & prim_lattice() const
Definition: Superlattice.hh:20
const Lattice & superlattice() const
Definition: Superlattice.hh:18
Unit Cell Coordinates.
Site site(const PrimType &prim) const
Get a copy of corresponding site.
const UnitCell & unitcell() const
const Site & sublattice_site(const PrimType &prim) const
Get reference to corresponding sublattice site in the unit structure.
Coordinate coordinate(const PrimType &prim) const
Get corresponding coordinate.
static UnitCellCoord from_coordinate(const PrimType &, const Coordinate &coord, double tol)
static void _throw_incompatible_primitive_cell()
bool _is_compatible_with_prim(const PrimType &prim) const
Unit Cell Indices.
static UnitCell from_cartesian(const Eigen::Vector3d &cartesian_coord, const Lattice &tiling_unit)
Coordinate coordinate(const Lattice &tiling_unit) const
static UnitCell from_coordinate(Coordinate const &lattice_point)
Convert lattice point to a unitcell.
UnitCell reset_tiling_unit(const Lattice &current_tiling_unit, const Lattice &new_tiling_unit) const
Finds a new UnitCell with values relative to the given tiling unit.
static void _throw_large_rounding_error()
Eigen::CwiseUnaryOp< decltype(Local::lround_l< typename Derived::Scalar >), const Derived > lround(const Eigen::MatrixBase< Derived > &val)
Round Eigen::MatrixXd to Eigen::MatrixXl.
Coordinate make_superlattice_coordinate(const UnitCell &ijk, const Superlattice &superlattice)
Main CASM namespace.
Definition: APICommand.hh:8
const COORD_TYPE FRAC
Definition: enum.hh:8
bool almost_zero(const T &val, double tol=TOL)
If T is not integral, use std::abs(val) < tol;.
Definition: CASM_math.hh:104
const COORD_TYPE CART
Definition: enum.hh:9
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39
Matrix< long int, 3, 1 > Vector3l
Definition: eigen.hh:13
Definition: stream_io.hh:24
std::size_t operator()(const CASM::xtal::UnitCell &value) const
std::size_t operator()(const CASM::xtal::UnitCellCoord &value) const