Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1from ase.data.colors import jmol_colors 

2from ase.data import covalent_radii 

3 

4 

5def view_sage_jmol(atoms): 

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') 

12 cell = atoms.cell.diagonal() / 2 

13 model = ColorCube(list(cell), ['blue', 'blue', 'blue'], opacity=0.1) 

14 for atom in atoms: 

15 atomic_number = atom.number 

16 color = tuple(jmol_colors[atomic_number]) 

17 radius = covalent_radii[atomic_number] 

18 model += Sphere(radius, color=color).translate( 

19 *(atom.position - atoms.cell.diagonal() / 2)) 

20 model.show(aspect_ratio=1, frame=False)