forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TeixeiraWater.py
54 lines (42 loc) · 1.74 KB
/
TeixeiraWater.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
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2007 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 +
# pylint: disable=no-init,invalid-name
'''
@author Spencer Howells, ISIS
@date December 05, 2013
'''
import numpy as np
from mantid.api import IFunction1D, FunctionFactory
from scipy import constants
class TeixeiraWater(IFunction1D):
planck_constant = constants.Planck / constants.e * 1E15 # meV*psec
hbar = planck_constant / (2 * np.pi) # meV * ps = ueV * ns
def category(self):
return "QuasiElastic"
def init(self):
# Active fitting parameters
self.declareParameter("Tau", 1.0, 'Residence time')
self.declareParameter("L", 1.5, 'Jump length')
def function1D(self, xvals):
tau = self.getParameterValue("Tau")
length = self.getParameterValue("L")
xvals = np.array(xvals)
with np.errstate(divide='ignore'):
hwhm = self.hbar * \
np.square(xvals * length) / \
(tau * (6 + np.square(xvals * length)))
return hwhm
def functionDeriv1D(self, xvals, jacobian):
tau = self.getParameterValue("Tau")
length = self.getParameterValue("L")
for i, x in enumerate(xvals, start=0):
hwhm = self.hbar * \
np.square(x * length) / (tau * (6 + np.square(x * length)))
jacobian.set(i, 0, -hwhm / tau)
jacobian.set(i, 1, 2 * hwhm * (1.0 - hwhm * tau) / length)
# Required to have Mantid recognise the new function
FunctionFactory.subscribe(TeixeiraWater)