ParM
parm
A molecular dynamics library
|
Based on LJatoms.cpp
Include the necessary header files:
AtomVec
Create 20 atoms, with mass 1.0:
We use boost::shared_ptr
for the major objects, to prevent memory leaks / segmentation faults and integrate more smoothly with Python. If you are not familiar with shared_ptr
, its a wrapper around a pointer such that multiple copies can be made, and the object will be deleted when the last shared_ptr
to it is deleted. See a reference for more details.
Box
Here, we'll use a periodic box with sides of length L
.
Interaction
We'll use the Lennard-Jones Interaction, \(V\left(r\right)=\varepsilon\left(1-\frac{\sigma^{6}}{r^{6}}\right)^{2}\), where \(\sigma\) is the size of each particle.
For computational purposes, we "truncate and shift" this potential at \(2.5\sigma\), a standard practice. We will also use a Neighbor list, which keeps track of which atoms are in the vicinity of each other.
We create that Interaction
, and give its NeighborList
a variable name:
Now we have given every Atom
a position and a random velocity.
Collection
A Collection
is a class that represents an integrator. There are various kinds of integrators: constant energy, constant temperature, energy minimization, etc. Here, we choose a Velocity Verlet integrator, which is constant energy:
Interaction
, NeighborList
, and Collection
We made our Collection, but it needs to know what potential to use with the atoms, and that it needs to update the NeighborList
:
Let's run it for 500,000 timesteps, outputting the current energy, kinetic_energy energy, and potential energy as we go:
That's all! To see this example fully fleshed out, see LJatoms.cpp