19const double RAD_TO_DEG = 180. / M_PI;
39 return (sum_1 < sum_2);
57 double alpha = b.
angle(c) * RAD_TO_DEG;
58 double beta = c.
angle(a) * RAD_TO_DEG;
59 double gamma = a.
angle(b) * RAD_TO_DEG;
61 double sum =
fabs(alpha - 90.0) +
fabs(beta - 90.0) +
fabs(gamma - 90.0);
74 return (sum_2 < sum_1);
84 throw std::invalid_argument(
"U is not a proper rotation");
102 throw std::invalid_argument(
"U is not a proper rotation");
116 const double _gamma,
const DblMatrix &Umatrix,
const int angleunit)
117 :
UnitCell(_a, _b, _c, _alpha, _beta, _gamma, angleunit) {
122 throw std::invalid_argument(
"U is not a proper rotation");
134 throw std::invalid_argument(
"U is not a proper rotation");
155 double alpha = b_dir.
angle(c_dir) * RAD_TO_DEG;
156 double beta = c_dir.
angle(a_dir) * RAD_TO_DEG;
157 double gamma = a_dir.
angle(b_dir) * RAD_TO_DEG;
159 if (
alpha < 90 + epsilon &&
beta < 90 + epsilon &&
gamma < 90 + epsilon) {
163 if (
alpha >= 90 - epsilon &&
beta >= 90 - epsilon &&
gamma >= 90 - epsilon) {
197 std::vector<V3D> directions;
199 for (
int i = -N_coeff; i <= N_coeff; i++) {
200 for (
int j = -N_coeff; j <= N_coeff; j++) {
201 for (
int k = -N_coeff; k <= N_coeff; k++) {
202 if (i != 0 || j != 0 || k != 0) {
209 directions.emplace_back(sum);
224 std::vector<DblMatrix> UB_list;
226 size_t num_needed = 25;
227 size_t max_to_try = 5;
228 while (UB_list.size() < num_needed && max_to_try < directions.size()) {
230 size_t num_to_try = std::min(max_to_try, directions.size());
234 double min_vol = .1f;
235 for (
size_t i = 0; i < num_to_try - 2; i++) {
237 for (
size_t j = i + 1; j < num_to_try - 1; j++) {
239 acrossb =
a.cross_prod(
b);
240 for (
size_t k = j + 1; k < num_to_try; k++) {
246 UB_list.emplace_back(new_tran);
254 if (UB_list.empty()) {
266 double length_tol = 0.001;
269 std::vector<DblMatrix> short_list;
270 short_list.emplace_back(UB_list[0]);
272 total_length =
a.norm() +
b.norm() +
c.norm();
274 bool got_short_list =
false;
276 while (i < UB_list.size() && !got_short_list) {
279 if (
fabs(next_length - total_length) / total_length < length_tol)
280 short_list.emplace_back(UB_list[i]);
282 got_short_list =
true;
290 newUB = short_list[0];
static bool HasNiggliAngles(const Kernel::V3D &a_dir, const Kernel::V3D &b_dir, const Kernel::V3D &c_dir, double epsilon)
Check if a,b,c cell has angles satifying Niggli condition within epsilon.
static bool MakeNiggliUB(const Kernel::DblMatrix &UB, Kernel::DblMatrix &newUB)
Construct a newUB corresponding to a Niggli cell from the given UB.
NiggliCell(const Kernel::DblMatrix &Umatrix=Kernel::DblMatrix(3, 3, true))
Default constructor.
static bool GetABC(const Kernel::DblMatrix &UB, Kernel::V3D &a_dir, Kernel::V3D &b_dir, Kernel::V3D &c_dir)
Get the real space edge vectors a, b, c corresponding to the UB matrix.
static bool GetUB(Kernel::DblMatrix &UB, const Kernel::V3D &a_dir, const Kernel::V3D &b_dir, const Kernel::V3D &c_dir)
Get the UB matix corresponding to the real space edge vectors a, b, c.
Class to implement unit cell of crystals.
const Kernel::DblMatrix & getB() const
Get the B-matrix.
double alpha() const
Get lattice parameter.
double c() const
Get lattice parameter.
double beta() const
Get lattice parameter.
double a() const
Get lattice parameter.
double b() const
Get lattice parameter.
double gamma() const
Get lattice parameter.
bool isRotation() const
Check if a matrix represents a proper rotation @ return :: true/false.
static bool compareMagnitude(const Kernel::V3D &v1, const Kernel::V3D &v2)
Convenience method for sorting list of V3D objects based on magnitude.
constexpr double scalar_prod(const V3D &v) const noexcept
Calculates the cross product.
double angle(const V3D &) const
Angle between this and another vector.
double norm() const noexcept
static bool CompareABCsum(const DblMatrix &UB_1, const DblMatrix &UB_2)
Comparator function for sorting list of UB matrices based on the sum of the lengths of the correspond...
static double GetDiffFrom90Sum(const DblMatrix &UB)
Get the cell angles for the unit cell corresponding to matrix UB and calculate the sum of the differe...
static bool CompareDiffFrom90(const DblMatrix &UB_1, const DblMatrix &UB_2)
Comparator to sort a list of UBs in decreasing order based on the difference of cell angles from 90 d...