forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MsdYi.py
57 lines (45 loc) · 2.04 KB
/
MsdYi.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
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2007-8 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
import math
import numpy as np
from mantid.api import IFunction1D, FunctionFactory
# The model of Yi et al(J Phys Chem B 116 5028 2012) takes into account motional heterogeneity.
# The elastic intensity is proportional to exp(-(1/6)*Q^2*msd)*(1+Q^4*sigma/72)
# where the mean square displacement msd = <r^2> and sigma^2 is the variance of the msd.
# In the limit sigma = 0 the model becomes Gaussian.
class MsdYi(IFunction1D):
def category(self):
return "QuasiElastic"
def init(self):
# Active fitting parameters
self.declareParameter("Height", 1.0, 'Height')
self.declareParameter("Msd", 0.05, 'Mean square displacement')
self.declareParameter("Sigma", 1.0, 'Sigma')
def function1D(self, xvals):
height = self.getParameterValue("Height")
msd = self.getParameterValue("Msd")
sigma = self.getParameterValue("Sigma")
xvals = np.array(xvals)
i1 = np.exp((-1.0 / 6.0) * xvals * xvals * msd)
i2 = 1.0 + (np.power(xvals, 4) * sigma / 72.0)
intensity = height * i1 * i2
return intensity
def functionDeriv1D(self, xvals, jacobian):
height = self.getParameterValue("Height")
msd = self.getParameterValue("Msd")
sigma = self.getParameterValue("Sigma")
for i, x in enumerate(xvals):
f1 = math.exp((-1.0 / 6.0) * x * x * msd)
df1 = -f1 * ((2.0 / 6.0) * x * msd)
x4 = math.pow(x, 4)
f2 = 1.0 + (x4 * sigma / 72.0)
df2 = x4 / 72.0
jacobian.set(i, 0, f1 * f2)
jacobian.set(i, 1, height * df1 * f2)
jacobian.set(i, 2, height * f1 * df2)
# Required to have Mantid recognise the new function
FunctionFactory.subscribe(MsdYi)