diff --git a/pymatgen/io/lmto.py b/pymatgen/io/lmto.py index 28282b46387..5844f5db2aa 100644 --- a/pymatgen/io/lmto.py +++ b/pymatgen/io/lmto.py @@ -184,13 +184,13 @@ def from_str(cls, data: str, sigfigs: int = 8) -> LMTOCtrl: for cat in ["STRUC", "CLASS", "SITE"]: fields = struct_lines[cat].split("=") - for f, field in enumerate(fields): + for idx, field in enumerate(fields): token = field.split()[-1] if token == "ALAT": - alat = round(float(fields[f + 1].split()[0]), sigfigs) - structure_tokens["ALAT"] = alat + a_lat = round(float(fields[idx + 1].split()[0]), sigfigs) + structure_tokens["ALAT"] = a_lat elif token == "ATOM": - atom = fields[f + 1].split()[0] + atom = fields[idx + 1].split()[0] if not bool(re.match("E[0-9]*$", atom)): if cat == "CLASS": structure_tokens["CLASS"].append(atom) @@ -200,9 +200,9 @@ def from_str(cls, data: str, sigfigs: int = 8) -> LMTOCtrl: pass elif token in ["PLAT", "POS"]: try: - arr = np.array([round(float(i), sigfigs) for i in fields[f + 1].split()]) + arr = np.array([round(float(i), sigfigs) for i in fields[idx + 1].split()]) except ValueError: - arr = np.array([round(float(i), sigfigs) for i in fields[f + 1].split()[:-1]]) + arr = np.array([round(float(i), sigfigs) for i in fields[idx + 1].split()[:-1]]) if token == "PLAT": structure_tokens["PLAT"] = arr.reshape([3, 3]) elif not bool(re.match("E[0-9]*$", atom)): @@ -212,9 +212,9 @@ def from_str(cls, data: str, sigfigs: int = 8) -> LMTOCtrl: else: pass try: - spcgrp_index = struct_lines["SYMGRP"].index("SPCGRP") - spcgrp = struct_lines["SYMGRP"][spcgrp_index : spcgrp_index + 12] - structure_tokens["SPCGRP"] = spcgrp.split("=")[1].split()[0] + spc_grp_index = struct_lines["SYMGRP"].index("SPCGRP") + spc_grp = struct_lines["SYMGRP"][spc_grp_index : spc_grp_index + 12] + structure_tokens["SPCGRP"] = spc_grp.split("=")[1].split()[0] except ValueError: pass diff --git a/pymatgen/io/nwchem.py b/pymatgen/io/nwchem.py index dd8ad469f69..edc3d22b574 100644 --- a/pymatgen/io/nwchem.py +++ b/pymatgen/io/nwchem.py @@ -920,15 +920,15 @@ def isfloatstring(in_str): for _freq, mode in normal_frequencies: mode[:] = zip(*[iter(mode)] * 3) if hessian: - n = len(hessian) - for i in range(n): - for j in range(i + 1, n): - hessian[i].append(hessian[j][i]) + len_hess = len(hessian) + for ii in range(len_hess): + for jj in range(ii + 1, len_hess): + hessian[ii].append(hessian[jj][ii]) if projected_hessian: - n = len(projected_hessian) - for i in range(n): - for j in range(i + 1, n): - projected_hessian[i].append(projected_hessian[j][i]) + len_hess = len(projected_hessian) + for ii in range(len_hess): + for jj in range(ii + 1, len_hess): + projected_hessian[ii].append(projected_hessian[jj][ii]) data.update( { diff --git a/tests/analysis/elasticity/test_elastic.py b/tests/analysis/elasticity/test_elastic.py index 0a290726523..27a56b81fd7 100644 --- a/tests/analysis/elasticity/test_elastic.py +++ b/tests/analysis/elasticity/test_elastic.py @@ -411,8 +411,8 @@ def test_get_strain_state_dict(self): strain_states.append(tuple(ss)) vec = np.zeros((4, 6)) rand_values = np.random.uniform(0.1, 1, 4) - for i in strain_ind: - vec[:, i] = rand_values + for idx in strain_ind: + vec[:, idx] = rand_values vecs[strain_ind] = vec all_strains = [Strain.from_voigt(v).zeroed() for vec in vecs.values() for v in vec] random.shuffle(all_strains) diff --git a/tests/analysis/ferroelectricity/test_polarization.py b/tests/analysis/ferroelectricity/test_polarization.py index 6d53def1b66..b28a2430626 100644 --- a/tests/analysis/ferroelectricity/test_polarization.py +++ b/tests/analysis/ferroelectricity/test_polarization.py @@ -17,7 +17,7 @@ TEST_DIR = f"{TEST_FILES_DIR}/vasp/fixtures/BTO_221_99_polarization" bto_folders = ["nonpolar_polarization"] -bto_folders += [f"interpolation_{i}_polarization" for i in range(1, 9)][::-1] +bto_folders += [f"interpolation_{idx}_polarization" for idx in range(8, 0, -1)] bto_folders += ["polar_polarization"] structures = [Structure.from_file(f"{TEST_DIR}/{folder}/POSCAR") for folder in bto_folders] diff --git a/tests/analysis/test_graphs.py b/tests/analysis/test_graphs.py index e14473ec8c0..e288357c84c 100644 --- a/tests/analysis/test_graphs.py +++ b/tests/analysis/test_graphs.py @@ -772,8 +772,8 @@ def test_split(self): diff_spec_mg.add_edge(0, 3) diff_spec_mg.add_edge(0, 4) - for i in range(1, 5): - bond = (0, i) + for idx in range(1, 5): + bond = (0, idx) split_mgs = diff_spec_mg.split_molecule_subgraphs([bond]) for split_mg in split_mgs: diff --git a/tests/analysis/test_local_env.py b/tests/analysis/test_local_env.py index 39608de3ec7..ab5b59d987d 100644 --- a/tests/analysis/test_local_env.py +++ b/tests/analysis/test_local_env.py @@ -534,18 +534,18 @@ def setUp(self): ) def test_site_is_of_motif_type(self): - for i in range(len(self.diamond)): - assert site_is_of_motif_type(self.diamond, i) == "tetrahedral" - for i in range(len(self.nacl)): - assert site_is_of_motif_type(self.nacl, i) == "octahedral" - for i in range(len(self.cscl)): - assert site_is_of_motif_type(self.cscl, i) == "bcc" + for idx in range(len(self.diamond)): + assert site_is_of_motif_type(self.diamond, idx) == "tetrahedral" + for idx in range(len(self.nacl)): + assert site_is_of_motif_type(self.nacl, idx) == "octahedral" + for idx in range(len(self.cscl)): + assert site_is_of_motif_type(self.cscl, idx) == "bcc" assert site_is_of_motif_type(self.square_pyramid, 0) == "square pyramidal" - for i in range(1, len(self.square_pyramid)): - assert site_is_of_motif_type(self.square_pyramid, i) == "unrecognized" + for idx in range(1, len(self.square_pyramid)): + assert site_is_of_motif_type(self.square_pyramid, idx) == "unrecognized" assert site_is_of_motif_type(self.trigonal_bipyramid, 0) == "trigonal bipyramidal" - for i in range(1, len(self.trigonal_bipyramid)): - assert site_is_of_motif_type(self.trigonal_bipyramid, i) == "unrecognized" + for idx in range(1, len(self.trigonal_bipyramid)): + assert site_is_of_motif_type(self.trigonal_bipyramid, idx) == "unrecognized" def test_get_neighbors_of_site_with_index(self): assert len(get_neighbors_of_site_with_index(self.diamond, 0)) == 4 @@ -1003,15 +1003,10 @@ def test_get_order_parameters(self): "tet_max", "sq_face_cap_trig_pris", ] - op_params = [None for i in range(len(op_types))] + op_params = [None] * len(op_types) op_params[1] = {"TA": 1, "IGW_TA": 1.0 / 0.0667} op_params[2] = {"TA": 45.0 / 180, "IGW_TA": 1.0 / 0.0667} - op_params[33] = { - "TA": 0.6081734479693927, - "IGW_TA": 18.33, - "fac_AA": 1.5, - "exp_cos_AA": 2, - } + op_params[33] = {"TA": 0.6081734479693927, "IGW_TA": 18.33, "fac_AA": 1.5, "exp_cos_AA": 2} ops_044 = LocalStructOrderParams(op_types, parameters=op_params, cutoff=0.44) ops_071 = LocalStructOrderParams(op_types, parameters=op_params, cutoff=0.71) ops_087 = LocalStructOrderParams(op_types, parameters=op_params, cutoff=0.87) diff --git a/tests/core/test_interface.py b/tests/core/test_interface.py index 2dc8e064e60..a8368127eb5 100644 --- a/tests/core/test_interface.py +++ b/tests/core/test_interface.py @@ -61,8 +61,8 @@ def test_in_plane_offset_setter(self): assert_allclose(interface.in_plane_offset, [0.2, 0.2]) test_coords = np.array(init_coords) - for i in interface.film_indices: - test_coords[i] += [0.2, 0.2, 0] + for idx in interface.film_indices: + test_coords[idx] += [0.2, 0.2, 0] assert_allclose(np.mod(test_coords, 1.0), np.mod(interface.frac_coords, 1.0)) def test_vacuum_over_film_setter(self): diff --git a/tests/core/test_lattice.py b/tests/core/test_lattice.py index ee342cf16c1..c6aaaa5c8a9 100644 --- a/tests/core/test_lattice.py +++ b/tests/core/test_lattice.py @@ -435,8 +435,8 @@ def test_get_distance_and_image(self): def test_get_distance_and_image_strict(self): for _ in range(10): - lengths = [np.random.randint(1, 100) for i in range(3)] - lattice = [np.random.rand(3) * lengths[i] for i in range(3)] + lengths = np.random.randint(1, 100, 3) + lattice = np.random.rand(3, 3) * lengths lattice = Lattice(lattice) f1 = np.random.rand(3) diff --git a/tests/core/test_surface.py b/tests/core/test_surface.py index a3f75b0a952..ae996d1131c 100644 --- a/tests/core/test_surface.py +++ b/tests/core/test_surface.py @@ -749,9 +749,9 @@ def test_get_symmetrically_distinct_miller_indices(self): assert all(len(hkl) == 4 for hkl in indices) # Test to see if the output with max_index i is a subset of the output with max_index i+1 - for i in range(1, 4): - assert set(get_symmetrically_distinct_miller_indices(self.trigBi, i)) <= set( - get_symmetrically_distinct_miller_indices(self.trigBi, i + 1) + for idx in range(1, 4): + assert set(get_symmetrically_distinct_miller_indices(self.trigBi, idx)) <= set( + get_symmetrically_distinct_miller_indices(self.trigBi, idx + 1) ) def test_get_symmetrically_equivalent_miller_indices(self): diff --git a/tests/core/test_trajectory.py b/tests/core/test_trajectory.py index ec2cb15f3b1..bed9a35a75a 100644 --- a/tests/core/test_trajectory.py +++ b/tests/core/test_trajectory.py @@ -71,8 +71,8 @@ def _get_species_and_coords(self): return species, coords, 0, 1 def test_single_index_slice(self): - assert all(self.traj[i] == self.structures[i] for i in range(0, len(self.structures), 19)) - assert all(self.traj_mols[i] == self.molecules[i] for i in range(len(self.molecules))) + assert all(self.traj[idx] == self.structures[idx] for idx in range(0, len(self.structures), 19)) + assert all(self.traj_mols[idx] == self.molecules[idx] for idx in range(len(self.molecules))) def test_slice(self): sliced_traj = self.traj[2:99:3] @@ -87,7 +87,7 @@ def test_slice(self): sliced_traj_from_structs = Trajectory.from_structures(self.structures[:-4:2]) if len(sliced_traj) == len(sliced_traj_from_structs): - assert all(sliced_traj[i] == sliced_traj_from_structs[i] for i in range(len(sliced_traj))) + assert all(sliced_traj[idx] == sliced_traj_from_structs[idx] for idx in range(len(sliced_traj))) else: raise AssertionError @@ -421,11 +421,11 @@ def test_displacements(self): structures = [Structure.from_file(f"{VASP_IN_DIR}/POSCAR")] displacements = np.zeros((11, *np.shape(structures[-1].frac_coords))) - for i in range(10): + for idx in range(10): displacement = np.random.random_sample(np.shape(structures[-1].frac_coords)) / 20 new_coords = displacement + structures[-1].frac_coords structures.append(Structure(structures[-1].lattice, structures[-1].species, new_coords)) - displacements[i + 1, :, :] = displacement + displacements[idx + 1, :, :] = displacement traj = Trajectory.from_structures(structures, constant_lattice=True) traj.to_displacements() diff --git a/tests/core/test_units.py b/tests/core/test_units.py index e59a4f80c09..3ca9fd6b00f 100644 --- a/tests/core/test_units.py +++ b/tests/core/test_units.py @@ -93,40 +93,37 @@ def test_memory(self): def test_unitized(self): @unitized("eV") - def f(): + def func1(): return [1, 2, 3] - assert str(f()[0]) == "1.0 eV" - assert isinstance(f(), list) + assert str(func1()[0]) == "1.0 eV" + assert isinstance(func1(), list) @unitized("eV") - def g(): + def func2(): return 2, 3, 4 - assert str(g()[0]) == "2.0 eV" - assert isinstance(g(), tuple) + assert str(func2()[0]) == "2.0 eV" + assert isinstance(func2(), tuple) @unitized("pm") - def h(): - dct = {} - for i in range(3): - dct[i] = i * 20 - return dct + def func3(): + return {idx: idx * 20 for idx in range(3)} - assert str(h()[1]) == "20.0 pm" - assert isinstance(h(), dict) + assert str(func3()[1]) == "20.0 pm" + assert isinstance(func3(), dict) @unitized("kg") - def i(): + def func4(): return FloatWithUnit(5, "g") - assert i() == FloatWithUnit(0.005, "kg") + assert func4() == FloatWithUnit(0.005, "kg") @unitized("kg") - def j(): + def func5(): return ArrayWithUnit([5, 10], "g") - j_out = j() + j_out = func5() assert j_out.unit == Unit("kg") assert j_out[0] == 0.005 assert j_out[1] == 0.01 diff --git a/tests/electronic_structure/test_boltztrap.py b/tests/electronic_structure/test_boltztrap.py index 5dc6cb2d9f1..6b0a94fd66c 100644 --- a/tests/electronic_structure/test_boltztrap.py +++ b/tests/electronic_structure/test_boltztrap.py @@ -93,9 +93,8 @@ def test_get_seebeck_eff_mass(self): sbk_mass_avg_mu = self.bz.get_seebeck_eff_mass(output="average", doping_levels=False, temp=300)[3] sbk_mass_avg_dop = self.bz.get_seebeck_eff_mass(output="average", doping_levels=True, temp=300)["n"][2] - for i in range(3): - assert sbk_mass_tens_mu[i] == approx(ref2[i], abs=1e-1) - assert sbk_mass_tens_dop[i] == approx(ref[i], abs=1e-4) + assert sbk_mass_tens_mu == approx(ref2, abs=1e-1) + assert sbk_mass_tens_dop == approx(ref, abs=1e-4) assert sbk_mass_avg_mu == approx(4361.4744008038842, abs=1e-1) assert sbk_mass_avg_dop == approx(1.661553842105382, abs=1e-4) @@ -109,52 +108,40 @@ def test_get_complexity_factor(self): sbk_mass_avg_mu = self.bz.get_complexity_factor(output="average", doping_levels=False, temp=300)[3] sbk_mass_avg_dop = self.bz.get_complexity_factor(output="average", doping_levels=True, temp=300)["n"][2] - for i in range(3): - assert sbk_mass_tens_mu[i] == approx(ref2[i], abs=1e-4) - assert sbk_mass_tens_dop[i] == approx(ref[i], abs=1e-4) + assert sbk_mass_tens_mu == approx(ref2, abs=1e-4) + assert sbk_mass_tens_dop == approx(ref, abs=1e-4) assert sbk_mass_avg_mu == approx(0.00628677029221, abs=1e-4) assert sbk_mass_avg_dop == approx(1.12322832119, abs=1e-4) def test_get_seebeck(self): ref = [-768.99078999999995, -724.43919999999991, -686.84682999999973] - for i in range(3): - assert self.bz.get_seebeck()["n"][800][3][i] == approx(ref[i]) + assert self.bz.get_seebeck()["n"][800][3] == approx(ref) assert self.bz.get_seebeck(output="average")["p"][800][3] == approx(697.608936667) assert self.bz.get_seebeck(output="average", doping_levels=False)[500][520] == approx(1266.7056) - assert self.bz.get_seebeck(output="average", doping_levels=False)[300][65] == approx( - -36.2459389333 - ) # TODO: this was originally "eigs" + assert self.bz.get_seebeck(output="average", doping_levels=False)[300][65] == approx(-36.2459389333) def test_get_conductivity(self): ref = [5.9043185000000022, 17.855599000000002, 26.462935000000002] - for i in range(3): - assert self.bz.get_conductivity()["p"][600][2][i] == approx(ref[i]) + assert self.bz.get_conductivity()["p"][600][2] == approx(ref) assert self.bz.get_conductivity(output="average")["n"][700][1] == approx(1.58736609667) assert self.bz.get_conductivity(output="average", doping_levels=False)[300][457] == approx(2.87163566667) - assert self.bz.get_conductivity( - output="average", - doping_levels=False, - # TODO: this was originally "eigs" - relaxation_time=1e-15, - )[200][63] == approx(16573.0536667) + assert self.bz.get_conductivity(output="average", doping_levels=False, relaxation_time=1e-15)[200][ + 63 + ] == approx(16573.0536667) def test_get_power_factor(self): ref = [6.2736602345523362, 17.900184232304138, 26.158282220458144] - for i in range(3): - assert self.bz.get_power_factor()["p"][200][2][i] == approx(ref[i]) + assert self.bz.get_power_factor()["p"][200][2] == approx(ref) assert self.bz.get_power_factor(output="average")["n"][600][4] == approx(411.230962976) assert self.bz.get_power_factor(output="average", doping_levels=False, relaxation_time=1e-15)[500][ 459 ] == approx(6.59277148467) - assert self.bz.get_power_factor(output="average", doping_levels=False)[800][61] == approx( - 2022.67064134 - ) # TODO: this was originally "eigs" + assert self.bz.get_power_factor(output="average", doping_levels=False)[800][61] == approx(2022.67064134) def test_get_thermal_conductivity(self): ref = [2.7719565628862623e-05, 0.00010048046886793946, 0.00015874549392499391] - for i in range(3): - assert self.bz.get_thermal_conductivity()["p"][300][2][i] == approx(ref[i]) + assert self.bz.get_thermal_conductivity()["p"][300][2] == approx(ref) assert self.bz.get_thermal_conductivity(output="average", relaxation_time=1e-15)["n"][500][0] == approx( 1.74466575612e-07 ) @@ -170,8 +157,7 @@ def test_get_thermal_conductivity(self): def test_get_zt(self): ref = [0.097408810215, 0.29335112354, 0.614673998089] - for i in range(3): - assert self.bz.get_zt()["n"][800][4][i] == approx(ref[i]) + assert self.bz.get_zt()["n"][800][4] == approx(ref) assert self.bz.get_zt(output="average", k_l=0.5)["p"][700][2] == approx(0.0170001879916) assert self.bz.get_zt(output="average", doping_levels=False, relaxation_time=1e-15)[300][240] == approx( 0.0041923533238348342 @@ -179,18 +165,15 @@ def test_get_zt(self): eigs = self.bz.get_zt(output="eigs", doping_levels=False)[700][65] ref_eigs = [0.082420053399668847, 0.29408035502671648, 0.40822061215079392] - for idx, val in enumerate(ref_eigs): - assert eigs[idx] == approx(val, abs=1e-5) + assert eigs == approx(ref_eigs, abs=1e-5) def test_get_average_eff_mass(self): ref = [0.76045816788363574, 0.96181142990667101, 2.9428428773308628] - for i in range(3): - assert self.bz.get_average_eff_mass()["p"][300][2][i] == approx(ref[i]) + assert self.bz.get_average_eff_mass()["p"][300][2] == approx(ref) ref = [1.1295783824744523, 1.3898454041924351, 5.2459984671977935] ref2 = [6.6648842712692078, 31.492540105738343, 37.986369302138954] - for i in range(3): - assert self.bz.get_average_eff_mass()["n"][600][1][i] == approx(ref[i]) - assert self.bz.get_average_eff_mass(doping_levels=False)[300][200][i] == approx(ref2[i]) + assert self.bz.get_average_eff_mass()["n"][600][1] == approx(ref) + assert self.bz.get_average_eff_mass(doping_levels=False)[300][200] == approx(ref2) ref = [ [9.61811430e-01, -8.25159596e-19, -4.70319444e-19], [-8.25159596e-19, 2.94284288e00, 3.00368916e-18], @@ -202,12 +185,8 @@ def test_get_average_eff_mass(self): [-1.36897140e-17, 8.74169648e-17, 2.21151980e01], ] - for i in range(3): - for j in range(3): - assert self.bz.get_average_eff_mass(output="tensor")["p"][300][2][i][j] == approx(ref[i][j], abs=1e-4) - assert self.bz.get_average_eff_mass(output="tensor", doping_levels=False)[300][500][i][j] == approx( - ref2[i][j], 4 - ) + assert self.bz.get_average_eff_mass(output="tensor")["p"][300][2] == approx(ref, abs=1e-4) + assert self.bz.get_average_eff_mass(output="tensor", doping_levels=False)[300][500] == approx(ref2, 4) assert self.bz.get_average_eff_mass(output="average")["n"][300][2] == approx(1.53769093989, abs=1e-4) def test_get_carrier_concentration(self): diff --git a/tests/electronic_structure/test_plotter.py b/tests/electronic_structure/test_plotter.py index 92a8dc3e8aa..33dd5d301c0 100644 --- a/tests/electronic_structure/test_plotter.py +++ b/tests/electronic_structure/test_plotter.py @@ -229,18 +229,18 @@ def test_methods(self): data_structure = [[[[0 for _ in range(12)] for _ in range(9)] for _ in range(70)] for _ in range(90)] band_struct_dict["projections"]["1"] = data_structure dct = band_struct_dict["projections"]["1"] - for i in range(len(dct)): - for j in range(len(dct[i])): - for k in range(len(dct[i][j])): - for m in range(len(dct[i][j][k])): - dct[i][j][k][m] = 0 + for ii in range(len(dct)): + for jj in range(len(dct[ii])): + for kk in range(len(dct[ii][jj])): + for ll in range(len(dct[ii][jj][kk])): + dct[ii][jj][kk][ll] = 0 # d[i][j][k][m] = np.random.rand() # generate random number for two atoms a = np.random.randint(0, 7) b = np.random.randint(0, 7) # c = np.random.randint(0,7) - dct[i][j][k][a] = np.random.rand() - dct[i][j][k][b] = np.random.rand() + dct[ii][jj][kk][a] = np.random.rand() + dct[ii][jj][kk][b] = np.random.rand() # d[i][j][k][c] = np.random.rand() band_struct = BandStructureSymmLine.from_dict(band_struct_dict) ax = plotter.get_plot(band_struct) diff --git a/tests/ext/test_matproj.py b/tests/ext/test_matproj.py index aa3eb42f65c..7387f133526 100644 --- a/tests/ext/test_matproj.py +++ b/tests/ext/test_matproj.py @@ -137,8 +137,8 @@ def test_get_entries_in_chemsys(self): assert isinstance(e, ComputedEntry) assert set(e.elements).issubset(elements) - e1 = {i.entry_id for i in entries} - e2 = {i.entry_id for i in entries2} + e1 = {ent.entry_id for ent in entries} + e2 = {ent.entry_id for ent in entries2} assert e1 == e2 stable_entries = self.rester.get_entries_in_chemsys(syms, additional_criteria={"e_above_hull": {"$lte": 0.001}}) diff --git a/tests/io/abinit/test_inputs.py b/tests/io/abinit/test_inputs.py index 1970df7c28b..2b281da3bff 100644 --- a/tests/io/abinit/test_inputs.py +++ b/tests/io/abinit/test_inputs.py @@ -223,7 +223,7 @@ def test_api(self): split = multi.split_datasets() assert len(split) == 2 - assert all(split[i] == multi[i] for i in range(multi.ndtset)) + assert all(split[idx] == multi[idx] for idx in range(multi.ndtset)) assert multi.to_str(with_pseudos=False) tmpdir = tempfile.mkdtemp() diff --git a/tests/io/lobster/test_inputs.py b/tests/io/lobster/test_inputs.py index 1ebea491204..50c10d51178 100644 --- a/tests/io/lobster/test_inputs.py +++ b/tests/io/lobster/test_inputs.py @@ -268,7 +268,7 @@ def test_cohp_data(self): assert cohp1 == approx(cohp2, abs=1e-3) def test_orbital_resolved_cohp(self): - orbitals = [(Orbital(i), Orbital(j)) for j in range(4) for i in range(4)] + orbitals = [(Orbital(jj), Orbital(ii)) for ii in range(4) for jj in range(4)] assert self.cohp_bise.orb_res_cohp is None assert self.coop_bise.orb_res_cohp is None assert self.cohp_fe.orb_res_cohp is None diff --git a/tests/io/test_pwscf.py b/tests/io/test_pwscf.py index 50fb70c6755..373518967c4 100644 --- a/tests/io/test_pwscf.py +++ b/tests/io/test_pwscf.py @@ -364,25 +364,25 @@ def test_read_str(self): ] ) - pwin = PWInput.from_str(string) + pw_in = PWInput.from_str(string) # generate list of coords - pw_sites = np.array([list(site.coords) for site in pwin.structure]) + pw_sites = np.array([list(site.coords) for site in pw_in.structure]) assert_allclose(sites, pw_sites) - assert_allclose(lattice, pwin.structure.lattice.matrix) - assert pwin.sections["system"]["smearing"] == "cold" + assert_allclose(lattice, pw_in.structure.lattice.matrix) + assert pw_in.sections["system"]["smearing"] == "cold" class TestPWOuput(PymatgenTest): def setUp(self): - self.pwout = PWOutput(f"{TEST_FILES_DIR}/Si.pwscf.out") + self.pw_out = PWOutput(f"{TEST_FILES_DIR}/Si.pwscf.out") def test_properties(self): - assert self.pwout.final_energy == approx(-93.45259708) + assert self.pw_out.final_energy == approx(-93.45259708) def test_get_celldm(self): - assert self.pwout.get_celldm(1) == approx(10.323) + assert self.pw_out.get_celldm(1) == approx(10.323) for i in range(2, 7): - assert self.pwout.get_celldm(i) == approx(0) + assert self.pw_out.get_celldm(i) == approx(0) diff --git a/tests/io/vasp/test_outputs.py b/tests/io/vasp/test_outputs.py index 438315e9c98..49dd687017a 100644 --- a/tests/io/vasp/test_outputs.py +++ b/tests/io/vasp/test_outputs.py @@ -240,7 +240,8 @@ def test_standard(self): assert vasp_run.structures[i] == step["structure"] assert all( - vasp_run.structures[i] == vasp_run.ionic_steps[i]["structure"] for i in range(len(vasp_run.ionic_steps)) + vasp_run.structures[idx] == vasp_run.ionic_steps[idx]["structure"] + for idx in range(len(vasp_run.ionic_steps)) ) assert total_sc_steps == 308, "Incorrect number of energies read from vasprun.xml" @@ -1023,11 +1024,10 @@ def test_read_lcalcpol(self): p_sp1 = [2.01124, 2.01124, -2.04426] p_sp2 = [2.01139, 2.01139, -2.04426] - for i in range(3): - assert outcar.p_ion[i] == approx(p_ion[i]) - assert outcar.p_elec[i] == approx(p_elec[i]) - assert outcar.p_sp1[i] == approx(p_sp1[i]) - assert outcar.p_sp2[i] == approx(p_sp2[i]) + assert outcar.p_ion == approx(p_ion) + assert outcar.p_elec == approx(p_elec) + assert outcar.p_sp1 == approx(p_sp1) + assert outcar.p_sp2 == approx(p_sp2) # outcar with |e| Angst units filepath = f"{VASP_OUT_DIR}/OUTCAR_vasp_6.3.gz" @@ -1040,11 +1040,10 @@ def test_read_lcalcpol(self): p_sp1 = [4.50564, 0.0, 1.62154] p_sp2 = [4.50563e00, -1.00000e-05, 1.62154e00] - for i in range(3): - assert outcar.p_ion[i] == approx(p_ion[i]) - assert outcar.p_elec[i] == approx(p_elec[i]) - assert outcar.p_sp1[i] == approx(p_sp1[i]) - assert outcar.p_sp2[i] == approx(p_sp2[i]) + assert outcar.p_ion == approx(p_ion) + assert outcar.p_elec == approx(p_elec) + assert outcar.p_sp1 == approx(p_sp1) + assert outcar.p_sp2 == approx(p_sp2) def test_read_piezo_tensor(self): filepath = f"{VASP_OUT_DIR}/OUTCAR.lepsilon.gz" @@ -1997,16 +1996,15 @@ def _check(wder): first_line = [int(a) for a in file.readline().split()] assert wder.nkpoints == first_line[1] assert wder.nbands == first_line[2] - for i in range(10): - assert wder.get_orbital_derivative_between_states(0, i, 0, 0, 0).real == approx( - wder_ref[i, 6], abs=1e-10 - ) - assert wder.cder[0, i, 0, 0, 0].real == approx(wder_ref[i, 6], abs=1e-10) - assert wder.cder[0, i, 0, 0, 0].imag == approx(wder_ref[i, 7], abs=1e-10) - assert wder.cder[0, i, 0, 0, 1].real == approx(wder_ref[i, 8], abs=1e-10) - assert wder.cder[0, i, 0, 0, 1].imag == approx(wder_ref[i, 9], abs=1e-10) - assert wder.cder[0, i, 0, 0, 2].real == approx(wder_ref[i, 10], abs=1e-10) - assert wder.cder[0, i, 0, 0, 2].imag == approx(wder_ref[i, 11], abs=1e-10) + assert [wder.get_orbital_derivative_between_states(0, idx, 0, 0, 0).real for idx in range(10)] == approx( + wder_ref[:10, 6], abs=1e-10 + ) + assert wder.cder[0, :10, 0, 0, 0].real == approx(wder_ref[:10, 6], abs=1e-10) + assert wder.cder[0, :10, 0, 0, 0].imag == approx(wder_ref[:10, 7], abs=1e-10) + assert wder.cder[0, :10, 0, 0, 1].real == approx(wder_ref[:10, 8], abs=1e-10) + assert wder.cder[0, :10, 0, 0, 1].imag == approx(wder_ref[:10, 9], abs=1e-10) + assert wder.cder[0, :10, 0, 0, 2].real == approx(wder_ref[:10, 10], abs=1e-10) + assert wder.cder[0, :10, 0, 0, 2].imag == approx(wder_ref[:10, 11], abs=1e-10) wder = Waveder.from_binary(f"{VASP_OUT_DIR}/WAVEDER.Si") _check(wder) diff --git a/tests/symmetry/test_analyzer.py b/tests/symmetry/test_analyzer.py index ffe76bb8ed8..8540638fe57 100644 --- a/tests/symmetry/test_analyzer.py +++ b/tests/symmetry/test_analyzer.py @@ -359,12 +359,12 @@ def test_tricky_structure(self): # for some reason this structure kills spglib1.9 # 1.7 can't find symmetry either, but at least doesn't kill python struct = Structure.from_file(f"{VASP_IN_DIR}/POSCAR_tricky_symmetry") - sa = SpacegroupAnalyzer(struct, 0.1) - assert sa.get_space_group_symbol() == "I4/mmm" - assert sa.get_space_group_number() == 139 - assert sa.get_point_group_symbol() == "4/mmm" - assert sa.get_crystal_system() == "tetragonal" - assert sa.get_hall() == "-I 4 2" + spg_analyzer = SpacegroupAnalyzer(struct, 0.1) + assert spg_analyzer.get_space_group_symbol() == "I4/mmm" + assert spg_analyzer.get_space_group_number() == 139 + assert spg_analyzer.get_point_group_symbol() == "4/mmm" + assert spg_analyzer.get_crystal_system() == "tetragonal" + assert spg_analyzer.get_hall() == "-I 4 2" class TestSpacegroup(unittest.TestCase): @@ -373,12 +373,12 @@ def setUp(self): self.sg1 = SpacegroupAnalyzer(self.structure, 0.001).get_space_group_operations() def test_are_symmetrically_equivalent(self): - sites1 = [self.structure[i] for i in [0, 1]] - sites2 = [self.structure[i] for i in [2, 3]] + sites1 = [self.structure[idx] for idx in [0, 1]] + sites2 = [self.structure[idx] for idx in [2, 3]] assert self.sg1.are_symmetrically_equivalent(sites1, sites2, 1e-3) - sites1 = [self.structure[i] for i in [0, 1]] - sites2 = [self.structure[i] for i in [0, 2]] + sites1 = [self.structure[idx] for idx in [0, 1]] + sites2 = [self.structure[idx] for idx in [0, 2]] assert not self.sg1.are_symmetrically_equivalent(sites1, sites2, 1e-3) diff --git a/tests/transformations/test_standard_transformations.py b/tests/transformations/test_standard_transformations.py index 3370af7cdd7..622394edd58 100644 --- a/tests/transformations/test_standard_transformations.py +++ b/tests/transformations/test_standard_transformations.py @@ -5,7 +5,6 @@ import functools import json import operator -import random import unittest from shutil import which @@ -126,7 +125,7 @@ def test_apply_transformation(self): assert struct.formula == "Li16 O16" def test_from_scaling_factors(self): - scale_factors = [random.randint(1, 5) for i in range(3)] + scale_factors = np.random.randint(1, 5, 3) trafo = SupercellTransformation.from_scaling_factors(*scale_factors) struct = trafo.apply_transformation(self.struct) assert len(struct) == 4 * functools.reduce(operator.mul, scale_factors)