Skip to content

Commit

Permalink
Recover Bravais group
Browse files Browse the repository at this point in the history
  • Loading branch information
lan496 committed Apr 6, 2024
1 parent cea78b3 commit 2624998
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 26 deletions.
4 changes: 4 additions & 0 deletions moyo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ union-find = "0.4.2"
strum = "0.25"
strum_macros = "0.25"
kiddo = "4.2.0"
# Disable trace and debug level logs in release build
log = { version = "0.4", features = ["release_max_level_info"] }

[dev-dependencies]
rand = "0.8.5"
rstest = "0.18.2"
criterion = { version = "0.4", features = ["html_reports"] }
env_logger = "0.11.3"
test-log = "0.2.15"

[[bench]]
name = "translation_search"
Expand Down
6 changes: 6 additions & 0 deletions moyo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@
math <- base <- data <- identify <- standardize <- lib
^---- search <--------------|
```

## Debugging

```shell
RUST_LOG=debug cargo test -- --nocapture
```
34 changes: 9 additions & 25 deletions moyo/src/search/symmetry_search.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use itertools::iproduct;
use std::collections::HashSet;

use log::{debug, warn};
use nalgebra::{Matrix3, Vector3};

use super::solve::{
pivot_site_indices, solve_correspondence, symmetrize_translation_from_permutation,
PeriodicKdTree,
};
use crate::base::{
AngleTolerance, Cell, Lattice, MoyoError, Operations, Permutation, Position, Rotation, EPS,
traverse, AngleTolerance, Cell, Lattice, MoyoError, Operations, Permutation, Position,
Rotation, EPS,
};

#[derive(Debug)]
Expand Down Expand Up @@ -190,19 +191,13 @@ fn search_bravais_group(
return Err(MoyoError::BravaisGroupSearchError);
}

// Check to reproduce rotation operations by group multiplication
let mut rotation_set = HashSet::new();
for rotation in rotations.iter() {
rotation_set.insert(*rotation);
// Complement rotations by group multiplication
let complemented_rotations = traverse(&rotations);
if complemented_rotations.len() != rotations.len() {
warn!("Found automorphisms for the lattice do not form a group. symprec and angle_tolerance may be too large.");
}
for (r1, r2) in iproduct!(rotation_set.iter(), rotation_set.iter()) {
let r12 = r1 * r2;
if !rotation_set.contains(&r12) {
return Err(MoyoError::BravaisGroupSearchError);
}
}

Ok(rotations)
debug!("Order of Bravais group: {}", complemented_rotations.len());
Ok(complemented_rotations)
}

/// Compare (basis.column(col1), basis.column(col2)) and (b1, b2)
Expand Down Expand Up @@ -278,16 +273,5 @@ mod tests {
search_bravais_group(&lattice, symprec, AngleTolerance::Default).unwrap();
assert_eq!(rotations.len(), 48);
}

{
let lattice = Lattice::new(matrix![
0.0, 14.30286652, 7.15143326;
0.0, 0.0, 12.38674029;
13.9744737, 0.0, 0.0;
]);
let rotations =
search_bravais_group(&lattice, symprec, AngleTolerance::Default).unwrap();
assert_eq!(rotations.len(), 24);
}
}
}
3 changes: 2 additions & 1 deletion moyo/tests/test_moyo_dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use nalgebra::{matrix, vector, Matrix3, Vector3};
use serde_json;
use std::fs;
use std::path::Path;
use test_log::test;

use moyo::base::{AngleTolerance, Cell, Lattice, Permutation, Rotation, Translation};
use moyo::data::Setting;
Expand Down Expand Up @@ -448,7 +449,7 @@ fn test_with_mp_1197586() {
let path = Path::new("tests/assets/mp-1197586.json");
let cell: Cell = serde_json::from_str(&fs::read_to_string(&path).unwrap()).unwrap();

let symprec = 1e-4;
let symprec = 1e-3; // 1e-4 gives C2/m
let angle_tolerance = AngleTolerance::Default;
let setting = Setting::Standard;

Expand Down

0 comments on commit 2624998

Please sign in to comment.