forked from JuliaMolSim/DFTK.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNormConservingPsp.jl
More file actions
233 lines (191 loc) · 7.94 KB
/
Copy pathNormConservingPsp.jl
File metadata and controls
233 lines (191 loc) · 7.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# Abstract interface for a norm-conserving pseudopotential. See PspHgh for an example.
abstract type NormConservingPsp end
# Subtypes must implement the following:
#### Fields:
# lmax::Int # Maximal angular momentum in the non-local part
# h::Vector{Matrix{Float64}} # Projector coupling coefficients per AM channel: h[l][i1,i2]
# identifier::String # String identifying the PSP
# description::String # Descriptive string
#### Methods:
# charge_ionic(psp)
# has_valence_density(psp)
# has_core_density(psp)
# eval_psp_projector_real(psp, i, l, r::Real)
# eval_psp_projector_fourier(psp, i, l, p::Real)
# eval_psp_local_real(psp, r::Real)
# eval_psp_local_fourier(psp, p::Real)
# eval_psp_energy_correction(T::Type, psp)
#### Optional methods:
# eval_psp_density_valence_real(psp, r::Real)
# eval_psp_density_valence_fourier(psp, p::Real)
# eval_psp_density_core_real(psp, r::Real)
# eval_psp_density_core_fourier(psp, p::Real)
# eval_psp_pswfc_real(psp, i::Int, l::Int, p::Real)
# eval_psp_pswfc_fourier(psp, i::Int, l::Int, p::Real)
# count_n_pswfc(psp, l::Integer)
# count_n_pswfc_radial(psp, l::Integer)
# pswfc_label(psp, i::Integer, l::Integer)
"""
eval_psp_projector_real(psp, i, l, r)
Evaluate the radial part of the `i`-th projector for angular momentum `l`
in real-space at the vector with modulus `r`.
"""
eval_psp_projector_real(psp::NormConservingPsp, i, l, r::AbstractVector) =
eval_psp_projector_real(psp, i, l, norm(r))
@doc raw"""
eval_psp_projector_fourier(psp, i, l, p)
Evaluate the radial part of the `i`-th projector for angular momentum `l`
at the reciprocal vector with modulus `p`:
```math
\begin{aligned}
{\rm proj}(p) &= ∫_{ℝ^3} {\rm proj}_{il}(r) e^{-ip·r} dr \\
&= 4π ∫_{ℝ_+} r^2 {\rm proj}_{il}(r) j_l(p·r) dr.
\end{aligned}
```
"""
eval_psp_projector_fourier(psp::NormConservingPsp, p::AbstractVector) =
eval_psp_projector_fourier(psp, norm(p))
"""
eval_psp_local_real(psp, r)
Evaluate the local part of the pseudopotential in real space.
"""
eval_psp_local_real(psp::NormConservingPsp, r::AbstractVector) =
eval_psp_local_real(psp, norm(r))
@doc raw"""
eval_psp_local_fourier(psp, p)
Evaluate the local part of the pseudopotential in reciprocal space:
```math
\begin{aligned}
V_{\rm loc}(p) &= ∫_{ℝ^3} V_{\rm loc}(r) e^{-ip·r} dr \\
&= 4π ∫_{ℝ_+} V_{\rm loc}(r) \frac{\sin(p·r)}{p} r dr
\end{aligned}
```
In practice, the local potential should be corrected using a Coulomb-like term ``C(r) = -Z/r``
to remove the long-range tail of ``V_{\rm loc}(r)`` from the integral:
```math
\begin{aligned}
V_{\rm loc}(p) &= ∫_{ℝ^3} (V_{\rm loc}(r) - C(r)) e^{-ip·r} dr + F[C(r)] \\
&= 4π ∫_{ℝ_+} (V_{\rm loc}(r) + Z/r) \frac{\sin(p·r)}{p·r} r^2 dr - Z/p^2.
\end{aligned}
```
"""
eval_psp_local_fourier(psp::NormConservingPsp, p::AbstractVector) =
eval_psp_local_fourier(psp, norm(p))
@doc raw"""
eval_psp_energy_correction([T=Float64,] psp::NormConservingPsp)
eval_psp_energy_correction([T=Float64,] element::Element)
Evaluate the energy correction to the Ewald electrostatic interaction energy per unit
of uniform negative charge. This is the correction required to account for the fact that
the Ewald expression assumes point-like nuclei and not nuclei of the shape induced by
the pseudopotential. The compensating background charge assumed for this expression is
scaled to ``1``. Therefore multiplying by the number of electrons and dividing by the unit
cell volume yields the energy correction per volume for the DFT simulation.
The energy correction is defined as the limit of the Fourier-transform of the local
potential as ``p \to 0``, using the same correction as in the Fourier-transform of the local
potential:
```math
\lim_{p \to 0} 4π N_{\rm elec} ∫_{ℝ_+} (V(r) - C(r)) \frac{\sin(p·r)}{p·r} r^2 dr + F[C(r)]
= 4π N_{\rm elec} ∫_{ℝ_+} (V(r) + Z/r) r^2 dr.
```
where as discussed above the implementation is expected to return the result
for ``N_{\rm elec} = 1``.
"""
function eval_psp_energy_correction end
# by default, no correction, see PspHgh implementation and tests
# for details on what to implement
eval_psp_energy_correction(psp::NormConservingPsp) = eval_psp_energy_correction(Float64, psp)
"""
eval_psp_density_valence_real(psp, r)
Evaluate the atomic valence charge density in real space.
"""
eval_psp_density_valence_real(psp::NormConservingPsp, r::AbstractVector) =
eval_psp_density_valence_real(psp, norm(r))
@doc raw"""
eval_psp_density_valence_fourier(psp, p)
Evaluate the atomic valence charge density in reciprocal space:
```math
\begin{aligned}
ρ_{\rm val}(p) &= ∫_{ℝ^3} ρ_{\rm val}(r) e^{-ip·r} dr \\
&= 4π ∫_{ℝ_+} ρ_{\rm val}(r) \frac{\sin(p·r)}{ρ·r} r^2 dr.
\end{aligned}
```
"""
eval_psp_density_valence_fourier(psp::NormConservingPsp, p::AbstractVector) =
eval_psp_density_valence_fourier(psp, norm(p))
"""
eval_psp_density_core_real(psp, r)
Evaluate the atomic core charge density in real space.
"""
eval_psp_density_core_real(::NormConservingPsp, ::T) where {T <: Real} = zero(T)
eval_psp_density_core_real(psp::NormConservingPsp, r::AbstractVector) =
eval_psp_density_core_real(psp, norm(r))
@doc raw"""
eval_psp_density_core_fourier(psp, p)
Evaluate the atomic core charge density in reciprocal space:
```math
\begin{aligned}
ρ_{\rm core}(p) &= ∫_{ℝ^3} ρ_{\rm core}(r) e^{-ip·r} dr \\
&= 4π ∫_{ℝ_+} ρ_{\rm core}(r) \frac{\sin(p·r)}{ρ·r} r^2 dr.
\end{aligned}
```
"""
eval_psp_density_core_fourier(::NormConservingPsp, ::T) where {T <: Real} = zero(T)
eval_psp_density_core_fourier(psp::NormConservingPsp, p::AbstractVector) =
eval_psp_density_core_fourier(psp, norm(p))
#### Methods defined on a NormConservingPsp
import Base.Broadcast.broadcastable
Base.Broadcast.broadcastable(psp::NormConservingPsp) = Ref(psp)
function projector_indices(psp::NormConservingPsp)
((i, l, m) for l = 0:psp.lmax for i = 1:size(psp.h[l+1], 1) for m = -l:l)
end
"""
count_n_proj_radial(psp, l)
Number of projector radial functions at angular momentum `l`.
"""
count_n_proj_radial(psp::NormConservingPsp, l::Integer) = size(psp.h[l + 1], 1)
"""
count_n_proj_radial(psp)
Number of projector radial functions at all angular momenta up to `psp.lmax`.
"""
function count_n_proj_radial(psp::NormConservingPsp)
sum(l -> count_n_proj_radial(psp, l), 0:psp.lmax; init=0)::Int
end
"""
count_n_proj(psp, l)
Number of projector functions for angular momentum `l`, including angular parts from `-m:m`.
"""
count_n_proj(psp::NormConservingPsp, l::Integer) = count_n_proj_radial(psp, l) * (2l + 1)
"""
count_n_proj(psp)
Number of projector functions for all angular momenta up to `psp.lmax`, including
angular parts from `-m:m`.
"""
function count_n_proj(psp::NormConservingPsp)
sum(l -> count_n_proj(psp, l), 0:psp.lmax; init=0)::Int
end
"""
count_n_proj(psps, psp_positions)
Number of projector functions for all angular momenta up to `psp.lmax` and for all
atoms in the system, including angular parts from `-m:m`.
"""
function count_n_proj(psps, psp_positions)
sum(count_n_proj(psp) * length(positions)
for (psp, positions) in zip(psps, psp_positions))
end
count_n_pswfc_radial(psp::NormConservingPsp, l) = error("Pseudopotential $psp does not implement atomic wavefunctions.")
function count_n_pswfc_radial(psp::NormConservingPsp)
sum(l -> count_n_pswfc_radial(psp, l), 0:psp.lmax; init=0)::Int
end
count_n_pswfc(psp::NormConservingPsp, l) = count_n_pswfc_radial(psp, l) * (2l + 1)
function count_n_pswfc(psp::NormConservingPsp)
sum(l -> count_n_pswfc(psp, l), 0:psp.lmax; init=0)::Int
end
function find_pswfc(psp::NormConservingPsp, label::String)
for l = 0:psp.lmax, i = 1:count_n_pswfc_radial(psp, l)
if pswfc_label(psp, i, l) == label
return (; l, i)
end
end
error("Could not find pseudo atomic orbital with label $label "
* "in pseudopotential $(psp.identifier).")
end