source: sasview/sansmodels/src/sans/models/GuinierPorodModel.py @ 2d9c4039

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 2d9c4039 was 8f20419d, checked in by Jae Cho <jhjcho@…>, 14 years ago

more models and some tests

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