Skip to content

Commit acd31af

Browse files
authored
Update of interface towards AtomsCalculator 0.2 (#11)
1 parent 1cd4598 commit acd31af

23 files changed

+526
-261
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
fail-fast: false
2020
matrix:
2121
version:
22-
- '1.9'
22+
- '1.10'
2323
- 'nightly'
2424
os:
2525
- ubuntu-latest

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/Manifest.toml
22
/docs/Manifest.toml
33
/docs/build/
4+
*~
5+
.*.swp

Project.toml

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,38 @@
11
name = "GeometryOptimization"
22
uuid = "673bf261-a53d-43b9-876f-d3c1fc8329c2"
33
authors = ["JuliaMolSim community"]
4-
version = "0.0.1"
4+
version = "0.0.2"
55

66
[deps]
77
AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a"
88
AtomsCalculators = "a3e0e189-c65a-42c1-833c-339540406eb1"
9-
EmpiricalPotentials = "38527215-9240-4c91-a638-d4250620c9e2"
9+
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
10+
LineSearches = "d3d80556-e9d4-5f37-9878-2ab0fcc64255"
11+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1012
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
1113
OptimizationOptimJL = "36348300-93cb-4f02-beb5-3c3902f8871e"
1214
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1315
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
1416
UnitfulAtomic = "a7773ee8-282e-5fa2-be4e-bd808c38a91a"
1517

1618
[compat]
17-
ASEconvert = "0.1"
1819
AtomsBase = "0.3"
19-
AtomsCalculators = "0.1"
20-
DFTK = "0.6"
21-
EmpiricalPotentials = "0.1.0"
22-
Optimization = "3.20"
23-
OptimizationOptimJL = "0.1"
24-
StaticArrays = "1.8"
20+
AtomsBuilder = "=0.0.4"
21+
AtomsCalculators = "0.2"
22+
DocStringExtensions = "0.9"
23+
LineSearches = "7"
24+
Optimization = "3"
25+
OptimizationOptimJL = "0.3"
26+
StaticArrays = "1"
2527
TestItemRunner = "0.2"
26-
Unitful = "1.19"
27-
UnitfulAtomic = "1.0"
28-
julia = "1.9"
28+
Unitful = "1"
29+
UnitfulAtomic = "1"
30+
julia = "1.10"
2931

3032
[extras]
31-
ASEconvert = "3da9722f-58c2-4165-81be-b4d7253e8fd2"
32-
DFTK = "acf6eb54-70d9-11e9-0013-234b7a5f5337"
33-
EmpiricalPotentials = "38527215-9240-4c91-a638-d4250620c9e2"
33+
AtomsBuilder = "f5cc8831-eeb7-4288-8d9f-d6c1ddb77004"
3434
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3535
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
3636

3737
[targets]
38-
examples = ["DFTK", "ASEconvert", "EmpiricalPotentials"]
39-
test = ["Test", "TestItemRunner"]
38+
test = ["AtomsBuilder", "Test", "TestItemRunner"]

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@
33
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaMolSim.github.io/GeometryOptimization.jl/stable/)
44
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuliaMolSim.github.io/GeometryOptimization.jl/dev/)
55
[![Build Status](https://github.com/JuliaMolSim/GeometryOptimization.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/JuliaMolSim/GeometryOptimization.jl/actions/workflows/CI.yml?query=branch%3Amain)
6+
7+
A geometry optimization package for
8+
[AtomsBase structures](https://github.com/JuliaMolSim/AtomsBase.jl)
9+
and [AtomsCalculator calculators](https://github.com/JuliaMolSim/AtomsCalculators.jl).
10+
See the [documentation](https://JuliaMolSim.github.io/GeometryOptimization.jl/stable/)
11+
for examples and further details.

docs/Project.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
11
[deps]
2+
ASEconvert = "3da9722f-58c2-4165-81be-b4d7253e8fd2"
3+
AtomsBase = "a963bdd2-2df7-4f54-a1ee-49d51e6be12a"
4+
AtomsBuilder = "f5cc8831-eeb7-4288-8d9f-d6c1ddb77004"
5+
AtomsCalculators = "a3e0e189-c65a-42c1-833c-339540406eb1"
6+
AtomsIO = "1692102d-eeb4-4df9-807b-c9517f998d44"
7+
DFTK = "acf6eb54-70d9-11e9-0013-234b7a5f5337"
28
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
9+
EmpiricalPotentials = "38527215-9240-4c91-a638-d4250620c9e2"
310
GeometryOptimization = "673bf261-a53d-43b9-876f-d3c1fc8329c2"
11+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
12+
OptimizationNLopt = "4e6fcdb7-1186-4e1f-a706-475e75c168bb"
13+
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
14+
UnitfulAtomic = "a7773ee8-282e-5fa2-be4e-bd808c38a91a"
15+
16+
[compat]
17+
ASEconvert = "0.1"
18+
DFTK = "0.6"
19+
Documenter = "~1.5"
20+
EmpiricalPotentials = "0.1"

docs/make.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Setup julia dependencies for docs generation if not yet done
2+
import Pkg
3+
Pkg.activate(@__DIR__)
4+
if !isfile(joinpath(@__DIR__, "Manifest.toml"))
5+
Pkg.develop(Pkg.PackageSpec(path=joinpath(@__DIR__, "..")))
6+
Pkg.instantiate()
7+
end
8+
19
using GeometryOptimization
210
using Documenter
311

@@ -16,6 +24,12 @@ makedocs(;
1624
),
1725
pages=[
1826
"Home" => "index.md",
27+
"Examples" => [
28+
"examples/aluminium_dftk.md",
29+
"examples/other_solvers.md",
30+
"examples/tial_lj.md",
31+
],
32+
"apireference.md",
1933
],
2034
)
2135

docs/src/apireference.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
```@meta
2+
CurrentModule = GeometryOptimization
3+
```
4+
5+
# API reference
6+
7+
```@index
8+
```
9+
10+
```@autodocs
11+
Modules = [GeometryOptimization]
12+
```

docs/src/examples/aluminium_dftk.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Aluminium supercell using density-functional theory
2+
3+
In this example we will optimise the structure of a rattled
4+
aluminium system using density-functional theory.
5+
6+
First we build a rattled aluminium system:
7+
8+
```@example dftk-aluminium
9+
using AtomsBuilder
10+
using Unitful
11+
12+
system = rattle!(bulk(:Al; cubic=true), 0.2u"Å")
13+
```
14+
15+
Next we create a calculator employing the
16+
[density-functional toolkit](https://dftk.org/)
17+
to compute energies and forces at using the LDA density functional.
18+
```@example dftk-aluminium
19+
using DFTK
20+
21+
model_kwargs = (; functionals=[:lda_x, :lda_c_pw], temperature=1e-3)
22+
basis_kwargs = (; kgrid=(3, 3, 3), Ecut=10.0)
23+
scf_kwargs = (; tol=1e-6, mixing=KerkerMixing())
24+
calc = DFTKCalculator(; model_kwargs, basis_kwargs, scf_kwargs, verbose=true)
25+
nothing
26+
```
27+
28+
We attach pseudopotentials to the aluminium system,
29+
i.e. we tell DFTK, that each aluminium atom should be modelled using
30+
a pseudopotential rather than the full Coulomb potential.
31+
32+
```@example dftk-aluminium
33+
system = attach_psp(system; Al="hgh/lda/al-q3")
34+
nothing
35+
```
36+
37+
!!! info "Crude computational parameters"
38+
Note, that these numerical parameters are chosen rather crudely in order
39+
to give a fast runtime on CI systems. For production calculations one would
40+
require larger computational parameters.
41+
42+
We perform the structure optimisation using the LBFGS solver
43+
from Optim with solver parameters adapted for our geometry optimisation setting.
44+
This is selected by passing the [GeometryOptimization.OptimLBFGS](@ref)
45+
solver as the third argument.
46+
47+
```@example dftk-aluminium
48+
using GeometryOptimization
49+
GO = GeometryOptimization
50+
51+
results = minimize_energy!(system, calc, GO.OptimLBFGS();
52+
tol_force=1e-4u"eV/Å",
53+
show_trace=true)
54+
nothing
55+
```
56+
57+
The final energy is
58+
```@example dftk-aluminium
59+
results.energy
60+
```
61+
62+
We can view the final structure
63+
```@example dftk-aluminium
64+
results.system
65+
```
66+
67+
Some statistics about the optimisation
68+
```@example dftk-aluminium
69+
results.stats
70+
```
71+
or the details about the selected algorithm:
72+
```@example dftk-aluminium
73+
results.alg
74+
```
75+
76+
The final state of the calculator object is also accessible
77+
via `results.state` and could be employed for postprocessing
78+
using the framework of the calculator. E.g. in the case
79+
of `DFTK`, the `results.state` is what `DFTK` calls an `scfres`
80+
and could just be used to plot a density of states or plot
81+
bands or compute response properties.

docs/src/examples/other_solvers.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Using a different Optimization.jl compatible solver
2+
3+
In this example we perform the simplistic optimisation
4+
the bond length of a Hydrogen molecule using a trust region
5+
quasi-Newton method from
6+
[NLopt](https://github.com/JuliaOpt/NLopt.jl).
7+
8+
We create a calculator employing the
9+
[density-functional toolkit](https://dftk.org/)
10+
to compute energies and forces at using the LDA density functional.
11+
12+
```@example other-solvers
13+
using DFTK
14+
15+
model_kwargs = (; functionals=[:lda_x, :lda_c_pw])
16+
basis_kwargs = (; kgrid=(1, 1, 1), Ecut=20.0)
17+
scf_kwargs = (; tol=1e-6)
18+
calc = DFTKCalculator(; model_kwargs, basis_kwargs, scf_kwargs, verbose=true)
19+
nothing
20+
```
21+
22+
and we build the hydrogen molecular system,
23+
where we attach pseudopotential information for DFTK:
24+
25+
```@example other-solvers
26+
using AtomsBuilder
27+
using Unitful
28+
using UnitfulAtomic
29+
30+
bounding_box = [[10.0, 0.0, 0.0], [0.0, 10.0, 0.0], [0.0, 0.0, 10.0]]u"Å"
31+
system = periodic_system([:H => [0, 0, 1.]u"bohr",
32+
:H => [0, 0, 3.]u"bohr"],
33+
bounding_box)
34+
system = attach_psp(system; H="hgh/lda/h-q1")
35+
nothing
36+
```
37+
38+
We now run [`GeometryOptimization.minimize_energy!`](@ref), but notably
39+
pass the `NLopt.LD_TNEWTON` solver from `NLopt` as the
40+
third argument to employ this solver. Extra keyword argument to `NLopt`
41+
can be added, e.g. here the `maxevel=100`, which limits the solver to
42+
100 function evaluations:
43+
```@example other-solvers
44+
using GeometryOptimization
45+
using OptimizationNLopt
46+
solver = NLopt.LD_TNEWTON()
47+
48+
results = minimize_energy!(system, calc, solver;
49+
tol_force=1e-4u"eV/Å", maxeval=100)
50+
nothing
51+
```
52+
53+
The final hydrogen bond length is:
54+
55+
```@example other-solvers
56+
using LinearAlgebra
57+
norm(position(results.system[1]) - position(results.system[2]))
58+
```

docs/src/examples/tial_lj.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# TiAl structure optimisation
2+
3+
TODO Write some text motivating this example
4+
5+
Setup system:
6+
```@example tial
7+
using AtomsBase
8+
using AtomsIO
9+
using EmpiricalPotentials
10+
using GeometryOptimization
11+
GO = GeometryOptimization
12+
13+
system = load_system(joinpath(pkgdir(EmpiricalPotentials), "data/TiAl-1024.xyz"))
14+
nothing
15+
```
16+
17+
Setup calculator:
18+
```@example tial
19+
using Unitful
20+
using UnitfulAtomic
21+
calc = LennardJones(-1.0u"meV", 3.1u"Å", 13, 13, 6.0u"Å")
22+
nothing
23+
```
24+
25+
Minimise energy:
26+
```julia
27+
## TODO: Should run as @example once EmpiricalPotentials is compatible
28+
29+
results = minimize_energy!(system, calc, GO.OptimCG(); maxiters=10, show_trace=true)
30+
results.energy
31+
```
32+
33+
Final structure:
34+
```julia
35+
## TODO: Should run as @example once EmpiricalPotentials is compatible
36+
37+
results.system
38+
```

docs/src/index.md

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,44 @@ CurrentModule = GeometryOptimization
44

55
# GeometryOptimization
66

7-
Documentation for [GeometryOptimization](https://github.com/ortner/GeometryOptimization.jl).
7+
A geometry optimization package for
8+
[AtomsBase structures](https://github.com/JuliaMolSim/AtomsBase.jl)
9+
and [AtomsCalculator calculators](https://github.com/JuliaMolSim/AtomsCalculators.jl).
10+
The source code can be found [on github](https://github.com/JuliaMolSim/GeometryOptimization.jl).
811

9-
```@index
10-
```
12+
## Motivating example
13+
14+
We consider the optimisation of the bondlength of a hydrogen
15+
molecule using a simple Lennard Jones potential:
16+
17+
```julia
18+
## TODO: Should run as @example once EmpiricalPotentials is compatible
19+
using AtomsBase
20+
using EmpiricalPotentials
21+
using GeometryOptimization
22+
using Unitful
23+
using UnitfulAtomic
24+
25+
# Setup system and calculator
26+
system = isolated_system([:H => [0, 0, 0.0]u"bohr",
27+
:H => [0, 0, 1.9]u"bohr"])
28+
calc = LennardJones(-1.17u"hartree", 0.743u"angstrom", 1, 1, 0.6u"nm")
1129

12-
```@autodocs
13-
Modules = [GeometryOptimization]
30+
# Run the geometry optimisation
31+
results = minimize_energy!(system, calc)
32+
33+
# Inspect the results
34+
optimised_system = results.system
35+
optimised_bondlength = norm(position(optsystem[1]) - position(optsystem[2]))
1436
```
37+
38+
The idea is that
39+
any [AtomsBase](https://github.com/JuliaMolSim/AtomsBase.jl)-compatible
40+
structure can be employed as a `system`
41+
any [AtomsCalculators](https://github.com/JuliaMolSim/AtomsCalculators.jl)-compatible
42+
calculator as a `calc`. See the list of examples to get an overview of possible
43+
calculators to employ.
44+
45+
Note that [`minimize_energy!`](@ref) supports further arguments to fine-tune the
46+
convergence tolerance or customise the solver selection.
47+
See the API documentation or the examples to explore this.

0 commit comments

Comments
 (0)