MCPcopy Create free account
hub / github.com/SINGROUP/dscribe / get_weights

Function get_weights

tests/testutils.py:149–194  ·  view source on GitHub ↗

Calculates the weights given an array of radials distances and the weighting function setup.

(r, weighting)

Source from the content-addressed store, hash-verified

147
148
149def 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
197def coefficients_gto(system, centers, args):

Callers 1

soap_coeffFunction · 0.85

Calls 1

funcFunction · 0.70

Tested by

no test coverage detected