-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathrectangleprofile.py
61 lines (41 loc) · 1.58 KB
/
rectangleprofile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
"""Demonstrate user-defined profile function for PDF calculation.
"""
from diffpy.srreal.peakprofile import PeakProfile
class RectangleProfile(PeakProfile):
"""Rectangle profile function with a unit area.
"""
# overload functions from the base class
def __call__(self, x, fwhm):
"""Evaluate rectangle function centered at zero.
x -- independent variable to calculate the profile at
fwhm -- width of the rectangle profile. In PDF simulation
this is determined from displacement parameters of
each contributing pair of atoms.
Return the profile function at x.
"""
y = 0.0
if -fwhm/2.0 < x < +fwhm/2.0:
y = 1.0 / fwhm
return y
def clone(self):
"Return a copy of this profile object."
import copy
return copy.copy(self)
def create(self):
"Return new instance of this profile type."
return RectangleProfile()
def type(self):
"Return unique string identifier for this profile type."
return "rectangleprofile"
def xboundhi(self, fwhm):
"""Upper bound where profile becomes smaller than the requested
precision (self.precision)."""
return +0.5 * fwhm
def xboundlo(self, fwhm):
"""Lower bound where profile becomes smaller than the requested
precision (self.precision)."""
return -0.5 * fwhm
# end of class RectangleProfile
# Register this profile function so it can be assigned by its string type.
RectangleProfile()._registerThisType()