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