diff --git a/pymatgen/analysis/wulff.py b/pymatgen/analysis/wulff.py index 4c519bf0397..ff28fb310fd 100644 --- a/pymatgen/analysis/wulff.py +++ b/pymatgen/analysis/wulff.py @@ -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})" diff --git a/pymatgen/electronic_structure/boltztrap.py b/pymatgen/electronic_structure/boltztrap.py index 0c51ee20fd4..a4a37dc2c4c 100644 --- a/pymatgen/electronic_structure/boltztrap.py +++ b/pymatgen/electronic_structure/boltztrap.py @@ -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'," @@ -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'," diff --git a/pymatgen/io/aims/inputs.py b/pymatgen/io/aims/inputs.py index 04747608049..41567ff0eff 100644 --- a/pymatgen/io/aims/inputs.py +++ b/pymatgen/io/aims/inputs.py @@ -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, diff --git a/pymatgen/io/cif.py b/pymatgen/io/cif.py index 75688f3e811..878beb71788 100644 --- a/pymatgen/io/cif.py +++ b/pymatgen/io/cif.py @@ -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.") diff --git a/pymatgen/io/cp2k/inputs.py b/pymatgen/io/cp2k/inputs.py index 487de9000d0..875bc515e46 100644 --- a/pymatgen/io/cp2k/inputs.py +++ b/pymatgen/io/cp2k/inputs.py @@ -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 @@ -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) diff --git a/pymatgen/io/vasp/inputs.py b/pymatgen/io/vasp/inputs.py index caeda4a25eb..f40a99cd601 100644 --- a/pymatgen/io/vasp/inputs.py +++ b/pymatgen/io/vasp/inputs.py @@ -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:] diff --git a/pymatgen/util/string.py b/pymatgen/util/string.py index 22fd959613f..33e6cb9b9ff 100644 --- a/pymatgen/util/string.py +++ b/pymatgen/util/string.py @@ -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 diff --git a/tests/analysis/ferroelectricity/test_polarization.py b/tests/analysis/ferroelectricity/test_polarization.py index edf47132441..63634251ab9 100644 --- a/tests/analysis/ferroelectricity/test_polarization.py +++ b/tests/analysis/ferroelectricity/test_polarization.py @@ -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( [ @@ -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 @@ -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 = [ diff --git a/tests/analysis/gb/test_grain.py b/tests/analysis/gb/test_grain.py index 0d73bb2f771..4fe8dcab866 100644 --- a/tests/analysis/gb/test_grain.py +++ b/tests/analysis/gb/test_grain.py @@ -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], @@ -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): diff --git a/tests/analysis/magnetism/test_heisenberg.py b/tests/analysis/magnetism/test_heisenberg.py index 22460c6525c..77cbb33b830 100644 --- a/tests/analysis/magnetism/test_heisenberg.py +++ b/tests/analysis/magnetism/test_heisenberg.py @@ -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] @@ -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: diff --git a/tests/analysis/test_functional_groups.py b/tests/analysis/test_functional_groups.py index b7bef249743..a9abe7ea1f5 100644 --- a/tests/analysis/test_functional_groups.py +++ b/tests/analysis/test_functional_groups.py @@ -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") @@ -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) @@ -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 diff --git a/tests/analysis/test_local_env.py b/tests/analysis/test_local_env.py index 32daec51521..8660bcc682a 100644 --- a/tests/analysis/test_local_env.py +++ b/tests/analysis/test_local_env.py @@ -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): @@ -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={ @@ -1404,7 +1404,7 @@ 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) @@ -1412,7 +1412,7 @@ def setUp(self): 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) diff --git a/tests/analysis/test_molecule_matcher.py b/tests/analysis/test_molecule_matcher.py index b83dbe836d7..8ef38edf7bd 100644 --- a/tests/analysis/test_molecule_matcher.py +++ b/tests/analysis/test_molecule_matcher.py @@ -26,7 +26,7 @@ except (ImportError, RuntimeError): openbabel = None -test_dir = f"{TEST_FILES_DIR}/molecules/molecule_matcher" +TEST_DIR = f"{TEST_FILES_DIR}/molecules/molecule_matcher" ob_align_missing = openbabel is None or "OBAlign" not in dir(openbabel) @@ -81,29 +81,29 @@ def generate_Si_cluster(): # Creating molecule for testing mol = Molecule.from_sites(struct) - XYZ(mol).write_file(f"{test_dir}/Si_cluster.xyz") + XYZ(mol).write_file(f"{TEST_DIR}/Si_cluster.xyz") # Rotate the whole molecule mol_rotated = mol.copy() rotate(mol_rotated, seed=42) - XYZ(mol_rotated).write_file(f"{test_dir}/Si_cluster_rotated.xyz") + XYZ(mol_rotated).write_file(f"{TEST_DIR}/Si_cluster_rotated.xyz") # Perturbing the atom positions mol_perturbed = mol.copy() perturb(mol_perturbed, 0.3, seed=42) - XYZ(mol_perturbed).write_file(f"{test_dir}/Si_cluster_perturbed.xyz") + XYZ(mol_perturbed).write_file(f"{TEST_DIR}/Si_cluster_perturbed.xyz") # Permuting the order of the atoms mol_permuted = mol.copy() permute(mol_permuted, seed=42) - XYZ(mol_permuted).write_file(f"{test_dir}/Si_cluster_permuted.xyz") + XYZ(mol_permuted).write_file(f"{TEST_DIR}/Si_cluster_permuted.xyz") # All-in-one mol2 = mol.copy() rotate(mol2, seed=42) perturb(mol2, 0.3, seed=42) permute(mol2, seed=42) - XYZ(mol2).write_file(f"{test_dir}/Si_cluster_2.xyz") + XYZ(mol2).write_file(f"{TEST_DIR}/Si_cluster_2.xyz") def generate_Si2O_cluster(): @@ -122,29 +122,29 @@ def generate_Si2O_cluster(): # Creating molecule for testing mol = Molecule.from_sites(struct) - XYZ(mol).write_file(f"{test_dir}/Si2O_cluster.xyz") + XYZ(mol).write_file(f"{TEST_DIR}/Si2O_cluster.xyz") # Rotate the whole molecule mol_rotated = mol.copy() rotate(mol_rotated, seed=42) - XYZ(mol_rotated).write_file(f"{test_dir}/Si2O_cluster_rotated.xyz") + XYZ(mol_rotated).write_file(f"{TEST_DIR}/Si2O_cluster_rotated.xyz") # Perturbing the atom positions mol_perturbed = mol.copy() perturb(mol_perturbed, 0.3, seed=42) - XYZ(mol_perturbed).write_file(f"{test_dir}/Si2O_cluster_perturbed.xyz") + XYZ(mol_perturbed).write_file(f"{TEST_DIR}/Si2O_cluster_perturbed.xyz") # Permuting the order of the atoms mol_permuted = mol.copy() permute(mol_permuted, seed=42) - XYZ(mol_permuted).write_file(f"{test_dir}/Si2O_cluster_permuted.xyz") + XYZ(mol_permuted).write_file(f"{TEST_DIR}/Si2O_cluster_permuted.xyz") # All-in-one mol2 = mol.copy() rotate(mol2, seed=42) perturb(mol2, 0.3, seed=42) permute(mol2, seed=42) - XYZ(mol2).write_file(f"{test_dir}/Si2O_cluster_2.xyz") + XYZ(mol2).write_file(f"{TEST_DIR}/Si2O_cluster_2.xyz") @unittest.skipIf(ob_align_missing, "OBAlign is missing, Skipping") @@ -155,18 +155,18 @@ def test_fit(self): def test_get_rmsd(self): mol_matcher = MoleculeMatcher() - mol1 = Molecule.from_file(f"{test_dir}/t3.xyz") - mol2 = Molecule.from_file(f"{test_dir}/t4.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/t3.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/t4.xyz") assert f"{mol_matcher.get_rmsd(mol1, mol2):7.3}" == "0.00488" def test_group_molecules(self): mol_matcher = MoleculeMatcher(tolerance=0.001) - with open(f"{test_dir}/mol_list.txt") as f: + with open(f"{TEST_DIR}/mol_list.txt") as f: filename_list = [line.strip() for line in f.readlines()] - mol_list = [Molecule.from_file(os.path.join(test_dir, f)) for f in filename_list] + mol_list = [Molecule.from_file(os.path.join(TEST_DIR, f)) for f in filename_list] mol_groups = mol_matcher.group_molecules(mol_list) filename_groups = [[filename_list[mol_list.index(m)] for m in g] for g in mol_groups] - with open(f"{test_dir}/grouped_mol_list.txt") as f: + with open(f"{TEST_DIR}/grouped_mol_list.txt") as f: grouped_text = f.read().strip() assert str(filename_groups) == grouped_text @@ -196,83 +196,83 @@ def fit_with_mapper(self, mapper): mol_matcher = MoleculeMatcher(mapper=mapper) assert mol_matcher.fit(mol1, mol2) - mol1 = Molecule.from_file(f"{test_dir}/benzene1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/benzene2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/benzene1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/benzene2.xyz") assert mol_matcher.fit(mol1, mol2) - mol1 = Molecule.from_file(f"{test_dir}/benzene1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/t2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/benzene1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/t2.xyz") assert not mol_matcher.fit(mol1, mol2) - mol1 = Molecule.from_file(f"{test_dir}/c1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/c2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/c1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/c2.xyz") assert mol_matcher.fit(mol1, mol2) - mol1 = Molecule.from_file(f"{test_dir}/t3.xyz") - mol2 = Molecule.from_file(f"{test_dir}/t4.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/t3.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/t4.xyz") assert mol_matcher.fit(mol1, mol2) - mol1 = Molecule.from_file(f"{test_dir}/j1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/j2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/j1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/j2.xyz") assert mol_matcher.fit(mol1, mol2) - mol1 = Molecule.from_file(f"{test_dir}/ethene1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/ethene2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/ethene1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/ethene2.xyz") assert mol_matcher.fit(mol1, mol2) - mol1 = Molecule.from_file(f"{test_dir}/toluene1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/toluene2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/toluene1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/toluene2.xyz") assert mol_matcher.fit(mol1, mol2) - mol1 = Molecule.from_file(f"{test_dir}/cyclohexane1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/cyclohexane2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/cyclohexane1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/cyclohexane2.xyz") assert mol_matcher.fit(mol1, mol2) - mol1 = Molecule.from_file(f"{test_dir}/oxygen1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/oxygen2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/oxygen1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/oxygen2.xyz") assert mol_matcher.fit(mol1, mol2) mol_matcher = MoleculeMatcher(tolerance=0.001, mapper=mapper) - mol1 = Molecule.from_file(f"{test_dir}/t3.xyz") - mol2 = Molecule.from_file(f"{test_dir}/t4.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/t3.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/t4.xyz") assert not mol_matcher.fit(mol1, mol2) def test_strange_inchi(self): mol_matcher = MoleculeMatcher(tolerance=0.05, mapper=InchiMolAtomMapper()) - mol1 = Molecule.from_file(f"{test_dir}/k1.sdf") - mol2 = Molecule.from_file(f"{test_dir}/k2.sdf") + mol1 = Molecule.from_file(f"{TEST_DIR}/k1.sdf") + mol2 = Molecule.from_file(f"{TEST_DIR}/k2.sdf") assert mol_matcher.fit(mol1, mol2) def test_thiane(self): mol_matcher = MoleculeMatcher(tolerance=0.05, mapper=InchiMolAtomMapper()) - mol1 = Molecule.from_file(f"{test_dir}/thiane1.sdf") - mol2 = Molecule.from_file(f"{test_dir}/thiane2.sdf") + mol1 = Molecule.from_file(f"{TEST_DIR}/thiane1.sdf") + mol2 = Molecule.from_file(f"{TEST_DIR}/thiane2.sdf") assert not mol_matcher.fit(mol1, mol2) def test_thiane_ethynyl(self): mol_matcher = MoleculeMatcher(tolerance=0.05, mapper=InchiMolAtomMapper()) - mol1 = Molecule.from_file(f"{test_dir}/thiane_ethynyl1.sdf") - mol2 = Molecule.from_file(f"{test_dir}/thiane_ethynyl2.sdf") + mol1 = Molecule.from_file(f"{TEST_DIR}/thiane_ethynyl1.sdf") + mol2 = Molecule.from_file(f"{TEST_DIR}/thiane_ethynyl2.sdf") assert not mol_matcher.fit(mol1, mol2) def test_cdi_23(self): mol_matcher = MoleculeMatcher(tolerance=0.05, mapper=InchiMolAtomMapper()) - mol1 = Molecule.from_file(f"{test_dir}/cdi_23_1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/cdi_23_2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/cdi_23_1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/cdi_23_2.xyz") assert not mol_matcher.fit(mol1, mol2) class TestKabschMatcher(unittest.TestCase): def test_get_rmsd(self): - mol1 = Molecule.from_file(f"{test_dir}/t3.xyz") - mol2 = Molecule.from_file(f"{test_dir}/t4.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/t3.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/t4.xyz") mol_matcher = KabschMatcher(mol1) _, _, rmsd = mol_matcher.match(mol2) assert rmsd == approx(0.0028172956033732936, abs=1e-6) def test_to_and_from_dict(self): - mol1 = Molecule.from_file(f"{test_dir}/t3.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/t3.xyz") mm_source = KabschMatcher(mol1) d_source = mm_source.as_dict() @@ -300,8 +300,8 @@ def test_rotated_molecule(self): assert rmsd == approx(0, abs=6) def test_mismatched_atom_composition(self): - mol1 = Molecule.from_file(f"{test_dir}/benzene1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/t2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/benzene1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/t2.xyz") mol_matcher = KabschMatcher(mol1) @@ -310,8 +310,8 @@ def test_mismatched_atom_composition(self): def test_mismatched_atom_order(self): for mol_name in ("benzene", "c"): - mol1 = Molecule.from_file(f"{test_dir}/{mol_name}1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/{mol_name}2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/{mol_name}1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/{mol_name}2.xyz") mol_matcher = KabschMatcher(mol1) @@ -320,16 +320,16 @@ def test_mismatched_atom_order(self): mol_matcher.fit(mol2) def test_fit(self): - mol1 = Molecule.from_file(f"{test_dir}/t3.xyz") - mol2 = Molecule.from_file(f"{test_dir}/t4.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/t3.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/t4.xyz") mol_matcher = KabschMatcher(mol1) _, rmsd = mol_matcher.fit(mol2) assert rmsd == approx(0.0028172956033732936, abs=1e-6) - mol1 = Molecule.from_file(f"{test_dir}/oxygen1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/oxygen2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/oxygen1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/oxygen2.xyz") mol_matcher = KabschMatcher(mol1) _, rmsd = mol_matcher.fit(mol2) @@ -338,8 +338,8 @@ def test_fit(self): class TestHungarianOrderMatcher(unittest.TestCase): def test_get_rmsd(self): - mol1 = Molecule.from_file(f"{test_dir}/t3.xyz") - mol2 = Molecule.from_file(f"{test_dir}/t4.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/t3.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/t4.xyz") mol_matcher = HungarianOrderMatcher(mol1) @@ -347,7 +347,7 @@ def test_get_rmsd(self): assert rmsd == approx(0.002825344731118855, abs=1e-6) def test_to_and_from_dict(self): - mol1 = Molecule.from_file(f"{test_dir}/t3.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/t3.xyz") mm_source = HungarianOrderMatcher(mol1) d_source = mm_source.as_dict() @@ -375,66 +375,66 @@ def test_rotated_molecule(self): assert rmsd == approx(0, abs=6) def test_mismatched_atom_composition(self): - mol1 = Molecule.from_file(f"{test_dir}/benzene1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/t2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/benzene1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/t2.xyz") mol_matcher = HungarianOrderMatcher(mol1) with pytest.raises(ValueError, match="The number of the same species aren't matching"): mol_matcher.fit(mol2) def test_fit(self): - mol1 = Molecule.from_file(f"{test_dir}/benzene1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/benzene2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/benzene1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/benzene2.xyz") mol_matcher = HungarianOrderMatcher(mol1) _, rmsd = mol_matcher.fit(mol2) assert rmsd == approx(1.4171601659148593e-5, abs=1e-6) - mol1 = Molecule.from_file(f"{test_dir}/c1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/c2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/c1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/c2.xyz") mol_matcher = HungarianOrderMatcher(mol1) _, rmsd = mol_matcher.fit(mol2) assert rmsd == approx(9.479012116064961e-5, abs=1e-6) - mol1 = Molecule.from_file(f"{test_dir}/t3.xyz") - mol2 = Molecule.from_file(f"{test_dir}/t4.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/t3.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/t4.xyz") mol_matcher = HungarianOrderMatcher(mol1) _, rmsd = mol_matcher.fit(mol2) assert rmsd == approx(0.002825344731118855, abs=1e-6) - mol1 = Molecule.from_file(f"{test_dir}/j1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/j2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/j1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/j2.xyz") mol_matcher = HungarianOrderMatcher(mol1) _, rmsd = mol_matcher.fit(mol2) assert rmsd == approx(9.28245597473488e-5, abs=1e-6) - mol1 = Molecule.from_file(f"{test_dir}/ethene1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/ethene2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/ethene1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/ethene2.xyz") mol_matcher = HungarianOrderMatcher(mol1) _, rmsd = mol_matcher.fit(mol2) assert rmsd == approx(0.00021150729609276233, abs=1e-6) - mol1 = Molecule.from_file(f"{test_dir}/toluene1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/toluene2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/toluene1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/toluene2.xyz") mol_matcher = HungarianOrderMatcher(mol1) _, rmsd = mol_matcher.fit(mol2) assert rmsd == approx(0.0001445787263551832, abs=1e-6) - mol1 = Molecule.from_file(f"{test_dir}/cyclohexane1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/cyclohexane2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/cyclohexane1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/cyclohexane2.xyz") mol_matcher = HungarianOrderMatcher(mol1) _, rmsd = mol_matcher.fit(mol2) assert rmsd == approx(0.00012447269440740117, abs=1e-6) - mol1 = Molecule.from_file(f"{test_dir}/oxygen1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/oxygen2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/oxygen1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/oxygen2.xyz") mol_matcher = HungarianOrderMatcher(mol1) _, rmsd = mol_matcher.fit(mol2) @@ -443,8 +443,8 @@ def test_fit(self): class TestGeneticOrderMatcher(unittest.TestCase): def test_get_rmsd(self): - mol1 = Molecule.from_file(f"{test_dir}/t3.xyz") - mol2 = Molecule.from_file(f"{test_dir}/t4.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/t3.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/t4.xyz") mol_matcher = GeneticOrderMatcher(mol1, threshold=0.3) @@ -452,7 +452,7 @@ def test_get_rmsd(self): assert rmsd == approx(0.0028172956033734615, abs=1e-6) def test_to_and_from_dict(self): - mol1 = Molecule.from_file(f"{test_dir}/t3.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/t3.xyz") mm_source = GeneticOrderMatcher(mol1, threshold=0.3) d_source = mm_source.as_dict() @@ -480,66 +480,66 @@ def test_rotated_molecule(self): assert rmsd == approx(0, abs=6) def test_mismatched_atom_composition(self): - mol1 = Molecule.from_file(f"{test_dir}/benzene1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/t2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/benzene1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/t2.xyz") mol_matcher = GeneticOrderMatcher(mol1, threshold=0.3) with pytest.raises(ValueError, match="The number of the same species aren't matching"): mol_matcher.fit(mol2)[0] def test_fit(self): - mol1 = Molecule.from_file(f"{test_dir}/benzene1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/benzene2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/benzene1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/benzene2.xyz") mol_matcher = GeneticOrderMatcher(mol1, threshold=0.01) _, rmsd = mol_matcher.fit(mol2)[0] assert rmsd == approx(7.061017534055039e-5, abs=1e-6) - mol1 = Molecule.from_file(f"{test_dir}/c1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/c2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/c1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/c2.xyz") mol_matcher = GeneticOrderMatcher(mol1, threshold=0.01) _, rmsd = mol_matcher.fit(mol2)[0] assert rmsd == approx(9.459575146593829e-5, abs=1e-6) - mol1 = Molecule.from_file(f"{test_dir}/t3.xyz") - mol2 = Molecule.from_file(f"{test_dir}/t4.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/t3.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/t4.xyz") mol_matcher = GeneticOrderMatcher(mol1, threshold=0.01) _, rmsd = mol_matcher.fit(mol2)[0] assert rmsd == approx(0.0028172956033734615, abs=1e-6) - mol1 = Molecule.from_file(f"{test_dir}/j1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/j2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/j1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/j2.xyz") mol_matcher = GeneticOrderMatcher(mol1, threshold=0.01) _, rmsd = mol_matcher.fit(mol2)[0] assert rmsd == approx(9.28245597473488e-5, abs=1e-6) - mol1 = Molecule.from_file(f"{test_dir}/ethene1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/ethene2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/ethene1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/ethene2.xyz") mol_matcher = GeneticOrderMatcher(mol1, threshold=0.01) _, rmsd = mol_matcher.fit(mol2)[0] assert rmsd == approx(0.00019757961816426042, abs=1e-6) - mol1 = Molecule.from_file(f"{test_dir}/toluene1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/toluene2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/toluene1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/toluene2.xyz") mol_matcher = GeneticOrderMatcher(mol1, threshold=0.1) _, rmsd = mol_matcher.fit(mol2)[0] assert rmsd == approx(0.0001398867874149986, abs=1e-6) - mol1 = Molecule.from_file(f"{test_dir}/cyclohexane1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/cyclohexane2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/cyclohexane1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/cyclohexane2.xyz") mol_matcher = GeneticOrderMatcher(mol1, threshold=0.01) _, rmsd = mol_matcher.fit(mol2)[0] assert rmsd == approx(0.00012190586696474853, abs=1e-6) - mol1 = Molecule.from_file(f"{test_dir}/oxygen1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/oxygen2.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/oxygen1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/oxygen2.xyz") mol_matcher = GeneticOrderMatcher(mol1, threshold=0.01) _, rmsd = mol_matcher.fit(mol2)[0] @@ -549,7 +549,7 @@ def test_fit(self): class TestKabschMatcherSi(unittest.TestCase): @classmethod def setUpClass(cls): - cls.mol1 = Molecule.from_file(f"{test_dir}/Si_cluster.xyz") + cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") cls.mol_matcher = KabschMatcher(cls.mol1) def test_to_and_from_dict(self): @@ -558,26 +558,26 @@ def test_to_and_from_dict(self): assert d == mol_matcher.as_dict() def test_mismatched_atoms(self): - mol2 = Molecule.from_file(f"{test_dir}/Si2O_cluster.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") with pytest.raises( ValueError, match="The order of the species aren't matching! Please try using PermInvMatcher" ): self.mol_matcher.fit(mol2) def test_rotated_molecule(self): - mol2 = Molecule.from_file(f"{test_dir}/Si_cluster_rotated.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si_cluster_rotated.xyz") _, rmsd = self.mol_matcher.fit(mol2) assert rmsd == approx(0, abs=6) def test_perturbed_atom_position(self): - mol2 = Molecule.from_file(f"{test_dir}/Si_cluster_perturbed.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si_cluster_perturbed.xyz") _, rmsd = self.mol_matcher.fit(mol2) assert rmsd == approx(0.2232223954240079, abs=1e-6) def test_permuted_atoms_order(self): # This test shows very poor rmsd result, because the `KabschMatcher` # is not capable to handle arbitrary atom's order - mol2 = Molecule.from_file(f"{test_dir}/Si_cluster_permuted.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si_cluster_permuted.xyz") _, rmsd = self.mol_matcher.fit(mol2) assert rmsd == approx(2.7962454578966454, abs=1e-6) @@ -585,7 +585,7 @@ def test_permuted_atoms_order(self): class TestBruteForceOrderMatcherSi(unittest.TestCase): @classmethod def setUpClass(cls): - cls.mol1 = Molecule.from_file(f"{test_dir}/Si_cluster.xyz") + cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") cls.mol_matcher = BruteForceOrderMatcher(cls.mol1) def test_to_and_from_dict(self): @@ -594,7 +594,7 @@ def test_to_and_from_dict(self): assert d == mol_matcher.as_dict() def test_random_match(self): - mol2 = Molecule.from_file(f"{test_dir}/Si_cluster_2.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si_cluster_2.xyz") with pytest.raises( ValueError, @@ -606,7 +606,7 @@ def test_random_match(self): class TestHungarianOrderMatcherSi(unittest.TestCase): @classmethod def setUpClass(cls): - cls.mol1 = Molecule.from_file(f"{test_dir}/Si_cluster.xyz") + cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") cls.mol_matcher = HungarianOrderMatcher(cls.mol1) def test_to_and_from_dict(self): @@ -615,29 +615,29 @@ def test_to_and_from_dict(self): assert d == mol_matcher.as_dict() def test_mismatched_atoms(self): - mol2 = Molecule.from_file(f"{test_dir}/Si2O_cluster_rotated.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster_rotated.xyz") with pytest.raises(ValueError, match="The number of the same species aren't matching"): self.mol_matcher.fit(mol2) def test_rotated_molecule(self): # TODO: Checking the cause of the large deviation - mol2 = Molecule.from_file(f"{test_dir}/Si_cluster_rotated.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si_cluster_rotated.xyz") _, rmsd = self.mol_matcher.fit(mol2) assert rmsd == approx(1.025066171481399, abs=1e-6) def test_perturbed_atom_position(self): - mol2 = Molecule.from_file(f"{test_dir}/Si_cluster_perturbed.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si_cluster_perturbed.xyz") _, rmsd = self.mol_matcher.fit(mol2) assert rmsd == approx(0.2232223954240077, abs=1e-6) def test_permuted_atoms_order(self): - mol2 = Molecule.from_file(f"{test_dir}/Si_cluster_permuted.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si_cluster_permuted.xyz") _, rmsd = self.mol_matcher.fit(mol2) assert rmsd == approx(0, abs=6) def test_random_match(self): # TODO: Checking the cause of the large deviation - mol2 = Molecule.from_file(f"{test_dir}/Si_cluster_2.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si_cluster_2.xyz") _, rmsd = self.mol_matcher.fit(mol2) assert rmsd == approx(1.0177241485450828, abs=1e-6) @@ -645,7 +645,7 @@ def test_random_match(self): class TestGeneticOrderMatcherSi(unittest.TestCase): @classmethod def setUpClass(cls): - cls.mol1 = Molecule.from_file(f"{test_dir}/Si_cluster.xyz") + cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") cls.mol_matcher = GeneticOrderMatcher(cls.mol1, threshold=0.3) def test_to_and_from_dict(self): @@ -654,27 +654,27 @@ def test_to_and_from_dict(self): assert d == mol_matcher.as_dict() def test_mismatched_atoms(self): - mol2 = Molecule.from_file(f"{test_dir}/Si2O_cluster.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") with pytest.raises(ValueError, match="The number of the same species aren't matching"): self.mol_matcher.fit(mol2) def test_rotated_molecule(self): - mol2 = Molecule.from_file(f"{test_dir}/Si_cluster_rotated.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si_cluster_rotated.xyz") res = self.mol_matcher.fit(mol2) assert res[0][-1] == approx(0, abs=6) def test_perturbed_atom_position(self): - mol2 = Molecule.from_file(f"{test_dir}/Si_cluster_perturbed.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si_cluster_perturbed.xyz") res = self.mol_matcher.fit(mol2) assert res[0][-1] == approx(0.2232223954240079, abs=1e-6) def test_permuted_atoms_order(self): - mol2 = Molecule.from_file(f"{test_dir}/Si_cluster_permuted.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si_cluster_permuted.xyz") res = self.mol_matcher.fit(mol2) assert res[0][-1] == approx(0, abs=6) def test_random_match(self): - mol2 = Molecule.from_file(f"{test_dir}/Si_cluster_2.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si_cluster_2.xyz") res = self.mol_matcher.fit(mol2) assert res[0][-1] == approx(0.22163169511782, abs=1e-6) @@ -682,30 +682,30 @@ def test_random_match(self): class TestKabschMatcherSi2O(unittest.TestCase): @classmethod def setUpClass(cls): - cls.mol1 = Molecule.from_file(f"{test_dir}/Si2O_cluster.xyz") + cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") cls.mol_matcher = KabschMatcher(cls.mol1) def test_mismatched_atoms(self): - mol2 = Molecule.from_file(f"{test_dir}/Si_cluster_rotated.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si_cluster_rotated.xyz") with pytest.raises( ValueError, match="The order of the species aren't matching! Please try using PermInvMatcher" ): self.mol_matcher.fit(mol2) def test_rotated_molecule(self): - mol2 = Molecule.from_file(f"{test_dir}/Si2O_cluster_rotated.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster_rotated.xyz") _, rmsd = self.mol_matcher.fit(mol2) assert rmsd == approx(0, abs=6) def test_perturbed_atom_position(self): - mol2 = Molecule.from_file(f"{test_dir}/Si2O_cluster_perturbed.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster_perturbed.xyz") _, rmsd = self.mol_matcher.fit(mol2) assert rmsd == approx(0.24340452336622473, abs=1e-6) def test_permuted_atoms_order(self): # This task should fail, because `KabschMatcher` is not capable # to handle arbitrary atom's order - mol2 = Molecule.from_file(f"{test_dir}/Si2O_cluster_permuted.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster_permuted.xyz") with pytest.raises( ValueError, match="The order of the species aren't matching! Please try using PermInvMatcher" ): @@ -715,31 +715,31 @@ def test_permuted_atoms_order(self): class TestBruteForceOrderMatcherSi2O(unittest.TestCase): @classmethod def setUpClass(cls): - cls.mol1 = Molecule.from_file(f"{test_dir}/Si2O_cluster.xyz") + cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") cls.mol_matcher = BruteForceOrderMatcher(cls.mol1) def test_mismatched_atoms(self): - mol2 = Molecule.from_file(f"{test_dir}/Si_cluster_rotated.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si_cluster_rotated.xyz") with pytest.raises(ValueError, match="The number of the same species aren't matching"): self.mol_matcher.fit(mol2) def test_rotated_molecule(self): - mol2 = Molecule.from_file(f"{test_dir}/Si2O_cluster_rotated.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster_rotated.xyz") _, rmsd = self.mol_matcher.fit(mol2) assert rmsd == approx(0, abs=6) def test_perturbed_atom_position(self): - mol2 = Molecule.from_file(f"{test_dir}/Si2O_cluster_perturbed.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster_perturbed.xyz") _, rmsd = self.mol_matcher.fit(mol2) assert rmsd == approx(0.2434045087608993, abs=1e-6) def test_permuted_atoms_order(self): - mol2 = Molecule.from_file(f"{test_dir}/Si2O_cluster_permuted.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster_permuted.xyz") _, rmsd = self.mol_matcher.fit(mol2) assert rmsd == approx(0, abs=6) def test_random_match(self): - mol2 = Molecule.from_file(f"{test_dir}/Si2O_cluster_2.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster_2.xyz") _, rmsd = self.mol_matcher.fit(mol2) assert rmsd == approx(0.23051587697194997, abs=1e-6) @@ -747,31 +747,31 @@ def test_random_match(self): class TestHungarianOrderMatcherSi2O(unittest.TestCase): @classmethod def setUpClass(cls): - cls.mol1 = Molecule.from_file(f"{test_dir}/Si2O_cluster.xyz") + cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") cls.mol_matcher = HungarianOrderMatcher(cls.mol1) def test_mismatched_atoms(self): - mol2 = Molecule.from_file(f"{test_dir}/Si_cluster_rotated.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si_cluster_rotated.xyz") with pytest.raises(ValueError, match="The number of the same species aren't matching"): self.mol_matcher.fit(mol2) def test_rotated_molecule(self): - mol2 = Molecule.from_file(f"{test_dir}/Si2O_cluster_rotated.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster_rotated.xyz") _, rmsd = self.mol_matcher.fit(mol2) assert rmsd == approx(0, abs=6) def test_perturbed_atom_position(self): - mol2 = Molecule.from_file(f"{test_dir}/Si2O_cluster_perturbed.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster_perturbed.xyz") _, rmsd = self.mol_matcher.fit(mol2) assert rmsd == approx(0.24474957657894614, abs=1e-6) def test_permuted_atoms_order(self): - mol2 = Molecule.from_file(f"{test_dir}/Si2O_cluster_permuted.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster_permuted.xyz") _, rmsd = self.mol_matcher.fit(mol2) assert rmsd == approx(0, abs=6) def test_random_match(self): - mol2 = Molecule.from_file(f"{test_dir}/Si2O_cluster_2.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster_2.xyz") _, rmsd = self.mol_matcher.fit(mol2) assert rmsd == approx(0.23231038877573124, abs=1e-6) @@ -779,33 +779,33 @@ def test_random_match(self): class TestGeneticOrderMatcherSi2O(unittest.TestCase): @classmethod def setUpClass(cls): - cls.mol1 = Molecule.from_file(f"{test_dir}/Si2O_cluster.xyz") + cls.mol1 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster.xyz") cls.mol_matcher = GeneticOrderMatcher(cls.mol1, threshold=0.3) def test_mismatched_atoms(self): - mol2 = Molecule.from_file(f"{test_dir}/Si_cluster.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si_cluster.xyz") with pytest.raises(ValueError, match="The number of the same species aren't matching"): self.mol_matcher.fit(mol2) def test_rotated_molecule(self): - mol2 = Molecule.from_file(f"{test_dir}/Si2O_cluster_rotated.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster_rotated.xyz") res = self.mol_matcher.fit(mol2) assert res[0][1] == approx(0, abs=6) def test_perturbed_atom_position(self): - mol2 = Molecule.from_file(f"{test_dir}/Si2O_cluster_perturbed.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster_perturbed.xyz") res = self.mol_matcher.fit(mol2) assert len(res) == 3 assert res[0][1] == approx(0.24340452336622473, abs=1e-6) def test_permuted_atoms_order(self): - mol2 = Molecule.from_file(f"{test_dir}/Si2O_cluster_permuted.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster_permuted.xyz") res = self.mol_matcher.fit(mol2) assert len(res) == 3 assert res[0][1] == approx(0, abs=6) def test_random_match(self): - mol2 = Molecule.from_file(f"{test_dir}/Si2O_cluster_2.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/Si2O_cluster_2.xyz") res = self.mol_matcher.match(mol2) assert len(res) == 3 assert res[0][0] == [5, 0, 4, 1, 3, 2] diff --git a/tests/analysis/test_molecule_structure_comparator.py b/tests/analysis/test_molecule_structure_comparator.py index 1ac640acd84..2e6e220e179 100644 --- a/tests/analysis/test_molecule_structure_comparator.py +++ b/tests/analysis/test_molecule_structure_comparator.py @@ -9,29 +9,29 @@ __author__ = "xiaohuiqu" -test_dir = f"{TEST_FILES_DIR}/molecules/structural_change" +TEST_DIR = f"{TEST_FILES_DIR}/molecules/structural_change" class TestMoleculeStructureComparator(TestCase): def test_are_equal(self): msc1 = MoleculeStructureComparator() - mol1 = Molecule.from_file(f"{test_dir}/t1.xyz") - mol2 = Molecule.from_file(f"{test_dir}/t2.xyz") - mol3 = Molecule.from_file(f"{test_dir}/t3.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/t1.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/t2.xyz") + mol3 = Molecule.from_file(f"{TEST_DIR}/t3.xyz") assert not msc1.are_equal(mol1, mol2) assert msc1.are_equal(mol2, mol3) - thio1 = Molecule.from_file(f"{test_dir}/thiophene1.xyz") - thio2 = Molecule.from_file(f"{test_dir}/thiophene2.xyz") + thio1 = Molecule.from_file(f"{TEST_DIR}/thiophene1.xyz") + thio2 = Molecule.from_file(f"{TEST_DIR}/thiophene2.xyz") # noinspection PyProtectedMember msc2 = MoleculeStructureComparator(priority_bonds=msc1._get_bonds(thio1)) assert msc2.are_equal(thio1, thio2) - hal1 = Molecule.from_file(f"{test_dir}/molecule_with_halogen_bonds_1.xyz") - hal2 = Molecule.from_file(f"{test_dir}/molecule_with_halogen_bonds_2.xyz") + hal1 = Molecule.from_file(f"{TEST_DIR}/molecule_with_halogen_bonds_1.xyz") + hal2 = Molecule.from_file(f"{TEST_DIR}/molecule_with_halogen_bonds_2.xyz") msc3 = MoleculeStructureComparator(priority_bonds=msc1._get_bonds(hal1)) assert msc3.are_equal(hal1, hal2) def test_get_bonds(self): - mol1 = Molecule.from_file(f"{test_dir}/t1.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/t1.xyz") msc = MoleculeStructureComparator() # noinspection PyProtectedMember bonds = msc._get_bonds(mol1) @@ -65,7 +65,7 @@ def test_get_bonds(self): (23, 25), ] assert bonds == bonds_ref - mol2 = Molecule.from_file(f"{test_dir}/MgBH42.xyz") + mol2 = Molecule.from_file(f"{TEST_DIR}/MgBH42.xyz") bonds = msc._get_bonds(mol2) assert bonds == [(1, 3), (2, 3), (3, 4), (3, 5), (6, 8), (7, 8), (8, 9), (8, 10)] msc = MoleculeStructureComparator(ignore_ionic_bond=False) @@ -89,7 +89,7 @@ def test_get_bonds(self): (8, 10), ] - mol1 = Molecule.from_file(f"{test_dir}/molecule_with_halogen_bonds_1.xyz") + mol1 = Molecule.from_file(f"{TEST_DIR}/molecule_with_halogen_bonds_1.xyz") msc = MoleculeStructureComparator() # noinspection PyProtectedMember bonds = msc._get_bonds(mol1) @@ -122,7 +122,7 @@ def test_to_and_from_dict(self): d1 = msc1.as_dict() d2 = MoleculeStructureComparator.from_dict(d1).as_dict() assert d1 == d2 - thio1 = Molecule.from_file(f"{test_dir}/thiophene1.xyz") + thio1 = Molecule.from_file(f"{TEST_DIR}/thiophene1.xyz") # noinspection PyProtectedMember msc2 = MoleculeStructureComparator(bond_length_cap=0.2, priority_bonds=msc1._get_bonds(thio1), priority_cap=0.5) d1 = msc2.as_dict() @@ -130,7 +130,7 @@ def test_to_and_from_dict(self): assert d1 == d2 # def test_structural_change_in_geom_opt(self): - # qcout_path = f"{test_dir}/mol_1_3_bond.qcout" + # qcout_path = f"{TEST_DIR}/mol_1_3_bond.qcout" # qcout = QcOutput(qcout_path) # mol1 = qcout.data[0]["molecules"][0] # mol2 = qcout.data[0]["molecules"][-1] diff --git a/tests/analysis/test_piezo_sensitivity.py b/tests/analysis/test_piezo_sensitivity.py index 5c315db4859..c2a5b64648d 100644 --- a/tests/analysis/test_piezo_sensitivity.py +++ b/tests/analysis/test_piezo_sensitivity.py @@ -30,21 +30,21 @@ __status__ = "Development" __date__ = "4/23/19" -test_dir = f"{TEST_FILES_DIR}/piezo_sensitivity" +TEST_DIR = f"{TEST_FILES_DIR}/piezo_sensitivity" class TestPiezoSensitivity(PymatgenTest): def setUp(self): self.piezo_struct = self.get_structure("Pb2TiZrO6") - self.IST = np.load(f"{test_dir}/pztist.npy", allow_pickle=True) - self.BEC = np.load(f"{test_dir}/pztborn.npy", allow_pickle=True) - self.FCM = np.load(f"{test_dir}/pztfcm.npy", allow_pickle=True) - self.pointops = np.load(f"{test_dir}/pointops.npy", allow_pickle=True) - self.sharedops = np.load(f"{test_dir}/sharedops.npy", allow_pickle=True) - self.IST_operations = np.load(f"{test_dir}/istops.npy", allow_pickle=True) - with open(f"{test_dir}/becops.pkl", "rb") as file: + self.IST = np.load(f"{TEST_DIR}/pztist.npy", allow_pickle=True) + self.BEC = np.load(f"{TEST_DIR}/pztborn.npy", allow_pickle=True) + self.FCM = np.load(f"{TEST_DIR}/pztfcm.npy", allow_pickle=True) + self.point_ops = np.load(f"{TEST_DIR}/pointops.npy", allow_pickle=True) + self.shared_ops = np.load(f"{TEST_DIR}/sharedops.npy", allow_pickle=True) + self.IST_operations = np.load(f"{TEST_DIR}/istops.npy", allow_pickle=True) + with open(f"{TEST_DIR}/becops.pkl", "rb") as file: self.BEC_operations = pickle.load(file) - with open(f"{test_dir}/fcmops.pkl", "rb") as file: + with open(f"{TEST_DIR}/fcmops.pkl", "rb") as file: self.FCM_operations = pickle.load(file) self.piezo = np.array( [ @@ -67,27 +67,27 @@ def setUp(self): ) def test_born_effective_charge_tensor(self): - bec = BornEffectiveCharge(self.piezo_struct, self.BEC, self.pointops) + bec = BornEffectiveCharge(self.piezo_struct, self.BEC, self.point_ops) assert_allclose(self.BEC, bec.bec) def test_internal_strain_tensor(self): - ist = InternalStrainTensor(self.piezo_struct, self.IST, self.pointops) + ist = InternalStrainTensor(self.piezo_struct, self.IST, self.point_ops) assert_allclose(ist.ist, self.IST) def test_force_constant_matrix(self): - fcmt = ForceConstantMatrix(self.piezo_struct, self.FCM, self.pointops, self.sharedops) + fcmt = ForceConstantMatrix(self.piezo_struct, self.FCM, self.point_ops, self.shared_ops) assert_allclose(fcmt.fcm, self.FCM) def test_get_bec_operations(self): - bec = BornEffectiveCharge(self.piezo_struct, self.BEC, self.pointops) + bec = BornEffectiveCharge(self.piezo_struct, self.BEC, self.point_ops) # update test file - # with open(f"{test_dir}/becops.pkl", "wb") as file: + # with open(f"{TEST_DIR}/becops.pkl", "wb") as file: # pickle.dump(bec.get_BEC_operations(), file) bec.get_BEC_operations() assert np.all(self.BEC_operations == bec.BEC_operations) def test_get_rand_bec(self): - bec = BornEffectiveCharge(self.piezo_struct, self.BEC, self.pointops) + bec = BornEffectiveCharge(self.piezo_struct, self.BEC, self.point_ops) bec.get_BEC_operations() rand_BEC = bec.get_rand_BEC() for i in range(len(self.BEC_operations)): @@ -99,7 +99,7 @@ def test_get_rand_bec(self): ) def test_get_rand_ist(self): - ist = InternalStrainTensor(self.piezo_struct, self.IST, self.pointops) + ist = InternalStrainTensor(self.piezo_struct, self.IST, self.point_ops) ist.get_IST_operations() rand_IST = ist.get_rand_IST() for i in range(len(self.IST_operations)): @@ -111,15 +111,15 @@ def test_get_rand_ist(self): ) def test_get_fcm_operations(self): - fcm = ForceConstantMatrix(self.piezo_struct, self.FCM, self.pointops, self.sharedops) + fcm = ForceConstantMatrix(self.piezo_struct, self.FCM, self.point_ops, self.shared_ops) # update test file - # with open(f"{test_dir}/fcmops.pkl", "wb") as file: + # with open(f"{TEST_DIR}/fcmops.pkl", "wb") as file: # pickle.dump(fcm.get_FCM_operations(), file) fcm.get_FCM_operations() assert np.all(fcm.FCM_operations == self.FCM_operations) def test_get_unstable_fcm(self): - fcm = ForceConstantMatrix(self.piezo_struct, self.FCM, self.pointops, self.sharedops) + fcm = ForceConstantMatrix(self.piezo_struct, self.FCM, self.point_ops, self.shared_ops) fcm.get_FCM_operations() rand_FCM = fcm.get_unstable_FCM() rand_FCM = np.reshape(rand_FCM, (10, 3, 10, 3)).swapaxes(1, 2) @@ -134,7 +134,7 @@ def test_get_unstable_fcm(self): ) def test_get_fcm_symmetry(self): - fcm = ForceConstantMatrix(self.piezo_struct, self.FCM, self.pointops, self.sharedops) + fcm = ForceConstantMatrix(self.piezo_struct, self.FCM, self.point_ops, self.shared_ops) fcm.get_FCM_operations() fcm = fcm.get_symmetrized_FCM(np.random.rand(30, 30)) @@ -150,7 +150,7 @@ def test_get_fcm_symmetry(self): ) def test_get_asum_fcm(self): - fcm = ForceConstantMatrix(self.piezo_struct, self.FCM, self.pointops, self.sharedops) + fcm = ForceConstantMatrix(self.piezo_struct, self.FCM, self.point_ops, self.shared_ops) fcm.get_FCM_operations() rand_FCM = fcm.get_unstable_FCM() rand_FCM = fcm.get_asum_FCM(rand_FCM) @@ -176,7 +176,7 @@ def test_get_asum_fcm(self): assert_allclose(asum2, np.zeros([3, 3]), atol=1e-5) def test_get_stable_fcm(self): - fcm = ForceConstantMatrix(self.piezo_struct, self.FCM, self.pointops, self.sharedops) + fcm = ForceConstantMatrix(self.piezo_struct, self.FCM, self.point_ops, self.shared_ops) fcm.get_FCM_operations() rand_FCM = fcm.get_unstable_FCM() rand_FCM1 = fcm.get_stable_FCM(rand_FCM) @@ -209,7 +209,7 @@ def test_get_stable_fcm(self): def test_rand_fcm(self): pytest.importorskip("phonopy") - fcm = ForceConstantMatrix(self.piezo_struct, self.FCM, self.pointops, self.sharedops) + fcm = ForceConstantMatrix(self.piezo_struct, self.FCM, self.point_ops, self.shared_ops) fcm.get_FCM_operations() rand_FCM = fcm.get_rand_FCM() structure = pymatgen.io.phonopy.get_phonopy_structure(self.piezo_struct) @@ -260,7 +260,7 @@ def test_get_piezo(self): def test_rand_piezo(self): pytest.importorskip("phonopy") rand_BEC, rand_IST, rand_FCM, _piezo = rand_piezo( - self.piezo_struct, self.pointops, self.sharedops, self.BEC, self.IST, self.FCM + self.piezo_struct, self.point_ops, self.shared_ops, self.BEC, self.IST, self.FCM ) for i in range(len(self.BEC_operations)): diff --git a/tests/analysis/test_quasirrho.py b/tests/analysis/test_quasirrho.py index f06cf50d511..1e3da6dfcdb 100644 --- a/tests/analysis/test_quasirrho.py +++ b/tests/analysis/test_quasirrho.py @@ -14,10 +14,10 @@ class TestQuasiRRHO(unittest.TestCase): """Test class for QuasiRRHO""" def setUp(self): - test_dir = TEST_FILES_DIR - self.gout = GaussianOutput(f"{test_dir}/molecules/quasirrho_gaufreq.log") - self.linear_gout = GaussianOutput(f"{test_dir}/molecules/co2.log.gz") - self.qout = QCOutput(f"{test_dir}/molecules/new_qchem_files/Frequency_no_equal.qout") + TEST_DIR = TEST_FILES_DIR + self.gout = GaussianOutput(f"{TEST_DIR}/molecules/quasirrho_gaufreq.log") + self.linear_gout = GaussianOutput(f"{TEST_DIR}/molecules/co2.log.gz") + self.qout = QCOutput(f"{TEST_DIR}/molecules/new_qchem_files/Frequency_no_equal.qout") def test_qrrho_gaussian(self): """ diff --git a/tests/analysis/xas/test_spectrum.py b/tests/analysis/xas/test_spectrum.py index bcbb67572bf..1e267fba3b6 100644 --- a/tests/analysis/xas/test_spectrum.py +++ b/tests/analysis/xas/test_spectrum.py @@ -12,19 +12,19 @@ from pymatgen.core import Element from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -test_dir = f"{TEST_FILES_DIR}/spectrum_test" +TEST_DIR = f"{TEST_FILES_DIR}/spectrum_test" -with open(f"{test_dir}/LiCoO2_k_xanes.json") as fp: +with open(f"{TEST_DIR}/LiCoO2_k_xanes.json") as fp: k_xanes_dict = json.load(fp, cls=MontyDecoder) -with open(f"{test_dir}/LiCoO2_k_exafs.json") as fp: +with open(f"{TEST_DIR}/LiCoO2_k_exafs.json") as fp: k_exafs_dict = json.load(fp, cls=MontyDecoder) -with open(f"{test_dir}/ZnO_l2_xanes.json") as fp: +with open(f"{TEST_DIR}/ZnO_l2_xanes.json") as fp: l2_xanes_dict = json.load(fp, cls=MontyDecoder) -with open(f"{test_dir}/ZnO_l3_xanes.json") as fp: +with open(f"{TEST_DIR}/ZnO_l3_xanes.json") as fp: l3_xanes_dict = json.load(fp, cls=MontyDecoder) -with open(f"{test_dir}/site1_k_xanes.json") as fp: +with open(f"{TEST_DIR}/site1_k_xanes.json") as fp: site1_xanes_dict = json.load(fp, cls=MontyDecoder) -with open(f"{test_dir}/site2_k_xanes.json") as fp: +with open(f"{TEST_DIR}/site2_k_xanes.json") as fp: site2_xanes_dict = json.load(fp, cls=MontyDecoder) @@ -56,8 +56,8 @@ def test_add_mul(self): assert approx(self.k_xanes.get_interpolated_value(7720.422), abs=1e-3) == 0.274302 def test_as_from_dict(self): - s = XAS.from_dict(self.k_xanes.as_dict()) - assert_allclose(s.y, self.k_xanes.y) + xas = XAS.from_dict(self.k_xanes.as_dict()) + assert_allclose(xas.y, self.k_xanes.y) def test_attributes(self): assert_array_equal(self.k_xanes.energy, self.k_xanes.x) @@ -69,12 +69,7 @@ def test_str(self): def test_validate(self): y_zeros = np.zeros(len(self.k_xanes.x)) with pytest.raises(ValueError, match="Double check the intensities. Most of them are non-positive"): - XAS( - self.k_xanes.x, - y_zeros, - self.k_xanes.structure, - self.k_xanes.absorbing_element, - ) + XAS(self.k_xanes.x, y_zeros, self.k_xanes.structure, self.k_xanes.absorbing_element) def test_stitch_xafs(self): with pytest.raises(ValueError, match="Invalid mode. Only XAFS and L23 are supported"): diff --git a/tests/command_line/test_bader_caller.py b/tests/command_line/test_bader_caller.py index ef0679aa34e..c793afbdb53 100644 --- a/tests/command_line/test_bader_caller.py +++ b/tests/command_line/test_bader_caller.py @@ -1,6 +1,5 @@ from __future__ import annotations -import os import unittest import warnings from shutil import which @@ -60,17 +59,17 @@ def test_init(self): assert len(analysis.data) == 14 # Test Cube file format parsing - test_dir = f"{TEST_FILES_DIR}/bader" - copy_r(test_dir, self.tmp_path) - analysis = BaderAnalysis(cube_filename=os.path.join(test_dir, "elec.cube.gz")) + TEST_DIR = f"{TEST_FILES_DIR}/bader" + copy_r(TEST_DIR, self.tmp_path) + analysis = BaderAnalysis(cube_filename=f"{TEST_DIR}/elec.cube.gz") assert len(analysis.data) == 9 def test_from_path(self): - test_dir = f"{TEST_FILES_DIR}/bader" + TEST_DIR = f"{TEST_FILES_DIR}/bader" # we need to create two copies of input files since monty decompressing files # deletes the compressed version which can't happen twice in same directory - copy_r(test_dir, direct_dir := f"{self.tmp_path}/direct") - copy_r(test_dir, from_path_dir := f"{self.tmp_path}/from_path") + copy_r(TEST_DIR, direct_dir := f"{self.tmp_path}/direct") + copy_r(TEST_DIR, from_path_dir := f"{self.tmp_path}/from_path") chgcar_path = f"{direct_dir}/CHGCAR.gz" chgref_path = f"{direct_dir}/_CHGCAR_sum.gz" diff --git a/tests/command_line/test_mcsqs_caller.py b/tests/command_line/test_mcsqs_caller.py index c2d5d2f2c9d..ce31da91f60 100644 --- a/tests/command_line/test_mcsqs_caller.py +++ b/tests/command_line/test_mcsqs_caller.py @@ -15,16 +15,16 @@ __email__ = "handongling@berkeley.edu, rwoodsrobinson@lbl.gov" -test_dir = f"{TEST_FILES_DIR}/mcsqs" +TEST_DIR = f"{TEST_FILES_DIR}/mcsqs" @unittest.skipIf(not (which("mcsqs") and which("str2cif")), "mcsqs executable not present") class TestMcsqsCaller(PymatgenTest): def setUp(self): - self.pzt_structs = loadfn(f"{test_dir}/pzt-structs.json") - self.pzt_structs2 = loadfn(f"{test_dir}/pzt-structs-2.json") + self.pzt_structs = loadfn(f"{TEST_DIR}/pzt-structs.json") + self.pzt_structs2 = loadfn(f"{TEST_DIR}/pzt-structs-2.json") self.struct = self.get_structure("Pb2TiZrO6") - self.perfect_match_zzn_rs = loadfn(f"{test_dir}/perfect_match_zzn_rs.json") + self.perfect_match_zzn_rs = loadfn(f"{TEST_DIR}/perfect_match_zzn_rs.json") def test_mcsqs_caller_supercell(self): struct = self.struct.copy() diff --git a/tests/command_line/test_vampire_caller.py b/tests/command_line/test_vampire_caller.py index f7b8f4703c7..e85089c6964 100644 --- a/tests/command_line/test_vampire_caller.py +++ b/tests/command_line/test_vampire_caller.py @@ -10,14 +10,14 @@ from pymatgen.core.structure import Structure from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -test_dir = f"{TEST_FILES_DIR}/magnetic_orderings" +TEST_DIR = f"{TEST_FILES_DIR}/magnetic_orderings" @unittest.skipIf(not which("vampire-serial"), "vampire executable not present") class TestVampireCaller(PymatgenTest): @classmethod def setUpClass(cls): - cls.Mn3Al = pd.read_json(f"{test_dir}/Mn3Al.json") + cls.Mn3Al = pd.read_json(f"{TEST_DIR}/Mn3Al.json") cls.compounds = [cls.Mn3Al] @@ -44,6 +44,4 @@ def test_vampire(self): user_input_settings=settings, ) - voutput = vc.output - critical_temp = voutput.critical_temp - assert approx(critical_temp) == 400 + assert approx(vc.output.critical_temp) == 400 diff --git a/tests/electronic_structure/test_boltztrap2.py b/tests/electronic_structure/test_boltztrap2.py index 0d2ee862ad5..9937b3b9d52 100644 --- a/tests/electronic_structure/test_boltztrap2.py +++ b/tests/electronic_structure/test_boltztrap2.py @@ -24,36 +24,36 @@ except Exception: BOLTZTRAP2_PRESENT = False -test_dir = f"{TEST_FILES_DIR}/boltztrap2" +TEST_DIR = f"{TEST_FILES_DIR}/boltztrap2" -vrun_file = f"{test_dir}/vasprun.xml" -vrun = Vasprun(vrun_file, parse_projected_eigen=True) +vasp_run_file = f"{TEST_DIR}/vasprun.xml" +vasp_run = Vasprun(vasp_run_file, parse_projected_eigen=True) -vrun_file_spin = f"{test_dir}/vasprun_spin.xml" -vrun_spin = Vasprun(vrun_file_spin, parse_projected_eigen=True) -bs = loadfn(f"{test_dir}/PbTe_bandstructure.json") -bs_sp = loadfn(f"{test_dir}/N2_bandstructure.json") +vasp_run_file_spin = f"{TEST_DIR}/vasprun_spin.xml" +vasp_run_spin = Vasprun(vasp_run_file_spin, parse_projected_eigen=True) +bs = loadfn(f"{TEST_DIR}/PbTe_bandstructure.json") +bs_sp = loadfn(f"{TEST_DIR}/N2_bandstructure.json") -bzt_interp_fn = f"{test_dir}/bztInterp.json.gz" -bzt_transp_fn = f"{test_dir}/bztTranspProps.json.gz" +bzt_interp_fn = f"{TEST_DIR}/bztInterp.json.gz" +bzt_transp_fn = f"{TEST_DIR}/bztTranspProps.json.gz" @unittest.skipIf(not BOLTZTRAP2_PRESENT, "No boltztrap2, skipping tests...") class TestVasprunBSLoader(unittest.TestCase): def setUp(self): - self.loader = VasprunBSLoader(vrun) + self.loader = VasprunBSLoader(vasp_run) assert self.loader is not None - self.loader = VasprunBSLoader(bs, vrun.final_structure) + self.loader = VasprunBSLoader(bs, vasp_run.final_structure) assert self.loader is not None - self.loader = VasprunBSLoader.from_file(vrun_file) + self.loader = VasprunBSLoader.from_file(vasp_run_file) assert self.loader is not None - self.loader_sp = VasprunBSLoader(vrun_spin) + self.loader_sp = VasprunBSLoader(vasp_run_spin) assert self.loader_sp is not None - self.loader_sp = VasprunBSLoader(bs_sp, vrun_spin.final_structure) + self.loader_sp = VasprunBSLoader(bs_sp, vasp_run_spin.final_structure) assert self.loader_sp is not None - self.loader_sp = VasprunBSLoader.from_file(vrun_file_spin) + self.loader_sp = VasprunBSLoader.from_file(vasp_run_file_spin) assert self.loader_sp is not None def test_properties(self): @@ -82,10 +82,10 @@ def test_get_volume(self): @unittest.skipIf(not BOLTZTRAP2_PRESENT, "No boltztrap2, skipping tests...") class TestBandstructureLoader(unittest.TestCase): def setUp(self): - self.loader = BandstructureLoader(bs, vrun.structures[-1]) + self.loader = BandstructureLoader(bs, vasp_run.structures[-1]) assert self.loader is not None - self.loader_sp = BandstructureLoader(bs_sp, vrun_spin.structures[-1]) + self.loader_sp = BandstructureLoader(bs_sp, vasp_run_spin.structures[-1]) assert self.loader_sp is not None assert self.loader_sp.ebands_all.shape == (24, 198) @@ -111,7 +111,7 @@ def test_get_volume(self): @unittest.skipIf(not BOLTZTRAP2_PRESENT, "No boltztrap2, skipping tests...") class TestVasprunLoader(unittest.TestCase): def setUp(self): - self.loader = VasprunLoader(vrun) + self.loader = VasprunLoader(vasp_run) assert self.loader.proj.shape == (120, 20, 2, 9) assert self.loader is not None @@ -124,14 +124,14 @@ def test_get_volume(self): assert self.loader.get_volume() == approx(477.6256714925874, abs=1e-5) def test_from_file(self): - self.loader = VasprunLoader().from_file(vrun_file) + self.loader = VasprunLoader().from_file(vasp_run_file) assert self.loader is not None @unittest.skipIf(not BOLTZTRAP2_PRESENT, "No boltztrap2, skipping tests...") class TestBztInterpolator(unittest.TestCase): def setUp(self): - self.loader = VasprunBSLoader(vrun) + self.loader = VasprunBSLoader(vasp_run) self.bztInterp = BztInterpolator(self.loader, lpfac=2) assert self.bztInterp is not None self.bztInterp = BztInterpolator(self.loader, lpfac=2, save_bztInterp=True, fname=bzt_interp_fn) @@ -139,7 +139,7 @@ def setUp(self): self.bztInterp = BztInterpolator(self.loader, load_bztInterp=True, fname=bzt_interp_fn) assert self.bztInterp is not None - self.loader_sp = VasprunBSLoader(vrun_spin) + self.loader_sp = VasprunBSLoader(vasp_run_spin) self.bztInterp_sp = BztInterpolator(self.loader_sp, lpfac=2) assert self.bztInterp_sp is not None self.bztInterp_sp = BztInterpolator(self.loader_sp, lpfac=2, save_bztInterp=True, fname=bzt_interp_fn) @@ -208,7 +208,7 @@ def test_tot_proj_dos(self): @unittest.skipIf(not BOLTZTRAP2_PRESENT, "No boltztrap2, skipping tests...") class TestBztTransportProperties(unittest.TestCase): def setUp(self): - loader = VasprunBSLoader(vrun) + loader = VasprunBSLoader(vasp_run) bztInterp = BztInterpolator(loader, lpfac=2) self.bztTransp = BztTransportProperties(bztInterp, temp_r=np.arange(300, 600, 100)) assert self.bztTransp is not None @@ -232,7 +232,7 @@ def setUp(self): self.bztTransp = BztTransportProperties(bztInterp, load_bztTranspProps=True, fname=bzt_transp_fn) assert self.bztTransp is not None - loader_sp = VasprunBSLoader(vrun_spin) + loader_sp = VasprunBSLoader(vasp_run_spin) bztInterp_sp = BztInterpolator(loader_sp, lpfac=2) self.bztTransp_sp = BztTransportProperties(bztInterp_sp, temp_r=np.arange(300, 600, 100)) assert self.bztTransp_sp is not None @@ -308,7 +308,7 @@ def test_compute_properties_doping(self): @unittest.skipIf(not BOLTZTRAP2_PRESENT, "No boltztrap2, skipping tests...") class TestBztPlotter(unittest.TestCase): def test_plot(self): - loader = VasprunBSLoader(vrun) + loader = VasprunBSLoader(vasp_run) bztInterp = BztInterpolator(loader, lpfac=2) bztTransp = BztTransportProperties(bztInterp, temp_r=np.arange(300, 600, 100)) self.bztPlotter = BztPlotter(bztTransp, bztInterp) diff --git a/tests/electronic_structure/test_cohp.py b/tests/electronic_structure/test_cohp.py index 1299f47fb3e..9d459a3edc5 100644 --- a/tests/electronic_structure/test_cohp.py +++ b/tests/electronic_structure/test_cohp.py @@ -17,25 +17,25 @@ from pymatgen.electronic_structure.core import Orbital, Spin from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -test_dir = f"{TEST_FILES_DIR}/cohp" +TEST_DIR = f"{TEST_FILES_DIR}/cohp" class TestCohp(unittest.TestCase): def setUp(self): - with open(f"{test_dir}/cohp.json") as file: + with open(f"{TEST_DIR}/cohp.json") as file: self.cohp = Cohp.from_dict(json.load(file)) self.cohp_only = Cohp(self.cohp.efermi, self.cohp.energies, self.cohp.cohp) - with open(f"{test_dir}/coop.json") as file: + with open(f"{TEST_DIR}/coop.json") as file: self.coop = Cohp.from_dict(json.load(file)) - with open(f"{test_dir}/cobi.json") as file: + with open(f"{TEST_DIR}/cobi.json") as file: self.cobi = Cohp.from_dict(json.load(file)) def test_as_from_dict(self): - with open(f"{test_dir}/cohp.json") as file: + with open(f"{TEST_DIR}/cohp.json") as file: cohp_dict = json.load(file) assert self.cohp.as_dict() == cohp_dict - with open(f"{test_dir}/cobi.json") as file: + with open(f"{TEST_DIR}/cobi.json") as file: cobi_dict = json.load(file) assert self.cobi.as_dict() == cobi_dict @@ -68,12 +68,12 @@ def test_get_interpolated_value(self): def test_str(self): header = "#Energy COOPUp ICOOPUp \n" - with open(f"{test_dir}/cohp.str") as file: + with open(f"{TEST_DIR}/cohp.str") as file: str_cohp = file.read() assert str(self.cohp) == str_cohp assert str(self.coop).strip().startswith(header) - with open(f"{test_dir}/coop.str") as file: + with open(f"{TEST_DIR}/coop.str") as file: str_coop = file.read() assert str(self.coop) == str_coop assert str(self.coop).strip().startswith(header) @@ -792,58 +792,58 @@ def test_extremum_icohpvalue(self): class TestCompleteCohp(PymatgenTest): def setUp(self): - filepath = f"{test_dir}/complete_cohp_lobster.json" + filepath = f"{TEST_DIR}/complete_cohp_lobster.json" with open(filepath) as f: self.cohp_lobster_dict = CompleteCohp.from_dict(json.load(f)) - filepath = f"{test_dir}/complete_coop_lobster.json" + filepath = f"{TEST_DIR}/complete_coop_lobster.json" with open(filepath) as f: self.coop_lobster_dict = CompleteCohp.from_dict(json.load(f)) - filepath = f"{test_dir}/complete_cohp_lmto.json" + filepath = f"{TEST_DIR}/complete_cohp_lmto.json" with open(filepath) as f: self.cohp_lmto_dict = CompleteCohp.from_dict(json.load(f)) - filepath = f"{test_dir}/complete_cohp_orbitalwise.json" + filepath = f"{TEST_DIR}/complete_cohp_orbitalwise.json" with open(filepath) as f: self.cohp_orb_dict = CompleteCohp.from_dict(json.load(f)) # Lobster 3.0 - filepath = f"{test_dir}/complete_cohp_forb.json" + filepath = f"{TEST_DIR}/complete_cohp_forb.json" with open(filepath) as f: self.cohp_lobster_forb_dict = CompleteCohp.from_dict(json.load(f)) # Lobster 2.0 - filepath = f"{test_dir}/COPL.BiSe" - structure = f"{test_dir}/CTRL.BiSe" + filepath = f"{TEST_DIR}/COPL.BiSe" + structure = f"{TEST_DIR}/CTRL.BiSe" self.cohp_lmto = CompleteCohp.from_file("lmto", filename=filepath, structure_file=structure) - filepath = f"{test_dir}/COHPCAR.lobster.gz" - structure = f"{test_dir}/POSCAR" + filepath = f"{TEST_DIR}/COHPCAR.lobster.gz" + structure = f"{TEST_DIR}/POSCAR" self.cohp_lobster = CompleteCohp.from_file("lobster", filename=filepath, structure_file=structure) - # with open(f"{test_dir}/complete_cohp_lobster.json",'w') as f: + # with open(f"{TEST_DIR}/complete_cohp_lobster.json",'w') as f: # json.dump(self.cohp_lobster.as_dict(),f) - filepath = f"{test_dir}/COOPCAR.lobster.BiSe.gz" - structure = f"{test_dir}/POSCAR.BiSe" + filepath = f"{TEST_DIR}/COOPCAR.lobster.BiSe.gz" + structure = f"{TEST_DIR}/POSCAR.BiSe" self.coop_lobster = CompleteCohp.from_file( "lobster", filename=filepath, structure_file=structure, are_coops=True ) - filepath = f"{test_dir}/COHPCAR.lobster.orbitalwise.gz" - structure = f"{test_dir}/POSCAR.orbitalwise" + filepath = f"{TEST_DIR}/COHPCAR.lobster.orbitalwise.gz" + structure = f"{TEST_DIR}/POSCAR.orbitalwise" self.cohp_orb = CompleteCohp.from_file("lobster", filename=filepath, structure_file=structure) - # with open(f"{test_dir}/complete_cohp_orbitalwise.json",'w') as f: + # with open(f"{TEST_DIR}/complete_cohp_orbitalwise.json",'w') as f: # json.dump(self.cohp_orb.as_dict(),f) - filepath = f"{test_dir}/COHPCAR.lobster.notot.orbitalwise.gz" + filepath = f"{TEST_DIR}/COHPCAR.lobster.notot.orbitalwise.gz" self.cohp_notot = CompleteCohp.from_file("lobster", filename=filepath, structure_file=structure) # Lobster 3.0 - filepath = f"{test_dir}/COHPCAR.lobster.Na2UO4.gz" - structure = f"{test_dir}/POSCAR.Na2UO4" + filepath = f"{TEST_DIR}/COHPCAR.lobster.Na2UO4.gz" + structure = f"{TEST_DIR}/POSCAR.Na2UO4" self.cohp_lobster_forb = CompleteCohp.from_file("lobster", filename=filepath, structure_file=structure) # spinpolarized case: - filepath = f"{test_dir}/environments/COHPCAR.lobster.mp-190.gz" - structure = f"{test_dir}/environments/POSCAR.mp_190.gz" + filepath = f"{TEST_DIR}/environments/COHPCAR.lobster.mp-190.gz" + structure = f"{TEST_DIR}/environments/POSCAR.mp_190.gz" self.cohp_lobster_spin_polarized = CompleteCohp.from_file( "lobster", filename=filepath, structure_file=structure ) # COBI - filepath = f"{test_dir}/COBICAR.lobster.gz" - structure = f"{test_dir}/POSCAR.COBI" + filepath = f"{TEST_DIR}/COBICAR.lobster.gz" + structure = f"{TEST_DIR}/POSCAR.COBI" self.cobi = CompleteCohp.from_file("lobster", filename=filepath, structure_file=structure, are_cobis=True) @@ -1195,16 +1195,16 @@ def test_orbital_resolved_cohp_summed_spin_channels(self): class TestMethod(unittest.TestCase): def setUp(self): - filepath = f"{test_dir}/COHPCAR.lobster.gz" - structure = f"{test_dir}/POSCAR" + filepath = f"{TEST_DIR}/COHPCAR.lobster.gz" + structure = f"{TEST_DIR}/POSCAR" self.cohp_lobster = CompleteCohp.from_file("lobster", filename=filepath, structure_file=structure) - filepath = f"{test_dir}/COHPCAR.lobster.orbitalwise.gz" - structure = f"{test_dir}/POSCAR.orbitalwise" + filepath = f"{TEST_DIR}/COHPCAR.lobster.orbitalwise.gz" + structure = f"{TEST_DIR}/POSCAR.orbitalwise" self.cohp_orb = CompleteCohp.from_file("lobster", filename=filepath, structure_file=structure) - filepath = f"{test_dir}/environments/COHPCAR.lobster.mp-190.gz" - structure = f"{test_dir}/environments/POSCAR.mp_190.gz" + filepath = f"{TEST_DIR}/environments/COHPCAR.lobster.mp-190.gz" + structure = f"{TEST_DIR}/environments/POSCAR.mp_190.gz" self.cohp_lobster_spin_polarized = CompleteCohp.from_file( "lobster", filename=filepath, structure_file=structure ) diff --git a/tests/entries/test_correction_calculator.py b/tests/entries/test_correction_calculator.py index 9815591538e..ec88c15143b 100644 --- a/tests/entries/test_correction_calculator.py +++ b/tests/entries/test_correction_calculator.py @@ -1,6 +1,5 @@ from __future__ import annotations -import os import unittest import pytest @@ -8,6 +7,8 @@ from pymatgen.entries.correction_calculator import CorrectionCalculator from pymatgen.util.testing import TEST_FILES_DIR +TEST_DIR = f"{TEST_FILES_DIR}/correction_calculator" + class TestCorrectionCalculator(unittest.TestCase): def setUp(self): @@ -91,12 +92,10 @@ def setUp(self): "ozonide": (0, 0), } - self.test_dir = f"{TEST_FILES_DIR}/correction_calculator" - def test_normal_corrections(self): """Test that the values in MPCompatibility.yaml are reproduced correctly.""" - exp_path = os.path.join(self.test_dir, "exp_compounds_norm.json.gz") - calc_path = os.path.join(self.test_dir, "calc_compounds_norm.json.gz") + exp_path = f"{TEST_DIR}/exp_compounds_norm.json.gz" + calc_path = f"{TEST_DIR}/calc_compounds_norm.json.gz" calculator = CorrectionCalculator(exclude_polyanions=self.exclude_polyanions) corrections = calculator.compute_from_files(exp_path, calc_path) @@ -105,8 +104,8 @@ def test_normal_corrections(self): def test_warnings_options(self): """Test that compounds can be included/excluded using the allow_{warning} optional parameters.""" - exp_path = os.path.join(self.test_dir, "exp_compounds_norm.json.gz") - calc_path = os.path.join(self.test_dir, "calc_compounds_norm.json.gz") + exp_path = f"{TEST_DIR}/exp_compounds_norm.json.gz" + calc_path = f"{TEST_DIR}/calc_compounds_norm.json.gz" calculator = CorrectionCalculator(max_error=1, exclude_polyanions=[], allow_unstable=True) corrections = calculator.compute_from_files(exp_path, calc_path) @@ -115,8 +114,8 @@ def test_warnings_options(self): def test_no_uncertainties(self): """Test that corrections can be calculated with no uncertainties.""" - exp_path = os.path.join(self.test_dir, "exp_no_error_compounds.json.gz") - calc_path = os.path.join(self.test_dir, "calc_compounds_norm.json.gz") + exp_path = f"{TEST_DIR}/exp_no_error_compounds.json.gz" + calc_path = f"{TEST_DIR}/calc_compounds_norm.json.gz" calculator = CorrectionCalculator(exclude_polyanions=self.exclude_polyanions) corrections = calculator.compute_from_files(exp_path, calc_path) @@ -125,8 +124,8 @@ def test_no_uncertainties(self): def test_missing_entry_response(self): """Test that correct error is raised (ValueError) if the input is missing a computed entry.""" - exp_path = os.path.join(self.test_dir, "exp_compounds_norm.json.gz") - calc_path = os.path.join(self.test_dir, "calc_missing_compounds.json.gz") + exp_path = f"{TEST_DIR}/exp_compounds_norm.json.gz" + calc_path = f"{TEST_DIR}/calc_missing_compounds.json.gz" calculator = CorrectionCalculator(exclude_polyanions=self.exclude_polyanions) with pytest.raises(ValueError, match="Computed entries missing O"): diff --git a/tests/io/abinit/test_inputs.py b/tests/io/abinit/test_inputs.py index 9f1baa7c6d1..3b39f7e7848 100644 --- a/tests/io/abinit/test_inputs.py +++ b/tests/io/abinit/test_inputs.py @@ -20,17 +20,17 @@ ) from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -_test_dir = f"{TEST_FILES_DIR}/abinit" +TEST_DIR = f"{TEST_FILES_DIR}/abinit" def abiref_file(filename): """Return absolute path to filename in ~pymatgen/tests/files/abinit.""" - return os.path.join(_test_dir, filename) + return os.path.join(TEST_DIR, filename) def abiref_files(*filenames): """Return list of absolute paths to filenames in ~pymatgen/tests/files/abinit.""" - return [os.path.join(_test_dir, f) for f in filenames] + return [os.path.join(TEST_DIR, f) for f in filenames] class AbinitInputTestCase(PymatgenTest): @@ -152,7 +152,7 @@ def test_input_errors(self): def test_helper_functions(self): """Testing BasicAbinitInput helper functions.""" - inp = BasicAbinitInput(structure=abiref_file("si.cif"), pseudos="14si.pspnc", pseudo_dir=_test_dir) + inp = BasicAbinitInput(structure=abiref_file("si.cif"), pseudos="14si.pspnc", pseudo_dir=TEST_DIR) inp.set_kmesh(ngkpt=(1, 2, 3), shiftk=(1, 2, 3, 4, 5, 6)) assert inp["kptopt"] == 1 diff --git a/tests/io/abinit/test_netcdf.py b/tests/io/abinit/test_netcdf.py index 497e218b923..e9f78d801ff 100644 --- a/tests/io/abinit/test_netcdf.py +++ b/tests/io/abinit/test_netcdf.py @@ -17,11 +17,11 @@ except ImportError: netCDF4 = None -_test_dir = f"{TEST_FILES_DIR}/abinit" +TEST_DIR = f"{TEST_FILES_DIR}/abinit" def ref_file(filename): - return os.path.join(_test_dir, filename) + return os.path.join(TEST_DIR, filename) class TestEtsfReader(PymatgenTest): diff --git a/tests/io/abinit/test_pseudos.py b/tests/io/abinit/test_pseudos.py index 2ecc96779a1..991f84e1773 100644 --- a/tests/io/abinit/test_pseudos.py +++ b/tests/io/abinit/test_pseudos.py @@ -9,11 +9,11 @@ from pymatgen.io.abinit.pseudos import Pseudo, PseudoTable from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -_test_dir = f"{TEST_FILES_DIR}/abinit" +TEST_DIR = f"{TEST_FILES_DIR}/abinit" def ref_file(filename): - return os.path.join(_test_dir, filename) + return os.path.join(TEST_DIR, filename) def ref_files(*filenames): diff --git a/tests/io/feff/test_outputs.py b/tests/io/feff/test_outputs.py index ad48ab1469e..4577141ebbb 100644 --- a/tests/io/feff/test_outputs.py +++ b/tests/io/feff/test_outputs.py @@ -5,7 +5,7 @@ from pymatgen.io.feff.outputs import LDos, Xmu from pymatgen.util.testing import TEST_FILES_DIR -test_dir_reci = f"{TEST_FILES_DIR}/feff_reci_dos" +TEST_DIR = f"{TEST_FILES_DIR}/feff_reci_dos" class TestFeffLdos(unittest.TestCase): @@ -13,8 +13,8 @@ class TestFeffLdos(unittest.TestCase): filepath2 = f"{TEST_FILES_DIR}/ldos" ldos = LDos.from_file(filepath1, filepath2) - reci_feffinp = f"{test_dir_reci}/feff.inp" - reci_ldos = f"{test_dir_reci}/ldos" + reci_feffinp = f"{TEST_DIR}/feff.inp" + reci_ldos = f"{TEST_DIR}/ldos" reci_dos = LDos.from_file(reci_feffinp, reci_ldos) def test_init(self): diff --git a/tests/io/lammps/test_data.py b/tests/io/lammps/test_data.py index 4a59ff6baf3..261c0132843 100644 --- a/tests/io/lammps/test_data.py +++ b/tests/io/lammps/test_data.py @@ -18,7 +18,7 @@ from pymatgen.io.lammps.data import CombinedData, ForceField, LammpsBox, LammpsData, Topology, lattice_2_lmpbox from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -test_dir = f"{TEST_FILES_DIR}/lammps" +TEST_DIR = f"{TEST_FILES_DIR}/lammps" class TestLammpsBox(PymatgenTest): @@ -78,11 +78,11 @@ def test_to_lattice(self): class TestLammpsData(PymatgenTest): @classmethod def setUpClass(cls): - cls.peptide = LammpsData.from_file(filename=f"{test_dir}/data.peptide") - cls.ethane = LammpsData.from_file(filename=f"{test_dir}/ethane.data") - cls.quartz = LammpsData.from_file(filename=f"{test_dir}/data.quartz", atom_style="atomic") - cls.virus = LammpsData.from_file(filename=f"{test_dir}/virus.data", atom_style="angle") - cls.tatb = LammpsData.from_file(filename=f"{test_dir}/tatb.data", atom_style="charge", sort_id=True) + cls.peptide = LammpsData.from_file(filename=f"{TEST_DIR}/data.peptide") + cls.ethane = LammpsData.from_file(filename=f"{TEST_DIR}/ethane.data") + cls.quartz = LammpsData.from_file(filename=f"{TEST_DIR}/data.quartz", atom_style="atomic") + cls.virus = LammpsData.from_file(filename=f"{TEST_DIR}/virus.data", atom_style="angle") + cls.tatb = LammpsData.from_file(filename=f"{TEST_DIR}/tatb.data", atom_style="charge", sort_id=True) def test_structure(self): quartz = self.quartz.structure @@ -280,7 +280,7 @@ def test_write_file(self): def test_disassemble(self): # general tests - c = LammpsData.from_file(f"{test_dir}/crambin.data") + c = LammpsData.from_file(f"{TEST_DIR}/crambin.data") _, c_ff, topos = c.disassemble() mass_info = [ ("N1", 14.0067), @@ -444,7 +444,7 @@ def test_from_ff_and_topologies(self): "Angle Coeffs": [{"coeffs": [42.1845, 109.4712], "types": [("H", "O", "H")]}], } ff = ForceField(mass.items(), non_bond_coeffs, topo_coeffs) - with gzip.open(f"{test_dir}/topologies_ice.json.gz") as f: + with gzip.open(f"{TEST_DIR}/topologies_ice.json.gz") as f: topo_dicts = json.load(f) topologies = [Topology.from_dict(d) for d in topo_dicts] box = LammpsBox([[-0.75694412, 44.165558], [0.38127473, 47.066074], [0.17900842, 44.193867]]) @@ -674,7 +674,7 @@ def setUpClass(cls): ] } cls.virus = ForceField(mass_info=mass_info, nonbond_coeffs=nonbond_coeffs, topo_coeffs=topo_coeffs) - cls.ethane = ForceField.from_file(f"{test_dir}/ff_ethane.yaml") + cls.ethane = ForceField.from_file(f"{TEST_DIR}/ff_ethane.yaml") def test_init(self): v = self.virus @@ -800,19 +800,19 @@ def test_lattice_2_lmpbox(self): class TestCombinedData(unittest.TestCase): @classmethod def setUpClass(cls): - cls.ec = LammpsData.from_file(filename=f"{test_dir}/ec.data.gz") - cls.fec = LammpsData.from_file(filename=f"{test_dir}/fec.data.gz") - cls.li = LammpsData.from_file(filename=f"{test_dir}/li.data") - cls.li_minimal = LammpsData.from_file(filename=f"{test_dir}/li_minimal.data") - cls.coord = CombinedData.parse_xyz(filename=f"{test_dir}/ec_fec.xyz.gz") - cls.small_coord = CombinedData.parse_xyz(filename=f"{test_dir}/li_ec.xyz") - cls.small_coord_2 = CombinedData.parse_xyz(filename=f"{test_dir}/li_ec_2.xyz") - cls.small_coord_3 = CombinedData.parse_xyz(filename=f"{test_dir}/li_2.xyz") + cls.ec = LammpsData.from_file(filename=f"{TEST_DIR}/ec.data.gz") + cls.fec = LammpsData.from_file(filename=f"{TEST_DIR}/fec.data.gz") + cls.li = LammpsData.from_file(filename=f"{TEST_DIR}/li.data") + cls.li_minimal = LammpsData.from_file(filename=f"{TEST_DIR}/li_minimal.data") + cls.coord = CombinedData.parse_xyz(filename=f"{TEST_DIR}/ec_fec.xyz.gz") + cls.small_coord = CombinedData.parse_xyz(filename=f"{TEST_DIR}/li_ec.xyz") + cls.small_coord_2 = CombinedData.parse_xyz(filename=f"{TEST_DIR}/li_ec_2.xyz") + cls.small_coord_3 = CombinedData.parse_xyz(filename=f"{TEST_DIR}/li_2.xyz") cls.ec_fec1 = CombinedData.from_files( - f"{test_dir}/ec_fec.xyz.gz", + f"{TEST_DIR}/ec_fec.xyz.gz", [1200, 300], - f"{test_dir}/ec.data.gz", - f"{test_dir}/fec.data.gz", + f"{TEST_DIR}/ec.data.gz", + f"{TEST_DIR}/fec.data.gz", ) cls.ec_fec2 = CombinedData.from_lammpsdata([cls.ec, cls.fec], ["EC", "FEC"], [1200, 300], cls.coord) cls.ec_fec_ld = cls.ec_fec1.as_lammpsdata() diff --git a/tests/io/lammps/test_generators.py b/tests/io/lammps/test_generators.py index c0913444320..95b08c3cc07 100644 --- a/tests/io/lammps/test_generators.py +++ b/tests/io/lammps/test_generators.py @@ -5,14 +5,14 @@ from pymatgen.io.lammps.generators import LammpsMinimization from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -test_dir = f"{TEST_FILES_DIR}/lammps" +TEST_DIR = f"{TEST_FILES_DIR}/lammps" class TestLammpsMinimization(PymatgenTest): @classmethod def setUpClass(cls): - cls.filename = f"{test_dir}/lgps.in" - cls.cif = f"{test_dir}/lgps.cif" + cls.filename = f"{TEST_DIR}/lgps.in" + cls.cif = f"{TEST_DIR}/lgps.cif" cls.structure = Structure.from_file(cls.cif) def test_get_input_set(self): diff --git a/tests/io/lammps/test_inputs.py b/tests/io/lammps/test_inputs.py index 2aeeb1a9ccf..7bc0c7cc96d 100644 --- a/tests/io/lammps/test_inputs.py +++ b/tests/io/lammps/test_inputs.py @@ -13,13 +13,13 @@ from pymatgen.io.lammps.inputs import LammpsInputFile, LammpsRun, LammpsTemplateGen, write_lammps_inputs from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -test_dir = f"{TEST_FILES_DIR}/lammps" +TEST_DIR = f"{TEST_FILES_DIR}/lammps" class TestLammpsInputFile(PymatgenTest): @classmethod def setUpClass(cls): - cls.filename = f"{test_dir}/lgps.in" + cls.filename = f"{TEST_DIR}/lgps.in" def test_from_file(self): lmp_input = LammpsInputFile().from_file(self.filename) diff --git a/tests/io/lammps/test_outputs.py b/tests/io/lammps/test_outputs.py index 55933bd1592..d1fa60c8e82 100644 --- a/tests/io/lammps/test_outputs.py +++ b/tests/io/lammps/test_outputs.py @@ -11,16 +11,16 @@ from pymatgen.io.lammps.outputs import LammpsDump, parse_lammps_dumps, parse_lammps_log from pymatgen.util.testing import TEST_FILES_DIR -test_dir = f"{TEST_FILES_DIR}/lammps" +TEST_DIR = f"{TEST_FILES_DIR}/lammps" class TestLammpsDump(unittest.TestCase): @classmethod def setUpClass(cls): - with open(f"{test_dir}/dump.rdx_wc.100") as file: + with open(f"{TEST_DIR}/dump.rdx_wc.100") as file: rdx_str = file.read() cls.rdx = LammpsDump.from_str(string=rdx_str) - with open(f"{test_dir}/dump.tatb") as file: + with open(f"{TEST_DIR}/dump.tatb") as file: tatb_str = file.read() cls.tatb = LammpsDump.from_str(string=tatb_str) @@ -57,13 +57,13 @@ def test_json_dict(self): class TestFunc(unittest.TestCase): def test_parse_lammps_dumps(self): # gzipped - rdx_10_pattern = f"{test_dir}/dump.rdx.gz" + rdx_10_pattern = f"{TEST_DIR}/dump.rdx.gz" rdx_10 = list(parse_lammps_dumps(file_pattern=rdx_10_pattern)) timesteps_10 = [d.timestep for d in rdx_10] np.testing.assert_array_equal(timesteps_10, np.arange(0, 101, 10)) assert rdx_10[-1].data.shape == (21, 5) # wildcard - rdx_25_pattern = f"{test_dir}{os.path.sep}dump.rdx_wc.*" + rdx_25_pattern = f"{TEST_DIR}{os.path.sep}dump.rdx_wc.*" rdx_25 = list(parse_lammps_dumps(file_pattern=rdx_25_pattern)) timesteps_25 = [d.timestep for d in rdx_25] np.testing.assert_array_equal(timesteps_25, np.arange(0, 101, 25)) @@ -71,7 +71,7 @@ def test_parse_lammps_dumps(self): def test_parse_lammps_log(self): comb_file = "log.5Oct16.comb.Si.elastic.g++.1.gz" - comb = parse_lammps_log(filename=os.path.join(test_dir, comb_file)) + comb = parse_lammps_log(filename=os.path.join(TEST_DIR, comb_file)) assert len(comb) == 6 # first comb run comb0 = comb[0] @@ -107,7 +107,7 @@ def test_parse_lammps_log(self): assert_allclose(comb_1.iloc[[0, -1], [0, -3]], comb_1_data) ehex_file = "log.13Oct16.ehex.g++.8.gz" - ehex = parse_lammps_log(filename=os.path.join(test_dir, ehex_file)) + ehex = parse_lammps_log(filename=os.path.join(TEST_DIR, ehex_file)) assert len(ehex) == 3 ehex0, ehex1, ehex2 = ehex # ehex run #1 @@ -136,7 +136,7 @@ def test_parse_lammps_log(self): assert_allclose(ehex2.iloc[[0, -1]], ehex2_data) peptide_file = "log.5Oct16.peptide.g++.1.gz" - peptide = parse_lammps_log(filename=os.path.join(test_dir, peptide_file)) + peptide = parse_lammps_log(filename=os.path.join(TEST_DIR, peptide_file)) peptide0 = peptide[0] np.testing.assert_array_equal( [ diff --git a/tests/io/lobster/test_lobsterenv.py b/tests/io/lobster/test_lobsterenv.py index a1249070e17..1f76da32d6a 100644 --- a/tests/io/lobster/test_lobsterenv.py +++ b/tests/io/lobster/test_lobsterenv.py @@ -21,7 +21,7 @@ __email__ = "janine.george@uclouvain.be" __date__ = "Jan 14, 2021" -test_dir = f"{TEST_FILES_DIR}/cohp/environments" +TEST_DIR = f"{TEST_FILES_DIR}/cohp/environments" module_dir = os.path.dirname(os.path.abspath(__file__)) @@ -32,231 +32,231 @@ def setUp(self): self.chem_env_lobster1 = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_190.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_190.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), additional_condition=1, ) # all bonds self.chem_env_lobster0 = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_190.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_190.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), additional_condition=0, ) # only cation-cation, anion-anion bonds self.chem_env_lobster5 = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_190.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_190.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), additional_condition=5, ) # only cation-cation bonds self.chem_env_lobster6 = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_190.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_190.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), additional_condition=6, ) # 2,3,4 are not tested so far self.chem_env_lobster2 = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_190.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_190.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), additional_condition=2, ) self.chem_env_lobster3 = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_190.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_190.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), additional_condition=3, ) self.chem_env_lobster4 = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_190.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_190.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), additional_condition=4, ) # search for other testcase where 2,3,4 arrive at different results self.chem_env_lobster0_second = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_353.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_353.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), additional_condition=0, ) self.chem_env_lobster1_second = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_353.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_353.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), additional_condition=1, ) self.chem_env_lobster2_second = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_353.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_353.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), additional_condition=2, ) self.chem_env_lobster5_second = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_353.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_353.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), additional_condition=5, ) self.chem_env_lobster5_second_percentage = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_353.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_353.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), additional_condition=5, perc_strength_ICOHP=1.0, ) self.chem_env_lobster6_second = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_353.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_353.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), additional_condition=6, ) # coop / cobi self.chem_env_lobster1_coop_NaCl = LobsterNeighbors( are_coops=True, - filename_ICOHP=f"{test_dir}/ICOOPLIST.lobster.NaCl.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.NaCl.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOOPLIST.lobster.NaCl.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.NaCl.gz"), additional_condition=1, noise_cutoff=None, ) self.chem_env_lobster1_cobi_NaCl = LobsterNeighbors( are_coops=True, - filename_ICOHP=f"{test_dir}/ICOBILIST.lobster.NaCl.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.NaCl.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOBILIST.lobster.NaCl.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.NaCl.gz"), additional_condition=1, noise_cutoff=None, ) self.chem_env_lobster1_cobi_mp470 = LobsterNeighbors( are_coops=True, - filename_ICOHP=f"{test_dir}/ICOBILIST.lobster.mp_470.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_470.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOBILIST.lobster.mp_470.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_470.gz"), additional_condition=1, ) # TODO: use charge instead of valence self.chem_env_lobster1_charges = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_353.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_353.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), valences_from_charges=True, - filename_CHARGE=f"{test_dir}/CHARGE.lobster.mp-353.gz", + filename_CHARGE=f"{TEST_DIR}/CHARGE.lobster.mp-353.gz", additional_condition=1, ) self.chem_env_lobster1_charges_noisecutoff = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_632319.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_632319.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_632319.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_632319.gz"), valences_from_charges=True, - filename_CHARGE=f"{test_dir}/CHARGE.lobster.mp_632319.gz", + filename_CHARGE=f"{TEST_DIR}/CHARGE.lobster.mp_632319.gz", additional_condition=1, perc_strength_ICOHP=0.05, noise_cutoff=0.1, ) self.chem_env_lobster1_charges_wo_noisecutoff = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_632319.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_632319.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_632319.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_632319.gz"), valences_from_charges=True, - filename_CHARGE=f"{test_dir}/CHARGE.lobster.mp_632319.gz", + filename_CHARGE=f"{TEST_DIR}/CHARGE.lobster.mp_632319.gz", additional_condition=1, perc_strength_ICOHP=0.05, noise_cutoff=None, ) self.chem_env_lobster1_charges_loewdin = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_353.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_353.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), valences_from_charges=True, - filename_CHARGE=f"{test_dir}/CHARGE.lobster.mp-353.gz", + filename_CHARGE=f"{TEST_DIR}/CHARGE.lobster.mp-353.gz", additional_condition=1, which_charge="Loewdin", ) self.chem_env_lobster6_charges_additional_condition = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_353.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_353.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), valences_from_charges=True, - filename_CHARGE=f"{test_dir}/CHARGE.lobster.mp-353.gz", + filename_CHARGE=f"{TEST_DIR}/CHARGE.lobster.mp-353.gz", additional_condition=6, adapt_extremum_to_add_cond=True, ) self.chem_env_lobster5_charges_additional_condition = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_353.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_353.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), valences_from_charges=True, - filename_CHARGE=f"{test_dir}/CHARGE.lobster.mp-353.gz", + filename_CHARGE=f"{TEST_DIR}/CHARGE.lobster.mp-353.gz", additional_condition=5, adapt_extremum_to_add_cond=True, ) self.chem_env_lobster4_charges_additional_condition = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_353.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_353.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), valences_from_charges=True, - filename_CHARGE=f"{test_dir}/CHARGE.lobster.mp-353.gz", + filename_CHARGE=f"{TEST_DIR}/CHARGE.lobster.mp-353.gz", additional_condition=4, adapt_extremum_to_add_cond=True, ) self.chem_env_lobster3_charges_additional_condition = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_353.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_353.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), valences_from_charges=True, - filename_CHARGE=f"{test_dir}/CHARGE.lobster.mp-353.gz", + filename_CHARGE=f"{TEST_DIR}/CHARGE.lobster.mp-353.gz", additional_condition=3, adapt_extremum_to_add_cond=True, ) self.chem_env_lobster2_charges_additional_condition = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_353.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_353.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), valences_from_charges=True, - filename_CHARGE=f"{test_dir}/CHARGE.lobster.mp-353.gz", + filename_CHARGE=f"{TEST_DIR}/CHARGE.lobster.mp-353.gz", additional_condition=2, adapt_extremum_to_add_cond=True, ) self.chem_env_lobster1_charges_additional_condition = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_353.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_353.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), valences_from_charges=True, - filename_CHARGE=f"{test_dir}/CHARGE.lobster.mp-353.gz", + filename_CHARGE=f"{TEST_DIR}/CHARGE.lobster.mp-353.gz", additional_condition=1, adapt_extremum_to_add_cond=True, ) self.chem_env_lobster0_charges_additional_condition = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_353.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_353.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), valences_from_charges=True, - filename_CHARGE=f"{test_dir}/CHARGE.lobster.mp-353.gz", + filename_CHARGE=f"{TEST_DIR}/CHARGE.lobster.mp-353.gz", additional_condition=0, adapt_extremum_to_add_cond=True, ) self.chem_env_lobster0_NaSi = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.NaSi.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.NaSi.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.NaSi.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.NaSi.gz"), valences_from_charges=True, - filename_CHARGE=f"{test_dir}/CHARGE.lobster.NaSi.gz", + filename_CHARGE=f"{TEST_DIR}/CHARGE.lobster.NaSi.gz", additional_condition=0, adapt_extremum_to_add_cond=True, ) @@ -267,8 +267,8 @@ def test_cation_anion_mode_without_ions(self): ): _ = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/../ICOHPLIST.lobster", - structure=Structure.from_file(f"{test_dir}/../POSCAR"), + filename_ICOHP=f"{TEST_DIR}/../ICOHPLIST.lobster", + structure=Structure.from_file(f"{TEST_DIR}/../POSCAR"), valences_from_charges=False, additional_condition=1, ) @@ -277,8 +277,8 @@ def test_cation_anion_mode_without_ions(self): ): _ = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/../ICOHPLIST.lobster", - structure=Structure.from_file(f"{test_dir}/../POSCAR"), + filename_ICOHP=f"{TEST_DIR}/../ICOHPLIST.lobster", + structure=Structure.from_file(f"{TEST_DIR}/../POSCAR"), valences_from_charges=False, additional_condition=1, valences=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], @@ -290,20 +290,20 @@ def test_wrong_additional_correction(self): ): LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_353.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_353.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), valences_from_charges=True, - filename_CHARGE=f"{test_dir}/CHARGE.lobster.mp-353.gz", + filename_CHARGE=f"{TEST_DIR}/CHARGE.lobster.mp-353.gz", additional_condition=10, ) def test_set_limits(self): test = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_353.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_353.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), valences_from_charges=True, - filename_CHARGE=f"{test_dir}/CHARGE.lobster.mp-353.gz", + filename_CHARGE=f"{TEST_DIR}/CHARGE.lobster.mp-353.gz", additional_condition=1, limits=[-100000, 0], ) @@ -330,7 +330,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster0.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), n=0, ) ) @@ -339,7 +339,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster0.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), n=1, ) ) @@ -349,7 +349,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster1.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), n=0, ) ) @@ -358,7 +358,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster1.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), n=1, ) ) @@ -386,7 +386,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster2.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), n=0, ) ) @@ -395,7 +395,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster2.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), n=1, ) ) @@ -405,7 +405,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster3.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), n=0, ) ) @@ -414,7 +414,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster3.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), n=1, ) ) @@ -424,7 +424,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster4.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), n=0, ) ) @@ -433,7 +433,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster4.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), n=1, ) ) @@ -443,7 +443,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster5.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), n=0, ) ) @@ -452,7 +452,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster5.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), n=1, ) ) @@ -462,7 +462,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster6.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), n=0, ) ) @@ -472,7 +472,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster6.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), n=1, ) ) @@ -485,7 +485,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster0_second.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), n=0, ) ) @@ -496,7 +496,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster1_second.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), n=0, ) ) @@ -506,7 +506,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster1_coop_NaCl.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.NaCl.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.NaCl.gz"), n=0, ) ) @@ -516,7 +516,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster1_cobi_NaCl.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.NaCl.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.NaCl.gz"), n=0, ) ) @@ -526,7 +526,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster1_cobi_mp470.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_470.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_470.gz"), n=3, ) ) @@ -537,7 +537,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster2_second.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), n=0, ) ) @@ -546,7 +546,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster2_second.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), n=4, ) ) @@ -557,7 +557,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster5_second.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), n=0, ) ) @@ -566,7 +566,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster5_second.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), n=4, ) ) @@ -576,7 +576,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster6_second.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), n=0, ) ) @@ -585,7 +585,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster6_second.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), n=4, ) ) @@ -595,7 +595,7 @@ def test_get_nn_info(self): assert ( len( self.chem_env_lobster5_second_percentage.get_nn( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), n=0, ) ) @@ -604,26 +604,26 @@ def test_get_nn_info(self): def test_structure_graph(self): sg = self.chem_env_lobster1_second.get_bonded_structure( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz") + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz") ) assert isinstance(sg, StructureGraph) def test_extended_structure_graph(self): self.chem_env_lobsterNaCl = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.NaCl.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.NaCl.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.NaCl.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.NaCl.gz"), valences_from_charges=True, - filename_CHARGE=f"{test_dir}/CHARGE.lobster.NaCl.gz", - filename_blist_sg1=f"{test_dir}/ICOBILIST.lobster.NaCl.gz", - filename_blist_sg2=f"{test_dir}/ICOOPLIST.lobster.NaCl.gz", + filename_CHARGE=f"{TEST_DIR}/CHARGE.lobster.NaCl.gz", + filename_blist_sg1=f"{TEST_DIR}/ICOBILIST.lobster.NaCl.gz", + filename_blist_sg2=f"{TEST_DIR}/ICOOPLIST.lobster.NaCl.gz", add_additional_data_sg=True, id_blist_sg1="icobi", id_blist_sg2="icoop", additional_condition=1, ) sg = self.chem_env_lobsterNaCl.get_bonded_structure( - structure=Structure.from_file(f"{test_dir}/POSCAR.NaCl.gz"), + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.NaCl.gz"), decorate=True, edge_properties=True, weights=True, @@ -639,12 +639,12 @@ def test_raises_extended_structure_graph(self): with pytest.raises(ValueError, match="Algorithm can only work with ICOOPs, ICOBIs"): self.chem_env_lobsterNaCl = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.NaCl.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.NaCl.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.NaCl.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.NaCl.gz"), valences_from_charges=True, - filename_CHARGE=f"{test_dir}/CHARGE.lobster.NaCl.gz", - filename_blist_sg1=f"{test_dir}/ICOBILIST.lobster.NaCl.gz", - filename_blist_sg2=f"{test_dir}/ICOOPLIST.lobster.NaCl.gz", + filename_CHARGE=f"{TEST_DIR}/CHARGE.lobster.NaCl.gz", + filename_blist_sg1=f"{TEST_DIR}/ICOBILIST.lobster.NaCl.gz", + filename_blist_sg2=f"{TEST_DIR}/ICOOPLIST.lobster.NaCl.gz", add_additional_data_sg=True, id_blist_sg1="icopppp", id_blist_sg2="icoop", @@ -653,7 +653,7 @@ def test_raises_extended_structure_graph(self): def test_order_parameter(self): assert self.chem_env_lobster1_second.get_local_order_parameters( - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_353.gz"), n=0 + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_353.gz"), n=0 )["linear"] == approx(1.0) def test_get_structure_environments(self): @@ -703,8 +703,8 @@ def test_get_sum_icohps_between_neighbors_of_atom(self): chemenv_here = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp-7000.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp-7000.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp-7000.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp-7000.gz"), additional_condition=1, ) assert len(chemenv_here.get_info_icohps_between_neighbors(isites=[0])[4]) == 6 @@ -737,11 +737,11 @@ def test_get_plot_label(self): def test_get_info_cohps_to_neighbors(self): chem_env_lobster1 = LobsterNeighbors( are_coops=False, - filename_ICOHP=f"{test_dir}/ICOHPLIST.lobster.mp_190_2.gz", - structure=Structure.from_file(f"{test_dir}/POSCAR.mp_190.gz"), + filename_ICOHP=f"{TEST_DIR}/ICOHPLIST.lobster.mp_190_2.gz", + structure=Structure.from_file(f"{TEST_DIR}/POSCAR.mp_190.gz"), additional_condition=1, ) - cohpcar_lobster_mp_190 = f"{test_dir}/COHPCAR.lobster.mp-190.gz" + cohpcar_lobster_mp_190 = f"{TEST_DIR}/COHPCAR.lobster.mp-190.gz" plot_label, summed_cohpcar_mp_190 = chem_env_lobster1.get_info_cohps_to_neighbors( path_to_COHPCAR=cohpcar_lobster_mp_190, isites=[0], @@ -780,14 +780,14 @@ def test_get_info_cohps_to_neighbors(self): assert summed_cohpcar_mp_190_Te is None plot_label, _summed_cohpcar_NaSi = self.chem_env_lobster0_NaSi.get_info_cohps_to_neighbors( - path_to_COHPCAR=f"{test_dir}/COHPCAR.lobster.NaSi.gz", + path_to_COHPCAR=f"{TEST_DIR}/COHPCAR.lobster.NaSi.gz", isites=[8], onlycation_isites=False, only_bonds_to=["Na"], ) assert plot_label == "1 x Na-Si (per bond)" info = self.chem_env_lobster0_NaSi.get_info_cohps_to_neighbors( - path_to_COHPCAR=f"{test_dir}/COHPCAR.lobster.NaSi.gz", + path_to_COHPCAR=f"{TEST_DIR}/COHPCAR.lobster.NaSi.gz", isites=[8], onlycation_isites=False, only_bonds_to=["Si"], diff --git a/tests/io/qchem/test_outputs.py b/tests/io/qchem/test_outputs.py index fa5b154fcba..30c40fafd48 100644 --- a/tests/io/qchem/test_outputs.py +++ b/tests/io/qchem/test_outputs.py @@ -278,22 +278,22 @@ def generate_multi_job_dict(): dumpfn(multi_job_dict, "multi_job.json") def _test_property(self, key, single_outs, multi_outs): - for name, out_data in single_outs.items(): + for filename, out_data in single_outs.items(): try: - assert out_data.get(key) == single_job_dict[name].get(key) + assert out_data.get(key) == single_job_dict[filename].get(key) except ValueError: try: - assert_array_equal(out_data.get(key), single_job_dict[name].get(key)) + assert_array_equal(out_data.get(key), single_job_dict[filename].get(key)) except AssertionError: - raise RuntimeError("Issue with file: " + name + " Exiting...") + raise RuntimeError(f"Issue with {filename=} Exiting...") except AssertionError: - raise RuntimeError("Issue with file: " + name + " Exiting...") - for name, outputs in multi_outs.items(): + raise RuntimeError(f"Issue with {filename=} Exiting...") + for filename, outputs in multi_outs.items(): for ii, sub_output in enumerate(outputs): try: - assert sub_output.data.get(key) == multi_job_dict[name][ii].get(key) + assert sub_output.data.get(key) == multi_job_dict[filename][ii].get(key) except ValueError: - assert_array_equal(sub_output.data.get(key), multi_job_dict[name][ii].get(key)) + assert_array_equal(sub_output.data.get(key), multi_job_dict[filename][ii].get(key)) @unittest.skipIf(openbabel is None, "OpenBabel not installed.") def test_all(self): diff --git a/tests/io/qchem/test_utils.py b/tests/io/qchem/test_utils.py index 49de884988f..8f3038974bd 100644 --- a/tests/io/qchem/test_utils.py +++ b/tests/io/qchem/test_utils.py @@ -15,7 +15,7 @@ logger = logging.getLogger(__name__) -test_dir = f"{TEST_FILES_DIR}/molecules/new_qchem_files" +TEST_DIR = f"{TEST_FILES_DIR}/molecules/new_qchem_files" class TestUtil(PymatgenTest): @@ -35,11 +35,11 @@ def test_lower_and_check_unique(self): lower_and_check_unique(d4) def test_process_parsed_hess(self): - with zopen(f"{test_dir}/parse_hess/132.0", mode="rb") 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: + 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) diff --git a/tests/io/test_atat.py b/tests/io/test_atat.py index 019c11e02f7..aa3bc43a100 100644 --- a/tests/io/test_atat.py +++ b/tests/io/test_atat.py @@ -7,7 +7,7 @@ from pymatgen.io.atat import Mcsqs from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -test_dir = f"{TEST_FILES_DIR}/mcsqs" +TEST_DIR = f"{TEST_FILES_DIR}/mcsqs" class TestAtat(PymatgenTest): @@ -87,10 +87,10 @@ def test_mcsqs_export(self): def test_mcsqs_cif_nacl(self): # CIF file from str2cif (utility distributed with atat) - struct_from_cif = Structure.from_file(f"{test_dir}/bestsqs_nacl.cif") + struct_from_cif = Structure.from_file(f"{TEST_DIR}/bestsqs_nacl.cif") # output file directly from mcsqs - struct_from_out = Structure.from_file(f"{test_dir}/bestsqs_nacl.out") + struct_from_out = Structure.from_file(f"{TEST_DIR}/bestsqs_nacl.out") assert struct_from_cif.matches(struct_from_out) assert_allclose( @@ -101,10 +101,10 @@ def test_mcsqs_cif_nacl(self): def test_mcsqs_cif_pzt(self): # CIF file from str2cif (utility distributed with atat) - struct_from_cif = Structure.from_file(f"{test_dir}/bestsqs_pzt.cif") + struct_from_cif = Structure.from_file(f"{TEST_DIR}/bestsqs_pzt.cif") # output file directly from mcsqs - struct_from_out = Structure.from_file(f"{test_dir}/bestsqs_pzt.out") + struct_from_out = Structure.from_file(f"{TEST_DIR}/bestsqs_pzt.out") assert struct_from_cif.matches(struct_from_out) assert_allclose( diff --git a/tests/io/test_gaussian.py b/tests/io/test_gaussian.py index f209100c6b6..e3330cee8b5 100644 --- a/tests/io/test_gaussian.py +++ b/tests/io/test_gaussian.py @@ -10,7 +10,7 @@ from pymatgen.io.gaussian import GaussianInput, GaussianOutput from pymatgen.util.testing import TEST_FILES_DIR -test_dir = f"{TEST_FILES_DIR}/molecules" +TEST_DIR = f"{TEST_FILES_DIR}/molecules" class TestGaussianInput(unittest.TestCase): @@ -95,14 +95,14 @@ def test_from_cart_coords(self): assert gau.input_parameters["EPS"] == "12" def test_from_file(self): - filepath = f"{test_dir}/MethylPyrrolidine_drawn.gjf" + filepath = f"{TEST_DIR}/MethylPyrrolidine_drawn.gjf" gau = GaussianInput.from_file(filepath) assert gau.molecule.composition.formula == "H11 C5 N1" assert "opt" in gau.route_parameters assert gau.route_parameters["geom"] == "connectivity" assert gau.functional == "b3lyp" assert gau.basis_set == "6-311+g(d,p)" - filepath = f"{test_dir}/g305_hb.txt" + filepath = f"{TEST_DIR}/g305_hb.txt" with open(filepath) as f: txt = f.read() tokens = txt.split("--link1--") @@ -202,7 +202,7 @@ def test_multiple_parameters(self): This test makes sure that input files with multi-parameter keywords and route cards with multiple lines can be parsed accurately. """ - filepath = f"{test_dir}/l-cysteine.inp" + filepath = f"{TEST_DIR}/l-cysteine.inp" route = { "test": None, "integral": {"grid": "UltraFine"}, @@ -255,7 +255,7 @@ class TestGaussianOutput(unittest.TestCase): # TODO: Add unittest for PCM type output. def setUp(self): - self.gau_out = GaussianOutput(f"{test_dir}/methane.log") + self.gau_out = GaussianOutput(f"{TEST_DIR}/methane.log") def test_resume(self): resume = self.gau_out.resumes[0] @@ -292,7 +292,7 @@ def test_props(self): assert gau.num_basis_func == 17 assert gau.is_spin is False - ch2o_co2 = GaussianOutput(f"{test_dir}/CH2O_CO2.log") + ch2o_co2 = GaussianOutput(f"{TEST_DIR}/CH2O_CO2.log") assert len(ch2o_co2.frequencies) == 2 assert len(ch2o_co2.frequencies[0]) == 6 assert len(ch2o_co2.frequencies[1]) == 4 @@ -319,7 +319,7 @@ def test_props(self): assert ch2o_co2.frequencies[1][3]["symmetry"] == "SGU" assert ch2o_co2.eigenvalues[Spin.up][3] == -1.18394 - h2o = GaussianOutput(f"{test_dir}/H2O_gau_vib.out") + h2o = GaussianOutput(f"{TEST_DIR}/H2O_gau_vib.out") assert len(h2o.frequencies[0]) == 3 assert h2o.frequencies[0][0]["frequency"] == 1662.8033 assert h2o.frequencies[0][1]["symmetry"] == "A'" @@ -338,7 +338,7 @@ def test_props(self): ] def test_pop(self): - gau = GaussianOutput(f"{test_dir}/H2O_gau.out") + gau = GaussianOutput(f"{TEST_DIR}/H2O_gau.out") assert gau.num_basis_func == 13 assert gau.electrons == (5, 5) assert gau.is_spin @@ -382,19 +382,19 @@ def test_pop(self): assert gau.atom_basis_labels[0] == ["1S", "2S", "2PX", "2PY", "2PZ", "3S", "3PX", "3PY", "3PZ"] assert gau.atom_basis_labels[2] == ["1S", "2S"] - gau = GaussianOutput(f"{test_dir}/H2O_gau_vib.out") + gau = GaussianOutput(f"{TEST_DIR}/H2O_gau_vib.out") assert gau.bond_orders[(0, 1)] == 0.7582 assert gau.bond_orders[(1, 2)] == 0.0002 def test_scan(self): - gau = GaussianOutput(f"{test_dir}/so2_scan.log") + gau = GaussianOutput(f"{TEST_DIR}/so2_scan.log") d = gau.read_scan() assert approx(d["energies"][-1]) == -548.02102 assert len(d["coords"]) == 1 assert len(d["energies"]) == len(gau.energies) assert len(d["energies"]) == 21 - gau = GaussianOutput(f"{test_dir}/so2_scan_opt.log") + gau = GaussianOutput(f"{TEST_DIR}/so2_scan_opt.log") assert len(gau.opt_structures) == 21 d = gau.read_scan() assert approx(d["energies"][-1]) == -548.02336 @@ -402,7 +402,7 @@ def test_scan(self): assert len(d["energies"]) == 21 assert approx(d["coords"]["DSO"][6]) == 1.60000 assert approx(d["coords"]["ASO"][2]) == 124.01095 - gau = GaussianOutput(f"{test_dir}/H2O_scan_G16.out") + gau = GaussianOutput(f"{TEST_DIR}/H2O_scan_G16.out") assert len(gau.opt_structures) == 21 coords = [ [0.000000, 0.000000, 0.094168], @@ -419,7 +419,7 @@ def test_scan(self): def test_geo_opt(self): """Test an optimization where no "input orientation" is outputted.""" - gau = GaussianOutput(f"{test_dir}/acene-n_gaussian09_opt.out") + gau = GaussianOutput(f"{TEST_DIR}/acene-n_gaussian09_opt.out") assert approx(gau.energies[-1]) == -1812.58399675 assert len(gau.structures) == 6 # Test the first 3 atom coordinates @@ -431,7 +431,7 @@ def test_geo_opt(self): assert gau.opt_structures[-1].cart_coords[:3].tolist() == coords def test_td(self): - gau = GaussianOutput(f"{test_dir}/so2_td.log") + gau = GaussianOutput(f"{TEST_DIR}/so2_td.log") transitions = gau.read_excitation_energies() assert len(transitions) == 4 assert transitions[0] == approx((3.9281, 315.64, 0.0054)) @@ -441,7 +441,7 @@ def test_multiple_parameters(self): This test makes sure that input files with multi-parameter keywords and route cards with multiple lines can be parsed accurately. """ - filepath = f"{test_dir}/l-cysteine.out" + filepath = f"{TEST_DIR}/l-cysteine.out" route = { "test": None, "integral": {"grid": "UltraFine"}, @@ -461,7 +461,7 @@ def test_multiple_parameters_with_multiple_completed_lines(self): This test makes sure that input files with multi-parameter keywords and route cards with multiple completed lines which are split by line break parse correctly. """ - filepath = f"{test_dir}/EC.log.gz" + filepath = f"{TEST_DIR}/EC.log.gz" route_params = { "opt": {"loose": None, "maxcyc": "400"}, "freq": None, diff --git a/tests/io/test_lmto.py b/tests/io/test_lmto.py index 44fd56d86f3..2b1150e5ef2 100644 --- a/tests/io/test_lmto.py +++ b/tests/io/test_lmto.py @@ -19,13 +19,13 @@ __date__ = "Nov 30, 2017" -test_dir = f"{TEST_FILES_DIR}/cohp" +TEST_DIR = f"{TEST_FILES_DIR}/cohp" module_dir = os.path.dirname(os.path.abspath(__file__)) class TestCtrl(PymatgenTest): def setUp(self): - os.chdir(test_dir) + os.chdir(TEST_DIR) self.ref_bise = LMTOCtrl.from_file(filename="CTRL.BiSe") self.ref_fe = LMTOCtrl.from_file() @@ -49,7 +49,7 @@ def test_read_write(self): class TestCopl(PymatgenTest): def setUp(self): - os.chdir(test_dir) + os.chdir(TEST_DIR) self.copl_bise = LMTOCopl("COPL.BiSe") self.copl_bise_eV = LMTOCopl(filename="COPL.BiSe", to_eV=True) self.copl_fe = LMTOCopl() diff --git a/tests/io/test_nwchem.py b/tests/io/test_nwchem.py index e10ffc0c107..96a5ea41730 100644 --- a/tests/io/test_nwchem.py +++ b/tests/io/test_nwchem.py @@ -10,7 +10,7 @@ from pymatgen.io.nwchem import NwInput, NwInputError, NwOutput, NwTask from pymatgen.util.testing import TEST_FILES_DIR -test_dir = f"{TEST_FILES_DIR}/nwchem" +TEST_DIR = f"{TEST_FILES_DIR}/nwchem" coords = [ [0.000000, 0.000000, 0.000000], @@ -327,7 +327,7 @@ def test_as_from_dict(self): json.dumps(d) def test_from_str_and_file(self): - nwi = NwInput.from_file(f"{test_dir}/ch4.nw") + nwi = NwInput.from_file(f"{TEST_DIR}/ch4.nw") assert nwi.tasks[0].theory == "dft" assert nwi.memory_options == "total 1000 mb stack 400 mb" assert nwi.tasks[0].basis_set["C"] == "6-31++G*" @@ -398,8 +398,8 @@ def test_from_str_and_file(self): class TestNwOutput(unittest.TestCase): def test_read(self): - nwo = NwOutput(f"{test_dir}/CH4.nwout") - nwo_cosmo = NwOutput(f"{test_dir}/N2O4.nwout") + nwo = NwOutput(f"{TEST_DIR}/CH4.nwout") + nwo_cosmo = NwOutput(f"{TEST_DIR}/N2O4.nwout") assert nwo[0]["charge"] == 0 assert nwo[-1]["charge"] == -1 @@ -437,22 +437,22 @@ def test_read(self): assert approx(ea, abs=1e-3) == -14.997877958701338 assert nwo[4]["basis_set"]["C"]["description"] == "6-311++G**" - nwo = NwOutput(f"{test_dir}/H4C3O3_1.nwout") + nwo = NwOutput(f"{TEST_DIR}/H4C3O3_1.nwout") assert nwo[-1]["has_error"] assert nwo[-1]["errors"][0] == "Bad convergence" - nwo = NwOutput(f"{test_dir}/CH3CH2O.nwout") + nwo = NwOutput(f"{TEST_DIR}/CH3CH2O.nwout") assert nwo[-1]["has_error"] assert nwo[-1]["errors"][0] == "Bad convergence" - nwo = NwOutput(f"{test_dir}/C1N1Cl1_1.nwout") + nwo = NwOutput(f"{TEST_DIR}/C1N1Cl1_1.nwout") assert nwo[-1]["has_error"] assert nwo[-1]["errors"][0] == "autoz error" - nwo = NwOutput(f"{test_dir}/anthrachinon_wfs_16_ethyl.nwout") + nwo = NwOutput(f"{TEST_DIR}/anthrachinon_wfs_16_ethyl.nwout") assert nwo[-1]["has_error"] assert nwo[-1]["errors"][0] == "Geometry optimization failed" - nwo = NwOutput(f"{test_dir}/anthrachinon_wfs_15_carboxyl.nwout") + nwo = NwOutput(f"{TEST_DIR}/anthrachinon_wfs_15_carboxyl.nwout") assert nwo[1]["frequencies"][0][0] == -70.47 assert len(nwo[1]["frequencies"][0][1]) == 27 assert nwo[1]["frequencies"][-1][0] == 3696.74 @@ -462,7 +462,7 @@ def test_read(self): assert nwo[1]["normal_frequencies"][1][1][-1] == (0.00056, 0.00042, 0.06781) def test_parse_tddft(self): - nwo = NwOutput(f"{test_dir}/phen_tddft.log") + nwo = NwOutput(f"{TEST_DIR}/phen_tddft.log") roots = nwo.parse_tddft() assert len(roots["singlet"]) == 20 assert roots["singlet"][0]["energy"] == approx(3.9291) @@ -470,7 +470,7 @@ def test_parse_tddft(self): assert roots["singlet"][1]["osc_strength"] == approx(0.00177) def test_get_excitation_spectrum(self): - nwo = NwOutput(f"{test_dir}/phen_tddft.log") + nwo = NwOutput(f"{TEST_DIR}/phen_tddft.log") spectrum = nwo.get_excitation_spectrum() assert len(spectrum.x) == 2000 assert spectrum.x[0] == approx(1.9291) diff --git a/tests/io/test_packmol.py b/tests/io/test_packmol.py index 8d9688ff592..66aaac7dd5a 100644 --- a/tests/io/test_packmol.py +++ b/tests/io/test_packmol.py @@ -13,7 +13,7 @@ from pymatgen.io.packmol import PackmolBoxGen from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -test_dir = f"{TEST_FILES_DIR}/packmol" +TEST_DIR = f"{TEST_FILES_DIR}/packmol" if which("packmol") is None: @@ -42,7 +42,6 @@ [10.203, 7.604, 12.673], ] water_atoms = ["H", "H", "O"] - water = Molecule(water_atoms, water_coords) @@ -65,8 +64,8 @@ def test_packmol_with_str(self): """Test coords input as strings.""" pw = PackmolBoxGen().get_input_set( molecules=[ - {"name": "EMC", "number": 10, "coords": f"{test_dir}/subdir with spaces/EMC.xyz"}, - {"name": "LiTFSi", "number": 20, "coords": f"{test_dir}/LiTFSi.xyz"}, + {"name": "EMC", "number": 10, "coords": f"{TEST_DIR}/subdir with spaces/EMC.xyz"}, + {"name": "LiTFSi", "number": 20, "coords": f"{TEST_DIR}/LiTFSi.xyz"}, ], ) pw.write_input(self.tmp_path) @@ -77,8 +76,8 @@ def test_packmol_with_str(self): def test_packmol_with_path(self): """Test coords input as Path. Use a subdirectory with spaces.""" - p1 = Path(f"{test_dir}/subdir with spaces/EMC.xyz") - p2 = Path(f"{test_dir}/LiTFSi.xyz") + p1 = Path(f"{TEST_DIR}/subdir with spaces/EMC.xyz") + p2 = Path(f"{TEST_DIR}/LiTFSi.xyz") pw = PackmolBoxGen().get_input_set( molecules=[ {"name": "EMC", "number": 10, "coords": p1}, diff --git a/tests/io/test_phonopy.py b/tests/io/test_phonopy.py index 8a7d7fc176a..e507fadfaf5 100644 --- a/tests/io/test_phonopy.py +++ b/tests/io/test_phonopy.py @@ -37,12 +37,12 @@ print(exc) Phonopy = None -test_dir = f"{TEST_FILES_DIR}/phonopy" +TEST_DIR = f"{TEST_FILES_DIR}/phonopy" class TestPhonopyParser(PymatgenTest): def test_get_ph_bs(self): - ph_bs = get_ph_bs_symm_line(f"{test_dir}/NaCl_band.yaml", has_nac=True) + ph_bs = get_ph_bs_symm_line(f"{TEST_DIR}/NaCl_band.yaml", has_nac=True) assert ph_bs.bands[1][10] == approx(0.7753555184) assert ph_bs.bands[5][100] == approx(5.2548379776) @@ -71,7 +71,7 @@ def test_get_ph_bs(self): assert ph_bs.get_nac_eigendisplacements_along_dir([1, 0, 1]) is None def test_get_ph_dos(self): - dos = get_ph_dos(f"{test_dir}/NaCl_total_dos.dat") + dos = get_ph_dos(f"{TEST_DIR}/NaCl_total_dos.dat") assert dos.densities[15] == approx(0.0001665998) assert dos.frequencies[20] == approx(0.0894965119) @@ -81,8 +81,8 @@ def test_get_ph_dos(self): def test_get_complete_dos(self): cdos = get_complete_ph_dos( - f"{test_dir}/NaCl_partial_dos.dat", - f"{test_dir}/NaCl_phonopy.yaml", + f"{TEST_DIR}/NaCl_partial_dos.dat", + f"{TEST_DIR}/NaCl_phonopy.yaml", ) site_Na = cdos.structure[0] site_Cl = cdos.structure[1] @@ -125,7 +125,7 @@ def test_structure_conversion(self): @unittest.skipIf(Phonopy is None, "Phonopy not present") class TestGetDisplacedStructures(PymatgenTest): def test_get_displaced_structures(self): - pmg_s = Structure.from_file(f"{test_dir}/POSCAR-unitcell", primitive=False) + pmg_s = Structure.from_file(f"{TEST_DIR}/POSCAR-unitcell", primitive=False) supercell_matrix = [[2, 0, 0], [0, 1, 0], [0, 0, 2]] structures = get_displaced_structures(pmg_structure=pmg_s, atom_disp=0.01, supercell_matrix=supercell_matrix) @@ -157,7 +157,7 @@ def test_get_displaced_structures(self): @unittest.skipIf(Phonopy is None, "Phonopy not present") class TestPhonopyFromForceConstants(unittest.TestCase): def setUp(self) -> None: - test_path = Path(test_dir) + test_path = Path(TEST_DIR) structure_file = test_path / "POSCAR-NaCl" fc_file = test_path / "FORCE_CONSTANTS" diff --git a/tests/io/xtb/test_inputs.py b/tests/io/xtb/test_inputs.py index 7b5d82620be..d82e5527c5f 100644 --- a/tests/io/xtb/test_inputs.py +++ b/tests/io/xtb/test_inputs.py @@ -8,8 +8,8 @@ __copyright__ = "Copyright 2020, The Materials Project" __version__ = "0.1" -test_dir = f"{TEST_FILES_DIR}/xtb/sample_CREST_output" -expected_dir = f"{TEST_FILES_DIR}/xtb/expected_output" +TEST_DIR = f"{TEST_FILES_DIR}/xtb/sample_CREST_output" +EXPECTED_DIR = f"{TEST_FILES_DIR}/xtb/expected_output" class TestCRESTInput(PymatgenTest): @@ -32,9 +32,9 @@ def test_coordinates_file(self): def test_constraints_file(self): constraints = {"atoms": [8, 1, 2], "force_constant": 0.5} - mol = Molecule.from_file(f"{test_dir}/crest_in.xyz") + mol = Molecule.from_file(f"{TEST_DIR}/crest_in.xyz") cin = CRESTInput(molecule=mol, constraints=constraints) - with open(f"{expected_dir}/expected_constrains.txt") as f: + with open(f"{EXPECTED_DIR}/expected_constrains.txt") as f: exp_con = f.read() assert ( exp_con.strip() diff --git a/tests/io/xtb/test_outputs.py b/tests/io/xtb/test_outputs.py index 0773f343fc6..b9ad5dfabaa 100644 --- a/tests/io/xtb/test_outputs.py +++ b/tests/io/xtb/test_outputs.py @@ -19,8 +19,8 @@ __copyright__ = "Copyright 2020, The Materials Project" __version__ = "0.1" -test_dir = f"{TEST_FILES_DIR}/xtb/sample_CREST_output" -expected_dir = f"{TEST_FILES_DIR}/xtb/expected_output" +TEST_DIR = f"{TEST_FILES_DIR}/xtb/sample_CREST_output" +EXPECTED_DIR = f"{TEST_FILES_DIR}/xtb/expected_output" class TestCRESTOutput(PymatgenTest): @@ -33,15 +33,15 @@ def test_all(self): expected_cmd_options = {"g": "H2O", "c": "2"} expected_energies = [["-13.66580"] * 10, ["-13.66479"] * 27] expected_sorted_structures = [[], []] - for filepath in os.listdir(expected_dir): + for filepath in os.listdir(EXPECTED_DIR): if filepath.endswith("xyz") and "_r" in filepath: n_conf = int(filepath.split("_")[0][-1]) n_rot = int(filepath.split("_")[1].split(".")[0][-1]) - mol = Molecule.from_file(os.path.join(expected_dir, filepath)) + mol = Molecule.from_file(os.path.join(EXPECTED_DIR, filepath)) expected_sorted_structures[n_conf].insert(n_rot, mol) - crest_out = CRESTOutput(output_filename="crest_out.out", path=test_dir) - exp_best = Molecule.from_file(f"{expected_dir}/expected_crest_best.xyz") + crest_out = CRESTOutput(output_filename="crest_out.out", path=TEST_DIR) + exp_best = Molecule.from_file(f"{EXPECTED_DIR}/expected_crest_best.xyz") for i, c in enumerate(crest_out.sorted_structures_energies): for j, r in enumerate(c): if openbabel: diff --git a/tests/symmetry/test_analyzer.py b/tests/symmetry/test_analyzer.py index e0df1a8c292..d8216cf3d21 100644 --- a/tests/symmetry/test_analyzer.py +++ b/tests/symmetry/test_analyzer.py @@ -13,7 +13,7 @@ from pymatgen.symmetry.structure import SymmetrizedStructure from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -test_dir_mol = f"{TEST_FILES_DIR}/molecules" +TEST_DIR = f"{TEST_FILES_DIR}/molecules" class TestSpacegroupAnalyzer(PymatgenTest): @@ -471,7 +471,7 @@ def test_spherical(self): pg_analyzer = PointGroupAnalyzer(PF6) assert pg_analyzer.sch_symbol == "Oh" assert len(pg_analyzer.get_pointgroup()) == 48 - mol = Molecule.from_file(f"{test_dir_mol}/c60.xyz") + mol = Molecule.from_file(f"{TEST_DIR}/c60.xyz") pg_analyzer = PointGroupAnalyzer(mol) assert pg_analyzer.sch_symbol == "Ih" @@ -492,7 +492,7 @@ def test_spherical(self): assert pg_analyzer.sch_symbol == "Oh" def test_tricky(self): - mol = Molecule.from_file(f"{test_dir_mol}/dh.xyz") + mol = Molecule.from_file(f"{TEST_DIR}/dh.xyz") pg_analyzer = PointGroupAnalyzer(mol, 0.1) assert pg_analyzer.sch_symbol == "D*h" @@ -546,7 +546,7 @@ def test_cyclic(self): pg_analyzer = PointGroupAnalyzer(NH3) assert pg_analyzer.sch_symbol == "C3v" assert len(pg_analyzer.get_pointgroup()) == 6 - cs2 = Molecule.from_file(f"{test_dir_mol}/Carbon_Disulfide.xyz") + cs2 = Molecule.from_file(f"{TEST_DIR}/Carbon_Disulfide.xyz") pg_analyzer = PointGroupAnalyzer(cs2, eigen_tolerance=0.001) assert pg_analyzer.sch_symbol == "C2v" @@ -557,7 +557,7 @@ def test_dihedral(self): pg_analyzer = PointGroupAnalyzer(BF3) assert pg_analyzer.sch_symbol == "D3h" assert len(pg_analyzer.get_pointgroup()) == 12 - mol = Molecule.from_file(f"{test_dir_mol}/b12h12.xyz") + mol = Molecule.from_file(f"{TEST_DIR}/b12h12.xyz") pg_analyzer = PointGroupAnalyzer(mol) assert pg_analyzer.sch_symbol == "Ih" diff --git a/tests/symmetry/test_kpath_lm.py b/tests/symmetry/test_kpath_lm.py index 5c6e6b2001b..baa020b3715 100644 --- a/tests/symmetry/test_kpath_lm.py +++ b/tests/symmetry/test_kpath_lm.py @@ -10,8 +10,6 @@ from pymatgen.symmetry.kpath import KPathLatimerMunro from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -test_dir_structs = TEST_FILES_DIR - class TestKPathLatimerMunro(PymatgenTest): def test_kpath_generation(self): @@ -46,7 +44,7 @@ def test_kpath_generation(self): struct = Structure.from_spacegroup(sg_num, lattice, species, coords) _ = KPathLatimerMunro(struct) # Throws error if something doesn't work, causing test to fail. - struct_file_path = f"{test_dir_structs}/AgO_kpath_test.cif" + struct_file_path = f"{TEST_FILES_DIR}/AgO_kpath_test.cif" struct = Structure.from_file(struct_file_path) _ = KPathLatimerMunro(struct) # Throws error if something doesn't work, causing test to fail. @@ -85,7 +83,7 @@ def test_kpath_acentered(self): ) def test_magnetic_kpath_generation(self): - struct_file_path = f"{test_dir_structs}/LaMnO3_magnetic.mcif" + struct_file_path = f"{TEST_FILES_DIR}/LaMnO3_magnetic.mcif" struct = Structure.from_file(struct_file_path) mga = CollinearMagneticStructureAnalyzer(struct) col_spin_orig = mga.get_structure_with_spin() diff --git a/tests/symmetry/test_kpath_sc.py b/tests/symmetry/test_kpath_sc.py index 76025c95cca..0b7863c737f 100644 --- a/tests/symmetry/test_kpath_sc.py +++ b/tests/symmetry/test_kpath_sc.py @@ -7,7 +7,7 @@ from pymatgen.symmetry.kpath import KPathSetyawanCurtarolo from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest -test_dir_structs = f"{TEST_FILES_DIR}/space_group_structs" +TEST_DIR = f"{TEST_FILES_DIR}/space_group_structs" class TestBandStructureSC(PymatgenTest): @@ -42,7 +42,7 @@ def test_kpath_generation(self): struct = Structure.from_spacegroup(sg_num, lattice, species, coords) _ = KPathSetyawanCurtarolo(struct) # Throws error if something doesn't work, causing test to fail. - struct_file_path = f"{test_dir_structs}/ICSD_170.cif" + struct_file_path = f"{TEST_DIR}/ICSD_170.cif" struct = Structure.from_file(struct_file_path) hkp = KPathSetyawanCurtarolo(struct) assert hkp.name == "MCLC5" diff --git a/tests/symmetry/test_site_symmetries.py b/tests/symmetry/test_site_symmetries.py index e77f535544f..8cc3db58f0e 100644 --- a/tests/symmetry/test_site_symmetries.py +++ b/tests/symmetry/test_site_symmetries.py @@ -36,7 +36,7 @@ def setUp(self): # return obj.tolist() # raise TypeError(f"Object of type {obj.__class__.__name__} is not JSON serializable") - # with gzip.open(f"{test_dir}/point_ops.json.gz", mode="wt") as file: + # with gzip.open(f"{TEST_FILES}/point_ops.json.gz", mode="wt") as file: # json.dump(self.point_ops, file, default=handler) def test_get_site_symmetries(self): diff --git a/tests/util/test_provenance.py b/tests/util/test_provenance.py index da5f6124ec1..74b044c2dec 100644 --- a/tests/util/test_provenance.py +++ b/tests/util/test_provenance.py @@ -47,7 +47,7 @@ def setUp(self): "\n year = {2013}\n}" ) repeat = "REPEAT" * 10000 - self.superlong = "@misc{SuperLong,\ntitle = {{" + repeat + "}}}" + self.superlong = f"@misc{{SuperLong,\ntitle = {{{repeat}}}}}" self.unicode_title = "@misc{Unicode_Title,\ntitle = {{A \u73ab is a rose}}}" self.junk = "This is junk text, not a BibTeX reference"