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 | |
---|
40 | ## Define parameters |
---|
41 | self.params = {} |
---|
42 | self.params['k'] = 10 |
---|
43 | self.params['lb'] = 7.1 |
---|
44 | self.params['h'] = 12 |
---|
45 | self.params['b'] = 10 |
---|
46 | self.params['cs'] = 0.0 |
---|
47 | self.params['alpha']= 0.05 |
---|
48 | self.params['c'] = 0.7 |
---|
49 | self.params['background'] = 0.0 |
---|
50 | |
---|
51 | |
---|
52 | ## Parameter details [units, min, max] |
---|
53 | self.details = {} |
---|
54 | self.details['k'] = ['barns', None, None] |
---|
55 | self.details['lb'] = ['A', None, None] |
---|
56 | self.details['h'] = ['A-3', None, None] |
---|
57 | self.details['b'] = ['A', None, None] |
---|
58 | self.details['cs'] = ['mol/L', None, None] |
---|
59 | self.details['alpha'] = ['', None, None] |
---|
60 | self.details['c'] = ['mol/L', None, None] |
---|
61 | self.details['background'] = ['cm-1', None, None] |
---|
62 | |
---|
63 | |
---|
64 | def _BEPoly(self, x): |
---|
65 | """ |
---|
66 | Evaluate |
---|
67 | F(x) = K*1/(4*pi*Lb*(alpha)^(2))*(q^(2)+k2)/(1+(r02)^(2))*(q^(2)+k2)\ |
---|
68 | *(q^(2)-(12*h*C/b^(2))) |
---|
69 | |
---|
70 | has 3 internal parameters : |
---|
71 | The inverse Debye Length: K2 = 4*pi*Lb*(2*Cs+alpha*C) |
---|
72 | r02 =1/alpha/Ca^(0.5)*(B/(48*pi*Lb)^(0.5)) |
---|
73 | Ca = C*6.022136e-4 |
---|
74 | """ |
---|
75 | Ca = self.params['c'] * 6.022136e-4 |
---|
76 | |
---|
77 | K2 = 4.0 * math.pi * self.params['lb'] * (2*self.params['cs'] + \ |
---|
78 | self.params['alpha'] * Ca) |
---|
79 | |
---|
80 | r02 = 1.0/self.params['alpha']/math.sqrt(Ca) * \ |
---|
81 | (self.params['b']/math.sqrt((48.0*math.pi *self.params['lb']))) |
---|
82 | |
---|
83 | return self.params['k']/( 4.0 * math.pi * self.params['lb'] * self.params['alpha']**2 ) \ |
---|
84 | * ( x**2 + K2 ) / ( 1.0 + r02**2 * ( x**2 + K2 ) \ |
---|
85 | * (x**2 - ( 12.0 * self.params['h'] \ |
---|
86 | * Ca/(self.params['b']**2) ))) \ |
---|
87 | + self.params['background'] |
---|
88 | |
---|
89 | |
---|
90 | def run(self, x = 0.0): |
---|
91 | """ Evaluate the model |
---|
92 | @param x: input q-value (float or [float, float] as [r, theta]) |
---|
93 | @return: (debye value) |
---|
94 | """ |
---|
95 | if x.__class__.__name__ == 'list': |
---|
96 | return self._BEPoly(x[0]) |
---|
97 | elif x.__class__.__name__ == 'tuple': |
---|
98 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
99 | else: |
---|
100 | return self._BEPoly(x) |
---|
101 | |
---|
102 | def runXY(self, x = 0.0): |
---|
103 | """ Evaluate the model |
---|
104 | @param x: input q-value (float or [float, float] as [qx, qy]) |
---|
105 | @return: debye value |
---|
106 | """ |
---|
107 | if x.__class__.__name__ == 'list': |
---|
108 | q = math.sqrt(x[0]**2 + x[1]**2) |
---|
109 | return self._BEPoly(q) |
---|
110 | elif x.__class__.__name__ == 'tuple': |
---|
111 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
112 | else: |
---|
113 | return self._BEPoly(x) |
---|