source: sasview/sansmodels/src/sans/models/GaussLorentzGelModel.py @ 1aaa579

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 1aaa579 was 8f20419d, checked in by Jae Cho <jhjcho@…>, 14 years ago

more models and some tests

  • Property mode set to 100644
File size: 3.3 KB
Line 
1#!/usr/bin/env python
2"""
3Provide I(q) = I_0 exp ( - R_g^2 q^2 / 3.0)
4GaussLorentzGel function as a BaseComponent model
5"""
6
7from sans.models.BaseComponent import BaseComponent
8from math import exp
9
10class GaussLorentzGelModel(BaseComponent):
11    """
12    Class that evaluates a GaussLorentzGel model.
13
14    I(q) = scale_g*exp(- q^2*Z^2 / 2)+scale_l/(1+q^2*z^2)
15            + background
16    List of default parameters:
17     scale_g = Gauss scale factor
18     Z = Static correlation length
19     scale_l = Lorentzian scale factor
20     z = Dynamic correlation length
21     background = Incoherent background
22    """
23       
24    def __init__(self):
25        """ Initialization """
26       
27        # Initialize BaseComponent first, then sphere
28        BaseComponent.__init__(self)
29       
30        ## Name of the model
31        self.name = "GaussLorentzGel"
32        self.description="""I(q)=scale_g*exp(-q^2*Z^2/2)+scale_l/(1+q^2*z^2)
33            + background
34            List of default parameters:
35             scale_g = Gauss scale factor
36             stat_colength = Static correlation length
37             scale_l = Lorentzian scale factor
38             dyn_colength = Dynamic correlation length
39             background = Incoherent background
40"""
41        ## Define parameters
42        self.params = {}
43        self.params['scale_g']  = 100.0
44        self.params['stat_colength']     = 100.0
45        self.params['scale_l']  = 50.0
46        self.params['dyn_colength']     = 20.0
47        self.params['background']     = 0.0
48        ## Parameter details [units, min, max]
49        self.details = {}
50        self.details['scale_g'] = ['', None, None]
51        self.details['stat_colength'] =  ['A', None, None]
52        self.details['scale_l']  =  ['', None, None]
53        self.details['dyn_colength']  =   ['A', None, None]
54        self.details['background']   =  ['[1/cm]', None, None]
55
56        #list of parameter that cannot be fitted
57        self.fixed= [] 
58    def _gausslorentzgel(self, x):
59        """
60        Model definition
61        """
62        inten = self.params['scale_g']*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 BaseComponent 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 BaseComponent models"
90        else:
91            return self._gausslorentzgel(x)
Note: See TracBrowser for help on using the repository browser.