Name

MDTrajectory — Class implementing an MD Trajectory container object.

Synopsis

Namespace: NanoLanguage
MDTrajectory()

Description

Constructor for the MDTrajectory

MDTrajectory Arguments

MDTrajectory Methods

A MDTrajectory object provides the following methods:

  • cells(): Return list with the cell vectors of the images.

  • coordinates(): Return list with the cartesian coordinates of the images.

  • elements(): Return list with the elements of the images.

  • forces(): Return list with the forces of the images.

  • image(image_index): Return the configuration with the image_index

    image_index

    The index of the configuration that should be extracted.

  • kineticEnergies(): Return list with the kinetic energy of the images.

  • lastImage():

  • length(): Return the length of the trajectory.

  • masses(): Return list with the masses of the images.

  • potentialEnergies(): Return list with the potential energy of the images.

  • steps(): Return list with the steps of the images.

  • times(): Return list with the times of the images.

  • velocities(): Return list with the velocities of the images.

  • writeToXYZ(filename): Function for making an xyz ASCII dump of the whole trajectory.

    filename

    The name of the file to write to.

Usage Examples

Perform four Molecular Dynamics simulations with different time steps and save their trajectories in the file trajectory.nc.

# Define a benzene ring
cartesian_coordinates = [[ 0.      ,  1.399795, -0.      ],
                         [ 1.212253,  0.69976 , -0.      ],
                         [ 1.212253, -0.69976 , -0.      ],
                         [-0.      , -1.399795, -0.      ],
                         [-1.212253, -0.69976 , -0.      ],
                         [-1.212253,  0.69976 , -0.      ],
                         [ 0.      ,  2.500678, -0.      ],
                         [ 2.165671,  1.250363, -0.      ],
                         [ 2.165671, -1.250363, -0.      ],
                         [ 0.      , -2.500678, -0.      ],
                         [-2.165671, -1.250363, -0.      ],
                         [-2.165671,  1.250363, -0.      ]]*Angstrom

molecule_configuration = MoleculeConfiguration(
    elements=[Carbon,]*6+[Hydrogen,]*6,
    cartesian_coordinates=cartesian_coordinates
    )

# Attach a calculator
molecule_configuration.setCalculator(BrennerCalculator())

initial_velocity = MaxwellBoltzmannDistribution(
        temperature=300.0*Kelvin
    )

length_of_simulation = 20*femtoSecond

# Generate trajectories for different time steps
for time_step in [0.1, 0.5, 1, 2]*femtoSecond:

    method = VelocityVerlet(
        time_step=time_step,
        initial_velocity=initial_velocity
        )

    # Generate trajectory
    molecular_dynamics = MolecularDynamics(
        molecule_configuration,
        trajectory_filename='trajectory.nc',
        steps=int(length_of_simulation/time_step),
        log_interval=max(1,int(2*femtoSecond/time_step)),
        method=method
        )

mdrun.py

Plot the total energy as function of time for the trajectories in the file trajectory.nc.

import pylab

# Read in a list with the trajectories
trajectories = nlread('trajectory.nc', MDTrajectory)

pylab.figure()
for trajectory in trajectories:
    # Get the time axis of the trajectory
    t = trajectory.times().inUnitsOf(femtoSecond)
    # Calculate the time step
    time_step = t[-1]/trajectory.steps()[-1]
    # Get the energies
    epot = trajectory.potentialEnergies().inUnitsOf(eV)
    ekin = trajectory.kineticEnergies().inUnitsOf(eV)
    # Plot the data
    pylab.plot(t,epot+ekin, label='timestep='+str(time_step)+' fs')
    pylab.xlabel('time (fs)')
    pylab.ylabel('total energy (eV)')
    pylab.legend()

pylab.show()

mdplot.py

The total energy as function of the simulation time in MD runs with different time steps.

Figure 13: The total energy as function of the simulation time in MD runs with different time steps.