Molecular Dynamics Applet
[Trouble loading the applet? Check that Java is enabled in your security settings, or try
a different browser, or make sure you're on a real computer and not a mobile device. You may
need to download and install the Java plugin. If all else
fails, you can try this rudimentary HTML5 version, which doesn't use Java.]
This applet simulates the dynamics
of simple atoms and molecules in a two-dimensional
universe. The force between the molecules is weakly attractive at short distances,
but strongly repulsive when they touch. Use the applet to explore
phases of matter,
emergent behavior,
irreversibility,
and thermal effects at the
nanoscale.
The physics:
- The force between the atoms is calculated from the
Lennard-Jones formula
(truncated at a distance of 3 molecular diameters). This is a reasonably accurate model
of the interactions between
noble gas atoms.
- The simulation uses a natural system of units,
with the atomic diameter, the atomic mass, the depth of the Lennard-Jones
potential, and Boltzmann's constant
all set equal to 1. For argon (for example),
the unit of distance is 3.4 angstroms,
the unit of mass
is 40 atomic mass units,
and the unit of energy
is 0.01 electron-volts;
the corresponding unit of time is then 2.2
picoseconds, the unit of velocity is 160 meters per second,
and the unit of temperature is 120 kelvin.
The Molecular size scrollbar determines the scale of the image,
in screen pixels per unit of distance.
- The motion of the atoms is governed
by Newton's laws,
approximated using
the Verlet
algorithm with the indicated Time step. For sufficiently
small time steps, the system's total energy should be approximately conserved.
- Atoms drawn in light gray are artifically fixed in space, as if they
have infinite mass.
- Atoms can also be connected by a bond, drawn as a thin gray line, which creates an
attractive spring-like force
between them (in addition to the Lennard-Jones force). The spring constant is 5 in
natural units. Although this feature allows some interesting qualitative
demonstrations, it is not realistic: Actual covalent bonds are thousands of
times stiffer.
- The walls exert a linear (spring)
force on the molecules, with a spring constant of 50 in natural units.
- There's also an optional uniform downward force, controlled by the Gravity
scrollbar. The magnitude of this force, however, is not meant to be realistic.
Earth's gravitational constant is
utterly negligible in the units used here (a little over 10-13 for argon).
- That's all the physics! Everything else you see is a consequence of these
basic laws (applied repeatedly as the atoms move), plus the initial configuration
of the atoms. The simulation code knows nothing about phase transformations
or crystal structure or irreversibility.
The user interface:
- Press Start to start the simulation, or Step to step forward in
time by a small amount. The Animation speed scrollbar controls both the speed
of continuous running and the number of time steps in a "step".
- The Faster and Slower buttons increase and decrease the speeds of all
the atoms by 10%. Press them repeatedly for a greater effect, or hold the shift
key down for a smaller effect. The Freeze
button sets all the speeds to zero. Using
these buttons puts the system out of thermal equilibrium; it's fun to then watch it try
to equilibrate.
- Don't expect the Reverse button to accurately run the motion backwards for long;
the motion is almost always chaotic!
- The statistics displayed below the image are time, temperature, pressure,
total energy, kinetic energy, potential energy (from interactions between
atoms and interactions with the walls), and gravitational energy.
(The temperature is computed from the average kinetic energy, so it isn't accurate
when there's organized motion on a large scale.)
Use the Write stats button to save a record of these statistics
in a separate window.
The number of atoms and the volume (actually area) of the box are also written
for your convenience, along with the total momentum, angular momentum about the
center of mass, and moment of inertia about the center of mass.
The temperature and pressure are averaged over time; for accurate equilibrium data,
be sure to let the system
equilibrate, then press the Reset stats button, then wait for the temperature
and pressure to
stabilize before recording the data. You can copy and
paste from the statistics window into a spreadsheet for further analysis.
Try plotting energy vs. temperature and pressure vs. temperature.
- Be sure to explore the Presets. For some you'll want to adjust the animation
speed. (Thanks to John Mallinckrodt for
inspiring several of the presets.)
- Sometimes the simulation becomes unstable, producing a runaway effect of exponentially
increasing energy. This is a consequence of approximating the relations between
position, velocity, and acceleration using small differences instead of derivatives.
When Safety mode is checked, the computer will try to reduce the time step
as needed to keep the calculation stable.
If the simulation becomes unstable, it will stop running and an alert
box will appear. Do what it says.
- Yes, you can drag the atoms around with the mouse. If the simulation is running,
the mouse actually pulls the atom by a simulated elastic cord. Try it!
- To fix an atom in space, click on it while holding down the Alt key (or Option on a Mac).
Do the same to unfix it.
- To create a bond between two atoms, hold down the Shift key while you press the mouse
button on one,
drag to the other, and release. Shift-click on a single atom to delete all its bonds.
Click the Make bonds button to create bonds between all nearby pairs; shift-click
on the button to delete all bonds.
- The Save state button dumps the current state of the system into a
separate text window, from which you can then read it back in. You can edit the numbers
in the window, or copy them into a spreadsheet. (To copy the data back from a
spreadsheet, you may first need to convert it to tab-delimited text. This happens automatically
if you copy the data into a plain-text editor.) You can also use
this data to customize the presets file, MDPresets.txt, if you're running the applet from your
own server or hard drive.
- When the molecules are colored By speed (highly recommended), the sequence of
20 colors is assigned linearly according to speed. The brightest color is used for
all speeds greater than 3.0.
- You can change the color of the selected atom (to watch its motion more easily)
by clicking on the word "Molecules" and then choosing a different color. Select a different
atom by clicking on it.
- If you wish to print the applet image and your browser leaves a blank space, try
a different browser. Or make a screen capture and print that from another program.
The fine print:
- This applet is computationally intensive! During each time step, the program
must test for interactions between all distinct pairs of atoms--and compute
the Lennard-Jones force for all pairs that are sufficiently close. When there are 100
atoms,
there are 4950 distinct pairs. Yet my personal computer can execute several thousand
such time steps per second.
- This applet was designed and tested on a 2 GHz dual core machine running Mac OS X
and Java 1.5. Your mileage may vary. On slower machines you'll need to reduce the
animation speed and limit the number of atoms to get smooth animation.
- This applet should work with any Java runtime environment since version 1.1,
but I haven't tested it on anything that old yet.
- You are currently running version 2.0 of this applet, last modified on June 29, 2008.
- Copyright 2007-2008, Dan Schroeder,
Physics Department, Weber State University, Ogden, UT 84408-2508.
This applet is free, open-source software. It comes with absolutely no
warranty, but you are welcome to copy and redistribute it under certain
conditions. Read the license for details.
To download a zip archive of the source code and all related files,
click here.
Of related interest:
“If, in some cataclysm, all of scientific knowledge were to be destroyed,
and only one sentence passed on to the next generation of creatures, what statement would contain
the most information in the fewest words? I believe it is the atomic hypothesis
(or the atomic fact, or whatever you wish to call it) that all things are made of
atoms&mdashlittle particles that move around in perpetual motion, attracting each
other when they are a little distance apart, but repelling upon being squeezed
into one another. In that one sentence, you will see, there is an enormous amount of
information about the world, if just a little imagination and thinking are applied.”
—Richard Feynman