@@ -64,18 +64,13 @@ def test_numerical_hf_data_h():
64
64
assert np .allclose (sp ._data .dens_tot [- 2 :], [0.0 , 0.0 ], atol = 1e-10 )
65
65
66
66
# evaluate radial density gradient (first derivative of density spline)
67
- dens = sp .dens_func (spin = "t" , log = True )
68
- gradient = dens (sp ._data .rs , deriv = 1 )
67
+ gradient = sp .d_dens_func (log = False )(sp ._data .rs )
69
68
70
- # load gradient reference values from numerical HF raw files
71
- fname = "001_q000_m02_numeric_gradient.npy"
72
- ref_grad = np .load (f"{ TEST_DATAPATH } /numeric/db/{ fname } " )
73
-
74
- # check interpolated gradient values against reference
75
- # close to the nuclei the spline derivative does not describe the gradient well
76
- assert np .allclose (gradient [:2 ], ref_grad [:2 ], atol = 1e-3 )
77
- # away from the nuclei the spline derivative describes the gradient well
78
- assert np .allclose (gradient [- 2 :], ref_grad [- 2 :], atol = 1e-10 )
69
+ # check interpolated gradient values against reference values from numerical HF raw files
70
+ # close to the nuclei
71
+ assert np .allclose (gradient [:2 ], [- 0.636619761671399 , - 0.613581739284137 ], atol = 1e-10 )
72
+ # away from the nuclei
73
+ assert np .allclose (gradient [- 2 :], [0.0 , 0.0 ], atol = 1e-10 )
79
74
80
75
81
76
def test_numerical_hf_data_h_anion ():
@@ -116,18 +111,12 @@ def test_numerical_hf_data_h_anion():
116
111
assert np .allclose (sp ._data .dens_tot [- 20 :], 0.0 , atol = 1e-10 )
117
112
118
113
# evaluate radial density gradient (first derivative of density spline)
119
- dens = sp .dens_func (spin = "t" , log = True )
120
- gradient = dens (sp ._data .rs , deriv = 1 )
121
-
122
- # load gradient reference values from numerical HF raw files
123
- fname = "001_q-01_m01_numeric_gradient.npy"
124
- ref_grad = np .load (f"{ TEST_DATAPATH } /numeric/db/{ fname } " )
114
+ gradient = sp .d_dens_func (log = False )(sp ._data .rs )
125
115
126
- # check interpolated gradient values against reference
127
- # close to the nuclei the spline derivative does not describe the gradient well
128
- assert np .allclose (gradient [:2 ], ref_grad [:2 ], atol = 1e-3 )
129
- # away from the nuclei the spline derivative describes the gradient well
130
- assert np .allclose (gradient [- 2 :], ref_grad [- 2 :], atol = 1e-10 )
116
+ # check interpolated gradient values against reference values from numerical HF raw files
117
+ assert np .allclose (gradient [:2 ], [- 0.618386750431843 , - 0.594311093621533 ], atol = 1e-10 )
118
+ assert np .allclose (gradient [20 :22 ], [- 0.543476018733641 , - 0.538979599233911 ], atol = 1e-10 )
119
+ assert np .allclose (gradient [- 20 :], [0.0 ] * 20 , atol = 1e-10 )
131
120
132
121
133
122
@pytest .mark .parametrize (
@@ -163,7 +152,11 @@ def test_numerical_hf_atomic_density(atom, mult, npoints, nelec):
163
152
assert all (sp ._data .dens_tot >= 0.0 )
164
153
165
154
# check the density integrates to the correct number of electrons
166
- assert_almost_equal (4 * np .pi * np .trapz (grid ** 2 * dens , grid ), nelec , decimal = 2 )
155
+ if hasattr (np , "trapezoid" ):
156
+ int_density = 4.0 * np .pi * np .trapezoid (grid ** 2 * dens , grid )
157
+ else :
158
+ int_density = 4.0 * np .pi * np .trapz (grid ** 2 * dens , grid )
159
+ assert_almost_equal (int_density , nelec , decimal = 2 )
167
160
168
161
# get density spline and check its values
169
162
spline = sp .dens_func (spin = "t" , log = True )
@@ -195,26 +188,48 @@ def test_numerical_hf_density_gradient(atom, charge, mult):
195
188
assert np .allclose (gradient [indx_radii ], ref_grad [indx_radii ], atol = 1e-3 )
196
189
197
190
198
- @pytest .mark .xfail (reason = "High errors in spline derivative of order 2" )
191
+ @pytest .mark .xfail (reason = "High errors in spline derivative of order 2 at intermediate distances " )
199
192
@pytest .mark .parametrize (
200
- "atom, charge, mult" , [("H" , 0 , 2 ), ("H" , - 1 , 1 ), ("Be" , 0 , 1 ), ("Cl" , 0 , 3 ), ("Ne" , 0 , 1 )]
193
+ "atom, charge, mult" , [("H" , 0 , 2 ), ("H" , - 1 , 1 ), ("Be" , 0 , 1 ), ("Cl" , 0 , 2 ), ("Ne" , 0 , 1 )]
201
194
)
202
- def test_numerical_hf_density_laplacian (atom , charge , mult ):
195
+ def test_numerical_hf_dd_density (atom , charge , mult ):
203
196
# load atomic and density data
204
197
sp = load (atom , charge , mult , dataset = "numeric" , datapath = TEST_DATAPATH )
205
198
206
- # evaluate density and laplacian (second derivative of density spline) on the radial grid
207
- grid = sp ._data .rs
208
- spline = sp .dens_func (spin = "t" , log = False )
209
- lapl = spline (grid , deriv = 2 )
199
+ # evaluate the second derivative of the density on the radial grid
200
+ dd_dens = sp .dd_dens_func (log = False )(sp ._data .rs )
210
201
211
202
# check shape of arrays
212
- assert lapl .shape == grid .shape
203
+ assert dd_dens .shape == sp ._data .rs .shape
204
+
205
+ # check interpolated density derivative values against reference values
206
+ # far away from the nuclei, the second derivative of the density is close to zero
207
+ assert np .allclose (dd_dens [- 10 :], [0.0 ] * 10 , atol = 1e-10 )
208
+ # for r=0, the second derivative of the density is set to zero
209
+ assert np .allclose (dd_dens [0 ], [0.0 ], atol = 1e-10 )
210
+
211
+ # WARNING: The values of the second order derivative of the density at intermediate r distances
212
+ # are not tested. Comparisong agains deriv=2 of the density spline:
213
+ # ref_dd_dens = sp.dens_func(log=True)(sp._data.rs, deriv=2)
214
+ # results in high errors, rendering this test case as unreliable.
215
+
216
+
217
+ @pytest .mark .parametrize (
218
+ "atom, charge, mult" , [("H" , 0 , 2 ), ("H" , - 1 , 1 ), ("Be" , 0 , 1 ), ("Cl" , 0 , 2 ), ("Ne" , 0 , 1 )]
219
+ )
220
+ def test_numerical_hf_density_laplacian (atom , charge , mult ):
221
+ # load atomic and density data
222
+ sp = load (atom , charge , mult , dataset = "numeric" , datapath = TEST_DATAPATH )
223
+
224
+ # evaluate the Laplacian of the density on the radial grid
225
+ laplacian_dens = sp .dd_dens_lapl_func (log = False )(sp ._data .rs )
213
226
214
227
# load reference values from numerical HF raw files
215
228
id = f"{ str (sp .atnum ).zfill (3 )} _q{ str (charge ).zfill (3 )} _m{ mult :02d} "
216
229
fname = f"{ id } _numeric_laplacian.npy"
217
230
ref_lapl = np .load (f"{ TEST_DATAPATH } /numeric/db/{ fname } " )
218
231
219
- # interpolated laplacian values against reference
220
- assert np .allclose (lapl , ref_lapl , atol = 1e-6 )
232
+ # check interpolated Laplacian of density values against reference values
233
+ assert np .allclose (laplacian_dens , ref_lapl , atol = 1e-10 )
234
+ # for r=0, the Laplacian function in not well defined and is set to zero
235
+ assert np .allclose (laplacian_dens [0 ], [0.0 ], atol = 1e-10 )
0 commit comments