source: sasview/src/sans/models/DebyeModel.py @ 6b20c4e

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 6b20c4e was 5777106, checked in by Mathieu Doucet <doucetm@…>, 11 years ago

Moving things around. Will definitely not build.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1"""
2    Provide F(x) = 2( exp(-x) + x - 1 )/x**2
3    with x = (q*R_g)**2
4   
5    Debye function as a BaseComponent model
6"""
7from sans.models.BaseComponent import BaseComponent
8import math
9
10class DebyeModel(BaseComponent):
11    """
12        Class that evaluates a Debye model.
13       
14        F(x) = 2( exp(-x) + x - 1 )/x**2
15        with x = (q*R_g)**2
16       
17        The model has three parameters:
18            Rg     =  radius of gyration
19            scale  =  scale factor
20            bkd    =  Constant background
21    """
22       
23    def __init__(self):
24        """ Initialization """
25       
26        # Initialize BaseComponent first, then sphere
27        BaseComponent.__init__(self)
28       
29        ## Name of the model
30        self.name = "Debye"
31        self.description = """
32        F(x) = 2( exp(-x) + x - 1 )/x**2
33        with x = (q*R_g)**2
34       
35        The model has three parameters:
36        Rg     =  radius of gyration
37        scale  =  scale factor
38        bkd    =  Constant background
39        """
40        ## Define parameters
41        self.params = {}
42        self.params['rg']          = 50.0
43        self.params['scale']       = 1.0
44        self.params['background']  = 0.0
45
46        ## Parameter details [units, min, max]
47        self.details = {}
48        self.details['rg']         = ['[A]', None, None]
49        self.details['scale']      = ['', None, None]
50        self.details['background'] = ['[1/cm]', None, None]
51        #list of parameter that cannot be fitted
52        self.fixed = [] 
53             
54    def _debye(self, x):
55        """
56            Evaluate F(x)= scale * D + bkd
57            has 2 internal parameters :
58                    D = 2 * (exp(-y) + y - 1)/y**2
59                    y = (x * Rg)^(2)
60        """
61        # Note that a zero denominator value will raise
62        # an exception
63        y = (x * self.params['rg'])**2.0
64        if x == 0:
65            D = 1
66        else:
67            D = 2.0*( math.exp(-y) + y -1.0 )/y**2.0
68        return self.params['scale'] * D + self.params['background']
69   
70    def run(self, x = 0.0):
71        """ Evaluate the model
72            @param x: input q-value (float or [float, float] as [r, theta])
73            @return: (debye value)
74        """
75        if x.__class__.__name__ == 'list':
76            return self._debye(x[0])
77        elif x.__class__.__name__ == 'tuple':
78            raise ValueError, "Tuples are not allowed as input to models"
79        else:
80            return self._debye(x)
81   
82    def runXY(self, x = 0.0):
83        """ Evaluate the model
84            @param x: input q-value (float or [float, float] as [qx, qy])
85            @return: debye value
86        """
87        if x.__class__.__name__ == 'list':
88            q = math.sqrt(x[0]**2 + x[1]**2)
89            return self._debye(q)
90        elif x.__class__.__name__ == 'tuple':
91            raise ValueError, "Tuples are not allowed as input to models"
92        else:
93            return self._debye(x)
Note: See TracBrowser for help on using the repository browser.