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

18 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-12-10 11:04 +0000

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

2import warnings 

3 

4try: 

5 from StringIO import StringIO 

6except ImportError: 

7 from io import StringIO 

8 

9from ase.io.x3d import write_x3d 

10 

11 

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

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

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

15 

16 Args: 

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

18 try: 

19 from IPython.display import HTML 

20 except ImportError: 

21 warnings.warn('Please install IPython') 

22 return 

23 

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

25 

26 temp = StringIO() 

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

28 data = temp.getvalue() 

29 temp.close() 

30 return HTML(data)