SurfaceViewer
Isosurfaces for orbital, density and density-difference grids. Surfaces are extracted in Python (CUBE/CHGCAR parsing and marching cubes) and drawn by the same engine as MolecularViewer, so structure settings, the player, camera presets, measurement and PNG/GIF export all apply.
See the Isosurfaces guide for worked examples.
Constructor
SurfaceViewer(source, *, molecule=None, surface_style="solid", show_molecule=True,
show_cell=True, show_bonds=True, theme=None, **kwargs)
| Parameter | Type | Description | Default |
|---|---|---|---|
source |
str, Path, cube.Cube, cube.GridField, payload |
CUBE/CHGCAR-style file or grid, or a prebuilt surface payload | Required |
molecule |
Atoms, frame dict, path, None |
Structure drawn with the surface; None uses the atoms stored in the grid file |
None |
surface_style |
str |
solid, mesh, contour or dot |
"solid" |
show_molecule, show_cell, show_bonds |
bool |
What to draw under the surfaces | True |
theme |
str |
Viewer theme; None uses get_theme() |
None |
Extraction options
| Keyword | Description | Default |
|---|---|---|
surface_kind |
orbital, density or delta_density (a signed difference field such as CHGDIFF) |
"orbital" |
dataset |
Dataset name or index for multi-dataset grids | None |
isovalue |
Number, list, "auto", or a range string (below) |
"auto" |
surface_color |
Positive density shells | "#3b82f6" |
positive_color, negative_color |
Positive/negative lobes; negative_color also colors negative density levels |
"#ef4444", "#2563eb" |
opacity |
Maximum shell opacity | 0.65 |
opacity_ramp |
One opacity per isovalue (same length as the level list) | None |
quality |
Extraction budget: low, medium or high |
"medium" |
max_grid_points, max_triangles |
Explicit budgets instead of quality |
None |
smoothing |
Smooth the field before extraction | None |
normalize_orbital |
Normalize orbital data before extraction | True |
Any other keyword is a viewer setting, e.g.
contour_slices, surface_opacity_scale, style or view_preset.
Isovalues
| Syntax | Levels |
|---|---|
0.04, [0.02, 0.04], "0.02,0.04,0.08" |
Explicit |
"0.02:0.08:4" or "linspace(0.02,0.08,4)" |
4 evenly spaced, both endpoints included |
"auto" |
Chosen from the data range |
density: levels are signed. Positive levels usesurface_color, negative levelsnegative_color; on an all-negative field"auto"picks a negative level.orbitalanddelta_density: levels are magnitudes, and each gives a positive and a negative shell (opacity_rampapplies to both).- Zero is not a valid isovalue.
Class methods
from_cube_diff()
SurfaceViewer.from_cube_diff(left, right, *, diff_sign="1-2", molecule=None,
surface_style="solid", theme=None, **kwargs)
Delta density left - right (diff_sign="2-1" for right - left). The grids
must match. Takes the same extraction options.
sequence()
One entry per frame, played like a trajectory:
| Key | Description |
|---|---|
label |
Frame label |
molecule |
Structure for this frame |
surface |
One surface: a path, or a dict with path (or two paths for a difference) and per-surface options such as surface_kind, isovalue |
surfaces |
Several surfaces, as a {"HOMO": ..., "LUMO": ...} mapping or a list of dicts with label |
A two-path surface is a delta density unless surface_kind says otherwise.
The CLI reads the same frames from a JSONL file (paths relative to the file) or
from extxyz Atoms.info keys; see
-v surface-sequence.
Methods
show(), get_html(), save_html(), save_png() and save_gif() work as in
MolecularViewer.
In the viewer
The Surfaces section comes first in the sidebar:
- style (solid, mesh, contour, dot) and a global opacity scale;
- one row per shell with visibility, color and opacity, plus All/None;
- a surface picker when frames carry several named surfaces;
- an isovalue field when served by
aseview FILE -O: the local server recomputes the shells at the new level.
Transparent solid shells are drawn back faces first, then front faces, so overlapping lobes stay readable over the molecule.
Scope
ESP and NCI workflows (ESP colormaps, NCI modes, solvent surfaces) and a VS Code
.cube editor are not implemented.