Skip to content

Commit a319eff

Browse files
committed
deploy: 0621694
1 parent 535dc07 commit a319eff

15 files changed

+721
-152
lines changed

README.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<link href="_static/styles/theme.css?digest=8878045cc6db502f8baf" rel="stylesheet" />
3131
<link href="_static/styles/pydata-sphinx-theme.css?digest=8878045cc6db502f8baf" rel="stylesheet" />
3232

33-
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=a746c00c" />
33+
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=8f2a1f02" />
3434
<link rel="stylesheet" type="text/css" href="_static/styles/sphinx-book-theme.css?v=a3416100" />
3535
<link rel="stylesheet" type="text/css" href="_static/copybutton.css?v=76b2166b" />
3636

@@ -154,6 +154,7 @@
154154
<li class="toctree-l1 has-children"><a class="reference internal" href="examples/examples.html">Examples</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
155155
<li class="toctree-l2"><a class="reference internal" href="examples/relax_example.html">1. Structure Optimization</a></li>
156156
<li class="toctree-l2"><a class="reference internal" href="examples/phonon_example.html">2. Phonon Dispersion</a></li>
157+
<li class="toctree-l2"><a class="reference internal" href="examples/batch_relaxation_example.html">3. Batch Structure Optimization</a></li>
157158
</ul>
158159
</details></li>
159160
</ul>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Batch Structure Optimization
2+
================
3+
4+
This is a simple example of how to use MatterSim to efficiently relax a list of structures.
5+
6+
7+
Import the necessary modules
8+
----------------------------
9+
10+
First we import the necessary modules.
11+
12+
.. code-block:: python
13+
:linenos:
14+
15+
from ase.build import bulk
16+
from mattersim.applications.batch_relax import BatchRelaxer
17+
from mattersim.forcefield.potential import Potential
18+
19+
Set up the MatterSim batch relaxer
20+
----------------------------------
21+
22+
.. code-block:: python
23+
:linenos:
24+
25+
# initialize the default MatterSim Potential
26+
potential = Potential.from_checkpoint()
27+
28+
# initialize the batch relaxer with a EXPCELLFILTER for cell relaxation and a FIRE optimizer
29+
relaxer = BatchRelaxer(potential, fmax=0.01, filter="EXPCELLFILTER", optimizer="FIRE")
30+
31+
32+
Relax the structures
33+
--------------------
34+
35+
.. code-block:: python
36+
:linenos:
37+
38+
# Here, we generate a list of ASE Atoms objects we want to relax
39+
atoms = [bulk("C"), bulk("Mg"), bulk("Si"), bulk("Ni")]
40+
41+
# And then perturb them a bit so that relaxation is not trivial
42+
for atom in atoms:
43+
atom.rattle(stdev=0.1)
44+
45+
# Run the relaxation
46+
relaxation_trajectories = relaxer.relax(atoms)
47+
48+
49+
Inspect the relaxed structures
50+
------------------------------
51+
52+
.. code-block:: python
53+
:linenos:
54+
55+
# Extract the relaxed structures and corresponding energies
56+
relaxed_structures = [traj[-1] for traj in relaxation_trajectories.values()]
57+
relaxed_energies = [structure.info['total_energy'] for structure in relaxed_structures]
58+
59+
# Do the same with the initial structures and energies
60+
initial_structures = [traj[0] for traj in relaxation_trajectories.values()]
61+
initial_energies = [structure.info['total_energy'] for structure in initial_structures]
62+
63+
# verify by inspection that total energy has decreased in all instances
64+
for initial_energy, relaxed_energy in zip(initial_energies, relaxed_energies):
65+
print(f"Initial energy: {initial_energy} eV, relaxed energy: {relaxed_energy} eV")

_sources/examples/examples.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ Examples
77

88
relax_example
99
phonon_example
10+
batch_relaxation_example

_static/pygments.css

Lines changed: 121 additions & 121 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)