15const double TWO_PI = 2. * M_PI;
27 throw std::invalid_argument(
"U is not a proper rotation");
46 throw std::invalid_argument(
"U is not a proper rotation");
60 const double _beta,
const double _gamma,
const DblMatrix &Umatrix,
const int angleunit)
61 :
UnitCell(_a, _b, _c, _alpha, _beta, _gamma, angleunit) {
67 throw std::invalid_argument(
"U is not a proper rotation");
80 throw std::invalid_argument(
"U is not a proper rotation");
110 throw std::invalid_argument(
"U is not a proper rotation");
120 newGstar = newUB.
Tprime() * newUB;
126 throw std::invalid_argument(
"determinant of UB is too close to 0");
137 newModHKL = UBinv *
ModUB;
148 V3D out = UBinv * Q / TWO_PI;
158 V3D t1 =
V3D(T[0][0], T[1][0], T[2][0]);
159 V3D t2 =
V3D(T[0][1], T[1][1], T[2][1]);
160 V3D t3 =
V3D(T[0][2], T[1][2], T[2][2]);
217 V3D buVec = BMatrix * u;
218 V3D bvVec = BMatrix * v;
220 if (buVec.
norm2() < 1e-10)
221 throw std::invalid_argument(
"|B.u|~0");
222 if (bvVec.
norm2() < 1e-10)
223 throw std::invalid_argument(
"|B.v|~0");
226 const auto norm = bwVec.
norm();
229 throw std::invalid_argument(
"u and v are parallel");
243 tau[0][0] = buVec[0];
244 tau[0][1] = bvVec[0];
245 tau[0][2] = bwVec[0];
246 tau[1][0] = buVec[1];
247 tau[1][1] = bvVec[1];
248 tau[1][2] = bwVec[1];
249 tau[2][0] = buVec[2];
250 tau[2][1] = bvVec[2];
251 tau[2][2] = bwVec[2];
253 this->
setU(lab * tau);
262 file->makeGroup(
group,
"NXcrystal",
true);
263 file->writeData(
"unit_cell_a", this->
a());
264 file->writeData(
"unit_cell_b", this->
b());
265 file->writeData(
"unit_cell_c", this->
c());
266 file->writeData(
"unit_cell_alpha", this->
alpha());
267 file->writeData(
"unit_cell_beta", this->
beta());
268 file->writeData(
"unit_cell_gamma", this->
gamma());
269 file->writeData(
"unit_cell_a_error", this->
errora());
270 file->writeData(
"unit_cell_b_error", this->
errorb());
271 file->writeData(
"unit_cell_c_error", this->
errorc());
272 file->writeData(
"unit_cell_alpha_error", this->
erroralpha());
273 file->writeData(
"unit_cell_beta_error", this->
errorbeta());
274 file->writeData(
"unit_cell_gamma_error", this->
errorgamma());
278 file->writeData(
"orientation_matrix", ub, dims);
282 file->writeData(
"modulated_orientation_matrix", modUB, dims);
284 file->writeData(
"modulated_hkl_error",
errorModHKL, dims);
285 file->writeData(
"maximum_order", this->
getMaxOrder());
286 file->writeData(
"cross_term",
int(this->
getCrossTerm()));
296 file->openGroup(
group,
"NXcrystal");
297 std::vector<double> ub;
298 file->readData(
"orientation_matrix", ub);
306 file->readData(
"unit_cell_a_error",
errora);
307 file->readData(
"unit_cell_b_error",
errorb);
308 file->readData(
"unit_cell_c_error",
errorc);
309 file->readData(
"unit_cell_alpha_error",
erroralpha);
310 file->readData(
"unit_cell_beta_error",
errorbeta);
311 file->readData(
"unit_cell_gamma_error",
errorgamma);
314 std::vector<double> modUB;
315 file->readData(
"modulated_orientation_matrix", modUB);
320 file->readData(
"modulated_hkl_error",
errorModHKL);
325 file->readData(
"maximum_order",
maxOrder);
328 file->readData(
"cross_term", crossTerm);
350 throw std::invalid_argument(
"Find_UB(): UB matrix NULL or not 3X3");
383 throw std::invalid_argument(
"GetABC(): UB matrix NULL or not 3X3");
392 a_dir(UB_inverse[0][0], UB_inverse[0][1], UB_inverse[0][2]);
393 b_dir(UB_inverse[1][0], UB_inverse[1][1], UB_inverse[1][2]);
394 c_dir(UB_inverse[2][0], UB_inverse[2][1], UB_inverse[2][2]);
Class to implement UB matrix.
Kernel::V3D cosFromDir(const Kernel::V3D &dir) const
Calculate the direction cosine corresponding to a given direction.
Kernel::V3D getuVector() const
gets a vector along beam direction when goniometers are at 0.
void setU(const Kernel::DblMatrix &newU, const bool force=true)
Sets the U matrix.
Kernel::V3D getvVector() const
gets a vector in the horizontal plane, perpendicular to the beam direction when goniometers are at 0.
OrientedLattice(const Kernel::DblMatrix &Umatrix=Kernel::DblMatrix(3, 3, true))
Default constructor.
void setModUB(const Kernel::DblMatrix &newModUB)
Sets the Modulation UB matrix.
Kernel::V3D hklFromQ(const Kernel::V3D &Q) const
Calculate the hkl corresponding to a given Q-vector.
void setUB(const Kernel::DblMatrix &newUB)
Sets the UB matrix and recalculates lattice parameters.
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.
bool operator==(const OrientedLattice &other) const
const Kernel::DblMatrix & setUFromVectors(const Kernel::V3D &u, const Kernel::V3D &v)
Set the U rotation matrix, to provide the transformation, which translate an arbitrary vector V expre...
void recalculate() override
Private function, called at initialization or whenever lattice parameters are changed.
const Kernel::DblMatrix & getUB() const
Get the UB matrix.
void saveNexus(Nexus::File *file, const std::string &group) const
Save the object to an open NeXus file.
void loadNexus(Nexus::File *file, const std::string &group)
Load the object from an open NeXus file.
bool operator!=(const OrientedLattice &other) const
static bool GetUB(Kernel::DblMatrix &UB, const Kernel::V3D &a_dir, const Kernel::V3D &b_dir, const Kernel::V3D &c_dir)
Get the UB matrix corresponding to the real space edge vectors a,b,c.
Kernel::V3D qFromHKL(const Kernel::V3D &hkl) const
Calculate the hkl corresponding to a given Q-vector.
const Kernel::DblMatrix & getModUB() const
const Kernel::DblMatrix & getU() const
Get the U matrix.
void recalculateFromGstar(const Kernel::DblMatrix &NewGstar) override
Make recalculateFrom private.
Class to implement unit cell of crystals.
const Kernel::DblMatrix & getB() const
Get the B-matrix.
double alpha() const
Get lattice parameter.
double erroralpha(const int angleunit=angDegrees) const
Get lattice parameter error.
int getMaxOrder() const
Get max order.
double c() const
Get lattice parameter.
const Kernel::DblMatrix & getModHKL() const
Get modulation vectors for satellites.
bool getCrossTerm() const
Get cross term boolean.
double errorgamma(const int angleunit=angDegrees) const
Get lattice parameter error.
double errorbeta(const int angleunit=angDegrees) const
Get lattice parameter error.
Kernel::DblMatrix errorModHKL
void setModHKL(double _dh1, double _dk1, double _dl1, double _dh2, double _dk2, double _dl2, double _dh3, double _dk3, double _dl3)
Set modulation vectors for satellites.
double beta() const
Get lattice parameter.
void setError(double _aerr, double _berr, double _cerr, double _alphaerr, double _betaerr, double _gammaerr, const int angleunit=angDegrees)
Set lattice parameter errors.
double a() const
Get lattice parameter.
virtual void recalculate()
Private function, called at initialization or whenever lattice parameters are changed.
void setErrorModHKL(const Kernel::DblMatrix &newErrorModHKL)
Set modulation vectors for satellites.
double b() const
Get lattice parameter.
double errorc() const
Get lattice parameter error.
void setCrossTerm(bool CT)
Set modulation vectors for satellites.
void setMaxOrder(int MaxO)
Set modulation vectors for satellites.
Kernel::DblMatrix B
B matrix for a right-handed coordinate system, in Busing-Levy convention.
double gamma() const
Get lattice parameter.
double errora() const
Get lattice parameter error.
double errorb() const
Get lattice parameter error.
T determinant() const
Calculate the determinant.
T Invert()
LU inversion routine.
Matrix< T > Tprime() const
Transpose the matrix.
bool isRotation() const
Check if a matrix represents a proper rotation @ return :: true/false.
void setRow(const size_t nRow, const std::vector< T > &newRow)
std::vector< T > getVector() const
size_t numRows() const
Return the number of rows in the matrix.
size_t numCols() const
Return the number of columns in the matrix.
bool isOrthogonal() const
Check if a matrix is orthogonal.
double normalize()
Make a normalized vector (return norm value)
constexpr V3D cross_prod(const V3D &v) const noexcept
Cross product (this * argument)
double norm() const noexcept
constexpr double norm2() const noexcept
Vector length squared.
Class that provides for a standard Nexus exception.
std::vector< dimsize_t > DimVector