Mantid
Loading...
Searching...
No Matches
ConventionalCell.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7/* File: ConventionalCell.cpp */
8
9#include <algorithm>
10#include <cstdio>
11#include <stdexcept>
12
16#include "MantidKernel/V3D.h"
17
18namespace Mantid::Geometry {
21
33ConventionalCell::ConventionalCell(const Kernel::DblMatrix &UB, size_t form_num, bool allowPermutations) {
34 form_number = form_num;
35 std::vector<double> lat_par;
37
38 ReducedCell form_0 = ReducedCell(0, lat_par[0], lat_par[1], lat_par[2], lat_par[3], lat_par[4], lat_par[5]);
39 ReducedCell form_i = ReducedCell(form_num, lat_par[0], lat_par[1], lat_par[2], lat_par[3], lat_par[4], lat_par[5]);
40 init(UB, form_0, form_i, allowPermutations);
41}
42
48size_t ConventionalCell::GetFormNum() const { return form_number; }
49
56double ConventionalCell::GetError() const { return scalars_error; }
57
63std::string ConventionalCell::GetCellType() const { return std::string(cell_type); }
64
70std::string ConventionalCell::GetCentering() const { return std::string(centering); }
71
79
87
95
102 std::vector<double> lat_par;
104 return lat_par[0] + lat_par[1] + lat_par[2];
105}
106
114 char buffer[100];
115 sprintf(buffer, std::string("Form #%2d").c_str(), GetFormNum());
116 std::string message(buffer);
117
118 sprintf(buffer, std::string(" Error:%7.4f").c_str(), GetError());
119 message += std::string(buffer);
120
121 sprintf(buffer, std::string(" %-12s").c_str(), GetCellType().c_str());
122 message += std::string(buffer);
123
124 sprintf(buffer, std::string(" %1s ").c_str(), GetCentering().c_str());
125 message += std::string(buffer);
126
127 return message;
128}
129
144 const bool allowPermutations) {
145 scalars_error = form_0.WeightedDistance(form_i);
146 cell_type = form_i.GetCellType();
147 centering = form_i.GetCentering();
148
150
151 hkl_tran = form_i.GetTransformation();
152
154 UB_tran.Invert();
155 adjusted_UB = UB * UB_tran;
156 if (allowPermutations) {
161 }
162 }
163}
164
175
176 std::vector<V3D> edges(3, V3D());
177 OrientedLattice::GetABC(UB, edges[0], edges[1], edges[2]);
178
179 std::sort(edges.begin(), edges.end(), V3D::compareMagnitude);
180
181 V3D a = edges[0];
182 V3D b = edges[1];
183 V3D c = edges[2];
184
185 V3D acrossb = a.cross_prod(b); // keep a,b,c right handed
186 if (acrossb.scalar_prod(c) < 0) {
187 c = c * (-1);
188 }
189 OrientedLattice::GetUB(UB, a, b, c);
190}
191
203 V3D a;
204 V3D b;
205 V3D c;
206 OrientedLattice::GetABC(UB, a, b, c);
207
208 double a_b_diff = fabs(a.norm() - b.norm()) / std::min(a.norm(), b.norm());
209
210 double a_c_diff = fabs(a.norm() - c.norm()) / std::min(a.norm(), c.norm());
211
212 double b_c_diff = fabs(b.norm() - c.norm()) / std::min(b.norm(), c.norm());
213
214 // if needed, change UB to have the two most nearly
215 // equal sides first.
216 if (a_c_diff <= a_b_diff && a_c_diff <= b_c_diff) {
217 OrientedLattice::GetUB(UB, c, a, b);
218 } else if (b_c_diff <= a_b_diff && b_c_diff <= a_c_diff) {
219 OrientedLattice::GetUB(UB, b, c, a);
220 }
221}
222
233 V3D a;
234 V3D b;
235 V3D c;
236 OrientedLattice::GetABC(UB, a, b, c);
237
238 double alpha = b.angle(c) * 180.0 / M_PI;
239 double beta = c.angle(a) * 180.0 / M_PI;
240 // first, make the non 90
241 // degree angle last
242 if (fabs(alpha - 90) > 20) {
243 OrientedLattice::GetUB(UB, b, c, a);
244 } else if (fabs(beta - 90) > 20) {
245 OrientedLattice::GetUB(UB, c, a, b);
246 }
247 // if the non 90 degree angle
248 // is about 60 degrees, make
249 // it about 120 degrees.
250 OrientedLattice::GetABC(UB, a, b, c);
251 double gamma = a.angle(b) * 180.0 / M_PI;
252 if (fabs(gamma - 60) < 10) {
253 a = a * (-1); // reflect a and c to change
254 c = c * (-1); // alpha and gamma to their
255 OrientedLattice::GetUB(UB, a, b, c); // supplementary angle
256 }
257}
258
259} // namespace Mantid::Geometry
#define fabs(x)
Definition: Matrix.cpp:22
void init(const Kernel::DblMatrix &UB, const ReducedCell &form_0, ReducedCell &form_i, const bool allowPermutations)
Initialize the fields of this ConventionalCell object, using a specified matrix and two forms.
std::string GetDescription() const
get string listing form number, error, cell type and centering
void StandardizeTetragonal(Kernel::DblMatrix &UB)
Change UB to a new matrix corresponding to a unit cell with the first two sides approximately equal i...
std::string GetCellType() const
get the cell type name, as named in the ReducedCell class
Kernel::DblMatrix GetNewUB() const
get the transformed orientation matrix for the conventional cell
ConventionalCell(const Kernel::DblMatrix &UB, size_t form_num=0, bool allowPermutations=false)
Construct a ConventionalCell for the specified UB and form number.
Kernel::DblMatrix GetOriginalUB() const
get the original orientation matrix as passed in to the constructor
std::string GetCentering() const
get the centering type name, as named in the ReducedCell class
Kernel::DblMatrix GetHKL_Tran() const
get the transform to change HKL to new conventional cell HKL
void SetSidesIncreasing(Kernel::DblMatrix &UB)
Change UB to a new matrix corresponding to a unit cell with the sides in increasing order of magnitud...
size_t GetFormNum() const
get the form number for this conventional cell
double GetError() const
get the error in the scalars for this form
double GetSumOfSides() const
get the sum of the sides of the conventional unit cell
void StandardizeHexagonal(Kernel::DblMatrix &UB)
Change UB to a new matrix corresponding to a hexagonal unit cell with angles approximately 90,...
static bool GetLatticeParameters(const Kernel::DblMatrix &UB, std::vector< double > &lattice_par)
Get the lattice parameters for the specified orientation matrix.
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.
Instances of this class represent information about reduced cell types including the transformation r...
Definition: ReducedCell.h:32
std::string GetCellType() const
Get the cell type of this form.
static const std::string HEXAGONAL()
Definition: ReducedCell.h:53
Kernel::DblMatrix GetTransformation()
Return the transformation to map the reduced cell to the conventional cell, as listed in Table 2,...
double WeightedDistance(const ReducedCell &other) const
Get the maximum absolute weighted difference between the scalars for the specifed ReducedCellInfo obj...
static const std::string RHOMBOHEDRAL()
Definition: ReducedCell.h:54
std::string GetCentering() const
Get centering assigned to this form.
static const std::string TETRAGONAL()
Definition: ReducedCell.h:55
T Invert()
LU inversion routine.
Definition: Matrix.cpp:924
Class for 3D vectors.
Definition: V3D.h:34
static bool compareMagnitude(const Kernel::V3D &v1, const Kernel::V3D &v2)
Convenience method for sorting list of V3D objects based on magnitude.
Definition: V3D.cpp:483
constexpr double scalar_prod(const V3D &v) const noexcept
Calculates the cross product.
Definition: V3D.h:274
constexpr V3D cross_prod(const V3D &v) const noexcept
Cross product (this * argument)
Definition: V3D.h:278
double angle(const V3D &) const
Angle between this and another vector.
Definition: V3D.cpp:165
double norm() const noexcept
Definition: V3D.h:263
Mantid::Kernel::Matrix< double > DblMatrix
Definition: Matrix.h:206