1
2
3
4
5
6
7
8
9
10
11
12
13
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
use nalgebra::{Matrix3, Vector3};
use serde::Serialize;
use strum_macros::EnumIter;
use crate::base::{Linear, Translation};
#[derive(Debug, Copy, Clone, PartialEq, EnumIter, Serialize)]
pub enum Centering {
P, // Primitive
A, // A-face centered
B, // B-face centered
C, // C-face centered
I, // Body centered
R, // Rhombohedral (obverse setting)
F, // Face centered
}
impl Centering {
pub fn order(&self) -> usize {
match self {
Centering::P => 1,
Centering::A => 2,
Centering::B => 2,
Centering::C => 2,
Centering::I => 2,
Centering::R => 3,
Centering::F => 4,
}
}
/// Transformation matrix from primitive to conventional cell.
// Inverse matrices of https://github.com/spglib/spglib/blob/39a95560dd831c2d16f162126921ac1e519efa31/src/spacegroup.c#L373-L384
pub fn linear(&self) -> Linear {
match self {
Centering::P => Linear::identity(),
Centering::A => Linear::new(
1, 0, 0, //
0, 1, 1, //
0, -1, 1, //
),
Centering::B => Linear::new(
1, 0, -1, //
0, 1, 0, //
1, 0, 1, //
),
Centering::C => Linear::new(
1, -1, 0, //
1, 1, 0, //
0, 0, 1, //
),
Centering::R => Linear::new(
1, 0, 1, //
-1, 1, 1, //
0, -1, 1, //
),
Centering::I => Linear::new(
0, 1, 1, //
1, 0, 1, //
1, 1, 0, //
),
Centering::F => Linear::new(
-1, 1, 1, //
1, -1, 1, //
1, 1, -1, //
),
}
}
/// Transformation matrix from conventional to primitive cell.
pub fn inverse(&self) -> Matrix3<f64> {
self.linear().map(|e| e as f64).try_inverse().unwrap()
}
pub fn lattice_points(&self) -> Vec<Vector3<f64>> {
match self {
Centering::P => {
vec![Translation::new(0.0, 0.0, 0.0)]
}
Centering::A => {
vec![
Translation::new(0.0, 0.0, 0.0),
Translation::new(0.0, 0.5, 0.5),
]
}
Centering::B => {
vec![
Translation::new(0.0, 0.0, 0.0),
Translation::new(0.5, 0.0, 0.5),
]
}
Centering::C => {
vec![
Translation::new(0.0, 0.0, 0.0),
Translation::new(0.5, 0.5, 0.0),
]
}
Centering::I => {
vec![
Translation::new(0.0, 0.0, 0.0),
Translation::new(0.5, 0.5, 0.5),
]
}
Centering::R => {
// obverse setting
vec![
Translation::new(0.0, 0.0, 0.0),
Translation::new(2.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0),
Translation::new(1.0 / 3.0, 2.0 / 3.0, 2.0 / 3.0),
]
}
// Centering::H => {
// vec![
// Translation::new(0.0, 0.0, 0.0),
// Translation::new(2.0 / 3.0, 1.0 / 3.0, 0.0),
// Translation::new(1.0 / 3.0, 2.0 / 3.0, 0.0),
// ]
// }
Centering::F => {
vec![
Translation::new(0.0, 0.0, 0.0),
Translation::new(0.0, 0.5, 0.5),
Translation::new(0.5, 0.0, 0.5),
Translation::new(0.5, 0.5, 0.0),
]
}
}
}
}
#[cfg(test)]
mod tests {
use strum::IntoEnumIterator;
use super::*;
use crate::base::Transformation;
#[test]
fn test_conventional_transformation_matrix() {
for centering in Centering::iter() {
assert_eq!(
Transformation::from_linear(centering.linear()).size,
centering.order()
);
}
}
}