MAFIA-MD: finding rings and fringes in reactive molecular dynamics
Reactive simulations of hydrocarbons produce thousands of atoms that bond, break and rearrange. MAFIA-MD reads the small trajectory files and reports which rings formed, which molecules exist, and how their layers stack, without the huge bond files.
A reactive molecular dynamics simulation of a hydrocarbon flame is a crowd of atoms that bond, break apart and bond again. The interesting question is what they build. Do the carbon atoms close into rings? Are those rings aromatic, the flat and stable kind that soot is made of? Do the rings stack into layers, like the fringes seen in electron-microscope images of real soot?
MAFIA-MD, short for Molecular Arrangement and Fringe Identification and Analysis from Molecular Dynamics, answers those questions from the simulation’s trajectory files alone. I developed it during my Ph.D. at Marquette University, and the paper describing it, with Dr. Somesh Roy and Dr. Eirini Goudeli, is published in Computer Physics Communications.
The bond file is the big one
Reactive simulation codes write two kinds of output. Trajectory files (.xyz) hold the position of every atom at each saved moment. Bond files record which atoms are bonded, and how strongly. For chemistry you want the bonds, but bond files grow fast. In one example from the paper, 0.1 nanoseconds of acetylene combustion with 6,000 atoms at 1500 K produced a bond file of about 5 GB, against a trajectory file of about 300 MB. In a fast-reacting system you also need to save often, so the difference adds up.
MAFIA-MD works from the small files. It rebuilds the connections it needs from the atom positions, then looks for structure.
What it tells you
- Rings: the number of 5-, 6- and 7-membered carbon rings, the C/H ratio, and the share of carbon atoms in rings (alicyclic or aromatic) against those in chains (aliphatic).
- Molecules: every molecule in the box as a SMILES string or an SDF file, ready for other chemistry tools. Bond orders come from a modified version of xyz2mol with RDKit, and they are what tells the aromatic rings apart from the rest.
- Fringes: a histogram and a smooth distribution of the spacing between stacked ring layers, for direct comparison with high-resolution transmission electron microscopy (HRTEM) of soot.
It processes a whole folder of snapshots in one run, through a small graphical interface.
How it works
The core idea is to treat the carbon atoms as a network. Two carbon atoms count as bonded when their distance falls inside a window, 1.2 to 1.8 Å by default. A window rather than a single bond length, because atoms vibrate in a simulation. That turns a list of coordinates into a graph, and finding rings becomes finding closed loops in the graph. MAFIA-MD builds the graph with NetworkX and uses Johnson’s algorithm, a depth-first search that lists every elementary cycle, keeping the 5-, 6- and 7-membered ones that matter for soot.
The catch is cost. In a dense cluster the number of possible loops explodes, so the box is cut into smaller pieces that are searched one at a time. Cut carelessly, and every ring that straddles a boundary is lost. MAFIA-MD makes the pieces overlap by at least the width of the largest ring; an 8 Å span catches rings of up to seven members. A ring that shows up in two overlapping pieces is recognized by its atom indices and counted once.

A Sanity Check mode searches the whole box without splitting it. It works as a built-in cross-check, and as the simpler option for small systems, up to roughly 700 carbon atoms depending on how connected they are.
For fringes, each ring gets a center and a direction perpendicular to its plane. Two rings form a fringe when their centers are 3 to 6 Å apart and their planes are parallel to within 10°. The spacings go into a histogram, and a Gaussian kernel density estimate gives the smooth curve.
Does it count correctly?
The code ships with test files where the answer is known. Two were built by hand with a set number of rings: one with 58 carbon atoms (4 five-, 8 six- and 1 seven-membered ring) and one with 110 (5, 7 and 2). The third is a 760-atom snapshot from a real simulation, with its rings counted by hand (14, 20 and 6). MAFIA-MD found exactly those counts in all three, with and without splitting the box.

It is quick on ordinary hardware. On a laptop with a 2.3 GHz Core i5, ring detection took 0.2 seconds for the smallest test file and about 5 seconds for a 1,769-atom cluster. About two-thirds of the run time goes into the loop search, which depends on how interconnected the carbon network is, so very dense clusters can take much longer: from seconds to a few hours per file. The run times for the test files, from the paper:
| File | Atoms | Ring detection | Chemical analysis | Fringe spacing |
|---|---|---|---|---|
| fabricated.xyz | 58 C, 96 H | 0.21 s | 0.02 s | – |
| fabricated2.xyz | 110 C, 190 H | 0.25 s | 0.03 s | – |
| realmd.xyz | 559 C, 201 H | 1.61 s | 0.09 s | – |
| 1769atoms.xyz | 1,256 C, 513 H | 5.02 s | 1.57 s | 1.09 s |
Fringes in a soot-like cluster
In the microscope, fringes are the dark, line-like patterns that the internal structure of a soot particle produces in high-resolution TEM images. They are described by their length, their spacing and their tortuosity (how much they curve), and each says something about how reactive the soot is. Short fringes have more free edges, where the reactive atoms sit. Widely spaced ones leave room for oxygen to get in. Strongly curved ones are strained and break more easily. MAFIA-MD measures the spacing in a simulation, so it can be compared directly with images of real soot.

The second example is that 1,769-atom cluster, with 1,256 carbon atoms. MAFIA-MD found 103 six-, 42 five- and 54 seven-membered rings, with about 59% of the carbon in rings, and then measured the spacing between parallel pairs of rings.

The statistics only mean something when the cluster is large enough to hold many fringes, so this mode is for particles rather than single molecules.
Limits
- Carbon and hydrogen only for now. Nitrogen, oxygen and sulfur are planned.
- Rings of five to seven carbons. The framework for larger and nested rings is in the code but not switched on.
- Serial. The pieces of the box are independent of each other, so the loop search can be parallelized; that is the next step.
- Fringe statistics need large clusters, as above.
Get it
MAFIA-MD is open source under the MIT license. The code is on GitHub, and the published version is archived in the CPC Program Library. It runs on Windows, macOS and Linux with conda:
git clone https://github.com/comp-comb/MAFIA-MD.git
cd MAFIA-MD
make # Linux and macOS (Windows: conda env create -f requirements.yml -p MAFIAMD)
conda activate ./MAFIAMD
python mafiamd.py # opens the interface
If MAFIA-MD helps your work, please cite the paper: K. M. Mukut, S. Roy and E. Goudeli, “Molecular arrangement and fringe identification and analysis from molecular dynamics (MAFIA-MD),” Computer Physics Communications 276, 108325 (2022), doi:10.1016/j.cpc.2022.108325. The BibTeX entry is on the Publications page.