source: sasview/src/sas/models/GaussLorentzGelModel.py @ 686fd10

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 686fd10 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.3 KB
Line 
1"""
2    Provide I(q) = I_0 exp ( - R_g^2 q^2 / 3.0)
3    GaussLorentzGel function as a BaseComponent model
4"""
5from sas.models.BaseComponent import BaseComponent
6import math
7
8class GaussLorentzGelModel(BaseComponent):
9    """
10    Class that evaluates a GaussLorentzGel model.
11
12    I(q) = scale_g*exp(- q^2*Z^2 / 2)+scale_l/(1+q^2*z^2)
13            + background
14    List of default parameters:
15     scale_g = Gauss scale factor
16     Z = Static correlation length
17     scale_l = Lorentzian scale factor
18     z = Dynamic correlation length
19     background = Incoherent background
20    """
21       
22    def __init__(self):
23        """ Initialization """
24       
25        # Initialize BaseComponent first, then sphere
26        BaseComponent.__init__(self)
27       
28        ## Name of the model
29        self.name = "GaussLorentzGel"
30        self.description = """I(q)=scale_g*exp(-q^2*Z^2/2)+scale_l/(1+q^2*z^2)
31            + background
32            List of default parameters:
33             scale_g = Gauss scale factor
34             stat_colength = Static correlation length
35             scale_l = Lorentzian scale factor
36             dyn_colength = Dynamic correlation length
37             background = Incoherent background
38"""
39        ## Define parameters
40        self.params = {}
41        self.params['scale_g']  = 100.0
42        self.params['stat_colength']     = 100.0
43        self.params['scale_l']  = 50.0
44        self.params['dyn_colength']     = 20.0
45        self.params['background']     = 0.0
46        ## Parameter details [units, min, max]
47        self.details = {}
48        self.details['scale_g'] = ['', None, None]
49        self.details['stat_colength'] =  ['A', None, None]
50        self.details['scale_l']  =  ['', None, None]
51        self.details['dyn_colength']  =   ['A', None, None]
52        self.details['background']   =  ['[1/cm]', None, None]
53
54        #list of parameter that cannot be fitted
55        self.fixed = [] 
56       
57    def _gausslorentzgel(self, x):
58        """
59        Model definition
60        """
61        inten = self.params['scale_g'] \
62                *math.exp(-1.0*x*x*self.params['stat_colength']* \
63                self.params['stat_colength']/2.0) + self.params['scale_l']/ \
64                (1.0 + (x*self.params['dyn_colength'])* \
65                 (x*self.params['dyn_colength'])) + self.params['background']
66        return inten 
67   
68    def run(self, x = 0.0):
69        """ Evaluate the model
70            @param x: input q-value (float or [float, float] as [r, theta])
71            @return: (guinier value)
72        """
73        if x.__class__.__name__ == 'list':
74            return self._gausslorentzgel(x[0])
75        elif x.__class__.__name__ == 'tuple':
76            raise ValueError, "Tuples are not allowed as input to models"
77        else:
78            return self._gausslorentzgel(x)
79   
80    def runXY(self, x = 0.0):
81        """ Evaluate the model
82            @param x: input q-value (float or [float, float] as [qx, qy])
83            @return: guinier value
84        """
85        if x.__class__.__name__ == 'list':
86            q = math.sqrt(x[0]**2 + x[1]**2)
87            return self._gausslorentzgel(q)
88        elif x.__class__.__name__ == 'tuple':
89            raise ValueError, "Tuples are not allowed as input to models"
90        else:
91            return self._gausslorentzgel(x)
Note: See TracBrowser for help on using the repository browser.