File: x3d.py

package info (click to toggle)
python-ase 3.22.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,344 kB
  • sloc: python: 126,379; xml: 946; makefile: 111; javascript: 47
file content (21 lines) | stat: -rw-r--r-- 519 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""Inline viewer for jupyter notebook using X3D."""

try:
    from StringIO import StringIO
except ImportError:
    from io import StringIO
from IPython.display import HTML


def view_x3d(atoms):
    """View atoms inline in a jupyter notbook. This command
    should only be used within a jupyter/ipython notebook.
    
    Args:
        atoms - ase.Atoms, atoms to be rendered"""
    
    output = StringIO()
    atoms.write(output, format='html')
    data = output.getvalue()
    output.close()
    return HTML(data)