source: sasview/src/sas/models/GuinierModel.py @ 4ee041f

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