[279e371] | 1 | """ |
---|
| 2 | Provide F(x) = K*1/(4*pi*Lb*(alpha)^(2))*(q^(2)+k2)/(1+(r02)^(2))*(q^(2)+k2)\ |
---|
[829eee9] | 3 | *(q^(2)-(12*h*C/b^(2))) |
---|
[279e371] | 4 | BEPolyelectrolyte as a BaseComponent model |
---|
[829eee9] | 5 | """ |
---|
| 6 | |
---|
[79492222] | 7 | from sas.models.BaseComponent import BaseComponent |
---|
[829eee9] | 8 | import math |
---|
| 9 | |
---|
| 10 | class BEPolyelectrolyte(BaseComponent): |
---|
| 11 | """ |
---|
| 12 | Class that evaluates a BEPolyelectrolyte. |
---|
| 13 | |
---|
[3db3895] | 14 | F(x) = K*1/(4*pi*Lb*(alpha)^(2))*(q^(2)+k2)/(1+(r02)^(2))*(q^(2)+k2)\ |
---|
[1ed3834] | 15 | *(q^(2)-(12*h*C/b^(2))) |
---|
[829eee9] | 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" |
---|
[279e371] | 36 | self.description = """ |
---|
[0824909] | 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 |
---|
[1ed3834] | 39 | |
---|
[96672c0] | 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 | """ |
---|
[829eee9] | 50 | ## Define parameters |
---|
| 51 | self.params = {} |
---|
[279e371] | 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 |
---|
[3db3895] | 59 | self.params['background'] = 0.0 |
---|
[829eee9] | 60 | |
---|
| 61 | ## Parameter details [units, min, max] |
---|
| 62 | self.details = {} |
---|
[279e371] | 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] |
---|
[0824909] | 70 | self.details['background'] = ['[1/cm]', None, None] |
---|
[988130c6] | 71 | #list of parameter that cannot be fitted |
---|
[279e371] | 72 | self.fixed = [] |
---|
[829eee9] | 73 | |
---|
| 74 | def _BEPoly(self, x): |
---|
| 75 | """ |
---|
| 76 | Evaluate |
---|
[0824909] | 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))) |
---|
[829eee9] | 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)) |
---|
[3db3895] | 83 | Ca = C*6.022136e-4 |
---|
[829eee9] | 84 | """ |
---|
[3db3895] | 85 | Ca = self.params['c'] * 6.022136e-4 |
---|
[e45a565] | 86 | #remove singulars |
---|
[279e371] | 87 | if self.params['alpha']<=0 or self.params['c']<=0\ |
---|
| 88 | or self.params['b']==0 or self.params['lb']<=0: |
---|
[e45a565] | 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) * \ |
---|
[279e371] | 96 | (self.params['b']/\ |
---|
| 97 | math.sqrt((48.0*math.pi*self.params['lb']))) |
---|
[e45a565] | 98 | |
---|
[279e371] | 99 | return self.params['k']/( 4.0 * math.pi * self.params['lb'] \ |
---|
| 100 | * self.params['alpha']**2 ) \ |
---|
[e45a565] | 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'] |
---|
[829eee9] | 105 | |
---|
| 106 | def run(self, x = 0.0): |
---|
| 107 | """ Evaluate the model |
---|
[3db3895] | 108 | @param x: input q-value (float or [float, float] as [r, theta]) |
---|
[829eee9] | 109 | @return: (debye value) |
---|
| 110 | """ |
---|
| 111 | if x.__class__.__name__ == 'list': |
---|
[a55fac1] | 112 | return self._BEPoly(x[0]) |
---|
[829eee9] | 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 |
---|
[3db3895] | 120 | @param x: input q-value (float or [float, float] as [qx, qy]) |
---|
[829eee9] | 121 | @return: debye value |
---|
| 122 | """ |
---|
| 123 | if x.__class__.__name__ == 'list': |
---|
[a55fac1] | 124 | q = math.sqrt(x[0]**2 + x[1]**2) |
---|
| 125 | return self._BEPoly(q) |
---|
[829eee9] | 126 | elif x.__class__.__name__ == 'tuple': |
---|
| 127 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
| 128 | else: |
---|
[3db3895] | 129 | return self._BEPoly(x) |
---|