Skip to content

Commit

Permalink
Store kgrid and kshift if available (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfherbst committed Nov 27, 2020
1 parent 579d43f commit 1f8ad3e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/PlaneWaveBasis.jl
Expand Up @@ -62,6 +62,9 @@ struct PlaneWaveBasis{T <: Real}
# ksymops[ik] is a list of symmetry operations (S,τ)
# mapping to points in the reducible BZ
ksymops::Vector{Vector{SymOp}}
# Monkhorst-Pack grid used to generate the k-Points, or nothing for custom k-Points
kgrid::Union{Nothing,Vec3{Int}}
kshift::Union{Nothing,Vec3{T}}

comm_kpts::MPI.Comm # communicator for the kpoints distribution
krange_thisproc::Vector{Int} # indices of kpoints treated explicitly by this
Expand Down Expand Up @@ -138,7 +141,8 @@ build_kpoints(basis::PlaneWaveBasis, kcoords) =
@timing function PlaneWaveBasis(model::Model{T}, Ecut::Number,
kcoords::AbstractVector, ksymops, symmetries=nothing;
fft_size=nothing, variational=true,
optimize_fft_size=false, supersampling=2) where {T <: Real}
optimize_fft_size=false, supersampling=2,
kgrid=nothing, kshift=nothing) where {T <: Real}
# TODO this constructor is too complicated, we should simplify it
# if possible (esp. the variational part)
mpi_ensure_initialized()
Expand Down Expand Up @@ -238,7 +242,7 @@ build_kpoints(basis::PlaneWaveBasis, kcoords) =

basis = PlaneWaveBasis{T}(
model, Ecut, kpoints,
kweights, ksymops, mpi_comm, krange_thisproc, fft_size,
kweights, ksymops, kgrid, kshift, mpi_comm, krange_thisproc, fft_size,
opFFT, ipFFT, opIFFT, ipIFFT,
opFFT_unnormalized, ipFFT_unnormalized, opBFFT_unnormalized, ipBFFT_unnormalized,
terms, symmetries)
Expand Down Expand Up @@ -289,7 +293,8 @@ function PlaneWaveBasis(model::Model, Ecut::Number;
# store in symmetries the set of kgrid-preserving symmetries
symmetries = symmetries_preserving_kgrid(model.symmetries, kcoords)
end
PlaneWaveBasis(model, Ecut, kcoords, ksymops, symmetries; kwargs...)
PlaneWaveBasis(model, Ecut, kcoords, ksymops, symmetries;
kgrid=kgrid, kshift=kshift, kwargs...)
end

"""
Expand Down
3 changes: 2 additions & 1 deletion src/external/etsf_nanoquanta.jl
Expand Up @@ -145,7 +145,8 @@ function load_basis(T, folder::EtsfFolder; magnetic_moments=[])
@assert kcoords_new normalize_kpoint_coordinate.(kcoords)

fft_size = size(folder.den["density"])[2:4]
PlaneWaveBasis(model, Ecut, kcoords, ksymops, fft_size=fft_size)
PlaneWaveBasis(model, Ecut, kcoords, ksymops, fft_size=fft_size,
kgrid=kgrid, kshift=kshift)
end
load_basis(folder; kwargs...) = load_basis(Float64, folder; kwargs...)

Expand Down
7 changes: 6 additions & 1 deletion src/jld2io.jl
Expand Up @@ -84,6 +84,8 @@ struct PlaneWaveBasisSerialisation{T <: Real}
kcoords::Vector{Vec3{T}}
kweights::Vector{T}
ksymops::Vector{Vector{SymOp}}
kgrid::Union{Nothing,Vec3{Int}}
kshift::Union{Nothing,Vec3{T}}
fft_size::Tuple{Int, Int, Int}
symmetries::Vector{SymOp}
end
Expand All @@ -102,6 +104,8 @@ function Base.convert(::Type{PlaneWaveBasisSerialisation{T}},
getproperty.(basis.kpoints[1:n_kcoords], :coordinate),
basis.kweights[1:n_kcoords],
basis.ksymops[1:n_kcoords],
basis.kgrid,
basis.kshift,
basis.fft_size,
basis.symmetries
)
Expand All @@ -111,5 +115,6 @@ function Base.convert(::Type{PlaneWaveBasis{T}},
serial::PlaneWaveBasisSerialisation{T}) where {T}
PlaneWaveBasis(serial.model, serial.Ecut, serial.kcoords,
serial.ksymops, serial.symmetries;
fft_size=serial.fft_size)
fft_size=serial.fft_size,
kgrid=serial.kgrid, kshift=serial.kshift)
end

0 comments on commit 1f8ad3e

Please sign in to comment.