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