Skip to content

Quick start

This walks through a complete analysis of a mixture of two species, malic acid (residue name MAL) and 2-methylerythritol (MOL), simulated with GROMACS.

1. What you need

  • A topology with residue names and masses, and preferably partial charges and bonds: a GROMACS .tpr, a CHARMM/NAMD .psf or a LAMMPS DATA file (atom_style full) has them all. A .gro or .pdb has neither: cm rules and the clusters' geometry work, but their charge and dipole moment are left empty and hb rules can't run. The residues must be numbered 1 to N in topology order (see Troubleshooting).
  • A trajectory MDAnalysis can read (.xtc, .trr, .dcd, a LAMMPS dump, ...), with the box, so distances respect periodic boundary conditions.
  • A configuration file saying which molecules connect to which.

2. Write the configuration

Save this as config.yml:

rules:            # which residue pairs connect, and how
  MAL:
    MAL: hb d 3.5 a 120   # hydrogen bond: donor-acceptor <= 3.5 Å, D-H-A angle >= 120°
    MOL: cm 6.0           # centers of mass closer than 6 Å
  MOL:
    MOL: cm 6.0

solute: [MAL]      # the species of interest
nucleus: [solute]  # nuclei: connected groups of solutes inside each cluster
follow: [solute]   # one coordinate file per solute molecule

solvent isn't given, so every residue name in rules that isn't a solute (here MOL) is the solvent. Every key is described in Configuration.

3. Run it

molclusters traj.trr topol.tpr config.yml --output-dir results

The terminal shows what was understood before the run starts, a progress bar, and a summary at the end:

15:16:44 | INFO     | System: 3600 atoms in 200 residues (100 MOL, 100 MAL)
15:16:44 | INFO     | Trajectory: 1042 frame(s) from 0 to 49968 ps, every 48 ps
15:16:44 | INFO     | Box (first frame): 324.60 x 324.60 x 324.60 angstrom
15:16:44 | INFO     | Topology has no elements, guessing them from atom names
15:16:44 | INFO     | Effective configuration:
rules (distances in angstrom, angles in degrees):
  MAL - MAL: hb d 3.5 a 120.0 hmin 0.9 hmax 1.1 hq 0.3 aq -0.5
  MAL - MOL: cm 6.0
  MOL - MOL: cm 6.0
solute: MAL
solvent: MOL
nucleus: MAL
follow: solute (one solute-<resid>.gro per solute)
...
analyses: SizeEvolution, Lineage, SoluteSolvent, ClusterCoordinates, Nucleus, JsonReport
report_compression: zstd (molclusters.jsonl.zst)
15:16:44 | INFO     | Tracking clusters over 1042 frame(s)
100%|##########| 1042/1042 [01:37<00:00, 10.72it/s]
15:18:21 | INFO     | Connections per frame, by rule: MAL - MAL (hb ...) 42.8, MAL - MOL (cm 6.0) 37.6, MOL - MOL (cm 6.0) 13.0
15:18:21 | INFO     | [SizeEvolution] Found 22.9 cluster(s) per frame on average (0-37); the largest held 100 molecule(s).
15:18:21 | INFO     | [Lineage] Cluster lineage: 1766 cluster(s) formed of free molecules and 11640 split off others; ...
15:18:22 | INFO     | Results written to results: evo.txt, cluster_events.csv, cluster_lifetimes.csv, ...

Check the effective configuration

The Effective configuration block shows the rules with their defaults filled in, the solute keyword expanded and the analyses that will run. It is the quickest way to catch a misspelled residue name or a cutoff in the wrong unit. The Connections per frame, by rule line at the end tells you whether each rule actually connected anything.

4. Look at the results

The results folder now holds:

File Contents
evo.txt number of clusters and their minimum, average and maximum size, per frame
cluster_events.csv every formation, split, merge and dissolution
cluster_lifetimes.csv each cluster's birth, end, lifetime, origin and fate
solute_solvent.csv the clusters holding both solutes and solvents, averaged per frame
nucleus_data.csv the nuclei inside the clusters, averaged per frame
coordinates/*.gro the clusters holding solutes, made whole, as GROMACS coordinate files
molclusters.jsonl.zst every cluster of every frame, with its properties and connections
molclusters_<date>_<time>.log the log of the run (and a .json copy)

For instance, plotting the number of clusters and the size of the largest one over time, from evo.txt (with matplotlib, installed separately):

import numpy as np
import matplotlib.pyplot as plt

time, n_clusters, min_size, avg_size, max_size = np.loadtxt("results/evo.txt", unpack=True)

fig, (top, bottom) = plt.subplots(2, 1, sharex=True)
top.plot(time / 1000, n_clusters)
top.set_title("Number of clusters", loc="left")
bottom.plot(time / 1000, max_size, color="C1")
bottom.set_title("Largest cluster (molecules)", loc="left")
bottom.set_xlabel("Time (ns)")
plt.show()

Two panels over 50 ns, one point per frame (48 ps). The number of clusters rises from 0 to about 20 by 3 ns, reaches about 28 between 8 and 16 ns (37 at most), then settles near 23, mostly between 17 and 29. The largest cluster grows from 2 molecules to about 15 by 12 ns and to about 23 by 20 ns, peaks at 100 molecules at about 22 ns, and then fluctuates mostly between 14 and 58 molecules, averaging about 30. Two panels over 50 ns, one point per frame (48 ps). The number of clusters rises from 0 to about 20 by 3 ns, reaches about 28 between 8 and 16 ns (37 at most), then settles near 23, mostly between 17 and 29. The largest cluster grows from 2 molecules to about 15 by 12 ns and to about 23 by 20 ns, peaks at 100 molecules at about 22 ns, and then fluctuates mostly between 14 and 58 molecules, averaging about 30.

The two quantities are counts of different things (clusters, and molecules in one cluster), so each gets its own panel rather than sharing an axis.

Every cluster of every frame is in the report, which reads as one table:

from molclusters.report import read_report

clusters = read_report("results/molclusters.jsonl.zst").clusters()
print(clusters[["time", "id", "size", "radius", "density", "dipole_moment"]])
          time     id  size    radius   density  dipole_moment
0         48.0      1     2  4.939751  0.888761       4.150092
1         48.0      2     2  4.975403  0.869793       3.345977
2         96.0      3     2  5.362132  0.694845       4.776185
3        144.0      4     3  5.867330  0.789490       2.908561
4        144.0      5     2  5.636959  0.593530       2.679938
...        ...    ...   ...       ...       ...            ...
23873  49968.0  13402     2  4.654313  1.054412       8.852622
23874  49968.0  13403     2  5.586917  0.609622      12.104313
23875  49968.0  13404     2  4.888511  0.917003       5.546337
23876  49968.0  13405     2  5.190601  0.766033       7.929750
23877  49968.0  13406     2  5.359340  0.695932       3.543585

[23878 rows x 6 columns]

Where to go next: