[3db3895] | 1 | """ |
---|
| 2 | Provide I(q) = I_0 exp ( - R_g^2 q^2 / 3.0) |
---|
| 3 | Guinier function as a BaseComponent model |
---|
[829eee9] | 4 | """ |
---|
| 5 | from sans.models.BaseComponent import BaseComponent |
---|
| 6 | import math |
---|
| 7 | |
---|
| 8 | class GuinierModel(BaseComponent): |
---|
[3db3895] | 9 | """ |
---|
| 10 | Class that evaluates a Guinier model. |
---|
[829eee9] | 11 | |
---|
[3db3895] | 12 | I(q) = I_0 exp ( - R_g^2 q^2 / 3.0 ) |
---|
[800fc80] | 13 | |
---|
[829eee9] | 14 | List of default parameters: |
---|
[3db3895] | 15 | I_0 = Scale |
---|
| 16 | R_g = Radius of gyration |
---|
| 17 | |
---|
[829eee9] | 18 | """ |
---|
| 19 | |
---|
| 20 | def __init__(self): |
---|
| 21 | """ Initialization """ |
---|
| 22 | |
---|
| 23 | # Initialize BaseComponent first, then sphere |
---|
| 24 | BaseComponent.__init__(self) |
---|
| 25 | |
---|
| 26 | ## Name of the model |
---|
| 27 | self.name = "Guinier" |
---|
[279e371] | 28 | self.description = """ I(q) = I_0 exp ( - R_g^2 q^2 / 3.0 ) |
---|
[1ed3834] | 29 | |
---|
| 30 | List of default parameters: |
---|
| 31 | I_0 = Scale |
---|
| 32 | R_g = Radius of gyration""" |
---|
[829eee9] | 33 | ## Define parameters |
---|
| 34 | self.params = {} |
---|
[3db3895] | 35 | self.params['scale'] = 1.0 |
---|
[800fc80] | 36 | self.params['rg'] = 60 |
---|
[829eee9] | 37 | |
---|
| 38 | ## Parameter details [units, min, max] |
---|
| 39 | self.details = {} |
---|
[0824909] | 40 | self.details['scale'] = ['[1/cm]', None, None] |
---|
[1ed3834] | 41 | self.details['rg'] = ['[A]', None, None] |
---|
[988130c6] | 42 | #list of parameter that cannot be fitted |
---|
[279e371] | 43 | self.fixed = [] |
---|
| 44 | |
---|
[829eee9] | 45 | def _guinier(self, x): |
---|
[279e371] | 46 | """ |
---|
| 47 | Evaluate guinier function |
---|
| 48 | :param x: q-value |
---|
| 49 | """ |
---|
| 50 | return self.params['scale']*math.exp( -(self.params['rg']*x)**2/3.0 ) |
---|
[829eee9] | 51 | |
---|
| 52 | def run(self, x = 0.0): |
---|
[279e371] | 53 | """ |
---|
| 54 | Evaluate the model |
---|
[3db3895] | 55 | @param x: input q-value (float or [float, float] as [r, theta]) |
---|
[829eee9] | 56 | @return: (guinier value) |
---|
| 57 | """ |
---|
| 58 | if x.__class__.__name__ == 'list': |
---|
[a55fac1] | 59 | return self._guinier(x[0]) |
---|
[829eee9] | 60 | elif x.__class__.__name__ == 'tuple': |
---|
[279e371] | 61 | raise ValueError, "Tuples are not allowed as input to models" |
---|
[829eee9] | 62 | else: |
---|
| 63 | return self._guinier(x) |
---|
| 64 | |
---|
| 65 | def runXY(self, x = 0.0): |
---|
| 66 | """ Evaluate the model |
---|
[3db3895] | 67 | @param x: input q-value (float or [float, float] as [qx, qy]) |
---|
[829eee9] | 68 | @return: guinier value |
---|
| 69 | """ |
---|
| 70 | if x.__class__.__name__ == 'list': |
---|
[a55fac1] | 71 | q = math.sqrt(x[0]**2 + x[1]**2) |
---|
| 72 | return self._guinier(q) |
---|
[829eee9] | 73 | elif x.__class__.__name__ == 'tuple': |
---|
[279e371] | 74 | raise ValueError, "Tuples are not allowed as input to models" |
---|
[829eee9] | 75 | else: |
---|
| 76 | return self._guinier(x) |
---|