Crystals & Surfaces
Periodic structures show their unit cell by default. This page covers cells and repeats, slabs with fixed atoms, and partially occupied sites. For coordination polyhedra see Polyhedra & Rings.
Bulk crystals
from ase.build import bulk
from aseview import MolecularViewer
si = bulk("Si", "diamond", a=5.43, cubic=True) * (2, 2, 2)
MolecularViewer(si, style="glossy").show()
Cell repeats and boundary atoms
Instead of building a supercell, the viewer can draw periodic images:
| Setting | Effect |
|---|---|
cell_repeat |
Extra cells along −/+ a, b and c (VESTA style), e.g. {"a": [0, 1], "b": [0, 1], "c": [0, 0]} |
show_boundary_atoms |
Copies of atoms that sit on cell faces, edges and corners |
show_bonded_neighbors |
Atoms outside the cell that complete bonds across the boundary |
All three are also in the sidebar under Cell.
Isolating elements and choosing bonds
Fade the cations to see oxygen behind them, or hide an element with its Visibility checkbox. Python uses the same settings:
MolecularViewer(
atoms,
element_visibility={"H": False},
element_opacities={"Ti": 0.35},
custom_bond_cutoffs=True,
bond_cutoffs={"O-Ti": 2.4, "O-O": 0},
).show()
Element alpha multiplies global and assigned fragment/structure alpha,
independently of color_by. Hiding retains the slider value and removes the
site from picking and its incident bonds. Reset in that block clears both
element maps while retaining colors and global/fragment settings. Opaque
structures keep the fast instanced path; many fractional atoms and bonds need
more draw calls. Intersecting translucent surfaces retain conventional sorting
limits. See the API details.
Per-pair values are maximum bond detection distances in Å, active only with
custom_bond_cutoffs=True. A bond requires distance < cutoff; 0 disables
the pair and unlisted pairs keep their radius-based defaults. "Ti-O" and
"O-Ti" mean the same pair, stored canonically as "O-Ti". The sidebar's
Per-pair cutoffs controls change these distances without changing atom
coordinates or actual bond lengths, including across periodic boundaries.
Fixed atoms on a slab
A Cu(111) slab with the bottom two layers frozen by FixAtoms. With
show_constraint=True the fixed atoms get a yellow overlay.
import numpy as np
from ase.build import fcc111
from ase.constraints import FixAtoms
slab = fcc111("Cu", size=(3, 3, 4), vacuum=8.0)
z = np.round(slab.positions[:, 2], 2)
bottom = np.unique(z)[:2]
fixed = [i for i, zi in enumerate(z) if zi in bottom]
slab.set_constraint(FixAtoms(indices=fixed))
MolecularViewer(slab, style="metallic", show_constraint=True).show()
A relaxation trajectory on a surface works like any trajectory; here H₂O adsorbs on Au(111) with the energy plot on:
from ase.io import read
relax = read("relax.traj", index=":")
MolecularViewer(relax, style="metallic", show_energy_plot=True)
Partial occupancy
ASE stores a disordered CIF site as one representative atom, with the
alternatives in atoms.info["occupancy"] indexed through
atoms.arrays["spacegroup_kinds"]:
from ase.io import read
atoms = read("structure.cif", fractional_occupancies=True)
MolecularViewer(atoms).show()
aseview draws such a site as sectors proportional to the occupancies, in the
current style. When the occupancies sum to less than one, an opaque white
sector marks the vacancy. Bonds and polyhedra use the representative element.
Element visibility and opacity also follow that representative identity in
frame.symbols: hiding Fe hides the whole Fe/Mn site below, and Fe opacity
fades both occupied sectors. A Mn override does not independently hide or fade
the Mn fraction of that Fe site. Occupancies stay unchanged, and the white
vacancy marker stays opaque while the site is visible.
Below, the centre site is 60 % Fe and 30 % Mn, so 10 % is vacant. Its oxygen octahedron crosses the cell boundary: turn on Bonded neighbours in the sidebar to complete it.
import numpy as np
from ase import Atoms
atoms = Atoms(
symbols=["Fe", "O", "O", "O"],
scaled_positions=[
[0.5, 0.5, 0.5], [0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0],
],
cell=np.eye(3) * 4.0,
pbc=True,
)
atoms.info["occupancy"] = {
"0": {"Fe": 0.6, "Mn": 0.3}, # 10 % vacant
"1": {"O": 1.0}, "2": {"O": 1.0}, "3": {"O": 1.0},
}
atoms.new_array("spacegroup_kinds", np.arange(len(atoms)))
MolecularViewer(
atoms, show_polyhedron=True, polyhedron_color_mode="geometry"
).show()
A larger case: a 2×2×2 perovskite with Ba₀.₅₅Sr₀.₃₅ A sites, Ti₀.₇₅Zr₀.₂₅ B sites and 95 % occupied oxygen. Switch Style to compare how each style draws the sectors; bonds and Ti–O polyhedra can be turned on under Bonds & polyhedra.
Viewer-frame dicts can give the occupancies directly with a species list: