Creating a simulation

The following code creates a MD simulation with two particles interacting via the 12-6 Lennard-Jones (LJ) potential.

Example Code

#include <iostream>                                             //Use the iostream library
#include <glotzmd.h>                                            //Use the glotzmd libarary
using namespace glotzmd;                                        //Use the glotzmd namespace

int main()
{
        MdSimulation s;                                         // 1. declare a new simulation
        s.SetForceRoutine(new BruteForce);                      // 2. set force routine
        s.SetBoundaryConditions(new PeriodicBoundary(15));      // 3. set a 15x15x15 periodic box
        s.AddInteraction(type::A, type::A, new LjPotential);    // 4. use LJ for A-A interactions
        s.SetIntegrationScheme(new VelocityVerletIntegrator);   // 5. use velocity verlet
        s.AddParticle(new PointParticle( 1, 0, 0));             // 6. Point particle at 1,0,0
        s.AddParticle(new PointParticle( -1, 0, 0));            // 7. Point particle at -1,0,0
        s.StepForward(1000);                                    // 8. Do 1000 MD timesteps
        std::cout << s.ComputePotentialEnergy() << "\n";        // 9. Print the potential energy
        return 0;
}               

Some Notes

  1. Simulation is of type MdSimulation
    • Carries out a molecular dynamics-like simulation (MD simulation, BD simulation, DPD simulation)
    • The MdSimulation class acts as a container to hold the parts comprising an MD simulation
    • Different parts communicate with each other via the MdSimulation class
  2. Force routine is of type Brute Force.
    • Calculates the distance between all pairs of particles
    • Simplest possible force routine
  3. Boundary conditions are of type PeriodicBoundary
  4. Interactions between A-A particles are of type LjPotential
    • Interacting types must be set to know which particles the potential applies to
    • Implements the Lennard-Jones potential
    • Default is the standard 12-6 form, although this can be altered
  5. Integration scheme is of type VelocityVerletIntegrator
  6. Particle 1 is of type MdPointParticle
    • Position is set to <1,0,0> in the constructor
    • Default type is type::A, although type can be explicitly set
  7. Particle 2 is of type MdPointParticle
    • Position is set to <-1,0,0> in the constructor
    • Default type is type::A, although type can be explicitly set
  8. StepForward(N) steps the simulaton forward N timesteps
    • Another way to write this would be s += 1000
    • Can also do "StepBackward" to go back in time (only certain integrators)
  9. ComputePotentialEnergy() returns the potential energy of the system

Next Step