MolSimWorkbench#
Prepared by Salman Bin Kashif as part of the US-RSE Mentorship Program, with mentorship from Chris Neely, and with the help of an AI assistant (see the AI usage statement).
Molecular simulations have become a routine part of materials discovery. However, they are often used as a black box. Without knowing what the critical parts of the engine do, users cannot be sure what a run has actually given them. Understanding those parts means reading and writing code, and programming has its own problem: it is hard to learn without something real to build.
This website teaches both at once. You take apart a small but real simulation engine piece by piece, and learn the C++ it is written in along the way. I chose C++ because I wanted to learn it myself; a Python version for a broader audience is coming soon.
Learning approach: read, play, take apart and code your own
A brief text and figures, from the ground up.
Explore the settings in the built-in simulator.
Read the code, one part at a time.
Plug in your own energy function, integrator or thermostat.
Getting started#
We start with one of the simplest materials to simulate: argon, the liquid in pioneering work by Aneesur Rahman in 1964, the first molecular dynamics simulation of a realistic liquid. Argon can be modelled well with a simple equation called the Lennard-Jones potential, which treats each atom as a soft sphere with two settings: how big it is and how sticky it is.
A simulation of argon is a simple loop. It starts with a set of atoms at given positions. From the positions, the Lennard-Jones potential gives the potential energy. Differentiating the energy gives the force on each atom, and integrating the forces over a short time step gives the new positions. Repeating this many times gives a trajectory: how the atoms move over time.
The simulator below holds only 125 atoms, a nanoscale block of liquid argon; a beaker of the real liquid holds about 10²⁴. Yet 125 atoms are enough: one small region of a liquid looks much like any other, so the properties calculated from how these atoms move are the same ones measured on real liquid argon at the same temperature and density.
Press Liquid argon at 94.4 K to rerun Rahman’s liquid. The atoms start from a solid-like grid and settle into a liquid; the simulator then shows two values, compared against those Rahman published.
Reading the Simulator panel#
The lines that scroll past are the engine reporting on each step of the run. You can ignore the energies for now: the next page explains them. A table appears when the run ends, showing two measurements. They wobble while the run is short, then stay close to one value:
Nearest neighbours: the distance at which atoms most often sit next to each other.
Diffusion constant: how quickly atoms wander away from where they were. The larger it is, the faster they spread.
Rahman checked both against experiment: the arrangement of neighbours with X-ray scattering on liquid argon, and the diffusion with measured values. So the table checks your run against his, and through him against real argon.
What to look for#
Now play with the parameter space: change the temperature and density, or invent a material of your own by changing the size and stickiness of its atoms. Try these six experiments in order.
Change the temperature#
1. Heat a liquid. Press Liquid argon at 94.4 K. Then set How hot to 300 K and press Run custom. Watch the Visualization panel, and read the last row of the table in the Simulator panel. Will the atoms spread apart as they heat up?
What happens
No. They stay just as crowded, but they move faster: the diffusion constant rises about four times.
They cannot spread apart because the simulation keeps the number of atoms, the size of the box and the temperature fixed, the conditions known as the NVT ensemble. It is like heating liquid argon in a sealed, rigid container: the atoms have nowhere to go, so the density stays the same however hot it gets. In an open container they could leave, and argon would boil away at 87 K, long before 300 K. A real sealed container would need to hold an enormous pressure to keep argon this crowded at 300 K.
Change the density#
2. Give the atoms room. Keep How hot at 300 K, set How crowded to 0.17 g/cm³ and run it. What do the atoms do with the extra space?
What happens
They spread out and become a gas. Liquid and gas are names for what atoms do, so what you see is what tells them apart:
Run |
How hot |
How crowded |
What the atoms do |
Diffusion constant (× 10⁻⁵ cm²/s) |
|---|---|---|---|---|
Liquid argon at 94.4 K |
94.4 K |
1.374 g/cm³ |
Stay packed together and jostle past each other |
About 2 |
Experiment 1 |
300 K |
1.36 g/cm³ |
Stay packed together and move faster |
About 10 |
This run |
300 K |
0.17 g/cm³ |
Stay far apart and fly across the box |
About 90 |
In a liquid, the atoms push past each other, which is what lets a liquid flow. In a gas, they rarely meet, which is why a gas spreads to fill its container and can be squeezed.
3. Condense a gas. With How crowded still at 0.17 g/cm³, set How hot to 96 K and run it, then again at 36 K. Where do the atoms go as the gas cools?
What happens
They stop filling the box evenly. By 36 K they have gathered into clumps with empty space between them, and the diffusion constant has fallen from about 90 × 10⁻⁵ to about 5 × 10⁻⁵ cm²/s, because an atom in a clump cannot wander far. The attraction between the atoms was always there; the hot atoms simply moved too fast to stay together. A real gas starts to condense the same way.
Change the material#
4. Change the stickiness. With How crowded still at 0.17 g/cm³, set How hot to 120 K. Run it with How sticky at 60 K, then at 360 K. At the same temperature, which material is a gas?
What happens
The less sticky one. At 60 K the atoms spread through the box; at 360 K they clump, and the diffusion constant is about six times smaller. Stickier atoms need more heat to pull apart, so the material boils at a higher temperature. Real materials show the same thing: the attraction between krypton atoms is about five times that between neon atoms, and krypton boils at −153 °C, where neon boils at −246 °C.
5. Heat against stickiness. Press Reset, then Run custom. Now set How hot to 240 K and How sticky to 240 K, and run again. This material is hotter, but also stickier. Which effect wins?
What happens
Neither. The atoms make the same pattern in both runs, and only move a little faster in the second. What decides the state is the heat compared with the stickiness, not either one alone.
6. Size against space. Press Reset, set How big to 4.76 Å and run it. Press Reset again, set How crowded to 1.38 g/cm³ and run it. Bigger atoms, or the same atoms in a smaller box: which is more crowded?
What happens
They come out the same: a crowded liquid, with a diffusion constant of about 3 to 4 × 10⁻⁵ cm²/s in both. The box looks smaller in the second run, but the atoms fill the same share of it. What decides the state is the size of the atoms compared with the space they have.
So two contests decide what a material does: heat against stickiness, and atom size against space. Change either balance, and you change whether it is a liquid or a gas.
Behind sim.run()#
The last line of the script hands control to the C++ engine, which runs the loop of every molecular dynamics simulation: one turn per time step, thousands of turns per run. Here is that loop twice, as physics and as the code that does it. Each call leads to the one below it (small helpers in between are left out), and the highlighted part is the loop; click a call to see its code.
Physics
Programming
sim.run()
Python calls into C++ through the compiled module_molsim.MolecularDynamics::runSimulation()
One pass of the simulation loop per time step.VelocityVerletIntegrator::step()
Moves every atom by its velocity and force.ForceCalculator::calculateForcesAndEnergy()
Adds up the forces of every energy function.LJPotential::calculateForcesAndEnergy()
The energy function, here Lennard-Jones.ljComputeGather(view, backend, numThreads)
The loop over every pair of atoms, serial or on several threads.
Each part of the loop gets its own explanation on the simple molecular dynamics loop page, with the equation and the code behind it. Then you can code your own: a different system, a different integrator, a different energy function. For that, learn C++ programming.
History#
November 2026: A new section, agentic AI in a molecular simulation workflow, hands the decisions in training a machine learning interatomic potential to a language model. For the MD it uses OpenMM beside this simulator, because OpenMM can already run such a potential.
October 2026: Grown into a molecular simulation workflow, with a Python interface and settings files. It is built so that any part of a molecular simulation, such as the energy function, the integrator or the thermostat, can be swapped for a new one, so that a new concept can be learned by adding it. The first addition, density functional theory and ab initio MD, is still a work in progress.
April 2025: Rewritten in C++, as an application for learning basic C++ (repository).
March 2018: The code started as a class project, a Lennard-Jones simulation in Python for a course on multiscale modelling at Clemson University, taught by Sapna Sarupria (repository).
AI usage statement
The simulation engine powering the interactive sliders and examples on this website was built by repurposing my own Python code from a class project. Turning that code into the engine, and then into this interactive website, relied heavily on an AI assistant, Claude (by Anthropic). However, both the code and the pages were revised substantially after the AI’s first drafts, as the commit history shows.
My aim in building this simulator and website is to learn new skills from the ground up, hands-on, by building applications related to my field. My own research projects have had little room for new and advanced concepts, such as agentic workflows, at the rigor needed for publication. So I built this workbench to learn such concepts hands-on, and used AI heavily to reduce the logistical friction: first to build working end-to-end applications, then to learn the basics interactively, and to write the webpages. I read the code and the pages, had the assistant quiz me on them (some of those questions became the “Check yourself” sections), and revised the pages several times until they matched my own understanding, presentation style and language.
What you read here is my own understanding, written down with AI help. I have read most of it and revised it more than once, but not all of it has been vetted line by line: some pages, including those marked Draft, have not had that careful check yet. Before release, every page was also checked against the engine’s code by AI reviewers, and the errors they found were fixed, but that is not a substitute for a careful human read. So the pages may still contain mistakes. If you find one, please open an issue on the repository.