Skip to content

Commit

Permalink
drop duplicates in set literals
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed May 24, 2023
1 parent ae3197d commit 7d2f9a1
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ci:

repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.269
rev: v0.0.270
hooks:
- id: ruff
args: [--fix]
Expand Down
3 changes: 0 additions & 3 deletions pymatgen/command_line/gulp_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@
"meanke",
"nodensity_out",
"nodpsym",
"nofirst_point",
"nofrequency",
"nokpoints",
"operators",
Expand All @@ -217,8 +216,6 @@
"save",
"terse",
# Structure control
"full",
"hexagonal",
"lower_symmetry",
"nosymmetry",
# PDF control
Expand Down
16 changes: 8 additions & 8 deletions pymatgen/io/lammps/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ def map_mass(v):

self.topo_coeffs = topo_coeffs
if self.topo_coeffs:
self.topo_coeffs = {k: v for k, v in self.topo_coeffs.items() if k in SECTION_KEYWORDS["ff"][2:]}
self.topo_coeffs = {key: v for key, v in self.topo_coeffs.items() if key in SECTION_KEYWORDS["ff"][2:]}
for k in self.topo_coeffs:
coeffs, mapper = self._process_topo(k)
ff_dfs.update(coeffs)
Expand All @@ -1091,20 +1091,20 @@ def map_mass(v):
def _process_nonbond(self):
pair_df = pd.DataFrame(self.nonbond_coeffs)
assert self._is_valid(pair_df), "Invalid nonbond coefficients with rows varying in length"
npair, ncoeff = pair_df.shape
pair_df.columns = [f"coeff{i}" for i in range(1, ncoeff + 1)]
n_pair, n_coeff = pair_df.shape
pair_df.columns = [f"coeff{i}" for i in range(1, n_coeff + 1)]
nm = len(self.mass_info)
ncomb = int(nm * (nm + 1) / 2)
if npair == nm:
n_comb = int(nm * (nm + 1) / 2)
if n_pair == nm:
kw = "Pair Coeffs"
pair_df.index = range(1, nm + 1)
elif npair == ncomb:
elif n_pair == n_comb:
kw = "PairIJ Coeffs"
ids = list(itertools.combinations_with_replacement(range(1, nm + 1), 2))
id_df = pd.DataFrame(ids, columns=["id1", "id2"])
pair_df = pd.concat([id_df, pair_df], axis=1)
else:
raise ValueError(f"Expecting {nm} Pair Coeffs or {ncomb} PairIJ Coeffs for {nm} atom types, got {npair}")
raise ValueError(f"Expecting {nm} Pair Coeffs or {n_comb} PairIJ Coeffs for {nm} atom types, got {n_pair}")
return {kw: pair_df}

def _process_topo(self, kw):
Expand All @@ -1113,7 +1113,7 @@ def find_eq_types(label, section):
label_arr = np.array(label)
seqs = [[0, 1, 2, 3], [0, 2, 1, 3], [3, 1, 2, 0], [3, 2, 1, 0]]
return [tuple(label_arr[s]) for s in seqs]
return [label] + [label[::-1]]
return [label, label[::-1]]

main_data, distinct_types = [], []
class2_data = {k: [] for k in self.topo_coeffs[kw][0] if k in CLASS2_KEYWORDS.get(kw, [])}
Expand Down
1 change: 0 additions & 1 deletion pymatgen/io/phonopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,6 @@ def get_thermal_displacement_matrices(
structure_path: path to POSCAR
Returns:
"""
thermal_displacements_dict = loadfn(thermal_displacements_yaml)

Expand Down
3 changes: 0 additions & 3 deletions pymatgen/io/qchem/tests/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,7 @@
"tfsi_nbo.qcout",
"crowd_nbo_charges.qcout",
"h2o_aimd.qcout",
"quinoxaline_anion.qcout",
"crowd_gradient_number.qcout",
"bsse.qcout",
"thiophene_wfs_5_carboxyl.qcout",
"time_nan_values.qcout",
"pt_dft_180.0.qcout",
"qchem_energies/hf-rimp2.qcout",
Expand Down
24 changes: 8 additions & 16 deletions pymatgen/io/vasp/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4677,29 +4677,21 @@ def __init__(self, filename="WAVECAR", verbose=False, precision="normal", vasp_t
np.fromfile(f, dtype=np.float64, count=(recl8 - 4 - 3 * self.nb) % recl8)

if self.vasp_type is None:
(
self.Gpoints[ink],
extra_gpoints,
extra_coeff_inds,
) = self._generate_G_points(kpoint, gamma=True)
self.Gpoints[ink], extra_gpoints, extra_coeff_inds = self._generate_G_points(kpoint, gamma=True)
if len(self.Gpoints[ink]) == nplane:
self.vasp_type = "gam"
else:
(
self.Gpoints[ink],
extra_gpoints,
extra_coeff_inds,
) = self._generate_G_points(kpoint, gamma=False)
self.Gpoints[ink], extra_gpoints, extra_coeff_inds = self._generate_G_points(
kpoint, gamma=False
)
self.vasp_type = "std" if len(self.Gpoints[ink]) == nplane else "ncl"

if verbose:
print("\ndetermined vasp_type =", self.vasp_type, "\n")
print(f"\ndetermined {self.vasp_type = }\n")
else:
(
self.Gpoints[ink],
extra_gpoints,
extra_coeff_inds,
) = self._generate_G_points(kpoint, gamma=self.vasp_type.lower()[0] == "g")
self.Gpoints[ink], extra_gpoints, extra_coeff_inds = self._generate_G_points(
kpoint, gamma=self.vasp_type.lower()[0] == "g"
)

if len(self.Gpoints[ink]) != nplane and 2 * len(self.Gpoints[ink]) != nplane:
raise ValueError(
Expand Down
16 changes: 3 additions & 13 deletions pymatgen/util/convergence.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def id_generator(size=8, chars=string.ascii_uppercase + string.digits):
chars ():
Returns:
"""
return "".join(random.choice(chars) for _ in range(size))

Expand Down Expand Up @@ -103,7 +102,6 @@ def print_and_raise_error(xs, ys, name):
name ():
Returns:
"""
print("Index error in", name)
print("ys: ", ys)
Expand Down Expand Up @@ -168,7 +166,6 @@ def p0_exponential(xs, ys):
ys ():
Returns:
"""
n0 = 1.005
b0 = (n0 ** -xs[-1] - n0 ** -xs[1]) / (ys[-1] - ys[1])
Expand Down Expand Up @@ -200,7 +197,6 @@ def p0_single_reciprocal(xs, ys):
ys ():
Returns:
"""
c = 1
b = (1 / (xs[-1] - c) - 1 / (xs[1] - c)) / (ys[-1] - ys[1])
Expand Down Expand Up @@ -230,7 +226,6 @@ def p0_simple_reciprocal(xs, ys):
ys ():
Returns:
"""
b = (ys[-1] - ys[-2]) / (1 / (xs[-1]) - 1 / (xs[-2]))
a = ys[-2] - b / (xs[-2])
Expand Down Expand Up @@ -260,7 +255,6 @@ def p0_simple_2reciprocal(xs, ys):
ys ():
Returns:
"""
c = 2
b = (ys[-1] - ys[1]) / (1 / xs[-1] ** c - 1 / xs[1] ** c)
Expand Down Expand Up @@ -291,7 +285,6 @@ def p0_simple_4reciprocal(xs, ys):
ys ():
Returns:
"""
c = 4
b = (ys[-1] - ys[1]) / (1 / xs[-1] ** c - 1 / xs[1] ** c)
Expand Down Expand Up @@ -321,7 +314,6 @@ def p0_simple_5reciprocal(xs, ys):
ys ():
Returns:
"""
c = 0.5
b = (ys[-1] - ys[1]) / (1 / xs[-1] ** c - 1 / xs[1] ** c)
Expand All @@ -337,7 +329,6 @@ def extrapolate_simple_reciprocal(xs, ys):
ys ():
Returns:
"""
b = (ys[-2] - ys[-1]) / (1 / (xs[-2]) - 1 / (xs[-1]))
a = ys[-1] - b / (xs[-1])
Expand Down Expand Up @@ -383,7 +374,7 @@ def measure(function, xs, ys, popt, weights):
raise NotImplementedError
n += 1
except IndexError:
raise RuntimeError("y does not exist for x = ", x, " this should not happen")
raise RuntimeError(f"y does not exist for {x = }, this should not happen")

return m

Expand All @@ -396,7 +387,6 @@ def get_weights(xs, ys, mode=2):
mode ():
Returns:
"""
ds = get_derivatives(xs, ys, fd=True)
if mode == 1:
Expand All @@ -407,10 +397,10 @@ def get_weights(xs, ys, mode=2):
for d in ds:
weights.append(abs(mind / d))
if mode == 2:
maxxs = max(xs) ** 2
x_max = max(xs) ** 2
weights = []
for x in xs:
weights.append(x**2 / maxxs)
weights.append(x**2 / x_max)
else:
weights = [1] * len(xs)
return weights
Expand Down

0 comments on commit 7d2f9a1

Please sign in to comment.