source: sasview/sansmodels/src/sans/models/GuinierModel.py @ 55e13ab

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 55e13ab was 922b0d1, checked in by Gervaise Alina <gervyh@…>, 16 years ago

guinier model description

  • Property mode set to 100644
File size: 2.3 KB
Line 
1#!/usr/bin/env python
2"""
3    Provide I(q) = I_0 exp ( - R_g^2 q^2 / 3.0)
4    Guinier function as a BaseComponent model
5"""
6
7from sans.models.BaseComponent import BaseComponent
8import math
9
10class GuinierModel(BaseComponent):
11    """
12        Class that evaluates a Guinier model.
13   
14        I(q) = I_0 exp ( - R_g^2 q^2 / 3.0 )
15     
16        List of default parameters:
17         I_0 = Scale
18         R_g = Radius of gyration
19         
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 = "Guinier"
30        self.description=" I(q) = I_0 exp ( - R_g^2 q^2 / 3.0 )\
31                        List of default parameters:\
32                        I_0 = Scale\
33                        R_g = Radius of gyration"
34        ## Define parameters
35        self.params = {}
36        self.params['scale']  = 1.0
37        self.params['rg']     = 0.1
38
39        ## Parameter details [units, min, max]
40        self.details = {}
41        self.details['scale'] = ['cm-1', None, None]
42        self.details['rg']    = ['A', None, None]
43               
44    def _guinier(self, x):
45        return self.params['scale'] * math.exp( -(self.params['rg']*x)**2 / 3.0 ) 
46   
47    def run(self, x = 0.0):
48        """ Evaluate the model
49            @param x: input q-value (float or [float, float] as [r, theta])
50            @return: (guinier value)
51        """
52        if x.__class__.__name__ == 'list':
53            return self._guinier(x[0])
54        elif x.__class__.__name__ == 'tuple':
55            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
56        else:
57            return self._guinier(x)
58   
59    def runXY(self, x = 0.0):
60        """ Evaluate the model
61            @param x: input q-value (float or [float, float] as [qx, qy])
62            @return: guinier value
63        """
64        if x.__class__.__name__ == 'list':
65            q = math.sqrt(x[0]**2 + x[1]**2)
66            return self._guinier(q)
67        elif x.__class__.__name__ == 'tuple':
68            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
69        else:
70            return self._guinier(x)
Note: See TracBrowser for help on using the repository browser.