From b14417ebe81080d2ad15f477f3b87aa167e34d55 Mon Sep 17 00:00:00 2001 From: Louis Ponet Date: Mon, 16 Oct 2017 13:35:12 +0200 Subject: [PATCH] fixed so now you should be able to have multiple atoms of the same kind --- src/file_processing.jl | 16 ++++++++++++---- src/types.jl | 2 +- test/file_processing_tests.jl | 2 +- test/job_control_tests.jl | 6 +++--- test/runtests.jl | 4 +--- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/file_processing.jl b/src/file_processing.jl index 1414542b..ba7191d5 100644 --- a/src/file_processing.jl +++ b/src/file_processing.jl @@ -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 @@ -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 @@ -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. @@ -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 diff --git a/src/types.jl b/src/types.jl index 527a872b..f101c957 100644 --- a/src/types.jl +++ b/src/types.jl @@ -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 diff --git a/test/file_processing_tests.jl b/test/file_processing_tests.jl index e124e51e..fc92e4b6 100644 --- a/test/file_processing_tests.jl +++ b/test/file_processing_tests.jl @@ -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] diff --git a/test/job_control_tests.jl b/test/job_control_tests.jl index 2c07d012..58344500 100644 --- a/test/job_control_tests.jl +++ b/test/job_control_tests.jl @@ -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/" @@ -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) @@ -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("") \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 892eac3b..8d3c59d7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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() \ No newline at end of file