Coverage for ase/calculators/bond_polarizability.py: 100.00%

52 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-11-27 15:21 +0000

1import numpy as np 

2 

3from ase.data import covalent_radii 

4from ase.neighborlist import NeighborList 

5from ase.units import Bohr, Ha 

6 

7from .polarizability import StaticPolarizabilityCalculator 

8 

9 

10class LippincottStuttman: 

11 # atomic polarizability values from: 

12 # Lippincott and Stutman J. Phys. Chem. 68 (1964) 2926-2940 

13 # DOI: 10.1021/j100792a033 

14 # see also: 

15 # Marinov and Zotov Phys. Rev. B 55 (1997) 2938-2944 

16 # DOI: 10.1103/PhysRevB.55.2938 

17 # unit: Angstrom^3 

18 atomic_polarizability = { 

19 'H': 0.592, 

20 'Be': 3.802, 

21 'B': 1.358, 

22 'C': 0.978, 

23 'N': 0.743, 

24 'O': 0.592, 

25 'Al': 3.918, 

26 'Si': 2.988, 

27 'P': 2.367, 

28 'S': 1.820, 

29 } 

30 # reduced electronegativity Table I 

31 reduced_eletronegativity = { 

32 'H': 1.0, 

33 'Be': 0.538, 

34 'B': 0.758, 

35 'C': 0.846, 

36 'N': 0.927, 

37 'O': 1.0, 

38 'Al': 0.533, 

39 'Si': 0.583, 

40 'P': 0.630, 

41 'S': 0.688, 

42 } 

43 

44 def __call__( 

45 self, el1: str, el2: str, length: float 

46 ) -> tuple[float, float]: 

47 """Bond polarizability 

48 

49 Parameters 

50 ---------- 

51 el1: element string 

52 el2: element string 

53 length: float 

54 

55 Returns 

56 ------- 

57 alphal: float 

58 Parallel component 

59 alphap: float 

60 Perpendicular component 

61 """ 

62 alpha1 = self.atomic_polarizability[el1] 

63 alpha2 = self.atomic_polarizability[el2] 

64 ren1 = self.reduced_eletronegativity[el1] 

65 ren2 = self.reduced_eletronegativity[el2] 

66 

67 sigma = 1.0 

68 if el1 != el2: 

69 sigma = np.exp(-((ren1 - ren2) ** 2) / 4) 

70 

71 # parallel component 

72 alphal = sigma * length**4 / (4**4 * alpha1 * alpha2) ** (1.0 / 6) 

73 # XXX consider fractional covalency ? 

74 

75 # prependicular component 

76 alphap = (ren1**2 * alpha1 + ren2**2 * alpha2) / (ren1**2 + ren2**2) 

77 # XXX consider fractional covalency ? 

78 

79 return alphal, alphap 

80 

81 

82class Linearized: 

83 def __init__(self): 

84 self._data = { 

85 # L. Wirtz, M. Lazzeri, F. Mauri, A. Rubio, 

86 # Phys. Rev. B 2005, 71, 241402. 

87 # R0 al al' ap ap' 

88 'CC': (1.53, 1.69, 7.43, 0.71, 0.37), 

89 'BN': (1.56, 1.58, 4.22, 0.42, 0.90), 

90 } 

91 

92 def __call__( 

93 self, el1: str, el2: str, length: float 

94 ) -> tuple[float, float]: 

95 """Bond polarizability 

96 

97 Parameters 

98 ---------- 

99 el1: element string 

100 el2: element string 

101 length: float 

102 

103 Returns 

104 ------- 

105 alphal: float 

106 Parallel component 

107 alphap: float 

108 Perpendicular component 

109 """ 

110 if el1 > el2: 

111 bond = el2 + el1 

112 else: 

113 bond = el1 + el2 

114 assert bond in self._data 

115 length0, al, ald, ap, apd = self._data[bond] 

116 

117 return al + ald * (length - length0), ap + apd * (length - length0) 

118 

119 

120class BondPolarizability(StaticPolarizabilityCalculator): 

121 def __init__(self, model=LippincottStuttman()): 

122 self.model = model 

123 

124 def __call__(self, atoms, radiicut=1.5): 

125 """Sum up the bond polarizability from all bonds 

126 

127 Parameters 

128 ---------- 

129 atoms: Atoms object 

130 radiicut: float 

131 Bonds are counted up to 

132 radiicut * (sum of covalent radii of the pairs) 

133 Default: 1.5 

134 

135 Returns 

136 ------- 

137 polarizability tensor with unit (e^2 Angstrom^2 / eV). 

138 Multiply with Bohr * Ha to get (Angstrom^3) 

139 """ 

140 radii = np.array([covalent_radii[z] for z in atoms.numbers]) 

141 nl = NeighborList(radii * 1.5, skin=0, self_interaction=False) 

142 nl.update(atoms) 

143 pos_ac = atoms.get_positions() 

144 

145 alpha = 0 

146 for ia, atom in enumerate(atoms): 

147 indices, offsets = nl.get_neighbors(ia) 

148 pos_ac = atoms.get_positions() - atoms.get_positions()[ia] 

149 

150 for ib, offset in zip(indices, offsets): 

151 weight = 1 

152 if offset.any(): # this comes from a periodic image 

153 weight = 0.5 # count half the bond only 

154 

155 dist_c = pos_ac[ib] + np.dot(offset, atoms.get_cell()) 

156 dist = np.linalg.norm(dist_c) 

157 al, ap = self.model(atom.symbol, atoms[ib].symbol, dist) 

158 

159 eye3 = np.eye(3) / 3 

160 alpha += weight * (al + 2 * ap) * eye3 

161 alpha += ( 

162 weight 

163 * (al - ap) 

164 * (np.outer(dist_c, dist_c) / dist**2 - eye3) 

165 ) 

166 return alpha / Bohr / Ha