ChemView
ChemView is a wrapper around Chemiscope for
visualising ASE trajectories in Jupyter notebooks. It computes geometric and
atomic properties from ase.Atoms objects and renders them as a linked
scatter plot and 3-D structure viewer.
from sparc.src.utils.chemview import ChemView
For worked examples, see the companion notebook below.
Interactive Demo
The widget below shows 264 frames of an ammonia borane (NH₃BH₃) trajectory. The scatter plot maps B–N distance (y-axis) vs frame index (x-axis), coloured by relative energy. Click any point to jump to that structure in the 3-D viewer; click any atom to highlight its environment.
Note
The viewer loads chemiscope.js from the internet.
If it does not appear, check your connection or open the file directly:
docs/source/_static/chemview_demo.html.
To regenerate the demo from a different trajectory:
python docs/source/generate_chemview_demo.py path/to/file.traj
Requirements
chemiscope and numpy must be installed alongside ASE:
pip install chemiscope numpy
Parameters
- frames
ase.Atomsorlist[ase.Atoms] Input structures. A single
Atomsobject or a list. Must be non-empty.- specs
list[str] Properties to compute from the trajectory. See Property Specs below.
- x, y
str Property names for the scatter-plot axes. Defaults to
"frame"and"energy"when those specs are present.- z
str Optional third axis for 3-D scatter plots.
- color
str Property used to colour scatter-plot points.
- size
str Property used to scale point size.
- symbol
str Property used for point symbols.
- names
list[str] Custom names for each spec. Length must match
specs.- color_atoms
"element"|"atom_index"|None Colouring scheme for atoms in the 3-D viewer. Default:
"element".- labels
bool Show element symbols on atoms in the 3-D viewer.
- show_index
bool Clicking an atom centres the view on it and shows its properties in the info panel.
- env_cutoff
float Cutoff radius in Å for the atom environment sphere. Default: 3.5.
- plot
bool Show the scatter-plot panel alongside the 3-D viewer. Default:
True.
Property Specs
Each spec is a string passed in the specs list.
Structure-level
One value per frame.
Spec |
Unit |
Description |
|---|---|---|
|
Frame index (0, 1, 2, …) |
|
|
eV |
Potential energy from |
|
Å |
Distance between atoms i and j |
|
deg |
Angle at atom j in the i-j-k triplet |
|
deg |
Dihedral angle for the i-j-k-l quadruplet |
|
ų |
Cell volume from |
|
Å |
Lattice vector lengths |
|
deg |
Cell angles |
Atom-level
One value per atom per frame. All frames must have the same number of atoms.
Spec |
Unit |
Description |
|---|---|---|
|
Å |
Cartesian position components |
|
Element symbol |
|
|
Atomic number |
|
|
eV/Å |
Force components |
|
eV/Å |
Force magnitude |
If forces are not available on a frame, values are filled with NaN.
Note
atom_index is always included as a default property and does not need
to be listed in specs.
Auto-generated Names
When names is not provided, property keys are generated from the spec
string:
"frame" → "frame"
"energy" → "energy"
"distance:0,4" → "distance_0_4"
"angle:0,1,2" → "angle_0_1_2"
"dihedral:0,1,2,3" → "dihedral_0_1_2_3"
"force_norm" → "force_norm"
These keys are used for x, y, color, etc. When the same spec
type appears more than once, use names to assign distinct keys.
Constraints
All frames must contain the same number of atoms.
energyand force-based specs require a calculator or pre-stored arrayson the
Atomsobjects. Missing values are filled withNaN.
Duplicate property names are not allowed. Use
namesto disambiguate.
API Reference
- sparc.src.utils.chemview.ChemView(*, frames, specs, x, y, z=None, names=None, units_override=None, **kwargs)[source]
Build properties from user defined specs and launch a Chemiscope viewer.
- Parameters:
frames (sequence of ase.Atoms)
specs (list ("frame", "energy", "distance:i,j", "angle:i,j,k", "dihedral:i,j,k,l"))
x (str structure property names ('energy', 'distance',...))
y (str structure property names ('energy', 'distance',...))
z (str or None)
names (list or None)
units_override (dict or None)
meta_name (str, optional) – Dataset label shown in Chemiscope. Default
"ChemView".color_atoms (str or None, optional) – Atom colouring in the 3-D viewer:
"element","atom_index", orNone. Default"element".labels (bool, optional) – Show element symbols on atoms. Default
False.show_index (bool, optional) – Show atom index numbers on atoms. Default
False.env_cutoff (float, optional) – Cutoff radius (Å) for atom environment selection. Default
3.5.map_color (str or None, optional) – Property used to colour scatter-plot points. Must be one of
x,y, orz. DefaultNone.plot (bool, optional) – Show the scatter-plot panel alongside the 3-D viewer. Default
True.
Examples
Basic usage:
from sparc.src.utils.chemview import ChemView ChemView(frames=traj, specs=["frame", "energy", "angle:0,1,7"], x="frame", y="energy", map_color='energy')
Show atom indices and click-to-select:
ChemView(frames=traj, specs=["frame", "energy"], x="frame", y="energy", show_index=True, color_atoms='atom_index')