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.
1. Water: single point and optimization
Section titled “1. Water: single point and optimization”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 moleculefrom atomli.calculators import XTBfrom atomli.optimize import BFGSfrom 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)The displayed trajectory starts from deliberately stretched bonds so the motion is visible. The code uses the built-in water geometry.
2. Water: vibrational modes
Section titled “2. Water: vibrational modes”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 moleculefrom atomli.calculators import QCfrom atomli.optimize import BFGSfrom atomli.vibrations import Vibrationsfrom 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.
See Vibrational analysis for Hessians, mode selection, and method support.
3. Periodic boundaries: relax a slab
Section titled “3. Periodic boundaries: relax a slab”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 bulkfrom atomli.calculators import LennardJonesfrom atomli.constraints import FixAtomsfrom atomli.optimize import BFGSfrom 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)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 Atomsfrom atomli.calculators import QCfrom atomli.constraints import FixAtomsfrom atomli.optimize import BFGSfrom atomli.vibrations import Vibrationsfrom 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")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.
Continue by task
Section titled “Continue by task”- Choose a calculator for your system and boundary conditions.
- Constraints for fixed atoms, directions, and distances.
- Visualization for notebooks, HTML export, and live updates.
- Worked examples for complete studies and downloadable Python.