source: sasview/src/sas/models/DebyeModel.py @ bc202cb

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 bc202cb was 79492222, checked in by krzywon, 10 years ago

Changed the file and folder names to remove all SANS references.

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