@@ -205,3 +205,42 @@ def test_smearing_incompatability(self, CalculatorClass, params, device, dtype):
205205 TypeError , match = "Must specify smearing to use a potential with .*"
206206 ):
207207 CalculatorClass (** params )
208+
209+
210+ def test_kspace_filter_error_catch ():
211+ interpolation_nodes = 5
212+
213+ calculator = P3MCalculator (
214+ potential = CoulombPotential (smearing = 1 , exclusion_radius = 4.5 ),
215+ interpolation_nodes = interpolation_nodes ,
216+ full_neighbor_list = True ,
217+ mesh_spacing = 0.5 ,
218+ )
219+
220+ charges = torch .ones ([4 , 1 ])
221+ positions = torch .arange (4 * 3 ).reshape (4 , 3 ).to (torch .float32 )
222+ cell = torch .tensor (
223+ [
224+ [- 2.2958 , - 0.5882 , - 0.0797 ],
225+ [1.3575 , - 0.2575 , - 1.9272 ],
226+ [1.9694 , - 5.7254 , 2.1524 ],
227+ ],
228+ )
229+
230+ neighbor_indices = torch .zeros ((0 , 2 ), dtype = torch .int64 )
231+ neighbor_distances = torch .zeros ((0 ,))
232+
233+ match = (
234+ "NaNs detected in the k-space filter result. This are probably caused "
235+ "by an unsuitable `mesh_spacing`, resulting in a problematic grid of "
236+ r"shape: \[1, 16, 16, 32\]. Try adjsuting the grid by using a "
237+ "different `mesh_spacing` value."
238+ )
239+ with pytest .raises (ValueError , match = match ):
240+ calculator .forward (
241+ charges = charges ,
242+ positions = positions ,
243+ cell = cell ,
244+ neighbor_indices = neighbor_indices ,
245+ neighbor_distances = neighbor_distances ,
246+ )
0 commit comments