[d86f0fc] | 1 | static double |
---|
| 2 | form_volume(double length_a, double b2a_ratio, double c2a_ratio) |
---|
[deb7ee0] | 3 | { |
---|
[a807206] | 4 | return length_a * (length_a*b2a_ratio) * (length_a*c2a_ratio); |
---|
[deb7ee0] | 5 | } |
---|
| 6 | |
---|
[d86f0fc] | 7 | static double |
---|
[99658f6] | 8 | radius_from_excluded_volume(double length_a, double b2a_ratio, double c2a_ratio) |
---|
| 9 | { |
---|
| 10 | double const r_equiv = sqrt(length_a*length_a*b2a_ratio/M_PI); |
---|
| 11 | double const length_c = c2a_ratio*length_a; |
---|
| 12 | return 0.5*cbrt(0.75*r_equiv*(2.0*r_equiv*length_c + (r_equiv + length_c)*(M_PI*r_equiv + length_c))); |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | static double |
---|
[d277229] | 16 | effective_radius(int mode, double length_a, double b2a_ratio, double c2a_ratio) |
---|
| 17 | { |
---|
[ee60aa7] | 18 | switch (mode) { |
---|
[d42dd4a] | 19 | default: |
---|
[99658f6] | 20 | case 1: // equivalent cylinder excluded volume |
---|
| 21 | return radius_from_excluded_volume(length_a,b2a_ratio,c2a_ratio); |
---|
| 22 | case 2: // equivalent volume sphere |
---|
[6d5601c] | 23 | return cbrt(cube(length_a)*b2a_ratio*c2a_ratio/M_4PI_3); |
---|
[99658f6] | 24 | case 3: // half length_a |
---|
[d277229] | 25 | return 0.5 * length_a; |
---|
[99658f6] | 26 | case 4: // half length_b |
---|
[d277229] | 27 | return 0.5 * length_a*b2a_ratio; |
---|
[99658f6] | 28 | case 5: // half length_c |
---|
[d277229] | 29 | return 0.5 * length_a*c2a_ratio; |
---|
[99658f6] | 30 | case 6: // equivalent circular cross-section |
---|
[d277229] | 31 | return length_a*sqrt(b2a_ratio/M_PI); |
---|
[99658f6] | 32 | case 7: // half ab diagonal |
---|
[d277229] | 33 | return 0.5*sqrt(square(length_a) * (1.0 + square(b2a_ratio))); |
---|
[99658f6] | 34 | case 8: // half diagonal |
---|
[d277229] | 35 | return 0.5*sqrt(square(length_a) * (1.0 + square(b2a_ratio) + square(c2a_ratio))); |
---|
| 36 | } |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | static double |
---|
[d86f0fc] | 40 | Iq(double q, |
---|
[deb7ee0] | 41 | double sld, |
---|
| 42 | double solvent_sld, |
---|
[a807206] | 43 | double length_a, |
---|
[deb7ee0] | 44 | double b2a_ratio, |
---|
| 45 | double c2a_ratio) |
---|
| 46 | { |
---|
[ab2aea8] | 47 | const double length_b = length_a * b2a_ratio; |
---|
| 48 | const double length_c = length_a * c2a_ratio; |
---|
| 49 | const double a_half = 0.5 * length_a; |
---|
| 50 | const double b_half = 0.5 * length_b; |
---|
| 51 | const double c_half = 0.5 * length_c; |
---|
[deb7ee0] | 52 | |
---|
| 53 | //Integration limits to use in Gaussian quadrature |
---|
[ab2aea8] | 54 | const double v1a = 0.0; |
---|
| 55 | const double v1b = M_PI_2; //theta integration limits |
---|
| 56 | const double v2a = 0.0; |
---|
| 57 | const double v2b = M_PI_2; //phi integration limits |
---|
[8de1477] | 58 | |
---|
[ab2aea8] | 59 | double outer_sum = 0.0; |
---|
[74768cb] | 60 | for(int i=0; i<GAUSS_N; i++) { |
---|
| 61 | const double theta = 0.5 * ( GAUSS_Z[i]*(v1b-v1a) + v1a + v1b ); |
---|
[ab2aea8] | 62 | double sin_theta, cos_theta; |
---|
| 63 | SINCOS(theta, sin_theta, cos_theta); |
---|
| 64 | |
---|
[1e7b0db0] | 65 | const double termC = sas_sinx_x(q * c_half * cos_theta); |
---|
[ab2aea8] | 66 | |
---|
| 67 | double inner_sum = 0.0; |
---|
[74768cb] | 68 | for(int j=0; j<GAUSS_N; j++) { |
---|
| 69 | double phi = 0.5 * ( GAUSS_Z[j]*(v2b-v2a) + v2a + v2b ); |
---|
[ab2aea8] | 70 | double sin_phi, cos_phi; |
---|
| 71 | SINCOS(phi, sin_phi, cos_phi); |
---|
| 72 | |
---|
| 73 | // Amplitude AP from eqn. (12), rewritten to avoid round-off effects when arg=0 |
---|
[1e7b0db0] | 74 | const double termA = sas_sinx_x(q * a_half * sin_theta * sin_phi); |
---|
| 75 | const double termB = sas_sinx_x(q * b_half * sin_theta * cos_phi); |
---|
[ab2aea8] | 76 | const double AP = termA * termB * termC; |
---|
[74768cb] | 77 | inner_sum += GAUSS_W[j] * AP * AP; |
---|
[ab2aea8] | 78 | } |
---|
| 79 | inner_sum = 0.5 * (v2b-v2a) * inner_sum; |
---|
[74768cb] | 80 | outer_sum += GAUSS_W[i] * inner_sum * sin_theta; |
---|
[deb7ee0] | 81 | } |
---|
| 82 | |
---|
[ab2aea8] | 83 | double answer = 0.5*(v1b-v1a)*outer_sum; |
---|
[deb7ee0] | 84 | |
---|
[8de1477] | 85 | // Normalize by Pi (Eqn. 16). |
---|
| 86 | // The term (ABC)^2 does not appear because it was introduced before on |
---|
[deb7ee0] | 87 | // the definitions of termA, termB, termC. |
---|
[8de1477] | 88 | // The factor 2 appears because the theta integral has been defined between |
---|
[deb7ee0] | 89 | // 0 and pi/2, instead of 0 to pi. |
---|
[3a48772] | 90 | answer /= M_PI_2; //Form factor P(q) |
---|
[deb7ee0] | 91 | |
---|
| 92 | // Multiply by contrast^2 and volume^2 |
---|
[ab2aea8] | 93 | const double volume = length_a * length_b * length_c; |
---|
| 94 | answer *= square((sld-solvent_sld)*volume); |
---|
[deb7ee0] | 95 | |
---|
[8de1477] | 96 | // Convert from [1e-12 A-1] to [cm-1] |
---|
[deb7ee0] | 97 | answer *= 1.0e-4; |
---|
| 98 | |
---|
| 99 | return answer; |
---|
| 100 | } |
---|
[8de1477] | 101 | |
---|
[71b751d] | 102 | static void |
---|
| 103 | Fq(double q, |
---|
| 104 | double *F1, |
---|
| 105 | double *F2, |
---|
| 106 | double sld, |
---|
| 107 | double solvent_sld, |
---|
| 108 | double length_a, |
---|
| 109 | double b2a_ratio, |
---|
| 110 | double c2a_ratio) |
---|
| 111 | { |
---|
| 112 | const double length_b = length_a * b2a_ratio; |
---|
| 113 | const double length_c = length_a * c2a_ratio; |
---|
| 114 | const double a_half = 0.5 * length_a; |
---|
| 115 | const double b_half = 0.5 * length_b; |
---|
| 116 | const double c_half = 0.5 * length_c; |
---|
| 117 | |
---|
| 118 | //Integration limits to use in Gaussian quadrature |
---|
| 119 | const double v1a = 0.0; |
---|
| 120 | const double v1b = M_PI_2; //theta integration limits |
---|
| 121 | const double v2a = 0.0; |
---|
| 122 | const double v2b = M_PI_2; //phi integration limits |
---|
| 123 | |
---|
| 124 | double outer_sum_F1 = 0.0; |
---|
| 125 | double outer_sum_F2 = 0.0; |
---|
| 126 | for(int i=0; i<GAUSS_N; i++) { |
---|
| 127 | const double theta = 0.5 * ( GAUSS_Z[i]*(v1b-v1a) + v1a + v1b ); |
---|
| 128 | double sin_theta, cos_theta; |
---|
| 129 | SINCOS(theta, sin_theta, cos_theta); |
---|
| 130 | |
---|
| 131 | const double termC = sas_sinx_x(q * c_half * cos_theta); |
---|
| 132 | |
---|
| 133 | double inner_sum_F1 = 0.0; |
---|
| 134 | double inner_sum_F2 = 0.0; |
---|
| 135 | for(int j=0; j<GAUSS_N; j++) { |
---|
| 136 | double phi = 0.5 * ( GAUSS_Z[j]*(v2b-v2a) + v2a + v2b ); |
---|
| 137 | double sin_phi, cos_phi; |
---|
| 138 | SINCOS(phi, sin_phi, cos_phi); |
---|
| 139 | |
---|
| 140 | // Amplitude AP from eqn. (12), rewritten to avoid round-off effects when arg=0 |
---|
| 141 | const double termA = sas_sinx_x(q * a_half * sin_theta * sin_phi); |
---|
| 142 | const double termB = sas_sinx_x(q * b_half * sin_theta * cos_phi); |
---|
| 143 | const double AP = termA * termB * termC; |
---|
| 144 | inner_sum_F1 += GAUSS_W[j] * AP; |
---|
| 145 | inner_sum_F2 += GAUSS_W[j] * AP * AP; |
---|
| 146 | } |
---|
| 147 | inner_sum_F1 = 0.5 * (v2b-v2a) * inner_sum_F1; |
---|
| 148 | inner_sum_F2 = 0.5 * (v2b-v2a) * inner_sum_F2; |
---|
| 149 | outer_sum_F1 += GAUSS_W[i] * inner_sum_F1 * sin_theta; |
---|
| 150 | outer_sum_F2 += GAUSS_W[i] * inner_sum_F2 * sin_theta; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | outer_sum_F1 *= 0.5*(v1b-v1a); |
---|
| 154 | outer_sum_F2 *= 0.5*(v1b-v1a); |
---|
| 155 | |
---|
| 156 | // Normalize by Pi (Eqn. 16). |
---|
| 157 | // The term (ABC)^2 does not appear because it was introduced before on |
---|
| 158 | // the definitions of termA, termB, termC. |
---|
| 159 | // The factor 2 appears because the theta integral has been defined between |
---|
| 160 | // 0 and pi/2, instead of 0 to pi. |
---|
| 161 | outer_sum_F1 /= M_PI_2; |
---|
| 162 | outer_sum_F2 /= M_PI_2; |
---|
| 163 | |
---|
| 164 | // Multiply by contrast and volume |
---|
| 165 | const double s = (sld-solvent_sld) * (length_a * length_b * length_c); |
---|
| 166 | |
---|
| 167 | // Convert from [1e-12 A-1] to [cm-1] |
---|
| 168 | *F1 = 1e-2 * s * outer_sum_F1; |
---|
| 169 | *F2 = 1e-4 * s * s * outer_sum_F2; |
---|
| 170 | } |
---|
| 171 | |
---|
[8de1477] | 172 | |
---|
[d86f0fc] | 173 | static double |
---|
| 174 | Iqabc(double qa, double qb, double qc, |
---|
[8de1477] | 175 | double sld, |
---|
| 176 | double solvent_sld, |
---|
| 177 | double length_a, |
---|
| 178 | double b2a_ratio, |
---|
| 179 | double c2a_ratio) |
---|
| 180 | { |
---|
| 181 | const double length_b = length_a * b2a_ratio; |
---|
| 182 | const double length_c = length_a * c2a_ratio; |
---|
| 183 | const double a_half = 0.5 * length_a; |
---|
| 184 | const double b_half = 0.5 * length_b; |
---|
| 185 | const double c_half = 0.5 * length_c; |
---|
| 186 | |
---|
| 187 | // Amplitude AP from eqn. (13) |
---|
| 188 | const double termA = sas_sinx_x(qa * a_half); |
---|
| 189 | const double termB = sas_sinx_x(qb * b_half); |
---|
| 190 | const double termC = sas_sinx_x(qc * c_half); |
---|
| 191 | const double AP = termA * termB * termC; |
---|
| 192 | |
---|
[71b751d] | 193 | // Multiply by contrast and volume |
---|
| 194 | const double s = (sld-solvent_sld) * (length_a * length_b * length_c); |
---|
[8de1477] | 195 | |
---|
| 196 | // Convert from [1e-12 A-1] to [cm-1] |
---|
[71b751d] | 197 | return 1.0e-4 * square(s * AP); |
---|
[d277229] | 198 | } |
---|