using DFTK using LinearAlgebra struct CustomPotential <: DFTK.Element α # Prefactor L # Width of the Gaussian nucleus end CustomPotential() = CustomPotential(1.0, 0.5); function DFTK.local_potential_real(el::CustomPotential, r::Real) -el.α / (√(2π) * el.L) * exp(- (r / el.L)^2 / 2) end function DFTK.local_potential_fourier(el::CustomPotential, q::Real) # = ∫ V(r) exp(-ix⋅q) dx -el.α * exp(- (q * el.L)^2 / 2) end a = 10 lattice = a .* [[1 0 0.]; [0 0 0]; [0 0 0]]; x1 = 0.2 x2 = 0.8 positions = [[x1, 0, 0], [x2, 0, 0]] gauss = CustomPotential() atoms = [gauss, gauss]; C = 1.0 α = 2; n_electrons = 1 # Increase this for fun terms = [Kinetic(), AtomicLocal(), LocalNonlinearity(ρ -> C * ρ^α)] model = Model(lattice, atoms, positions; n_electrons, terms, spin_polarization=:spinless); # use "spinless electrons" basis = PlaneWaveBasis(model; Ecut=500, kgrid=(1, 1, 1)) ρ = zeros(eltype(basis), basis.fft_size..., 1) scfres = self_consistent_field(basis; tol=1e-5, ρ) scfres.energies compute_forces(scfres) tot_local_pot = DFTK.total_local_potential(scfres.ham)[:, 1, 1]; # use only dimension 1 ρ = scfres.ρ[:, 1, 1, 1] # converged density, first spin component ψ_fourier = scfres.ψ[1][:, 1] # first k-point, all G components, first eigenvector ψ = ifft(basis, basis.kpoints[1], ψ_fourier)[:, 1, 1] ψ /= (ψ[div(end, 2)] / abs(ψ[div(end, 2)])); using Plots x = a * vec(first.(DFTK.r_vectors(basis))) p = plot(x, real.(ψ), label="real(ψ)") plot!(p, x, imag.(ψ), label="imag(ψ)") plot!(p, x, ρ, label="ρ") plot!(p, x, tot_local_pot, label="tot local pot")