[8f20419d] | 1 | """ |
---|
[279e371] | 2 | BroadPeakModel function as a BaseComponent model |
---|
[8f20419d] | 3 | """ |
---|
| 4 | |
---|
[79492222] | 5 | from sas.models.BaseComponent import BaseComponent |
---|
[411d8bf] | 6 | import math |
---|
[18695bf] | 7 | from numpy import power |
---|
[8f20419d] | 8 | |
---|
| 9 | class BroadPeakModel(BaseComponent): |
---|
| 10 | """ |
---|
| 11 | Class that evaluates a BroadPeakModel. |
---|
| 12 | I(q) = I(q) = scale_p/pow(qval,exponent)+scale_l/ |
---|
| 13 | (1.0 + pow((qval*length_l),exponent_l) )+ background |
---|
| 14 | """ |
---|
| 15 | |
---|
| 16 | def __init__(self): |
---|
| 17 | """ Initialization """ |
---|
| 18 | |
---|
| 19 | # Initialize BaseComponent first, then sphere |
---|
| 20 | BaseComponent.__init__(self) |
---|
[18695bf] | 21 | self.counter = 0 |
---|
[8f20419d] | 22 | ## Name of the model |
---|
[b71a53b] | 23 | self.name = "BroadPeakModel" |
---|
[411d8bf] | 24 | self.description = """I(q) = scale_p/pow(q,exponent)+scale_l/ |
---|
[8f20419d] | 25 | (1.0 + pow((fabs(q-q_peak)*length_l),exponent_l) )+ background |
---|
| 26 | List of default parameters: |
---|
| 27 | scale_p = Porod term scaling |
---|
| 28 | exponent_p = Porod exponent |
---|
| 29 | scale_l = Lorentzian term scaling |
---|
| 30 | length_l = Lorentzian screening length [A] |
---|
| 31 | q_peak = peak location [1/A] |
---|
| 32 | exponent_l = Lorentzian exponent |
---|
| 33 | background = Incoherent background |
---|
| 34 | """ |
---|
| 35 | ## Define parameters |
---|
| 36 | self.params = {} |
---|
| 37 | self.params['scale_p'] = 1.0e-05 |
---|
| 38 | self.params['exponent_p'] = 3.0 |
---|
| 39 | self.params['scale_l'] = 10.0 |
---|
| 40 | self.params['length_l'] = 50.0 |
---|
| 41 | self.params['q_peak'] = 0.1 |
---|
| 42 | self.params['exponent_l'] = 2.0 |
---|
| 43 | self.params['background'] = 0.1 |
---|
| 44 | ## Parameter details [units, min, max] |
---|
| 45 | self.details = {} |
---|
| 46 | self.details['scale_p'] = ['', None, None] |
---|
| 47 | self.details['exponent_p'] = ['', None, None] |
---|
| 48 | self.details['scale_l'] = ['', None, None] |
---|
[5385a9e] | 49 | self.details['length_l'] = ['[A]', None, None] |
---|
| 50 | self.details['q_peak'] = ['[1/A]', None, None] |
---|
[8f20419d] | 51 | self.details['exponent_l'] = ['', None, None] |
---|
| 52 | self.details['background'] = ['[1/cm]', None, None] |
---|
| 53 | |
---|
| 54 | #list of parameter that cannot be fitted |
---|
[411d8bf] | 55 | self.fixed = [] |
---|
[8f20419d] | 56 | def _broadpeak(self, x): |
---|
| 57 | """ |
---|
| 58 | Model definition |
---|
| 59 | """ |
---|
| 60 | inten = self.params['scale_p']/pow(x,self.params['exponent_p']) |
---|
| 61 | inten += self.params['scale_l']/(1.0 + \ |
---|
[279e371] | 62 | power((math.fabs(x-self.params['q_peak'])\ |
---|
| 63 | *self.params['length_l']),\ |
---|
[18695bf] | 64 | self.params['exponent_l'])) |
---|
[8f20419d] | 65 | |
---|
[18695bf] | 66 | inten += self.params['background'] |
---|
| 67 | |
---|
[8f20419d] | 68 | return inten |
---|
| 69 | |
---|
| 70 | def run(self, x = 0.0): |
---|
| 71 | """ |
---|
| 72 | Evaluate the model |
---|
| 73 | |
---|
| 74 | param x: input q-value (float or [float, float] as [r, theta]) |
---|
| 75 | return: (scattering value) |
---|
| 76 | """ |
---|
| 77 | if x.__class__.__name__ == 'list': |
---|
| 78 | return self._broadpeak(x[0]) |
---|
| 79 | elif x.__class__.__name__ == 'tuple': |
---|
[279e371] | 80 | raise ValueError, "Tuples are not allowed as input to models" |
---|
[8f20419d] | 81 | else: |
---|
| 82 | return self._broadpeak(x) |
---|
| 83 | |
---|
| 84 | def runXY(self, x = 0.0): |
---|
| 85 | """ |
---|
| 86 | Evaluate the model |
---|
| 87 | |
---|
| 88 | param x: input q-value (float or [float, float] as [qx, qy]) |
---|
| 89 | return: scattering value |
---|
| 90 | """ |
---|
| 91 | if x.__class__.__name__ == 'list': |
---|
| 92 | q = math.sqrt(x[0]**2 + x[1]**2) |
---|
| 93 | return self._broadpeak(q) |
---|
| 94 | elif x.__class__.__name__ == 'tuple': |
---|
[279e371] | 95 | raise ValueError, "Tuples are not allowed as input to models" |
---|
[8f20419d] | 96 | else: |
---|
| 97 | return self._broadpeak(x) |
---|
| 98 | |
---|
| 99 | |
---|