Skip to content

Commit

Permalink
better handling of projections
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Nov 19, 2019
1 parent a217f99 commit 1cc6473
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/input.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ isdftucalc(input::DFInput) = false
ismagneticcalc(input::DFInput{QE}) = flag(input, :nspin) [2, 4] || (flag(input, :lda_plus_u) == true && flag(input, :noncolin) == true)
ismagneticcalc(input::DFInput) = false

issoccalc(input::DFInput{QE}) = flag(input, :lspinorb) == true && flag(input, :noncolin) == true
issoccalc(input::DFInput{Wannier90}) = flag(input, :spinors) == true
issoccalc(input::DFInput) = false

#TODO review this!
outdata(input::DFInput) = input.outdata
hasoutput(input::DFInput) = !isempty(outdata(input))
Expand Down
8 changes: 5 additions & 3 deletions src/jobAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ function setwanenergies!(job::DFJob, nscf::DFInput{QE}, Emin::Real; Epad=5.0)
bands = readbands(nscf)
wancalcs = searchinputs(job, Wannier90)
@assert length(wancalcs) != 0 "Job ($(job.name)) has no Wannier90 calculations, nothing to do."
nbnd = isnoncolincalc(nscf) ? 2 * nprojections(structure(job)) : nprojections(structure(job))
nbnd = nprojections(structure(job))
@info "num_bands=$nbnd (inferred from provided projections)."
winmin, frozmin, frozmax, winmax = wanenergyranges(Emin, nbnd, bands, Epad)
map(x->setflags!(x, :dis_win_min => winmin, :dis_froz_min => frozmin, :dis_froz_max => frozmax, :dis_win_max => winmax, :num_wann => nbnd, :num_bands=>length(bands)), wancalcs)
Expand Down Expand Up @@ -445,8 +445,10 @@ projections(job::DFJob) = projections(structure(job))
"""
sets the projections of the specified atoms inside the job structure.
"""
setprojections!(job::DFJob, projections...) =
setprojections!(job.structure, projections...)
function setprojections!(job::DFJob, projections...)
socid = findfirst(issoccalc, inputs(job))
setprojections!(job.structure, projections...; soc=socid !== nothing)
end

for hub_param in (:U, :J0, , )
f = Symbol("set_Hubbard_$(hub_param)!")
Expand Down
8 changes: 4 additions & 4 deletions src/structure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ hasprojections_assert(str::AbstractStructure) =
reciprocal(cell::AbstractMatrix) = inv(cell)

"""
setprojections!(str::Structure, projs::Pair...)
setprojections!(str::Structure, projs::Pair...; soc=false)
Sets the projections of the specified atoms. `projs` has to be of form `:atsym => [:proj]`,
where proj = :s, :p, :d, :f, etc.
where proj = :s, :p, :d, :f, etc. If `soc` is set to `true` both up and down projections will be taken into account.
"""
function setprojections!(str::Structure, projs::Pair...)
function setprojections!(str::Structure, projs::Pair...; soc=false)
projdict = Dict(projs)
for at in unique(str.atoms)
if !haskey(projdict, name(at))
projdict[name(at)] = [proj.orb for proj in projections(at)]
end
end
emptyprojections!(str)
addprojections!(atoms(str), projdict)
addprojections!(atoms(str), projdict, soc)
end

function emptyprojections!(str::Structure)
Expand Down
4 changes: 2 additions & 2 deletions src/wannier90/projections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ orbsize(proj::Projection) = proj.last - proj.start + 1
"""
Adds projections to atoms.
"""
function addprojections!(atoms, projections_)
function addprojections!(atoms, projections_, soc)
t_start = 1
for (proj_at, projs) in projections_
for at in atoms
Expand All @@ -41,7 +41,7 @@ function addprojections!(atoms, projections_)
end
for proj in projs
if name(at) == proj_at
size = orbsize(proj)
size = soc ? 2*orbsize(proj) : orbsize(proj)
t_proj = Projection(orbital(proj), t_start, t_start + size - 1)
push!(projections(at), t_proj)
t_start += size
Expand Down

0 comments on commit 1cc6473

Please sign in to comment.