source: sasview/sansmodels/src/sans/models/GuinierPorodModel.py @ 28612ca

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 28612ca was 279e371, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

Fixing code style problems

  • Property mode set to 100644
File size: 3.6 KB
Line 
1"""
2    I(q) = scale/q^s* exp ( - R_g^2 q^2 / (3-s) ) for q<= ql
3        = scale/q^m*exp((-ql^2*Rg^2)/(3-s))*ql^(m-s) for q>=ql
4    Guinier function as a BaseComponent model
5"""
6from sans.models.BaseComponent import BaseComponent
7from math import sqrt,exp
8
9class GuinierPorodModel(BaseComponent):
10    """
11    Class that evaluates a GuinierPorod model.
12
13    I(q) = scale/q^s* exp ( - R_g^2 q^2 / (3-s) ) for q<= ql
14        = scale/q^m*exp((-ql^2*Rg^2)/(3-s))*ql^(m-s) for q>=ql
15    """
16    def __init__(self):
17        """ Initialization """
18       
19        # Initialize BaseComponent first, then sphere
20        BaseComponent.__init__(self)
21       
22        ## Name of the model
23        self.name = "GuinierPorod"
24        self.description = """
25         I(q) = scale/q^s* exp ( - R_g^2 q^2 / (3-s) ) for q<= ql
26         = scale/q^m*exp((-ql^2*Rg^2)/(3-s))*ql^(m-s) for q>=ql
27                        where ql = sqrt((m-s)(3-s)/2)/Rg.
28                        List of parameters:
29                        scale = Guinier Scale
30                        s = Dimension Variable
31                        Rg = Radius of Gyration [A]
32                        m = Porod Exponent
33                        background  = Background [1/cm]"""
34        ## Define parameters
35        self.params = {}
36        self.params['scale']  = 1.0
37        self.params['dim']  = 1.0
38        self.params['rg']     = 100.0
39        self.params['m']     = 3.0
40        self.params['background']     = 0.1
41        ## Parameter details [units, min, max]
42        self.details = {}
43        self.details['scale'] = ['', None, None]
44        self.details['dim']  = ['', None, None]
45        self.details['rg']    = ['[A]', None, None]
46        self.details['m']     = ['', None, None]
47        self.details['background']     = ['[1/cm]', None, None]
48
49        #list of parameter that cannot be fitted
50        self.fixed = [] 
51       
52    def _guinier_porod(self, x):
53        """
54        Guinier-Porod Model
55        """
56        # parameters
57        G = self.params['scale']
58        s = self.params['dim']
59        Rg = self.params['rg']
60        m = self.params['m']
61        bgd = self.params['background']
62        n = 3.0 - s
63        qval = x
64       
65        #do the calculation and return the function value
66        q1 = sqrt((n-3.0+m)*n/2.0)/Rg
67        if qval < q1:
68            F = (G/pow(qval,(3.0-n)))*exp((-qval*qval*Rg*Rg)/n) 
69        else:
70            F = (G/pow(qval, m))*exp(-(n-3.0+m)/2.0)*pow(((n-3.0+m)*n/2.0),
71                                        ((n-3.0+m)/2.0))/pow(Rg,(n-3.0+m))
72        inten = F + bgd
73   
74        return inten
75   
76    def run(self, x = 0.0):
77        """ Evaluate the model
78            @param x: input q-value (float or [float, float] as [r, theta])
79            @return: (guinier value)
80        """
81        if x.__class__.__name__ == 'list':
82            return self._guinier_porod(x[0])
83        elif x.__class__.__name__ == 'tuple':
84            raise ValueError, "Tuples are not allowed as input to models"
85        else:
86            return self._guinier_porod(x)
87   
88    def runXY(self, x = 0.0):
89        """ Evaluate the model
90            @param x: input q-value (float or [float, float] as [qx, qy])
91            @return: guinier value
92        """
93        if x.__class__.__name__ == 'list':
94            q = sqrt(x[0]**2 + x[1]**2)
95            return self._guinier_porod(q)
96        elif x.__class__.__name__ == 'tuple':
97            raise ValueError, "Tuples are not allowed as input to models"
98        else:
99            return self._guinier_porod(x)
Note: See TracBrowser for help on using the repository browser.