// Trim atoms that very definitely cannot interact with anything inside the image of
// the unit cell with the specified `latt`, assuming that positions were all reduced
// into the cell prior to supercell generation.
//
// This provides a constant factor speedup of about 8 on large systems.
//
// NOTE: This is correct even for arbitrarily-skewed cells.
Trim atoms that very definitely cannot interact with anything inside the image of
the unit cell with the specified `latt`, assuming that positions were all reduced
into the cell prior to supercell generation.

This provides a constant factor speedup of about 8 on large systems.

This is correct even for arbitrarily-skewed cells.
Trim atoms that very definitely cannot interact with anything inside the image of the unit cell with the specified ` latt ` assuming that positions were all reduced into the cell prior to supercell generation . This provides a constant factor speedup of about 8 on large systems . This is correct even for arbitrarily - skewed cells .
fn mask_faraway_atoms(
    prim_lattice: &Lattice,
    super_coords: &Coords,
    interaction_range: f64,
    latt: V3<i32>,
) -> Vec<bool> {
    let mut super_carts = super_coords.to_carts();
    // Move the center of the chosen cell to the origin.
    let center = latt.map(|x| x as f64 + 0.5) * prim_lattice;
    for cart in &mut super_carts {
        *cart -= center;
    }
    let mut good_mask: Vec<bool> = std::iter::repeat(true).take(super_coords.len()).collect();
    // Pick a pair of faces to consider.
    for axis in 0..3 {
        // Consider distances not along the lattice vectors, but rather, along the face normals.
        let miller = V3::axis_unit(axis);
        let plane_spacing = prim_lattice.plane_spacing(miller);
        let normal = prim_lattice.plane_normal(miller);
        // Along the axis represented by `normal`, no matter *how* skewed the cell is, we know that
        // all atoms in the central unit cell have a projection of `abs(x) <= 0.5 * plane_spacing`.
        //
        // This means that anything with a projection `x` with `abs(x) >= 0.5 * plane_spacing +
        // interaction_range` is too far to interact with this image.
        let threshold = 0.5 * plane_spacing + interaction_range ;
        for (i, &cart) in super_carts.iter().enumerate() {
            if V3::dot(&cart, &normal).abs() >= threshold * (1.0+1e-6) {
                good_mask[i] = false;
            }
        }
    }
    good_mask
}
fn mask_faraway_atoms ( prim_lattice : & Lattice , super_coords : & Coords , interaction_range : f64 , latt : V3 < i32 > , ) -> Vec < bool > { let mut super_carts = super_coords . to_carts ( ) ; // Move the center of the chosen cell to the origin. let center = latt . map ( | x | x as f64 + 0.5 ) * prim_lattice ; for cart in & mut super_carts { * cart -= center ; } let mut good_mask : Vec < bool > = std :: iter :: repeat ( true ) . take ( super_coords . len ( ) ) . collect ( ) ; // Pick a pair of faces to consider. for axis in 0 .. 3 { // Consider distances not along the lattice vectors, but rather, along the face normals. let miller = V3 :: axis_unit ( axis ) ; let plane_spacing = prim_lattice . plane_spacing ( miller ) ; let normal = prim_lattice . plane_normal ( miller ) ; // Along the axis represented by `normal`, no matter *how* skewed the cell is, we know that // all atoms in the central unit cell have a projection of `abs(x) <= 0.5 * plane_spacing`. // // This means that anything with a projection `x` with `abs(x) >= 0.5 * plane_spacing + // interaction_range` is too far to interact with this image. let threshold = 0.5 * plane_spacing + interaction_range ; for ( i , & cart ) in super_carts . iter ( ) . enumerate ( ) { if V3 :: dot ( & cart , & normal ) . abs ( ) >= threshold * ( 1.0 + 1e-6 ) { good_mask [ i ] = false ; } } } good_mask }
Trim atoms that very definitely cannot interact with anything inside the image of
the unit cell with the specified `latt`, assuming that positions were all reduced
into the cell prior to supercell generation.
Trim atoms that very definitely cannot interact with anything inside the image of the unit cell with the specified ` latt ` assuming that positions were all reduced into the cell prior to supercell generation .
prim_lattice
&Lattice
super_coords
&Coords
interaction_range
f64
latt
V3<i32>