root / ase / xrdebye.py @ 15
Historique | Voir | Annoter | Télécharger (3,57 ko)
1 |
from math import exp, pi, sin, sqrt, cos, acos |
---|---|
2 |
import numpy as np |
3 |
|
4 |
from ase.data import atomic_numbers |
5 |
|
6 |
# Table (1) of
|
7 |
# D. WAASMAIER AND A. KIRFEL, Acta Cryst. (1995). A51, 416-431
|
8 |
waasmaier = { |
9 |
# a1 b1 a2 b2 a3 b3 a4 b4 a5 b5 c
|
10 |
'C' : [2.657506, 14.780758, 1.078079, 0.776775, 1.490909, 42.086843, -4.241070, -0.000294, 0.713791, 0.239535, 4.297983], |
11 |
'S' : [6.372157, 1.514347, 5.154568, 22.092528, 1.473732, 0.061373, 1.635073, 55.445176, 1.209372, 0.646925, 0.154722], |
12 |
'Pd': [6.121511, 0.062549, 4.784063, 0.784031, 16.631683, 8.751391, 4.318258, 34.489983, 13.246773, 0.784031, 0.883099], |
13 |
'Ag': [6.073874, 0.055333, 17.155437, 7.896512, 4.173344, 28.443739, 0.852238, 110.376108, 17.988685, 0.716809, 0.756603], |
14 |
'Au': [16.777389, 0.122737, 19.317156, 8.621570, 32.979682, 1.256902, 5.595453, 38.008821, 10.576854, 0.000601, -6.279078], |
15 |
'P' : [1.950541, 0.908139, 4.146930, 27.044953, 1.494560, 0.071280, 1.522042, 67.520190, 5.729711, 1.981173, 0.155233], |
16 |
'Cl': [1.446071, 0.052357, 6.870609, 1.193165, 6.151801, 18.343416, 1.750347, 46.398394, 0.634168, 0.401005, 0.146773], |
17 |
} |
18 |
|
19 |
class XrDebye: |
20 |
def __init__(self, wavelength, alpha=1.01, damping=0.04, warn=True, |
21 |
method='Iwasa'):
|
22 |
"""
|
23 |
Obtain powder x-ray spectra.
|
24 |
|
25 |
wavelength in Angstrom
|
26 |
damping in Angstrom**2
|
27 |
"""
|
28 |
self.wavelength = wavelength
|
29 |
self.damping = damping
|
30 |
self.alpha = alpha
|
31 |
self.warn = warn
|
32 |
self.method = method
|
33 |
|
34 |
def set_damping(self, damping): |
35 |
self.damping = damping
|
36 |
|
37 |
def get(self, atoms, s): |
38 |
"""Get the powder x-ray (XRD) pattern using the Debye-Formula.
|
39 |
|
40 |
After: T. Iwasa and K. Nobusada, J. Phys. Chem. C 111 (2007) 45
|
41 |
s is assumed to be in 1/Angstrom
|
42 |
"""
|
43 |
|
44 |
sinth = self.wavelength * s / 2. |
45 |
costh = sqrt(1. - sinth**2) |
46 |
cos2th = cos(2. * acos(costh))
|
47 |
pre = exp(- self.damping * s**2 / 2) |
48 |
|
49 |
if self.method == 'Iwasa': |
50 |
pre *= costh / (1. + self.alpha * cos2th**2) |
51 |
|
52 |
f = {} |
53 |
def atomic(symbol): |
54 |
if not f.has_key(symbol): |
55 |
if self.method == 'Iwasa': |
56 |
f[symbol] = self.get_waasmaier(symbol, s)
|
57 |
else:
|
58 |
f[symbol] = atomic_numbers[symbol] |
59 |
return f[symbol]
|
60 |
|
61 |
def sinc(x): |
62 |
if x < 1.e-6: |
63 |
x2 = x * x |
64 |
return 1 - x2 / 6. + x2 * x2 / 120. |
65 |
else:
|
66 |
return sin(x) / x
|
67 |
|
68 |
I = 0.
|
69 |
for a in atoms: |
70 |
fa = atomic(a.symbol) |
71 |
# print a.symbol, fa
|
72 |
for b in atoms: |
73 |
fb = atomic(b.symbol) |
74 |
|
75 |
if a == b:
|
76 |
twopis = 0.
|
77 |
else:
|
78 |
vrij = a.position - b.position |
79 |
rij = np.sqrt(np.dot(vrij, vrij)) |
80 |
twopisr = 2 * pi * s * rij
|
81 |
|
82 |
I += fa * fb * sinc(twopisr) |
83 |
|
84 |
return pre * I
|
85 |
|
86 |
def get_waasmaier(self, symbol, s): |
87 |
"""Scattering factor for free atoms."""
|
88 |
if symbol == 'H': |
89 |
# XXXX implement analytical H
|
90 |
return 0 |
91 |
elif waasmaier.has_key(symbol):
|
92 |
abc = waasmaier[symbol] |
93 |
f = abc[10]
|
94 |
s2 = s*s |
95 |
for i in range(5): |
96 |
f += abc[2 * i] * exp(-abc[2 * i + 1] * s2) |
97 |
return f
|
98 |
if self.warn: |
99 |
print '<xrdebye::get_atomic> Element', symbol, 'not available' |
100 |
return 0 |
101 |
|