File: test_atoms_bytes.py

package info (click to toggle)
python-ase 3.21.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,936 kB
  • sloc: python: 122,428; xml: 946; makefile: 111; javascript: 47
file content (21 lines) | stat: -rw-r--r-- 661 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
from ase.build import bulk
from ase.io.bytes import to_bytes, parse_images, parse_atoms
from ase.calculators.calculator import compare_atoms

atoms = bulk('Ti')
images = [bulk('Au'), bulk('Ti'), bulk('NaCl', 'rocksalt', 17)]

def test_format():
    fmt = 'traj'  # TODO: parametrize?
    buf = to_bytes(atoms, format=fmt)
    atoms1 = parse_atoms(buf)

    err = compare_atoms(atoms, atoms1)
    assert not err, err  # Should be empty list

    buf = to_bytes(images, format=fmt)
    images1 = parse_images(buf)
    assert len(images) == len(images1)
    for img, img1 in zip(images, images1):
        err = compare_atoms(img, img1)
        assert not err, err