Skip to content

Commit

Permalink
supercell business
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Jul 9, 2019
1 parent 2c6ce6d commit 533da20
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export searchinput, searchinputs, setcutoffs!, setname!
export atom, atoms, setatoms!, setpseudos!, projections, setprojections!, cell,
set_magnetization!

export create_supercell

# Atom interface functions
for interface_function in (:name,
:position_cart,
Expand Down
2 changes: 1 addition & 1 deletion src/atom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Atom(name::Symbol, el::Symbol, args...; kwargs...) =
Atom(name, element(el), args...; kwargs...)

#TODO this is a little iffy
Atom(orig_at::Atom, new_pos_cart::Point3) = Atom(name(orig_at), element(orig_at), new_pos_cart, position_cryst(orig_at), pseudo(orig_at), projections(orig_at), magnetization(orig_at), dftu(orig_at))
Atom(orig_at::Atom, new_pos_cart::Point3, new_pos_cryst::Point3) = Atom(name(orig_at), element(orig_at), new_pos_cart, new_pos_cryst, pseudo(orig_at), projections(orig_at), magnetization(orig_at), dftu(orig_at))
#Easiest way to implement a new abstractatom is to provide a way to access
#the struct holding `name`, `position_cart`, `element`, `pseudo`, `projection` fields
atom(at::Atom) = at
Expand Down
3 changes: 3 additions & 0 deletions src/jobAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,6 @@ set_magnetization!(job::DFJob, args...) =

Base.joinpath(job::DFJob, p) =
joinpath(job.local_dir, p)

create_supercell(job::DFJob, args...) =
create_supercell(structure(job), args...)
14 changes: 8 additions & 6 deletions src/structure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,16 @@ function create_supercell(structure::AbstractStructure, na::Int, nb::Int, nc::In
orig_cell = cell(structure)
scale_mat = diagm(0 => 1 .+ [na, nb, nc])
new_cell = orig_cell * scale_mat
new_atoms = deepcopy(orig_ats)
new_atoms = eltype(orig_ats)[]
for ia=0:na, ib=0:nb, ic=0:nc
if all((ia, ib, ic) .== 0)
continue
end
transl_vec = orig_cell*[ia, ib, ic]
# if all((ia, ib, ic) .== 0)
# continue
# end
transl_vec = orig_cell * [ia, ib, ic]
for at in orig_ats
push!(new_atoms, Atom(at, position_cart(at)+transl_vec))
cart_pos = position_cart(at) + transl_vec
cryst_pos = inv(new_cell) * cart_pos
push!(new_atoms, Atom(at, cart_pos, Point3(cryst_pos)))
end
end
return Structure(name(structure), Mat3(new_cell), new_atoms, data(structure))
Expand Down

0 comments on commit 533da20

Please sign in to comment.