Coverage for /builds/kinetik161/ase/ase/io/bytes.py: 100.00%
19 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-12-10 11:04 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-12-10 11:04 +0000
1from io import BytesIO
3from ase.io import iread, write
6def to_bytes(images, format=None, **kwargs):
7 """Convert atoms or multiple atoms objects to bytes."""
8 buf = _to_buffer(images, format=format, **kwargs)
9 btxt = buf.getvalue()
10 return btxt
13def _to_buffer(images, format=None, **kwargs):
14 buf = BytesIO()
15 write(buf, images, format=format, **kwargs)
16 buf.seek(0)
17 return buf
20def parse_images(data, format=None, **kwargs):
21 """Parse string or bytes into list of atoms objects."""
22 buf = BytesIO(data)
23 images = list(iread(buf, format=format, **kwargs))
24 return images
27def parse_atoms(data, format=None, **kwargs):
28 images = parse_images(data, format=format, index=-1, **kwargs)
29 assert len(images) == 1
30 return images[0]