Skip to content

Commit 79237b2

Browse files
authored
np.(arange->linspace) in io/vasp/optics.py get_delta, get_setp and epsilon_imag (#3286)
`np.linspace` ensures the array size is numerically stable. See the [`numpy.arange` warning](https://numpy.org/doc/stable/reference/generated/numpy.arange.html).
1 parent e4792d1 commit 79237b2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pymatgen/io/vasp/optics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def get_delta(x0: float, sigma: float, nx: int, dx: float, ismear: int = 3):
310310
np.array: Array of size `nx` with delta function on the desired outputgrid.
311311
312312
"""
313-
xgrid = np.arange(0, nx * dx, dx)
313+
xgrid = np.linspace(0, nx * dx, nx, endpoint=False)
314314
xgrid -= x0
315315
x_scaled = (xgrid + (dx / 2)) / sigma
316316
sfun = step_func(x_scaled, ismear)
@@ -334,7 +334,7 @@ def get_step(x0, sigma, nx, dx, ismear):
334334
Return:
335335
np.array: Array of size `nx` with step function on the desired outputgrid.
336336
"""
337-
xgrid = np.arange(0, nx * dx, dx)
337+
xgrid = np.linspace(0, nx * dx, nx, endpoint=False)
338338
xgrid -= x0
339339
x_scaled = (xgrid + (dx / 2)) / sigma
340340
return step_func(x_scaled, ismear)
@@ -373,7 +373,7 @@ def epsilon_imag(
373373
374374
"""
375375
norm_kweights = np.array(kweights) / np.sum(kweights)
376-
egrid = np.arange(0, nedos * deltae, deltae)
376+
egrid = np.linspace(0, nedos * deltae, nedos, endpoint=False)
377377
eigs_shifted = eigs - efermi
378378
# np.subtract.outer results in a matrix of shape (nband, nband)
379379
rspin = 3 - cder.shape[3]

0 commit comments

Comments
 (0)