From e8bacc1211e0a5dabbe1ffc00d7e95c1280a49a7 Mon Sep 17 00:00:00 2001 From: ardunn Date: Fri, 19 Aug 2022 23:43:48 -0700 Subject: [PATCH] reformat --- matminer/datasets/tests/test_utils.py | 8 ++++++-- matminer/datasets/utils.py | 19 +++++++------------ matminer/featurizers/composition/alloy.py | 6 +++--- matminer/featurizers/site/fingerprint.py | 2 +- matminer/featurizers/site/rdf.py | 4 ++-- .../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 +- 12 files changed, 32 insertions(+), 33 deletions(-) diff --git a/matminer/datasets/tests/test_utils.py b/matminer/datasets/tests/test_utils.py index 521205662..c30f1ce0c 100644 --- a/matminer/datasets/tests/test_utils.py +++ b/matminer/datasets/tests/test_utils.py @@ -60,12 +60,16 @@ def test_validate_dataset(self): _validate_dataset(self._path, url=None, file_hash=self._hash, download_if_missing=True) with self.assertRaises(UserWarning): - _validate_dataset(self._path, self._url, file_hash="!@#$%^&*", download_if_missing=True, n_retries_allowed=0) + _validate_dataset( + self._path, self._url, file_hash="!@#$%^&*", download_if_missing=True, n_retries_allowed=0 + ) if os.path.exists(self._path): os.remove(self._path) with self.assertRaises(ValueError): - _validate_dataset(self._path, self._url, file_hash=self._hash, download_if_missing=True, n_retries_allowed=-1) + _validate_dataset( + self._path, self._url, file_hash=self._hash, download_if_missing=True, n_retries_allowed=-1 + ) _validate_dataset(self._path, self._url, self._hash, download_if_missing=True) self.assertTrue(os.path.exists(self._path)) diff --git a/matminer/datasets/utils.py b/matminer/datasets/utils.py index 7a8389915..8d3765645 100644 --- a/matminer/datasets/utils.py +++ b/matminer/datasets/utils.py @@ -45,13 +45,7 @@ def _get_data_home(data_home=None): return data_home -def _validate_dataset( - data_path, - url=None, - file_hash=None, - download_if_missing=True, - n_retries_allowed=3 -): +def _validate_dataset(data_path, url=None, file_hash=None, download_if_missing=True, n_retries_allowed=3): """ Checks to see if a dataset is on the local machine, if not tries to download if download_if_missing is set to true, @@ -76,7 +70,7 @@ def _validate_dataset( Returns (None) """ - DOWNLOAD_RETRY_WAIT = 60 + download_retry_wait = 60 if n_retries_allowed < 0: raise ValueError("Number of retries for download cannot be less than 0.") @@ -100,8 +94,9 @@ def _validate_dataset( do_download = True - hash_mismatch_msg = "Error, hash of downloaded file does not match that " \ - "included in metadata, the data may be corrupt or altered" + hash_mismatch_msg = ( + "Error, hash of downloaded file does not match that " "included in metadata, the data may be corrupt or altered" + ) if do_download: n_retries = 0 while n_retries <= n_retries_allowed: @@ -116,8 +111,8 @@ def _validate_dataset( except UserWarning: warnings.warn(hash_mismatch_msg) if n_retries < n_retries_allowed: - warnings.warn(f"Waiting {DOWNLOAD_RETRY_WAIT}s and trying again...") - time.sleep(DOWNLOAD_RETRY_WAIT) + warnings.warn(f"Waiting {download_retry_wait}s and trying again...") + time.sleep(download_retry_wait) else: raise UserWarning( f"File could not be downloaded to {data_path} after {n_retries_allowed} retries" diff --git a/matminer/featurizers/composition/alloy.py b/matminer/featurizers/composition/alloy.py index e30073f86..9179762c7 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 af3b80728..8462a10bc 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 5b4ff743b..c4dd5820f 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 7b648dbf6..598e9c9e2 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 3c4499ecb..2e0527396 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 b3349b7e8..04f1c26da 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 04f9e5aba..7433f07d4 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 5a8617137..70080c184 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 3b04a9ccb..dd8089017 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 2face5e25..60a34bebc 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)