Skip to content

Commit 84d3a4c

Browse files
committed
CONSTANT_CASE module-scoped TEST_DIR
1 parent 42ebece commit 84d3a4c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+563
-575
lines changed

pymatgen/analysis/wulff.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ def get_plotly(
530530

531531
tri_indices = np.array(list(itertools.combinations(index_list, 3))).T
532532
hkl = self.miller_list[plane.index]
533-
hkl = unicodeify_spacegroup("(" + "%s" * len(hkl) % hkl + ")")
533+
hkl = unicodeify_spacegroup(f"({'%s' * len(hkl) % hkl})")
534534
cs = tuple(np.array(plane_color) * 255)
535535
color = f"rgba({cs[0]:.5f}, {cs[1]:.5f}, {cs[2]:.5f}, {cs[3]:.5f})"
536536

pymatgen/electronic_structure/boltztrap.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def write_def(self, output_file) -> None:
351351
"6,'boltztrap.outputtrans', 'unknown', "
352352
"'formatted',0\n"
353353
"20,'boltztrap.struct', 'old', 'formatted',0\n"
354-
"10,'boltztrap.energy" + so + "', 'old', "
354+
f"10,'boltztrap.energy{so}', 'old', "
355355
"'formatted',0\n48,'boltztrap.engre', 'unknown', "
356356
"'unformatted',0\n49,'boltztrap.transdos', 'unknown', "
357357
"'formatted',0\n50,'boltztrap.sigxx', 'unknown', 'formatted',"
@@ -400,7 +400,7 @@ def write_proj(self, output_file_proj, output_file_def) -> None:
400400
"6,'boltztrap.outputtrans', 'unknown', "
401401
"'formatted',0\n"
402402
"20,'boltztrap.struct', 'old', 'formatted',0\n"
403-
"10,'boltztrap.energy" + so + "', 'old', "
403+
f"10,'boltztrap.energy{so}', 'old', "
404404
"'formatted',0\n48,'boltztrap.engre', 'unknown', "
405405
"'unformatted',0\n49,'boltztrap.transdos', 'unknown', "
406406
"'formatted',0\n50,'boltztrap.sigxx', 'unknown', 'formatted',"

pymatgen/io/aims/inputs.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -469,18 +469,18 @@ def parameters(self, parameters: dict[str, Any]) -> None:
469469
if "output" not in self._parameters:
470470
self._parameters["output"] = []
471471

472-
def get_aims_control_parameter_str(self, key: str, value: Any, format: str) -> str:
472+
def get_aims_control_parameter_str(self, key: str, value: Any, fmt: str) -> str:
473473
"""Get the string needed to add a parameter to the control.in file
474474
475475
Args:
476-
key(str): The name of the input flag
477-
value(Any): The value to be set for the flag
478-
format(str): The format string to apply to the value
476+
key (str): The name of the input flag
477+
value (Any): The value to be set for the flag
478+
fmt (str): The format string to apply to the value
479479
480480
Returns:
481481
The line to add to the control.in file
482482
"""
483-
return f"{key:35s}" + (format % value) + "\n"
483+
return f"{key:35s}{fmt.format(value)}\n"
484484

485485
def write_file(
486486
self,

pymatgen/io/cif.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -808,8 +808,8 @@ def get_magsymops(self, data):
808808
label = bns_name if bns_name else list(map(int, (bns_num.split("."))))
809809

810810
if data.data.get("_space_group_magn.transform_BNS_Pp_abc") != "a,b,c;0,0,0":
811-
jf = data.data.get("_space_group_magn.transform_BNS_Pp_abc")
812-
msg = MagneticSpaceGroup(label, jf)
811+
jonas_faithful = data.data.get("_space_group_magn.transform_BNS_Pp_abc")
812+
msg = MagneticSpaceGroup(label, jonas_faithful)
813813

814814
elif data.data.get("_space_group_magn.transform_BNS_Pp"):
815815
return NotImplementedError("Incomplete specification to implement.")

pymatgen/io/cp2k/inputs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ def _get_str(d, indent=0):
575575
string += "\t" * (indent + 1) + v.get_str() + "\n"
576576
for v in d.subsections.values():
577577
string += v._get_str(v, indent + 1)
578-
string += "\t" * indent + "&END " + d.name + "\n"
578+
string += "\t" * indent + f"&END {d.name}\n"
579579

580580
return string
581581

@@ -764,7 +764,7 @@ def _from_lines(self, lines):
764764
self.by_path(current)[s.alias or s.name] = SectionList(sections=[tmp, s])
765765
else:
766766
self.by_path(current).insert(s)
767-
current = current + "/" + alias if alias else current + "/" + name
767+
current = f"{current}/{alias or name}"
768768
else:
769769
kwd = Keyword.from_str(line)
770770
tmp = self.by_path(current).get(kwd.name)

pymatgen/io/vasp/inputs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def from_str(cls, data, default_names=None, read_velocities=True):
460460
# First line in chunk is a key in CONTCAR
461461
# Second line is POTIM
462462
# Third line is the thermostat parameters
463-
predictor_corrector_preamble = lines[0] + "\n" + lines[1] + "\n" + lines[2]
463+
predictor_corrector_preamble = f"{lines[0]}\n{lines[1]}\n{lines[2]}"
464464
# Rest is three sets of parameters, each set contains
465465
# x, y, z predictor-corrector parameters for every atom in order
466466
lines = lines[3:]

pymatgen/util/string.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def charge_string(charge, brackets=True, explicit_one=True):
140140
chg_str = chg_str.replace("1", "")
141141

142142
if chg_str != "(aq)" and brackets:
143-
chg_str = "[" + chg_str + "]"
143+
chg_str = f"[{chg_str}]"
144144

145145
return chg_str
146146

tests/analysis/ferroelectricity/test_polarization.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
from pymatgen.io.vasp.outputs import Outcar
1616
from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest
1717

18-
test_dir = f"{TEST_FILES_DIR}/BTO_221_99_polarization"
18+
TEST_DIR = f"{TEST_FILES_DIR}/BTO_221_99_polarization"
1919
bto_folders = ["nonpolar_polarization"]
2020
bto_folders += [f"interpolation_{i}_polarization" for i in range(1, 9)][::-1]
2121
bto_folders += ["polar_polarization"]
2222

23-
structures = [Structure.from_file(test_dir + "/" + folder + "/POSCAR") for folder in bto_folders]
23+
structures = [Structure.from_file(f"{TEST_DIR}/{folder}/POSCAR") for folder in bto_folders]
2424

2525
ions = np.array(
2626
[
@@ -40,7 +40,7 @@
4040

4141
class TestUtils(PymatgenTest):
4242
def setUp(self):
43-
self.potcar = Potcar.from_file(test_dir + "/POTCAR")
43+
self.potcar = Potcar.from_file(f"{TEST_DIR}/POTCAR")
4444
self.zval_dict = {"Ba": 10, "Ti": 10, "O": 6}
4545
self.ions = ions
4646
self.structures = structures
@@ -131,7 +131,7 @@ def setUp(self):
131131
# We do not use the p_ions values from Outcar.
132132
# We calculate using calc_ionic_from_zval because it is more reliable.
133133
self.polarization = Polarization(self.p_elecs, self.p_ions, self.structures)
134-
self.outcars = [Outcar(test_dir + "/" + folder + "/OUTCAR") for folder in bto_folders]
134+
self.outcars = [Outcar(f"{TEST_DIR}/{folder}/OUTCAR") for folder in bto_folders]
135135
self.change = np.array([[-5.79448738e-03, -4.41226597e-03, 4.62887522e01]])
136136
self.change_norm = 46.288752795325244
137137
self.max_jumps = [

tests/analysis/gb/test_grain.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
__email__ = "[email protected]"
1414
__date__ = "07/30/18"
1515

16-
test_dir = f"{TEST_FILES_DIR}/grain_boundary"
16+
TEST_DIR = f"{TEST_FILES_DIR}/grain_boundary"
1717

1818

1919
class TestGrainBoundary(PymatgenTest):
2020
@classmethod
2121
def setUpClass(cls):
22-
cls.Cu_conv = Structure.from_file(f"{test_dir}/Cu_mp-30_conventional_standard.cif")
22+
cls.Cu_conv = Structure.from_file(f"{TEST_DIR}/Cu_mp-30_conventional_standard.cif")
2323
GB_Cu_conv = GrainBoundaryGenerator(cls.Cu_conv)
2424
cls.Cu_GB1 = GB_Cu_conv.gb_from_parameters(
2525
[1, 2, 3],
@@ -107,17 +107,17 @@ def test_as_dict_and_from_dict(self):
107107
class TestGrainBoundaryGenerator(PymatgenTest):
108108
@classmethod
109109
def setUpClass(cls):
110-
cls.Cu_prim = Structure.from_file(f"{test_dir}/Cu_mp-30_primitive.cif")
110+
cls.Cu_prim = Structure.from_file(f"{TEST_DIR}/Cu_mp-30_primitive.cif")
111111
cls.GB_Cu_prim = GrainBoundaryGenerator(cls.Cu_prim)
112-
cls.Cu_conv = Structure.from_file(f"{test_dir}/Cu_mp-30_conventional_standard.cif")
112+
cls.Cu_conv = Structure.from_file(f"{TEST_DIR}/Cu_mp-30_conventional_standard.cif")
113113
cls.GB_Cu_conv = GrainBoundaryGenerator(cls.Cu_conv)
114-
cls.Be = Structure.from_file(f"{test_dir}/Be_mp-87_conventional_standard.cif")
114+
cls.Be = Structure.from_file(f"{TEST_DIR}/Be_mp-87_conventional_standard.cif")
115115
cls.GB_Be = GrainBoundaryGenerator(cls.Be)
116-
cls.Pa = Structure.from_file(f"{test_dir}/Pa_mp-62_conventional_standard.cif")
116+
cls.Pa = Structure.from_file(f"{TEST_DIR}/Pa_mp-62_conventional_standard.cif")
117117
cls.GB_Pa = GrainBoundaryGenerator(cls.Pa)
118-
cls.Br = Structure.from_file(f"{test_dir}/Br_mp-23154_conventional_standard.cif")
118+
cls.Br = Structure.from_file(f"{TEST_DIR}/Br_mp-23154_conventional_standard.cif")
119119
cls.GB_Br = GrainBoundaryGenerator(cls.Br)
120-
cls.Bi = Structure.from_file(f"{test_dir}/Bi_mp-23152_primitive.cif")
120+
cls.Bi = Structure.from_file(f"{TEST_DIR}/Bi_mp-23152_primitive.cif")
121121
cls.GB_Bi = GrainBoundaryGenerator(cls.Bi)
122122

123123
def test_gb_from_parameters(self):

tests/analysis/magnetism/test_heisenberg.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
from pymatgen.core.structure import Structure
99
from pymatgen.util.testing import TEST_FILES_DIR
1010

11-
test_dir = f"{TEST_FILES_DIR}/magnetic_orderings"
11+
TEST_DIR = f"{TEST_FILES_DIR}/magnetic_orderings"
1212

1313

1414
class TestHeisenbergMapper(unittest.TestCase):
1515
@classmethod
1616
def setUpClass(cls):
17-
cls.df = pd.read_json(f"{test_dir}/mag_orderings_test_cases.json")
17+
cls.df = pd.read_json(f"{TEST_DIR}/mag_orderings_test_cases.json")
1818

1919
# Good tests
20-
cls.Mn3Al = pd.read_json(f"{test_dir}/Mn3Al.json")
20+
cls.Mn3Al = pd.read_json(f"{TEST_DIR}/Mn3Al.json")
2121

2222
cls.compounds = [cls.Mn3Al]
2323

@@ -36,8 +36,8 @@ def setUp(self):
3636

3737
def test_graphs(self):
3838
for hm in self.hms:
39-
sgraphs = hm.sgraphs
40-
assert len(sgraphs) == 7
39+
struct_graphs = hm.sgraphs
40+
assert len(struct_graphs) == 7
4141

4242
def test_sites(self):
4343
for hm in self.hms:

tests/analysis/test_functional_groups.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pymatgen.core.structure import Molecule
1111
from pymatgen.util.testing import TEST_FILES_DIR
1212

13-
test_dir = f"{TEST_FILES_DIR}/functional_groups"
13+
TEST_DIR = f"{TEST_FILES_DIR}/functional_groups"
1414

1515
pytest.importorskip("openbabel")
1616
pytest.importorskip("networkx")
@@ -26,7 +26,7 @@
2626

2727
class TestFunctionalGroupExtractor(unittest.TestCase):
2828
def setUp(self):
29-
self.file = f"{test_dir}/func_group_test.mol"
29+
self.file = f"{TEST_DIR}/func_group_test.mol"
3030
self.mol = Molecule.from_file(self.file)
3131
self.strategy = OpenBabelNN()
3232
self.mg = MoleculeGraph.with_local_env_strategy(self.mol, self.strategy)
@@ -44,17 +44,17 @@ def test_init(self):
4444
assert extractor_str.species == extractor_mg.species
4545

4646
# Test optimization
47-
file_no_h = f"{test_dir}/func_group_test_no_h.mol"
47+
file_no_h = f"{TEST_DIR}/func_group_test_no_h.mol"
4848
extractor_no_h = FunctionalGroupExtractor(file_no_h, optimize=True)
4949

5050
assert len(extractor_no_h.molecule) == len(extractor_mol.molecule)
5151
assert extractor_no_h.species == extractor_mol.species
5252

5353
def test_get_heteroatoms(self):
54-
heteroatoms = self.extractor.get_heteroatoms()
55-
hetero_species = [self.extractor.species[x] for x in heteroatoms]
54+
hetero_atoms = self.extractor.get_heteroatoms()
55+
hetero_species = [self.extractor.species[x] for x in hetero_atoms]
5656

57-
assert len(heteroatoms) == 3
57+
assert len(hetero_atoms) == 3
5858
assert sorted(hetero_species) == ["N", "O", "O"]
5959

6060
# Test with limitation

tests/analysis/test_local_env.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from pymatgen.core import Element, Lattice, Molecule, Structure
4141
from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest
4242

43-
test_dir = f"{TEST_FILES_DIR}/fragmenter_files"
43+
TEST_DIR = f"{TEST_FILES_DIR}/fragmenter_files"
4444

4545

4646
class TestValenceIonicRadiusEvaluator(PymatgenTest):
@@ -1354,8 +1354,8 @@ def test_cn(self):
13541354

13551355
class TestMetalEdgeExtender(PymatgenTest):
13561356
def setUp(self):
1357-
self.LiEC = Molecule.from_file(f"{test_dir}/LiEC.xyz")
1358-
self.phsh = Molecule.from_file(f"{test_dir}/phsh.xyz")
1357+
self.LiEC = Molecule.from_file(f"{TEST_DIR}/LiEC.xyz")
1358+
self.phsh = Molecule.from_file(f"{TEST_DIR}/phsh.xyz")
13591359
self.phsh_graph = MoleculeGraph.with_edges(
13601360
molecule=self.phsh,
13611361
edges={
@@ -1404,15 +1404,15 @@ def setUp(self):
14041404
)
14051405

14061406
# potassium + 7 H2O. 4 at ~2.5 Ang and 3 more within 4.25 Ang
1407-
uncharged_K_cluster = Molecule.from_file(f"{test_dir}/water_cluster_K.xyz")
1407+
uncharged_K_cluster = Molecule.from_file(f"{TEST_DIR}/water_cluster_K.xyz")
14081408
K_sites = [s.coords for s in uncharged_K_cluster]
14091409
K_species = [s.species for s in uncharged_K_cluster]
14101410
charged_K_cluster = Molecule(K_species, K_sites, charge=1)
14111411
self.water_cluster_K = MoleculeGraph.with_empty_graph(charged_K_cluster)
14121412
assert len(self.water_cluster_K.graph.edges) == 0
14131413

14141414
# Mg + 6 H2O at 1.94 Ang from Mg
1415-
uncharged_Mg_cluster = Molecule.from_file(f"{test_dir}/water_cluster_Mg.xyz")
1415+
uncharged_Mg_cluster = Molecule.from_file(f"{TEST_DIR}/water_cluster_Mg.xyz")
14161416
Mg_sites = [s.coords for s in uncharged_Mg_cluster]
14171417
Mg_species = [s.species for s in uncharged_Mg_cluster]
14181418
charged_Mg_cluster = Molecule(Mg_species, Mg_sites, charge=2)

0 commit comments

Comments
 (0)