File: test_atoms_bytes.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 (23 lines) | stat: -rw-r--r-- 673 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
# fmt: off
from ase.build import bulk
from ase.calculators.calculator import compare_atoms
from ase.io.bytes import parse_atoms, parse_images, to_bytes

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