Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mfherbst committed Aug 2, 2024
1 parent ca59931 commit d002617
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 20 deletions.
3 changes: 3 additions & 0 deletions docs/src/apireference.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ CurrentModule = GeometryOptimization

# API reference

```@index
```

```@autodocs
Modules = [GeometryOptimization]
```
13 changes: 10 additions & 3 deletions docs/src/examples/aluminium_dftk.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ using DFTK
model_kwargs = (; functionals=[:lda_x, :lda_c_pw], temperature=1e-3)
basis_kwargs = (; kgrid=(3, 3, 3), Ecut=10.0)
scf_kwargs = (; tol=1e-5, mixing=KerkerMixing())
calc = DFTKCalculator(; model_kwargs, basis_kwargs, scf_kwargs, verbose=true);
scf_kwargs = (; tol=1e-6, mixing=KerkerMixing())
calc = DFTKCalculator(; model_kwargs, basis_kwargs, scf_kwargs, verbose=true)
nothing
```

We attach pseudopotentials to the aluminium system,
i.e. we tell DFTK, that each aluminium atom should be modelled using
a pseudopotential rather than the full Coulomb potential.

```@example dftk-aluminium
system = attach_psp(system; Al="hgh/lda/al-q3");
system = attach_psp(system; Al="hgh/lda/al-q3")
nothing
```

!!! info "Crude computational parameters"
Expand All @@ -49,6 +51,11 @@ GO = GeometryOptimization
results = minimize_energy!(system, calc, GO.OptimLBFGS();
tol_force=1e-4u"eV/Å",
show_trace=true)
nothing
```

The final energy is
```@example dftk-aluminium
results.energy
```

Expand Down
18 changes: 9 additions & 9 deletions docs/src/examples/tial_lj.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ using EmpiricalPotentials
using GeometryOptimization
GO = GeometryOptimization
system = load_system(joinpath(pkgdir(EmpiricalPotentials), "data/TiAl-1024.xyz")
# Convert to AbstractSystem, so we have the `particles` attribute.
particles = map(system) do atom
Atom(; pairs(atom)...)
end
system = AbstractSystem(data; particles)
system = load_system(joinpath(pkgdir(EmpiricalPotentials), "data/TiAl-1024.xyz"))
nothing
```

Setup calculator:
```@example tial
using Unitful
using UnitfulAtomic
calc = LennardJones(-1.0u"meV", 3.1u"Å", 13, 13, 6.0u"Å")
nothing
```

Minimise energy:
```@example tial
```julia
## TODO: Should run as @example once EmpiricalPotentials is compatible

results = minimize_energy!(system, calc, GO.OptimCG(); maxiters=10, show_trace=true)
results.energy
```

Final structure:
```@example tial
```julia
## TODO: Should run as @example once EmpiricalPotentials is compatible

results.system
```
4 changes: 0 additions & 4 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,3 @@ calculators to employ.
Note that [`minimize_energy!`](@ref) supports further arguments to fine-tune the
convergence tolerance or customise the solver selection.
See the API documentation or the examples to explore this.


```@index
```
2 changes: 1 addition & 1 deletion src/GeometryOptimization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $(TYPEDSIGNATURES)
$(DOCSTRING)
"""

include("atomsbase_interface.jl")
include("clamping_updating_positions.jl")
include("optimization.jl")

end
17 changes: 14 additions & 3 deletions src/atomsbase_interface.jl → src/clamping_updating_positions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@
#
export clamp_atoms

"""
Convert the input system to a kind of system we can work with, i.e. one where
we have the `particles` keyword argument for setting new particles and positions.
"""
function convert_to_updatable(system)
if length(system) > 0 && !(system[1] isa Atom)
particles = [Atom(; pairs(atom)...) for atom in system]
AbstractSystem(system; particles)
else
system
end
end

"""
Creates a new system based on ``system`` but with atoms positions updated
to the ones provided.
"""
function update_positions(system, positions::AbstractVector{<:AbstractVector{<:Unitful.Length}})
particles = [Atom(atom; position) for (atom, position) in zip(system, positions)]
Expand Down Expand Up @@ -52,6 +63,6 @@ indices corresponding to their positions in the system.
function clamp_atoms(system, clamped_indexes::Union{AbstractVector{<:Integer},Nothing})
clamped = falses(length(system))
clamped[clamped_indexes] .= true
particles = [Atom(atom; clamped=m) for (atom, m) in zip(system, clamped)]
AbstractSystem(system, particles=particles)
particles = [Atom(atom; clamped=msk) for (atom, msk) in zip(system, clamped)]
AbstractSystem(system; particles)
end
2 changes: 2 additions & 0 deletions src/optimization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ function minimize_energy!(system, calculator, solver;
tol_virial=1e-6u"eV", # TODO How reasonable ?
callback=(x,y) -> false,
kwargs...)
system = convert_to_updatable(system)

geoopt_state = GeometryOptimizationState(system, calculator)
problem = OptimizationProblem(system, calculator, geoopt_state; sense=Optimization.MinSense)
converged = false
Expand Down

0 comments on commit d002617

Please sign in to comment.