Skip to content

Volumetric fields

view_field renders native scalar grids with Tako’s isosurface viewer. Contours, opacity, and sections are adjustable without repeating the electronic calculation. Coordinates and voxel vectors retain their original registration.

Runnable Python · Data and method records

The molecular examples use relaxed PBE/def2-SVP water and a 41³ display grid. They provide a reproducible small calculation; quantitative density analysis requires method, basis, grid-extent, and grid-spacing convergence.

from atomli.build import molecule
from atomli.calculators import QC
from atomli.optimize import BFGS
from atomli.visualize import view_field
atoms = molecule("H2O")
atoms.calc = QC(xc="PBE", basis="def2-svp", device="cpu", scf={"energy_tolerance": 1e-8})
if not BFGS(atoms).run(fmax=1e-4, steps=60):
raise RuntimeError("Geometry did not converge")
grid = {"shape": [41, 41, 41], "margin": 2.5}
density = atoms.calc.get_field(atoms=atoms, kind="electron_density", **grid)
v = view_field(atoms, density, isovalue=0.06, opacity=0.65)
display(v)
v.write_html("water-density.html")

Water electron density with contour opacity and section controls

Contour values use electron/ų. Changing the contour changes the displayed envelope, not the electronic state. The enclosed region is not an atomic-charge partition or an integrated electron count.

Density metadata · Snapshot and field samples

Water density at a higher contour with clipping and a scalar section

This figure starts at 0.18 electron/ų. Slice clips the surface and draws a scalar section. Axis selections refer to the grid vectors; in a skew cell they need not be Cartesian planes.

v.set_isovalue(0.18)
v.set_opacity(0.8)
v.set_slice(axis="z", position=0.5, keep="below", style="both")
v.write_html("density-section.html")

Electrostatic potential on a density contour

Section titled “Electrostatic potential on a density contour”
esp = atoms.calc.get_field(kind="electrostatic_potential", **grid)
v = view_field(atoms, density, isovalue=0.06,
color_by=esp, colormap="diverging", opacity=0.85)
display(v)

Water electrostatic potential mapped onto its electron density surface

Surface geometry follows density; color samples ESP at each surface vertex. The diverging map assigns lower values to blue and higher values to red. Tako autoscales colors on the current surface, so colors across different contours or screenshots do not define a common quantitative scale. ESP uses eV per elementary positive charge. A potential map is not a fitted charge model.

color_by must share the surface field’s shape, origin, voxel vectors, and periodicity. Misregistered grids raise an error.

import numpy as np
state = atoms.calc.get_electronic_state(matrices=False)
occupied = np.flatnonzero(np.asarray(state["occupations"])[0, 0] > 1e-6)
homo = int(occupied[-1])
orbital = atoms.calc.get_field(kind="orbital_amplitude", band=homo, **grid)
view_field(atoms, orbital, isovalue=0.12, surface="both", opacity=0.8)

PBE def2 SVP water HOMO orbital phase

PBE def2 SVP water LUMO orbital phase

Blue and orange indicate positive and negative amplitudes at equal absolute contour values. They represent phase, not charge. Orbital amplitudes use Å⁻³ᐟ². A global phase reversal preserves the physical state. These orbital plots do not establish excitation or electron-attachment energies.

radical = molecule("OH")
radical.calc = QC(xc="PBE", basis="def2-svp", unpaired=1, device="cpu")
spin = radical.calc.get_field(atoms=radical, kind="spin_density", **grid)
view_field(radical, spin, isovalue=0.04)

PBE OH doublet spin density

spin-polarized PBE/def2-SVP OH at the builder geometry. The field is alpha-minus-beta density, in electron/ų. Preserve the charge and unpaired-electron count with the map.

Electron density of water adsorbed at the exposed Li site of a LiF cluster

PBE/def2-SVP total density at the optimized fixed-host (LiF)₂–H₂O geometry used in the constraint study. This is the complex density, not a difference-density or charge-transfer map. Difference fields require matched geometry, grid, and fragment-state conventions.

Periodic silicon valence density in its primitive cell

Two-atom silicon cell; PBE/GTH-SZV, Gamma sampling, 17³ SCF mesh, and a 33³ display grid. This coarse configuration illustrates periodic field registration. GTH removes core electrons, so the field is valence density. Quantitative results require basis, k-point, and SCF-grid convergence.

from atomli.build import bulk
from atomli.calculators import QC
crystal = bulk("Si", "diamond", a=5.43)
crystal.calc = QC(xc="PBE", device="cpu", settings={
"periodic": True, "basis": "gth-szv", "pseudopotential": "gth-pbe",
"mesh": [17, 17, 17], "kpoints": [1, 1, 1],
})
field = crystal.calc.get_field(atoms=crystal, kind="electron_density", shape=[33, 33, 33])
view_field(crystal, field, isovalue=0.12, look={"cell": True})

Analysis exposes MBIS stockholder fitting, basin populations, isodensity-surface ESP descriptors, and CHELPG/RESP charge fits:

from atomli.analysis import Analysis
analysis = Analysis(atoms, shape=[81, 81, 81], margin=2.5)
mbis = analysis.mbis()
# Hirshfeld additionally requires reference-atom densities on the same grid.
chelpg = analysis.chelpg()
resp = analysis.resp(equivalence_groups=[[1, 2]]) # equivalent water H atoms

A visualization grid does not establish a quantitative atomic population. The saved PBE water check integrates to 11.61, 10.25, and 10.05 electrons on 41³, 61³, and 81³ grids with the same 2.5 Å margin; the expected count is 10. Nuclear density peaks need finer spatial sampling than smooth outer isosurfaces. Retain integrated electron count, population drift, boundary behavior, and convergence status. Neither a successful charge fit nor a basin count removes grid error. These integration records use the sampled density directly and do not renormalize its electron count.

GridIntegrated electronsError
41³11.611.61
61³10.250.25
81³10.050.05

Spatial integration records

Use native field representation metadata when working with pseudopotentials. Valence-only density cannot determine missing core density. ESP fits depend on the point selection, charge restraints, and equivalence groups. MBIS convergence refers to its iterative fit, not to the resolution of the supplied density.

from atomli.io import read_cube
field = read_cube("density.cube", kind="electron_density")
v = view_field(atoms, field, isovalue=0.06)
display(v)
v.write_html("density.html")
snapshot = v.to_snapshot()

Supply the structure associated with the field. read_cube and read_field preserve Å-based coordinates and explicit value units. Wavefunction archives and sampled-field HDF5 files use different readers.

The display payload uses Float32; the source arrays remain unchanged. Resample a field after changing geometry. The figures use native electronic fields and analytical nuclear derivatives, without finite-difference response calculations.