Skip to content

Utilities and Errors

This page covers the small public helpers exported from aseview.__all__. For viewer-specific constructor settings, use the dedicated API pages: MolecularViewer, SurfaceViewer, OverlayViewer, NormalViewer, FragSelector, and LiteViewer; every keyword setting is listed in Viewer Settings.

Public import surface

from aseview import (
    MolecularData,
    read_trajectory,
    MolecularViewer,
    SurfaceViewer,
    OverlayViewer,
    NormalViewer,
    FragSelector,
    LiteViewer,
    view,
    set_theme,
    get_theme,
    list_themes,
    normalize_settings,
    settings_schema,
    ImageExportError,
)

These names are the supported top-level import surface. Lower-level modules (aseview.viewers, aseview.data, aseview.surface_*, parser helpers) are implementation details unless they are promoted here.

settings_schema() and normalize_settings()

settings_schema() returns the viewer settings schema (the data behind Viewer Settings): every key with its type, default, range or options, and the viewers it applies to. normalize_settings(settings, mode) validates a dict the way viewer constructors do and returns camelCase keys:

from aseview import normalize_settings

normalize_settings({"show_cell": False, "style": "Glossy"}, "molecular")
# {'showCell': False, 'style': 'glossy'}

read_trajectory()

read_trajectory(coordinates, *, topology, index=":", format=None,
                topology_format=None) -> list[Atoms]

Requires pip install "aseview[md]". Reads a coordinate path or ordered list of paths with a matching topology and returns selected independent ASE Atoms objects. Paths may be strings or pathlib.Path values. Frame indices may be integers, slices or ASE-style strings, and apply separately to each coordinate file. Empty selections and invalid inputs raise ValueError; a missing MD dependency raises ImportError with installation guidance.

Positions and cell vectors are in Å. Per-atom arrays preserve atomtypes (names), atom_ids, residuenames, residuenumbers, chain_ids and segment_ids when available, plus md_element_guessed. info preserves md_source, zero-based md_source_segment and md_source_frame, time_ps, md_time_source and md_elements_source. Original atom IDs need not be unique and are distinct from zero-based row indices. No atom reordering or topology bond rendering is performed.

See MD topology and coordinates for the supported format matrix, element inference, time and cell behavior.

MolecularData

MolecularData converts ASE Atoms objects into the JSON-compatible frame contract consumed by the browser viewers.

from ase.build import molecule
from aseview import MolecularData

atoms = molecule("H2O")
frame = MolecularData.from_atoms(atoms)

assert frame["symbols"] == ["O", "H", "H"]
assert len(frame["positions"]) == 3

The serialized frame includes only values that are present and JSON-safe. Cell, PBC, forces, charges, magnetic moments, arrays, energy, and name metadata are preserved when they are unambiguous. aseview does not infer energy or forces provenance: if a value is present it is passed through for display/export; if it is absent or non-finite it is omitted rather than fabricated.

Fixed atoms and move masks

fixed is an index list in the displayed atom order:

{"fixed": [0, 3, 4]}

It is not a boolean mask. Boolean fixed masks and three-axis selective-dynamics masks live under arrays.fixed and arrays.move_mask when those arrays are available. When a viewer is created from a filtered or duplicated index list, the Python serializer remaps fixed indices to the displayed output atoms.

Themes

import aseview

aseview.list_themes()   # ['spring', 'simple', 'glass', 'dark', 'darkgreen']
aseview.get_theme()     # current default: 'spring'
aseview.set_theme("dark")

The default theme applies to viewers created afterwards whose theme= is None. All five themes ship inside the viewer engine, so every viewer (MolecularViewer, SurfaceViewer, OverlayViewer, NormalViewer, FragSelector, LiteViewer) supports every theme. See Theming.

view()

view() is a notebook-friendly shorthand for creating a LiteViewer, showing it immediately, and returning it:

from ase.build import molecule
from aseview import view

viewer = view(molecule("H2O"), style="cinematic", hide_hydrogens=True, center=True)

ImageExportError

ImageExportError is raised by Python PNG/GIF export helpers when browser export fails or returns invalid image data.

from aseview import ImageExportError, MolecularViewer

try:
    MolecularViewer(atoms).save_png("molecule.png")
except ImageExportError as exc:
    print(f"image export failed: {exc}")

The error means no valid image was confirmed. The export path validates browser data before writing the destination file, so corrupt or non-image payloads fail before replacing output.