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