root / ase / calculators / jacapo / mayavis.py @ 7
Historique | Voir | Annoter | Télécharger (1,86 ko)
| 1 |
'''
|
|---|---|
| 2 |
mayavi interface to plot atoms, unit cells, and volumetric data
|
| 3 |
'''
|
| 4 |
import numpy as np |
| 5 |
from enthought.mayavi import mlab |
| 6 |
mlab.figure(1, bgcolor=(1,1,1), size=(350, 350)) |
| 7 |
mlab.clf() |
| 8 |
|
| 9 |
def plot_cylinder(start,end,tube_radius=0.1,color=(0,0,0)): |
| 10 |
|
| 11 |
mlab.plot3d([start[0],end[0]],[start[1],end[1]],[start[2],end[2]], |
| 12 |
tube_radius=tube_radius,color=color) |
| 13 |
|
| 14 |
|
| 15 |
def plot_atoms(atoms): |
| 16 |
|
| 17 |
for atom in atoms: |
| 18 |
pos = atom.get_position() |
| 19 |
mlab.points3d([pos[0]],[pos[1]],[pos[2]], |
| 20 |
scale_factor=4,
|
| 21 |
resolution=20,
|
| 22 |
color=(1,0,0), #this should get species specifuc |
| 23 |
scale_mode='none')
|
| 24 |
|
| 25 |
(u0,u1,u2) = atoms.get_cell() |
| 26 |
origin = np.array([0.0,0.0,0.0]) |
| 27 |
|
| 28 |
plot_cylinder(origin,u0) |
| 29 |
plot_cylinder(origin,u1) |
| 30 |
plot_cylinder(origin,u2) |
| 31 |
|
| 32 |
plot_cylinder(u0,u0+u1) |
| 33 |
plot_cylinder(u0,u0+u2) |
| 34 |
|
| 35 |
plot_cylinder(u1,u1+u0) |
| 36 |
plot_cylinder(u1,u1+u2) |
| 37 |
|
| 38 |
plot_cylinder(u2,u2+u0) |
| 39 |
plot_cylinder(u2,u2+u1) |
| 40 |
|
| 41 |
plot_cylinder(u0+u1,u0+u1+u2) |
| 42 |
plot_cylinder(u1+u2,u0+u1+u2) |
| 43 |
plot_cylinder(u0+u2,u0+u1+u2) |
| 44 |
mlab.show() |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
if __name__ == '__main__': |
| 52 |
from ase.lattice.cubic import * |
| 53 |
|
| 54 |
from ase.lattice.bravais import cross |
| 55 |
import numpy as np |
| 56 |
|
| 57 |
a = np.array([0.5,0,0]) |
| 58 |
c = np.array([0,1,0],dtype=np.float) |
| 59 |
b1 = c - a |
| 60 |
|
| 61 |
a = np.array([0,1,0],np.float) |
| 62 |
c = np.array([0,0.5,0.5]) |
| 63 |
b2 = c - a |
| 64 |
|
| 65 |
a3 = np.array([2,1,1],np.float) |
| 66 |
|
| 67 |
a1 = cross(b1,a3) |
| 68 |
a2 = cross(b2,a3) |
| 69 |
v211 = FaceCenteredCubic(directions=[a1,a2,a3], |
| 70 |
miller=(None,None,[2,1,1]), |
| 71 |
symbol='Pd',
|
| 72 |
size=(1,1,2), |
| 73 |
debug=0)
|
| 74 |
|
| 75 |
uc = v211.get_cell() |
| 76 |
uc[2][2] += 10.0 |
| 77 |
v211.set_cell(uc) |
| 78 |
|
| 79 |
plot_atoms(v211.repeat((2,2,1))) |
| 80 |
|