File: test_traj.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 (49 lines) | stat: -rw-r--r-- 1,393 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
39
40
41
42
43
44
45
46
47
48
49
import pytest

from ase.io import read, write
from ase.build import molecule
from ase.test.factories import ObsoleteFactoryWrapper

parameters = {
    'aims': dict(sc_accuracy_rho=5.e-3, sc_accuracy_forces=1e-4, xc='LDA'),
    'crystal': dict(basis='sto-3g'),
    'gamess_us': dict(label='test_traj'),
    #'elk': dict(tasks=0, rgkmax=5.0, epsengy=1.0, epspot=1.0, tforce=True,
    #            pbc=True),
    'Psi4': {},
}

calc = pytest.mark.calculator


@calc('gpaw',
      mode='lcao',
      basis='sz(dzp)',
      marks=pytest.mark.filterwarnings('ignore:The keyword'))
# Deprecated keyword, remove this once things are resolved
@calc('abinit', 'cp2k', 'emt')
@calc('vasp', xc='lda', prec='low')
def test_h2_traj(factory):
    run(factory)


@pytest.mark.parametrize('name', sorted(parameters))
def test_h2_traj_old(name):
    factory = ObsoleteFactoryWrapper(name)
    run(factory)


def run(factory):
    name = factory.name
    par = parameters.get(name, {})
    h2 = molecule('H2')
    h2.center(vacuum=2.0)
    h2.calc = factory.calc(**par)
    e = h2.get_potential_energy()
    assert not h2.calc.calculation_required(h2, ['energy'])
    f = h2.get_forces()
    assert not h2.calc.calculation_required(h2, ['energy', 'forces'])
    write('h2.traj', h2)
    h2 = read('h2.traj')
    assert abs(e - h2.get_potential_energy()) < 1e-12
    assert abs(f - h2.get_forces()).max() < 1e-12