Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1"""Class for demonstrating the ASE-calculator interface.""" 

2import numpy as np 

3 

4 

5class Calculator: 

6 """ASE calculator. 

7 

8 A calculator should store a copy of the atoms object used for the 

9 last calculation. When one of the *get_potential_energy*, 

10 *get_forces*, or *get_stress* methods is called, the calculator 

11 should check if anything has changed since the last calculation 

12 and only do the calculation if it's really needed. Two sets of 

13 atoms are considered identical if they have the same positions, 

14 atomic numbers, unit cell and periodic boundary conditions.""" 

15 

16 def get_potential_energy(self, atoms=None, force_consistent=False): 

17 """Return total energy. 

18 

19 Both the energy extrapolated to zero Kelvin and the energy 

20 consistent with the forces (the free energy) can be 

21 returned.""" 

22 return 0.0 

23 

24 def get_forces(self, atoms): 

25 """Return the forces.""" 

26 return np.zeros((len(atoms), 3)) 

27 

28 def get_stress(self, atoms): 

29 """Return the stress.""" 

30 return np.zeros(6) 

31 

32 def calculation_required(self, atoms, quantities): 

33 """Check if a calculation is required. 

34 

35 Check if the quantities in the *quantities* list have already 

36 been calculated for the atomic configuration *atoms*. The 

37 quantities can be one or more of: 'energy', 'forces', 'stress', 

38 'charges' and 'magmoms'. 

39 

40 This method is used to check if a quantity is available without 

41 further calculations. For this reason, calculators should 

42 react to unknown/unsupported quantities by returning True, 

43 indicating that the quantity is *not* available.""" 

44 return False 

45 

46 

47class DFTCalculator(Calculator): 

48 """Class for demonstrating the ASE interface to DFT-calculators.""" 

49 

50 def get_number_of_bands(self): 

51 """Return the number of bands.""" 

52 return 42 

53 

54 def get_xc_functional(self): 

55 """Return the XC-functional identifier. 

56 

57 'LDA', 'PBE', ...""" 

58 return 'LDA' 

59 

60 def get_bz_k_points(self): 

61 """Return all the k-points in the 1. Brillouin zone. 

62 

63 The coordinates are relative to reciprocal latice vectors.""" 

64 return np.zeros((1, 3)) 

65 

66 def get_number_of_spins(self): 

67 """Return the number of spins in the calculation. 

68 

69 Spin-paired calculations: 1, spin-polarized calculation: 2.""" 

70 return 1 

71 

72 def get_spin_polarized(self): 

73 """Is it a spin-polarized calculation?""" 

74 return False 

75 

76 def get_ibz_k_points(self): 

77 """Return k-points in the irreducible part of the Brillouin zone. 

78 

79 The coordinates are relative to reciprocal latice vectors.""" 

80 return np.zeros((1, 3)) 

81 

82 def get_k_point_weights(self): 

83 """Weights of the k-points. 

84 

85 The sum of all weights is one.""" 

86 return np.ones(1) 

87 

88 def get_pseudo_density(self, spin=None, pad=True): 

89 """Return pseudo-density array. 

90 

91 If *spin* is not given, then the total density is returned. 

92 Otherwise, the spin up or down density is returned (spin=0 or 

93 1).""" 

94 return np.zeros((40, 40, 40)) 

95 

96 def get_effective_potential(self, spin=0, pad=True): 

97 """Return pseudo-effective-potential array.""" 

98 return np.zeros((40, 40, 40)) 

99 

100 def get_pseudo_wave_function(self, band=0, kpt=0, spin=0, broadcast=True, 

101 pad=True): 

102 """Return pseudo-wave-function array.""" 

103 return np.zeros((40, 40, 40)) 

104 

105 def get_eigenvalues(self, kpt=0, spin=0): 

106 """Return eigenvalue array.""" 

107 return np.arange(42, float) 

108 

109 def get_occupation_numbers(self, kpt=0, spin=0): 

110 """Return occupation number array.""" 

111 return np.ones(42) 

112 

113 def get_fermi_level(self): 

114 """Return the Fermi level.""" 

115 return 0.0 

116 

117 def initial_wannier(self, initialwannier, kpointgrid, fixedstates, 

118 edf, spin, nbands): 

119 """Initial guess for the shape of wannier functions. 

120 

121 Use initial guess for wannier orbitals to determine rotation 

122 matrices U and C. 

123 """ 

124 raise NotImplementedError 

125 

126 def get_wannier_localization_matrix(self, nbands, dirG, kpoint, 

127 nextkpoint, G_I, spin): 

128 """Calculate integrals for maximally localized Wannier functions.""" 

129 

130 def get_magnetic_moment(self, atoms=None): 

131 """Return the total magnetic moment.""" 

132 return self.occupation.magmom 

133 

134 def get_number_of_grid_points(self): 

135 """Return the shape of arrays.""" 

136 return self.gd.N_c