diff --git a/moyo/src/base/operation.rs b/moyo/src/base/operation.rs index 03c3067..1bac86a 100644 --- a/moyo/src/base/operation.rs +++ b/moyo/src/base/operation.rs @@ -1,5 +1,7 @@ use std::collections::{HashSet, VecDeque}; +use std::iter::Zip; use std::ops::Mul; +use std::slice::Iter; use nalgebra::base::{Matrix3, Vector3}; @@ -43,6 +45,10 @@ impl Operations { .map(|r| lattice.basis * r.map(|e| e as f64) * inv_basis) .collect() } + + pub fn iter(&self) -> Zip, Iter> { + self.rotations.iter().zip(self.translations.iter()) + } } #[derive(Debug, PartialEq, Eq, Clone, Hash)] diff --git a/moyo/src/base/transformation.rs b/moyo/src/base/transformation.rs index efc40d0..39b1e4f 100644 --- a/moyo/src/base/transformation.rs +++ b/moyo/src/base/transformation.rs @@ -59,11 +59,7 @@ impl UnimodularTransformation { pub fn transform_operations(&self, operations: &Operations) -> Operations { let mut new_rotations = vec![]; let mut new_translations = vec![]; - for (rotation, translation) in operations - .rotations - .iter() - .zip(operations.translations.iter()) - { + for (rotation, translation) in operations.iter() { let new_rotation = self.linear_inv * rotation * self.linear; let new_translation = self.linear_inv.map(|e| e as f64) * (rotation.map(|e| e as f64) * self.origin_shift + translation @@ -141,11 +137,7 @@ impl Transformation { pub fn transform_operations(&self, operations: &Operations) -> Operations { let mut new_rotations = vec![]; let mut new_translations = vec![]; - for (rotation, translation) in operations - .rotations - .iter() - .zip(operations.translations.iter()) - { + for (rotation, translation) in operations.iter() { if let Some((new_rotation, new_translation)) = transform_operation_as_f64( rotation, translation, @@ -165,11 +157,7 @@ impl Transformation { pub fn inverse_transform_operations(&self, operations: &Operations) -> Operations { let mut new_rotations = vec![]; let mut new_translations = vec![]; - for (rotation, translation) in operations - .rotations - .iter() - .zip(operations.translations.iter()) - { + for (rotation, translation) in operations.iter() { if let Some((new_rotation, new_translation)) = transform_operation_as_f64( rotation, translation, diff --git a/moyo/src/data/hall_symbol.rs b/moyo/src/data/hall_symbol.rs index ab36d4f..ea604cc 100644 --- a/moyo/src/data/hall_symbol.rs +++ b/moyo/src/data/hall_symbol.rs @@ -237,12 +237,7 @@ impl HallSymbol { rotations.push(rotation_lhs); translations.push(translation_lhs); - for (rotation_rhs, translation_rhs) in self - .generators - .rotations - .iter() - .zip(self.generators.translations.iter()) - { + for (rotation_rhs, translation_rhs) in self.generators.iter() { let new_rotation = rotation_lhs * rotation_rhs; let new_translation = rotation_lhs.map(|e| e as f64) * translation_rhs + translation_lhs; diff --git a/moyo/src/identify/space_group.rs b/moyo/src/identify/space_group.rs index 73fafe0..14e596f 100644 --- a/moyo/src/identify/space_group.rs +++ b/moyo/src/identify/space_group.rs @@ -168,11 +168,7 @@ fn match_origin_shift( let new_prim_operations = UnimodularTransformation::from_linear(*trans_mat).transform_operations(prim_operations); let mut hm_translations = HashMap::new(); - for (rotation, translation) in new_prim_operations - .rotations - .iter() - .zip(new_prim_operations.translations.iter()) - { + for (rotation, translation) in new_prim_operations.iter() { hm_translations.insert(*rotation, *translation); } @@ -186,12 +182,7 @@ fn match_origin_shift( // <-> (R - E) * s = t_db - t_target (mod 1) let mut a = OMatrix::::zeros(3 * db_prim_generators.rotations.len()); let mut b = OVector::::zeros(3 * db_prim_generators.rotations.len()); - for (k, (rotation, other_translation)) in db_prim_generators - .rotations - .iter() - .zip(db_prim_generators.translations.iter()) - .enumerate() - { + for (k, (rotation, other_translation)) in db_prim_generators.iter().enumerate() { // Correction transformation matrix may not be normalizer of the point group. For example, mm2 -> 2mm let target_translation = hm_translations.get(rotation)?; @@ -297,11 +288,7 @@ mod tests { UnimodularTransformation::from_linear(*corr).transform_operations(&prim_operations); let mut hm_translations = HashMap::new(); - for (rotation, translation) in corr_prim_operations - .rotations - .iter() - .zip(corr_prim_operations.translations.iter()) - { + for (rotation, translation) in corr_prim_operations.iter() { hm_translations.insert(rotation.clone(), translation.clone()); } let r = matrix![ @@ -349,11 +336,7 @@ mod tests { .inverse_transform_operations(&matched_operations); let mut hm_translations = HashMap::new(); - for (rotation, translation) in matched_prim_operations - .rotations - .iter() - .zip(matched_prim_operations.translations.iter()) - { + for (rotation, translation) in matched_prim_operations.iter() { hm_translations.insert(rotation, translation); } @@ -365,11 +348,7 @@ mod tests { matched_prim_operations.rotations.len(), transformed_prim_operations.rotations.len() ); - for (rotation, translation) in transformed_prim_operations - .rotations - .iter() - .zip(transformed_prim_operations.translations.iter()) - { + for (rotation, translation) in transformed_prim_operations.iter() { assert!(hm_translations.contains_key(rotation)); let mut diff = *hm_translations.get(rotation).unwrap() - translation; diff -= diff.map(|e| e.round()); // in [-0.5, 0.5] diff --git a/moyo/src/lib.rs b/moyo/src/lib.rs index b953b79..3b7182d 100644 --- a/moyo/src/lib.rs +++ b/moyo/src/lib.rs @@ -284,11 +284,7 @@ fn operations_in_cell(prim_cell: &PrimitiveCell, prim_operations: &Operations) - let input_operations = Transformation::from_linear(prim_cell.linear).transform_operations(prim_operations); for t1 in prim_cell.translations.iter() { - for (rotation, t2) in input_operations - .rotations - .iter() - .zip(input_operations.translations.iter()) - { + for (rotation, t2) in input_operations.iter() { // (E, t1) (rotation, t2) = (rotation, t1 + t2) rotations.push(*rotation); let t12 = (t1 + t2).map(|e| e % 1.); diff --git a/moyo/src/symmetrize/standardize.rs b/moyo/src/symmetrize/standardize.rs index 4cf0dd6..e0a9258 100644 --- a/moyo/src/symmetrize/standardize.rs +++ b/moyo/src/symmetrize/standardize.rs @@ -312,11 +312,9 @@ fn symmetrize_positions( (0..cell.num_atoms()) .map(|i| { let mut acc = Vector3::zeros(); - for (inv_perm, rotation, translation) in izip!( - inverse_permutations.iter(), - operations.rotations.iter(), - operations.translations.iter(), - ) { + for (inv_perm, (rotation, translation)) in + inverse_permutations.iter().zip(operations.iter()) + { let mut frac_displacements = rotation.map(|e| e as f64) * cell.positions[inv_perm.apply(i)] + translation - cell.positions[i]; diff --git a/moyo/tests/test_moyo_dataset.rs b/moyo/tests/test_moyo_dataset.rs index 02d6644..47fc747 100644 --- a/moyo/tests/test_moyo_dataset.rs +++ b/moyo/tests/test_moyo_dataset.rs @@ -32,12 +32,7 @@ fn assert_dataset( } } - for (rotation, translation) in dataset - .operations - .rotations - .iter() - .zip(dataset.operations.translations.iter()) - { + for (rotation, translation) in dataset.operations.iter() { // Check if operation induces permutation let permutation = permutation_from_operation(cell, rotation, translation).unwrap(); diff --git a/moyopy/src/data.rs b/moyopy/src/data.rs index da2d96f..2a7f0a7 100644 --- a/moyopy/src/data.rs +++ b/moyopy/src/data.rs @@ -38,7 +38,7 @@ pub fn operations_from_number( let lattice_points = hs.centering.lattice_points(); for t1 in lattice_points.iter() { - for (r2, t2) in coset.rotations.iter().zip(coset.translations.iter()) { + for (r2, t2) in coset.iter() { // (E, t1) (r2, t2) = (r2, t1 + t2) rotations.push(*r2); let t12 = (t1 + t2).map(|e| e % 1.); @@ -58,11 +58,7 @@ mod tests { fn unique_sites(position: &Position, operations: &Operations) -> Vec { let mut sites: Vec = vec![]; - for (rotation, translation) in operations - .rotations - .iter() - .zip(operations.translations.iter()) - { + for (rotation, translation) in operations.iter() { let new_site = rotation.map(|e| e as f64) * position + translation; let mut overlap = false; for site in sites.iter() {