Molecular dynamics
Atomli provides ASE-shaped Velocity Verlet and thermostat drivers. The worked example uses g-xTB analytical forces on an isolated water molecule. Geometry, velocities, total energy, and sampling times are retained for analysis.
Water NVE dynamics
Section titled “Water NVE dynamics”g-xTB water dynamics with total-energy and RMSD traces
The input is relaxed to fmax=0.001 eV/Å. Velocities are initialized at 300 K,
then center-of-mass translation and rotation are removed. This is an initial
condition rather than a statement of an equilibrated molecular temperature.
Velocity Verlet propagates 500 steps at 0.25 fs, with one saved frame every
0.50 fs.
import numpy as npfrom atomli.build import moleculefrom atomli.calculators import XTBfrom atomli.md.velocitydistribution import MaxwellBoltzmannDistribution, Stationary, ZeroRotationfrom atomli.md.verlet import VelocityVerletfrom atomli.optimize import BFGSfrom atomli.units import fs
atoms = molecule("H2O")atoms.calc = XTB(method="gxtb", device="cpu")if not BFGS(atoms, maxstep=.12).run(fmax=.001, steps=180): raise RuntimeError("Starting geometry did not converge")np.random.seed(42)MaxwellBoltzmannDistribution(atoms, temperature_K=300)Stationary(atoms)ZeroRotation(atoms)
frames, total_energy = [], []dyn = VelocityVerlet(atoms, timestep=.25 * fs)def sample(): frames.append(atoms.copy()) total_energy.append(atoms.get_potential_energy() + atoms.get_kinetic_energy())dyn.attach(sample, interval=2)dyn.run(500)print("Total-energy spread (eV):", np.ptp(total_energy))Python source · Saved trajectory · Energy and structural record
Integration and sampling checks
Section titled “Integration and sampling checks”For NVE, inspect total-energy drift alongside energy exchange between kinetic and potential terms. Compare the same physical duration with a smaller timestep and tighter electronic convergence. Bond stretching, light atoms, and the chosen potential determine a suitable timestep. A visually smooth animation does not establish energy conservation.
The saved-frame interval can exceed the integration timestep. Use 0.50 fs when analyzing the frames above. Sparse sampling changes correlation spectra and can make periodic unwrapping ambiguous. Keep momenta or velocities in the trajectory when requesting velocity correlations or VDOS.
Thermostats
Section titled “Thermostats”from atomli.md.langevin import Langevin
dyn = Langevin(atoms, timestep=.25 * fs, temperature_K=300, friction=.01)dyn.run(1000)Thermostatted dynamics changes energy conservation and time correlation functions. Equilibration and production should have explicit ensemble, thermostat, timestep, duration, and sampling settings. The displayed 125 fs isolated-molecule NVE run does not establish a bulk diffusion coefficient or a converged thermal distribution.
Native analysis and visualization
Section titled “Native analysis and visualization”from atomli.analysis import TrajectoryAnalysisfrom atomli.io import writefrom atomli.visualize import view
write("water-nve.extxyz", frames)analysis = TrajectoryAnalysis(frames, timestep_fs=.5)rmsd = analysis.rmsd(align=True)vacf = analysis.vacf()view(frames).write_html("trajectory.html")The trajectory analysis guide covers RMSF, torsion distributions, hydrogen bonds, contacts, RDFs, VDOS, and transport fits, including the different conditions required for each observable.