In this lecture, I will introduce molecular dynamics (MD) as one of the flagship computational techniques for the sampling of important statistical mechanics ensembles, such as the microcanonical (constant energy) and the canonical (constant temperature) ensembles. Merits and limits of MD, together with some warnings, will be discussed, with a particular attention to the so-called ab initio (Born-Oppenheimer) MD,
i.e., where forces acting on the nuclei (as classical point particles) are computed from (ground-state) electronic-structure calculations that are performed “on the fly” as the MD trajectory is generated. I will also introduce basic techniques for the computation of
free-energy differences, that (can) use MD as sampling tool: thermodynamic integration, thermodynamic perturbation, and histogram reweighting.