1 | """ |
---|
2 | Provide I(q) = I_0 exp ( - R_g^2 q^2 / 3.0) |
---|
3 | GaussLorentzGel function as a BaseComponent model |
---|
4 | """ |
---|
5 | from sans.models.BaseComponent import BaseComponent |
---|
6 | import math |
---|
7 | |
---|
8 | class GaussLorentzGelModel(BaseComponent): |
---|
9 | """ |
---|
10 | Class that evaluates a GaussLorentzGel model. |
---|
11 | |
---|
12 | I(q) = scale_g*exp(- q^2*Z^2 / 2)+scale_l/(1+q^2*z^2) |
---|
13 | + background |
---|
14 | List of default parameters: |
---|
15 | scale_g = Gauss scale factor |
---|
16 | Z = Static correlation length |
---|
17 | scale_l = Lorentzian scale factor |
---|
18 | z = Dynamic correlation length |
---|
19 | background = Incoherent background |
---|
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 = "GaussLorentzGel" |
---|
30 | self.description = """I(q)=scale_g*exp(-q^2*Z^2/2)+scale_l/(1+q^2*z^2) |
---|
31 | + background |
---|
32 | List of default parameters: |
---|
33 | scale_g = Gauss scale factor |
---|
34 | stat_colength = Static correlation length |
---|
35 | scale_l = Lorentzian scale factor |
---|
36 | dyn_colength = Dynamic correlation length |
---|
37 | background = Incoherent background |
---|
38 | """ |
---|
39 | ## Define parameters |
---|
40 | self.params = {} |
---|
41 | self.params['scale_g'] = 100.0 |
---|
42 | self.params['stat_colength'] = 100.0 |
---|
43 | self.params['scale_l'] = 50.0 |
---|
44 | self.params['dyn_colength'] = 20.0 |
---|
45 | self.params['background'] = 0.0 |
---|
46 | ## Parameter details [units, min, max] |
---|
47 | self.details = {} |
---|
48 | self.details['scale_g'] = ['', None, None] |
---|
49 | self.details['stat_colength'] = ['A', None, None] |
---|
50 | self.details['scale_l'] = ['', None, None] |
---|
51 | self.details['dyn_colength'] = ['A', None, None] |
---|
52 | self.details['background'] = ['[1/cm]', None, None] |
---|
53 | |
---|
54 | #list of parameter that cannot be fitted |
---|
55 | self.fixed = [] |
---|
56 | |
---|
57 | def _gausslorentzgel(self, x): |
---|
58 | """ |
---|
59 | Model definition |
---|
60 | """ |
---|
61 | inten = self.params['scale_g'] \ |
---|
62 | *math.exp(-1.0*x*x*self.params['stat_colength']* \ |
---|
63 | self.params['stat_colength']/2.0) + self.params['scale_l']/ \ |
---|
64 | (1.0 + (x*self.params['dyn_colength'])* \ |
---|
65 | (x*self.params['dyn_colength'])) + self.params['background'] |
---|
66 | return inten |
---|
67 | |
---|
68 | def run(self, x = 0.0): |
---|
69 | """ Evaluate the model |
---|
70 | @param x: input q-value (float or [float, float] as [r, theta]) |
---|
71 | @return: (guinier value) |
---|
72 | """ |
---|
73 | if x.__class__.__name__ == 'list': |
---|
74 | return self._gausslorentzgel(x[0]) |
---|
75 | elif x.__class__.__name__ == 'tuple': |
---|
76 | raise ValueError, "Tuples are not allowed as input to models" |
---|
77 | else: |
---|
78 | return self._gausslorentzgel(x) |
---|
79 | |
---|
80 | def runXY(self, x = 0.0): |
---|
81 | """ Evaluate the model |
---|
82 | @param x: input q-value (float or [float, float] as [qx, qy]) |
---|
83 | @return: guinier value |
---|
84 | """ |
---|
85 | if x.__class__.__name__ == 'list': |
---|
86 | q = math.sqrt(x[0]**2 + x[1]**2) |
---|
87 | return self._gausslorentzgel(q) |
---|
88 | elif x.__class__.__name__ == 'tuple': |
---|
89 | raise ValueError, "Tuples are not allowed as input to models" |
---|
90 | else: |
---|
91 | return self._gausslorentzgel(x) |
---|