Skip to content

Commit

Permalink
tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Mar 23, 2018
1 parent 8c95b49 commit f31ba54
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 60 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -44,7 +44,7 @@ configure_default_pseudos()
This will then connect to the server, look through all the defined pseudo sets inside the `default_pseudos` and tries to link for each element, for each set the correct filename.
To find out the filename of a certain atom for a certain pseudo set, or to check whether your config worked, you can do:
```julia
default_pseudo(:O, :pbesolrel) #again change `pbesolrel` to the set you defined before
getdefault_pseudo(:O, :pbesolrel) #again change `pbesolrel` to the set you defined before
```
This should return you the filename for the pseudo potential file of Oxygen, `:O`, the format for elements in general is e.g. `:Mn`.
If multiple pseudos are defined for one set and element, you can specify keyword `pseudo_fuzzy = ...` to pull out the one you want to use.
Expand All @@ -64,14 +64,14 @@ When the `job.tt` file gets written upon saving of the `DFJob`, calculations whi

As a quick start to see this in action you can do (Juno is highly recommended, for reading clarity)
```julia
job = load_job(joinpath(Pkg.dir("DFControl"), "test/test_job/"))
job = DFJob(joinpath(Pkg.dir("DFControl"), "test/test_job/"))
```

It will automatically look through the directory for a file which matches the fuzzy `*job*`. This can be specified through kwargs, further info in the documentation and examples.

To do something similar on a directory on a server, you can do
```julia
job = load_server_job("path/to/job/starting_from_home", "local_dir", server=default_server())
job = load_server_job("path/to/job/starting_from_home", "local_dir", server=getdefault_server())
```
If the `local_dir` doesn't exist it will be first created before pulling the `job` script and the calculations that it read from this file.

Expand Down
2 changes: 1 addition & 1 deletion examples/1createandrun_job_from_cif.jl
Expand Up @@ -53,7 +53,7 @@ job = DFJob(name, local_dir, "/home/ponet/Downloads/9011998.cif", calculations,
pseudo_set = :pbesol,
pseudo_specifier = pseudo_specifier
)
# An additional kwarg is `server=default_server()`, which is set to the server you have defined while following the setup in README.
# An additional kwarg is `server=getdefault_server()`, which is set to the server you have defined while following the setup in README.
# This can ofcourse be setd to a different server.

#Now the job can be submitted to the server to run.
Expand Down
2 changes: 1 addition & 1 deletion examples/2edit_job_resubmit.jl
Expand Up @@ -18,7 +18,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'")
#shorthand: stfls!
#shorthand: setflags!!

#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/DFControl.jl
Expand Up @@ -49,7 +49,7 @@ module DFControl
export setflow!
export add!
export runcommand
export runcommand!
export setruncommand!
export setrunflags!
export runflags
export setexecflags!
Expand Down
18 changes: 9 additions & 9 deletions src/defaults.jl
Expand Up @@ -92,11 +92,11 @@ function setdefault_server(server::String)
end

"""
default_server()
getdefault_server()
Returns the default server if it's defined. If it is not defined return "".
"""
function default_server()
function getdefault_server()
if isdefined(:default_server)
return default_server
else
Expand All @@ -105,11 +105,11 @@ function default_server()
end

"""
default_pseudo_dirs()
getdefault_pseudo_dirs()
Returns the default pseudo dirs if it's defined. If it is not defined return nothing.
"""
function default_pseudo_dirs()
function getdefault_pseudo_dirs()
if isdefined(:default_pseudo_dirs)
return default_pseudo_dirs
else
Expand All @@ -122,11 +122,11 @@ function default_pseudo_dir(pseudo_set)
end

"""
configure_default_pseudos(server = default_server(), pseudo_dirs=default_pseudo_dirs())
configure_default_pseudos(server = getdefault_server(), pseudo_dirs=getdefault_pseudo_dirs())
Reads the specified `default_pseudo_dirs` on the `default_server` and sets up the `default_pseudos` variable, and also adds all the entries to the `user_defaults.jl` file.
"""
function configure_default_pseudos(server = default_server(), pseudo_dirs=default_pseudo_dirs())
function configure_default_pseudos(server = getdefault_server(), pseudo_dirs=getdefault_pseudo_dirs())
if server == ""
error("Either supply a valid server string or setup a default server through 'setdefault_server!()'.")
end
Expand Down Expand Up @@ -173,11 +173,11 @@ function configure_default_pseudos(server = default_server(), pseudo_dirs=defaul
end

"""
default_pseudo(atom::Symbol, pseudo_setname=:default; pseudo_specifier=nothing)
getdefault_pseudo(atom::Symbol, pseudo_setname=:default; pseudo_specifier=nothing)
Returns the pseudo potential string linked to the atom.
"""
function default_pseudo(atom::Symbol, pseudo_setname=:default; pseudo_specifier="")
function getdefault_pseudo(atom::Symbol, pseudo_setname=:default; pseudo_specifier="")
if !isnull(tryparse(Int, String(atom)[end:end]))
pp_atom = Symbol(String(atom)[1:end-1])
else
Expand Down Expand Up @@ -250,7 +250,7 @@ function remove_default_input(input::Symbol)
end
end

function default_job_header()
function getdefault_jobheader()
if isdefined(:default_job_header)
return default_job_header
else
Expand Down
4 changes: 2 additions & 2 deletions src/fileio.jl
Expand Up @@ -62,7 +62,7 @@ function write_job_name(f, job::DFJob)
end

function write_job_header(f, job::DFJob)
job_header = job.header == "" ? default_job_header() : job.header
job_header = job.header == "" ? getdefault_jobheader() : job.header
for line in job_header
if contains(line, "\n")
write(f, line)
Expand Down Expand Up @@ -125,7 +125,7 @@ function writetojob(f, job, input::WannierInput)

pw2wanid = findfirst(x -> x.control[1].name == :inputpp && contains(x.exec.exec, "pw2wannier90"), job.calculations[id+1:end])+id
pw2wan = job.calculations[pw2wanid]
stfls!(pw2wan, :seedname => "'$(splitext(input.filename)[1])'")
setflags!(pw2wan, :seedname => "'$(splitext(input.filename)[1])'")

if !pw2wan.run
write(f, "#")
Expand Down
12 changes: 6 additions & 6 deletions src/input.jl
Expand Up @@ -166,9 +166,9 @@ end
Returns the specified 'DataBlock'.
"""
function data(input::DFInput, block_symbol::Symbol)
block = block(input, block_symbol)
if block != nothing && typeof(block) <: DataBlock
return block.data
block_ = block(input, block_symbol)
if block_ != nothing && typeof(block_) <: DataBlock
return block_.data
else
error("No `DataBlock` with name '$block_symbol' found. ")
end
Expand All @@ -180,9 +180,9 @@ end
Returns the block with name `block_symbol`.
"""
function block(input::Union{AbinitInput, WannierInput}, block_symbol::Symbol)
for block in input.data
if block.name == block_symbol
return block
for block_ in input.data
if block_.name == block_symbol
return block_
end
end
return nothing
Expand Down
35 changes: 16 additions & 19 deletions src/job.jl
Expand Up @@ -11,7 +11,7 @@ mutable struct DFJob
server ::String
server_dir ::String
header ::Vector{String}
function DFJob(name, structure, calculations, local_dir, server, server_dir, header = default_job_header())
function DFJob(name, structure, calculations, local_dir, server, server_dir, header = getdefault_jobheader())
if local_dir != ""
local_dir = form_directory(local_dir)
end
Expand All @@ -34,14 +34,14 @@ end

#TODO implement abinit
function DFJob(job_name, local_dir, structure::AbstractStructure, calculations::Vector, common_flags...;
server=default_server(),
server=getdefault_server(),
server_dir="",
package=:qe,
bin_dir="~/bin/",
runcommand=Exec("mpirun", bin_dir, Dict(:np => 24)),
pseudo_set=:default,
pseudo_specifier="",
header=default_job_header())
header=getdefault_jobheader())

@assert package==:qe "Only implemented for Quantum Espresso!"
local_dir = form_directory(local_dir)
Expand Down Expand Up @@ -131,20 +131,20 @@ function DFJob(job::DFJob, flagstoset...;
newjob.name = name
end

stfls!(newjob, flagstoset...)
setflags!!(newjob, flagstoset...)
return newjob
end

"""
DFJob(job_dir::String, T=Float64; job_fuzzy = "job", new_job_name=nothing, new_local_dir=nothing, server=default_server(),server_dir="")
DFJob(job_dir::String, T=Float64; job_fuzzy = "job", new_job_name=nothing, new_local_dir=nothing, server=getdefault_server(),server_dir="")
Loads and returns a local DFJob. If local_dir is not specified the job directory will be registered as the local one.
"""
function DFJob(job_dir::String, T=Float64;
job_fuzzy = "job",
new_job_name = "",
new_local_dir = nothing,
server = default_server(),
server = getdefault_server(),
server_dir = "")

job_dir = form_directory(job_dir)
Expand All @@ -162,11 +162,11 @@ function DFJob(job_dir::String, T=Float64;
end

"""
DFJob(server_dir::String, local_dir::String, server=default_server(); job_fuzzy="*job*", new_job_name="")
DFJob(server_dir::String, local_dir::String, server=getdefault_server(); job_fuzzy="*job*", new_job_name="")
Pulls a server job to local directory and then loads it. A fuzzy search for the job file will be performed and the found input files will be pulled.
"""
function DFJob(server_dir::String, local_dir::String, server = default_server();
function DFJob(server_dir::String, local_dir::String, server = getdefault_server();
job_fuzzy = "*job*",
new_job_name = "")

Expand Down Expand Up @@ -242,7 +242,7 @@ function pulljob(server::String, server_dir::String, local_dir::String; job_fuzz
end
end

pulljob(args...; kwargs...) = pulljob(default_server(), args..., kwargs...)
pulljob(args...; kwargs...) = pulljob(getdefault_server(), args..., kwargs...)


"""
Expand Down Expand Up @@ -362,9 +362,9 @@ Looks through the calculation filenames and returns the value of the specified f
"""
function flag(job::DFJob, calc_filenames, flag_name::Symbol)
for calc in inputs(job, calc_filenames)
flag = flag(calc, flag_name)
if flag != nothing
return flag
flag_ = flag(calc, flag_name)
if flag_ != nothing
return flag_
end
end
error("Flag $flag_name not found in any input files.")
Expand All @@ -377,9 +377,9 @@ Looks through all the calculations and returns the value of the specified flag.
"""
function flag(job::DFJob, flag_name::Symbol)
for calc in job.calculations
flag = flag(calc, flag_name)
if flag != nothing
return flag
flag_ = flag(calc, flag_name)
if flag_ != nothing
return flag_
end
end
error("Flag $flag_name not found in any input files.")
Expand Down Expand Up @@ -455,7 +455,7 @@ function setflow!(job::DFJob, should_runs...)
return job
end

setflow!(job::DFJob, should_runs::Vector{Bool}) = setflow!(job, [calc.filename => run for (calc, run) in zip(inputs(job), should_runs)]...)
setflow!(job::DFJob, should_runs::Vector{Bool}) = setflow!(job, [calc.filename => run for (calc, run) in zip(job.calculations, should_runs)]...)

"""
setflow!(job::DFJob, filenames::Array{String,1}, should_run)
Expand Down Expand Up @@ -899,9 +899,6 @@ function setlocaldir!(job, dir)
return job
end

setserverdir!(job, dir) = setserverdir!(job, dir)
setlocaldir!(job, dir) = setlocaldir!(job, dir)

"""
sets the projections of the specified atoms inside the job structure.
"""
Expand Down
6 changes: 3 additions & 3 deletions src/qe/input.jl
Expand Up @@ -11,9 +11,9 @@ mutable struct QEDataBlock <: DataBlock
end
mutable struct QEInput <: DFInput
filename ::String
control ::Vector{QEControlBlock}
data ::Vector{QEDataBlock}
runcommand ::Exec
control ::Vector{QEControlBlock}
data ::Vector{QEDataBlock}
runcommand ::Exec
exec ::Exec
run ::Bool
end
Expand Down
14 changes: 7 additions & 7 deletions src/server_comm.jl
Expand Up @@ -12,11 +12,11 @@ function pull_file(server::String, server_dir::String, local_dir::String, filena
end

"""
pull_file(server_dir::String, local_dir::String, filename::String; server=default_server())
pull_file(server_dir::String, local_dir::String, filename::String; server=getdefault_server())
Pulls a file from the default server if the default server is specified.
"""
function pull_file(server_dir::String, local_dir::String, filename::String; server=default_server())
function pull_file(server_dir::String, local_dir::String, filename::String; server=getdefault_server())
if server != ""
run(`scp $(server * ":" * server_dir * filename) $local_dir`)
pulled_files = search_dir(local_dir, filename)
Expand All @@ -29,7 +29,7 @@ function pull_file(server_dir::String, local_dir::String, filename::String; serv
end
end

function pull_files(server_dir::String, local_dir::String, filenames::Vector{String}; server=default_server())
function pull_files(server_dir::String, local_dir::String, filenames::Vector{String}; server=getdefault_server())
pulled_files = String[]
for file in filenames
push!(pulled_files, pull_file(server_dir, local_dir, file; server))
Expand All @@ -38,11 +38,11 @@ function pull_files(server_dir::String, local_dir::String, filenames::Vector{Str
end

"""
pull_file(filepath::String, local_dir::String; server=default_server(), local_filename=nothing)
pull_file(filepath::String, local_dir::String; server=getdefault_server(), local_filename=nothing)
Pulls a file from the default server if the default server is specified.
"""
function pull_file(filepath::String, local_dir::String; server=default_server(), local_filename=nothing)
function pull_file(filepath::String, local_dir::String; server=getdefault_server(), local_filename=nothing)
local_dir = form_directory(local_dir)
if server != ""
if local_filename != nothing
Expand Down Expand Up @@ -117,11 +117,11 @@ end
If sbatch is running on server it will return the output of the `qstat` command.
"""
qstat(server) = run(`ssh -t $server qstat`)
qstat() = qstat(default_server())
qstat() = qstat(getdefault_server())

"""
watch_qstat(server)
If sbatch is running on server it will return the output of the `watch qstat` command.
"""
watch_qstat(server) = run(`ssh -t $server watch qstat`)
watch_qstat() = watch_qstat(default_server())
watch_qstat() = watch_qstat(getdefault_server())
6 changes: 3 additions & 3 deletions test/file_processing_tests.jl
Expand Up @@ -52,14 +52,14 @@ else
end
setdefault_pseudo_dir(:default, "/test/test/test");
@test isdefined(:default_pseudo_dirs)
@test DFControl.default_pseudo_dirs()[:default] == "/test/test/test"
@test DFControl.getdefault_pseudo_dirs()[:default] == "/test/test/test"
remove_default_pseudo_dir(:default);
@test length(keys(default_pseudo_dirs))==pr_l

pr_s = DFControl.default_server();
pr_s = DFControl.getdefault_server();

setdefault_server("test/default");
@test DFControl.default_server() == "test/default"
@test DFControl.getdefault_server() == "test/default"
if pr_s != ""
setdefault_server(pr_s)
end
Expand Down
8 changes: 4 additions & 4 deletions test/job_control_tests.jl
@@ -1,8 +1,8 @@
using DFControl, Base.Test

test_job_path = joinpath(@__DIR__, "test_job")
df_job = load_job(test_job_path);
df_job2 = load_job(joinpath(@__DIR__, test_job_path), new_local_dir="blabla");
df_job = DFJob(test_job_path);
df_job2 = DFJob(joinpath(@__DIR__, test_job_path), new_local_dir="blabla");
@test df_job2.local_dir == "blabla/"
@test length(df_job.calculations) == 7
@test input(df_job, "nscf").runcommand.exec == runcommand(df_job, "nscf").exec
Expand All @@ -12,7 +12,7 @@ try mkdir(joinpath(test_job_path,"test_dir/")) end
test_dir = joinpath(test_job_path,"test_dir/")
df_job.local_dir = test_dir
save(df_job)
df_job2 = load_job(test_dir)
df_job2 = DFJob(test_dir)
@test begin
for (i,calc) in enumerate(df_job.calculations)
calc2 = df_job2.calculations[i]
Expand Down Expand Up @@ -63,7 +63,7 @@ setflow!(df_job, "nscf" => true, "bands" => true)
setflow!(df_job, "pw2wan" => true)
@test df_job.calculations[end-1].run

runcommand!(df_job, "nscf", Exec("test"))
setruncommand!(df_job, "nscf", Exec("test"))
@test runcommand(df_job, "nscf").exec == Exec("test").exec

print_run_command(df_job, "nscf")
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Expand Up @@ -5,7 +5,7 @@ using Base.Test


tic()
@testset "Job control tests" begin include("job_control_tests.jl") end
@testset "File processing tests" begin include("file_processing_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 f31ba54

Please sign in to comment.