4
$\begingroup$

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?

$\endgroup$

1 Answer 1

4
$\begingroup$

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.io import read, write
from ase import units
from ase.md.velocitydistribution import MaxwellBoltzmannDistribution
surface = read('POSCAR', format='vasp')
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.

$\endgroup$
7
  • $\begingroup$ Thank you so much @Jaafar Mehrez Can you elaborate about random_seed and why you use the specified number 123? $\endgroup$ Dec 1, 2023 at 12:16
  • 1
    $\begingroup$ 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. $\endgroup$ Dec 1, 2023 at 12:24
  • $\begingroup$ 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. $\endgroup$ Dec 1, 2023 at 12:24
  • 1
    $\begingroup$ thank you so much @ Jaafar Mehrez it is very useful for me. Is there any process for accepting or will it happen automatically :) $\endgroup$ Dec 1, 2023 at 12:36
  • 1
    $\begingroup$ @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! $\endgroup$ Dec 1, 2023 at 13:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .