~ubuntu-branches/ubuntu/trusty/mayavi2/trusty

« back to all changes in this revision

Viewing changes to examples/mayavi/mlab/chemistry.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-07-09 01:18:36 UTC
  • mfrom: (1.1.10 upstream) (2.2.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110709011836-fha21zirlgkqh92s
Tags: 4.0.0-1
* New upstream release
* debian/control:
  - Bump Standards-Version to 3.9.2
  - Set X-Python-Version: 2.6, fixes FTBFS (Closes: #625148)
  - Update Depends
* Update debian/watch file
* Cleanup debian/rules file

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
The electron localization function is displayed using volume rendering.
9
9
Good use of the `vmin` and `vmax` argument to
10
 
`mlab.pipeline.volume` is critical to achieve a good visualization: the 
 
10
`mlab.pipeline.volume` is critical to achieve a good visualization: the
11
11
`vmin` threshold should placed high-enough for features to stand out.
12
12
 
13
13
The original is an electron localization function from Axel Kohlmeyer.
14
14
"""
15
 
# Author: Gael Varoquaux <gael.varoquaux@normalesup.org> 
 
15
# Author: Gael Varoquaux <gael.varoquaux@normalesup.org>
16
16
# Copyright (c) 2008, Enthought, Inc.
17
17
# License: BSD Style.
18
18
 
25
25
    opener = urllib.urlopen(
26
26
        'http://code.enthought.com/projects/mayavi/data/h2o-elf.cube'
27
27
        )
28
 
    open('h2o-elf.cube', 'w').write(opener.read())
 
28
    open('h2o-elf.cube', 'wb').write(opener.read())
29
29
 
30
30
 
31
31
# Plot the atoms and the bonds #################################################
32
32
import numpy as np
33
 
from enthought.mayavi import mlab
 
33
from mayavi import mlab
34
34
mlab.figure(1, bgcolor=(0, 0, 0), size=(350, 350))
35
35
mlab.clf()
36
36
 
39
39
atoms_y = np.array([3.0, 3.0, 3.0])*40/5.5
40
40
atoms_z = np.array([3.8, 2.9, 2.7])*40/5.5
41
41
 
42
 
O = mlab.points3d(atoms_x[1:-1], atoms_y[1:-1], atoms_z[1:-1], 
 
42
O = mlab.points3d(atoms_x[1:-1], atoms_y[1:-1], atoms_z[1:-1],
43
43
                  scale_factor=3,
44
44
                  resolution=20,
45
45
                  color=(1, 0, 0),
46
46
                  scale_mode='none')
47
47
 
48
 
H1 = mlab.points3d(atoms_x[:1], atoms_y[:1], atoms_z[:1], 
 
48
H1 = mlab.points3d(atoms_x[:1], atoms_y[:1], atoms_z[:1],
49
49
                   scale_factor=2,
50
50
                   resolution=20,
51
51
                   color=(1, 1, 1),
52
52
                   scale_mode='none')
53
53
 
54
 
H2 = mlab.points3d(atoms_x[-1:], atoms_y[-1:], atoms_z[-1:], 
 
54
H2 = mlab.points3d(atoms_x[-1:], atoms_y[-1:], atoms_z[-1:],
55
55
                   scale_factor=2,
56
56
                   resolution=20,
57
57
                   color=(1, 1, 1),
59
59
 
60
60
# The bounds between the atoms, we use the scalar information to give
61
61
# color
62
 
mlab.plot3d(atoms_x, atoms_y, atoms_z, [1, 2, 1], 
 
62
mlab.plot3d(atoms_x, atoms_y, atoms_z, [1, 2, 1],
63
63
            tube_radius=0.4, colormap='Reds')
64
64
 
65
65
# Display the electron localization function ###################################
72
72
source = mlab.pipeline.scalar_field(data)
73
73
min = data.min()
74
74
max = data.max()
75
 
vol = mlab.pipeline.volume(source, vmin=min+0.65*(max-min), 
 
75
vol = mlab.pipeline.volume(source, vmin=min+0.65*(max-min),
76
76
                                   vmax=min+0.9*(max-min))
77
77
 
78
78
mlab.view(132, 54, 45, [21, 20, 21.5])