[230f479] | 1 | /** |
---|
| 2 | This software was developed by the University of Tennessee as part of the |
---|
| 3 | Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
| 4 | project funded by the US National Science Foundation. |
---|
| 5 | |
---|
| 6 | If you use DANSE applications to do scientific research that leads to |
---|
| 7 | publication, we ask that you acknowledge the use of the software with the |
---|
| 8 | following sentence: |
---|
| 9 | |
---|
| 10 | "This work benefited from DANSE software developed under NSF award DMR-0520547." |
---|
| 11 | |
---|
| 12 | copyright 2008, University of Tennessee |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | /** |
---|
| 16 | * Scattering model classes |
---|
| 17 | * The classes use the IGOR library found in |
---|
| 18 | * sansmodels/src/libigor |
---|
| 19 | * |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #include <math.h> |
---|
| 23 | #include "parameters.hh" |
---|
| 24 | #include <stdio.h> |
---|
| 25 | using namespace std; |
---|
| 26 | #include "vesicle.h" |
---|
| 27 | |
---|
| 28 | extern "C" { |
---|
| 29 | #include "libSphere.h" |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | typedef struct { |
---|
| 33 | double scale; |
---|
| 34 | double radius; |
---|
| 35 | double thickness; |
---|
| 36 | double solv_sld; |
---|
| 37 | double shell_sld; |
---|
| 38 | double background; |
---|
| 39 | } VesicleParameters; |
---|
| 40 | |
---|
| 41 | VesicleModel :: VesicleModel() { |
---|
| 42 | scale = Parameter(1.0); |
---|
| 43 | radius = Parameter(100.0, true); |
---|
| 44 | radius.set_min(0.0); |
---|
| 45 | thickness = Parameter(30.0, true); |
---|
| 46 | thickness.set_min(0.0); |
---|
| 47 | solv_sld = Parameter(6.36e-6); |
---|
| 48 | shell_sld = Parameter(5.0e-7); |
---|
| 49 | background = Parameter(0.0); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | /** |
---|
| 53 | * Function to evaluate 1D scattering function |
---|
| 54 | * The NIST IGOR library is used for the actual calculation. |
---|
| 55 | * @param q: q-value |
---|
| 56 | * @return: function value |
---|
| 57 | */ |
---|
| 58 | double VesicleModel :: operator()(double q) { |
---|
| 59 | double dp[6]; |
---|
| 60 | |
---|
| 61 | // Fill parameter array for IGOR library |
---|
| 62 | // Add the background after averaging |
---|
| 63 | dp[0] = scale(); |
---|
| 64 | dp[1] = radius(); |
---|
| 65 | dp[2] = thickness(); |
---|
| 66 | dp[3] = solv_sld(); |
---|
| 67 | dp[4] = shell_sld(); |
---|
| 68 | dp[5] = 0.0; |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | // Get the dispersion points for the core radius |
---|
| 72 | vector<WeightPoint> weights_radius; |
---|
| 73 | radius.get_weights(weights_radius); |
---|
| 74 | // Get the dispersion points for the thickness |
---|
| 75 | vector<WeightPoint> weights_thickness; |
---|
| 76 | thickness.get_weights(weights_thickness); |
---|
| 77 | |
---|
| 78 | // Perform the computation, with all weight points |
---|
| 79 | double sum = 0.0; |
---|
| 80 | double norm = 0.0; |
---|
| 81 | double vol = 0.0; |
---|
| 82 | |
---|
| 83 | // Loop over radius weight points |
---|
| 84 | for(int i=0; i< (int)weights_radius.size(); i++) { |
---|
| 85 | dp[1] = weights_radius[i].value; |
---|
| 86 | for(int j=0; j< (int)weights_thickness.size(); j++) { |
---|
| 87 | dp[2] = weights_thickness[j].value; |
---|
| 88 | sum += weights_radius[i].weight |
---|
| 89 | * weights_thickness[j].weight * VesicleForm(dp, q) |
---|
| 90 | *(pow(weights_radius[i].value+weights_thickness[j].value,3)-pow(weights_radius[i].value,3)); |
---|
| 91 | //Find average volume |
---|
| 92 | vol += weights_radius[i].weight * weights_thickness[j].weight |
---|
| 93 | *(pow(weights_radius[i].value+weights_thickness[j].value,3)-pow(weights_radius[i].value,3)); |
---|
| 94 | norm += weights_radius[i].weight * weights_thickness[j].weight; |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | if (vol != 0.0 && norm != 0.0) { |
---|
| 98 | //Re-normalize by avg volume |
---|
| 99 | sum = sum/(vol/norm);} |
---|
| 100 | |
---|
| 101 | return sum/norm + background(); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | /** |
---|
| 105 | * Function to evaluate 2D scattering function |
---|
| 106 | * @param q_x: value of Q along x |
---|
| 107 | * @param q_y: value of Q along y |
---|
| 108 | * @return: function value |
---|
| 109 | */ |
---|
| 110 | double VesicleModel :: operator()(double qx, double qy) { |
---|
| 111 | double q = sqrt(qx*qx + qy*qy); |
---|
| 112 | return (*this).operator()(q); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | /** |
---|
| 116 | * Function to evaluate 2D scattering function |
---|
| 117 | * @param pars: parameters of the vesicle |
---|
| 118 | * @param q: q-value |
---|
| 119 | * @param phi: angle phi |
---|
| 120 | * @return: function value |
---|
| 121 | */ |
---|
| 122 | double VesicleModel :: evaluate_rphi(double q, double phi) { |
---|
| 123 | return (*this).operator()(q); |
---|
| 124 | } |
---|
| 125 | /** |
---|
| 126 | * Function to calculate effective radius |
---|
| 127 | * @return: effective radius value |
---|
| 128 | */ |
---|
| 129 | double VesicleModel :: calculate_ER() { |
---|
| 130 | VesicleParameters dp; |
---|
| 131 | |
---|
| 132 | dp.radius = radius(); |
---|
| 133 | dp.thickness = thickness(); |
---|
| 134 | |
---|
| 135 | double rad_out = 0.0; |
---|
| 136 | |
---|
| 137 | // Perform the computation, with all weight points |
---|
| 138 | double sum = 0.0; |
---|
| 139 | double norm = 0.0; |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | // Get the dispersion points for the major shell |
---|
| 143 | vector<WeightPoint> weights_thickness; |
---|
| 144 | thickness.get_weights(weights_thickness); |
---|
| 145 | |
---|
| 146 | // Get the dispersion points for the minor shell |
---|
| 147 | vector<WeightPoint> weights_radius ; |
---|
| 148 | radius.get_weights(weights_radius); |
---|
| 149 | |
---|
| 150 | // Loop over major shell weight points |
---|
| 151 | for(int j=0; j< (int)weights_thickness.size(); j++) { |
---|
| 152 | dp.thickness = weights_thickness[j].value; |
---|
| 153 | for(int k=0; k< (int)weights_radius.size(); k++) { |
---|
| 154 | dp.radius = weights_radius[k].value; |
---|
| 155 | sum += weights_thickness[j].weight |
---|
| 156 | * weights_radius[k].weight*(dp.radius+dp.thickness); |
---|
| 157 | norm += weights_thickness[j].weight* weights_radius[k].weight; |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | if (norm != 0){ |
---|
| 161 | //return the averaged value |
---|
| 162 | rad_out = sum/norm;} |
---|
| 163 | else{ |
---|
| 164 | //return normal value |
---|
| 165 | rad_out = (dp.radius+dp.thickness);} |
---|
| 166 | |
---|
| 167 | return rad_out; |
---|
| 168 | } |
---|
| 169 | /** |
---|
| 170 | * Function to calculate volf_ratio for shell |
---|
| 171 | * @return: volf_ratio value |
---|
| 172 | */ |
---|
| 173 | double VesicleModel :: calculate_VR() { |
---|
| 174 | VesicleParameters dp; |
---|
| 175 | |
---|
| 176 | dp.radius = radius(); |
---|
| 177 | dp.thickness = thickness(); |
---|
| 178 | |
---|
| 179 | double rad_out = 0.0; |
---|
| 180 | |
---|
| 181 | // Perform the computation, with all weight points |
---|
| 182 | double sum_tot = 0.0; |
---|
| 183 | double sum_shell = 0.0; |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | // Get the dispersion points for the major shell |
---|
| 187 | vector<WeightPoint> weights_thickness; |
---|
| 188 | thickness.get_weights(weights_thickness); |
---|
| 189 | |
---|
| 190 | // Get the dispersion points for the minor shell |
---|
| 191 | vector<WeightPoint> weights_radius ; |
---|
| 192 | radius.get_weights(weights_radius); |
---|
| 193 | |
---|
| 194 | // Loop over major shell weight points |
---|
| 195 | for(int j=0; j< (int)weights_thickness.size(); j++) { |
---|
| 196 | dp.thickness = weights_thickness[j].value; |
---|
| 197 | for(int k=0; k< (int)weights_radius.size(); k++) { |
---|
| 198 | dp.radius = weights_radius[k].value; |
---|
| 199 | sum_tot += weights_thickness[j].weight |
---|
| 200 | * weights_radius[k].weight*pow((dp.radius+dp.thickness), 3); |
---|
| 201 | sum_shell += weights_thickness[j].weight |
---|
| 202 | * weights_radius[k].weight*(pow((dp.radius+dp.thickness), 3) |
---|
| 203 | - pow((dp.radius), 3)); |
---|
| 204 | } |
---|
| 205 | } |
---|
| 206 | if (sum_tot == 0.0){ |
---|
| 207 | //return the default value |
---|
| 208 | rad_out = 1.0;} |
---|
| 209 | else{ |
---|
| 210 | //return ratio value |
---|
| 211 | return sum_shell/sum_tot; |
---|
| 212 | } |
---|
| 213 | } |
---|