Skip to content

Commit ad048da

Browse files
author
jensj
committed
Small fix for non-orthogonal cells. Also shifted points to (0,0,0)
1 parent 51eef64 commit ad048da

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

ase/visualize/mlab.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ def plot(atoms, data, contours):
2424

2525
# Delay slow imports:
2626
from mayavi import mlab
27-
from tvtk.api import tvtk
28-
import mayavi.tools.pipeline
2927

3028
mlab.figure(1, bgcolor=(1, 1, 1)) # make a white figure
3129

@@ -38,7 +36,6 @@ def plot(atoms, data, contours):
3836

3937
# Draw the unit cell:
4038
A = atoms.cell
41-
print('A=%s' % str(A))
4239
for i1, a in enumerate(A):
4340
i2 = (i1 + 1) % 3
4441
i3 = (i1 + 2) % 3
@@ -51,17 +48,18 @@ def plot(atoms, data, contours):
5148
[p1[2], p2[2]],
5249
tube_radius=0.1)
5350

54-
cp = mlab.contour3d(data, contours=contours)
55-
# Do some tvtk magic in order to allow for non-orthogonal unit cells
51+
cp = mlab.contour3d(data, contours=contours, transparent=True,
52+
opacity=0.5, colormap='hot')
53+
# Do some tvtk magic in order to allow for non-orthogonal unit cells:
5654
polydata = cp.actor.actors[0].mapper.input
57-
pts = np.array(polydata.points)
58-
# Transform the points to the unit cell
59-
polydata.points = np.dot(pts, A / data.shape)
55+
pts = np.array(polydata.points) - 1
56+
# Transform the points to the unit cell:
57+
polydata.points = np.dot(pts, A / np.array(data.shape)[:, np.newaxis])
6058

6159
# Apparently we need this to redraw the figure, maybe it can be done in
6260
# another way?
6361
mlab.view(azimuth=155, elevation=70, distance='auto')
64-
# Show the 3d plot
62+
# Show the 3d plot:
6563
mlab.show()
6664

6765

0 commit comments

Comments
 (0)