File: test_atoms_instantiation.py

package info (click to toggle)
python-ase 3.24.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 15,448 kB
  • sloc: python: 144,945; xml: 2,728; makefile: 113; javascript: 47
file content (54 lines) | stat: -rw-r--r-- 1,373 bytes parent folder | download | duplicates (3)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from ase import Atom, Atoms

"""The documentation says:

    These three are equivalent:

    >>> d = 1.104  # N2 bondlength
    >>> a = Atoms('N2', [(0, 0, 0), (0, 0, d)])
    >>> a = Atoms(numbers=[7, 7], positions=[(0, 0, 0), (0, 0, d)])
    >>> a = Atoms([Atom('N', (0, 0, 0)), Atom('N', (0, 0, d))])

so let's check"""


numbers = [7, 7]
symbols = ["N", "N"]
dummy_array = 2 * [3 * [0.0]]

d = 1.104  # N2 bondlength
a1 = Atoms("N2", [(0, 0, 0), (0, 0, d)])
a2 = Atoms(numbers=[7, 7], positions=[(0, 0, 0), (0, 0, d)])
a3 = Atoms([Atom("N", (0, 0, 0)), Atom("N", (0, 0, d))])


def test_atoms(atoms1=a1, atoms2=a2, atoms3=a3):
    assert atoms1 == atoms2
    assert atoms2 == atoms3


# test redundant keywords
def test_symbols(numbers=numbers, symbols=symbols):
    kw = {"numbers": numbers, "symbols": symbols}
    _test_keywords(**kw)


def test_momenta(numbers=numbers, momenta=dummy_array):
    kw = {"momenta": momenta, "velocities": momenta}
    _test_keywords(numbers=numbers, **kw)


def test_positions(numbers=numbers, positions=dummy_array):
    kw = {"positions": positions, "scaled_positions": positions}
    _test_keywords(numbers=numbers, **kw)


def _test_keywords(**kw):
    was_raised = False
    try:
        Atoms(**kw)
    except Exception as inst:
        assert isinstance(inst, TypeError), inst
        was_raised = True

    assert was_raised