Skip to content

Commit 987e547

Browse files
committed
Add AGOX documentation
1 parent 20bf70f commit 987e547

2 files changed

Lines changed: 146 additions & 0 deletions

File tree

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
.. agox:
2+
3+
=============
4+
AGOX tutorial
5+
=============
6+
7+
RAFFLE is implemented into AGOX as a generator, allowing it to be used in conjunction with other AGOX features such database management and optimisation routines.
8+
The generator is designed to be used with the AGOX framework, which provides a user-friendly way to set up and run RAFFLE-based structure searches.
9+
10+
This tutorial will guide you through the process of setting up and using the RAFFLE generator within AGOX.
11+
The example script can be found in the following directory:
12+
13+
.. code-block:: bash
14+
15+
raffle/example/python_pkg/agox_runs/Si-Ge_run/agox_run.py
16+
17+
This script utilises the `hex` slurm experiment management package.
18+
The script is designed to run on a slurm cluster, but can also be run locally by removing the slurm-specific code.
19+
`hex` can be installed via pip:
20+
21+
.. code-block:: bash
22+
23+
pip install hex
24+
25+
Documentation for the `hex` package can be found here: https://gitlab.com/Mads-Peter/shephex/
26+
27+
Documentation for the AGOX framework can be found here: https: https://agox.gitlab.io/agox/
28+
29+
Currently, the RAFFLE generator is only available on the `raffle_generator` branch of AGOX.
30+
To use the RAFFLE generator, you need to install the `raffle_generator` branch of AGOX:
31+
32+
.. code-block:: bash
33+
34+
git clone -b raffle_generator https://gitlab.com/agox/agox.git
35+
cd agox
36+
pip install -e .
37+
38+
The RAFFLE generator differs slightly from the standard AGOX generator, as it requires a host structure to be provided directly to the generator.
39+
40+
An environment must be set up for the search, this defines the host structure, the stoichiometry of atoms to be added, and the bounding box for the search.
41+
The bounding box must first be defined in terms of a lower left and upper right corner, which can be done using the `bounds_to_confinement` function.
42+
The `bounds_to_confinement` function is used to convert the bounding box coordinates into the `confinement_corner` and `confinement_cell` parameters required by the `Environment` class in AGOX.
43+
44+
.. code-block:: python
45+
46+
from agox.generators.raffle import bounds_to_confinement
47+
48+
confinement_corner, confinement_cell = bounds_to_confinement(
49+
[
50+
[0.0, 0.0, 0.0],
51+
[1.0, 1.0, 1.0]
52+
],
53+
template
54+
)
55+
56+
The `bounds_to_confinement` function takes a list of two points defining the lower left and upper right corners of the bounding box, and the host structure.
57+
58+
The environment is defined as follows:
59+
60+
.. code-block:: python
61+
62+
from agox.environments import Environment
63+
64+
environment = Environment(
65+
template = template,
66+
symbols = symbols,
67+
confinement_cell = confinement_cell,
68+
confinement_corner = confinement_corner,
69+
...
70+
)
71+
72+
The `template` is the host structure, an ASE atoms object, which can be created using ASE, ARTEMIS, or read in from a file.
73+
The `symbols` is an alphanumeric string defining the stoichiometry of atoms to be added, e.g. 'Si2Ge2' for a 2:2 ratio of Si to Ge.
74+
75+
A database object must be attached to the search, which is used to store the generated structures.
76+
The database can be created using the `Database` class in AGOX in the following way:
77+
78+
.. code-block:: python
79+
80+
from agox.databases import Database
81+
82+
db_path = f"../database.db"
83+
database = Database(filename=db_path, order=5)
84+
database.restore_to_memory()
85+
86+
The `order` parameter defines the order in which the database is called in the AGOX framework; more can be read about this in the AGOX documentation.
87+
88+
The RAFFLE generator can then be set up using the `RaffleGenerator` class in AGOX:
89+
90+
.. code-block:: python
91+
92+
from agox.generators.raffle import RaffleGenerator
93+
94+
generator = RaffleGenerator(
95+
**environment.get_confinement(),
96+
host = template,
97+
database = database,
98+
environment = environment,
99+
species = symbols,
100+
n_structures = 5,
101+
...
102+
)
103+
104+
This sets up the RAFFLE generator to generate 5 structures each iteration, using the host structure and the environment defined earlier.
105+
106+
Evaluators and structure filters can be set up as usual in AGOX.
107+
For example, to set up an evaluator to perform structural optimisation, and a pre- and post-process filter that removes structures with bondlengths less than a certain value, you can use the following code:
108+
109+
.. code-block:: python
110+
111+
from agox.evaluators import LocalOptimizationEvaluator
112+
from agox.postprocessors.minimum_dist import MinimumDistPostProcess
113+
114+
evaluator = LocalOptimizationEvaluator(
115+
mace,
116+
gets = {"get_key": "candidates"},
117+
store_trajectory = False,
118+
optimizer_run_kwargs = {"fmax": 0.05, "steps": 200},
119+
order = 3,
120+
number_to_evaluate = 5,
121+
constraints = environment.get_constraints(),
122+
fix_template = False,
123+
)
124+
125+
minimum_dist_pre = MinimumDistPostProcess(
126+
c1 = 0.6,
127+
c2 = 5,
128+
order=1.5,
129+
)
130+
minimum_dist_post = MinimumDistPostProcess(
131+
c1 = 0.6,
132+
gets = {"get_key" : "evaluated_candidates"},
133+
sets = {"set_key" : "evaluated_candidates"},
134+
c2 = 5,
135+
order = 3.5,
136+
)
137+
138+
Finally, the AGOX search can be set up and run using the `AGOX` class in AGOX:
139+
140+
.. code-block:: python
141+
142+
agox = AGOX(generator, minimum_dist_pre, minimum_dist_post, database, evaluator, seed=seed)
143+
144+
## Run the AGOX search for N_iterations
145+
agox.run(N_iterations=40)

docs/source/tutorials/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Whilst RAFFLE is a random sturcture search package designed primarlily for inter
3535
aluminium_tutorial
3636
Si-Ge_tutorial
3737
graphene_grain_boundary_tutorial
38+
agox_tutorial
3839

3940
.. toctree::
4041
:maxdepth: 2

0 commit comments

Comments
 (0)