Juliacon 2024

Molly.jl: Molecular dynamics in Julia
07-12, 11:00–11:30 (Europe/Amsterdam), REPL (2, main stage)

Much of science can be explained by the movement and interaction of molecules. Molecular dynamics (MD) is a computational technique used to explore these phenomena, from noble gases to biological macromolecules. Molly.jl is a pure Julia package for MD, and for the simulation of physical systems more broadly. This talk will introduce Molly.jl and its features, which include a flexible interface for custom interactions and support for differentiable simulations.


Molecular dynamics (MD) is the physical simulation of a molecular system using Newton's equations of motion. It can be used to gain mechanistic insight into experiments and to make predictions. There are a variety of mature, widely-used packaged for MD including Gromacs, NAMD, LAMMPS and OpenMM. Due to the performance requirements of MD, however, these all consist of an interface layer and fast code running under the hood in one or more low-level languages.

Julia presents an opportunity to write a MD package in the same language all the way down, making it easier to interact with and extend. Molly.jl, which has grown steadily since its inception in 2018, is such a package. It has had 13 non-trivial contributors and has been the focus of 3 Summer of Code projects. This talk will introduce Molly.jl including its features, its unique selling points, and the challenges of competing with mature software whilst allowing differentiability.

Implemented features include classical biomolecular force field potentials, various integrators and thermostats, Monte Carlo simulation, enhanced sampling methods, support for different boundary types, and some analysis functions. The package is designed to be modular and extensible, with user-implemented potentials and simulators being as fast as the built-in versions. There is support for different precision and custom number types; for example, the recommended approach is to use Unitful.jl to ensure that all quantities have compatible units. The flexible logging interface allows user-defined properties to be recorded during a simulation, and there is simple functionality to animate trajectories using GLMakie.jl. Molly.jl is part of the JuliaMolSim ecosystem and is compatible with the AtomsBase.jl interface, allowing interoperability with packages such as ACEpotentials.jl and DFTK.jl.

The emerging research field of differentiable molecular simulation (DMS) uses automatic differentiation, the technique usually used to train neural networks, to improve the force fields used in MD. DMS can also be used to train neural networks. It usually requires specialist MD software such as Jax MD or TorchMD. Molly.jl allows fast differentiable simulations of biomolecules on multi-threaded CPU and GPU by making use of Zygote.jl and Enzyme.jl. The ability to take gradients through GPU kernels written in a high-level language with CUDA.jl is a unique feature of Julia.

To date Molly.jl has been used in research to improve biomolecular force fields with differentiable simulation and to compute transport coefficients. It is starting to attract users from the materials modelling and machine learning potential communities due to its flexibility and ease of use within the wider Julia package ecosystem. Future developments including bond and angle constraints, Ewald summation methods, better system setup and faster GPU performance aim to make Molly.jl a widely useful package for biomolecular simulation.

See also:

I am a group leader at the MRC Laboratory of Molecular Biology working on improving molecular simulations. Previously I was a research fellow (postdoc) in the Bioinformatics Group at University College London (UCL) and a PhD student in the Structural Bioinformatics Group at Imperial College London.

My interests include molecular simulation, protein structures, software development and open science. Currently my work aims to use the concept of differentiable programming to improve the force fields used to simulate proteins, enabling us to better study disordered proteins and protein aggregation.