File: test_amin.py

package info (click to toggle)
python-ase 3.21.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,936 kB
  • sloc: python: 122,428; xml: 946; makefile: 111; javascript: 47
file content (34 lines) | stat: -rw-r--r-- 1,016 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
import numpy as np
import pytest

from ase.build import bulk
from ase.calculators.lj import LennardJones
from ase.optimize.precon import Exp, PreconLBFGS


@pytest.mark.skip('FAILS WITH PYAMG')
@pytest.mark.slow
def test_precon_amin():
    cu0 = bulk("Cu") * (2, 2, 2)
    sigma = cu0.get_distance(0,1)*(2.**(-1./6))
    lj = LennardJones(sigma=sigma)

    # perturb the cell
    cell = cu0.get_cell()
    cell *= 0.95
    cell[1,0] += 0.2
    cell[2,1] += 0.5
    cu0.set_cell(cell, scale_atoms=True)

    energies = []
    for use_armijo in [True, False]:
        for a_min in [None, 1e-3]:
            atoms = cu0.copy()
            atoms.calc = lj
            opt = PreconLBFGS(atoms, precon=Exp(A=3), use_armijo=use_armijo,
                              a_min=a_min, variable_cell=True)
            opt.run(fmax=1e-3, smax=1e-4)
            energies.append(atoms.get_potential_energy())

    # check we get the expected energy for all methods
    assert np.abs(np.array(energies) - -63.5032311942).max() < 1e-4