source: sasview/src/sas/models/GuinierPorodModel.py @ 5f0be1f

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 5f0be1f 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: 3.7 KB
RevLine 
[8f20419d]1"""
[279e371]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
[8f20419d]5"""
[79492222]6from sas.models.BaseComponent import BaseComponent
[8f20419d]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"
[279e371]24        self.description = """
25         I(q) = scale/q^s* exp ( - R_g^2 q^2 / (3-s) ) for q<= ql
[8f20419d]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
[279e371]50        self.fixed = [] 
[8f20419d]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
[3be2eb6]64        # take care of the singular points
65        if Rg <= 0.0:
66            return bgd
67        if (n-3.0+m) <= 0.0:
68            return bgd
[8f20419d]69        #do the calculation and return the function value
[279e371]70        q1 = sqrt((n-3.0+m)*n/2.0)/Rg
[8f20419d]71        if qval < q1:
72            F = (G/pow(qval,(3.0-n)))*exp((-qval*qval*Rg*Rg)/n) 
73        else:
[279e371]74            F = (G/pow(qval, m))*exp(-(n-3.0+m)/2.0)*pow(((n-3.0+m)*n/2.0),
[8f20419d]75                                        ((n-3.0+m)/2.0))/pow(Rg,(n-3.0+m))
76        inten = F + bgd
77   
78        return inten
79   
80    def run(self, x = 0.0):
81        """ Evaluate the model
82            @param x: input q-value (float or [float, float] as [r, theta])
83            @return: (guinier value)
84        """
85        if x.__class__.__name__ == 'list':
86            return self._guinier_porod(x[0])
87        elif x.__class__.__name__ == 'tuple':
[279e371]88            raise ValueError, "Tuples are not allowed as input to models"
[8f20419d]89        else:
90            return self._guinier_porod(x)
91   
92    def runXY(self, x = 0.0):
93        """ Evaluate the model
94            @param x: input q-value (float or [float, float] as [qx, qy])
95            @return: guinier value
96        """
97        if x.__class__.__name__ == 'list':
98            q = sqrt(x[0]**2 + x[1]**2)
99            return self._guinier_porod(q)
100        elif x.__class__.__name__ == 'tuple':
[279e371]101            raise ValueError, "Tuples are not allowed as input to models"
[8f20419d]102        else:
103            return self._guinier_porod(x)
Note: See TracBrowser for help on using the repository browser.