Newer
Older
#ifndef MANTID_GEOMETRY_UNITCELL_H_
#define MANTID_GEOMETRY_UNITCELL_H_
Gigg, Martyn Anthony
committed
#include "MantidGeometry/DllConfig.h"
#include "MantidGeometry/Crystal/AngleUnits.h"
Gigg, Martyn Anthony
committed
#include "MantidKernel/PhysicalConstants.h"
Gigg, Martyn Anthony
committed
#include "MantidKernel/Matrix.h"
#include "MantidKernel/Quat.h"
#include "MantidKernel/V3D.h"
#include <cmath>
#include <vector>
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
namespace Mantid {
namespace Geometry {
/** @class UnitCell UnitCell.h Geometry/Crystal/UnitCell.h
Class to implement unit cell of crystals.
It is based on code by Laurent Chapon. It does not contain information about
lattice orientation.
See documentation about UB matrix in the Mantid repository.\n
For documentation purposes, units for lengths are assumed to be \f$ \mbox{ \AA
} \f$, and for reciprocal lattice lengths
\f$ \mbox{ \AA }^{-1} \f$, but can be anything, as long as used consistently.
Note that the convention used for
reciprocal lattice follows the one in International Tables for
Crystallography, meaning that for an orthogonal lattice
\f$ a^{*} = 1/a \f$ , not \f$ a^{*} = 2 \pi /a \f$
References:
- International Tables for Crystallography (2006). Vol. B, ch. 1.1, pp. 2-9
- W. R. Busing and H. A. Levy, Angle calculations for 3- and 4-circle X-ray
and neutron diffractometers - Acta Cryst. (1967). 22, 457-464
@author Andrei Savici, SNS, ORNL
@date 2011-03-23
Copyright © 2007-8 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_GEOMETRY_DLL UnitCell {
public:
// Default constructor. a = b = c = 1, alpha = beta = gamma = 90 degrees
UnitCell();
// Copy constructor
UnitCell(const UnitCell &other);
// Copy constructor
UnitCell(const UnitCell *other);
// a,b,c constructor
UnitCell(const double _a, const double _b, const double _c);
// a,b,c,alpha,beta,gamma constructor
UnitCell(const double _a, const double _b, const double _c,
const double _alpha, const double _beta, const double _gamma,
const int angleunit = angDegrees);
// Destructor
virtual ~UnitCell();
// Get and set lattice parameters
// Direct lattice parameters, angle in radians.
double a1() const;
double a2() const;
double a3() const;
double alpha1() const;
double alpha2() const;
double alpha3() const;
// Direct lattice parameters, angle in degrees.
double a(int nd) const; // get lattice parameter as function of index (0-2)
double a() const;
double b() const;
double c() const;
double alpha() const;
double beta() const;
double gamma() const;
// Reciprocal lattice parameters, angle in radians.
double b1() const;
double b2() const;
double b3() const;
double beta1() const;
double beta2() const;
double beta3() const;
// Reciprocal lattice parameters, angle in degrees.
double astar() const;
double bstar() const;
double cstar() const;
double alphastar() const;
double betastar() const;
double gammastar() const;
// Set lattice
void set(double _a, double _b, double _c, double _alpha, double _beta,
double _gamma, const int angleunit = angDegrees);
void seta(double _a);
void setb(double _b);
void setc(double _c);
void setalpha(double _alpha, const int angleunit = angDegrees);
void setbeta(double _beta, const int angleunit = angDegrees);
void setgamma(double _gamma, const int angleunit = angDegrees);
// Set errors
void setError(double _aerr, double _berr, double _cerr, double _alphaerr,
double _betaerr, double _gammaerr,
const int angleunit = angDegrees);
void setErrora(double _aerr);
void setErrorb(double _berr);
void setErrorc(double _cerr);
void setErroralpha(double _alphaerr, const int angleunit = angDegrees);
void setErrorbeta(double _betaerr, const int angleunit = angDegrees);
void setErrorgamma(double _gammaerr, const int angleunit = angDegrees);
// Get errors in latice parameters
double errora() const;
double errorb() const;
double errorc() const;
double erroralpha(const int angleunit = angDegrees) const;
double errorbeta(const int angleunit = angDegrees) const;
double errorgamma(const int angleunit = angDegrees) const;
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Access private variables
const Kernel::DblMatrix &getG() const;
const Kernel::DblMatrix &getGstar() const;
const Kernel::DblMatrix &getB() const;
const Kernel::DblMatrix &getBinv() const;
// Calculate things about lattice and vectors
double d(double h, double k, double l) const;
double dstar(double h, double k, double l) const;
double d(const Kernel::V3D &hkl) const;
double dstar(const Kernel::V3D &hkl) const;
double recAngle(double h1, double k1, double l1, double h2, double k2,
double l2, const int angleunit = angDegrees) const;
double volume() const;
double recVolume() const;
virtual void recalculateFromGstar(const Kernel::Matrix<double> &NewGstar);
private:
/// Lattice parameter a,b,c,alpha,beta,gamma (in \f$ \mbox{ \AA } \f$ and
/// radians)
std::vector<double> da;
/// Reciprocal lattice parameters (in \f$ \mbox{ \AA }^{-1} \f$ and radians)
std::vector<double> ra;
/// Error in lattice parameters (in \f$ \mbox{ \AA } \f$ and radians)
std::vector<double> errorda;
/** Metric tensor
\f[ \left( \begin{array}{ccc}
aa & ab\cos(\gamma) & ac\cos(\beta) \\
ab\cos(\gamma) & bb & bc\cos(\alpha) \\
ac\cos(\beta) & bc\cos(\alpha) & cc \end{array} \right) \f]
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
Kernel::DblMatrix G;
/** Reciprocal lattice tensor
*\f[ \left( \begin{array}{ccc}
a^*a^* & a^*b^*\cos(\gamma^*) & a^*c^*\cos(\beta^*) \\
a^*b^*\cos(\gamma^*) & b^*b^* & b^*c^*\cos(\alpha^*) \\
a^*c^*\cos(\beta^*) & b^*c^*\cos(\alpha^*) & c^*c^* \end{array} \right) \f]
*/
Kernel::DblMatrix Gstar;
/** B matrix for a right-handed coordinate system, in Busing-Levy convention
\f[ \left( \begin{array}{ccc}
a^* & b^*\cos(\gamma^*) & c^*\cos(\beta^*) \\
0 & b^*\sin(\gamma^*) & -c^*\sin(\beta^*)\cos(\alpha) \\
0 & 0 & 1/c \end{array} \right) \f]
*/
Kernel::DblMatrix B;
/** Inverse of the B matrix.
*/
Kernel::DblMatrix Binv;
// Private functions
void recalculate();
void calculateG();
void calculateGstar();
void calculateReciprocalLattice();
void calculateB();
};
MANTID_GEOMETRY_DLL std::ostream &operator<<(std::ostream &out,
const UnitCell &unitCell);
MANTID_GEOMETRY_DLL UnitCell strToUnitCell(const std::string &unitCellString);
MANTID_GEOMETRY_DLL std::string unitCellToStr(const UnitCell &unitCell);
} // namespace Mantid
} // namespace Geometry
#endif /* MANTID_GEOMETRY_UNITCELL_H_ */