Skip to content

Commit d0cf01a

Browse files
committed
Change in testing
- Kwarg use_nlcc=false has been added for all meta_gga tests; - Kwarg spin_polarization=:none added to anyonic test, to avoid failure from @Assert length(basis.kpoints) == 1; - Tolerance for condition number in wigner_d_matrix increased to 100, neq decreased to 2*l+2.
1 parent 0d69edd commit d0cf01a

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

src/common/spherical_harmonics.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function wigner_d_matrix(l::Integer, Wcart::AbstractMatrix{T}) where {T}
6464
return D .= 1
6565
end
6666
rng = Xoshiro(1234)
67-
neq = 4*(2*l+1)
67+
neq = (2*l+2) # This value should work for p and d orbitals, but can be increased if needed
6868
for m1 in -l:l
6969
b = Vector{T}(undef, neq)
7070
A = Matrix{T}(undef, neq, 2*l+1)
@@ -78,7 +78,7 @@ function wigner_d_matrix(l::Integer, Wcart::AbstractMatrix{T}) where {T}
7878
end
7979
end
8080
κ = cond(A)
81-
@assert κ < 10.0 "The Wigner matrix computation is badly conditioned. κ(A)=$(κ)"
81+
@assert κ < 100.0 "The Wigner matrix computation is badly conditioned. κ(A)=$(κ)"
8282
D[m1+l+1,:] = A\b
8383
end
8484

src/scf/self_consistent_field.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ Overview of parameters:
181181
end
182182
for term in basis.terms
183183
if isa(term, DFTK.TermHubbard)
184-
nhubbard = compute_nhubbard(term.manifold, basis, ψ, occupation; projectors=term.P, labels=term.labels).nhubbard
184+
nhubbard = compute_nhubbard(term.manifold, basis, ψ, occupation;
185+
projectors=term.P, labels=term.labels).nhubbard
185186
end
186187
end
187188

src/terms/hubbard.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ end
5959
"""
6060
Symmetrize the Hubbard occupation matrix according to the l quantum number of the manifold.
6161
"""
62-
function symmetrize_nhub(nhubbard::Array{Matrix{Complex{T}}}, lattice, symmetries, positions) where {T}
62+
function symmetrize_nhub(nhubbard::Array{Matrix{Complex{T}}},
63+
lattice, symmetries, positions) where {T}
6364
# For now we apply symmetries only on nII terms, not on cross-atom terms (nIJ)
6465
# WARNING: To implement +V this will need to be changed!
6566

@@ -83,7 +84,7 @@ function symmetrize_nhub(nhubbard::Array{Matrix{Complex{T}}}, lattice, symmetrie
8384
sym_atom = find_symmetry_preimage(positions, positions[iatom], symmetry)
8485
for m1 in 1:size(ns[σ, iatom, iatom], 1), m2 in 1:size(ns[σ, iatom, iatom], 2)
8586
# TODO: Here QE flips spin for time-reversal in collinear systems, should we?
86-
for m0 in 1:size(nhubbard[σ, iatom, iatom], 1), m00 in 1:size(nhubbard[σ, iatom, iatom], 2)
87+
for m0 in 1:size(nhubbard[σ,iatom,iatom],1), m00 in 1:size(nhubbard[σ,iatom,iatom],2)
8788
ns[σ, iatom, iatom][m1, m2] += WigD[m0, m1] *
8889
nhubbard[σ, sym_atom, sym_atom][m0, m00] *
8990
WigD[m00, m2]
@@ -135,14 +136,15 @@ function compute_nhubbard(manifold::OrbitalManifold,
135136
# We divide by filled_occ to deal with the physical two spin channels separately.
136137
ψk, projk, nk = @views ψ[ik], projectors[ik], occupation[ik]/filled_occ
137138
c = projk' * ψk # <ϕ|ψ>
138-
# The matrix product is done over the bands. In QE, basis.kweights[ik]*nk[ibnd] would be wg(ik,ibnd)
139+
# The matrix product is done over the bands.
140+
# In QE, basis.kweights[ik]*nk[ibnd] would be wg(ik,ibnd)
139141
n_matrix[σ, :, :] .+= basis.kweights[ik] * c * diagm(nk) * c'
140142
end
141143
n_matrix = mpi_sum(n_matrix, basis.comm_kpts)
142144

143145
# Now I want to reshape it to match the notation used in the papers.
144-
# Reshape into n[I, J, σ][m1, m2] where I, J indicate the atom in the Hubbard manifold, σ is the spin,
145-
# m1 and m2 are magnetic quantum numbers (n, l are fixed)
146+
# Reshape into n[I, J, σ][m1, m2] where I, J indicate the atom in the Hubbard manifold,
147+
# σ is the spin, m1 and m2 are magnetic quantum numbers (n, l are fixed)
146148
manifold_atoms = findall(at -> at.species == Symbol(manifold.species), basis.model.atoms)
147149
natoms = length(manifold_atoms) # Number of atoms of the species in the manifold
148150
nhubbard = Array{Matrix{Complex{T}}}(undef, nspins, natoms, natoms)
@@ -178,7 +180,8 @@ function compute_nhubbard(manifold::OrbitalManifold,
178180
return (; nhubbard, manifold_labels=labels, p_I)
179181
end
180182

181-
function reshape_hubbard_proj(basis, projectors::Vector{Matrix{Complex{T}}}, labels, manifold) where {T}
183+
function reshape_hubbard_proj(basis, projectors::Vector{Matrix{Complex{T}}},
184+
labels, manifold) where {T}
182185
manifold_atoms = findall(at -> at.species == Symbol(manifold.species), basis.model.atoms)
183186
natoms = length(manifold_atoms)
184187
nprojs = length(labels)

test/hamiltonian_consistency.jl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ using Logging
55
using DFTK: mpi_sum
66
using LinearAlgebra
77
using ..TestCases: silicon
8-
using PseudoPotentialData
9-
testcase = silicon
8+
testcase = silicon
109

1110
function test_matrix_repr_operator(hamk, ψk; atol=1e-8)
1211
for operator in hamk.operators
@@ -94,17 +93,17 @@ end
9493
test_consistency_term(ExternalFromFourier(X -> abs(norm(X))))
9594
test_consistency_term(LocalNonlinearity-> ρ^2))
9695
test_consistency_term(Hartree())
97-
test_consistency_term(Hubbard(DFTK.OrbitalManifold(;species=:Si, label="3P"), 10))
96+
test_consistency_term(Hubbard(DFTK.OrbitalManifold(;species=:Si, label="3P"), 0.01), )
9897
test_consistency_term(Ewald())
9998
test_consistency_term(PspCorrection())
10099
test_consistency_term(Xc([:lda_xc_teter93]))
101100
test_consistency_term(Xc([:lda_xc_teter93]), spin_polarization=:collinear)
102101
test_consistency_term(Xc([:gga_x_pbe]), spin_polarization=:collinear)
103-
test_consistency_term(Xc([:mgga_x_tpss]))
104-
test_consistency_term(Xc([:mgga_x_scan]))
105-
test_consistency_term(Xc([:mgga_c_scan]), spin_polarization=:collinear)
106-
test_consistency_term(Xc([:mgga_x_b00]))
107-
test_consistency_term(Xc([:mgga_c_b94]), spin_polarization=:collinear)
102+
test_consistency_term(Xc([:mgga_x_tpss]; use_nlcc=false))
103+
test_consistency_term(Xc([:mgga_x_scan]; use_nlcc=false))
104+
test_consistency_term(Xc([:mgga_c_scan]; use_nlcc=false), spin_polarization=:collinear)
105+
test_consistency_term(Xc([:mgga_x_b00]; use_nlcc=false))
106+
test_consistency_term(Xc([:mgga_c_b94]; use_nlcc=false), spin_polarization=:collinear)
108107

109108
let
110109
a = 6
@@ -114,6 +113,6 @@ end
114113
test_consistency_term(Magnetic(Apot); kgrid=[1, 1, 1], kshift=[0, 0, 0],
115114
lattice=[a 0 0; 0 a 0; 0 0 0], Ecut=20)
116115
test_consistency_term(DFTK.Anyonic(2, 3.2); kgrid=[1, 1, 1], kshift=[0, 0, 0],
117-
lattice=[a 0 0; 0 a 0; 0 0 0], Ecut=20)
116+
lattice=[a 0 0; 0 a 0; 0 0 0], Ecut=20, spin_polarization=:none)
118117
end
119118
end

test/hubbard.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@testitem "Test Wigner matrices on Silicon symmetries" setup=[TestCases] begin
1+
@testitem "Test Wigner matrices" setup=[TestCases] begin
22
using DFTK
33
using PseudoPotentialData
44
using LinearAlgebra

0 commit comments

Comments
 (0)