@@ -352,26 +352,40 @@ def test_get_points_in_sphere(self):
352352 # This is a non-niggli representation of a cubic lattice
353353 lattice = Lattice ([[1 , 5 , 0 ], [0 , 1 , 0 ], [5 , 0 , 1 ]])
354354 # evenly spaced points array between 0 and 1
355- pts = np .array (list (itertools .product (range (5 ), repeat = 3 ))) / 5
356- pts = lattice .get_fractional_coords (pts )
355+ points = np .array (list (itertools .product (range (5 ), repeat = 3 ))) / 5
356+ points = lattice .get_fractional_coords (points )
357357
358358 # Test getting neighbors within 1 neighbor distance of the origin
359- fcoords , dists , inds , images = lattice .get_points_in_sphere (pts , [0 , 0 , 0 ], 0.20001 , zip_results = False )
360- assert len (fcoords ) == 7 # There are 7 neighbors
359+ frac_coords , dists , indices , images = lattice .get_points_in_sphere (
360+ points , [0 , 0 , 0 ], 0.20001 , zip_results = False
361+ )
362+ assert len (frac_coords ) == 7 # There are 7 neighbors
361363 assert np .isclose (dists , 0.2 ).sum () == 6 # 6 are at 0.2
362364 assert np .isclose (dists , 0 ).sum () == 1 # 1 is at 0
363- assert len (set (inds )) == 7 # They have unique indices
364- assert_array_equal ( images [np .isclose (dists , 0 )], [[0 , 0 , 0 ]])
365+ assert len (set (indices )) == 7 # They have unique indices
366+ assert images [np .isclose (dists , 0 )]. tolist () == [[0 , 0 , 0 ]]
365367
366368 # More complicated case, using the zip output
367- result = lattice .get_points_in_sphere (pts , [0.5 , 0.5 , 0.5 ], 1.0001 )
369+ result = lattice .get_points_in_sphere (points , [0.5 , 0.5 , 0.5 ], 1.0001 )
370+ assert isinstance (result , tuple )
368371 assert len (result ) == 552
369- assert len (result [0 ]) == 4 # coords, dists, ind , supercell
372+ assert len (result [0 ]) == 4 # coords, dists, indices , supercell
370373
371374 # test pbc
372375 latt_pbc = Lattice ([[1 , 5 , 0 ], [0 , 1 , 0 ], [5 , 0 , 1 ]], pbc = (True , True , False ))
373- fcoords , dists , inds , images = latt_pbc .get_points_in_sphere (pts , [0 , 0 , 0 ], 0.20001 , zip_results = False )
374- assert len (fcoords ) == 6
376+ frac_coords , dists , indices , images = latt_pbc .get_points_in_sphere (
377+ points , [0 , 0 , 0 ], 0.20001 , zip_results = False
378+ )
379+ assert len (frac_coords ) == 6
380+
381+ # ensure consistent return type if zip_results=False and no points in sphere are found
382+ # https://github.com/materialsproject/pymatgen/issues/3794
383+ result = lattice .get_points_in_sphere (points , [0.5 , 0.5 , 0.5 ], 0.0001 , zip_results = False )
384+ assert isinstance (result , tuple )
385+ assert len (result ) == 4
386+ assert all (len (arr ) == 0 for arr in result )
387+ types = {* map (type , result )}
388+ assert types == {np .ndarray }, f"Expected only np.ndarray, got { types } "
375389
376390 def test_get_all_distances (self ):
377391 fcoords = np .array (
0 commit comments