[ae3ce4e] | 1 | #!/usr/bin/env python |
---|
[95986b5] | 2 | |
---|
[79ac6f8] | 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 | ############################################################################## |
---|
[95986b5] | 16 | |
---|
| 17 | |
---|
[79ac6f8] | 18 | """ |
---|
| 19 | Provide functionality for a C extension model |
---|
[ae3ce4e] | 20 | |
---|
[79ac6f8] | 21 | :WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY |
---|
| 22 | DO NOT MODIFY THIS FILE, MODIFY ..\c_extensions\cylinder.h |
---|
| 23 | AND RE-RUN THE GENERATOR SCRIPT |
---|
[ae3ce4e] | 24 | |
---|
| 25 | """ |
---|
| 26 | |
---|
| 27 | from sans.models.BaseComponent import BaseComponent |
---|
| 28 | from sans_extension.c_models import CCylinderModel |
---|
| 29 | import copy |
---|
| 30 | |
---|
| 31 | class CylinderModel(CCylinderModel, BaseComponent): |
---|
[79ac6f8] | 32 | """ |
---|
| 33 | Class that evaluates a CylinderModel model. |
---|
| 34 | This file was auto-generated from ..\c_extensions\cylinder.h. |
---|
| 35 | Refer to that file and the structure it contains |
---|
| 36 | for details of the model. |
---|
| 37 | List of default parameters: |
---|
[ae3ce4e] | 38 | scale = 1.0 |
---|
[1ed3834] | 39 | radius = 20.0 [A] |
---|
| 40 | length = 400.0 [A] |
---|
[f10063e] | 41 | sldCyl = 4e-006 [1/A^(2)] |
---|
| 42 | sldSolv = 1e-006 [1/A^(2)] |
---|
[0824909] | 43 | background = 0.0 [1/cm] |
---|
| 44 | cyl_theta = 1.0 [rad] |
---|
| 45 | cyl_phi = 1.0 [rad] |
---|
[ae3ce4e] | 46 | |
---|
| 47 | """ |
---|
| 48 | |
---|
| 49 | def __init__(self): |
---|
| 50 | """ Initialization """ |
---|
| 51 | |
---|
| 52 | # Initialize BaseComponent first, then sphere |
---|
| 53 | BaseComponent.__init__(self) |
---|
| 54 | CCylinderModel.__init__(self) |
---|
| 55 | |
---|
| 56 | ## Name of the model |
---|
| 57 | self.name = "CylinderModel" |
---|
[836fe6e] | 58 | ## Model description |
---|
[f10063e] | 59 | self.description =""" f(q)= 2*(sldCyl - sldSolv)*V*sin(qLcos(alpha/2)) |
---|
[1ed3834] | 60 | /[qLcos(alpha/2)]*J1(qRsin(alpha/2))/[qRsin(alpha)] |
---|
| 61 | |
---|
| 62 | P(q,alpha)= scale/V*f(q)^(2)+bkg |
---|
[9316609] | 63 | V: Volume of the cylinder |
---|
| 64 | R: Radius of the cylinder |
---|
| 65 | L: Length of the cylinder |
---|
| 66 | J1: The bessel function |
---|
[1ed3834] | 67 | alpha: angle betweenthe axis of the |
---|
| 68 | cylinder and the q-vector for 1D |
---|
| 69 | :the ouput is P(q)=scale/V*integral |
---|
| 70 | from pi/2 to zero of... |
---|
[0824909] | 71 | f(q)^(2)*sin(alpha)*dalpha+ bkg""" |
---|
[836fe6e] | 72 | |
---|
[fe9c19b4] | 73 | ## Parameter details [units, min, max] |
---|
[ae3ce4e] | 74 | self.details = {} |
---|
| 75 | self.details['scale'] = ['', None, None] |
---|
[1ed3834] | 76 | self.details['radius'] = ['[A]', None, None] |
---|
| 77 | self.details['length'] = ['[A]', None, None] |
---|
[f10063e] | 78 | self.details['sldCyl'] = ['[1/A^(2)]', None, None] |
---|
| 79 | self.details['sldSolv'] = ['[1/A^(2)]', None, None] |
---|
[0824909] | 80 | self.details['background'] = ['[1/cm]', None, None] |
---|
| 81 | self.details['cyl_theta'] = ['[rad]', None, None] |
---|
| 82 | self.details['cyl_phi'] = ['[rad]', None, None] |
---|
[836fe6e] | 83 | |
---|
[fe9c19b4] | 84 | ## fittable parameters |
---|
[836fe6e] | 85 | self.fixed=['cyl_phi.width', 'cyl_theta.width', 'length.width', 'radius.width'] |
---|
[25a608f5] | 86 | |
---|
[35aface] | 87 | ## non-fittable parameters |
---|
| 88 | self.non_fittable=[] |
---|
| 89 | |
---|
[25a608f5] | 90 | ## parameters with orientation |
---|
| 91 | self.orientation_params =['cyl_phi', 'cyl_theta', 'cyl_phi.width', 'cyl_theta.width'] |
---|
[ae3ce4e] | 92 | |
---|
| 93 | def clone(self): |
---|
| 94 | """ Return a identical copy of self """ |
---|
[95986b5] | 95 | return self._clone(CylinderModel()) |
---|
[fe9c19b4] | 96 | |
---|
| 97 | def __getstate__(self): |
---|
[79ac6f8] | 98 | """ |
---|
| 99 | return object state for pickling and copying |
---|
| 100 | """ |
---|
[fe9c19b4] | 101 | model_state = {'params': self.params, 'dispersion': self.dispersion, 'log': self.log} |
---|
| 102 | |
---|
| 103 | return self.__dict__, model_state |
---|
| 104 | |
---|
| 105 | def __setstate__(self, state): |
---|
[79ac6f8] | 106 | """ |
---|
| 107 | create object from pickled state |
---|
| 108 | |
---|
| 109 | :param state: the state of the current model |
---|
| 110 | |
---|
| 111 | """ |
---|
[fe9c19b4] | 112 | |
---|
| 113 | self.__dict__, model_state = state |
---|
| 114 | self.params = model_state['params'] |
---|
| 115 | self.dispersion = model_state['dispersion'] |
---|
| 116 | self.log = model_state['log'] |
---|
| 117 | |
---|
[ae3ce4e] | 118 | |
---|
[79ac6f8] | 119 | def run(self, x=0.0): |
---|
| 120 | """ |
---|
| 121 | Evaluate the model |
---|
| 122 | |
---|
| 123 | :param x: input q, or [q,phi] |
---|
| 124 | |
---|
| 125 | :return: scattering function P(q) |
---|
| 126 | |
---|
[ae3ce4e] | 127 | """ |
---|
| 128 | |
---|
| 129 | return CCylinderModel.run(self, x) |
---|
| 130 | |
---|
[79ac6f8] | 131 | def runXY(self, x=0.0): |
---|
| 132 | """ |
---|
| 133 | Evaluate the model in cartesian coordinates |
---|
| 134 | |
---|
| 135 | :param x: input q, or [qx, qy] |
---|
| 136 | |
---|
| 137 | :return: scattering function P(q) |
---|
| 138 | |
---|
[ae3ce4e] | 139 | """ |
---|
| 140 | |
---|
| 141 | return CCylinderModel.runXY(self, x) |
---|
[95986b5] | 142 | |
---|
[79ac6f8] | 143 | def evalDistribution(self, x=[]): |
---|
| 144 | """ |
---|
| 145 | Evaluate the model in cartesian coordinates |
---|
| 146 | |
---|
| 147 | :param x: input q[], or [qx[], qy[]] |
---|
| 148 | |
---|
| 149 | :return: scattering function P(q[]) |
---|
| 150 | |
---|
[9bd69098] | 151 | """ |
---|
[f9a1279] | 152 | return CCylinderModel.evalDistribution(self, x) |
---|
[9bd69098] | 153 | |
---|
[5eb9154] | 154 | def calculate_ER(self): |
---|
[79ac6f8] | 155 | """ |
---|
| 156 | Calculate the effective radius for P(q)*S(q) |
---|
| 157 | |
---|
| 158 | :return: the value of the effective radius |
---|
| 159 | |
---|
[5eb9154] | 160 | """ |
---|
| 161 | return CCylinderModel.calculate_ER(self) |
---|
| 162 | |
---|
[95986b5] | 163 | def set_dispersion(self, parameter, dispersion): |
---|
| 164 | """ |
---|
[79ac6f8] | 165 | Set the dispersion object for a model parameter |
---|
| 166 | |
---|
| 167 | :param parameter: name of the parameter [string] |
---|
| 168 | :param dispersion: dispersion object of type DispersionModel |
---|
| 169 | |
---|
[95986b5] | 170 | """ |
---|
| 171 | return CCylinderModel.set_dispersion(self, parameter, dispersion.cdisp) |
---|
| 172 | |
---|
[ae3ce4e] | 173 | |
---|
| 174 | # End of file |
---|