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