Skip to content

Commit

Permalink
only flags left
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Jun 19, 2021
1 parent d5da023 commit 4eea6a7
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 151 deletions.
8 changes: 0 additions & 8 deletions docs/api/atom.md

This file was deleted.

8 changes: 0 additions & 8 deletions docs/api/defaults.md

This file was deleted.

8 changes: 0 additions & 8 deletions docs/api/fileio.md

This file was deleted.

10 changes: 0 additions & 10 deletions docs/api/input.md

This file was deleted.

8 changes: 0 additions & 8 deletions docs/api/job.md

This file was deleted.

6 changes: 0 additions & 6 deletions docs/api/library.md

This file was deleted.

11 changes: 0 additions & 11 deletions docs/api/printing.md

This file was deleted.

8 changes: 0 additions & 8 deletions docs/api/structure.md

This file was deleted.

8 changes: 0 additions & 8 deletions docs/api/utils.md

This file was deleted.

7 changes: 7 additions & 0 deletions docs/src/guide/calculations.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ set_kpoints!
```

## Flags
A big part of working with DFT calculations is specifying the various calculation flags.
Remembering all the names of the flags, where they belong, and what types they are expected to be,
is quite complicated and can lead to easily made mistakes like typos.
DFControl tries to catch these as it knows which flags are allowed for which calculations.
It will report when a flag can not be found for a given [`DFCalculation`](@ref Calculations),
and it will


## Execs
```@docs
Expand Down
39 changes: 38 additions & 1 deletion docs/src/guide/structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,60 @@ scale_cell!
```@docs
Atom
atoms(::Structure)
set_position!
```
## Element
```@docs
DFControl.Element
element
```

# [Pseudo Potentials](@id pseudo_header)
## [Pseudo Potentials](@id pseudo_header)
```@docs
Pseudo
set_pseudo!
set_pseudos!
```
!!! note
If pseudopotentials from different sets/directories are specified for the atoms, they will be
copied to the `DFJob` `local_dir`.

### Pseudo sets
See the section on [Configuration](@ref) for a demonstration on how to set up pseudopotential sets.
```@docs
getdefault_pseudo
setdefault_pseudodir
configuredefault_pseudos
```

## Magnetization
Magnetization can be set on a per [`Atom`](@ref Atom) basis. It will partially determine the unique
[`Atom`](@ref Atom) types and also what calculation flags should be set in order to allow for the
magnetic calculation (either colinear or non-colinear).
```@docs
set_magnetization!
```

## Projections
These projections will mainly be used for generating Wannier90 inputs, and to distinguish which indices
in the Wannier90 output matrices correspond to the various atoms/orbitals.
```@docs
Projection
set_projections!
```

### Orbitals
```@docs
Orbital
orbital
```

## DFT + U
```@docs
DFTU
set_Hubbard_U!
set_Hubbard_J0!
set_Hubbard_α!
set_Hubbard_β!
set_Hubbard_J!
```
6 changes: 3 additions & 3 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ DFControl is aimed to be user friendly first and foremost, with features being a
DFControl therefore should never be a barrier to DFT code functionality, just a tool to increase efficiency of its users.

In light of this DFControl is structured to mimic the often adopted strategy of a linear submission script that specifies which input files
are ran with which DFT codes producing which outputs. Everything revolves around the [`DFJob`](@ref Jobs) that holds a collection of [`DFCalculations`](@ref Calculations) which will be ran sequentially in the job's directory, on the job's crystal [`Structure`](@ref Structure). A `DFJob` is therefore identified with a specific directory.
Using the script that is created upon saving or submitting a job, a `DFJob` can be easily reloaded at a later stage to continue the investigation where left off.
are ran with which DFT codes producing which outputs. Everything revolves around the [`DFJob`](@ref Jobs) that holds a collection of [`DFCalculations`](@ref Calculations) which will be ran sequentially in the job's directory, on the job's crystal [`Structure`](@ref Structure). A [`DFJob`](@ref Jobs) is therefore identified with a specific directory.
Using the script that is created upon saving or submitting a job, a [`DFJob`](@ref Jobs) can be easily reloaded at a later stage to continue the investigation where left off.


## Highlighted features
- Creation and submission of a simple self-consistent-field calculation starting from a structure Cif file in less than 10 lines of code (see the [Basic Tutorial](@ref)])
- Separation of `Structure` and `DFInput` so that the same `DFInputs` can be copied and used with a different `Structure` in a new job
- Separation of [`Structure`](@ref Structure) and [`DFCalculation`](@ref Calculations) so that the same [`DFCalculations`](@ref Calculations) can be copied and used with a different [`Structure`](@ref Structure) in a new job
- Automatic validation and conversion of input flags
- Tracking of jobs for ease of continuation at later times
- Ease of input generation
Expand Down
10 changes: 5 additions & 5 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ export gencalc_scf, gencalc_vcrelax, gencalc_nscf, gencalc_bands,
include("jobAPI.jl")
#Basic Job Control Functionality
export save, submit, abort, set_flow!, set_headerword!, isrunning, last_running_calculation, progressreport,
set_serverdir!, set_localdir!, structure,
set_serverdir!, set_localdir!, structure, scale_cell!, volume,
switch_version, version, versions, registered_jobs, rm_version!, rm_versions!, rm_tmp_dirs!,
cleanup

#Basic Interaction with DFCalculations inside DFJob
export searchcalculation, searchcalculations, set_cutoffs!

#Interacting with the Structure inside DFJob
export atom, atoms, set_atoms!, set_pseudos!, projections, set_projections!,
set_magnetization!, symmetry_operators, international, niggli_reduce, update_geometry!,
high_symmetry_kpath, high_symmetry_kpoints, element
export atom, atoms, set_atoms!, set_pseudo!, set_pseudos!, projections, set_projections!, orbital, cell, a, b, c,
cell_parameters, set_magnetization!, symmetry_operators, international, niggli_reduce, update_geometry!,
high_symmetry_kpath, high_symmetry_kpoints

export create_supercell, cell_parameters, cell, a, b, c, volume, scale_cell!, volume
export create_supercell

# Atom interface functions
export name, position_cart, position_cryst, element, pseudo, projections, magnetization, dftu
Expand Down
2 changes: 1 addition & 1 deletion src/DFControl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module DFControl
export Vec3, Point3
include("types.jl")
export DFJob, Exec, DFCalculation, InputData
export Structure, Atom, Pseudo, DFTU
export Structure, Atom, Pseudo, DFTU, Orbital, Projection

include("atom.jl")
include("structure.jl")
Expand Down
117 changes: 56 additions & 61 deletions src/atom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,52 +125,6 @@ set_name!(at::AbstractAtom, name::Symbol) =

length_unit(at::Atom{T, LT}) where {T, LT} = LT

function set_pseudo!(at::AbstractAtom, pseudo::Pseudo; print=true)
print && @info "Pseudo of atom $(name(at)) set to $pseudo."
!ispath(path(pseudo)) && @warn "Pseudopath $(path(pseudo)) not found."
atom(at).pseudo = pseudo
end

function set_projections!(at::AbstractAtom, projections::Vector{Projection}; print=true)
print && @info "Setting projections for atom $(name(at)) to $projections"
atom(at).projections = projections
end

"""
set_projections!(str::Structure, projs::Pair...; soc=false)
Sets the projections of the specified atoms. `projs` has to be of form `:atsym => [:proj]`,
where proj = :s, :p, :d, :f, etc. If `soc` is set to `true` both up and down projections will be taken into account.
"""
function set_projections!(str::Structure, projs::Pair...; soc = false, kwargs...)
projdict = Dict(projs)
for at in unique(str.atoms)
if !haskey(projdict, name(at))
projdict[name(at)] = [proj.orb for proj in projections(at)]
end
end
emptyprojections!(str)
addprojections!(atoms(str), projdict, soc; kwargs...)
end

function emptyprojections!(str::Structure)
for at in str.atoms
empty!(projections(at))
end
end

function nprojections(structure)
n = 0
for at in atoms(structure)
projs = projections(at)
if !isempty(projs)
n += sum(orbsize.(projs))
end
end
return n
end


bondlength(at1::AbstractAtom{T}, at2::AbstractAtom{T}, R=T(0.0)) where T<:AbstractFloat = norm(position_cart(at1) - position_cart(at2) - R)

==(at1::AbstractAtom{T, LT}, at2::AbstractAtom{T, LT}) where {T, LT} =
Expand Down Expand Up @@ -226,14 +180,29 @@ function position_string(::Type{QE}, at::AbstractAtom; relative=true)
return "$(name(at)) $(pos[1]) $(pos[2]) $(pos[3])\n"
end

"""
set_magnetization!(at::AbstractAtom, mag; print=true)
Sets the magnetization of the [`Atom`](@ref Atom).
set_magnetization!(str::Structure, atsym_mag::Pair{Symbol,<:AbstractVector}...)
set_magnetization!(job::DFJob, atsym_mag::Pair{Symbol,<:AbstractVector}...)
Each of the names in `atsym_mag` will be matched with the [`Atoms`](@ref Atom) and their magnetization
will be set to the specified ones.
Example:
```
set_magnetization!(job, :Ni1 => [0.0, 0.0, -1.0], :Ni2 => [0.0, 0.0, 1.0])
```
will set all the moments of [`Atoms`](@ref Atom) with name `Ni1` to `[0.0, 0.0, -1.0]` and `Ni2` to `[0.0, 0.0, 1.0]`.
Since the moments are aligned with the z-direction this will signal that colinear calculations should be ran.
"""
function set_magnetization!(at::AbstractAtom, mag; print=true)
at.magnetization = convert(Vec3, mag)
print && @info "Magnetization of at $(name(at)) was set to $(magnetization(at))"
end

set_magnetization!(job::DFJob, args...) =
set_magnetization!(job.structure, args...)

function set_magnetization!(str::Structure, atsym_mag::Pair{Symbol,<:AbstractVector}...)
for (atsym, mag) in atsym_mag
for at in str[atsym]
Expand All @@ -242,6 +211,10 @@ function set_magnetization!(str::Structure, atsym_mag::Pair{Symbol,<:AbstractVec
end
end

set_magnetization!(job::DFJob, args...) =
set_magnetization!(job.structure, args...)



projections(str::AbstractStructure) = projections.(atoms(str))
hasprojections(str::AbstractStructure) = !all(isempty, projections(str))
Expand Down Expand Up @@ -293,7 +266,40 @@ function scale_bondlength!(at1::AbstractAtom, at2::AbstractAtom, scale::Real, ce
set_position!(at2, new_p2, cell)
end

"sets the pseudopotentials to the specified one in the default pseudoset."
"""
set_pseudo!(at::AbstractAtom, pseudo::Pseudo; print=true)
Sets the pseudopotential `at` to `pseudo`, and the validity of the `Pseudo` is checked.
"""
function set_pseudo!(at::AbstractAtom, pseudo::Pseudo; print=true)
print && @info "Pseudo of atom $(name(at)) set to $pseudo."
!ispath(path(pseudo)) && @warn "Pseudopath $(path(pseudo)) not found."
atom(at).pseudo = pseudo
end

"""
set_pseudos!(job::DFJob, set::Symbol, specifier::String=""; kwargs...)
set_pseudos!(structure::AbstractStructure, set::Symbol, specifier::String=""; kwargs...)
set_pseudos!(job::DFJob, atsym::Symbol, set::Symbol, specifier::String=""; kwargs...)
set_pseudos!(structure::AbstractStructure, atsym::Symbol, set::Symbol, specifier::String=""; kwargs...)
Sets the pseudopotentials of the atoms inside the `structure` (or `job.structure`) to the ones of `set`.
`specifier` can be specified to select a specific pseudo if multiple pseudopotentials
for a given element exist in the set.
Example:
```
set_pseudos!(job, :pbesol, "rrkjus")
```
will select the pseudo file that contains "rrkjus" in the filename.
If `atsym` is used, only the pseudos of the atoms with that name will be set.
set_pseudos!(job::DFJob, at_pseudos::Pair{Symbol, Pseudo}...; kwargs...)
set_pseudos!(structure::AbstractStructure, at_pseudos::Pair{Symbol, Pseudo}...; kwargs...)
Convenience function that allows to set pseudopotentials for multiple atom types at the same time.
e.g. `set_pseudos!(job, :Si => getdefault_pseudo(:Si, :sssp)
"""
set_pseudos!(job::DFJob, set::Symbol, specifier::String=""; kwargs...) =
set_pseudos!(job.structure, set, specifier; kwargs...)

Expand Down Expand Up @@ -335,17 +341,6 @@ function set_pseudos!(structure::AbstractStructure, at_pseudos::Pair{Symbol,Pseu
end
end

"Returns all the projections inside the job."
projections(job::DFJob) = projections(structure(job))

"""
sets the projections of the specified atoms inside the job structure.
"""
function set_projections!(job::DFJob, projections...; kwargs...)
socid = findfirst(issoc, calculations(job))
set_projections!(job.structure, projections...; soc=socid !== nothing, kwargs...)
end

for hub_param in (:U, :J0, , )
f = Symbol("set_Hubbard_$(hub_param)!")
str = "$hub_param"
Expand Down
2 changes: 1 addition & 1 deletion src/defaults.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ end
Returns the pseudo potential string linked to the atom.
"""
function getdefault_pseudo(atom::Symbol, set=:default; specifier="")
function getdefault_pseudo(atom::Symbol, set::Symbol; specifier="")
maybe_init_defaults()
if tryparse(Int, String(atom)[end:end]) !== nothing
pp_atom = Symbol(String(atom)[1:end-1])
Expand Down

0 comments on commit 4eea6a7

Please sign in to comment.