File: test_unitcellfilter.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 (32 lines) | stat: -rw-r--r-- 1,035 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
# fmt: off
import pytest

import ase
from ase.build import bulk
from ase.calculators.lj import LennardJones
from ase.filters import Filter, FrechetCellFilter, UnitCellFilter
from ase.optimize.precon import Exp, PreconLBFGS


# @pytest.mark.skip('FAILS WITH PYAMG')
@pytest.mark.optimize()
@pytest.mark.slow()
# Ignore UserWarning by failure of Armijo line search in PreconLBFGS
@pytest.mark.filterwarnings('ignore::UserWarning')
@pytest.mark.parametrize("filter_cls, tol", [
    (UnitCellFilter, 1e-3),
    # FrechetCellFilter allows relaxing to lower tolerance
    (FrechetCellFilter, 1e-7),
])
def test_precon(filter_cls, tol: float):
    cu0: ase.Atoms = bulk("Cu") * (2, 2, 2)
    lj = LennardJones(sigma=cu0.get_distance(0, 1))

    ratio = 1.2
    cu = cu0.copy()
    cu.set_cell(ratio * cu.get_cell())
    cu.calc = lj
    filter: Filter = filter_cls(cu, constant_volume=True)
    opt = PreconLBFGS(filter, precon=Exp(mu=1.0, mu_c=1.0))
    opt.run(fmax=1e-3)
    assert abs(cu.get_volume() / cu0.get_volume() - ratio**3) < tol