Skip to content

Commit

Permalink
added JLD2 conversion from old dftu
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Sep 14, 2023
1 parent dc2338c commit c1a6eb2
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "DFControl"
uuid = "1e31e15d-4957-550d-a244-318eced754ae"
authors = ["Louis Ponet <louisponet@gmail.com>"]
repo = "https://github.com/louisponet/DFControl.jl.git"
version = "0.6.0"
version = "0.6.1"

[deps]
ANSIColoredPrinters = "a4c015fc-c6ff-483c-b24f-f7ea428134e9"
Expand Down
86 changes: 81 additions & 5 deletions src/Display/plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ end
end
end

@recipe function f(job::Job, ymin, ymax, occupy_ratio = 0.2; overlap_spin = false, plot_pdos=true, outdat=Client.outputdata(job))
@recipe function f(job::Job, ymin, ymax, occupy_ratio = 0.2; overlap_spin = false, plot_pdos=true, outdat=Client.outputdata(job), tot_dos=false, energy_guide = true)
palette_ = ismissing(Plots.default(:palette)) ? :default : Plots.default(:palette)
tc = Plots.plot_color(pop!(plotattributes, :seriescolor,
RGB.(Plots.color_list(Plots.palette(palette_)))))
Expand Down Expand Up @@ -126,7 +126,7 @@ end
end
window_ids === nothing && error("No bands inside window")
# We define a single band plotting series here
function plot_band(band, color, label, subplot)
function plot_band(band, color, label, subplot, linestyle=:solid)
if overlap_spin
tit = ""
else
Expand All @@ -136,10 +136,11 @@ end
@series begin
xticks --> (tick_vals, tick_syms)
title --> tit
yguide := subplot == 1 ? "Energy (eV)" : ""
yguide := subplot == 1 && energy_guide ? "Energy (eV)" : ""
serieslabel := label
subplot := subplot
seriescolor := color
linestyle := linestyle
legend --> false
1:length(kpoints), band.eigvals .- frmi
end
Expand All @@ -148,7 +149,7 @@ end
# PDOS part
projwfc = Utils.getfirst(x -> Calculations.isprojwfc(x) && haskey(outdat, x.name), job.calculations)
plot_pdos = plot_pdos && projwfc !== nothing && haskey(outdat[projwfc.name], :energies)
if plot_pdos
if plot_pdos && !tot_dos
if bands isa NamedTuple && !overlap_spin
doswindow = 3
layout --> (1, 3)
Expand Down Expand Up @@ -198,13 +199,15 @@ end
label --> "$(atsym)_$(orb.name)_up"
yguide --> ""
subplot := doswindow
xguide --> ""
seriescolor := atom_colors[1][ia]
title := "DOS"
pd[:, 1], energies .- frmi
end
@series begin
label --> "$(atsym)_$(orb.name)_down"
yguide --> ""
xguide --> ""
subplot := doswindow
seriescolor := atom_colors[2][ia]
title := "DOS"
Expand All @@ -215,6 +218,7 @@ end
label --> "$(atsym)_$(orb.name)"
yguide --> ""
subplot := doswindow
xguide --> ""
seriescolor := atom_colors[1][ia]
title := "DOS"
pd, energies .- frmi
Expand Down Expand Up @@ -255,6 +259,77 @@ end
end
end

elseif plot_pdos && tot_dos
if bands isa NamedTuple && !overlap_spin
doswindow = 3
layout --> @layout [a{0.4w} b{0.4w} c{0.2w}]
else
doswindow = 2
layout --> @layout [a{0.8w} c{0.2w}]
end
energies = outdat[projwfc.name][:energies]
dos = nothing
for projs in values(outdat[projwfc.name][:pdos])
for proj_dos in values(projs)
if dos === nothing
dos = proj_dos
else
dos .+= proj_dos
end
end
end
if dos isa Vector
@series begin
label --> ""
yguide --> ""
xguide --> ""
subplot := doswindow
seriescolor := :black
xticks --> nothing
title := "DOS"
dos, energies .- frmi
end
else
@series begin
label --> "up"
yguide --> ""
xguide --> ""
subplot := doswindow
seriescolor := :blue
xticks --> nothing
title := "DOS"
dos[:, 1], energies .- frmi
end
@series begin
label --> "down"
yguide --> ""
subplot := doswindow
xguide --> ""
xticks --> nothing
seriescolor := :red
title := "DOS"
-1.0*dos[:, 2], energies .- frmi
end
end

@info "Plotting bands..."
if bands isa NamedTuple
#loop over up down
for (iplt, bnds) in enumerate(bands)
lab = iplt == 1 ? "up" : "down"
color = iplt == 1 ? :blue : :red
linestyle = overlap_spin ? (iplt == 1 ? :solid : :dot) : :solid
#loop over bands inside window
for (ib, b) in enumerate(bnds[window_ids[iplt]])
plot_band(b, color, ib == 1 ? lab : "", overlap_spin ? 1 : iplt, linestyle)
end
end
else
for (ib, b) in enumerate(bands[window_ids[1]])
plot_band(b, plt_colors[mod1(ib, length(plt_colors))], "", 1)
end
end

# If no pdos is present
else
if bands isa NamedTuple && !overlap_spin
Expand All @@ -268,9 +343,10 @@ end
for (iplt, bnds) in enumerate(bands)
lab = iplt == 1 ? "up" : "down"
color = iplt == 1 ? :blue : :red
linestyle = overlap_spin ? (iplt == 1 ? :solid : :dot) : :solid
#loop over bands inside window
for (ib, b) in enumerate(bnds[window_ids[iplt]])
plot_band(b, color, ib == 1 ? lab : "", overlap_spin ? 1 : iplt)
plot_band(b, color, ib == 1 ? lab : "", overlap_spin ? 1 : iplt, linestyle)
end
end
else
Expand Down
2 changes: 1 addition & 1 deletion src/Jobs/job.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ StructTypes.StructType(::Type{Job}) = StructTypes.Mutable()
scriptpath(job::Job) = joinpath(job, "job.sh")
submission_time(job::Job) = mtime(scriptpath(job))

runslocal(job::Job) = job.server == "localhost"
runslocal(job::Job) = job.server == RemoteHPC.local_server().name
isarchived(job::Job) = occursin("archived", job.dir)

"""
Expand Down
2 changes: 2 additions & 0 deletions src/Structures/atom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ end

StructTypes.StructType(::Type{DFTU}) = StructTypes.Struct()

Base.convert(::Type{DFTU}, x::JLD2.ReconstructedMutable{:DFTU, (:l, :U, :J0, :α, :β, :J)}) = DFTU(x.l, x.U, x.J0, x.α, x.β, x.J, "ortho-atomic")

"""
Element(symbol::Symbol, Z::Int, name::String, atomic_weight::Float64, color::NTuple{3, Float64})
Expand Down
2 changes: 1 addition & 1 deletion src/Structures/structure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function mergestructures(structures::Vector{Structure})
position_cryst = zero(Point3{Float64}))
for structure in nonvoid[2:end]
for at1 in out.atoms, at2 in structure.atoms
if at1.position_cryst == at2.position_cryst
if isapprox(at1.position_cryst, at2.position_cryst, atol=1e-5)
for fname in fieldnames(typeof(at1))
if fname in [:name, :element, :position_cart, :position_cryst]
continue
Expand Down

0 comments on commit c1a6eb2

Please sign in to comment.