Calculates the weights given an array of radials distances and the weighting function setup.
(r, weighting)
| 147 | |
| 148 | |
| 149 | def get_weights(r, weighting): |
| 150 | """Calculates the weights given an array of radials distances and the |
| 151 | weighting function setup. |
| 152 | """ |
| 153 | fname = weighting.get("function") |
| 154 | w0 = weighting.get("w0") |
| 155 | n = r.shape[0] |
| 156 | |
| 157 | # No weighting specified |
| 158 | if fname is None and w0 is None: |
| 159 | return np.ones(n) |
| 160 | else: |
| 161 | # No weighting function, only w0 |
| 162 | if fname is None and w0 is not None: |
| 163 | weights = np.ones(n) |
| 164 | weights[r == 0] = w0 |
| 165 | return weights |
| 166 | else: |
| 167 | if fname == "poly": |
| 168 | r0 = weighting["r0"] |
| 169 | c = weighting["c"] |
| 170 | m = weighting["m"] |
| 171 | |
| 172 | def f(r): |
| 173 | w = c * np.power(1 + 2 * (r / r0) ** 3 - 3 * (r / r0) ** 2, m) |
| 174 | w[r > r0] = 0 |
| 175 | return w |
| 176 | |
| 177 | func = f |
| 178 | elif fname == "pow": |
| 179 | r0 = weighting["r0"] |
| 180 | c = weighting["c"] |
| 181 | d = weighting["d"] |
| 182 | m = weighting["m"] |
| 183 | func = lambda r: c / (d + np.power(r / r0, m)) |
| 184 | elif fname == "exp": |
| 185 | r0 = weighting["r0"] |
| 186 | c = weighting["c"] |
| 187 | d = weighting["d"] |
| 188 | func = lambda r: c / (d + np.exp(-r / r0)) |
| 189 | |
| 190 | # Weighting function and w0 |
| 191 | weights = func(r) |
| 192 | if w0 is not None: |
| 193 | weights[r == 0] = w0 |
| 194 | return weights |
| 195 | |
| 196 | |
| 197 | def coefficients_gto(system, centers, args): |