Skip to content

Commit

Permalink
many updates
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed May 11, 2021
1 parent 3d8c06a commit 76c788c
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 75 deletions.
5 changes: 3 additions & 2 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ export searchinput, searchinputs, setcutoffs!

#Interacting with the Structure inside DFJob
export atom, atoms, setatoms!, setpseudos!, projections, setprojections!, cell, a, b, c,
set_magnetization!, symmetry_operators, international, niggli_reduce, update_geometry!
set_magnetization!, symmetry_operators, international, niggli_reduce, update_geometry!,
high_symmetry_kpath, high_symmetry_kpoints

export create_supercell

# Atom interface functions
export name, position_cart, position_cryst, element, pseudo, projections, magnetization, dftu
export distance, set_position!, scale_bondlength!
export distance, set_position!, scale_bondlength!, polyhedron

#Bands related functionality
export bandgap
Expand Down
13 changes: 13 additions & 0 deletions src/atom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,16 @@ function scale_bondlength!(at1::AbstractAtom, at2::AbstractAtom, scale::Real, ce
set_position!(at1, new_p1, cell)
set_position!(at2, new_p2, cell)
end

"""
polyhedron(at::AbstractAtom, atoms::Vector{<:AbstractAtom}, order::Int)
polyhedron(at::AbstractAtom, str::AbstractStructure, order::Int)
Returns a polyhedron around the atom, i.e. the `order` closest atoms.
The returned atoms will be ordered according to their distance to the first one.
In the case of a structure rather than a set of atoms, the search will
be performed over all atoms in the structure.
"""
function polyhedron(at::AbstractAtom, atoms::Vector{<:AbstractAtom}, order::Int)
return sort(atoms, by = x -> distance(x, at))[1:order]
end
9 changes: 7 additions & 2 deletions src/display/glimpse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ const Gl = Glimpse

function Gl.Diorama(str::AbstractStructure)
dio = Diorama(name=Symbol(str.name))
add_structure!(dio, str)
dio[Gl.PointLight].data[1] = Gl.PointLight(diffuse=1.5f0, ambient=1.5f0)
Gl.center_cameras(dio)
return dio
end
function add_structure!(dio::Diorama, str::AbstractStructure)
Entity(dio, Gl.assemble_wire_axis_box(position=zero(Point3f0), x=ustrip(a(str)), y=ustrip(b(str)), z=ustrip(c(str)), color=Gl.BLACK)...)
for at in atoms(str)
origin = Point3f0(ustrip(position_cart(at))...)
Expand All @@ -13,6 +19,5 @@ function Gl.Diorama(str::AbstractStructure)
Entity(dio, Gl.assemble_arrow(origin, origin + Point3f0(magnetization(at)...), color=color, radius_ratio=1.5f0, thickness = 0.05f0)...)
end
end
dio[Gl.PointLight].data[1] = Gl.PointLight(diffuse=1.5f0, ambient=1.5f0)
expose(dio)
return dio
end
1 change: 1 addition & 0 deletions src/fileio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ function read_job_inputs(job_file::String)
elseif occursin("#SBATCH", line)
if occursin("-J", line)
name = split(line)[end]
name = name == "-J" ? "noname" : name
else
push!(header, line)
end
Expand Down
13 changes: 11 additions & 2 deletions src/jobAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ function save(job::DFJob, local_dir=job.local_dir; kwargs...)
mkpath(local_dir)
@info "$local_dir did not exist, it was created."
end
if isempty(job.name)
@warn "Job had no name, changed it to: noname"
job.name = "noname"
end
sanitize_magnetization!(job)
sanitize_projections!(job)
sanitizeflags!(job)
Expand Down Expand Up @@ -665,7 +669,8 @@ function pdos(job::DFJob, atsym::Symbol, filter_word="")
end
end

pdos(job::DFJob, atom::AbstractAtom, args...) = pdos(job, name(atom), args...)
pdos(job::DFJob, atom::AbstractAtom, args...) =
pdos(job, name(atom), args...)

function pdos(job::DFJob, atoms::Vector{AbstractAtom} = atoms(job), args...)
t_energies, t_pdos = pdos(job, atoms[1], args...)
Expand All @@ -676,5 +681,9 @@ function pdos(job::DFJob, atoms::Vector{AbstractAtom} = atoms(job), args...)
return (energies=t_energies, pdos=t_pdos)
end

update_geometry!(job::DFJob, new_str::AbstractStructure) = update_geometry!(job.structure, new_str)
update_geometry!(job::DFJob, new_str::AbstractStructure) =
update_geometry!(job.structure, new_str)

high_symmetry_kpath(j::DFJob, args...;kwargs...) =
high_symmetry_kpath(j.structure, args...; kwargs...)

11 changes: 5 additions & 6 deletions src/plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ To plot multiple bands on one plot.
end
end

@recipe function f(job::DFJob, ymin, ymax, occupy_ratio=0.2)
@recipe function f(job::DFJob, ymin, ymax, occupy_ratio=0.2; overlap_spin=false)
ylims --> [ymin, ymax]
if !isQEjob(job)
error("output plotting only implemented for QE jobs.")
Expand All @@ -109,7 +109,6 @@ end
tick_vals = Int[]
tick_syms = String[]
kpoints = bands isa NamedTuple ? bands.up[1].k_points_cryst : bands[1].k_points_cryst
@show ks.kpoints
for (i, k) in enumerate(kpoints)
if ks!==nothing
kpath = ks.kpoints
Expand Down Expand Up @@ -156,7 +155,7 @@ end
# PDOS part
projwfc = getfirst(x -> isprojwfccalc(x) && hasoutfile(x), inputs(job))
if projwfc !== nothing
if bands isa NamedTuple
if bands isa NamedTuple && !overlap_spin
doswindow = 3
layout --> (1,3)
else
Expand Down Expand Up @@ -242,13 +241,13 @@ end
lab = ""
end
for (ib, (b, c)) in enumerate(zip(bnds[window_ids], colors))
plot_band(b, c, ib == 1 ? lab : "", iplt)
plot_band(b, c, ib == 1 ? lab : "", overlap_spin ? 1 : iplt)
end
end

# If no pdos is present
else
if bands isa NamedTuple
if bands isa NamedTuple && !overlap_spin
layout := (1,2)
else
layout := (1,1)
Expand All @@ -261,7 +260,7 @@ end
color = iplt == 1 ? :blue : :red
#loop over bands inside window
for (ib, b) in enumerate(bnds[window_ids])
plot_band(b, color, ib == 1 ? lab : "", iplt)
plot_band(b, color, ib == 1 ? lab : "", overlap_spin ? 1 : iplt)
end
end
else
Expand Down
Loading

0 comments on commit 76c788c

Please sign in to comment.