File: test_repeat_FixAtoms.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 (38 lines) | stat: -rw-r--r-- 1,018 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
# fmt: off
from ase.build import molecule
from ase.constraints import FixAtoms


def test_repeat_FixAtoms():

    N = 2

    atoms = molecule('CO2')
    atoms.set_cell((15, 15, 15))

    # Indices method:
    atomsi = atoms.copy()
    atomsi.set_constraint(FixAtoms(indices=[0]))
    atomsi = atomsi.repeat((N, 1, 1))

    atomsiref = atoms.copy().repeat((N, 1, 1))
    atomsiref.set_constraint(FixAtoms(indices=list(range(0, 3 * N, 3))))

    lcatomsi = list(atomsi.constraints[0].index)
    lcatomsiref = list(atomsiref.constraints[0].index)

    assert lcatomsi == lcatomsiref

    # Mask method:
    atomsm = atoms.copy()
    atomsm.set_constraint(FixAtoms(mask=[True, False, False]))
    atomsm = atomsm.repeat((N, 1, 1))

    atomsmref = atoms.copy().repeat((N, 1, 1))
    atomsmref.set_constraint(FixAtoms(mask=[True, False, False] * N))

    lcatomsm = list(atomsm.constraints[0].index)
    lcatomsmref = list(atomsmref.constraints[0].index)

    assert lcatomsm == lcatomsmref
    assert lcatomsm == lcatomsi