荒っぽい結晶構造ビューア using Mayavi

import numpy as np
import sys
from phonopy.vasp import read_vasp
from enthought.mayavi import mlab

def line_plot( m, n, pt ):
    mlab.plot3d( [pt[m][0], pt[n][0]],
                 [pt[m][1], pt[n][1]],
                 [pt[m][2], pt[n][2]],
                 tube_radius=0.025, colormap='Spectral')

cell = read_vasp(sys.argv[1])
pos = cell.get_positions()
x = pos[:,0]
y = pos[:,1]
z = pos[:,2]
s = cell.get_masses()
mlab.points3d(x, y, z, s, resolution=20, scale_factor=.025)

lat = cell.get_cell()
origin = np.zeros(3)
pt = [ origin,
       lat[0],
       lat[1],
       lat[2],
       lat[0]+lat[1],
       lat[1]+lat[2],
       lat[2]+lat[0],
       lat[0]+lat[1]+lat[2] ]

line_plot( 0, 1, pt )
line_plot( 0, 2, pt )
line_plot( 0, 3, pt )
line_plot( 4, 7, pt )
line_plot( 5, 7, pt )
line_plot( 6, 7, pt )
line_plot( 1, 4, pt )
line_plot( 2, 5, pt )
line_plot( 3, 6, pt )
line_plot( 1, 6, pt )
line_plot( 2, 4, pt )
line_plot( 3, 5, pt )

mlab.show()