[−][src]Function bader::methods::weight
pub fn weight(
p: usize,
density: &Density<'_>,
weight_map: WeightMap
) -> (isize, Vec<(usize, f64)>)
Finds the maxima associated with the current point, p.
Note: This function will deadlock if the points above it have no associated
maxima in [VoxelMap.voxel_map
].
p
: The point from which to step.density
: The referenceDensity
.weight_map
: AnArc
wrappedVoxelMap
for tracking the maxima.
Returns:
(isize, Vec::<f64>::with_capacity(14))
: The maxima associated with the
point, p, and it's associated weights.
Examples
use bader::density::Density; use bader::atoms::Lattice; use bader::voxel_map::VoxelMap; use bader::methods::weight; use std::sync::Arc; // Intialise the reference density. let data = (0..64).map(|rho| rho as f64).collect::<Vec<f64>>(); let lattice = Lattice::new([[3., 0., 0.], [0., 3., 0.], [0., 0., 3.]]); let density = Density::new(&data, [4, 4, 4], lattice.to_cartesian, 1E-8, None, [0., 0., 0.]); let voxel_map = VoxelMap::new(64); let voxel_map = Arc::new(voxel_map); // The highest gradient between point, p = 33, and it's neighbours, with // periodic boundary conditions, is with point p = 61. // to avoid deadlock let's store maxima for all the values above us and // store as either 61 or 62 to make the current point a boundary. for i in [34, 37, 45, 49].iter() { voxel_map.maxima_store(*i, 62 - i % 2); } let (p_maxima, weights) = weight(33, &density, Arc::clone(&voxel_map)); let mut maxima = weights.into_iter().map(|(m, w)| m).collect::<Vec<usize>>(); maxima.sort_unstable(); assert_eq!(p_maxima, 61); assert_eq!(maxima, vec![61, 62]);