source: sasview/src/sas/models/GuinierModel.py @ f4c0513

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 f4c0513 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: 2.4 KB
Line 
1"""
2    Provide I(q) = I_0 exp ( - R_g^2 q^2 / 3.0)
3    Guinier function as a BaseComponent model
4"""
5from sas.models.BaseComponent import BaseComponent
6import math
7
8class GuinierModel(BaseComponent):
9    """
10        Class that evaluates a Guinier model.
11   
12        I(q) = I_0 exp ( - R_g^2 q^2 / 3.0 )
13       
14        List of default parameters:
15         I_0 = Scale
16         R_g = Radius of gyration
17         
18    """
19       
20    def __init__(self):
21        """ Initialization """
22       
23        # Initialize BaseComponent first, then sphere
24        BaseComponent.__init__(self)
25       
26        ## Name of the model
27        self.name = "Guinier"
28        self.description = """ I(q) = I_0 exp ( - R_g^2 q^2 / 3.0 )
29       
30                        List of default parameters:
31                        I_0 = Scale
32                        R_g = Radius of gyration"""
33        ## Define parameters
34        self.params = {}
35        self.params['scale']  = 1.0
36        self.params['rg']     = 60
37
38        ## Parameter details [units, min, max]
39        self.details = {}
40        self.details['scale'] = ['[1/cm]', None, None]
41        self.details['rg']    = ['[A]', None, None]
42        #list of parameter that cannot be fitted
43        self.fixed = [] 
44       
45    def _guinier(self, x):
46        """
47            Evaluate guinier function
48            :param x: q-value
49        """
50        return self.params['scale']*math.exp( -(self.params['rg']*x)**2/3.0 ) 
51   
52    def run(self, x = 0.0):
53        """
54            Evaluate the model
55            @param x: input q-value (float or [float, float] as [r, theta])
56            @return: (guinier value)
57        """
58        if x.__class__.__name__ == 'list':
59            return self._guinier(x[0])
60        elif x.__class__.__name__ == 'tuple':
61            raise ValueError, "Tuples are not allowed as input to models"
62        else:
63            return self._guinier(x)
64   
65    def runXY(self, x = 0.0):
66        """ Evaluate the model
67            @param x: input q-value (float or [float, float] as [qx, qy])
68            @return: guinier value
69        """
70        if x.__class__.__name__ == 'list':
71            q = math.sqrt(x[0]**2 + x[1]**2)
72            return self._guinier(q)
73        elif x.__class__.__name__ == 'tuple':
74            raise ValueError, "Tuples are not allowed as input to models"
75        else:
76            return self._guinier(x)
Note: See TracBrowser for help on using the repository browser.