Skip to content

Commit

Permalink
Fix origin-shift parse in Hall symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
lan496 committed Mar 16, 2024
1 parent c13dfd9 commit 2cb7fcc
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
34 changes: 31 additions & 3 deletions moyo/src/data/hall_symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ impl HallSymbol {
return None;
}
let origin_shift = Vector3::<f64>::new(
(tokens[0].parse::<i32>().unwrap() / MAX_DENOMINATOR) as f64,
(tokens[1].parse::<i32>().unwrap() / MAX_DENOMINATOR) as f64,
(tokens[2].parse::<i32>().unwrap() / MAX_DENOMINATOR) as f64,
tokens[0].parse::<f64>().unwrap() / MAX_DENOMINATOR as f64,
tokens[1].parse::<f64>().unwrap() / MAX_DENOMINATOR as f64,
tokens[2].parse::<f64>().unwrap() / MAX_DENOMINATOR as f64,
);
Some(origin_shift)
}
Expand Down Expand Up @@ -559,6 +559,7 @@ impl HallSymbol {

#[cfg(test)]
mod tests {
use nalgebra::{matrix, vector};
use rstest::rstest;
use strum::IntoEnumIterator;

Expand All @@ -570,6 +571,7 @@ mod tests {
#[case("P 2 2ab -1ab", Centering::P, 0, 3, 8)] // No. 51
#[case("P 31 2 (0 0 4)", Centering::P, 0, 2, 6)] // No. 151
#[case("P 65", Centering::P, 0, 1, 6)] // No. 170
#[case("P 61 2 (0 0 5)", Centering::P, 0, 2, 12)] // No. 178
#[case("-P 6c 2c", Centering::P, 0, 3, 24)] // No. 194
#[case("F 4d 2 3", Centering::F, 3, 3, 24)] // No. 210
fn test_hall_symbol_small(
Expand All @@ -587,6 +589,32 @@ mod tests {
assert_eq!(operations.num_operations(), num_operations);
}

#[test]
fn test_hall_symbol_generators() {
// No. 178
let hs = HallSymbol::new("P 61 2 (0 0 5)").unwrap();
let generators = hs.generators;
assert_eq!(generators.num_operations(), 2);
assert_eq!(
generators.rotations[0],
matrix![
1, -1, 0;
1, 0, 0;
0, 0, 1;
]
);
assert_relative_eq!(generators.translations[0], vector![0.0, 0.0, 1.0 / 6.0]);
assert_eq!(
generators.rotations[1],
matrix![
0, -1, 0;
-1, 0, 0;
0, 0, -1;
]
);
assert_relative_eq!(generators.translations[1], vector![0.0, 0.0, 5.0 / 6.0]);
}

#[test]
fn test_hall_symbol_whole() {
for entry in iter_hall_symbol_entry() {
Expand Down
40 changes: 40 additions & 0 deletions moyo/tests/test_moyo_dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,43 @@ fn test_with_corundum() {
]
);
}

#[test]
#[allow(non_snake_case)]
fn test_with_hexagonal_Sc() {
// P6_122 (No. 178)
// https://legacy.materialsproject.org/materials/mp-601273/
let a = 3.234;
let c = 16.386;
let lattice = Lattice::new(matrix![
a, 0.0, 0.0;
-a / 2.0, a * 3.0_f64.sqrt() / 2.0, 0.0;
0.0, 0.0, c;
]);
let x_6a = 0.4702;
let positions = vec![
// 6a
Vector3::new(x_6a, 0.0, 0.0),
Vector3::new(0.0, x_6a, 1.0 / 3.0),
Vector3::new(-x_6a, -x_6a, 2.0 / 3.0),
Vector3::new(-x_6a, 0.0, 0.5),
Vector3::new(0.0, -x_6a, 5.0 / 6.0),
Vector3::new(x_6a, x_6a, 1.0 / 6.0),
];
let numbers = vec![0, 0, 0, 0, 0, 0];
let cell = Cell::new(lattice, positions, numbers);

let symprec = 1e-4;
let angle_tolerance = AngleTolerance::Default;
let setting = Setting::Standard;

let dataset = assert_dataset(&cell, symprec, angle_tolerance, setting);
assert_dataset(&dataset.std_cell, symprec, angle_tolerance, setting);
assert_dataset(&dataset.prim_std_cell, symprec, angle_tolerance, setting);

assert_eq!(dataset.number, 178);
assert_eq!(dataset.hall_number, 472);
assert_eq!(dataset.num_operations(), 12);
assert_eq!(dataset.orbits, vec![0, 0, 0, 0, 0, 0]);
assert_eq!(dataset.wyckoffs, vec!['a', 'a', 'a', 'a', 'a', 'a']);
}

0 comments on commit 2cb7fcc

Please sign in to comment.