Skip to content

Commit 0fe681c

Browse files
committed
Make sure to look in enough sub-cells when computing neighbors list
1 parent e540e97 commit 0fe681c

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

rascaline/src/systems/neighbors.rs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ impl CellList {
132132
// number of cells to search in each direction to make sure all possible
133133
// pairs below the cutoff are accounted for.
134134
let mut n_search = [
135-
f64::trunc(cutoff * n_cells[0] / distances_between_faces[0]) as i32,
136-
f64::trunc(cutoff * n_cells[1] / distances_between_faces[1]) as i32,
137-
f64::trunc(cutoff * n_cells[2] / distances_between_faces[2]) as i32,
135+
f64::ceil(cutoff * n_cells[0] / distances_between_faces[0]) as i32,
136+
f64::ceil(cutoff * n_cells[1] / distances_between_faces[1]) as i32,
137+
f64::ceil(cutoff * n_cells[2] / distances_between_faces[2]) as i32,
138138
];
139139

140140
let n_cells = [
@@ -394,8 +394,7 @@ impl NeighborsList {
394394
mod tests {
395395
use approx::assert_ulps_eq;
396396

397-
use crate::Matrix3;
398-
397+
use crate::types::Matrix3;
399398
use super::*;
400399

401400
#[test]
@@ -512,4 +511,39 @@ mod tests {
512511
assert_eq!(&pair.cell_shift_indices, shifts);
513512
}
514513
}
514+
515+
#[test]
516+
fn non_cubic_cell() {
517+
let cell = UnitCell::from(Matrix3::new([
518+
[4.26, -2.45951215, 0.0],
519+
[2.13, 1.22975607, 0.0],
520+
[0.0, 0.0, 50.0],
521+
]));
522+
let positions = [
523+
Vector3D::new(1.42, 0.0, 0.0),
524+
Vector3D::new(2.84, 0.0, 0.0),
525+
Vector3D::new(3.55, -1.22975607, 0.0),
526+
Vector3D::new(4.97, -1.22975607, 0.0),
527+
];
528+
let neighbors = NeighborsList::new(&positions, cell, 6.4);
529+
530+
assert_eq!(neighbors.pairs.len(), 90);
531+
532+
let previously_missing = [
533+
(0, 3, [-2, 0, 0]),
534+
(0, 3, [-2, 1, 0]),
535+
(0, 3, [-2, 2, 0]),
536+
];
537+
538+
for missing in previously_missing {
539+
let mut found = false;
540+
for pair in &neighbors.pairs {
541+
if pair.first == missing.0 && pair.second == missing.1
542+
&& pair.cell_shift_indices == missing.2 {
543+
found = true;
544+
}
545+
}
546+
assert!(found, "could not find pair {:?}", missing);
547+
}
548+
}
515549
}

0 commit comments

Comments
 (0)