Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
bc0e2eb
Adding Hubbard
fsicignano Sep 25, 2025
d4dfa7b
Complex Spherical Harmonics have been removed
fsicignano Sep 25, 2025
48a33f0
Correction to testcases.jl
fsicignano Sep 25, 2025
6c77122
Added test for hubbard term
fsicignano Sep 25, 2025
5540b22
Added explicit import of Hubbard in testcases.jl
fsicignano Sep 25, 2025
9e894bf
Speed up of the hubbard test
fsicignano Sep 25, 2025
4a1d0e2
Hubbard test now functional
fsicignano Sep 25, 2025
db7d948
Still errors in the consistency test
fsicignano Sep 26, 2025
e0a1002
Some comments have been resolved
fsicignano Sep 29, 2025
7045a6d
Some comments have been resolved
fsicignano Sep 29, 2025
fab6fb5
Comments have been resolved
fsicignano Sep 29, 2025
ae13ba7
Comments have been resolved
fsicignano Sep 29, 2025
5aefec2
Added nhubbard field to scfres in forwarddiff_rules.
fsicignano Sep 30, 2025
0d69edd
Update to Wigner_sym, now wigner_d_matrix and relative test
fsicignano Sep 30, 2025
d0cf01a
Change in testing
fsicignano Sep 30, 2025
16a3f6f
New example in examples/hubbard.jl
fsicignano Oct 2, 2025
c9d8328
use_nlcc=false for all mgga tests
fsicignano Oct 3, 2025
f905197
Most comments have been addressed
fsicignano Oct 7, 2025
7ea2342
Several issues solved
fsicignano Oct 7, 2025
3b72e16
Merge branch 'master' into hubbard-v2
fsicignano Oct 7, 2025
42b5f85
Semplification in compute_nhubbard
fsicignano Oct 9, 2025
5a95c9d
Simplification to the apply!(HubbardUOperator)
fsicignano Oct 9, 2025
20b1370
Merge branch 'hubbard-v2' of https://github.com/fsicignano/DFTK.jl in…
fsicignano Oct 9, 2025
914bbe6
Simplification to the apply!(HubbardUOperator)
fsicignano Oct 9, 2025
b31874d
New comments addressed
fsicignano Oct 9, 2025
d4cb53c
New comments addressed
fsicignano Oct 10, 2025
aeab561
Merge branch 'master' into hubbard-v2
fsicignano Oct 10, 2025
1fad1c8
Issue solved with mpi
fsicignano Oct 10, 2025
efc83f5
ntermediate version
fsicignano Oct 21, 2025
074f539
New simplified version
fsicignano Oct 22, 2025
41bebad
New simplified version
fsicignano Oct 22, 2025
a431717
New simplified version
fsicignano Oct 22, 2025
8a87487
Test issue solved
fsicignano Oct 23, 2025
52a20d8
Merge branch 'master' into hubbard-v2
fsicignano Oct 23, 2025
8de7498
Updating branch
fsicignano Oct 23, 2025
8f636d7
Merge branch 'hubbard-v2' of https://github.com/fsicignano/DFTK.jl in…
fsicignano Oct 23, 2025
75cc62c
Test hubbard.jl fixed for mpi case
fsicignano Oct 24, 2025
b2da690
New comments addressed
fsicignano Oct 24, 2025
761ee8b
New comments have been addressed
fsicignano Oct 28, 2025
ea48cca
Update examples/hubbard.jl
fsicignano Oct 28, 2025
b7e90bb
New comments have been addressed
fsicignano Oct 29, 2025
3cf787e
Merge branch 'master' into hubbard-v2
fsicignano Oct 29, 2025
0e17b63
Merge branch 'hubbard-v2' of https://github.com/fsicignano/DFTK.jl in…
fsicignano Oct 29, 2025
2fe39dc
Be more explicit
mfherbst Oct 29, 2025
3c611b1
Cosmetic fixes to example
mfherbst Oct 29, 2025
aecf0bd
Announce feature
mfherbst Oct 29, 2025
1d4d73c
Minor changes
fsicignano Nov 5, 2025
15304e7
Modifications to the OrbitalManifold interface
fsicignano Nov 10, 2025
253931d
Merge branch 'hubbard-v2' of https://github.com/fsicignano/DFTK.jl in…
fsicignano Nov 10, 2025
f649481
Name 'nhubbard' converted to 'hubbard_n'
fsicignano Nov 10, 2025
df51495
Merge branch 'master' into hubbard-v2
fsicignano Nov 10, 2025
5c05a9f
New constructors added for OrbitalManifold. Testing
fsicignano Nov 11, 2025
a021e32
Various changes
Technici4n Nov 12, 2025
e2d97d6
Minor tweaks
Technici4n Nov 12, 2025
2da2d03
Fix tests not testing anything
Technici4n Nov 12, 2025
9f7dbcd
Reorder OrbitalManifold constructors
Technici4n Nov 12, 2025
ca16a44
Move hubbard_n computation down
Technici4n Nov 12, 2025
7aab38e
Review comments
Technici4n Nov 12, 2025
3533669
Minor typo in documentation
fsicignano Nov 13, 2025
99bddba
Merge branch 'master' into hubbard-v2
fsicignano Nov 13, 2025
872c29a
Reduce example running time, update manifold naming comment
Technici4n Nov 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/scf/self_consistent_field.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@ Overview of parameters:
end
ihubbard = findfirst(t -> t isa TermHubbard, basis.terms)
if !isnothing(ihubbard)
term = basis.terms[ihubbard]
hubbard_n = compute_hubbard_n(term.manifold, basis, ψ, occupation;
projectors=term.P, labels=term.labels)
hubbard_n = compute_hubbard_n(basis.terms[ihubbard], basis, ψ, occupation)
end

# Update info with results gathered so far
Expand Down
35 changes: 12 additions & 23 deletions src/terms/hubbard.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,42 +68,31 @@ function extract_manifold(manifold::OrbitalManifold, projectors, labels)
end

"""
compute_hubbard_n(manifold, basis, ψ, occupation; [projectors, labels, positions])
compute_hubbard_n(term::TermHubbard, basis, ψ, occupation)

Computes a matrix hubbard_n of size (n_spin, natoms, natoms), where each entry hubbard_n[iatom, jatom]
contains the submatrix of the occupation matrix corresponding to the projectors
of atom iatom and atom jatom, with dimensions determined by the number of projectors for each atom.
The atoms and orbitals are defined by the manifold tuple.
contains the submatrix of the occupation matrix corresponding to the projectors
of atom iatom and atom jatom, with dimensions determined by the number of projectors for each atom.
The atoms and orbitals are defined by the manifold tuple.

hubbard_n[σ, iatom, jatom][m1, m2] = Σₖ₍ₛₚᵢₙ₎Σₙ weights[ik, ibnd] * ψₙₖ' * Pᵢₘ₁ * Pᵢₘ₂' * ψₙₖ

where n or ibnd is the band index, ``weights[ik ibnd] = kweights[ik] * occupation[ik, ibnd]``
and ``Pᵢₘ₁`` is the pseudoatomic orbital projector for atom i and orbital m₁
(just the magnetic quantum number, since l is fixed, as is usual in the literature).
For details on the projectors see `atomic_orbital_projectors`.

Overview of inputs:
- `manifold`: OrbitalManifold with the atomic orbital type to define the Hubbard manifold.
- `occupation`: Occupation matrix for the bands.
- `projectors` (kwarg): Vector of projection matrices. For each matrix, each column corresponds
to a different atomic orbital projector, as specified in labels.
- `labels` (kwarg): Vector of NamedTuples. Each projectors[ik][:,iproj] column has all relevant
chemical information stored in the corresponding labels[iproj] NamedTuple.

Overview of outputs:
- `hubbard_n`: 3-tensor of matrices. See above for details.
where n or ibnd is the band index, ``weights[ik ibnd] = kweights[ik] * occupation[ik, ibnd]``
and ``Pᵢₘ₁`` is the pseudoatomic orbital projector for atom i and orbital m₁
(just the magnetic quantum number, since l is fixed, as is usual in the literature).
For details on the projectors see `atomic_orbital_projectors`.
"""
function compute_hubbard_n(manifold::OrbitalManifold,
function compute_hubbard_n(term::TermHubbard,
basis::PlaneWaveBasis{T},
ψ, occupation;
projectors, labels) where {T}
ψ, occupation) where {T}
filled_occ = filled_occupation(basis.model)
n_spin = basis.model.n_spin_components

manifold = term.manifold
manifold_atoms = manifold.iatoms
natoms = length(manifold_atoms)
l = manifold.l
projectors = reshape_hubbard_proj(projectors, labels, manifold)
projectors = reshape_hubbard_proj(term.P, term.labels, manifold)
hubbard_n = Array{Matrix{Complex{T}}}(undef, n_spin, natoms, natoms)
for σ in 1:n_spin
for idx in 1:natoms, jdx in 1:natoms
Expand Down
49 changes: 35 additions & 14 deletions test/hamiltonian_consistency.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ function test_consistency_term(term; rtol=1e-4, atol=1e-8, ε=1e-6, kgrid=[1, 2,
compute_density(basis, ψ, occupation)
end
τ = compute_kinetic_energy_density(basis, ψ, occupation)
E0, ham = energy_hamiltonian(basis, ψ, occupation; ρ, τ)
hubbard_n = nothing
if term isa Hubbard
hubbard_n = DFTK.compute_hubbard_n(only(basis.terms), basis, ψ, occupation)
end
E0, ham = energy_hamiltonian(basis, ψ, occupation; ρ, τ, hubbard_n)

@assert length(basis.terms) == 1

Expand All @@ -60,7 +64,14 @@ function test_consistency_term(term; rtol=1e-4, atol=1e-8, ε=1e-6, kgrid=[1, 2,
compute_density(basis, ψ_trial, occupation)
end
τ_trial = compute_kinetic_energy_density(basis, ψ_trial, occupation)
(; energies) = energy_hamiltonian(basis, ψ_trial, occupation; ρ=ρ_trial, τ=τ_trial)
hubbard_n_trial = nothing
if term isa Hubbard
hubbard_n_trial = DFTK.compute_hubbard_n(only(basis.terms), basis,
ψ_trial, occupation)
end
(; energies) = energy_hamiltonian(basis, ψ_trial, occupation;
ρ=ρ_trial, τ=τ_trial,
hubbard_n=hubbard_n_trial)
energies.total
end
diff = (compute_E(ε) - compute_E(-ε)) / (2ε)
Expand Down Expand Up @@ -91,26 +102,36 @@ end
using .HamConsistency: test_consistency_term, testcase

test_consistency_term(Kinetic())
test_consistency_term(AtomicLocal())
test_consistency_term(AtomicNonlocal())
test_consistency_term(ExternalFromReal(X -> cos(X[1])))
test_consistency_term(ExternalFromFourier(X -> abs(norm(X))))
test_consistency_term(LocalNonlinearity(ρ -> ρ^2))
test_consistency_term(Hartree())
let
Si = ElementPsp(14, load_psp(testcase.psp_upf))
test_consistency_term(Hubbard(OrbitalManifold(Si, [1, 2], "3P"), 0.01), atom=Si)
test_consistency_term(Hubbard(OrbitalManifold(Si, [1, 2], "3P"), 0.01), atom=Si,
spin_polarization=:collinear)
end
# Disabled since the energy is constant, and the test guards against 0 differences
# test_consistency_term(Ewald())
# test_consistency_term(PspCorrection())
for psp in [testcase.psp_gth, testcase.psp_upf]
Si = ElementPsp(14, load_psp(psp))
test_consistency_term(AtomicLocal(), atom=Si)
test_consistency_term(AtomicNonlocal(), atom=Si)
test_consistency_term(Xc([:lda_xc_teter93]), atom=Si)
test_consistency_term(Xc([:lda_xc_teter93]), atom=Si, spin_polarization=:collinear)
test_consistency_term(Xc([:gga_x_pbe]), atom=Si, spin_polarization=:collinear)
# TODO: for use_nlcc=true need to fix consistency for meta-GGA with NLCC
# (see JuliaMolSim/DFTK.jl#1180)
test_consistency_term(Xc([:mgga_x_tpss]; use_nlcc=false), atom=Si)
test_consistency_term(Xc([:mgga_x_scan]; use_nlcc=false), atom=Si)
test_consistency_term(Xc([:mgga_c_scan]; use_nlcc=false), atom=Si,
spin_polarization=:collinear)
test_consistency_term(Xc([:mgga_x_b00]; use_nlcc=false), atom=Si)
test_consistency_term(Xc([:mgga_c_b94]; use_nlcc=false), atom=Si,
spin_polarization=:collinear)
end
test_consistency_term(Ewald())
test_consistency_term(PspCorrection())
test_consistency_term(Xc([:lda_xc_teter93]))
test_consistency_term(Xc([:lda_xc_teter93]), spin_polarization=:collinear)
test_consistency_term(Xc([:gga_x_pbe]), spin_polarization=:collinear)
test_consistency_term(Xc([:mgga_x_tpss]))
test_consistency_term(Xc([:mgga_x_scan]))
test_consistency_term(Xc([:mgga_c_scan]), spin_polarization=:collinear)
test_consistency_term(Xc([:mgga_x_b00]))
test_consistency_term(Xc([:mgga_c_b94]), spin_polarization=:collinear)

let
a = 6
Expand Down
6 changes: 2 additions & 4 deletions test/hubbard.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ end
term_idx = findfirst(term -> isa(term, DFTK.TermHubbard),
scfres_nosym.basis.terms)
term_hub = scfres_nosym.basis.terms[term_idx]
nhub_nosym = DFTK.compute_hubbard_n(manifold, scfres_nosym.basis,
scfres_nosym.ψ, scfres_nosym.occupation;
projectors=term_hub.P,
labels=term_hub.labels)
nhub_nosym = DFTK.compute_hubbard_n(term_hub, scfres_nosym.basis,
scfres_nosym.ψ, scfres_nosym.occupation)
@test n_hub ≈ nhub_nosym
end
end
Expand Down
Loading