Adding a Visualizer

The following code demonstrates how to add a visualizer to the previous example. The example uses our built-in OpenGL visualizer. If you have VMD installed on your machine, you can use it by commenting out line "1." and uncommenting line "2."

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;                                         // declare a new simulation
        s.SetForceRoutine(new BruteForce);                      // set force routine
        s.SetBoundaryConditions(new PeriodicBoundary(15));      // set a 15x15x15 periodic box
        s.AddInteraction(type::A, type::A, new LjPotential);    // use LJ for A-A interactions
        s.SetIntegrationScheme(new VelocityVerletIntegrator);   // use velocity verlet
        s.AddParticle(new PointParticle( 1, 0, 0));             // Point particle at 1,0,0
        s.AddParticle(new PointParticle( -1, 0, 0));            // Point particle at -1,0,0
        s.AddSimulationModifier(new OpenGlVisualizer);          // 1. Add an OpenGL visualizer  
//      s.AddSimulationModifier(new VmdVisualizer);             // 2. Add a VMD visualizer
        s.StepForward(10000);                                   // Do 10000 MD timesteps
        return 0;
}               

Some Notes

We add a visualizer to the system by adding a SimulationModifier. A SimulationModifier is a class that adds a new method to the MD "main loop." Therefore, for each timestep, in addition to calculating forces, integrating Newton's equations of motion, etc., we pass data to a visualizer.

  1. SimulationModifier is of type OpenGlVisualizer
    • Relatively simple visualizer with fewer features than VMD
    • Since it is built along with the source code it is very flexible
  2. SimulationModifier is of type VmdVisualizer
    • Uses the VMD visualizer that works with NAMD
    • Supports many useful features such as GUI control, python interface and ray-traced output

Next Step?