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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
# fmt: off
from io import StringIO
from pathlib import Path
import numpy as np
import pytest
from ase.io import read
from ase.io.siesta import read_fdf, read_struct_out
from ase.units import Bohr
sample_struct_out = """\
3.0 0.0 0.0
-1.5 4.0 0.0
0.0 0.0 5.0
2
1 45 0.0 0.0 0.0
1 46 0.3 0.4 0.5
"""
def test_read_struct_out():
atoms = read_struct_out(StringIO(sample_struct_out))
assert all(atoms.numbers == [45, 46])
assert atoms.get_scaled_positions() == pytest.approx(
np.array([[0., 0., 0.], [.3, .4, .5]]))
assert atoms.cell[:] == pytest.approx(np.array([[3.0, 0.0, 0.0],
[-1.5, 4.0, 0.0],
[0.0, 0.0, 5.0]]))
assert all(atoms.pbc)
sample_fdf = """\
potatoes 5
COFFEE 6.5
%block spam
1 2.5 hello
%endblock spam
"""
def test_read_fdf():
dct = read_fdf(StringIO(sample_fdf))
# This is a "raw" parser, no type conversion is done.
ref = dict(potatoes=['5'],
coffee=['6.5'],
spam=[['1', '2.5', 'hello']])
assert dct == ref
"""
"Hand-written" dummy file based on HCP Ti
"""
xv_file = """\
5.6 0.0 0.0 0.0 0.0 0.0
-2.8 4.8 0.0 0.0 0.0 0.0
0.0 0.0 8.9 0.0 0.0 0.0
2
1 22 0.0 0.0 0.0 0.0 0.0 0.0
1 22 0.0 3.2 4.4 0.0 0.0 0.0
"""
def test_read_xv():
path = Path('tmp.XV')
path.write_text(xv_file)
atoms = read(path)
assert str(atoms.symbols) == 'Ti2'
pos = atoms.positions
assert pos[0] == pytest.approx(0)
assert pos[1] / Bohr == pytest.approx([0, 3.2, 4.4])
assert all(atoms.pbc)
assert atoms.cell / Bohr == pytest.approx(np.array(
[[5.6, 0, 0], [-2.8, 4.8, 0], [0, 0, 8.9]]
))
|