Coverage for ase/visualize/x3d.py: 38.89%
18 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-27 15:21 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-27 15:21 +0000
1"""Inline viewer for jupyter notebook using X3D."""
3import warnings
5try:
6 from StringIO import StringIO
7except ImportError:
8 from io import StringIO
10from ase.io.x3d import write_x3d
13def view_x3d(atoms, *args, **kwargs):
14 """View atoms inline in a jupyter notebook. This command
15 should only be used within a jupyter/ipython notebook.
17 Args:
18 atoms - ase.Atoms, atoms to be rendered"""
19 try:
20 from IPython.display import HTML
21 except ImportError:
22 warnings.warn('Please install IPython')
23 return None
25 notebook_style = {'width': '400px', 'height': '300px'}
27 temp = StringIO()
28 write_x3d(temp, atoms, format='X3DOM', style=notebook_style)
29 data = temp.getvalue()
30 temp.close()
31 return HTML(data)