1import pytest 2import numpy as np 3 4from ase import Atoms 5from ase.io import read, write 6 7 8@pytest.mark.parametrize('pbc', [False, [True, True, False], True]) 9@pytest.mark.parametrize('cell', [None, [[2.5, 0, 0], [2, 4, 0], [1, 2, 3]]]) 10@pytest.mark.parametrize('write_format', ['gen', 'dftb']) 11def test_gen(pbc, cell, write_format): 12 atoms = Atoms(symbols='OCO', pbc=pbc, cell=cell, 13 positions=[[-0.1, 1.2, 0.3], 14 [-0.1, 0.0, 0.2], 15 [0.4, -0.9, 0.0]]) 16 write('test.gen', atoms, format=write_format) 17 18 atoms_new = read('test.gen') 19 assert np.all(atoms_new.numbers == atoms.numbers) 20 assert np.allclose(atoms_new.positions, atoms.positions) 21 22 if atoms.pbc.any(): 23 assert np.all(atoms_new.pbc) 24 if atoms.cell is not None: 25 assert np.allclose(atoms_new.cell, atoms.cell) 26 else: 27 assert np.all(~atoms_new.pbc) 28 assert np.allclose(atoms_new.cell, 0.) 29 30 31def test_gen_multiple(): 32 # Try with multiple images. This is not supported by the 33 # format and should fail 34 atoms = Atoms('H2') 35 36 with pytest.raises(ValueError): 37 write('test.gen', [atoms, atoms]) 38