source: sasview/src/sas/models/BEPolyelectrolyte.py @ ac7be54

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 ac7be54 was ac7be54, checked in by Paul Kienzle <pkienzle@…>, 9 years ago

fix sphinx errors in api manual

  • Property mode set to 100644
File size: 4.8 KB
Line 
1"""
2 BEPolyelectrolyte as a BaseComponent model
3"""
4
5from sas.models.BaseComponent import BaseComponent
6import math
7
8class BEPolyelectrolyte(BaseComponent):
9    """
10        Class that evaluates a BEPolyelectrolyte.
11       
12        F(x) = K/(4 pi Lb (alpha)^(2)) (q^(2)+k2)/(1+(r02)^(2)) (q^(2)+k2)\
13                        (q^(2)-(12 h C/b^(2)))
14       
15        The model has Eight parameters::
16
17            K        = Constrast factor of the polymer
18            Lb       = Bjerrum length
19            H        = virial parameter
20            B        = monomer length
21            Cs       = Concentration of monovalent salt
22            alpha    = ionazation degree
23            C        = polymer molar concentration
24            bkd      = background
25    """
26       
27    def __init__(self):
28        """ Initialization """
29       
30        # Initialize BaseComponent first, then sphere
31        BaseComponent.__init__(self)
32       
33        ## Name of the model
34        self.name = "BEPolyelectrolyte"
35        self.description = """
36        F(x) = K*1/(4*pi*Lb*(alpha)^(2))*(q^(2)+k^(2))/(1+(r02)^(2))
37            *(q^(2)+k^(2))*(q^(2)-(12*h*C/b^(2)))+bkd
38               
39        The model has Eight parameters:
40        K        =  Constrast factor of the polymer
41        Lb       =  Bjerrum length
42        H        =  virial parameter
43        B        =  monomer length
44        Cs       =  Concentration of monovalent salt
45        alpha    =  ionazation degree
46        C        = polymer molar concentration
47        bkd      = background
48        """
49        ## Define parameters
50        self.params = {}
51        self.params['k']     = 10
52        self.params['lb']    = 7.1
53        self.params['h']     = 12
54        self.params['b']     = 10
55        self.params['cs']    = 0.0
56        self.params['alpha'] = 0.05
57        self.params['c']     = 0.7
58        self.params['background']  = 0.0
59
60        ## Parameter details [units, min, max]
61        self.details = {}
62        self.details['k']     = ['[barns]', None, None]
63        self.details['lb']    = ['[A]', None, None]
64        self.details['h']     = ['[1/A^(2)]', None, None]
65        self.details['b']     = ['[A]', None, None]
66        self.details['cs']    = ['[mol/L]', None, None]
67        self.details['alpha'] = ['', None, None]
68        self.details['c']     = ['[mol/L]', None, None]
69        self.details['background'] = ['[1/cm]', None, None]
70        #list of parameter that cannot be fitted
71        self.fixed = []
72               
73    def _BEPoly(self, x):
74        """
75            Evaluate 
76            F(x) = K 1/(4 pi Lb (alpha)^(2)) (q^(2)+k2)/(1+(r02)^(2))
77                 (q^(2)+k2) (q^(2)-(12 h C/b^(2)))
78       
79            has 3 internal parameters :
80                   The inverse Debye Length: K2 = 4 pi Lb (2 Cs+alpha C)
81                   r02 =1/alpha/Ca^(0.5) (B/(48 pi Lb)^(0.5))
82                   Ca = 6.022136e-4 C
83        """
84        Ca = self.params['c'] * 6.022136e-4
85        #remove singulars
86        if self.params['alpha']<=0 or self.params['c']<=0\
87            or self.params['b']==0 or self.params['lb']<=0:
88            return 0
89        else:
90           
91            K2 = 4.0 * math.pi * self.params['lb'] * (2*self.params['cs'] + \
92                     self.params['alpha'] * Ca)
93           
94            r02 = 1.0/self.params['alpha']/math.sqrt(Ca) * \
95                    (self.params['b']/\
96                     math.sqrt((48.0*math.pi*self.params['lb'])))
97           
98            return self.params['k']/( 4.0 * math.pi * self.params['lb'] \
99                                      * self.params['alpha']**2 ) \
100                   * ( x**2 + K2 ) / ( 1.0 + r02**2 * ( x**2 + K2 ) \
101                        * (x**2 - ( 12.0 * self.params['h'] \
102                        * Ca/(self.params['b']**2) ))) \
103                        + self.params['background']
104   
105    def run(self, x = 0.0):
106        """ Evaluate the model
107            @param x: input q-value (float or [float, float] as [r, theta])
108            @return: (debye value)
109        """
110        if x.__class__.__name__ == 'list':
111            return self._BEPoly(x[0])
112        elif x.__class__.__name__ == 'tuple':
113            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
114        else:
115            return self._BEPoly(x)
116   
117    def runXY(self, x = 0.0):
118        """ Evaluate the model
119            @param x: input q-value (float or [float, float] as [qx, qy])
120            @return: debye value
121        """
122        if x.__class__.__name__ == 'list':
123            q = math.sqrt(x[0]**2 + x[1]**2)
124            return self._BEPoly(q)
125        elif x.__class__.__name__ == 'tuple':
126            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
127        else:
128            return self._BEPoly(x)
Note: See TracBrowser for help on using the repository browser.