File: test_repeat_FixAtoms.py

package info (click to toggle)
python-ase 3.21.1-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 13,936 kB
  • sloc: python: 122,428; xml: 946; makefile: 111; javascript: 47
file content (35 lines) | stat: -rw-r--r-- 1,013 bytes parent folder | download | duplicates (2)
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
def test_repeat_FixAtoms():
    from ase.build import molecule
    from ase.constraints import 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