Skip to main content

New in 0.38

Features added in the 0.38 release: a molecular surface that wraps a molecule in 3D, curved electron-pushing arrows for reaction mechanisms, and two additions to the geo module, animated flow arcs and animated choropleth recoloring. Each section lists the real exported API, a copy-paste snippet, and a runnable example. All data is hand-authored inline: no files, no network calls.

MolecularSurface (0.38)​

MolecularSurface wraps a set of atoms in a translucent skin and extends Group, so it composes with Molecule3D in the same ThreeDScene and the same world coordinates. An atom is { element, position: [x, y, z] }, the same Atom3DSpec that Molecule3D takes. kind is 'vdw' (the union of van der Waals spheres, the default) or 'sas' (the solvent-accessible surface, which adds a probeRadius). Keep opacity low (about 0.4) so the sticks underneath read through the skin.

The example wraps the benzene ball-and-stick model from the molecular page in a translucent blue van der Waals surface, then spins it.

Source Code
import { Molecule3D, MolecularSurface, Create, FadeIn } from 'manim-web';

// The ball-and-stick structure (benzene atoms + bonds).
const benzene = new Molecule3D({ atoms, bonds, style: 'ball-and-stick' });
scene.add(benzene); // use a ThreeDScene
await scene.play(new Create(benzene, { duration: 2 }));

// A translucent van der Waals skin over the SAME atoms, same world coords.
const surface = new MolecularSurface({
atoms,
kind: 'vdw', // or 'sas' for the solvent-accessible surface
color: '#6fa8dc',
opacity: 0.4, // low, so the sticks read through
});
scene.add(surface);
await scene.play(new FadeIn(surface));

Options are atoms (required), kind, probeRadius, radiusScale, color, opacity, resolution (marching-cubes grid cells per axis, default 48), isoValue, padding, and scale. The read-only surface field is the underlying ImplicitSurface, or null when there are no atoms.


FlowArc (0.38)​

FlowArc draws a curved flow line between two geographic points on a projection, the 2D counterpart of Globe.arc. It extends Polygon, so Create reveals it progressively. Endpoints are [latitude, longitude] in degrees. Pass the SAME projection instance the map uses, or the arcs will not land on the regions. bulge sets how far the arc bows from the straight chord (default 0.2; negative bows the other way).

FlowArc is 2D, so it uses a regular Scene. The example lays three flow arcs over a row of ChoroplethMap regions on a shared equirectangular projection; a wide bulge makes each arc bow up over the row so the flow reads clearly.

Source Code
import { ChoroplethMap, FlowArc, equirectangular, Create } from 'manim-web';

// One projection instance, shared by the map and every arc.
const projection = equirectangular({ radius: 24 });

const map = new ChoroplethMap({
geojson, // a FeatureCollection of rectangular Polygons, coords [lon, lat]
value: (feature) => feature.properties.value,
colorScale: ['#0d1b2a', '#4cc9f0'],
projection,
});
await scene.play(new Create(map, { duration: 1.5 }));

// Endpoints are [lat, lon]; the arc swaps the pair before projecting. A wide
// bulge bows the arc up over the regions, into the background.
const flow = new FlowArc({
from: [0, -11], // [lat, lon]
to: [0, 10],
projection, // the SAME instance as the map
bulge: 0.4,
color: '#ff6b35',
lineWidth: 3,
});
await scene.play(new Create(flow, { duration: 1 }));

Options are from and to (required), projection, bulge, color, lineWidth (default 2), and samples (polyline resolution, default 48).


animateChoropleth (0.38)​

animateChoropleth(map, toValue, options) returns an Animation that crossfades every region fill of a ChoroplethMap toward the colors a new value accessor produces. toValue is a value accessor (feature) => number, the same shape as the map's value option, not a plain object. ChoroplethMap.setValues(toValue) applies a new accessor at once with no animation. The AnimateChoropleth class is also exported.

The example builds a three-region map colored by value set A, then plays animateChoropleth to recolor the regions to value set B over two seconds. A fixed domain keeps both sets on the same color ramp.

Source Code
import { ChoroplethMap, animateChoropleth, equirectangular, Create } from 'manim-web';

// Each region carries two values; two accessors read set A and set B.
const valueA = (feature) => feature.properties.a;
const valueB = (feature) => feature.properties.b;

const map = new ChoroplethMap({
geojson,
value: valueA, // the start coloring
colorScale: ['#0d1b2a', '#4cc9f0'],
domain: [0, 10], // fixed, so both sets share one ramp
projection: equirectangular({ radius: 24 }),
});
await scene.play(new Create(map, { duration: 1.5 }));

// Recolor every region from set A to set B.
await scene.play(animateChoropleth(map, valueB, { runTime: 2 }));

Options extend the standard animation options: runTime (seconds, the default 1), its alias duration, and rateFunc.


Reaction mechanisms with ElectronPushingArrow (0.38)​

ElectronPushingArrow draws the curved arrow that organic chemists use to show where electrons move in a reaction step. It extends VMobject, so Create reveals the curl progressively. The arrow goes from a source point to a destination point, both [x, y, z]. electrons picks the head: 'pair' (the default) draws a double-barbed arrow for a two-electron pair; 'single' draws a single-barbed fishhook for a one-electron (radical) shift. bulge sets how far the shaft bows off the straight chord, as a fraction of the chord length (default 0.3). direction picks the side it bows to, 'ccw' or 'cw', so you can bend an arrow clear of the atom labels. color and strokeWidth style it.

arrowBetweenAtoms(molecule, i, j, opts) is a convenience that reads the world positions of atoms i and j from a MoleculeMobject and returns an arrow from atom i to atom j, so you do not hand-type the endpoints. It takes the same options as ElectronPushingArrow minus from and to.

The example builds a 2D skeletal fragment for an SN2 step, a nucleophile O, a carbon C, and a leaving group Br joined by a C–Br bond, then overlays two electron-pair arrows: a pink arrow for the nucleophilic attack of O on C (arrowBetweenAtoms), and a magenta arrow for the C–Br bond breaking onto Br. ElectronPushingArrow is 2D, so it uses a regular Scene.

Source Code
import { MoleculeMobject, ElectronPushingArrow, arrowBetweenAtoms, Create } from 'manim-web';

// Atom 0 = nucleophile O, atom 1 = carbon C, atom 2 = leaving group Br.
const molecule = new MoleculeMobject({
atoms: [
{ element: 'O', x: -1.2, y: 1.2 },
{ element: 'C', x: 0.6, y: 0 },
{ element: 'Br', x: 2.4, y: -0.6 },
],
bonds: [{ from: 1, to: 2 }], // the C–Br bond
showCarbonLabels: true,
});
molecule.center();
await scene.play(new Create(molecule, { duration: 1.5 }));

// Nucleophilic attack: an electron pair moves from O (atom 0) to C (atom 1).
const attack = arrowBetweenAtoms(molecule, 0, 1, {
electrons: 'pair', // 'single' for a one-electron fishhook
bulge: 0.35,
direction: 'ccw',
color: '#e84393',
});
await scene.play(new Create(attack, { duration: 1 }));

// Bond breaking: the C–Br pair leaves onto Br. 'cw' bows it clear of the label.
const breaking = new ElectronPushingArrow({
from: [1.5, -0.3, 0],
to: [2.4, -0.9, 0],
electrons: 'pair',
bulge: 0.3,
direction: 'cw',
color: '#f368e0',
});
await scene.play(new Create(breaking, { duration: 1 }));

Options are from and to (required), electrons ('pair' or 'single'), bulge, direction ('ccw' or 'cw'), color, and strokeWidth.


Reaction schemes with ReactionArrow (0.38)​

ReactionArrow draws the arrow between reactants and products in a reaction scheme. It extends VGroup, so Create reveals the shaft progressively. The arrow goes from start to end, both [x, y, z]. kind picks the symbol: 'forward' (the default) is one shaft with one head; 'reversible' is two parallel shafts with full heads pointing opposite ways; 'equilibrium' is two shafts with single-barb harpoon half-heads; 'resonance' is one shaft with a head at both ends. conditionsAbove and conditionsBelow set labels centered over and under the arrow midpoint, for catalysts, solvents, or rate constants. color, strokeWidth, and fontSize style the arrow and the labels.

The example stacks all four kinds in one 2D frame. ReactionArrow is 2D, so it uses a regular Scene. The arrows are white, so they read on the dark background. The forward arrow carries a cat., Δ label above and H2O below; the reversible arrow carries a k1 label above.

Source Code
import { ReactionArrow, Create } from 'manim-web';

// Forward: one shaft, one head, with conditions above and below.
const forward = new ReactionArrow({
start: [-2, 2.4, 0],
end: [2, 2.4, 0],
kind: 'forward', // 'reversible' | 'equilibrium' | 'resonance'
conditionsAbove: 'cat., Δ',
conditionsBelow: 'H2O',
color: '#ffffff',
strokeWidth: 6,
});
await scene.play(new Create(forward, { duration: 0.9 })); // use a regular Scene

// Reversible: two full heads pointing opposite ways, with a rate label.
const reversible = new ReactionArrow({
start: [-2, 0.8, 0],
end: [2, 0.8, 0],
kind: 'reversible',
conditionsAbove: 'k1',
color: '#ffffff',
strokeWidth: 6,
});
await scene.play(new Create(reversible, { duration: 0.9 }));

// equilibrium (harpoon half-heads) and resonance (a head at both ends) follow
// the same pattern, each drawn with its own Create.

Options are start and end (required), kind ('forward', 'reversible', 'equilibrium', or 'resonance'), conditionsAbove, conditionsBelow, color, strokeWidth, and fontSize (default 24).


Atomic orbitals with OrbitalSurface (0.38)​

OrbitalSurface draws an atomic orbital as a two-color isosurface, the positive phase in one color and the negative phase in another. It extends Group, so it lives in a ThreeDScene and composes with Molecule3D in the same world coordinates. type picks the shape: 's' is one sphere, 'px', 'py', and 'pz' are two-lobe dumbbells along each axis, 'dz2' is two lobes with a torus around the waist, and 'dxy' is four lobes. center places the orbital, scale sets the lobe size, and isoValue sets the threshold the lobe is drawn at (a smaller value grows the lobe). positiveColor, negativeColor, and opacity style the two phases.

The example fades in a single pz orbital, the red-and-blue dumbbell, then spins it with a gentle ambient camera rotation. The scene uses orbitControlsUp: 'z', so the dumbbell stays upright along z while it turns.

Source Code
import { OrbitalSurface, FadeIn } from 'manim-web';

// A pz orbital: two lobes along z, red (positive) over blue (negative).
const orbital = new OrbitalSurface({ type: 'pz', scale: 2 });
scene.add(orbital); // use a ThreeDScene with orbitControlsUp: 'z'
await scene.play(new FadeIn(orbital, { duration: 1.5 }));

// Spin slowly so both lobes and the waist between them read as 3D.
scene.beginAmbientCameraRotation(0.3);

Options are type ('s', 'px', 'py', 'pz', 'dz2', or 'dxy', default 'pz'), center, scale (default 2), isoValue, resolution, positiveColor, negativeColor, and opacity. The read-only surfaces field holds the underlying ImplicitSurface per phase.


Molecules from MOL/SDF files (0.38)​

moleculeFromMolfile(text, options) parses a V2000 MOL block (an .mol file or one record of an .sdf file) into a 2D skeletal MoleculeMobject. It reads the atom block for the elements and 2D coordinates, and the bond block for the bond orders and the wedge/dash stereo flags. A bond of order 2 draws a double line; the wedge flag (stereo 1) draws a solid wedge toward the viewer; the dash flag (stereo 6) draws a hashed bond going behind. parseMolfile returns the raw parsed data instead of a mobject, and parseSdf splits a multi-record SDF. The returned mobject is a normal MoleculeMobject, so .center(), .scale() and Create all work on it. The parser takes a string, so there is no file or network access.

The example parses a four-atom inline MOL block: a C=C double bond, a C–O single bond, a C–Cl wedge, and an O–Cl dash. moleculeFromMolfile is 2D, so it uses a regular Scene.

Source Code
import { moleculeFromMolfile, Create } from 'manim-web';

// A hand-authored V2000 MOL block: 4 atoms, 4 bonds.
const molfile = `test-molecule
manim-web
a comment line
4 4 0 0 0 0 0 0 0 0999 V2000
0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.0000 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
0.0000 1.0000 0.0000 Cl 0 0 0 0 0 0 0 0 0 0 0 0
1 2 2 0 0 0 0
2 3 1 0 0 0 0
1 4 1 1 0 0 0
3 4 1 6 0 0 0
M END`;

// Parse into a 2D skeletal MoleculeMobject, then draw it.
const molecule = moleculeFromMolfile(molfile, {
bondLength: 1.8,
showCarbonLabels: true,
});
molecule.center();
molecule.scale(1.6);
await scene.play(new Create(molecule, { duration: 2 })); // use a regular Scene

Options are the MoleculeMobject options minus atoms and bonds (those come from the file), for example bondLength, showCarbonLabels, and bondColor.


Binding-site selection (0.38)​

parsePdb(text) reads fixed-column PDB records from a string into a ParsedStructure: atoms (from ATOM records), hetatms (from HETATM records, the ligand), bonds (from CONECT records), and residues. bindingSiteSelection(structure, radius) returns a new ParsedStructure with only the protein atoms within radius angstrom of any hetatm, the pocket that lines the bound ligand. The ligand is the reference, so it is not kept in the result; render it from structure.hetatms. bonds are kept only when both endpoints survive, re-numbered into the new atom order, and the input is never mutated. selectAtoms(structure, options) is the general filter (by element, chain, residue, or proximity) that this convenience builds on. The default radius is DEFAULT_BINDING_SITE_RADIUS (5). Parsing and selection are pure data operations, so this works without a scene.

The example parses a tiny inline PDB of three residues (ALA 1, SER 2, LEU 3) and a three-atom ligand between residues 1 and 2. bindingSiteSelection with a 6-angstrom radius keeps the ALA 1 and SER 2 atoms (the pocket) and drops LEU 3, which sits about 12 angstrom away. The pocket renders as ball-and-stick with the ligand beside it. Molecule3D is 3D, so it uses a ThreeDScene.

Source Code
import { parsePdb, bindingSiteSelection, Molecule3D, Create, FadeIn } from 'manim-web';

// A hand-authored PDB string (fixed columns). LEU 3 sits far from the ligand.
const pdb = `ATOM 1 N ALA A 1 1.200 1.000 0.000 1.00 0.00 N
ATOM 2 CA ALA A 1 2.000 0.600 0.600 1.00 0.00 C
... (ALA 1, SER 2, far LEU 3, and a 3-atom HETATM ligand LIG) ...
HETATM 15 C1 LIG A 4 0.000 0.000 0.000 1.00 0.00 C
CONECT 2 1 3 5
END`;

const structure = parsePdb(pdb);

// Keep protein atoms within 6 angstrom of the ligand: the pocket. The ligand
// (hetatms) is the reference, so render it separately.
const site = bindingSiteSelection(structure, 6);

const pocket = new Molecule3D({ atoms: site.atoms, bonds: site.bonds, style: 'ball-and-stick' });
const ligand = new Molecule3D({ atoms: structure.hetatms, style: 'ball-and-stick' });
scene.add(pocket); // use a ThreeDScene
scene.add(ligand);
await scene.play(new Create(pocket, { duration: 2 }));
await scene.play(new FadeIn(ligand, { duration: 1 }));

parsePdb takes includeWater (default false). bindingSiteSelection takes the radius in angstrom. selectAtoms takes elements, chains, resSeqs, residueCodes, nearPoint, nearLigand, includeHetatms, and invert.

Molecules from SMILES (0.38)​

moleculeFromSmiles(smiles, options?) parses a SMILES string (the organic subset) into a 2D skeletal MoleculeMobject. It handles atoms, bond orders (=, #), branches (), ring closures (e.g. c1ccccc1), and disconnected components .. Stereochemistry (@/@@, /, \\) is parsed but not drawn, and aromaticity is read from lowercase spelling (no ring perception).

Source Code
import { moleculeFromSmiles, Create } from 'manim-web';

// Organic-subset SMILES: 'CCO' (ethanol), 'c1ccccc1' (benzene),
// 'C1CCCCC1' (cyclohexane), 'CC(=O)O' (acetic acid).
const molecule = moleculeFromSmiles('CC(=O)O', { bondLength: 1.6, showCarbonLabels: true });
molecule.center();
await scene.play(new Create(molecule, { duration: 2 }));

parseSmiles(smiles) returns the parsed { atoms, bonds } graph (with per-atom aromatic/charge/hcount) if you want the data without a mobject.