File: sage.py

package info (click to toggle)
python-ase 3.21.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,936 kB
  • sloc: python: 122,428; xml: 946; makefile: 111; javascript: 47
file content (20 lines) | stat: -rw-r--r-- 829 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from ase.data.colors import jmol_colors
from ase.data import covalent_radii


def view_sage_jmol(atoms):
    try:
        from .sage.plot.plot3d.shapes import ColorCube, Sphere
    except Exception:  # XXX Which kind of exception exactly?
        raise ImportError(
            'view_sage_jmol requires sage (http://www.sagemath.org/) ' +
            'and is intended to be used directly in the browser')
    cell = atoms.cell.diagonal() / 2
    model = ColorCube(list(cell), ['blue', 'blue', 'blue'], opacity=0.1)
    for atom in atoms:
        atomic_number = atom.number
        color = tuple(jmol_colors[atomic_number])
        radius = covalent_radii[atomic_number]
        model += Sphere(radius, color=color).translate(
            *(atom.position - atoms.cell.diagonal() / 2))
    model.show(aspect_ratio=1, frame=False)