From 7f8520b97175db3c4fc6afe055cee664ebd77238 Mon Sep 17 00:00:00 2001 From: ardunn Date: Sat, 20 Aug 2022 00:04:41 -0700 Subject: [PATCH] reformat to make linter happy --- matminer/featurizers/composition/alloy.py | 6 +++--- matminer/featurizers/site/fingerprint.py | 2 +- matminer/featurizers/site/rdf.py | 4 ++-- matminer/featurizers/site/tests/test_fingerprint.py | 4 ++-- matminer/featurizers/structure/bonding.py | 2 +- matminer/featurizers/structure/order.py | 2 +- matminer/featurizers/utils/grdf.py | 10 +++++----- matminer/featurizers/utils/stats.py | 4 ++-- matminer/featurizers/utils/tests/test_grdf.py | 2 +- matminer/utils/kernels.py | 2 +- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/matminer/featurizers/composition/alloy.py b/matminer/featurizers/composition/alloy.py index 9179762c7..e30073f86 100644 --- a/matminer/featurizers/composition/alloy.py +++ b/matminer/featurizers/composition/alloy.py @@ -766,7 +766,7 @@ def compute_lambda(yang_delta, entropy): float """ if yang_delta != 0: - return entropy / yang_delta ** 2 + return entropy / yang_delta**2 else: return 0 @@ -791,8 +791,8 @@ def compute_gamma_radii(miracle_radius_stats): mrmin = miracle_radius_stats["min"] mrmax = miracle_radius_stats["max"] - numerator = 1 - np.sqrt((mrmean * mrmin + mrmin ** 2) / (mrmean + mrmin) ** 2) - denominator = 1 - np.sqrt((mrmean * mrmax + mrmax ** 2) / (mrmean + mrmax) ** 2) + numerator = 1 - np.sqrt((mrmean * mrmin + mrmin**2) / (mrmean + mrmin) ** 2) + denominator = 1 - np.sqrt((mrmean * mrmax + mrmax**2) / (mrmean + mrmax) ** 2) return numerator / denominator @staticmethod diff --git a/matminer/featurizers/site/fingerprint.py b/matminer/featurizers/site/fingerprint.py index 8462a10bc..af3b80728 100644 --- a/matminer/featurizers/site/fingerprint.py +++ b/matminer/featurizers/site/fingerprint.py @@ -262,7 +262,7 @@ def featurize(self, struct, idx): site_list.append(n) this_av_inv_drel += 1.0 / (neigh_dist[j][1]) this_av_inv_drel = this_av_inv_drel / float(this_cn) - d_fac = this_av_inv_drel ** self.dist_exp + d_fac = this_av_inv_drel**self.dist_exp for cn in range(max(2, prev_cn + 1), min(this_cn + 1, 13)): # Set all OPs of non-CN-complying neighbor environments # to zero if applicable. diff --git a/matminer/featurizers/site/rdf.py b/matminer/featurizers/site/rdf.py index c4dd5820f..5b4ff743b 100644 --- a/matminer/featurizers/site/rdf.py +++ b/matminer/featurizers/site/rdf.py @@ -74,7 +74,7 @@ def g2(eta, rs, cutoff): Returns: (float) Gaussian radial symmetry function. """ - ridge = np.exp(-eta * (rs ** 2.0) / (cutoff ** 2.0)) * GaussianSymmFunc.cosine_cutoff(rs, cutoff) + ridge = np.exp(-eta * (rs**2.0) / (cutoff**2.0)) * GaussianSymmFunc.cosine_cutoff(rs, cutoff) return ridge.sum() @staticmethod @@ -118,7 +118,7 @@ def g4(etas, zetas, gammas, neigh_dist, neigh_coords, cutoff): ind = 0 for eta in etas: # Compute the eta term - eta_term = np.exp(-eta * (r_ij ** 2.0 + r_ik ** 2.0 + r_jk ** 2.0) / (cutoff ** 2.0)) * cutoff_fun + eta_term = np.exp(-eta * (r_ij**2.0 + r_ik**2.0 + r_jk**2.0) / (cutoff**2.0)) * cutoff_fun for zeta in zetas: for gamma in gammas: term = (1.0 + gamma * cos_theta) ** zeta * eta_term diff --git a/matminer/featurizers/site/tests/test_fingerprint.py b/matminer/featurizers/site/tests/test_fingerprint.py index 598e9c9e2..7b648dbf6 100644 --- a/matminer/featurizers/site/tests/test_fingerprint.py +++ b/matminer/featurizers/site/tests/test_fingerprint.py @@ -68,9 +68,9 @@ def test_off_center_cscl(self): self.assertArrayAlmostEqual(-1 * site1[8:], site2[8:]) # Make sure the site-ones are as expected. - right_dist = 4.209 * np.sqrt(0.45 ** 2 + 2 * 0.5 ** 2) + right_dist = 4.209 * np.sqrt(0.45**2 + 2 * 0.5**2) right_xdist = 4.209 * 0.45 - left_dist = 4.209 * np.sqrt(0.55 ** 2 + 2 * 0.5 ** 2) + left_dist = 4.209 * np.sqrt(0.55**2 + 2 * 0.5**2) left_xdist = 4.209 * 0.55 self.assertAlmostEqual( 4 diff --git a/matminer/featurizers/structure/bonding.py b/matminer/featurizers/structure/bonding.py index 2e0527396..3c4499ecb 100644 --- a/matminer/featurizers/structure/bonding.py +++ b/matminer/featurizers/structure/bonding.py @@ -421,7 +421,7 @@ def _approximate_bonds(self, local_bonds): d0 = u_mends[0] - l_mends[0] d1 = u_mends[1] - l_mends[1] - d = (d0 ** 2.0 + d1 ** 2.0) ** 0.5 + d = (d0**2.0 + d1**2.0) ** 0.5 if not d_min: d_min = d nearest = [abss] diff --git a/matminer/featurizers/structure/order.py b/matminer/featurizers/structure/order.py index 04f1c26da..b3349b7e8 100644 --- a/matminer/featurizers/structure/order.py +++ b/matminer/featurizers/structure/order.py @@ -62,7 +62,7 @@ def featurize(self, s): raise ValueError("Disordered structure support not built yet.") total_rad = 0 for site in s: - total_rad += site.specie.atomic_radius ** 3 + total_rad += site.specie.atomic_radius**3 output.append(4 * math.pi * total_rad / (3 * s.volume)) return output diff --git a/matminer/featurizers/utils/grdf.py b/matminer/featurizers/utils/grdf.py index 7433f07d4..04f9e5aba 100644 --- a/matminer/featurizers/utils/grdf.py +++ b/matminer/featurizers/utils/grdf.py @@ -65,7 +65,7 @@ def volume(self, cutoff): (float): Volume of bin """ - results = integrate.quad(lambda x: 4.0 * pi * self(x) * x ** 2.0, 0, cutoff) + results = integrate.quad(lambda x: 4.0 * pi * self(x) * x**2.0, 0, cutoff) if results[1] > 1e-5: raise ValueError("Numerical integration fails for this function." " Please implement analytic integral") return results[0] @@ -92,7 +92,7 @@ def __call__(self, r_ij): ) def volume(self, cutoff): - return 4.0 / 3 * np.pi * (min(self.start + self.width, cutoff) ** 3 - self.start ** 3) + return 4.0 / 3 * np.pi * (min(self.start + self.width, cutoff) ** 3 - self.start**3) class Gaussian(AbstractPairwise): @@ -117,7 +117,7 @@ def volume(self, cutoff): * self.width * ( np.sqrt(pi) - * (2 * self.center ** 2 + self.width ** 2) + * (2 * self.center**2 + self.width**2) * (erf((cutoff - self.center) / self.width) + erf(self.center / self.width)) + 2 * self.width * (self.center * self(0) - (self.center + cutoff) * self(cutoff)) ) @@ -143,7 +143,7 @@ def volume(self, cutoff): 4 * pi * (((self.a * cutoff) ** 2 - 2) * np.sin(self.a * cutoff) + 2 * self.a * cutoff * np.cos(self.a * cutoff)) - / self.a ** 3 + / self.a**3 ) @@ -170,7 +170,7 @@ def volume(self, cutoff): + 2 * self.a * cutoff * np.sin(self.a * cutoff) - 2 ) - / self.a ** 3 + / self.a**3 ) diff --git a/matminer/featurizers/utils/stats.py b/matminer/featurizers/utils/stats.py index 70080c184..5a8617137 100644 --- a/matminer/featurizers/utils/stats.py +++ b/matminer/featurizers/utils/stats.py @@ -173,7 +173,7 @@ def skewness(data_lst, weights=None): u2 = np.dot(weights, np.power(diff, 2)) / total_weight if np.isclose(u3, 0): return 0 - return u3 / u2 ** 1.5 + return u3 / u2**1.5 @staticmethod def kurtosis(data_lst, weights=None): @@ -203,7 +203,7 @@ def kurtosis(data_lst, weights=None): u2 = np.dot(weights, diff_sq) if np.isclose(u4, 0): return 0 - return u4 / u2 ** 2 * total_weight + return u4 / u2**2 * total_weight @staticmethod def geom_std_dev(data_lst, weights=None): diff --git a/matminer/featurizers/utils/tests/test_grdf.py b/matminer/featurizers/utils/tests/test_grdf.py index dd8089017..3b04a9ccb 100644 --- a/matminer/featurizers/utils/tests/test_grdf.py +++ b/matminer/featurizers/utils/tests/test_grdf.py @@ -35,7 +35,7 @@ def test_gaussian(self): def test_histogram(self): h = Histogram(1, 4) self.assertArrayAlmostEqual([0, 1, 0], h([0.5, 2, 5])) - self.assertAlmostEqual(h.volume(10), 4 / 3.0 * np.pi * (5 ** 3 - 1 ** 3)) + self.assertAlmostEqual(h.volume(10), 4 / 3.0 * np.pi * (5**3 - 1**3)) def test_cosine(self): c = Cosine(2) diff --git a/matminer/utils/kernels.py b/matminer/utils/kernels.py index 60a34bebc..2face5e25 100644 --- a/matminer/utils/kernels.py +++ b/matminer/utils/kernels.py @@ -18,4 +18,4 @@ def gaussian_kernel(arr0, arr1, SIGMA): kernel trick. """ diff = arr0 - arr1 - return np.exp(-np.linalg.norm(diff.A1, ord=2) ** 2 / 2 / SIGMA ** 2) + return np.exp(-np.linalg.norm(diff.A1, ord=2) ** 2 / 2 / SIGMA**2)