Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1from io import BytesIO 

2from ase.io import iread, write 

3 

4 

5def to_bytes(images, format=None, **kwargs): 

6 """Convert atoms or multiple atoms objects to bytes.""" 

7 buf = _to_buffer(images, format=format, **kwargs) 

8 btxt = buf.getvalue() 

9 return btxt 

10 

11 

12def _to_buffer(images, format=None, **kwargs): 

13 buf = BytesIO() 

14 write(buf, images, format=format, **kwargs) 

15 buf.seek(0) 

16 return buf 

17 

18 

19def parse_images(data, format=None, **kwargs): 

20 """Parse string or bytes into list of atoms objects.""" 

21 buf = BytesIO(data) 

22 images = list(iread(buf, format=format, **kwargs)) 

23 return images 

24 

25 

26def parse_atoms(data, format=None, **kwargs): 

27 images = parse_images(data, format=format, index=-1, **kwargs) 

28 assert len(images) == 1 

29 return images[0]