root / ase / md / verlet.py
Historique | Voir | Annoter | Télécharger (1,04 ko)
1 |
import numpy as np |
---|---|
2 |
|
3 |
from ase.md.md import MolecularDynamics |
4 |
|
5 |
|
6 |
class VelocityVerlet(MolecularDynamics): |
7 |
def __init__(self, atoms, dt, trajectory=None, logfile=None, |
8 |
loginterval=1):
|
9 |
MolecularDynamics.__init__(self, atoms, dt, trajectory, logfile,
|
10 |
loginterval) |
11 |
|
12 |
def step(self, f): |
13 |
atoms = self.atoms
|
14 |
p = self.atoms.get_momenta()
|
15 |
p += 0.5 * self.dt * f |
16 |
self.atoms.set_positions(self.atoms.get_positions() + |
17 |
self.dt * p / self.atoms.get_masses()[:,np.newaxis]) |
18 |
# We need to store the momenta on the atoms before calculating
|
19 |
# the forces, as in a parallel Asap calculation atoms may
|
20 |
# migrate during force calculations, and the momenta need to
|
21 |
# migrate along with the atoms. For the same reason, we
|
22 |
# cannot use self.masses in the line above.
|
23 |
self.atoms.set_momenta(p)
|
24 |
f = self.atoms.get_forces()
|
25 |
atoms.set_momenta(self.atoms.get_momenta() + 0.5 * self.dt * f) |
26 |
return f
|