Skip to content

Atoms

Atoms stores species, positions, cell, periodicity, per-atom arrays, constraints, and the attached calculator. Positions use Å. Indices are zero-based and follow the supplied atom order.

from atomli.build import molecule
from atomli.visualize import view
water = molecule("H2O")
print(water.get_chemical_symbols()) # ['O', 'H', 'H'] for this builder
v = view(water, tags="index")
v.add_distance(0, 1)
v.add_angle(1, 0, 2)

Water atom indices bond distance and bond angle

The molecular formula does not determine the stored index order. For example, an explicit Atoms("H2O", ...) constructor follows H,H,O, while this molecule builder returns O,H,H. Inspect the symbols before assigning constraints or orbital projections.

from atomli import Atoms
water = Atoms(symbols=["O", "H", "H"], positions=[
[0, 0, 0], [0.96, 0, 0], [-0.24, 0.93, 0],
])
positions = water.get_positions()
positions[1, 0] += 0.05
water.set_positions(positions)

set_positions applies attached constraints. Use the normal setter during a constrained workflow; bypass constraint application only for an intentional change of reference geometry.

from atomli.build import bulk
silicon = bulk("Si", "diamond", a=5.43)
print(silicon.get_cell())
print(silicon.get_pbc())

Two atom primitive silicon cell

The diamond primitive cell contains two atoms and nonorthogonal cell vectors. A conventional cubic diamond cell contains eight. pbc accepts a Boolean or three-axis mask; calculator support for partial periodicity is method-specific.

water.set_tags([1, 2, 2])
water.set_initial_charges([0.0, 0.0, 0.0])
water.set_initial_magnetic_moments([0.0, 0.0, 0.0])
water.set_masses([15.999, 2.014, 2.014])

Tags classify sites; they do not change the electronic Hamiltonian. Masses affect nuclear dynamics and mass-weighted vibrations. Charge and spin inputs must match the intended electronic state. Preserve these arrays and their atom order in saved structures.

from atomli.calculators import QC
water.calc = QC(xc="PBE", basis="def2-svp", device="cpu", scf={"energy_tolerance": 1e-8})
energy = water.get_potential_energy() # eV
forces = water.get_forces() # eV/Å
snapshot = water.copy()

Changes to geometry, composition, charge, or spin invalidate electronic results. A copied structure is useful for trajectory storage; assign the intended calculator before requesting fresh properties. ASE Python calculators can be assigned directly and are adapted internally.

Structure builders · Constraints in adsorption · File I/O