Statistiques
| Révision :

root / ase / examples / plot-ase-atoms.py @ 3

Historique | Voir | Annoter | Télécharger (1,25 ko)

1
from ase import Atoms, Atom, view
2
from gpaw import GPAW
3

    
4
logo = """\
5
 H   HH HHH
6
H H H   H
7
HHH  H  HH
8
H H   H H
9
H H HH  HHH"""
10

    
11
d = 0.8
12
atoms = Atoms()
13
for y, line in enumerate(logo.split('\n')):
14
    for x, c in enumerate(line):
15
        if c == 'H':
16
            atoms.append(Atom('H', [d * x, -d * y, 0]))
17
atoms.center(vacuum=2.0)
18
view(atoms)
19

    
20
if 0:
21
    calc = GPAW(nbands=30)
22
    atoms.set_calculator(calc)
23
    atoms.get_potential_energy()
24
    calc.write('ase-logo.gpw')
25
else:
26
    calc = GPAW('ase-logo.gpw', txt=None)
27

    
28
density = calc.get_pseudo_density()
29
image = density[..., density.shape[2] // 2]
30

    
31
if 1: # scale colors to wiki background / foreground
32
    import numpy as np
33
    background = np.array([[[19., 63., 82.]]]).T / 255 # 1c4e63 blueish
34
    foreground = np.array([[[1., 1., 1.]]]).T  # white
35
    image = background + image / image.max() * (foreground - background)
36
    image = image.T
37
else: # Use a standard color scheme
38
    image = pl.cm.hot(image.T)
39

    
40
import pylab as pl
41
x, y, z = atoms.cell.diagonal()
42
pl.figure(1, figsize=(8, 8 * y / x), dpi=80)
43
pl.axes([0, 0, 1, 1])
44
pl.imshow(image,
45
          origin='lower',
46
          extent=[0, x, 0, y],
47
          aspect='equal',
48
          interpolation='spline16')
49
pl.axis('off')
50
pl.savefig('ase-logo.png', dpi=80)
51
pl.show()