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