File: test_reduce.py

package info (click to toggle)
python-ase 3.26.0-2
  • 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 (38 lines) | stat: -rw-r--r-- 1,103 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
26
27
28
29
30
31
32
33
34
35
36
37
38
# fmt: off
import numpy as np
import pytest

from ase import Atoms
from ase.build.tools import reduce_lattice
from ase.calculators.emt import EMT


def test_reduce_lattice():
    """Test that reduce_lattice() correctly in-place-reduces lattice.

    We test that the 60 degree hex cell reduces to 120 degree cell.
    To verify that the full system is physically equivalent, we verify
    that the EMT energy is the same after the transformation."""

    origcellpar = [3, 3, 4, 90, 90, 60]
    ref_cellpar = list(origcellpar)
    ref_cellpar[-1] = 120

    symbols = 'CuAgAuPt'
    scaled_positions = np.random.RandomState(42).random((4, 3))

    atoms = Atoms(symbols=symbols,
                  scaled_positions=scaled_positions,
                  cell=origcellpar, pbc=True)

    reduced_atoms = atoms.copy()
    reduce_lattice(reduced_atoms)

    assert reduced_atoms.cell.cellpar() == pytest.approx(ref_cellpar)
    assert emt_energy(atoms) == pytest.approx(emt_energy(reduced_atoms))


def emt_energy(atoms):
    atoms = atoms.copy()
    atoms.calc = EMT()
    return atoms.get_potential_energy()