| Bsoft 2.0.5 Bernard's software package

UnitCell.cpp
Go to the documentation of this file.
1
9 #include "UnitCell.h"
10 #include "utilities.h"
11
12 // Declaration of global variables
13 extern int verbose; // Level of output to the screen
14
26 Matrix3 UnitCell::skew_matrix()
27 {
28 if ( verbose & VERB_DEBUG )
29 cout << "DEBUG UnitCell::skew_matrix: Calculating the fractionalization matrix" << endl;
30
31 if ( alpha() < 0 ) alpha(-alpha());
32 if ( beta() < 0 ) beta(-beta());
33 if ( gamma() < 0 ) gamma(-gamma());
34 if ( alpha() > M_PI || beta() > M_PI || gamma() > M_PI )
35 degrees_to_radians();
36
37 Matrix3 skew;
38
39 double cterm = (cos(beta())*cos(gamma())-
40 cos(alpha()))/
41 (sin(beta())*sin(gamma()));
42 double sterm = sqrt(1.0 - cterm*cterm);
43
44 skew[0][0] = 1.0/a();
45 skew[0][1] = -cos(gamma())/(sin(gamma())*a());
46 skew[0][2] = -(cos(gamma())*sin(beta())*cterm+
47 cos(beta())*sin(gamma()))/
48 (sin(beta())*sterm*sin(gamma())*a());
49 skew[1][1] = 1.0/(sin(gamma())*b());
50 skew[1][2] = cterm/(sterm*sin(gamma())*b());
51 skew[2][2] = 1.0/(sin(beta())*sterm*c());
52
53 for ( size_t i=0; i<3; i++ )
54 for ( size_t j=0; j<3; j++ )
55 if ( skew[i][j] < 1e-6 ) skew[i][j] = 0;
56
57 if ( verbose & VERB_DEBUG ) {
58 cout << "DEBUG UnitCell::skew_matrix: Fractionalization matrix: " << endl;
59 cout << skew << endl;
60 }
61
62 return skew;
63 }
64
65 Matrix3 UnitCell::skew_rotation(int invert)
66 {
67 Matrix3 skew = skew_matrix();
68 Matrix3 mat(1);
69
70 mat[0][0] = skew[0][0]*a();
71 mat[0][1] = skew[0][1]*a();
72 mat[0][2] = skew[0][2]*a();
73 mat[1][1] = skew[1][1]*b();
74 mat[1][2] = skew[1][2]*b();
75 mat[2][2] = skew[2][2]*c();
76
77 if ( invert ) { // Invert the skew matrix
78 mat[0][0] = 1/mat[0][0];
79 mat[1][1] = 1/mat[1][1];
80 mat[2][2] = 1/mat[2][2];
81 mat[0][1] = -mat[0][1]*mat[0][0]*mat[1][1];
82 mat[1][2] = -mat[1][2]*mat[1][1]*mat[2][2];
83 mat[0][2] = mat[0][1]*mat[1][2]/mat[1][1] - mat[0][0]*mat[2][2]*mat[0][2];
84 }
85
86 return mat;
87 }
UnitCell::c
double c()
Definition: UnitCell.h:44
utilities.h
Header file for general utilities.
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:112
Matrix3
Definition: Matrix3.h:17
verbose
int verbose
UnitCell::a
double a()
Definition: UnitCell.h:42
UnitCell::b
double b()
Definition: UnitCell.h:43
UnitCell::beta
double beta()
Definition: UnitCell.h:46
UnitCell::gamma
double gamma()
Definition: UnitCell.h:47
M_PI
#define M_PI
Definition: utilities.h:59
UnitCell::skew_rotation
Matrix3 skew_rotation(int invert)
Definition: UnitCell.cpp:65
UnitCell::degrees_to_radians
void degrees_to_radians()
Definition: UnitCell.h:54
UnitCell.h
Header file for unit cell functions.
UnitCell::skew_matrix
Matrix3 skew_matrix()
Calculates the skew matrix from the unit cell parameters.
Definition: UnitCell.cpp:26
UnitCell::alpha
double alpha()
Definition: UnitCell.h:45