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