Skip to content

Commit

Permalink
fixed so now you should be able to have multiple atoms of the same kind
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Oct 16, 2017
1 parent 142e5ed commit b14417e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
16 changes: 12 additions & 4 deletions src/file_processing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function read_qe_input(filename,T=Float32)
control_blocks = Dict{Symbol,Dict{Symbol,Any}}()
cell_param = Dict{Symbol,Any}()
pseudos = Dict{Symbol,String}()
atoms = Dict{Symbol,Point3D}()
atoms = Dict{Symbol,Array{<:Point3D,1}}()
k_dict = Dict{Symbol,Any}()

open(filename) do f
Expand Down Expand Up @@ -236,7 +236,11 @@ function read_qe_input(filename,T=Float32)
line_segs = split(line)
atom = Symbol(line_segs[1])
position=Point3D(parse(T,line_segs[2]),parse(T,line_segs[3]),parse(T,line_segs[4]))
atoms[atom] = position
if !haskey(atoms,atom)
atoms[atom]=[position]
else
push!(atoms[atom],position)
end
line = readline(f)
end
@goto startlabel
Expand Down Expand Up @@ -264,6 +268,8 @@ function read_qe_input(filename,T=Float32)
return DFInput(:QE,control_blocks,pseudos,cell_param,atoms,k_dict)
end


# change atom writing!
"""
Writes a Quantum Espresso input file.
Expand Down Expand Up @@ -309,8 +315,10 @@ function write_qe_input(filename::String,df_input::DFInput)

if !isempty(df_input.atoms)
write(f,"ATOMIC_POSITIONS (crystal)\n")
for (atom,point) in df_input.atoms
write(f,"$(String(atom)) $(point.x) $(point.y) $(point.z) \n")
for (atom,points) in df_input.atoms
for point in points
write(f,"$(String(atom)) $(point.x) $(point.y) $(point.z) \n")
end
end
write(f,"\n")
end
Expand Down
2 changes: 1 addition & 1 deletion src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mutable struct DFInput
control_blocks::Dict{Symbol,Dict{Symbol,Any}}
pseudos::Dict{Symbol,String}
cell_param::Dict{Symbol,Any}
atoms::Dict{Symbol,Any}
atoms::Dict{Symbol,Array{<:Point3D,1}}
k_points::Dict{Symbol,Any}
end

Expand Down
2 changes: 1 addition & 1 deletion test/file_processing_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ projwfc_input = read_qe_input(joinpath(@__DIR__,"../assets/inputs/qe/projwfc.in"
@test scf_input.pseudos[:Te] == "Te.rel-pbesol-dn-kjpaw_psl.0.2.2.UPF"
@test scf_input.k_points[:option] == :automatic
@test scf_input.k_points[:nk3] == 10
@test scf_input.atoms[:Te] == Point3D{Float64}(0.523252856, 0.523252856, 0.523252856)
@test scf_input.atoms[:Te] == [Point3D{Float64}(0.523252856, 0.523252856, 0.523252856)]

@test bands_input.control_blocks[:control][:calculation] == "'bands'"
@test bands_input.pseudos[:Te] == scf_input.pseudos[:Te]
Expand Down
6 changes: 3 additions & 3 deletions test/job_control_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using DFControl, Base.Test
TT = STDOUT
redirect_stdout()


df_job = load_qe_job("test_job",joinpath(@__DIR__,"../assets/inputs/qe"))
df_job2 = load_qe_job("test_job",joinpath(@__DIR__,"../assets/inputs/qe"),new_homedir="blabla")
@test df_job2.home_dir == "blabla/"
Expand All @@ -10,7 +11,6 @@ df_job2 = load_qe_job("test_job",joinpath(@__DIR__,"../assets/inputs/qe"),new_ho
@test df_job.home_dir == joinpath(@__DIR__,"../assets/inputs/qe/")

mkdir(joinpath(@__DIR__,"../assets/inputs/qe/test_dir/"))

test_dir = joinpath(@__DIR__,"../assets/inputs/qe/test_dir/")
df_job.home_dir = test_dir
save_job(df_job)
Expand Down Expand Up @@ -44,13 +44,13 @@ change_job_data!(df_job,change_data2)
check_keys = Symbol[:sk1,:prefix,:noncolin,:ecutwfc]
@test check_job_data(df_job,check_keys) == Dict(:sk1=>3,:prefix=>"'test'",:noncolin => false, :ecutwfc=> 35)

set_data1 = Dict(:Ze => Point3D(1.2,3.2,1.2))
set_data1 = Dict(:Ze => [Point3D(1.2,3.2,1.2)])
set_data2 = Dict(:control => Dict(:test => true))
set_job_data!(df_job,["bands","scf"],:atoms,set_data1)
set_job_data!(df_job,["bands","scf"],:control_blocks,set_data2)
@test df_job.calculations["bands"].control_blocks[:control][:test]
@test df_job.calculations["scf"].control_blocks[:control][:pseudo_dir] == "'./'"
@test df_job.calculations["scf"].atoms[:Ze] == Point3D(1.2,3.2,1.2)
@test df_job.calculations["scf"].atoms[:Ze] == [Point3D(1.2,3.2,1.2)]

redirect_stdout(TT)
println("")
4 changes: 1 addition & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ using Base.Test

tic()
@testset "File processing tests" begin include("file_processing_tests.jl") end
@testset "Job control tests" begin
include("job_control_tests.jl")
end
@testset "Job control tests" begin include("job_control_tests.jl") end
@testset "Plotting tests" begin include("plotting_tests.jl") end
toc()

0 comments on commit b14417e

Please sign in to comment.