* Used to calculate the Gaussian weights for each neighbouring atom. Provide * either r1s (=r) or r2s (=r^2) and use the boolean "squared" to indicate if * r1s should be calculated from r2s. */
| 9 | * r1s should be calculated from r2s. |
| 10 | */ |
| 11 | void getWeights(int size, double* r1s, double* r2s, const bool squared, const py::dict &weighting, double* weights) { |
| 12 | // No weighting specified |
| 13 | if (!weighting.contains("function") && !weighting.contains("w0")) { |
| 14 | for (int i = 0; i < size; i++) { |
| 15 | weights[i] = 1; |
| 16 | } |
| 17 | } else { |
| 18 | // No weighting function, only w0 |
| 19 | if (squared) { |
| 20 | for (int i = 0; i < size; i++) { |
| 21 | r1s[i] = sqrt(r2s[i]); |
| 22 | } |
| 23 | } |
| 24 | if (!weighting.contains("function") && weighting.contains("w0")) { |
| 25 | double w0 = weighting["w0"].cast<double>(); |
| 26 | for (int i = 0; i < size; i++) { |
| 27 | double r = r1s[i]; |
| 28 | if (r == 0) { |
| 29 | weights[i] = w0; |
| 30 | } else { |
| 31 | weights[i] = 1; |
| 32 | } |
| 33 | } |
| 34 | } else { |
| 35 | function<double (double)> func; |
| 36 | string fname = weighting["function"].cast<string>(); |
| 37 | if (fname == "poly") { |
| 38 | double r0 = weighting["r0"].cast<double>(); |
| 39 | double c = weighting["c"].cast<double>(); |
| 40 | double m = weighting["m"].cast<double>(); |
| 41 | func = [r0, c, m](double r) {return weightPoly(r, r0, c, m);}; |
| 42 | } else if (fname == "pow") { |
| 43 | double r0 = weighting["r0"].cast<double>(); |
| 44 | double c = weighting["c"].cast<double>(); |
| 45 | double d = weighting["d"].cast<double>(); |
| 46 | double m = weighting["m"].cast<double>(); |
| 47 | func = [r0, c, d, m](double r) {return weightPow(r, r0, c, d, m);}; |
| 48 | } else if (fname == "exp") { |
| 49 | double r0 = weighting["r0"].cast<double>(); |
| 50 | double c = weighting["c"].cast<double>(); |
| 51 | double d = weighting["d"].cast<double>(); |
| 52 | func = [r0, c, d](double r) {return weightExp(r, r0, c, d);}; |
| 53 | } |
| 54 | // Weighting function and w0 |
| 55 | if (weighting.contains("w0")) { |
| 56 | double w0 = weighting["w0"].cast<double>(); |
| 57 | for (int i = 0; i < size; i++) { |
| 58 | double r = r1s[i]; |
| 59 | if (r == 0) { |
| 60 | weights[i] = w0; |
| 61 | } else { |
| 62 | weights[i] = func(r); |
| 63 | } |
| 64 | } |
| 65 | // Weighting function only |
| 66 | } else { |
| 67 | for (int i = 0; i < size; i++) { |
| 68 | double r = r1s[i]; |
no test coverage detected