File: test_integration.py

package info (click to toggle)
python-ase 3.22.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,344 kB
  • sloc: python: 126,379; xml: 946; makefile: 111; javascript: 47
file content (59 lines) | stat: -rw-r--r-- 1,464 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
50
51
52
53
54
55
56
57
58
59
import pytest
import numpy as np

from ase.build import bulk

from ase.optimize import BFGS
from ase.calculators.socketio import SocketIOCalculator
from ase.constraints import ExpCellFilter
from ase.units import Ry


abinit_boilerplate = dict(
    ionmov=28,
    expert_user=1,
    optcell=2,
    tolmxf=1e-300,
    ntime=100_000,
    ecutsm=0.5,
)


commands = dict(
    espresso='{exe} < PREFIX.pwi --ipi {unixsocket}:UNIX > PREFIX.pwo',
    abinit='{exe} PREFIX.in --ipi {unixsocket}:UNIX > PREFIX.log',
)


calc = pytest.mark.calculator


@calc('espresso', ecutwfc=200 / Ry)
@calc('abinit', ecut=200, **abinit_boilerplate)
def test_socketio_espresso(factory):
    name = factory.name
    if name == 'abinit':
        factory.require_version('9.4')

    atoms = bulk('Si')

    exe = factory.factory.executable
    unixsocket = f'ase_test_socketio_{name}'

    espresso = factory.calc(
        kpts=[2, 2, 2],
    )
    template = commands[name]
    command = template.format(exe=exe, unixsocket=unixsocket)
    espresso.command = command

    atoms.rattle(stdev=.2, seed=42)

    with BFGS(ExpCellFilter(atoms)) as opt, \
         pytest.warns(UserWarning, match='Subprocess exited'), \
         SocketIOCalculator(espresso, unixsocket=unixsocket) as calc:
        atoms.calc = calc
        for _ in opt.irun(fmax=0.05):
            e = atoms.get_potential_energy()
            fmax = max(np.linalg.norm(atoms.get_forces(), axis=0))
            print(e, fmax)