how to customize/define an xc functional
Closed this issue · 2 comments
Hello,
Is there a simple way to customize the xc functional or the xc potential used in the Kohn-Sham Hamiltonian? for example: similar to PySCF code: https://github.com/pyscf/pyscf/blob/master/examples/dft/24-define_xc_functional.py
Thanks
Yes there is.
Essentially you need to implement the interface required by the DftFunctionals.jl package using a custom struct and then you can use an instance of that struct as a functional in the model_DFT
constructor (instead of just supplying the libxc functional key).
For LDA and GGA functionals you only need to implement the energy
and identifier
function. E.g. as a quick sketch
using DftFunctional
using DFTK
using AtomsIO
struct MyCustomGgaCorrelationFunctional <: Functional{:gga,:x}
end
identifier(::MyCustomGgaCorrelationFunctional) = :custom
function energy(::MyCustomGgaCorrelationFunctional, ρ::Number, σ::Number)
#= do something with ρ and σ =#
return -3//4 * cbrt(3/π * ρ) * ρ
end
# ....
system = load_system("some file ... ")
model_custom = model_DFT(system, [:lda_c, MyCustomGgaCorrelationFunctional()])
Currently there is no documented example for doing this, unfortunately. But if you come up with a nice example, I'd appreciate a PR at https://github.com/JuliaMolSim/DftFunctionals.jl.
Also I'm closing this here as this is really concerned with the functional implementation, which should be discussed in an issue in https://github.com/JuliaMolSim/DftFunctionals.jl.
For LDA type xc functionals you can also use LocalNonlinearity, see the gross pitaevskii example