Molecular Dynamics Simulation

This tutorial will guide the user through the general workflow to perform a molecular dynamicsi (MD) simulation for a water dimer by using python based packages such as eDFTpy and the Atomic Simulation Environment (ASE)

Note

To avoid mixing some files, we strongly recommend setup each calculation (e.g. Optimization of density, relaxation of a structure of an MD simulation) in separate folders.

Input Files

Same as the relaxation step, MD simulation also, requires a set of input files divided into four different types:

  • Global system coordinates

  • eDFTpy input file

  • Aditional subsystem configuration

  • ASE input file

Global system coordinates

In this tutorial, we are going to use the optimized structure obtaned as an output from the relaxation of a structure tutorial opt.xyz however, this workflow in real conditions depends on the needs of each user, this means there may be times when the user does not have to perform a relaxation calculation prior to the molecular dynamics simulation.

eDFTpy input file

Essentially, this file is the same as the one provided in the previous step. Nevertheless, for this step of the tutorial, you should change the cell file name to opt.xyz. Also, we are going to use the adaptive definition of the subsystems for the global system through the MD simulation, using the same distance method introduced in the SCF tutorial with the automatic definition of subsystems. It means we should include the decompose keyword and all of the atomic radius in the [GSYSTEM] flag, as follows:

cell-file          = opt.xyz
kedf-k_str         = revAPBEK
decompose-method   = distance
decompose-radius-O = 0.90
decompose-radius-H = 0.60
decompose-radius-Cl = 1.0

Aditional subsystem configuration

We use the same base file provided for the relaxation step, you can change to different parameters if you require.

ASE input file

Followed the ASE input file explanation for the relaxation of a strcutre, this input file also is written following the ASE input file format. Contrary to the previous file, this input file includes definitions of temperature, thermodynamics ensemble, thermostat, time step, etc used to run the simulation, follows we summarize the ones that we consider you should think about before setting up a real calculation. Check ASE Molecular dynamics module for an extensive keywords description.

atoms = ase.io.read(cell_file)                                                            # Name of the file from ASE will read the coordinates

T = 300                                                                                   # Base temperature at the MD simulation will be runnied.
MaxwellBoltzmannDistribution(atoms, temperature_K = T, force_temp=True)                   # Initialize the velocities at the defined temperature base on the Maxwell Boltzmann distribution
dyn = NVTBerendsen(atoms, 0.7 * units.fs, temperature_K = T, taut=0.2*1000*units.fs)      # Define the type of thermostat we will used for the simulation and the time step used, for this tutorial we used a dt = 0.7 fs.
traj = Trajectory("md.traj", "w", atoms)                                                  # Name of the output trajectory file
nsteps = 10                                                                               # Number of steps you will run your simulation

Running eDFTpy

Once you finish setting out the calculation, you can run the calculation using:

$ mpirun -n 4 python -m ase_relax.py > log

Note

Here the log file storages the summary of the calculation.

Warning

If you are using python3 version you should change all the python command lines wrote here from python to python3

Additional output Files

  • edftpy_gsystem.xyz Global system coordinates for the last step of the simulation

  • md.traj Output trajectory file for the global system.

Preliminary Analysis

Once you finished your simulation you would like to analyze your results, most of the time your structural analysis will require your trajectory file (md.traj). Although this trajectory formatis only useful if you are using the ASE package to perform visual analysis.

Open the trajectory file with the ASE visualization tool by typing:

$ ase gui md.traj

Once you open MD trajectory file observe the step by step structure change and a graphic generator which includes a set of graphics check ASE’s GUI. Here we show the variation of the total energy (eV) in function of the number steps for the MD simulation of the binary salt (NaCl) molecule surrounded by a water dimer by 20 steps of simulation.

Total energy Variation

logo1

Note

For the purposes of this tutorial, the configured input file only includes 20 steps, otherwise the wait time would be proportional to a couple of days using four (4) cores.

Convert the format of a trajectory file

If you would like to use any other package to carry out structural analysis will be useful for you to covert this trajectory file to a most common type as xyz. We developed a python script that you can use to convert your trajectory files by typing:

$ python -m edftpy –-convert –-traj md.traj -o md-traj.xyz

You can check the command line miscellaneous for eDFTpy in the command line section of the sofware website.

Restarting a MD simulation

Restarting a calculation could be a powerful option taking into account the time-consuming disadvantage of an ab-initio molecular dynamics simulation. Here we give the user a guide on how can restart an MD simulation

To restart a simulation the user should modify the eDFTpy and ASE input files either Structure optimizartion or MD production.

  1. Copy your trajectory file (md.traj) to a new file:

    $ cp md.traj md-1.traj
    
  2. Create a new global system coordinate file using the last geometry coordinates:

    $ cp edftpy_gsystem.xyz rst-1.xyz
    
  3. Change the file name for the cell-file in the eDFTpy input file

    • from

    cell-file          = opt.xyz
    
    • to

    cell-file          = rst-1.xyz
    
  4. Change the cell_file in the ASE input file to your old trajectory file

    • from

    atoms = ase.io.read(cell_file)
    
    • to

    atoms = ase.io.read("md-1.traj")
    
  5. As you already initialize velocities from your las trajectory you should not include the Maxwell Boltzmann Distribution line, you can comment this line adding a hash # at he begining of the line

  6. To avoid to concatenate all the trajectory file at the end of the simulation you can attempt the new trajectory to the old md.traj file modifying the trajectory file section:

    • from

    traj = Trajectory("md.traj", "w", atoms)
    
    • to

    traj = Trajectory("md.traj", "a", atoms)
    
  7. Restart your simulation using:

    $ mpirun -n 4 python -m ase_relax.py > log