1. Structure Optimization#

This is a simple example of how to perform a structure optimization using the MatterSim.

1.1. Import the necessary modules#

1import numpy as np
2from ase.build import bulk
3from ase.units import GPa
4from mattersim.forcefield.potential import MatterSimCalculator
5from mattersim.applications.relax import Relaxer

1.2. Set up the structure to relax#

1# initialize the structure of silicon
2si = bulk("Si", "diamond", a=5.43)
3
4# perturb the structure
5si.positions += 0.1 * np.random.randn(len(si), 3)
6
7# attach the calculator to the atoms object
8si.calc = MatterSimCalculator()

1.3. Run the relaxation#

MatterSim implements a built-in relaxation class to support the relaxation of ase atoms.

1# initialize the relaxation object
2relaxer = Relaxer(
3    optimizer="BFGS", # the optimization method
4    filter="ExpCellFilter", # filter to apply to the cell
5    constrain_symmetry=True, # whether to constrain the symmetry
6)
7
8relaxed_structure = relaxer.relax(si, steps=500)