Coverage for /builds/ase/ase/ase/visualize/x3d.py: 38.89%

18 statements  

« prev     ^ index     » next       coverage.py v7.5.3, created at 2025-08-02 00:12 +0000

1# fmt: off 

2 

3"""Inline viewer for jupyter notebook using X3D.""" 

4import warnings 

5 

6try: 

7 from StringIO import StringIO 

8except ImportError: 

9 from io import StringIO 

10 

11from ase.io.x3d import write_x3d 

12 

13 

14def view_x3d(atoms, *args, **kwargs): 

15 """View atoms inline in a jupyter notebook. This command 

16 should only be used within a jupyter/ipython notebook. 

17 

18 Args: 

19 atoms - ase.Atoms, atoms to be rendered""" 

20 try: 

21 from IPython.display import HTML 

22 except ImportError: 

23 warnings.warn('Please install IPython') 

24 return None 

25 

26 notebook_style = {'width': '400px', 'height': '300px'} 

27 

28 temp = StringIO() 

29 write_x3d(temp, atoms, format='X3DOM', style=notebook_style) 

30 data = temp.getvalue() 

31 temp.close() 

32 return HTML(data)