Skip to content

Commit

Permalink
added constant tests
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed May 26, 2018
1 parent 36cab48 commit 71a88d2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/job.jl
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,8 @@ function setwanenergies!(job::DFJob, Emin, bands; Epad=5.0, print=true)
nbnd = sum([sum(orbsize.(t)) for t in projections(job)])
print && info("num_bands=$nbnd (inferred from provided projections).")
winmin, frozmin, frozmax, winmax = wanenergyranges(Emin, nbnd, bands, Epad)
setflags!.(wancalcs, :dis_win_min => winmin, :dis_froz_min => frozmin, :dis_froz_max => frozmax, :dis_win_max => winmax, print=false)
setflags!.(wancalcs, :dis_win_min => winmin, :dis_froz_min => frozmin, :dis_froz_max => frozmax, :dis_win_max => winmax, :num_wann => nbnd, print=false)
return job
end

"""
Expand Down
20 changes: 10 additions & 10 deletions src/qe/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function QEControlBlockInfo(lines::Array{<:AbstractString, 1})
end

#TODO rewrite this this is garbage
function qe_variable(block::AbstractBlockInfo, variable_name::Symbol)
function qevariable(block::AbstractBlockInfo, variable_name::Symbol)
varstr1 = string(variable_name)
for var in block.variables
varstr2 = string(var.name)
Expand Down Expand Up @@ -211,19 +211,19 @@ qe_input_info(input::DFInput{QE}) = getfirst(x-> contains(input.exec, x.exec), Q
qe_input_info(exec::AbstractString) = getfirst(x-> contains(exec, x.exec), QEInputInfos)
qe_input_flags(exec::AbstractString) = allflags(qe_input_info(exec))

function qe_variable(input_info::QEInputInfo, variable_name::Symbol)
function qevariable(input_info::QEInputInfo, variable_name::Symbol)
for block in vcat(input_info.control, input_info.data)
var = qe_variable(block, variable_name)
var = qevariable(block, variable_name)
if var.typ != Void
return var
end
end
return QEVariableInfo()
end

function qe_variable(variable_name::Symbol)
function qevariable(variable_name::Symbol)
for info in QEInputInfos
var = qe_variable(info, variable_name)
var = qevariable(info, variable_name)
if var.typ != Void
return var
end
Expand All @@ -233,18 +233,18 @@ end

function qe_block_variable(input_info::QEInputInfo, variable_name)
for block in vcat(input_info.control, input_info.data)
var = qe_variable(block, variable_name)
var = qevariable(block, variable_name)
if var.typ != Void
return block, var
end
end
return :error, QEVariableInfo()
end

function qe_variable(exec::Exec, varname)
function qevariable(exec::Exec, varname)
for input_info in QEInputInfos
if contains(exec.exec, input_info.exec)
return qe_variable(input_info, varname)
return qevariable(input_info, varname)
end
end
return QEVariableInfo()
Expand Down Expand Up @@ -276,5 +276,5 @@ end

qe_block_variable(input::DFInput, flagname) = qe_block_variable(execs(input)[2].exec, flagname)

flagtype(input::DFInput{QE}, flag) = qe_variable(execs(input)[2], flag).typ
flagtype(::Type{QE}, exec, flag) = qe_variable(exec, flag).typ
flagtype(input::DFInput{QE}, flag) = qevariable(execs(input)[2], flag).typ
flagtype(::Type{QE}, exec, flag) = qevariable(exec, flag).typ
12 changes: 12 additions & 0 deletions test/constant_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using DFControl
import DFControl: searchdir, QEVariableInfo, QEControlBlockInfo, QEInputInfo, QEDataBlockInfo, qevariable

qeassetpath = joinpath(Pkg.dir("DFControl"), "assets/inputs/qe/")
inputinfos = begin
file_paths = qeassetpath .* searchdir(qeassetpath, "INPUT")
QEInputInfo.(file_paths)
end


@test qevariable(inputinfos[2], :calculation).typ == Void
@test qevariable(inputinfos[3], :calculation).typ == qevariable(:calculation).typ
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Base.Test

tic()
@testset "New defaults" begin include("defaults_test.jl") end
@testset "constants" begin include("constant_tests.jl") end
@testset "Setting defaults" begin include("defaults_test.jl") end
@testset "Job from CIF file" begin include("jobfromcif_test.jl") end
@testset "Job control tests" begin include("job_control_tests.jl") end
@testset "Remove defaults" begin include("rmdefaults_test.jl") end
Expand Down

0 comments on commit 71a88d2

Please sign in to comment.