Skip to main content

New in 0.39

Features added in the 0.39 release: five new map projections (including an orthographic projection you animate for a spinning globe), MD-trajectory playback for molecules, and property-based protein coloring. Each section lists the real exported API, a copy-paste snippet, and a runnable example. The two map examples share one inline world outline (the Natural Earth 1:110m land, a compact TopoJSON decoded with topojsonToGeojson); the molecule examples are hand-authored inline. No files, no network calls.

Rotating globe with the orthographic projection (0.39)​

orthographic(options) builds the "view of a globe from far away" projection. Its rotate: [centerLon, centerLat] option sets the geographic point at the center of the disc; animate centerLon and the globe spins about its axis. The far hemisphere is unmappable, so the projection returns [NaN, NaN] for those points. ChoroplethMap reads the projection's clipRadius and clips each land ring to the globe limb, following the edge across the hidden side, so continents end cleanly on the silhouette instead of chording across the disc.

ChoroplethMap fixes its projection at construction and has no reprojection call, so a holder Group with an updater rebuilds the map every frame from a ValueTracker that sweeps the longitude. A fixed domain holds the color ramp steady while the regions move. orthographic is 2D, so this uses a regular Scene.

Source Code
import { ChoroplethMap, orthographic, ValueTracker, Group, Circle, topojsonToGeojson } from 'manim-web';

// Decode the inline Natural Earth 1:110m land outline (one MultiPolygon of the
// continents). Color every feature as land.
const geojson = topojsonToGeojson(worldLandTopology, 'land');

// A static blue disc behind the land: the ocean and the globe silhouette.
const ocean = new Circle({ radius: 2.6, strokeWidth: 0 });
ocean.setFill('#0d3b66', 1);

// One orthographic view of the land, centered on `lon`. ChoroplethMap clips each
// ring to the limb, so the continents end on the globe edge.
const buildLand = (lon) =>
new ChoroplethMap({
geojson,
value: () => 1,
colorScale: ['#3a9f5a', '#3a9f5a'], // green land
domain: [0, 1],
projection: orthographic({ radius: 2.6, rotate: [lon, 0] }),
borderColor: '#0b2a17',
borderWidth: 0.4,
});

// Animate the center longitude; a holder's updater swaps in a freshly projected
// land layer (ChoroplethMap cannot reproject in place). Rebuilding every 2
// degrees keeps the turn smooth without rebuilding the outline every frame.
const centerLon = new ValueTracker(0);
const holder = new Group();
let lastStep = null;
holder.addUpdater(() => {
const step = Math.round(centerLon.getValue() / 2) * 2;
if (step === lastStep) return;
lastStep = step;
holder.clear();
holder.add(buildLand(step));
});
holder.add(buildLand(0));
scene.add(ocean); // use a regular Scene
scene.add(holder);

await scene.play(centerLon.animateTo(360, { duration: 10 })); // one full turn

orthographic options are radius (disc radius, default 1) and rotate ([centerLon, centerLat] in degrees, default [0, 0]).


Whole-world maps with mollweide and robinson (0.39)​

mollweide(options) is the elliptical equal-area whole-world projection; robinson(options) is the compromise flat-top world map. Both take the same options and plug straight into a ChoroplethMap as its projection. albers (conic equal-area) and the composite albersUsa (continental US with Alaska and Hawaii insets) round out the five new projections, for US thematic maps. These projections are 2D, so this uses a regular Scene.

The example projects the same inline world outline used by the globe above into the Mollweide ellipse, fills the continents green over a blue ocean ellipse, and reveals it with Create.

Source Code
import { ChoroplethMap, mollweide, Create, Ellipse, topojsonToGeojson } from 'manim-web';

// The same inline Natural Earth 1:110m land outline as the globe example.
const geojson = topojsonToGeojson(worldLandTopology, 'land');

// A blue ocean ellipse the size of the Mollweide frame (x half-width
// 2*sqrt(2)*R, y half-height sqrt(2)*R), behind the green continents.
const ocean = new Ellipse({
width: 2 * 2 * Math.SQRT2 * 1.3,
height: 2 * Math.SQRT2 * 1.3,
strokeWidth: 0,
});
ocean.setFill('#0d3b66', 1);

const map = new ChoroplethMap({
geojson,
value: () => 1,
colorScale: ['#3a9f5a', '#3a9f5a'], // green land
domain: [0, 1],
// mollweide: elliptical equal-area. Swap for robinson() for the flat-top
// world map with the same call shape.
projection: mollweide({ radius: 1.3 }),
borderColor: '#0b2a17',
borderWidth: 0.5,
});

scene.add(ocean); // use a regular Scene
scene.add(map);
await scene.play(new Create(map, { duration: 2.5 }));

mollweide and robinson options are radius (scale, default 1) and centerLon (central meridian in degrees, default 0). albers adds parallels, centerLon and centerLat; albersUsa takes only radius.


MD-trajectory playback with playTrajectory (0.39)​

parsePdbTrajectory(text) reads a multi-MODEL PDB into { structure, frames, numModels }: one conformation per MODEL block, every frame with the same atoms in the same order. playTrajectory({ molecule, frames }) returns an Animation that drives a Molecule3D from frame 0 through each frame in order, interpolating atom positions and rebuilding the bonds every frame so the sticks follow. MoleculeTrajectory is the underlying class; morphMolecule is the single-target sibling that morphs from the molecule's current shape to one to conformation. Molecule3D is 3D, so this uses a ThreeDScene.

The example parses an inline 3-MODEL PDB of one 6-carbon chain (extended, half-folded, hairpin) and plays it forward then back.

Source Code
import { parsePdbTrajectory, Molecule3D, playTrajectory, Create } from 'manim-web';

// pdb is an inline multi-MODEL PDB string (3 models, 6 carbons, CONECT chain).
const traj = parsePdbTrajectory(pdb); // { structure, frames, numModels }

// Build the molecule from model 1; its atom count matches every frame. The
// carbons are tinted so the chain reads on the dark background.
const molecule = new Molecule3D({
atoms: traj.structure.atoms,
bonds: traj.structure.bonds,
style: 'ball-and-stick',
colors: { C: '#58c4dd' },
bondColor: '#9fe3f0',
});
scene.add(molecule); // use a ThreeDScene
await scene.play(new Create(molecule, { duration: 1.2 }));

// Play frame 0 -> 1 -> 2, then back, so it loops.
await scene.play(playTrajectory({ molecule, frames: traj.frames, runTime: 2.5 }));
await scene.play(playTrajectory({ molecule, frames: [...traj.frames].reverse(), runTime: 2.5 }));

playTrajectory options are molecule, frames (one conformation per frame), and runTime (seconds, default 2). morphMolecule takes molecule, a single to (or a frames trajectory), and runTime.


Property-based protein coloring (0.39)​

Protein gains three property color modes beyond the structural ones: colorMode: 'bfactor' maps the per-residue B-factor (temperature factor) onto a blue -> white -> red ramp; 'hydrophobicity' uses the Kyte-Doolittle scale; and 'charge' paints basic, acidic and neutral residues. The 'bfactor' mode reads residue.tempFactor, which parsePdb fills from the PDB B-factor column, so parse the structure first. The other two read only the residue code.

The example parses an inline CA-only PDB whose B-factors rise from the rigid ends to a flexible middle, then draws a tube colored by 'bfactor'. Protein is 3D, so this uses a ThreeDScene.

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

// parsePdb reads the B-factor column into each residue's tempFactor.
const { residues } = parsePdb(pdb);

const protein = new Protein({
residues,
representation: 'tube',
colorMode: 'bfactor', // blue (rigid) -> white -> red (flexible); 'hydrophobicity' / 'charge' too
tubeRadius: 0.35,
smoothing: 8,
});
scene.add(protein); // use a ThreeDScene
await scene.play(new Create(protein, { duration: 2.5 }));

colorMode 'bfactor' needs per-residue B-factor data (parse with parsePdb, or it throws). 'hydrophobicity' and 'charge' work from the residue code alone. The B-factor ramp is DEFAULT_BFACTOR_COLORS, with the domain taken from the data.