Skip to content

Commit

Permalink
fix some ruff PERF401
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Aug 10, 2023
1 parent 00c9f7d commit 96f7084
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 33 deletions.
4 changes: 1 addition & 3 deletions pymatgen/util/convergence.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ def exponential(x, a, b, n):
elif b > 10:
b = 10
if isinstance(x, list):
y_l = []
for x_v in x:
y_l.append(a + b * n**-x_v)
y_l = [a + b * n**-x_v for x_v in x]
y = np.array(y_l)
else:
y = a + b * n**-x
Expand Down
16 changes: 7 additions & 9 deletions tests/analysis/test_reaction_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,10 @@ def setUp(self):
entries = []
for e in d:
entries.append(ComputedEntry.from_dict(e))
rcts = list(filter(lambda e: e.composition.reduced_formula in ["Li", "O2"], entries))
reactants = list(filter(lambda e: e.composition.reduced_formula in ["Li", "O2"], entries))
prods = list(filter(lambda e: e.composition.reduced_formula == "Li2O2", entries))

self.rxn = ComputedReaction(rcts, prods)
self.rxn = ComputedReaction(reactants, prods)

def test_calculated_reaction_energy(self):
assert self.rxn.calculated_reaction_energy == approx(-5.60748821935)
Expand Down Expand Up @@ -449,10 +449,10 @@ def test_calculated_reaction_energy_uncertainty(self):
entries = []
for e in d:
entries.append(ComputedEntry.from_dict(e))
rcts = list(filter(lambda e: e.composition.reduced_formula in ["Li", "O2"], entries))
reactants = list(filter(lambda e: e.composition.reduced_formula in ["Li", "O2"], entries))
prods = list(filter(lambda e: e.composition.reduced_formula == "Li2O2", entries))

rxn_with_uncertainty = ComputedReaction(rcts, prods)
rxn_with_uncertainty = ComputedReaction(reactants, prods)
assert rxn_with_uncertainty.calculated_reaction_energy_uncertainty == approx(0.5 * 0.0744)

def test_calculated_reaction_energy_uncertainty_for_no_uncertainty(self):
Expand Down Expand Up @@ -519,13 +519,11 @@ def test_calculated_reaction_energy_uncertainty_for_nan(self):
"correction": -1.864,
},
]
entries = []
for e in d:
entries.append(ComputedEntry.from_dict(e))
rcts = list(filter(lambda e: e.composition.reduced_formula in ["Li", "O2"], entries))
entries = [ComputedEntry.from_dict(e) for e in d]
reactants = list(filter(lambda e: e.composition.reduced_formula in ["Li", "O2"], entries))
prods = list(filter(lambda e: e.composition.reduced_formula == "Li2O2", entries))

rxn_with_uncertainty = ComputedReaction(rcts, prods)
rxn_with_uncertainty = ComputedReaction(reactants, prods)
assert isnan(rxn_with_uncertainty.calculated_reaction_energy_uncertainty)

def test_init(self):
Expand Down
15 changes: 6 additions & 9 deletions tests/core/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1409,18 +1409,15 @@ def test_extract_cluster(self):
coords = [
[0, 0, 0],
[0, 0, 1.089000],
[1.026719, 0, -0.363000],
[-0.513360, -0.889165, -0.363000],
[-0.513360, 0.889165, -0.363000],
[1.026719, 0, -0.363],
[-0.513360, -0.889165, -0.363],
[-0.513360, 0.889165, -0.363],
]
ch4 = ["C", "H", "H", "H", "H"]

species = []
all_coords = []
for vec in ([0, 0, 0], [4, 0, 0], [0, 4, 0], [4, 4, 0]):
species.extend(ch4)
for c in coords:
all_coords.append(np.array(c) + vec)
vectors = [[0, 0, 0], [4, 0, 0], [0, 4, 0], [4, 4, 0]]
species = [atom for vec in vectors for atom in ch4]
all_coords = [np.array(c) + vec for vec in vectors for c in coords]

structure = Structure(Lattice.cubic(10), species, all_coords, coords_are_cartesian=True)

Expand Down
17 changes: 5 additions & 12 deletions tests/io/qchem/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,11 @@ def test_lower_and_check_unique(self):
lower_and_check_unique(d4)

def test_process_parsed_HESS(self):
data_132 = []
with zopen(f"{test_dir}/parse_hess/132.0", mode="rb") as file:
binary = file.read()
for ii in range(int(len(binary) / 8)):
data_132.append(struct.unpack("d", binary[ii * 8 : (ii + 1) * 8])[0])

data_HESS = []
with zopen(
f"{test_dir}/parse_hess/HESS",
mode="rt",
encoding="ISO-8859-1",
) as f:
with zopen(f"{test_dir}/parse_hess/132.0", mode="rb") as f:
binary = f.read()
data_132 = [struct.unpack("d", binary[ii * 8 : (ii + 1) * 8])[0] for ii in range(int(len(binary) / 8))]

with zopen(f"{test_dir}/parse_hess/HESS", mode="rt", encoding="ISO-8859-1") as f:
data_HESS = f.readlines()

processed_data_HESS = process_parsed_HESS(data_HESS)
Expand Down

0 comments on commit 96f7084

Please sign in to comment.