Gallery
A collection of visualization examples. Each example shows a live 3D preview and the code needed to reproduce it in Jupyter, React, or the VSCode extension.
Small Molecule System
Visualize a solvated small molecule system with distance-based bond detection.
import meganefrom megane import Pipeline, LoadStructure, AddBonds, Viewport
pipe = Pipeline()s = pipe.add_node(LoadStructure("caffeine_water.pdb"))ab = pipe.add_node(AddBonds(source="distance"))v = pipe.add_node(Viewport())
pipe.add_edge(s.out.particle, ab.inp.particle)pipe.add_edge(s.out.particle, v.inp.particle)pipe.add_edge(ab.out.bond, v.inp.bond)
viewer = megane.MolecularViewer()viewer.set_pipeline(pipe)viewerCrystal with Coordination Polyhedra
Render TiO₆ coordination polyhedra on a perovskite crystal structure with periodic cell axes.
import meganefrom megane import Pipeline, LoadStructure, AddBonds, AddPolyhedra, Viewport
pipe = Pipeline()s = pipe.add_node(LoadStructure("perovskite_srtio3_3x3x3.xyz"))ab = pipe.add_node(AddBonds(source="distance"))# TiO6 octahedra: center = Ti (22), ligand = O (8)poly = pipe.add_node(AddPolyhedra( center_elements=[22], ligand_elements=[8], max_distance=2.5, opacity=0.5, show_edges=True,))v = pipe.add_node(Viewport(cell_axes_visible=True))
pipe.add_edge(s.out.particle, ab.inp.particle)pipe.add_edge(s.out.particle, poly.inp.particle)pipe.add_edge(s.out.particle, v.inp.particle)pipe.add_edge(s.out.cell, v.inp.cell)pipe.add_edge(ab.out.bond, v.inp.bond)pipe.add_edge(poly.out.mesh, v.inp.mesh)
viewer = megane.MolecularViewer()viewer.set_pipeline(pipe)viewerAtom Filter
Select solute atoms with a query and enlarge them 3× while fading solvent to 15% opacity, making the selection immediately obvious.
import meganefrom megane import Pipeline, LoadStructure, Filter, Modify, Viewport
pipe = Pipeline()s = pipe.add_node(LoadStructure("caffeine_water.pdb"))
# Branch A: enlarge the solute (caffeine = first 24 atoms)fc = pipe.add_node(Filter(query="index < 24"))mc = pipe.add_node(Modify(scale=3.0, opacity=1.0))
# Branch B: fade the solvent (water = remaining atoms)fw = pipe.add_node(Filter(query="index >= 24"))mw = pipe.add_node(Modify(scale=1.0, opacity=0.15))
v = pipe.add_node(Viewport())
pipe.add_edge(s.out.particle, fc.inp.particle)pipe.add_edge(fc.out.particle, mc.inp.particle)pipe.add_edge(mc.out.particle, v.inp.particle)
pipe.add_edge(s.out.particle, fw.inp.particle)pipe.add_edge(fw.out.particle, mw.inp.particle)pipe.add_edge(mw.out.particle, v.inp.particle)
viewer = megane.MolecularViewer()viewer.set_pipeline(pipe)viewerDual Representation
Fan out the pipeline to render the solute in full detail while the solvent is dimmed and semi-transparent.
import meganefrom megane import Pipeline, LoadStructure, AddBonds, Filter, Modify, Viewport
pipe = Pipeline()s = pipe.add_node(LoadStructure("caffeine_water.pdb"))ab = pipe.add_node(AddBonds(source="distance"))
# Branch 1: caffeine (index < 24) — full sizef_solute = pipe.add_node(Filter(query="index < 24"))m_solute = pipe.add_node(Modify(scale=1.3, opacity=1.0))
# Branch 2: water (index >= 24) — small and transparentf_solvent = pipe.add_node(Filter(query="index >= 24"))m_solvent = pipe.add_node(Modify(scale=0.8, opacity=0.15))
v = pipe.add_node(Viewport())
# Bondspipe.add_edge(s.out.particle, ab.inp.particle)pipe.add_edge(ab.out.bond, v.inp.bond)
# Solute branchpipe.add_edge(s.out.particle, f_solute.inp.particle)pipe.add_edge(f_solute.out.particle, m_solute.inp.particle)pipe.add_edge(m_solute.out.particle, v.inp.particle)
# Solvent branchpipe.add_edge(s.out.particle, f_solvent.inp.particle)pipe.add_edge(f_solvent.out.particle, m_solvent.inp.particle)pipe.add_edge(m_solvent.out.particle, v.inp.particle)
viewer = megane.MolecularViewer()viewer.set_pipeline(pipe)viewerAtom Labels
Generate per-atom text labels (element symbols) on a filtered subset of atoms.
import meganefrom megane import Pipeline, LoadStructure, Filter, AddLabels, Viewport
pipe = Pipeline()s = pipe.add_node(LoadStructure("caffeine_water.pdb"))# Focus on the solute molecule onlyf = pipe.add_node(Filter(query="index < 24"))lbl = pipe.add_node(AddLabels(source="element"))v = pipe.add_node(Viewport())
pipe.add_edge(s.out.particle, f.inp.particle)pipe.add_edge(f.out.particle, v.inp.particle)pipe.add_edge(f.out.particle, lbl.inp.particle)pipe.add_edge(lbl.out.label, v.inp.label)
viewer = megane.MolecularViewer()viewer.set_pipeline(pipe)viewerBond Filter
Use a bond query to hide solvent bonds: select bonds touching a water atom and set their opacity to 0, leaving only intramolecular solute bonds visible.
import meganefrom megane import Pipeline, LoadStructure, AddBonds, Filter, Modify, Viewport
pipe = Pipeline()s = pipe.add_node(LoadStructure("caffeine_water.pdb"))ab = pipe.add_node(AddBonds(source="distance"))
# Select bonds that touch a water atom (atom_index >= 24) — these will be hiddenfb = pipe.add_node(Filter(bond_query="atom_index >= 24"))# Set opacity=0 on the selected (water) bonds to hide themmb = pipe.add_node(Modify(opacity=0.0))
v = pipe.add_node(Viewport())
pipe.add_edge(s.out.particle, ab.inp.particle)pipe.add_edge(ab.out.bond, fb.inp.particle) # bond → filter "in" portpipe.add_edge(fb.out.particle, mb.inp.particle) # filter "out" → modify "in"pipe.add_edge(mb.out.particle, v.inp.bond) # modify "out" → viewport bond
pipe.add_edge(s.out.particle, v.inp.particle)
viewer = megane.MolecularViewer()viewer.set_pipeline(pipe)viewerTrajectory Animation
Load an XTC trajectory file alongside the structure to animate molecular vibrations frame by frame. The gallery preview auto-plays a built-in vibration demo.
import meganefrom megane import Pipeline, LoadStructure, LoadTrajectory, AddBonds, Viewport
pipe = Pipeline()s = pipe.add_node(LoadStructure("caffeine_water.pdb"))traj = pipe.add_node(LoadTrajectory(xtc="caffeine_water_vibration.xtc"))ab = pipe.add_node(AddBonds(source="structure"))v = pipe.add_node(Viewport())
pipe.add_edge(s.out.particle, ab.inp.particle)pipe.add_edge(s.out.particle, traj.inp.particle) # topology for XTCpipe.add_edge(s.out.particle, v.inp.particle)pipe.add_edge(ab.out.bond, v.inp.bond)pipe.add_edge(traj.out.traj, v.inp.traj)
viewer = megane.MolecularViewer()viewer.set_pipeline(pipe)viewerVector Arrows
Overlay per-atom vector data (forces or velocities) as arrows using load_vector and vector_overlay nodes. The gallery preview shows synthetic radial arrows.
import meganefrom megane import Pipeline, LoadStructure, AddBonds, LoadVector, VectorOverlay, Viewport
pipe = Pipeline()s = pipe.add_node(LoadStructure("caffeine_water.pdb"))ab = pipe.add_node(AddBonds(source="distance"))vec = pipe.add_node(LoadVector("demo_vectors.vec"))# Scale arrows to a visible lengthoverlay = pipe.add_node(VectorOverlay(scale=1.5))v = pipe.add_node(Viewport())
pipe.add_edge(s.out.particle, ab.inp.particle)pipe.add_edge(s.out.particle, v.inp.particle)pipe.add_edge(ab.out.bond, v.inp.bond)pipe.add_edge(vec.out.vector, overlay.inp.vector)pipe.add_edge(overlay.out.vector, v.inp.vector)
viewer = megane.MolecularViewer()viewer.set_pipeline(pipe)viewerAdding Your Own Example
To contribute a new gallery example, edit docs/src/gallery/registry.ts and add an entry to the galleryExamples array.
| Field | Description |
|---|---|
id | Unique kebab-case identifier (used as HTML anchor) |
title | Short display name |
description | One-sentence description |
tags | Array of lowercase tag strings |
snapshotUrl | Path to a snapshot JSON in docs/public/data/ |
code.jupyter | Python snippet for Jupyter |
code.react | TSX snippet using PipelineViewer |
code.vscode | megane.json content (SerializedPipeline JSON) |