source: sasview/sansmodels/src/sans/models/DebyeModel.py @ 95986b5

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 95986b5 was 96672c0, checked in by Gervaise Alina <gervyh@…>, 16 years ago

code for description modified

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