File: x3d.py

package info (click to toggle)
python-ase 3.26.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,484 kB
  • sloc: python: 148,112; xml: 2,728; makefile: 110; javascript: 47
file content (32 lines) | stat: -rw-r--r-- 780 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
22
23
24
25
26
27
28
29
30
31
32
# fmt: off

"""Inline viewer for jupyter notebook using X3D."""
import warnings

try:
    from StringIO import StringIO
except ImportError:
    from io import StringIO

from ase.io.x3d import write_x3d


def view_x3d(atoms, *args, **kwargs):
    """View atoms inline in a jupyter notebook. This command
    should only be used within a jupyter/ipython notebook.

    Args:
        atoms - ase.Atoms, atoms to be rendered"""
    try:
        from IPython.display import HTML
    except ImportError:
        warnings.warn('Please install IPython')
        return None

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

    temp = StringIO()
    write_x3d(temp, atoms, format='X3DOM', style=notebook_style)
    data = temp.getvalue()
    temp.close()
    return HTML(data)