fn maxima_to_atom(chunk: &[isize],
                  atoms: &Atoms,
                  grid: &Grid,
                  progress_bar: &Bar)
                  -> Result<(Vec<usize>, Vec<f64>)> {
    let chunk_size = chunk.len();
    // create vectors for storing the assigned atom and distance for each maxima
    let mut ass_atom = Vec::with_capacity(chunk_size);
    let mut min_dist = Vec::with_capacity(chunk_size);
    for m in chunk.iter() {
        // convert the point first to cartesian, then to the reduced basis
        let m_cartesian = grid.to_cartesian(*m as isize);
        let m_reduced_cartesian = atoms.reduced_lattice.to_reduced(m_cartesian);
        let mut atom_num = 0;
        let mut min_distance = f64::INFINITY;
        // go through each atom in the reduced basis and shift in each
        // reduced direction, save the atom with the shortest distance
        for (i, atom) in atoms.reduced_positions.iter().enumerate() {
            for atom_shift in
                atoms.reduced_lattice.cartesian_shift_matrix.iter()
            {
                let distance = {
                    (m_reduced_cartesian[0]
                                        - (atom[0] + atom_shift[0]))
                                                                    .powi(2)
                                       + (m_reduced_cartesian[1]
                                          - (atom[1] + atom_shift[1]))
                                                                      .powi(2)
                                       + (m_reduced_cartesian[2]
                                          - (atom[2] + atom_shift[2]))
                                                                      .powi(2)
                };
                if distance < min_distance {
                    min_distance = distance;
                    atom_num = i;
                }
            }
        }
        // remember to square root the distance
        ass_atom.push(atom_num);
        min_dist.push(min_distance.powf(0.5));
        progress_bar.tick()
    }
    Ok((ass_atom, min_dist))
}
/// Calculates the distance between a maxima and its nearest atom.
/// Chunk represents a collection of bader maxima positions withing the density
/// array.
Calculates the distance between a maxima and its nearest atom.
Chunk represents a collection of bader maxima positions withing the density
array.
Calculates the distance between a maxima and its nearest atom . Chunk represents a collection of bader maxima positions withing the density array .
fn maxima_to_atom(chunk: &[isize],
                  atoms: &Atoms,
                  grid: &Grid,
                  progress_bar: &Bar)
                  -> Result<(Vec<usize>, Vec<f64>)> {
    let chunk_size = chunk.len();
    // create vectors for storing the assigned atom and distance for each maxima
    let mut ass_atom = Vec::with_capacity(chunk_size);
    let mut min_dist = Vec::with_capacity(chunk_size);
    for m in chunk.iter() {
        // convert the point first to cartesian, then to the reduced basis
        let m_cartesian = grid.to_cartesian(*m as isize);
        let m_reduced_cartesian = atoms.reduced_lattice.to_reduced(m_cartesian);
        let mut atom_num = 0;
        let mut min_distance = f64::INFINITY;
        // go through each atom in the reduced basis and shift in each
        // reduced direction, save the atom with the shortest distance
        for (i, atom) in atoms.reduced_positions.iter().enumerate() {
            for atom_shift in
                atoms.reduced_lattice.cartesian_shift_matrix.iter()
            {
                let distance = {
                    (m_reduced_cartesian[0]
                                        - (atom[0] + atom_shift[0]))
                                                                    .powi(2)
                                       + (m_reduced_cartesian[1]
                                          - (atom[1] + atom_shift[1]))
                                                                      .powi(2)
                                       + (m_reduced_cartesian[2]
                                          - (atom[2] + atom_shift[2]))
                                                                      .powi(2)
                };
                if distance < min_distance {
                    min_distance = distance;
                    atom_num = i;
                }
            }
        }
        // remember to square root the distance
        ass_atom.push(atom_num);
        min_dist.push(min_distance.powf(0.5));
        progress_bar.tick()
    }
    Ok((ass_atom, min_dist))
}
fn maxima_to_atom ( chunk : & [ isize ] , atoms : & Atoms , grid : & Grid , progress_bar : & Bar ) -> Result < ( Vec < usize > , Vec < f64 > ) > { let chunk_size = chunk . len ( ) ; // create vectors for storing the assigned atom and distance for each maxima let mut ass_atom = Vec :: with_capacity ( chunk_size ) ; let mut min_dist = Vec :: with_capacity ( chunk_size ) ; for m in chunk . iter ( ) { // convert the point first to cartesian, then to the reduced basis let m_cartesian = grid . to_cartesian ( * m as isize ) ; let m_reduced_cartesian = atoms . reduced_lattice . to_reduced ( m_cartesian ) ; let mut atom_num = 0 ; let mut min_distance = f64 :: INFINITY ; // go through each atom in the reduced basis and shift in each // reduced direction, save the atom with the shortest distance for ( i , atom ) in atoms . reduced_positions . iter ( ) . enumerate ( ) { for atom_shift in atoms . reduced_lattice . cartesian_shift_matrix . iter ( ) { let distance = { ( m_reduced_cartesian [ 0 ] - ( atom [ 0 ] + atom_shift [ 0 ] ) ) . powi ( 2 ) + ( m_reduced_cartesian [ 1 ] - ( atom [ 1 ] + atom_shift [ 1 ] ) ) . powi ( 2 ) + ( m_reduced_cartesian [ 2 ] - ( atom [ 2 ] + atom_shift [ 2 ] ) ) . powi ( 2 ) } ; if distance < min_distance { min_distance = distance ; atom_num = i ; } } } // remember to square root the distance ass_atom . push ( atom_num ) ; min_dist . push ( min_distance . powf ( 0.5 ) ) ; progress_bar . tick ( ) } Ok ( ( ass_atom , min_dist ) ) }
Calculates the distance between a maxima and its nearest atom.
Calculates the distance between a maxima and its nearest atom .
chunk
&[isize]
atoms
&Atoms
grid
&Grid
progress_bar
&Bar
chunk
&[isize]
atoms
&Atoms
grid
&Grid
progress_bar
&Bar