# Random velocity generation

How to generate random velocities in the geometry coordinates of a surface (POSCAR file) using the Boltzmann distribution law with Atomic Simulation Environment (ASE) or other codes for Molecular Dynamics (MD) calculations?

You can use ASE to generate the required random velocities, you may refer to this sample code to achieve this taks:

import numpy as np
from ase import units
from ase.md.velocitydistribution import MaxwellBoltzmannDistribution
temperature = 300.0
np.random.seed(123)

MaxwellBoltzmannDistribution(surface, temperature_K=temperature*units.kB)
print(surface.get_velocities()[:5])
write('modified_POSCAR', surface, format='vasp')


Here, I explicitly specify the temperature in Kelvin.

• Thank you so much @Jaafar Mehrez Can you elaborate about random_seed and why you use the specified number 123? Commented Dec 1, 2023 at 12:16
• When you use a random number generator, it generates a sequence of seemingly random numbers based on an initial seed value. By setting a specific seed value, you can reproduce the same sequence of random numbers every time you run the code. In the context of molecular dynamics simulations, setting a random seed allows you to reproduce the same initial velocities for the atoms. This can be useful for debugging or comparing simulation results between different runs. Commented Dec 1, 2023 at 12:24
• The specific value 123 used in the example is an arbitrary choice. You can use any integer value as the random seed. The important thing is to use the same seed if you want to reproduce the same set of random velocities. Commented Dec 1, 2023 at 12:24
• thank you so much @ Jaafar Mehrez it is very useful for me. Is there any process for accepting or will it happen automatically :) Commented Dec 1, 2023 at 12:36
• @RubiAgrawal There is a tick symbol (✔) next to the answer, that would show that you accept the answer as the right answer for your question if you think so. On the other hand, you can choose to click the upvote if you think other answers might be more suitable or correct to your question. Happy computing! Commented Dec 1, 2023 at 13:00