Skip to content

Structures & Coloring

The basics of MolecularViewer: a structure, a style, and what the atoms are colored by.

from ase.io import read
from aseview import MolecularViewer

atoms = read("molecule.xyz")
MolecularViewer(atoms, style="cartoon").show()
aseview molecule.xyz --style cartoon

Styles and size

style picks the atom and bond look (compare them all on Styles). atom_size, bond_thickness and radius_contrast set the proportions; bond_threshold decides which atoms are bonded.

MolecularViewer(
    atoms,
    style="neon",
    background_color="#000000",
    atom_size=0.5,
    bond_thickness=0.15,
)

Partial charges

color_by="charge" colors atoms from red (negative) through white to blue (positive), with a colorbar. Charges come from atoms.arrays["charges"] or atoms.info["charges"]; magnetic moments work the same way with color_by="magmom".

import numpy as np

atoms.arrays["charges"] = np.array([...])
MolecularViewer(atoms, color_by="charge", show_charge_labels=True)

normalize_charges=True scales positive and negative values to their own extremes; show_charge_labels=True prints the values on the atoms.

Fixed atoms

show_constraint=True marks atoms fixed by ASE FixAtoms with a semi-transparent yellow overlay; they keep their element color. See the Cu(111) slab for a live example.

from ase.constraints import FixAtoms

atoms.set_constraint(FixAtoms(indices=[0, 1, 2]))
MolecularViewer(atoms, show_constraint=True)

More