Skip to content

OverlayViewer

Draw several structures in one frame of reference to compare conformers, optimization steps or reaction paths, with optional Kabsch alignment.

See the Overlay Comparison example for a walkthrough.

Constructor

OverlayViewer(data, index_list=None, *, topology=None, index=":", format=None,
              topology_format=None, visible_indices=None,
              all_visible=False, theme=None, **settings)
Parameter Type Description Default
data list[Atoms], trajectory, dict, str Structures to overlay Required
index_list None, list[int], list[list[int]] Atom subset, see below None
topology, index, format, topology_format Paired MD read controls; index selects frames before the index_list atom subset. None, ":", None, None
visible_indices list[int] Structures shown initially (default: the first three) None
all_visible bool Show every structure initially; cannot be combined with visible_indices False
theme str Viewer theme; None uses get_theme() None
**settings Viewer settings for this viewer

index_list keeps only some atoms:

Value Behaviour
None All atoms of every structure
[0, 1, 2] The same indices in every structure
[[0, 1], [2, 3], [0, 2]] One index list per structure (one entry per structure)

Fixed-atom indices and per-atom arrays are remapped to the kept atoms.

Overlay settings:

Setting Description Default
color_by structure (one color per structure), colormap (colors along the sequence) or element "structure"
overlay_colormap viridis, plasma, coolwarm, jet, rainbow or grayscale "viridis"
structure_colors, structure_opacities, structure_visibility Per-structure overrides keyed by index, e.g. {1: "#ff0000"}
align_structures Kabsch-align every structure onto the first False
reorder_atoms Match atoms element by element before aligning (different atom order) True
align_indices Fit on these atoms only, e.g. [0, 1, 2] or "0-5, 8"; the fit moves the whole structure. Empty fits on all atoms. []

Styles, bonds and view settings work as in MolecularViewer.

Methods

show(), get_html(), save_html() and save_png() work as in MolecularViewer.

In the viewer

  • Structures section: one row per structure with visibility, color and opacity; All/None toggles.
  • Align (Kabsch): switch between original and aligned coordinates; reorder atoms and the fit subset are next to it.

Structures are labelled with atoms.info["name"] when present.

Examples

Compare conformers

from ase.io import read
from aseview import OverlayViewer

conformers = read("conformers.xyz", index=":")
OverlayViewer(conformers, align_structures=True, all_visible=True).show()

Align on part of the molecule

# Fit on the ring atoms only; the rest follows the same rotation.
OverlayViewer(conformers, align_structures=True, reorder_atoms=False,
              align_indices="0-5").show()

Optimization path with a colormap

trajectory = read("optimization.xyz", index=":")
OverlayViewer(trajectory, color_by="colormap", overlay_colormap="plasma",
              all_visible=True).show()

Atom subsets

OverlayViewer(structures, index_list=[0, 1, 2])            # same atoms in every structure
OverlayViewer(structures, index_list=[[0, 1], [2, 3]])     # per structure
OverlayViewer(structures, visible_indices=[0, len(structures) - 1])  # first and last shown

Named structures

from ase.build import molecule

reactant = molecule("C2H6"); reactant.info["name"] = "Ethane (reactant)"
product = molecule("C2H4"); product.info["name"] = "Ethene (product)"
OverlayViewer([reactant, product]).save_html("comparison.html")