@@ -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 = [
@@ -407,8 +407,7 @@ impl NeighborsList {
407407mod tests {
408408 use approx:: assert_ulps_eq;
409409
410- use crate :: Matrix3 ;
411-
410+ use crate :: types:: Matrix3 ;
412411 use super :: * ;
413412
414413 #[ test]
@@ -525,4 +524,39 @@ mod tests {
525524 assert_eq ! ( & pair. cell_shift_indices, shifts) ;
526525 }
527526 }
527+
528+ #[ test]
529+ fn non_cubic_cell ( ) {
530+ let cell = UnitCell :: from ( Matrix3 :: new ( [
531+ [ 4.26 , -2.45951215 , 0.0 ] ,
532+ [ 2.13 , 1.22975607 , 0.0 ] ,
533+ [ 0.0 , 0.0 , 50.0 ] ,
534+ ] ) ) ;
535+ let positions = [
536+ Vector3D :: new ( 1.42 , 0.0 , 0.0 ) ,
537+ Vector3D :: new ( 2.84 , 0.0 , 0.0 ) ,
538+ Vector3D :: new ( 3.55 , -1.22975607 , 0.0 ) ,
539+ Vector3D :: new ( 4.97 , -1.22975607 , 0.0 ) ,
540+ ] ;
541+ let neighbors = NeighborsList :: new ( & positions, cell, 6.4 ) ;
542+
543+ assert_eq ! ( neighbors. pairs. len( ) , 90 ) ;
544+
545+ let previously_missing = [
546+ ( 0 , 3 , [ -2 , 0 , 0 ] ) ,
547+ ( 0 , 3 , [ -2 , 1 , 0 ] ) ,
548+ ( 0 , 3 , [ -2 , 2 , 0 ] ) ,
549+ ] ;
550+
551+ for missing in previously_missing {
552+ let mut found = false ;
553+ for pair in & neighbors. pairs {
554+ if pair. first == missing. 0 && pair. second == missing. 1
555+ && pair. cell_shift_indices == missing. 2 {
556+ found = true ;
557+ }
558+ }
559+ assert ! ( found, "could not find pair {:?}" , missing) ;
560+ }
561+ }
528562}
0 commit comments