Skip to content

Commit

Permalink
changed "'"
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Dec 5, 2018
1 parent 00b0c48 commit 8b204e1
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 70 deletions.
10 changes: 5 additions & 5 deletions examples/1createandrun_job_from_cif.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ header = ["#SBATCH -N 1", "#SBATCH --ntasks-per-node=24",
# - calculation specific flags and data are associated with the calculation they belong to
# - common flags can be defined as Pair{Symbol, Any} varargs at the end of the constructor call.

scf_data = Dict(:k_points => [6, 6, 6, 1, 1, 1], :flags => [:verbosity => "'low'"])
scf_data = Dict(:k_points => [6, 6, 6, 1, 1, 1], :flags => [:verbosity => "low"])
bands_data = Dict(:k_points => [[0.5, 0.5, 0.5, 100.],
[0.0, 0.0, 0.0, 100.],
[0.0, 0.5, 0.0, 1.]],
:flags => [:verbosity => "'high'", :nbnd => 8])
:flags => [:verbosity => "high", :nbnd => 8])

nscf_data = merge(bands_data, Dict(:k_points => (10, 10, 10)))
#the order here is the order in which the calculations will run! The first string in the tuple is the executable name that will be ran, which should be in the bin dir.

#Now we load the cif file and create a `DFJob` from it.

job = DFJob(name, local_dir, "/home/ponet/Downloads/9011998.cif", calculations,
:prefix => "'$name'",
:restart_mode => "'from_scratch'",
:prefix => "$name",
:restart_mode => "from_scratch",
:ecutwfc => 18.0,
:mixing_mode => "'plain'",
:mixing_mode => "plain",
:mixing_beta => 0.7,
:conv_thr => 1.0e-8,
#kwargs
Expand Down
2 changes: 1 addition & 1 deletion examples/2edit_job_resubmit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ setflags!(job, :ecutwfc => 25.0) #more `Pair{Symbol, Any}`'s can be given as va

setflags!(job, :ecut_rho => 80.) #won't work, it goes through the QE documentation to find the allowed flags for the input files in the job, and also tries to convert the given value to what it should be.

setflags!(job, :ecutrho => 80., :diagonalization => "'david'")
setflags!(job, :ecutrho => 80., :diagonalization => "david")

#now we might not want to run all the calculations again.
#one can set the job "flow":
Expand Down
2 changes: 1 addition & 1 deletion src/fileio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function writetojob(f, job, _input::DFInput{Wannier90})
id = findfirst(isequal(_input), job.inputs)
seedname = name(_input)
runexec = input(job, "nscf").execs
pw2waninput = qe_generate_pw2waninput(_input, "'$(job.name)'", runexec)
pw2waninput = qe_generate_pw2waninput(_input, "$(job.name)", runexec)
preprocess = pop!(flags(_input), :preprocess)

if !preprocess || !should_run
Expand Down
20 changes: 10 additions & 10 deletions src/input.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,23 @@ end
function setkpoints!(input::DFInput{QE}, k_grid::NTuple{3, Int}; print=true) #nscf

calc = flag(input, :calculation)
print && calc != "'nscf'" && (@warn "Expected calculation to be 'nscf'.\nGot $calc.")
print && calc != "nscf" && (@warn "Expected calculation to be 'nscf'.\nGot $calc.")
setdata!(input, :k_points, kgrid(k_grid..., :nscf), option = :crystal, print=print)
prod(k_grid) > 100 && setflags!(input, :verbosity => "'high'", print=print)
prod(k_grid) > 100 && setflags!(input, :verbosity => "high", print=print)
return input
end

function setkpoints!(input::DFInput{QE}, k_grid::NTuple{6, Int}; print=true) #scf
calc = flag(input, :calculation)
print && (calc != "'scf'" || !occursin("relax", calc)) && (@warn "Expected calculation to be 'scf', 'vc-relax', 'relax'.\nGot $calc.")
print && (calc != "scf" || !occursin("relax", calc)) && (@warn "Expected calculation to be scf, vc-relax, relax.\nGot $calc.")
setdata!(input, :k_points, [k_grid...], option = :automatic, print=print)
prod(k_grid[1:3]) > 100 && setflags!(input, :verbosity => "'high'", print=print)
prod(k_grid[1:3]) > 100 && setflags!(input, :verbosity => "high", print=print)
return input
end

function setkpoints!(input::DFInput{QE}, k_grid::Vector{NTuple{4, T}}; print=true, k_option=:crystal_b) where T<:AbstractFloat
calc = flag(input, :calculation)
print && calc != "'bands'" && (@warn "Expected calculation to be 'bands', got $calc.")
print && calc != "bands" && (@warn "Expected calculation to be bands, got $calc.")
@assert in(k_option, [:tpiba_b, :crystal_b, :tpiba_c, :crystal_c]) error("Only $([:tpiba_b, :crystal_b, :tpiba_c, :crystal_c]...) are allowed as a k_option, got $k_option.")
if k_option in [:tpiba_c, :crystal_c]
@assert length(k_grid) == 3 error("If $([:tpiba_c, :crystal_c]...) is selected the length of the k_points needs to be 3, got length: $(length(k_grid)).")
Expand All @@ -134,7 +134,7 @@ function setkpoints!(input::DFInput{QE}, k_grid::Vector{NTuple{4, T}}; print=tru
num_k += k[4]
end
if num_k > 100.
setflags!(input, :verbosity => "'high'", print=print)
setflags!(input, :verbosity => "high", print=print)
if print
@info "Verbosity is set to high because num_kpoints > 100,\n
otherwise bands won't get printed."
Expand Down Expand Up @@ -212,7 +212,7 @@ function sanitizeflags!(input::DFInput)
end
function sanitizeflags!(input::DFInput{QE})
cleanflags!(input)
flag(input, :outdir) != fortstring(dir(input)) && setflags!(input, :outdir => fortstring(dir(input)), print=false)
flag(input, :outdir) != "$(dir(input))" && setflags!(input, :outdir => "$(dir(input))", print=false)
#TODO add all the required flags
end

Expand Down Expand Up @@ -299,9 +299,9 @@ function setdataoption!(input::DFInput, name::Symbol, option::Symbol; print=true
return input
end

isbandscalc(input::DFInput{QE}) = flag(input, :calculation) == "'bands'"
isnscfcalc(input::DFInput{QE}) = flag(input, :calculation) == "'nscf'"
isscfcalc(input::DFInput{QE}) = flag(input, :calculation) == "'scf'"
isbandscalc(input::DFInput{QE}) = flag(input, :calculation) == "bands"
isnscfcalc(input::DFInput{QE}) = flag(input, :calculation) == "nscf"
isscfcalc(input::DFInput{QE}) = flag(input, :calculation) == "scf"
isspincalc(input::DFInput{QE}) = all(flag(input, :nspin) .!= [nothing, 1])

outdata(input::DFInput) = input.outdata
Expand Down
45 changes: 22 additions & 23 deletions src/job.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ function DFJob(job_name, local_dir, structure::AbstractStructure, calculations::
common_flags = Dict(common_flags)
end
bin_dir = bin_dir
req_flags = Dict(:prefix => "'$job_name'",
:outdir => "'$server_dir'",
req_flags = Dict(:prefix => "$job_name",
:outdir => "$server_dir",
:ecutwfc => 25.)
merge!(req_flags, common_flags)
for (calc, (excs, data)) in calculations
Expand All @@ -74,13 +74,13 @@ function DFJob(job_name, local_dir, structure::AbstractStructure, calculations::
if !haskey(data, :flags)
data[:flags] = Pair{Symbol, Any}[]
end
push!(data[:flags], :verbosity => "'high'")
push!(data[:flags], :verbosity => "high")
end
k_option = :crystal_b
end
flags = convert(Vector{Pair{Symbol, Any}}, get(data, :flags, Pair{Symbol, Any}[]))
if excs[2].exec == "pw.x"
push!(flags, :calculation => "'$(string(calc_))'")
push!(flags, :calculation => "$(string(calc_))")
datablocks = [InputData(:k_points, k_option, k_points)]
else
datablocks = InputData[]
Expand Down Expand Up @@ -168,8 +168,8 @@ starttime(job::DFJob) = mtime(scriptpath(job))

runslocal(job::DFJob) = job.server=="localhost"
structure(job::DFJob) = job.structure
iswannierjob(job::DFJob) = any(x->package(x) == Wannier90, inputs(job)) && any(x->flag(x, :calculation) == "'nscf'", inputs(job))
getnscfcalc(job::DFJob) = getfirst(x->flag(x, :calculation) == "'nscf'", inputs(job))
iswannierjob(job::DFJob) = any(x->package(x) == Wannier90, inputs(job)) && any(x->flag(x, :calculation) == "nscf", inputs(job))
getnscfcalc(job::DFJob) = getfirst(x->flag(x, :calculation) == "nscf", inputs(job))
cell(job::DFJob) = cell(structure(job))

input(job::DFJob, n::String) = getfirst(x -> occursin(n, name(x)), inputs(job))
Expand Down Expand Up @@ -248,8 +248,7 @@ end

"Runs some checks on the set flags for the inputs in the job, and sets metadata (:prefix, :outdir etc) related flags to the correct ones. It also checks whether flags in the various inputs are allowed and set to the correct types."
function sanitizeflags!(job::DFJob)
setflags!(job, :prefix => "'$(job.name)'", print=false)
# setflags!(job, :outdir => "'./'", print=false)
setflags!(job, :prefix => "$(job.name)", print=false)
if iswannierjob(job)
setflags!(job, :num_bands => flag(getnscfcalc(job), :nbnd), print=false)
end
Expand Down Expand Up @@ -515,14 +514,14 @@ end
function setpseudos!(job::DFJob, set, specifier="")
setpseudos!(job.structure, set, specifier)
dir = getdefault_pseudodir(set)
dir != nothing && setflags!(job, :pseudo_dir => "'$dir'", print=false)
dir != nothing && setflags!(job, :pseudo_dir => "$dir", print=false)
return job
end

"sets the pseudopotentials to the specified one in the default pseudoset."
function setpseudos!(job::DFJob, pseudodir, at_pseudos::Pair{Symbol, String}...)
setpseudos!(job.structure, at_pseudos...)
setflags!(job, :pseudo_dir => "'$pseudodir'", print=false)
setflags!(job, :pseudo_dir => "$pseudodir", print=false)
return job
end
"""
Expand Down Expand Up @@ -590,7 +589,7 @@ function addwancalc!(job::DFJob, nscf::DFInput{QE}, Emin::Real, projections_...;
wannames = ["wan"]
end

@assert flag(nscf, :calculation) == "'nscf'" error("Please provide a valid 'nscf' calculation.")
@assert flag(nscf, :calculation) == "nscf" error("Please provide a valid 'nscf' calculation.")
if flag(nscf, :nosym) != true
print && (@info "'nosym' flag was not set in the nscf calculation.\nIf this was not intended please set it and rerun the nscf calculation.\nThis generally gives errors because of omitted kpoints, needed for pw2wannier90.x")
end
Expand All @@ -617,8 +616,8 @@ function addwancalc!(job::DFJob, nscf::DFInput{QE}, Emin::Real, projections_...;

setfls!(job, name, flags...) = setflags!(job, name, flags..., print=false)
if spin
setfls!(job, "wanup", :spin => "'up'")
setfls!(job, "wandn", :spin => "'down'")
setfls!(job, "wanup", :spin => "up")
setfls!(job, "wandn", :spin => "down")
end
return job
end
Expand Down Expand Up @@ -708,40 +707,40 @@ function addcalc!(job::DFJob, template::DFInput, name::String, newflags...; inde
addcalc!(job, newcalc, index)
job
end
addcalc!(job::DFJob, template::String, args...; kwargs...) = addcalc!(job, input(job, template), args...; kwargs...)

"""
addcalc!(job::DFJob, kpoints::Vector{NTuple{4}}, newflags...; name="bands", run=true, template="scf")
addcalc!(job::DFJob, template::DFInput, kpoints::Vector{NTuple{4}}, newflags...; name="bands", run=true, template="scf")
Searches for the given template and creates a bands calculation from it.
"""
function addcalc!(job::DFJob, kpoints::Vector{<:NTuple{4}},args...; name="bands", template="scf", kwargs...)
addcalc!(job, template, name, :calculation => "'bands'",args...; kwargs...)
function addcalc!(job::DFJob, template::DFInput, kpoints::Vector{<:NTuple{4}}, args...; name="bands", kwargs...)
addcalc!(job, template, name, :calculation => "bands",args...; kwargs...)
setkpoints!(job, name, kpoints, print=false)
job
end

"""
addcalc!(job::DFJob, kpoints::NTuple{3}, newflags...; name="nscf", run=true, template="scf")
addcalc!(job::DFJob, template::DFInput, kpoints::NTuple{3}, newflags...; name="nscf", run=true, template="scf")
Searches for the given template and creates a bands calculation from it.
"""
function addcalc!(job::DFJob, kpoints::NTuple{3}, args...; name="nscf", template="scf", kwargs...)
addcalc!(job, template, name, :calculation => "'nscf'",args...; kwargs...)
function addcalc!(job::DFJob, template::DFInput, kpoints::NTuple{3}, args...; name="nscf", kwargs...)
addcalc!(job, template, name, :calculation => "nscf",args...; kwargs...)
setkpoints!(job, name, kpoints, print=false)
job
end
"""
addcalc!(job::DFJob, kpoints::NTuple{6}, newflags...; name="scf", run=true, template="nscf")
addcalc!(job::DFJob, template::DFInput, kpoints::NTuple{6}, newflags...; name="scf", run=true, template="nscf")
Searches for the given template and creates a bands calculation from it.
"""
function addcalc!(job::DFJob, kpoints::NTuple{6}, args...; name="scf", template="nscf", kwargs...)
addcalc!(job, template, name, :calculation => "'scf'",args...; kwargs...)
function addcalc!(job::DFJob, template::DFInput, kpoints::NTuple{6}, args...; name="scf", kwargs...)
addcalc!(job, template, name, :calculation => "scf", args...; kwargs...)
setkpoints!(job, name, kpoints, print=false)
job
end

addcalc!(job::DFJob, template::String, args...; kwargs...) = addcalc!(job, input(job, template), args...; kwargs...)
"""
Sets the server dir of the job.
"""
Expand Down
31 changes: 17 additions & 14 deletions src/qe/fileio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -413,18 +413,19 @@ Returns a `DFInput{QE}` and the `Structure` that is found in the input.
"""
function read_qe_input(filename; execs=[Exec("pw.x")], run=true, structure_name="noname")
@assert ispath(filename) "$filename is not a valid path."
lines = read(filename) |>
String |>
x -> split(x, "\n") |>
x -> filter(!isempty, x) .|>
strip |>
lines = read(filename) |>
String |>
x -> split(x, "\n") |>
x -> filter(!isempty, x) .|>
strip |>
x -> filter(y -> y[1] != '!', x) |>
x -> filter(y -> y[1] != '#', x) |>
x -> join(x, "\n") |>
x -> replace(x, ", " => "\n") |>
x -> replace(x, "," => " ") |>
x -> split(x, "\n") .|>
strip |>
x -> join(x, "\n") |>
x -> replace(x, ", " => "\n") |>
x -> replace(x, "," => " ") |>
x -> replace(x, "'" => " ") |>
x -> split(x, "\n") .|>
strip |>
x -> filter(y -> !occursin("&", y), x) |>
x -> filter(y -> !(occursin("/", y) && length(y) == 1), x)

Expand Down Expand Up @@ -571,6 +572,8 @@ function qe_writeflag(f, flag, value)
end
end
end
elseif isa(value, String)
write(f, " $flag = '$value'\n")
else
write(f, " $flag = $value\n")
end
Expand Down Expand Up @@ -673,9 +676,9 @@ end
function qe_generate_pw2waninput(input::DFInput{Wannier90}, qeprefix, runexecs)
flags = Dict()
flags[:prefix] = qeprefix
flags[:seedname] = "'$(name(input))'"
flags[:outdir] = "'$(dir(input))'"
flags[:wan_mode] = "'standalone'"
flags[:seedname] = "$(name(input))"
flags[:outdir] = "$(dir(input))"
flags[:wan_mode] = "standalone"
flags[:write_mmn] = true
flags[:write_amn] = true
if flag(input, :spin) != nothing
Expand All @@ -684,7 +687,7 @@ function qe_generate_pw2waninput(input::DFInput{Wannier90}, qeprefix, runexecs)
if flag(input, :wannier_plot) != nothing
flags[:write_unk] = flag(input, :wannier_plot)
end
if any(flag(input, :berry_task) .== ("morb", "'morb'"))
if any(flag(input, :berry_task) .== ("morb"))
flags[:write_uHu] = true
end
pw2wanexec = Exec("pw2wannier90.x", runexecs[2].dir)
Expand Down
2 changes: 0 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,3 @@ macro undoable(func)
end
end
end

fortstring(s::AbstractString) = "'$s'"
14 changes: 7 additions & 7 deletions test/job_control_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ setkpoints!(nscf2, (3,3,3,0,0,1), print=false)
fermi = read_qe_output(outpath(job, "nscf"))[:fermi]
@test fermi == read_fermi_from_qe_output(joinpath(job.local_dir, "nscf.out"))

addcalc!(job, [(0.5,0.0,0.5,10.0),(0.0,0.0,0.0,10.0),(0.5,0.5,0.5,1.0)], name="bands2")
@test flag(job, "bands2", :calculation) == "'bands'"
addcalc!(job, "bands", [(0.5,0.0,0.5,10.0),(0.0,0.0,0.0,10.0),(0.5,0.5,0.5,1.0)], name="bands2")
@test flag(job, "bands2", :calculation) == "bands"
@test data(job, "bands2", :k_points).data == [(0.5,0.0,0.5,10.0),(0.0,0.0,0.0,10.0),(0.5,0.5,0.5,1.0)]
addcalc!(job, (10,10,10), name="nscf2")
@test flag(job, "nscf2", :calculation) == "'nscf'"
addcalc!(job, (5,5,5,1,1,1), name="1scf2")
@test flag(job, "1scf2", :calculation) == "'scf'"
addcalc!(job, "nscf", (10,10,10), name="nscf2")
@test flag(job, "nscf2", :calculation) == "nscf"
addcalc!(job, "scf", (5,5,5,1,1,1), name="1scf2")
@test flag(job, "1scf2", :calculation) == "scf"
@test job["nscf2"][:calculation] == flag(job, "nscf2", :calculation)


Expand Down Expand Up @@ -89,7 +89,7 @@ job2 = DFJob(local_dir)

setpseudos!(job, "pseudos", :Pt => "Pt.UPF")
@test job.structure.atoms[1].pseudo == "Pt.UPF"
@test job["nscf"][:pseudo_dir] == "'pseudos'"
@test job["nscf"][:pseudo_dir] == "pseudos"

begin
for (calc, calc2) in zip(job.inputs, job2.inputs)
Expand Down
14 changes: 7 additions & 7 deletions test/jobfromcif_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ header = ["#SBATCH -N 1", "#SBATCH --ntasks-per-node=24",
"module load open-mpi/gcc/1.10.4-hfi", "module load mkl/2016.1.056"
]

scf_data = Dict(:k_points => [6, 6, 6, 1, 1, 1], :flags => [:verbosity => "'low'"])
scf_data = Dict(:k_points => [6, 6, 6, 1, 1, 1], :flags => [:verbosity => "low"])
bands_data = Dict(:k_points => [[0.5, 0.5, 0.5, 100.],
[0.0, 0.0, 0.0, 100.],
[0.0, 0.5, 0.0, 1.]],
:flags => [:verbosity => "'high'", :nbnd => 8])
:flags => [:verbosity => "high", :nbnd => 8])

nscf_data = merge(bands_data, Dict(:k_points => [10, 10, 10]))
calculations = [:vc_relax => (excs, scf_data), :scf => (excs, scf_data), :bands => (excs, bands_data), :nscf =>(excs, nscf_data), :blabla => ([Exec(), Exec()], Dict())]

job = DFJob(name, local_dir, joinpath(testjobpath, "Pt.cif"), calculations,
:prefix => "'$name'",
:restart_mode => "'from_scratch'",
:prefix => "$name",
:restart_mode => "from_scratch",
:ecutwfc => 18.0,
:mixing_mode => "'plain'",
:mixing_mode => "plain",
:mixing_beta => 0.7,
:conv_thr => 1.0e-8,
#kwargs
Expand All @@ -44,8 +44,8 @@ show(job)
@test data(job, "scf", :k_points).data == [6, 6, 6, 1, 1, 1]
@test data(job, "nscf", :k_points).data == DFControl.kgrid(10, 10, 10, :nscf)

@test flag(job, "scf", :prefix) == flag(job, "nscf", :prefix) == "'$name'"
@test flag(job, "bands", :verbosity) == "'high'"
@test flag(job, "scf", :prefix) == flag(job, "nscf", :prefix) == "$name"
@test flag(job, "bands", :verbosity) == "high"

setflags!(job, :prefix => "blabla", print=false)
@test flag(job, "scf", :prefix) == flag(job, "nscf", :prefix) == "blabla"
Expand Down

0 comments on commit 8b204e1

Please sign in to comment.