Open source · Python · MIT

Cluster millions
of MD frames
in minutes, not days.

MDANCE is a toolkit of n-ary clustering algorithms for molecular dynamics. It compares all frames at once, so your analysis scales linearly and gives the same answer every run.

$ pip install mdance
Read the docs ★ Star on GitHub

8 algorithms · 9 peer-reviewed papers in JCTC, JCIM & Digital Discovery · NIH-funded

The problem

MD simulations got huge. Pairwise clustering didn't scale with them.

Modern simulations generate terabytes of conformations. Most clustering tools still reason about them two at a time.

Quadratic cost

Pairwise methods compare every frame with every other frame. Double the trajectory, quadruple the work.

Memory walls

A full RMSD matrix for a million-frame trajectory runs to terabytes before clustering even starts.

Irreproducible runs

Random seeding means different clusters on every run, so reviewers and collaborators get different answers.

Pairwise · every frame vs every frame
n-ary · all frames at once
Try it

How big is your trajectory?

n-ary operations100,000
Pairwise comparisons4,999,950,000
Pairwise distance matrix (float64)40 GB
Too big for a laptop

MDANCE does 50,000× less work at this size.

Benchmarks

Analyze your MD trajectories today, not tomorrow.

On the same 75,000-frame trajectory, HELM finishes in about 2 minutes. Classic hierarchical clustering (HAC) needs 29 hours. Press play to watch the race.

Elapsed (simulated) 00:00:00
HELMMDANCE · 75,000 frames
2 min
Classic HACpairwise · 75,000 frames48× speed
29 h

Source: HELM paper, J. Chem. Inf. Model. 2025. Same 75,000-frame trajectory for both methods; the clock is sped up.

The toolkit

Eight algorithms. One linear-time framework.

Every method shares the same n-ary similarity core, so each one is O(N), deterministic, and avoids pairwise matrices.

O(N)

NANI

k-means initialization

Deterministic k-means seeding that finds metastable states the first time.

  • Picks diverse centroids from high-density regions
  • Same cluster populations across replicates
Best for: Simple Analysis
O(N)

HELM

Hybrid hierarchical

The speed of k-means with the flexibility of a full hierarchy.

  • No pairwise distance matrix
  • Any number of partitions from one run
  • 75,000 frames in ~2 min (classic HAC: 29 h)
Best for: High Resolution
O(N)

DIVINE

Divisive hierarchical

Top-down splitting that explores every resolution in a single pass.

  • NANI-anchored, fully deterministic
  • Weighted-variance split criterion
  • Matches or beats bisecting k-means, faster
Best for: Fast Hierarchy
O(N)

mdBIRCH

Online clustering

Cluster frames as they stream in, with merge tests calibrated to RMSD.

  • Physically interpretable RMSD threshold
  • Near-linear scaling with frame count
  • Hundreds of thousands of frames on one core, in seconds
Best for: On-the-fly Analysis, Huge Trajectories
O(N)

SHINE

Pathway clustering

Find the dominant transition pathways hiding in enhanced-sampling runs.

  • Picks the most representative pathway per class
  • Cheaper than Fréchet-distance approaches
  • Validated on alanine dipeptide & adenylate kinase
Best for: Pathway Exploration
O(N)

PRISM

Pathway representation

Summarize each pathway by its structural medoids, then compare them all.

  • Compact medoid fingerprint per pathway
  • Weighted average Hausdorff distance
  • Three medoid-construction strategies
Best for: Multi-pathway comparison
O(N)

eQual

Flat clustering

Radial threshold clustering, rebuilt to run in linear time.

  • O(N²) RTC → O(N)
  • No memory-hungry RMSD matrices
  • Compact, well-separated clusters
Best for: Radial Clustering
O(N)

PRIME

Native structure prediction

Retrieve the native fold from your ensemble, within 2 Å of experiment.

  • Mapped every structural motif in benchmarks
  • Consistently within 2 Å RMSD of experiment
  • Works as post-processing on any clustering
Best for: Structure Selection
Built for you

Whoever runs your trajectories, MDANCE fits in.

Computational chemists

Drop the N×N RMSD matrix. Cluster full-length trajectories on a laptop or a single node, with results you can reproduce.

Structural biologists

Go from simulations to biology: dominant transition pathways, metastable states, and native structures that match experiment.

Pharma & industry

Screen conformational ensembles at scale. Linear cost and deterministic output fit production pipelines and audits.

Students & newcomers

Learn modern MD analysis with step-by-step tutorials and notebooks.

Start with NANI →
Quick start

From pip install to clusters in 60 seconds.

  1. 01

    Install from PyPI

    One command. Pure Python, built on NumPy, scikit-learn and MDAnalysis.

  2. 02

    Load your trajectory

    Read AMBER, GROMACS or CHARMM output through MDAnalysis, or bring a NumPy array.

  3. 03

    Pick an algorithm

    Start with NANI, then go further with HELM, DIVINE, SHINE or PRIME.

pip install mdance

# verify
python -c "import mdance; print(mdance.__version__)"
import numpy as np
from sklearn.cluster import KMeans
from mdance import data
from mdance.cluster.nani import KmeansNANI

# Example trajectory: 6,001 frames x 50 backbone atoms
X = np.load(data.sim_traj_numpy)

# Deterministic NANI seeding: no random starts
nani = KmeansNANI(data=X, n_clusters=6, metric='MSD',
                  N_atoms=50, init_type='strat_reduced',
                  percentage=10)
centroids = nani.initiate_kmeans()

# k-means from NANI's seeds: same labels every run
labels = KMeans(n_clusters=6, init=centroids,
                n_init=1).fit(X).labels_
Peer reviewed

References

Each algorithm in MDANCE is described and validated in its own paper.

Using MDANCE? Please cite us.

@article{chen_k-means_2024,
  title   = {k-Means NANI: An Improved Clustering Algorithm for Molecular Dynamics Simulations},
  author  = {Chen, Lexin and Roe, Daniel R. and Kochert, Matthew and Simmerling, Carlos and Miranda-Quintana, Ram{\'o}n Alain},
  journal = {Journal of Chemical Theory and Computation},
  year    = {2024},
  doi     = {10.1021/acs.jctc.4c00308},
}

Also cite the paper for each algorithm you use.

  1. 2026 PRISM Digital Discovery
  2. 2026 mdBIRCH J. Chem. Theory Comput.
  3. 2026 NANI J. Chem. Inf. Model.
  4. 2026 DIVINE J. Chem. Inf. Model.
  5. 2025 HELM J. Chem. Inf. Model.
  6. 2025 SHINE J. Chem. Inf. Model.
  7. 2025 eQual J. Chem. Inf. Model.
  8. 2024 PRIME J. Chem. Theory Comput.
  9. 2024 NANI J. Chem. Theory Comput.

Your next trajectory deserves better clustering.

Free, open source, and one command away.

$ pip install mdance
Read the docs →

Have a hard dataset or a research idea? Open an issue or reach out to collaborate.