Statistiques
| Révision :

root / ase / test / geometry.py @ 1

Historique | Voir | Annoter | Télécharger (4,18 ko)

1
"Test the ase.utils.geometry module"
2

    
3
import numpy as np
4

    
5
import ase
6
from ase.lattice.spacegroup import crystal
7
from ase.utils.geometry import get_layers, cut, stack
8

    
9
np.set_printoptions(suppress=True)
10

    
11
al = crystal('Al', [(0,0,0)], spacegroup=225, cellpar=4.05)
12

    
13

    
14
# Cut out slab of 5 Al(001) layers
15
al001 = cut(al, nlayers=5)
16
correct_pos = np.array([[ 0. ,  0. ,  0. ],
17
                        [ 0. ,  0.5,  0.2],
18
                        [ 0.5,  0. ,  0.2],
19
                        [ 0.5,  0.5,  0. ],
20
                        [ 0. ,  0. ,  0.4],
21
                        [ 0. ,  0.5,  0.6],
22
                        [ 0.5,  0. ,  0.6],
23
                        [ 0.5,  0.5,  0.4],
24
                        [ 0. ,  0. ,  0.8],
25
                        [ 0.5,  0.5,  0.8]])
26
assert np.allclose(correct_pos, al001.get_scaled_positions())
27

    
28
# Check layers along 001
29
tags, levels = get_layers(al001, (0, 0, 1))
30
assert np.allclose(tags, [0, 1, 1, 0, 2, 3, 3, 2, 4, 4])
31
assert np.allclose(levels, [ 0., 2.025, 4.05, 6.075, 8.1])
32

    
33
# Check layers along 101
34
tags, levels = get_layers(al001, (1, 0, 1))
35
assert np.allclose(tags, [0, 1, 5, 3, 2, 4, 8, 7, 6, 9])
36
assert np.allclose(levels, [0.000, 0.752, 1.504, 1.880, 2.256,
37
                            2.632, 3.008, 3.384, 4.136, 4.888], atol=0.001)
38

    
39
# Check layers along 111
40
tags, levels = get_layers(al001, (1, 1, 1))
41
assert np.allclose(tags, [0, 2, 2, 4, 1, 5, 5, 6, 3, 7])
42
assert np.allclose(levels, [0.000, 1.102, 1.929, 2.205, 
43
                            2.756, 3.031, 3.858, 4.960], atol=0.001)
44

    
45

    
46
# Cut out slab of three Al(111) layers
47
al111 = cut(al, (1,-1,0), (0,1,-1), nlayers=3)
48
correct_pos = np.array([[ 0.        ,  0.5       ,  0.        ],
49
                        [ 0.5       ,  0.5       ,  0.        ],
50
                        [ 2/3.      ,  5/6.      ,  1/3.      ],
51
                        [ 0.5       ,  0.        ,  0.        ],
52
                        [ 0.        ,  0.        ,  0.        ],
53
                        [ 1/6.      ,  1/3.      ,  1/3.      ],
54
                        [ 2/3.      ,  1/3.      ,  1/3.      ],
55
                        [ 1/3.      ,  1/6.      ,  2/3.      ],
56
                        [ 5/6.      ,  1/6.      ,  2/3.      ],
57
                        [ 5/6.      ,  2/3.      ,  2/3.      ],
58
                        [ 1/6.      ,  5/6.      ,  1/3.      ],
59
                        [ 1/3.      ,  2/3.      ,  2/3.      ]])
60
assert np.allclose(correct_pos, al111.get_scaled_positions())
61

    
62

    
63
# Cut out cell including all corner and edge atoms (non-periodic structure)
64
al = cut(al, extend=1.1)
65
correct_pos = np.array([[ 0. ,  0. ,  0. ],
66
                        [ 0. ,  0.5,  0.5],
67
                        [ 0.5,  0. ,  0.5],
68
                        [ 0.5,  0.5,  0. ],
69
                        [ 0. ,  0. ,  0. ],
70
                        [ 0. ,  0.5,  0.5],
71
                        [ 0. ,  0. ,  0. ],
72
                        [ 0.5,  0. ,  0.5],
73
                        [ 0. ,  0. ,  0. ],
74
                        [ 0. ,  0. ,  0. ],
75
                        [ 0.5,  0.5,  0. ],
76
                        [ 0. ,  0. ,  0. ],
77
                        [ 0. ,  0. ,  0. ],
78
                        [ 0. ,  0. ,  0. ]])
79
assert np.allclose(correct_pos, al.get_scaled_positions())
80

    
81

    
82
# Create an Ag(111)/Si(111) interface
83
ag = crystal(['Ag'], basis=[(0,0,0)], spacegroup=225, cellpar=4.09)
84
si = crystal(['Si'], basis=[(0,0,0)], spacegroup=227, cellpar=5.43)
85

    
86
ag111 = cut(ag, a=(4, -4, 0), b=(4, 4, -8), nlayers=5)
87
si111 = cut(si, a=(3, -3, 0), b=(3, 3, -6), nlayers=5)
88

    
89
interface = stack(ag111, si111)
90
assert len(interface) == 1000
91
assert np.allclose(interface.positions[::100], 
92
                   [[ 28.56875   ,  -2.040625  , -26.528125  ],
93
                    [ 20.40916667,   6.12479167, -22.44395833],
94
                    [ 24.49916667,  12.25541667, -20.39458333],
95
                    [ 24.49041667,  -6.11895833, -14.28145833],
96
                    [ 10.20895833,  10.20895833, -12.23791667],
97
                    [ 24.49625   ,   2.049375  , -14.275625  ],
98
                    [ 16.33375   ,  -4.0725    ,   0.00875   ],
99
                    [ 31.30027778,  12.25444444, -17.67472222],
100
                    [ 25.85861111,  14.97527778, -14.95388889],
101
                    [ 23.13777778,   4.09194444,  -1.34972222]])
102