File: test_counterions.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 (27 lines) | stat: -rw-r--r-- 781 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
# fmt: off
import numpy as np

from ase import Atoms, units
from ase.calculators.counterions import AtomicCounterIon as ACI
from ase.calculators.fd import calculate_numerical_forces


def test_counterions():
    """ Test AtomicCounterIon is force/energy consistent over
        PBCs and with cutoff """

    sigma = 1.868 * (1.0 / 2.0)**(1.0 / 6.0)
    epsilon = 0.00277 * units.kcal / units.mol

    atoms = Atoms('3Na', positions=np.array([[0, 0, -2], [0, 0, 0], [0, 0, 2]]))
    atoms.cell = [10, 10, 10]
    atoms.pbc = True

    atoms.calc = ACI(1, epsilon, sigma, rc=4.5)
    points = np.arange(-15., 15., 0.2)

    for _ in points:
        f = atoms.get_forces()
        fn = calculate_numerical_forces(atoms, 1e-5)
        df = (f - fn)
        assert abs(df).max() < 1e-8