File: test_python_interface.py

package info (click to toggle)
python-ase 3.26.0-3
  • 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 (33 lines) | stat: -rw-r--r-- 944 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
# fmt: off
import os

import numpy as np
import pytest

from ase.build import bulk
from ase.calculators.emt import EMT
from ase.calculators.socketio import PySocketIOClient, SocketIOCalculator
from ase.filters import FrechetCellFilter
from ase.optimize import BFGS


@pytest.mark.optimize()
@pytest.mark.skipif(os.name != 'posix', reason='only posix')
def test_socketio_python():

    atoms = bulk('Au') * (2, 2, 2)
    atoms.rattle(stdev=0.05)
    fmax = 0.01
    atoms.cell += np.random.RandomState(42).rand(3, 3) * 0.05

    client = PySocketIOClient(EMT)

    pid = os.getpid()
    with SocketIOCalculator(launch_client=client,
                            unixsocket=f'ase-python-{pid}') as atoms.calc:
        with BFGS(FrechetCellFilter(atoms)) as opt:
            opt.run(fmax=fmax)

    residual_forces = np.linalg.norm(atoms.get_forces(), axis=1)
    assert len(residual_forces) == len(atoms)
    assert np.max(residual_forces) < fmax