File: test_hookean_pbc.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 (28 lines) | stat: -rw-r--r-- 733 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
# fmt: off
from ase import Atoms
from ase.calculators.emt import EMT
from ase.constraints import Hookean


def test_hookean_pbc():

    L = 8.  # length of the cubic box
    d = 2.3  # Au-Au distance
    cell = [L] * 3
    positions = [[(L - d / 2) %
                  L, L / 2, L / 2], [(L + d / 2) %
                                     L, L / 2, L / 2]]
    a = Atoms('AuAu', cell=cell, positions=positions, pbc=True)

    a.calc = EMT()
    e1 = a.get_potential_energy()

    constraint = Hookean(a1=0, a2=1, rt=1.1 * d, k=10.)
    a.set_constraint(constraint)
    e2 = a.get_potential_energy()

    a.set_pbc([False, True, True])
    e3 = a.get_potential_energy()

    assert abs(e1 - e2) < 1e-8
    assert abs(e1 - e3) >= 1e-8