mdapy (Molecular Dynamics Analysis in Python) is a fast, full-featured Python library for analyzing Molecular Dynamics (MD) simulation data β from structural characterization and machine-learning potential workflows to built-in ray-tracing visualization, all in a clean Pythonic API.
pip install mdapy
Why mdapy?ΒΆ
β‘ |
Blazing Fast |
C++ core (via Nanobind) with full OpenMP parallelism. Analyses that take minutes elsewhere finish in seconds. |
π |
Pythonic by Design |
One-liner analyses. All data lives in a Polars DataFrame and interops natively with NumPy. |
πͺΆ |
Minimal Dependencies |
The core package depends only on NumPy and Polars, keeping installation lightweight and easy to reproduce across environments. |
π |
Truly Cross-Platform |
Pre-built wheels for Windows, Linux, and macOS (including Apple Silicon). No compiler needed for standard installs. |
π¨ |
Built-in Ray-Tracing |
Tachyon-powered CPU and GPU (NVIDIA OptiX) renderer baked right in β no third-party renderer required. |
π€ |
Ecosystem Friendly |
First-class interop with OVITO, ASE, freud, phonopy, LAMMPS and GPUMD. |
π |
Thoroughly Documented |
Full API reference, tutorials, and Jupyter notebooks on ReadTheDocs. |
π |
Actively Maintained |
Regular releases, responsive issue tracker, and a growing feature set. |
Feature OverviewΒΆ
Neighbor SearchΒΆ
Fixed-radius cutoff |
Efficient cell-list algorithm |
k-Nearest neighbors |
Exact kNN via kd-tree |
Voronoi neighbors |
Topology-based, powered by Voro++ |
Structural AnalysisΒΆ
Structure identification β Polyhedral Template Matching (PTM), Common Neighbor Analysis (CNA), Ackland-Jones Analysis, Common Neighbor Parameter, Identify Diamond Structure
Defect characterization β Centro-Symmetry Parameter (CSP), Identify FCC Planar Faults (ISF / TB / ESF), Atomic Strain, Wigner-Seitz defect analysis
Order parameters β Steinhardt Bond Orientation (qββ¦qββ, averaged), Structure Entropy, Warren-Cowley SRO parameter
Distributions β Radial Distribution Function, Structure Factor (total + partial + X-ray weighted), Angular Distribution Function, Bond Analysis
Model BuildingΒΆ
Single-crystal lattices (FCC, BCC, HCP, diamond, and more)
Large-scale polycrystalline structures via Voronoi tessellation
High-entropy alloy (HEA) configurations
Machine-Learning Potential WorkflowsΒΆ
NEP / qNEP potential evaluation (energy, forces, stress, virials)
ASE-compatible
NEP4ASEcalculatorElastic constant tensor calculation
Equation-of-state (EOS) fitting
Stacking-fault energy curves
Phonon dispersion via phonopy
Dataset extraction, PCA, FPS, display Train/Thermo results, etc.
VisualizationΒΆ
TachyonRender β CPU or NVIDIA OptiX GPU ray-tracing, renders any
Systemto a PNG/JPEG with one method callPer-element colors and radii, transparent background, anti-aliasing, ambient occlusion, shadows β all configurable
UtilitiesΒΆ
EAM potential generation and averaging
Mean Squared Displacement (FFT-accelerated or direct)
Lindemann parameter, Void analysis, Cluster analysis
Spatial binning (multi-dimensional)
Atomic temperature averaging
Parallel
.gzcompressionMulti-frame XYZ trajectory reader / splitter
InstallationΒΆ
pip install mdapy
Pre-built wheels cover Windows / Linux / macOS (Apple Silicon included). For optional extras, source builds, GPU-renderer details, and interoperability notes with PyTorch / OVITO / freud / scikit-learn, see the full Installation guide.
Verify:
python -c "import mdapy as mp; print('mdapy', mp.__version__, 'β ready!')"
Quick ExamplesΒΆ
Load & analyse in three lines:
import mdapy as mp
sys = mp.System("fcc.dump")
sys.cal_polyhedral_template_matching() # adds 'ptm' column
sys.cal_centro_symmetry_parameter(N=12) # CSP for FCC
print(sys.data) # Polars DataFrame
Radial distribution function:
rdf = sys.cal_radial_distribution_function(rc=6.0)
rdf.plot() # matplotlib figure β one line
Machine-learning potential workflow:
from mdapy import get_elastic_constant
calc = mp.NEP('nep.txt')
C = get_elastic_constant(sys, calc)
C.print() # 6Γ6 elastic tensor in GPa
Ray-tracing render:
from mdapy.render import TachyonRender
ren = TachyonRender(backend="auto") # GPU if available, else CPU
ren.render_system(sys, width=1920, height=1080,
output_figure="structure.png")
Build a polycrystal:
unit = mp.build_crystal("Al", "fcc", 4.05)
poly = mp.CreatePolycrystal(unit, box=100, seed_number=10, metal_overlap_dis=2.0)
system = poly.compute()
system.write_xyz("polycrystal.xyz")
Supported File FormatsΒΆ
Format |
Read / Write |
|---|---|
LAMMPS DUMP |
β / β |
LAMMPS DATA |
β / β |
VASP POSCAR/CONTCAR |
β / β |
XYZ (extended) |
β / β |
MP (mdapy native) |
β / β |
ASE Atoms |
β (import / export) |
OVITO DataCollection |
β (import / export) |
Documentation & ResourcesΒΆ
π Full documentation |
|
π Source code |
|
π Issue tracker |
DependenciesΒΆ
Required:
Optional:
matplotlibβ plotting (pip install mdapy[plot])k3dβ interactive 3-D notebook viewer (pip install mdapy[k3d])pyfftwβ faster FFT for MSD calculationsphonopyβ phonon dispersionlammpsβ LAMMPS-based potential calculations
Running the TestsΒΆ
pip install pytest
pip install .
cd tests && pytest -q
CitationΒΆ
If mdapy contributes to a scientific publication, please cite:
@article{mdapy2023,
title = {mdapy: A flexible and efficient analysis software for
molecular dynamics simulations},
journal = {Computer Physics Communications},
pages = {108764},
year = {2023},
issn = {0010-4655},
doi = {10.1016/j.cpc.2023.108764},
url = {https://www.sciencedirect.com/science/article/pii/S0010465523001091},
author = {Yong-Chao Wu and Jian-Li Shao},
}
Version NoticeΒΆ
mdapy 1.0 is a ground-up rewrite with a new, cleaner API. The legacy release (β€ 0.11.5) is preserved on the mdapy_old branch.
ContributingΒΆ
Bug reports, feature requests, and pull requests are all very welcome! Please open an issue or submit a PR on GitHub.
LicenseΒΆ
BSD 3-Clause β see LICENSE for details.
ContactΒΆ
Issues / feature requests: https://github.com/mushroomfire/mdapy/issues
Email: 934313174@qq.com
If mdapy helps your research, a β on GitHub is always appreciated!