MDsquadby Titus Adrian Beu · Open teaching resource
Molecular dynamics, made accessible
MD has matured into one of the most reliable computational tools in research — and, as the models and methods have piled up, into one that risks remaining the preserve of initiates. MDsquad is a concept and a software repository for teaching it at graduate and post-graduate level, built on unifying data structures across Python and C/C++.
Python builds the initial configurations and post-analyses the trajectories. C/C++ builds a suite of simulators that mimic an established MD code, in a sequence of gradually growing complexity — so coding ability is acquired in parallel with the skill of operating a real simulator.
Python
C/C++
NAMD · PDB · PSF · PAR · DCD
8 chapters available
Created by Titus Adrian Beu, Faculty of Physics, Babeș-Bolyai University — [email protected]
The course
Eight chapters, each with its own code
Every chapter is a PDF and a matching bundle of programs. Fundamental aspects — molecular models, force fields, time propagation, thermodynamic reservoirs, electrostatics in periodic systems and acceleration techniques — are given particular emphasis, and test runs are compared against output from established MD codes.
Chapter 01Introduction to MD simulationsWhat molecular dynamics does, where it is reliable, and how the pieces of a simulation fit together.Read the chapter (PDF) →
Chapter 02Molecular structureBuilding configurations from scratch: clusters, crystals, C60, graphene, nanotubes, DNA, water boxes and solvation.Read the chapter (PDF) →
Chapter 03Basic Molecular DynamicsThe first simulator — Lennard-Jones forces, time propagation and velocity rescaling, written from the ground up.Read the chapter (PDF) →
Chapter 04Simulation of simple fluidsExtending the simulator to fluids, and comparing the results against output from an established MD code.Read the chapter (PDF) →
Chapter 05MeasurementsGetting numbers out of a trajectory: time averages, velocity distributions, the H-Boltzmann function, radial distribution and diffusion coefficients.Read the chapter (PDF) →
Chapter 06Force fieldsBonded and non-bonded terms, and the pair-list optimisation that makes larger systems tractable.Read the chapter (PDF) →
Chapter 07Electrostatics in periodic systemsLong-range Coulomb interactions under periodic boundary conditions.Read the chapter (PDF) →
Chapter 08Simulations with NAMDOperating an established MD code, and reading its input and output with the same Python library.Read the chapter (PDF) →
Under construction. Five further chapters are in preparation: Special numerical techniques, Parallelization, Parameterizing force fields, Rigid-body dynamics and vibrational analysis.
The Python side
MDsquad.py — setting up and looking at systems
One library builds the configurations that go into a run and analyses the trajectories that come out. The numerical and graphical routines it relies on are those of Introduction to Numerical Programming.
AtomMasses.py
Atomic masses and atomic numbers.
AtomMass · AtomMasses
AtomMass · AtomMasses
Constants.py
Basic units and conversion factors.
CoordTrans0.py / CoordTrans.py
Coordinate transformations for atom sets — bounding boxes, centre of mass, radius of gyration, principal axes and rotations. The 0 version is the tutorial one.
GetBBox · GetCM · MoveCM · MoveRel · Center · RadiusGyration · PrincipalAxes · Rotate · RotMatEuler · RotMatAxis · RotMatVec · RotMatVec2Vec · CircleCenter · AlignAtoms2Axes
GetBBox · GetCM · MoveCM · MoveRel · Center · RadiusGyration · PrincipalAxes · Rotate · RotMatEuler · RotMatAxis · RotMatVec · RotMatVec2Vec · CircleCenter · AlignAtoms2Axes
DataInOut0.py / DataInOut.py
Input/output from and to NAMD and Gromacs files. The tutorial version handles PDB alone; the full version adds PSF, CHARMM parameter files, DCD trajectories and the Gromacs formats.
ReadPDB · WritePDB · GetSetNumPDB · SeekSetPDB · ReadSetPDB · ReadPSF · WritePSF · ReadPar · WritePar · ReadParFF · WriteParFF
ReadPDB · WritePDB · GetSetNumPDB · SeekSetPDB · ReadSetPDB · ReadPSF · WritePSF · ReadPar · WritePar · ReadParFF · WriteParFF
DataTypes0.py / DataTypes.py
The core classes shared by every program.
Atom · Bond · Angle · Dihedral · Residue · Pair · IntCoord · BeadType
Atom · Bond · Angle · Dihedral · Residue · Pair · IntCoord · BeadType
GetBonded.py
Identifying and measuring bonds, angles and dihedrals.
Measure.py
Trajectory analysis — radial distribution function, radius of gyration, diffusion coefficient.
Residues.py
Residue identification and selection.
SelectAtoms.py
Atom selection by expression, in the style of an established MD front end.
SetupConfig.py
Configuration builders — crystals, graphene, nanotubes, water boxes and solvation.
VecMatR0.py / VecMatR3.py
Vector and matrix operations in R³.
The C/C++ side
Four simulators, each one a step further
Rather than one finished program, a sequence — each version adding the theory introduced in its chapter, so nothing arrives as a black box.
01
MDsim0
Chapter 3The starting point: a Lennard-Jones simulator with its own data types, memory allocation, force routine, propagator and velocity rescaling. Reads mdsim.dat, .pdb, .psf and .par; writes a trajectory and a statistics file.
02
MDsim1
Chapter 4The same engine extended to simple fluids, with results checked against an established MD code.
03
MDsim2
Chapter 6Force fields and the pair-list optimisation, added as PairList0.h — the first step towards a simulator that scales.
04
MDsim3
Chapter 7Electrostatics under periodic boundary conditions, for charged systems.
The programs
List of programs by chapter
What each chapter’s bundle contains: the Python scripts and C/C++ sources, the input files they read, and what they produce. Click any result to see it full size.
Chapter 2 · Molecular structure
p02.zipChapter 3 · Basic Molecular Dynamics
p03.zipChapter 4 · Simulating simple fluids
p04.zipChapter 5 · Measurements
p05.zipChapter 6 · Force fields
p06.zipChapter 7 · Electrostatics in periodic systems
p07.zipOpen teaching resource. MDsquad is made available for study, teaching and research, with the request that the authorship is mentioned. It is a learning repository, not a production MD package — for production work it points you at an established code, and shows you how to check one against the other.




































