Skip to content

Constraints in adsorption calculations

The examples use H₂O coordinated to an exposed Li site of a finite (LiF)₂ cluster. The four host atoms start in a 1.7 Å square; water starts above one Li site. Calculations use molecular PBE/def2-SVP, analytical forces, and BFGS with fmax=0.003 eV/Å.

This finite cluster isolates the constraint choices. A quantitative surface study requires a larger or periodic substrate, basis convergence, and appropriate correlation and electrostatics. These calculations do not define a surface coverage or adsorption free energy.

Each figure contains an optimization trajectory and a Geometry and force history panel with Li–O/O–H distances and raw/projected force residuals.

Runnable Python · Calculation records

Host indices are 0–3; water is 4–6, with O at index 4.

from atomli import Atoms
from atomli.calculators import QC
from atomli.constraints import FixAtoms
from atomli.optimize import BFGS
atoms = Atoms("LiFLiFOH2", positions=[
[0, 0, 0], [1.7, 0, 0], [1.7, 1.7, 0], [0, 1.7, 0],
[-0.3, -0.25, 2.15], [-0.3, 0.513, 2.746], [-0.3, -1.013, 2.746],
])
atoms.set_constraint(FixAtoms(indices=[0, 1, 2, 3]))
atoms.calc = QC(xc="PBE", basis="def2-svp", device="cpu", scf={"energy_tolerance": 1e-8})
if not BFGS(atoms, maxstep=0.12).run(fmax=0.003, steps=160):
raise RuntimeError("Adsorbate relaxation did not converge")

Water adsorption at a frozen LiF cluster: optimization and force residuals

All nine adsorbate coordinates relax. The optimized water approaches the exposed Li site near the cluster edge. Gray host atoms retain their initial positions. The fixed host remains part of the electronic calculation.

Fixed lateral coordinates or a specified approach axis

Section titled “Fixed lateral coordinates or a specified approach axis”
from atomli.constraints import FixCartesian
atoms.set_constraint([
FixAtoms(indices=[0, 1, 2, 3]),
FixCartesian(4, mask=[True, True, False]),
])

True fixes the corresponding component. The O atom retains x and y while its height and the hydrogen coordinates relax.

Water adsorption with lateral oxygen coordinates held fixed

For an oblique approach coordinate, use an allowed direction:

from atomli.constraints import FixedLine
atoms.set_constraint([
FixAtoms(indices=[0, 1, 2, 3]),
FixedLine(4, direction=[0.25, 0.25, 1]),
])

Constrained oblique approach of water to the Li coordination site

These are restricted minima. Their transverse raw forces can remain nonzero. They are suitable starting points for a constrained adsorption-coordinate study; release the approach constraint before claiming a fully relaxed adsorption geometry.

from atomli.constraints import FixedPlane
atoms.set_constraint([
FixAtoms(indices=[0, 1, 2, 3]),
FixedPlane(4, direction=[0, 0, 1]),
])

The vector is the plane normal. O retains its initial height while lateral coordinates and both hydrogens relax.

Lateral adsorbate relaxation at a fixed oxygen height

For periodic slabs, FixScaled can constrain components relative to the cell:

from atomli.constraints import FixScaled
# On the intended periodic slab, allow motion along its third cell vector.
atoms.set_constraint([
FixAtoms(indices=bottom_layer_indices),
FixScaled(adsorbate_index, mask=[True, True, False]),
])

In a skew cell, cell-vector and Cartesian constraints define different subspaces. Use the actual surface normal when the third cell vector is oblique to it.

A single O–H distance can be retained during adsorption:

from atomli.constraints import FixBondLength
atoms.set_constraint([
FixAtoms(indices=[0, 1, 2, 3]),
FixBondLength(4, 5),
])

Adsorption relaxation with one O H distance constrained

For both O–H distances:

from atomli.constraints import FixBondLengths
atoms.set_constraint([
FixAtoms(indices=[0, 1, 2, 3]),
FixBondLengths([(4, 5), (4, 6)]),
])

Adsorption relaxation with both O H distances constrained

The distances remain fixed; the H–O–H angle and adsorption geometry remain active. This is not a rigid-water model. Verify the retained distances in the saved trajectory and in the distance records.

Local host relaxation without host translation

Section titled “Local host relaxation without host translation”
from atomli.constraints import FixSubsetCom
atoms.set_constraint(FixSubsetCom([0, 1, 2, 3]))

Local LiF host relaxation with its center of mass fixed

The host deforms while its mass-weighted center remains fixed. Water is free. FixCom() instead constrains the center of mass of the complete system. Neither constraint makes the selected fragment rigid.

Remove one collective adsorbate displacement

Section titled “Remove one collective adsorbate displacement”
import numpy as np
from atomli.constraints import FixedMode
mode = np.zeros((len(atoms), 3))
mode[[4, 5, 6], 0] = 1 # collective water translation along x
atoms.set_constraint([
FixAtoms(indices=[0, 1, 2, 3]),
FixedMode(mode),
])

Adsorbate optimization with one lateral collective direction projected out

FixedMode removes the supplied Cartesian direction; it does not calculate a vibrational eigenvector. The mode array must follow the full atom ordering.

from atomli.constraints import Hookean
atoms.set_constraint([
Hookean(0, 4, k=0.8, rt=1.8), # Li–O; eV/Ų, Å
FixAtoms(indices=[0, 1, 2, 3]),
])

Water adsorption with a soft Hookean Li O restraint

The spring contributes above 1.8 Å. It does not enforce a hard upper bound, and its energy belongs to the restrained model. Do not mix restrained and unrestrained energies in an adsorption-energy difference.

raw = atoms.get_forces(apply_constraint=False)
projected = atoms.get_forces()
raw_fmax = np.linalg.norm(raw, axis=1).max()
projected_fmax = np.linalg.norm(projected, axis=1).max()

The optimizer tests projected forces. A small projected residual establishes stationarity in the allowed subspace; raw forces quantify forces supported by the constraints. The figures retain both residuals.

set_constraint(...) replaces the constraint list. Pass one list to combine constraints; set_constraint() clears it. Set constraints before constructing the driver, and verify indices after slicing, replication, or an I/O round trip.

For the fixed-host minimum, calculate the analytical Hessian block over the nine water coordinates:

from atomli.vibrations import Vibrations
vib = Vibrations(atoms, indices=[4, 5, 6], method="analytical").run()
frequencies = vib.get_frequencies()
hessian = vib.get_hessian_2d() # 9 × 9, eV/Ų

Analytical low frequency adsorbate mode on the fixed LiF cluster

The host displacement is zero. This partial Hessian excludes substrate response and host–adsorbate vibrational coupling. The nine adsorbate coordinates include frustrated translations and rotations; they are not six removable rigid-body modes of the isolated water molecule.

Mode123456789
Frequency (cm⁻¹)33.8129.9262.5356.5459.9896.41596.53245.13763.1

Use the fully relaxed adsorbate under FixAtoms for this Cartesian partial-Hessian analysis. Additional bond, line, or plane constraints require treatment of their independent coordinate subspace.

Analytical Hessian and eigenvectors · Vibration and mode analysis · Adsorption density