[829eee9] | 1 | #!/usr/bin/env python |
---|
| 2 | """ |
---|
| 3 | |
---|
[3db3895] | 4 | Provide F(x) = K*1/(4*pi*Lb*(alpha)^(2))*(q^(2)+k2)/(1+(r02)^(2))*(q^(2)+k2)\ |
---|
[829eee9] | 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 | |
---|
[3db3895] | 17 | F(x) = K*1/(4*pi*Lb*(alpha)^(2))*(q^(2)+k2)/(1+(r02)^(2))*(q^(2)+k2)\ |
---|
[829eee9] | 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" |
---|
[96672c0] | 39 | self.description=""" |
---|
| 40 | F(x) = K*1/(4*pi*Lb*(alpha)^(2))*(q^(2)+k2)/(1+(r02)^(2))*(q^(2)+k2)\ |
---|
| 41 | *(q^(2)-(12*h*C/b^(2))) |
---|
| 42 | The model has Eight parameters: |
---|
| 43 | K = Constrast factor of the polymer |
---|
| 44 | Lb = Bjerrum length |
---|
| 45 | H = virial parameter |
---|
| 46 | B = monomer length |
---|
| 47 | Cs = Concentration of monovalent salt |
---|
| 48 | alpha = ionazation degree |
---|
| 49 | C = polymer molar concentration |
---|
| 50 | bkd = background |
---|
| 51 | """ |
---|
[829eee9] | 52 | ## Define parameters |
---|
| 53 | self.params = {} |
---|
[3db3895] | 54 | self.params['k'] = 10 |
---|
| 55 | self.params['lb'] = 7.1 |
---|
| 56 | self.params['h'] = 12 |
---|
| 57 | self.params['b'] = 10 |
---|
| 58 | self.params['cs'] = 0.0 |
---|
[829eee9] | 59 | self.params['alpha']= 0.05 |
---|
[3db3895] | 60 | self.params['c'] = 0.7 |
---|
| 61 | self.params['background'] = 0.0 |
---|
[829eee9] | 62 | |
---|
| 63 | |
---|
| 64 | ## Parameter details [units, min, max] |
---|
| 65 | self.details = {} |
---|
[3db3895] | 66 | self.details['k'] = ['barns', None, None] |
---|
| 67 | self.details['lb'] = ['A', None, None] |
---|
| 68 | self.details['h'] = ['A-3', None, None] |
---|
| 69 | self.details['b'] = ['A', None, None] |
---|
| 70 | self.details['cs'] = ['mol/L', None, None] |
---|
[829eee9] | 71 | self.details['alpha'] = ['', None, None] |
---|
[3db3895] | 72 | self.details['c'] = ['mol/L', None, None] |
---|
| 73 | self.details['background'] = ['cm-1', None, None] |
---|
[988130c6] | 74 | #list of parameter that cannot be fitted |
---|
| 75 | self.fixed= [] |
---|
[829eee9] | 76 | |
---|
| 77 | def _BEPoly(self, x): |
---|
| 78 | """ |
---|
| 79 | Evaluate |
---|
[3db3895] | 80 | F(x) = K*1/(4*pi*Lb*(alpha)^(2))*(q^(2)+k2)/(1+(r02)^(2))*(q^(2)+k2)\ |
---|
[829eee9] | 81 | *(q^(2)-(12*h*C/b^(2))) |
---|
| 82 | |
---|
| 83 | has 3 internal parameters : |
---|
| 84 | The inverse Debye Length: K2 = 4*pi*Lb*(2*Cs+alpha*C) |
---|
| 85 | r02 =1/alpha/Ca^(0.5)*(B/(48*pi*Lb)^(0.5)) |
---|
[3db3895] | 86 | Ca = C*6.022136e-4 |
---|
[829eee9] | 87 | """ |
---|
[3db3895] | 88 | Ca = self.params['c'] * 6.022136e-4 |
---|
[829eee9] | 89 | |
---|
[3db3895] | 90 | K2 = 4.0 * math.pi * self.params['lb'] * (2*self.params['cs'] + \ |
---|
| 91 | self.params['alpha'] * Ca) |
---|
[829eee9] | 92 | |
---|
[3db3895] | 93 | r02 = 1.0/self.params['alpha']/math.sqrt(Ca) * \ |
---|
| 94 | (self.params['b']/math.sqrt((48.0*math.pi *self.params['lb']))) |
---|
[829eee9] | 95 | |
---|
[3db3895] | 96 | return self.params['k']/( 4.0 * math.pi * self.params['lb'] * self.params['alpha']**2 ) \ |
---|
| 97 | * ( x**2 + K2 ) / ( 1.0 + r02**2 * ( x**2 + K2 ) \ |
---|
| 98 | * (x**2 - ( 12.0 * self.params['h'] \ |
---|
| 99 | * Ca/(self.params['b']**2) ))) \ |
---|
| 100 | + self.params['background'] |
---|
[829eee9] | 101 | |
---|
| 102 | |
---|
| 103 | def run(self, x = 0.0): |
---|
| 104 | """ Evaluate the model |
---|
[3db3895] | 105 | @param x: input q-value (float or [float, float] as [r, theta]) |
---|
[829eee9] | 106 | @return: (debye value) |
---|
| 107 | """ |
---|
| 108 | if x.__class__.__name__ == 'list': |
---|
[a55fac1] | 109 | return self._BEPoly(x[0]) |
---|
[829eee9] | 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) |
---|
| 114 | |
---|
| 115 | def runXY(self, x = 0.0): |
---|
| 116 | """ Evaluate the model |
---|
[3db3895] | 117 | @param x: input q-value (float or [float, float] as [qx, qy]) |
---|
[829eee9] | 118 | @return: debye value |
---|
| 119 | """ |
---|
| 120 | if x.__class__.__name__ == 'list': |
---|
[a55fac1] | 121 | q = math.sqrt(x[0]**2 + x[1]**2) |
---|
| 122 | return self._BEPoly(q) |
---|
[829eee9] | 123 | elif x.__class__.__name__ == 'tuple': |
---|
| 124 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
| 125 | else: |
---|
[3db3895] | 126 | return self._BEPoly(x) |
---|