File: test_potential_energies.py

package info (click to toggle)
python-ase 3.26.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,484 kB
  • sloc: python: 148,112; xml: 2,728; makefile: 110; javascript: 47
file content (25 lines) | stat: -rw-r--r-- 678 bytes parent folder | download
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
# fmt: off
from numpy.testing import assert_allclose

import ase.build
from ase.calculators.emt import EMT


def test_potential_energies():
    TOL = 1E-8

    atoms = ase.build.bulk("Ni", crystalstructure="fcc", cubic=1)
    atoms *= (2, 2, 2)
    atoms.calc = EMT()
    energies = atoms.get_potential_energies()
    energy = atoms.get_potential_energy()

    # energy sums should be identical
    assert abs(energies.sum() - energy) < TOL

    # in ideal FCC crystal per-atom energies should be identical
    assert_allclose(energies, energies[0], rtol=TOL)

    # rattle the system and check energy sums again
    atoms.rattle()
    assert abs(energies.sum() - energy) < TOL