@@ -132,9 +132,9 @@ impl CellList {
132
132
// number of cells to search in each direction to make sure all possible
133
133
// pairs below the cutoff are accounted for.
134
134
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 ,
138
138
] ;
139
139
140
140
let n_cells = [
@@ -394,8 +394,7 @@ impl NeighborsList {
394
394
mod tests {
395
395
use approx:: assert_ulps_eq;
396
396
397
- use crate :: Matrix3 ;
398
-
397
+ use crate :: types:: Matrix3 ;
399
398
use super :: * ;
400
399
401
400
#[ test]
@@ -512,4 +511,39 @@ mod tests {
512
511
assert_eq ! ( & pair. cell_shift_indices, shifts) ;
513
512
}
514
513
}
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
+ }
515
549
}
0 commit comments