Skip to content

Quick start

Start with H₂O, then apply the same Atoms → calculator → optimizer → analysis workflow to a periodic slab and a constrained adsorption complex. Install Atomli first. Run the blocks within each numbered section in order; each section starts a new system.

Positions use Å, energies eV, and forces eV/Å. In a notebook, view() displays an interactive structure; in a script, save it with view(atoms).write_html("structure.html"). Element labels, the species legend, and the coordinate widget are enabled by default. Drag the structure or coordinate widget to rotate; use the playback bar to explore trajectories. Double-click the legend or coordinate widget to unlock it, drag it to a new position, then click the checkmark to pin it. The coordinate widget also has a resize handle. Open the gear menu to change visualization settings or restore a hidden overlay.

A single point gives the energy and forces at the current geometry. Optimization then moves the atoms until the largest force is below fmax.

from atomli.build import molecule
from atomli.calculators import XTB
from atomli.optimize import BFGS
from atomli.visualize import view
water = molecule("H2O")
water.calc = XTB(method="gxtb", device="cpu")
print("Energy (eV):", water.get_potential_energy())
print("Forces (eV/Å):", water.get_forces())
frames = [water.copy()]
opt = BFGS(water, logfile="-")
opt.attach(lambda: frames.append(water.copy()), interval=1)
if not opt.run(fmax=0.02, steps=100):
raise RuntimeError("Water relaxation did not converge")
view(frames)
H₂O relaxation with g-xTB: follow the O–H bonds and H–O–H angle through the trajectory.

The displayed trajectory starts from deliberately stretched bonds so the motion is visible. The code uses the built-in water geometry.

H₂O has three internal vibrations: a bend and two stretches. Use a tightly relaxed PBE/def2-SVP geometry and its analytical Hessian to calculate the frequencies. This section starts a fresh water calculation.

from atomli.build import molecule
from atomli.calculators import QC
from atomli.optimize import BFGS
from atomli.vibrations import Vibrations
from atomli.visualize import plot
water = molecule("H2O")
water.calc = QC(xc="PBE", basis="def2-svp", device="cpu",
scf={"energy_tolerance": 1e-8})
if not BFGS(water).run(fmax=1e-4, steps=60):
raise RuntimeError("Water relaxation did not converge")
vib = Vibrations(water, method="analytical").run()
vib.summary() # frequencies in cm⁻¹
plot.vibration(vib).write_html("water-modes.html")

Open water-modes.html to inspect the frequency spectrum. The six rigid-body directions of an isolated nonlinear molecule lie near zero; interpret the three internal modes separately. A significant imaginary internal frequency calls for checking the geometry and convergence.

PBE/def2-SVP water bending mode from the analytical Hessian. Animation amplitudes are enlarged for visibility.

See Vibrational analysis for Hessians, mode selection, and method support.

An Ar(100) slab is a small, inexpensive surface example with a Lennard-Jones potential. Repeat the crystal in x and y, add vacuum along z, and freeze the bottom two layers while the surface relaxes. The cell stays fixed.

from atomli.build import bulk
from atomli.calculators import LennardJones
from atomli.constraints import FixAtoms
from atomli.optimize import BFGS
from atomli.visualize import view
slab = bulk("Ar", "fcc", a=5.26, cubic=True).repeat((3, 3, 2))
slab.set_pbc([True, True, False])
slab.center(vacuum=8.0, axis=[False, False, True])
z = slab.get_positions()[:, 2]
slab.set_constraint(FixAtoms(indices=[i for i, zi in enumerate(z)
if zi < z.min() + 3.0]))
slab.calc = LennardJones(epsilon=0.0103, sigma=3.4, rc=5.0, shift=True)
if not BFGS(slab).run(fmax=0.005, steps=2000):
raise RuntimeError("Slab relaxation did not converge")
view(slab, cell=True)
Periodic Ar(100) surface with an Ar adatom: the bottom layers stay fixed while the surface and adatom relax.

The figure extends the clean-slab code with an adatom. The 5 Å interaction cutoff is smaller than half the in-plane cell length. This model illustrates periodic boundaries and constraints; choose a material-appropriate calculator for a quantitative surface study. See Optimization.

4. Water adsorption: constraints and local vibrations

Section titled “4. Water adsorption: constraints and local vibrations”

Bind H₂O to an exposed Li site of a finite (LiF)₂ cluster. Freeze the four host atoms, relax water, then calculate only the nine adsorbate coordinates. This is a molecular coordination model with open boundaries.

from atomli import Atoms
from atomli.calculators import QC
from atomli.constraints import FixAtoms
from atomli.optimize import BFGS
from atomli.vibrations import Vibrations
from atomli.visualize import view, plot
ads = 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],
])
ads.set_constraint(FixAtoms(indices=[0, 1, 2, 3]))
ads.calc = QC(xc="PBE", basis="def2-svp", device="cpu",
scf={"energy_tolerance": 1e-8})
if not BFGS(ads, maxstep=0.12).run(fmax=0.003, steps=160):
raise RuntimeError("Adsorbate relaxation did not converge")
view(ads)
local = Vibrations(ads, indices=[4, 5, 6], method="analytical").run()
local.summary()
plot.vibration(local).write_html("adsorbate-modes.html")
H₂O approaches an exposed Li site while the (LiF)₂ host remains fixed.
Water motion in the fixed-host adsorption model; the host has zero mode displacement.

The nine modes include hindered translations and rotations as well as internal water vibrations. The partial Hessian excludes host relaxation and coupling to host motion. Follow the adsorption study for mode assignments and the electronic adsorption energy E(complex) − E(host) − E(water), evaluated with consistent settings.