-
Notifications
You must be signed in to change notification settings - Fork 94
[WIP] Hybrid functionals #717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
4b9a614
Overhaul docs organisation (#684)
antoine-levitt 69f534c
minor corrections in docs
antoine-levitt 5081905
minor doc fix
antoine-levitt 30fe9ea
Fix dual handling for parametrised functionals (#699)
mfherbst a3bc617
Typo in dos.jl (#702)
f28b9ec
fix spglib (#707)
mfherbst 0684562
Bump version: 0.5.5 → 0.5.6
mfherbst 06dbf3b
Add documentation about conducting a convergence study (#701)
killah-t-cell 40fb53d
Fix some image links in documentation (#713)
mfherbst 222ae6a
Bump version: 0.5.6 → 0.5.7
mfherbst 77ef797
typo
antoine-levitt ce348a9
ForwardDiff: Return dual energies in scfres (#709)
niklasschmitz 8279d37
Remove advertisement for summer school (#716)
mfherbst 582d3ee
Merge remote-tracking branch 'upstream/master'
BKaperick 4603777
Add fock_exchange term and energy for one kpoint
BKaperick ddf11cf
Add ExchangeOperator to fock_exchange with consistency test
BKaperick bf0e14b
WIP connecting to LibXc
BKaperick 5627ec1
Copy-paste gga methods in DispatchFunctional for hyb_gga
BKaperick 3426b5e
Add scaling_factor to fock_exchange term
BKaperick d008d40
Fix printing bug in other terms using scale_factor
BKaperick ada9b29
Reduce code duplication (with Union) and implement hybrid lda and mgga
BKaperick f770fde
Compute green coeffs only once, and set first term to 0
BKaperick b3d650c
Michael comments part 1
BKaperick cb791f9
Merge remote-tracking branch 'upstream/master'
BKaperick 2ead1c5
Michael comments part 2
BKaperick 81854cc
Clean term implementation
BKaperick b1a703d
Clean operator
BKaperick c69a914
Merge branch 'master' into hybrid_functionals
BKaperick 91a5dda
Some progress
mfherbst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
""" | ||
Exact exchange term: the Hartree-Exact exchange energy of the orbitals | ||
|
||
-1/2 ∑ ∫∫ ϕ_i^*(r)ϕ_j^*(r')ϕ_i(r')ϕ_j(r) / |r - r'| dr dr' | ||
|
||
""" | ||
struct ExactExchange | ||
scaling_factor::Real # to scale the term (e.g. for hybrid models) | ||
end | ||
ExactExchange(; scaling_factor=1) = ExactExchange(scaling_factor) | ||
(exchange::ExactExchange)(basis) = TermExactExchange(basis, exchange.scaling_factor) | ||
function Base.show(io::IO, exchange::ExactExchange) | ||
fac = isone(exchange.scaling_factor) ? "" : "scaling_factor=$(exchange.scaling_factor)" | ||
print(io, "ExactExchange($fac)") | ||
end | ||
struct TermExactExchange <: Term | ||
scaling_factor::Real # scaling factor, absorbed into poisson_green_coeffs | ||
poisson_green_coeffs::AbstractArray | ||
end | ||
function TermExactExchange(basis::PlaneWaveBasis{T}, scaling_factor) where T | ||
scale = T(scaling_factor) | ||
|
||
# q = T[0.5, 0.5, 0.5] | ||
# Gqs = map(G_vectors(basis)) do G | ||
# recip_vector_red_to_cart(basis.model, G + q) | ||
# end | ||
# poisson_green_coeffs = 4T(π) * scale ./ norm2.(Gqs) | ||
|
||
poisson_green_coeffs = 4T(π) * scale ./ norm2.(G_vectors_cart(basis)) | ||
poisson_green_coeffs[1] = 0 # Compensating charge background => Zero DC | ||
|
||
@assert iszero(G_vectors(basis, basis.kpoints[1])[1]) | ||
|
||
TermExactExchange(scale, poisson_green_coeffs) | ||
end | ||
|
||
# Note: Implementing exact exchange in a scalable and numerically stable way, such that it | ||
# rapidly converges with k-points is tricky. This implementation here is far too simple and | ||
# slow to be useful. | ||
# | ||
# For further information (in particular on regularising the Coulomb), consider the following | ||
# https://www.vasp.at/wiki/index.php/Coulomb_singularity | ||
# https://journals.aps.org/prb/pdf/10.1103/PhysRevB.34.4405 (QE default) | ||
# https://journals.aps.org/prb/pdf/10.1103/PhysRevB.73.205119 | ||
# https://docs.abinit.org/topics/documents/hybrids-2017.pdf (Abinit apparently | ||
# uses a short-ranged Coulomb) | ||
|
||
@timing "ene_ops: ExactExchange" function ene_ops(term::TermExactExchange, | ||
basis::PlaneWaveBasis{T}, ψ, occupation; | ||
kwargs...) where {T} | ||
if isnothing(ψ) || isnothing(occupation) | ||
return (; E=T(0), ops=NoopOperator.(basis, basis.kpoints)) | ||
end | ||
|
||
@assert iszero(basis.model.temperature) # ground state | ||
ψ, occupation = select_occupied_orbitals(basis, ψ, occupation; threshold=0.1) | ||
E = zero(T) | ||
|
||
@assert length(ψ) == 1 # TODO: make it work for more kpoints | ||
ik = 1 | ||
kpt = basis.kpoints[ik] | ||
occk = occupation[ik] | ||
ψk = ψ[ik] | ||
|
||
for (n, ψn) in enumerate(eachcol(ψk)) | ||
for (m, ψm) in enumerate(eachcol(ψk)) | ||
ψn_real = ifft(basis, kpt, ψn) | ||
ψm_real = ifft(basis, kpt, ψm) | ||
|
||
BKaperick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ρnm_real = conj(ψn_real) .* ψm_real | ||
ρmn_real = conj(ψm_real) .* ψn_real | ||
|
||
Vx_nm_four = fft(basis, ρnm_real) .* term.poisson_green_coeffs | ||
Vx_nm_real = ifft(basis, Vx_nm_four) | ||
|
||
occ_mn = occk[n] * occk[m] | ||
E -= real(dot(Vx_nm_real, ρmn_real)) * basis.dvol * occ_mn / 2 | ||
end | ||
end | ||
|
||
ops = [ExchangeOperator(basis, kpt, term.poisson_green_coeffs, occk, ψk)] | ||
(E=E, ops=ops) | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.