5.2. How to run the exercises

Access the NVE version of the code using this link and activate the virtual environment in the terminal again.

source ~/my_venvs/mdmc/bin/activate

Now you can proceed to modify and run the code files.

5.3. Exercises

5.3.1. MD Initialization and Temperature

  1. Implement the initialization described in the Theory section in our ToyMD code in toy_md.py in the section ##INITIALIZATION HERE##. For this you should pick random velocities using np.random.randn() which will produce random numbers according to a gaussian distribution \(\mathcal{N}(0,1)\). \(\sigma\) of \(\mathcal{N}\) needs to be adjusted such that the width of the velocity distribution matches the kinetic energy at the target temperature. Use the variables masses[i] for the mass of particle i and Boltzmanns constant 0.00831415. Remember that for each degree of freedom (e.g velocity in x direction) (5.22) holds.

  2. Implement the Berendsen thermostat in the toy_md.py and toy_md_integrate.py (change the compute_lambda_T function) files.

  3. A better thermostat is the Andersen thermostat. It can be implemented as follows below. Describe what problems this thermostat will present to us e.g for sampling of diffusion coefficients. What advantage does this thermostat have compared to the Berendsen thermostat?

#Andersen Thermostat
for i in range(N_part): # Loop over all particles
    if (r.random()<float(md_params["nu-T"])*float(md_params['time-step'])): # pick random particles according to nu
        sd=np.sqrt(0.00831415*float(md_params['temperature'])/masses[i])  # Velocity distribution at target temperature
        velocities[i]=0+np.random.randn(3)*sd

5.3.2. Force field

Now we can run a MD simulation in our desired NVT ensemble using our code on simple systems. Let’s simulate a box of CO2 molecules.

Investigate the force_field.txt file in the carbon-dioxide folder and then run a short molecular dynamics simulation using the following parameters:

number-of-steps  2000 # Number of integration time steps
time-step        0.001  # Integration time step (picoseconds)
temperature      50  # Simulation temperature
tau-T            0.05 # Temperature coupling time (picoseconds)
output-frequency  10   # Store coordinates every N steps

The simulation is run using

path/to/toy_md.py -c co2.pdb -p params.txt -f force_field.txt -o co2-traj.pdb -w co2-final.pdb

where co2-traj.pdb is a trajectory written each output-frequency steps and co2-final.pdb is the final geometry after the simulation has run the specified number of steps.

Open the resulting trajectory in VMD and plot the bond distance of a C-O bond. What to you observe?

  1. Plot the distribution of the CO and OO bond lengths during the simulation. How do the sampled values correspond to the values set in the force field?

  2. Visualize the radial distribution function of the CO2 trajectory. What do you observe? Bonus: What would you observe for a heterogenous system (i.e a polar molecule solvated in liquid CO2)?

5.3.3. Timestep and coupling

  1. Test the influence of the coupling parameter \(\tau\) and timestep \(dt\). You set both of those parameters in params.txt Test 3 different settings of \(\tau\) and \(dt\) and describe what you observe.