1
1
from __future__ import annotations
2
2
3
3
import numpy as np
4
+ import pytest
5
+ import scipy .special
4
6
5
- from pymatgen .io .vasp .optics import DielectricFunctionCalculator
7
+ from pymatgen .io .vasp .optics import DielectricFunctionCalculator , delta_func , delta_methfessel_paxton , step_func
6
8
from pymatgen .io .vasp .outputs import Vasprun
7
9
from pymatgen .util .testing import PymatgenTest
8
10
@@ -18,6 +20,10 @@ def test_optics(self):
18
20
dfc = DielectricFunctionCalculator .from_directory (eps_data_path )
19
21
egrid , eps = dfc .get_epsilon (0 , 0 )
20
22
23
+ assert egrid [0 ] == 0
24
+ assert egrid [- 1 ] == 59.3802
25
+ assert len (egrid ) == len (eps ) == 3000
26
+
21
27
_ , eps_real_ref , eps_imag_ref = vrun .dielectric
22
28
eps_real_ref = np .array (eps_real_ref )[:, 0 ]
23
29
eps_imag_ref = np .array (eps_imag_ref )[:, 0 ]
@@ -40,3 +46,39 @@ def test_optics(self):
40
46
mask = np .ones_like (dfc .cder , dtype = float )
41
47
x_val , y_val , text = dfc .plot_weighted_transition_data (0 , 0 , mask = mask , min_val = 0.001 )
42
48
assert len (x_val ) == len (y_val ) == len (text )
49
+
50
+
51
+ def test_delta_func ():
52
+ x = np .array ([0 , 1 , 2 , 3 , 4 , 5 ])
53
+
54
+ # ismear < -1
55
+ with pytest .raises (ValueError , match = "Delta function not implemented for ismear < -1" ):
56
+ delta_func (x , - 2 )
57
+
58
+ # ismear == -1
59
+ assert np .all (delta_func (x , - 1 ) == step_func (x , - 1 ) * (1 - step_func (x , - 1 )))
60
+
61
+ # ismear == 0
62
+ assert np .all (delta_func (x , 0 ) == np .exp (- (x * x )) / np .sqrt (np .pi ))
63
+
64
+ # ismear > 0
65
+ for ismear in [1 , 2 , 3 ]:
66
+ assert np .all (delta_func (x , ismear ) == delta_methfessel_paxton (x , ismear ))
67
+
68
+
69
+ def test_step_func ():
70
+ # array of positive values
71
+ x = np .array ([1 , 2 , 3 , 4 , 5 ])
72
+ assert np .allclose (step_func (x , - 1 ), 1 / (1.0 + np .exp (- x )))
73
+
74
+ # array of negative values
75
+ x = np .array ([- 1 , - 2 , - 3 , - 4 , - 5 ])
76
+ assert np .allclose (step_func (x , - 1 ), 1 / (1.0 + np .exp (- x )))
77
+
78
+ # array that includes zero
79
+ x = np .array ([- 1 , 0 , 1 ])
80
+ assert np .allclose (step_func (x , - 1 ), 1 / (1.0 + np .exp (- x )))
81
+
82
+ # ismear == 0
83
+ x = np .array ([1 , 2 , 3 , 4 , 5 ])
84
+ assert np .allclose (step_func (x , 0 ), 0.5 + 0.5 * scipy .special .erf (x ))
0 commit comments