JuliaMolSim / DftFunctionals.jl

Interface and Julia implementation of exchange-correlation functionals
https://juliamolsim.github.io/DftFunctionals.jl/stable/
MIT License
8 stars 7 forks source link

using an xc potential without the energy functional #10

Closed aouinaayoub closed 1 year ago

aouinaayoub commented 1 year ago

I would like to use a new xc potential in the Kohn-Sham Hamiltonian for a given system. This xc potential does not have an energy functional, it reads:

$v{\rm xc}({\bf r},[n]) = v^{\rm LDA}{\rm xc} (n^c_r )$

where: $n({\bf r})$ is the electronic density,

$v^{\rm LDA}_{\rm xc}(n)$ is the LDA xc potential function,

$n^c{\bf r} = \int d {\bf r}' \frac{f{\rm xc}( |{\bf r}-{\bf r}'|, n0) }{f^h{\rm xc}(n'_0)} n({\bf r}')$,

with $f_{\rm xc}(|\mathbf{r}-\mathbf{r}'|,n0)=\left.\delta v{\rm xc}(\mathbf{r},[ n])/\delta n(\mathbf{r}')\right|{n=n_0}$ is the static non local xc kernel of the homogeneous electron gas with density $n0$, and $f^h{\rm xc}(n'_0)$ is its limit of zero wave-vector. Both functions are parameterized and available,

$n0=\frac{n({\bf r})+n^c{\bf r}}{2}$ and $n'_0=\frac{n({\bf r})+n({\bf r'})}{2}$.

Could you provide me with guidelines to implement and use this functional?

antoine-levitt commented 1 year ago

So in general if you want a new term that isn't covered by the existing ones you have to implement it yourself: look at hartree.jl for instance. If you don't have an energy functional, you can set it to an arbitrary value; it might break things in DFTK (like the default heuristics for the SCF) but that can be fixed. The issue I see here is that your potential function is not a simple form in the density, because the kernel K(r,r') = fxc(r-r', n0)/fxch(n0') looks like a general nonseparable function of r and r' (not of r-r'). You can implement it directly, but it will probably be pretty expensive. I'd start by getting and idea of how costly (in flops and in ram) it is to form the matrix K(r,r') for all r,r' in the grid (of size basis.fft_size), for the system of interest. If it's doable you can try, but you will very likely be limited to very small systems.

aouinaayoub commented 1 year ago

I don't find hartree.jl. I also checked the documentation, I don't see how to implement my own xc potential, could you write a snippet of code how to personalize the vxc let's say for $v_{\rm xc}=\int d{\bf r'} n({\bf r'})/|{\bf r-r'}$| ? (I'm very beginner with julia)

antoine-levitt commented 1 year ago

hartree.jl is here: https://github.com/JuliaMolSim/DFTK.jl/blob/master/src/terms/hartree.jl, it does exactly what you say here https://github.com/JuliaMolSim/DFTK.jl/blob/master/src/terms/hartree.jl#L45 and here https://github.com/JuliaMolSim/DFTK.jl/blob/master/src/terms/hartree.jl#L33. Note that this uses the convolution theorem and FFTs (because 1/|r-r'| is a function of r-r'), which is not feasible in your case. You need something like (in real space) pot = reshape(K * vec(total_density(ρ)), basis.fft_size) where K is a matrix of size prod(basis.fft_size) by itself.

aouinaayoub commented 1 year ago

Thank you that's very helpful. Then how can I use/call it in the KS equations?

antoine-levitt commented 1 year ago

You add it as an extra term, see the extra_terms keyword argument in the model_DFT constructor (in standard_models.jl) and eg this tutorial: https://docs.dftk.org/dev/examples/gross_pitaevskii/. Let us know how that goes!

aouinaayoub commented 1 year ago

Thanks a lot!

mfherbst commented 1 year ago

@aouinaayoub Sorry that I redirected you here. I thought you wanted to implement really a custom semilocal XC functional (for which repo would be the right place). As Antoine said with the 1/|r-r'| dependency you need a convolution, for which you need FFTs, so the right place for discussion and implementation indeed was your earlier issue https://github.com/JuliaMolSim/DFTK.jl/issues/848 was indeed the right place to discuss.