Isosurfaces
SurfaceViewer draws orbital, density and
density-difference isosurfaces from Gaussian CUBE and VASP CHGCAR-style grids.
Surfaces are extracted in Python and shown in the same engine as
MolecularViewer, so styles, the player, measurement and export all work.
Orbitals and densities
from aseview import SurfaceViewer
SurfaceViewer(
"HOMO.cube",
surface_kind="orbital",
isovalue=0.04,
positive_color="#ef4444",
negative_color="#2563eb",
).show()
Orbital isovalues are magnitudes: each level gives a positive and a negative lobe.
Several isovalues and styles
isovalue also takes a list, a comma string, "start:stop:count" or
"linspace(start,stop,count)" (both endpoints included). opacity_ramp sets
one opacity per level.
SurfaceViewer(
"HOMO.cube",
surface_kind="orbital",
isovalue="0.03:0.09:4",
opacity_ramp=[0.25, 0.45, 0.65, 0.8],
surface_style="contour", # or "solid", "mesh", "dot"
).show()
Contour style uses a denser grid and draws horizontal slices, so more levels give a tighter contour field. Each shell can be hidden, recolored or faded in the Surfaces section of the sidebar.
Density differences
Subtract two cubes on the same grid:
SurfaceViewer.from_cube_diff(
"state-a-density.cube",
"state-b-density.cube",
diff_sign="1-2", # "2-1" for the opposite order
isovalue=0.0015,
).show()
For three or more fields, build the difference with the cube package that the
surface extra installs. The docs ship a matgenb CHGCAR fixture of LiMoSâ‚‚ + F
and its two parts on one grid:
from pathlib import Path
from cube import delta_grid_field, read_grid_field
base = Path("docs/assets/examples/surface/chgcar_data")
def density(name):
return read_grid_field(base / f"{name}_CHGCAR", format="chgcar", name=name,
kind="density", chgcar_dataset="total")
ab, a, b = density("LiMoS2_F"), density("LiMoS2"), density("F")
chgdiff = delta_grid_field(delta_grid_field(ab, a, sign="1-2"), b, sign="1-2")
SurfaceViewer(chgdiff, surface_kind="delta_density", isovalue=0.01,
molecule=ab.to_atoms()).show()
A file that already holds a signed difference (CHGDIFF) loads directly:
SurfaceViewer(
"docs/assets/examples/surface/samples/chgdiff/zenodo_13752735_d24_diff.vasp",
surface_kind="delta_density",
isovalue=0.025,
).show()
More CHGCAR, CHGDIFF and CUBE fixtures are listed in
docs/assets/examples/surface/samples/.
Surface sequences
When the surfaces change from frame to frame, SurfaceViewer.sequence() takes
one dict per frame, each with a molecule and one surface or several named
surfaces. The player steps through frames; the Surface picker switches
between named surfaces such as HOMO and LUMO.
frames = [
{"label": "step 0", "molecule": atoms_0,
"surfaces": {"HOMO": "step_000/HOMO.cube", "LUMO": "step_000/LUMO.cube"}},
{"label": "step 1", "molecule": atoms_1,
"surfaces": {"HOMO": "step_001/HOMO.cube", "LUMO": "step_001/LUMO.cube"}},
]
viewer = SurfaceViewer.sequence(frames, surface_kind="orbital", isovalue=0.03)
viewer.save_html("homo-lumo.html")
From the CLI, write the same frames as JSONL (one object per line, paths relative to the file), or keep the paths in extxyz frame metadata:
aseview frames.jsonl -v surface-sequence --surface-kind orbital --isovalue 0.03
aseview traj.extxyz -v surface-sequence --surface-path-key surface_path \
--surface-kind density
Below, a two-frame sequence over the Psi4 densities psi4_Da.cube and
psi4_Db.cube in docs/assets/examples/surface/samples/cube/: