[51f14603] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | ############################################################################## |
---|
| 4 | # This software was developed by the University of Tennessee as part of the |
---|
| 5 | # Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
| 6 | # project funded by the US National Science Foundation. |
---|
| 7 | # |
---|
| 8 | # If you use DANSE applications to do scientific research that leads to |
---|
| 9 | # publication, we ask that you acknowledge the use of the software with the |
---|
| 10 | # following sentence: |
---|
| 11 | # |
---|
| 12 | # "This work benefited from DANSE software developed under NSF award DMR-0520547." |
---|
| 13 | # |
---|
| 14 | # copyright 2008, University of Tennessee |
---|
| 15 | ############################################################################## |
---|
| 16 | from sans.models.BaseComponent import BaseComponent |
---|
| 17 | from scipy.special import gammainc,gamma |
---|
| 18 | import copy |
---|
| 19 | import math |
---|
| 20 | |
---|
| 21 | class PolymerExclVolume(BaseComponent): |
---|
| 22 | """ |
---|
| 23 | Class that evaluates a PolymerExclVolModel model. |
---|
| 24 | This file was auto-generated from ..\c_extensions\polyexclvol.h. |
---|
| 25 | Refer to that file and the structure it contains |
---|
| 26 | for details of the model. |
---|
| 27 | |
---|
| 28 | List of default parameters: |
---|
| 29 | |
---|
| 30 | * scale = 0.01 |
---|
| 31 | * rg = 100.0 [A] |
---|
| 32 | * m = 3.0 |
---|
| 33 | * background = 0.0 [1/cm] |
---|
| 34 | |
---|
| 35 | """ |
---|
| 36 | |
---|
| 37 | def __init__(self): |
---|
| 38 | """ Initialization """ |
---|
| 39 | |
---|
| 40 | # Initialize BaseComponent first, then sphere |
---|
| 41 | BaseComponent.__init__(self) |
---|
| 42 | |
---|
| 43 | ## Name of the model |
---|
| 44 | self.name = "PolymerExclVolume" |
---|
| 45 | ## Model description |
---|
| 46 | self.description =""" Compute the scattering intensity from polymers with excluded volume effects. |
---|
| 47 | scale: scale factor times volume fraction, |
---|
| 48 | or just volume fraction for absolute scale data |
---|
| 49 | rg: radius of gyration |
---|
| 50 | m = Porod exponent |
---|
| 51 | background: incoherent background |
---|
| 52 | """ |
---|
| 53 | ## Define parameters |
---|
| 54 | self.params = {} |
---|
| 55 | self.params['scale'] = 1.0 |
---|
| 56 | self.params['rg'] = 60.0 |
---|
| 57 | self.params['m'] = 3.0 |
---|
| 58 | self.params['background'] = 0.0 |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | ## Parameter details [units, min, max] |
---|
| 62 | self.details = {} |
---|
| 63 | self.details['scale'] = ['', None, None] |
---|
| 64 | self.details['rg'] = ['[A]', None, None] |
---|
| 65 | self.details['m'] = ['', None, None] |
---|
| 66 | self.details['background'] = ['[1/cm]', None, None] |
---|
| 67 | |
---|
| 68 | ## fittable parameters |
---|
| 69 | self.fixed=[] |
---|
| 70 | |
---|
| 71 | ## non-fittable parameters |
---|
| 72 | self.non_fittable=[] |
---|
| 73 | |
---|
| 74 | ## parameters with orientation |
---|
| 75 | self.orientation_params =[] |
---|
| 76 | |
---|
| 77 | def _polymerexclvol(self, x): |
---|
| 78 | |
---|
| 79 | sc = self.params['scale'] |
---|
| 80 | rg = self.params['rg'] |
---|
| 81 | mm = self.params['m'] |
---|
| 82 | bg = self.params['background'] |
---|
| 83 | |
---|
| 84 | nu = 1.0 / mm |
---|
| 85 | |
---|
| 86 | Xx = x * x * rg * rg *(2.0 * nu + 1.0) * (2.0 * nu + 2.0) / 6.0 |
---|
| 87 | onu = 1.0 / nu |
---|
| 88 | o2nu = 1.0 /(2.0 * nu) |
---|
| 89 | Ps =(1.0 / (nu * pow(Xx,o2nu))) * (gamma(o2nu)*gammainc(o2nu,Xx) - \ |
---|
| 90 | 1.0 / pow(Xx,o2nu) * gamma(onu)*gammainc(onu,Xx)) |
---|
| 91 | |
---|
| 92 | if x == 0: |
---|
| 93 | Ps = 1.0 |
---|
| 94 | |
---|
| 95 | return (sc * Ps + bg); |
---|
| 96 | |
---|
| 97 | def run(self, x = 0.0): |
---|
| 98 | """ Evaluate the model |
---|
| 99 | @param x: input q-value (float or [float, float] as [r, theta]) |
---|
| 100 | @return: (guinier value) |
---|
| 101 | """ |
---|
| 102 | if x.__class__.__name__ == 'list': |
---|
| 103 | return self._polymerexclvol(x[0]) |
---|
| 104 | elif x.__class__.__name__ == 'tuple': |
---|
| 105 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
| 106 | else: |
---|
| 107 | return self._polymerexclvol(x) |
---|
| 108 | |
---|
| 109 | def runXY(self, x = 0.0): |
---|
| 110 | """ Evaluate the model |
---|
| 111 | @param x: input q-value (float or [float, float] as [qx, qy]) |
---|
| 112 | @return: guinier value |
---|
| 113 | """ |
---|
| 114 | if x.__class__.__name__ == 'list': |
---|
| 115 | q = math.sqrt(x[0]**2 + x[1]**2) |
---|
| 116 | return self._polymerexclvol(x) |
---|
| 117 | elif x.__class__.__name__ == 'tuple': |
---|
| 118 | raise ValueError, "Tuples are not allowed as input to BaseComponent models" |
---|
| 119 | else: |
---|
| 120 | return self._polymerexclvol(x) |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | # End of file |
---|