File: set_momenta.py

package info (click to toggle)
python-ase 3.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 14,192 kB
  • ctags: 8,112
  • sloc: python: 93,375; sh: 99; makefile: 94
file content (27 lines) | stat: -rw-r--r-- 827 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""Test that set_momenta behaves as expected when constraints are
involved."""

import numpy as np
from ase import Atoms, Atom
from ase.constraints import Hookean, FixAtoms


# FixAtoms check
atoms = Atoms([Atom('H', (0., 0., 0.)),
               Atom('H', (2., 0., 0.))])
atoms.set_constraint(FixAtoms(indices=[0]))
atoms.set_momenta(np.ones(atoms.get_momenta().shape))
desired = np.ones(atoms.get_momenta().shape)
desired[0] = 0.
actual = atoms.get_momenta()
assert (actual == desired).all()

# Hookean check
atoms = Atoms([Atom('H', (0., 0., 0.)),
               Atom('H', (2., 0., 0.))])
atoms.set_constraint(Hookean(0, 1, rt=1., k=10.))
atoms.set_momenta(np.zeros(atoms.get_momenta().shape))
actual = atoms.get_momenta()
desired = np.zeros(atoms.get_momenta().shape)
# Disabled for now:
# assert (actual == desired).all()