File: test_gen.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 (37 lines) | stat: -rw-r--r-- 1,197 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
36
37
import pytest
import numpy as np

from ase import Atoms
from ase.io import read, write


@pytest.mark.parametrize('pbc', [False, [True, True, False], True])
@pytest.mark.parametrize('cell', [None, [[2.5, 0, 0], [2, 4, 0], [1, 2, 3]]])
@pytest.mark.parametrize('write_format', ['gen', 'dftb'])
def test_gen(pbc, cell, write_format):
    atoms = Atoms(symbols='OCO', pbc=pbc, cell=cell,
                  positions=[[-0.1, 1.2, 0.3],
                             [-0.1, 0.0, 0.2],
                             [0.4, -0.9, 0.0]])
    write('test.gen', atoms, format=write_format)

    atoms_new = read('test.gen')
    assert np.all(atoms_new.numbers == atoms.numbers)
    assert np.allclose(atoms_new.positions, atoms.positions)

    if atoms.pbc.any():
        assert np.all(atoms_new.pbc)
        if atoms.cell is not None:
            assert np.allclose(atoms_new.cell, atoms.cell)
    else:
        assert np.all(~atoms_new.pbc)
        assert np.allclose(atoms_new.cell, 0.)


def test_gen_multiple():
    # Try with multiple images. This is not supported by the
    # format and should fail
    atoms = Atoms('H2')

    with pytest.raises(ValueError):
        write('test.gen', [atoms, atoms])