Skip to content

Commit

Permalink
CONSTANT_CASE module-scoped TEST_DIR
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Jan 23, 2024
1 parent 42ebece commit 84d3a4c
Show file tree
Hide file tree
Showing 47 changed files with 563 additions and 575 deletions.
2 changes: 1 addition & 1 deletion pymatgen/analysis/wulff.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def get_plotly(

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

Expand Down
4 changes: 2 additions & 2 deletions pymatgen/electronic_structure/boltztrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def write_def(self, output_file) -> None:
"6,'boltztrap.outputtrans', 'unknown', "
"'formatted',0\n"
"20,'boltztrap.struct', 'old', 'formatted',0\n"
"10,'boltztrap.energy" + so + "', 'old', "
f"10,'boltztrap.energy{so}', 'old', "
"'formatted',0\n48,'boltztrap.engre', 'unknown', "
"'unformatted',0\n49,'boltztrap.transdos', 'unknown', "
"'formatted',0\n50,'boltztrap.sigxx', 'unknown', 'formatted',"
Expand Down Expand Up @@ -400,7 +400,7 @@ def write_proj(self, output_file_proj, output_file_def) -> None:
"6,'boltztrap.outputtrans', 'unknown', "
"'formatted',0\n"
"20,'boltztrap.struct', 'old', 'formatted',0\n"
"10,'boltztrap.energy" + so + "', 'old', "
f"10,'boltztrap.energy{so}', 'old', "
"'formatted',0\n48,'boltztrap.engre', 'unknown', "
"'unformatted',0\n49,'boltztrap.transdos', 'unknown', "
"'formatted',0\n50,'boltztrap.sigxx', 'unknown', 'formatted',"
Expand Down
10 changes: 5 additions & 5 deletions pymatgen/io/aims/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,18 +469,18 @@ def parameters(self, parameters: dict[str, Any]) -> None:
if "output" not in self._parameters:
self._parameters["output"] = []

def get_aims_control_parameter_str(self, key: str, value: Any, format: str) -> str:
def get_aims_control_parameter_str(self, key: str, value: Any, fmt: str) -> str:
"""Get the string needed to add a parameter to the control.in file
Args:
key(str): The name of the input flag
value(Any): The value to be set for the flag
format(str): The format string to apply to the value
key (str): The name of the input flag
value (Any): The value to be set for the flag
fmt (str): The format string to apply to the value
Returns:
The line to add to the control.in file
"""
return f"{key:35s}" + (format % value) + "\n"
return f"{key:35s}{fmt.format(value)}\n"

def write_file(
self,
Expand Down
4 changes: 2 additions & 2 deletions pymatgen/io/cif.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,8 +808,8 @@ def get_magsymops(self, data):
label = bns_name if bns_name else list(map(int, (bns_num.split("."))))

if data.data.get("_space_group_magn.transform_BNS_Pp_abc") != "a,b,c;0,0,0":
jf = data.data.get("_space_group_magn.transform_BNS_Pp_abc")
msg = MagneticSpaceGroup(label, jf)
jonas_faithful = data.data.get("_space_group_magn.transform_BNS_Pp_abc")
msg = MagneticSpaceGroup(label, jonas_faithful)

elif data.data.get("_space_group_magn.transform_BNS_Pp"):
return NotImplementedError("Incomplete specification to implement.")
Expand Down
4 changes: 2 additions & 2 deletions pymatgen/io/cp2k/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def _get_str(d, indent=0):
string += "\t" * (indent + 1) + v.get_str() + "\n"
for v in d.subsections.values():
string += v._get_str(v, indent + 1)
string += "\t" * indent + "&END " + d.name + "\n"
string += "\t" * indent + f"&END {d.name}\n"

return string

Expand Down Expand Up @@ -764,7 +764,7 @@ def _from_lines(self, lines):
self.by_path(current)[s.alias or s.name] = SectionList(sections=[tmp, s])
else:
self.by_path(current).insert(s)
current = current + "/" + alias if alias else current + "/" + name
current = f"{current}/{alias or name}"
else:
kwd = Keyword.from_str(line)
tmp = self.by_path(current).get(kwd.name)
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/io/vasp/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def from_str(cls, data, default_names=None, read_velocities=True):
# First line in chunk is a key in CONTCAR
# Second line is POTIM
# Third line is the thermostat parameters
predictor_corrector_preamble = lines[0] + "\n" + lines[1] + "\n" + lines[2]
predictor_corrector_preamble = f"{lines[0]}\n{lines[1]}\n{lines[2]}"
# Rest is three sets of parameters, each set contains
# x, y, z predictor-corrector parameters for every atom in order
lines = lines[3:]
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/util/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def charge_string(charge, brackets=True, explicit_one=True):
chg_str = chg_str.replace("1", "")

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

return chg_str

Expand Down
8 changes: 4 additions & 4 deletions tests/analysis/ferroelectricity/test_polarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
from pymatgen.io.vasp.outputs import Outcar
from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest

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

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

ions = np.array(
[
Expand All @@ -40,7 +40,7 @@

class TestUtils(PymatgenTest):
def setUp(self):
self.potcar = Potcar.from_file(test_dir + "/POTCAR")
self.potcar = Potcar.from_file(f"{TEST_DIR}/POTCAR")
self.zval_dict = {"Ba": 10, "Ti": 10, "O": 6}
self.ions = ions
self.structures = structures
Expand Down Expand Up @@ -131,7 +131,7 @@ def setUp(self):
# We do not use the p_ions values from Outcar.
# We calculate using calc_ionic_from_zval because it is more reliable.
self.polarization = Polarization(self.p_elecs, self.p_ions, self.structures)
self.outcars = [Outcar(test_dir + "/" + folder + "/OUTCAR") for folder in bto_folders]
self.outcars = [Outcar(f"{TEST_DIR}/{folder}/OUTCAR") for folder in bto_folders]
self.change = np.array([[-5.79448738e-03, -4.41226597e-03, 4.62887522e01]])
self.change_norm = 46.288752795325244
self.max_jumps = [
Expand Down
16 changes: 8 additions & 8 deletions tests/analysis/gb/test_grain.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
__email__ = "xil110@eng.ucsd.edu"
__date__ = "07/30/18"

test_dir = f"{TEST_FILES_DIR}/grain_boundary"
TEST_DIR = f"{TEST_FILES_DIR}/grain_boundary"


class TestGrainBoundary(PymatgenTest):
@classmethod
def setUpClass(cls):
cls.Cu_conv = Structure.from_file(f"{test_dir}/Cu_mp-30_conventional_standard.cif")
cls.Cu_conv = Structure.from_file(f"{TEST_DIR}/Cu_mp-30_conventional_standard.cif")
GB_Cu_conv = GrainBoundaryGenerator(cls.Cu_conv)
cls.Cu_GB1 = GB_Cu_conv.gb_from_parameters(
[1, 2, 3],
Expand Down Expand Up @@ -107,17 +107,17 @@ def test_as_dict_and_from_dict(self):
class TestGrainBoundaryGenerator(PymatgenTest):
@classmethod
def setUpClass(cls):
cls.Cu_prim = Structure.from_file(f"{test_dir}/Cu_mp-30_primitive.cif")
cls.Cu_prim = Structure.from_file(f"{TEST_DIR}/Cu_mp-30_primitive.cif")
cls.GB_Cu_prim = GrainBoundaryGenerator(cls.Cu_prim)
cls.Cu_conv = Structure.from_file(f"{test_dir}/Cu_mp-30_conventional_standard.cif")
cls.Cu_conv = Structure.from_file(f"{TEST_DIR}/Cu_mp-30_conventional_standard.cif")
cls.GB_Cu_conv = GrainBoundaryGenerator(cls.Cu_conv)
cls.Be = Structure.from_file(f"{test_dir}/Be_mp-87_conventional_standard.cif")
cls.Be = Structure.from_file(f"{TEST_DIR}/Be_mp-87_conventional_standard.cif")
cls.GB_Be = GrainBoundaryGenerator(cls.Be)
cls.Pa = Structure.from_file(f"{test_dir}/Pa_mp-62_conventional_standard.cif")
cls.Pa = Structure.from_file(f"{TEST_DIR}/Pa_mp-62_conventional_standard.cif")
cls.GB_Pa = GrainBoundaryGenerator(cls.Pa)
cls.Br = Structure.from_file(f"{test_dir}/Br_mp-23154_conventional_standard.cif")
cls.Br = Structure.from_file(f"{TEST_DIR}/Br_mp-23154_conventional_standard.cif")
cls.GB_Br = GrainBoundaryGenerator(cls.Br)
cls.Bi = Structure.from_file(f"{test_dir}/Bi_mp-23152_primitive.cif")
cls.Bi = Structure.from_file(f"{TEST_DIR}/Bi_mp-23152_primitive.cif")
cls.GB_Bi = GrainBoundaryGenerator(cls.Bi)

def test_gb_from_parameters(self):
Expand Down
10 changes: 5 additions & 5 deletions tests/analysis/magnetism/test_heisenberg.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
from pymatgen.core.structure import Structure
from pymatgen.util.testing import TEST_FILES_DIR

test_dir = f"{TEST_FILES_DIR}/magnetic_orderings"
TEST_DIR = f"{TEST_FILES_DIR}/magnetic_orderings"


class TestHeisenbergMapper(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.df = pd.read_json(f"{test_dir}/mag_orderings_test_cases.json")
cls.df = pd.read_json(f"{TEST_DIR}/mag_orderings_test_cases.json")

# Good tests
cls.Mn3Al = pd.read_json(f"{test_dir}/Mn3Al.json")
cls.Mn3Al = pd.read_json(f"{TEST_DIR}/Mn3Al.json")

cls.compounds = [cls.Mn3Al]

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

def test_graphs(self):
for hm in self.hms:
sgraphs = hm.sgraphs
assert len(sgraphs) == 7
struct_graphs = hm.sgraphs
assert len(struct_graphs) == 7

def test_sites(self):
for hm in self.hms:
Expand Down
12 changes: 6 additions & 6 deletions tests/analysis/test_functional_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pymatgen.core.structure import Molecule
from pymatgen.util.testing import TEST_FILES_DIR

test_dir = f"{TEST_FILES_DIR}/functional_groups"
TEST_DIR = f"{TEST_FILES_DIR}/functional_groups"

pytest.importorskip("openbabel")
pytest.importorskip("networkx")
Expand All @@ -26,7 +26,7 @@

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

# Test optimization
file_no_h = f"{test_dir}/func_group_test_no_h.mol"
file_no_h = f"{TEST_DIR}/func_group_test_no_h.mol"
extractor_no_h = FunctionalGroupExtractor(file_no_h, optimize=True)

assert len(extractor_no_h.molecule) == len(extractor_mol.molecule)
assert extractor_no_h.species == extractor_mol.species

def test_get_heteroatoms(self):
heteroatoms = self.extractor.get_heteroatoms()
hetero_species = [self.extractor.species[x] for x in heteroatoms]
hetero_atoms = self.extractor.get_heteroatoms()
hetero_species = [self.extractor.species[x] for x in hetero_atoms]

assert len(heteroatoms) == 3
assert len(hetero_atoms) == 3
assert sorted(hetero_species) == ["N", "O", "O"]

# Test with limitation
Expand Down
10 changes: 5 additions & 5 deletions tests/analysis/test_local_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from pymatgen.core import Element, Lattice, Molecule, Structure
from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest

test_dir = f"{TEST_FILES_DIR}/fragmenter_files"
TEST_DIR = f"{TEST_FILES_DIR}/fragmenter_files"


class TestValenceIonicRadiusEvaluator(PymatgenTest):
Expand Down Expand Up @@ -1354,8 +1354,8 @@ def test_cn(self):

class TestMetalEdgeExtender(PymatgenTest):
def setUp(self):
self.LiEC = Molecule.from_file(f"{test_dir}/LiEC.xyz")
self.phsh = Molecule.from_file(f"{test_dir}/phsh.xyz")
self.LiEC = Molecule.from_file(f"{TEST_DIR}/LiEC.xyz")
self.phsh = Molecule.from_file(f"{TEST_DIR}/phsh.xyz")
self.phsh_graph = MoleculeGraph.with_edges(
molecule=self.phsh,
edges={
Expand Down Expand Up @@ -1404,15 +1404,15 @@ def setUp(self):
)

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

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

0 comments on commit 84d3a4c

Please sign in to comment.