Coverage for /builds/kinetik161/ase/ase/visualize/sage.py: 22.22%
18 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-12-10 11:04 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-12-10 11:04 +0000
1from ase.data import covalent_radii
2from ase.data.colors import jmol_colors
5def view_sage_jmol(atoms, repeat=None, *args, **kwargs):
6 try:
7 from .sage.plot.plot3d.shapes import ColorCube, Sphere
8 except Exception: # XXX Which kind of exception exactly?
9 raise ImportError(
10 'view_sage_jmol requires sage (http://www.sagemath.org/) ' +
11 'and is intended to be used directly in the browser')
13 if repeat is not None:
14 atoms = atoms.repeat(repeat)
16 cell = atoms.cell.diagonal() / 2
17 model = ColorCube(list(cell), ['blue', 'blue', 'blue'], opacity=0.1)
18 for atom in atoms:
19 atomic_number = atom.number
20 color = tuple(jmol_colors[atomic_number])
21 radius = covalent_radii[atomic_number]
22 model += Sphere(radius, color=color).translate(
23 *(atom.position - atoms.cell.diagonal() / 2))
24 model.show(aspect_ratio=1, frame=False)
27view_sage = view_sage_jmol