Coverage for /builds/ase/ase/ase/utils/deltacodesdft.py: 21.43%

14 statements  

« prev     ^ index     » next       coverage.py v7.5.3, created at 2025-08-02 00:12 +0000

1import numpy as np 

2 

3from ase.eos import birchmurnaghan 

4 

5 

6def delta( 

7 v1: float, 

8 B1: float, 

9 Bp1: float, 

10 v2: float, 

11 B2: float, 

12 Bp2: float, 

13 symmetric=True, 

14) -> float: 

15 """Calculate Delta-value between two equation of states. 

16 

17 .. seealso:: https://github.com/molmod/DeltaCodesDFT 

18 

19 Parameters 

20 ---------- 

21 v1,v2: float 

22 Volume per atom. 

23 B1,B2: float 

24 Bulk-modulus (in eV/Ang^3). 

25 Bp1,Bp2: float 

26 Pressure derivative of bulk-modulus. 

27 symmetric: bool 

28 Default is to calculate a symmetric delta. 

29 

30 Returns 

31 ------- 

32 delta: float 

33 Delta value in eV/atom. 

34 """ 

35 if symmetric: 

36 va = 0.94 * (v1 + v2) / 2 

37 vb = 1.06 * (v1 + v2) / 2 

38 else: 

39 va = 0.94 * v2 

40 vb = 1.06 * v2 

41 npoints = 100 

42 dv = (vb - va) / npoints 

43 v = np.linspace(va + dv / 2, vb - dv / 2, npoints) 

44 e1 = birchmurnaghan(v, 0.0, B1, Bp1, v1) 

45 e2 = birchmurnaghan(v, 0.0, B2, Bp2, v2) 

46 return (((e1 - e2) ** 2).sum() * dv / (vb - va)) ** 0.5