Skip to content

Commit 668fa57

Browse files
DanielYang59janosh
andauthored
Clean up test files: dedicated VASP directories, xyz, mcif, cssr, exciting, wannier90 (materialsproject#3681)
* relocate fixture dir: absorption * relocate dir: absorption * relocate `BTO_221_99_polarization` dir * remove unused `chgden` * remove unused `defect` * relocate `fe_monomer` * relocate * relocate `fake_potcars` * Reapply "relocate fake_potcars" This reverts commit 61d6cd3. * relocate `grid_data_files` * relocate `kpoints_opt` * relocate `neb_analysis` * fix path typo * remove unused `path_finder` * relocate `relaxation` * relocate `reproduce_eps` * fix same typo again * fix neb file path * relocate `scan_relaxation` * relocate `static_silicon` * remove unused `Zr_Vasprun` * relocate `thermal_displacement_matrices` * remove unused `ion_placer` from qchem * relocate VASP output WSWQ * remove unused file `sio2.pw.in` * relocate fiesta file * relocate some `xyz` files * relocate `exciting` files * relocate cssr files * relocate `wannier90`files * relocate multiple mcif files * try gzip vasprun.xml in vasp fixtures * try removing skip `matgl` * Revert "try removing skip `matgl`" This reverts commit 27a4eeb. * decompress vasprun for optics * relocate a mcif file * relocate gulp and remove moved mcif * create dir for `borg` * create dedicated `borg` test dir * removed unnecessary self. * fix path and use stronger assert * revert vasprun to "vasp run" * add type hints --------- Co-authored-by: Janosh Riebesell <[email protected]>
1 parent 910e571 commit 668fa57

File tree

176 files changed

+143
-265022
lines changed

Some content is hidden

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

176 files changed

+143
-265022
lines changed

dev_scripts/potcar_scrambler.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from pymatgen.core import SETTINGS
1313
from pymatgen.io.vasp import Potcar, PotcarSingle
1414
from pymatgen.io.vasp.sets import _load_yaml_config
15+
from pymatgen.util.testing import VASP_IN_DIR
1516

1617

1718
class PotcarScrambler:
@@ -180,7 +181,7 @@ def potcar_cleanser():
180181
and freely shared by VASP)
181182
"""
182183

183-
search_dir = "../tests/files/fake_potcars/real_potcars/"
184+
search_dir = f"{VASP_IN_DIR}/fake_potcars/real_potcars/"
184185
rebase_dir = search_dir.replace("real", "fake")
185186
potcars_to_cleanse = glob(f"{search_dir}/**/POTCAR*", recursive=True)
186187

pymatgen/apps/borg/queen.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
import logging
1010
import os
1111
from multiprocessing import Manager, Pool
12+
from typing import TYPE_CHECKING
1213

1314
from monty.io import zopen
1415
from monty.json import MontyDecoder, MontyEncoder
1516

17+
if TYPE_CHECKING:
18+
from pathlib import Path
19+
1620
logger = logging.getLogger("BorgQueen")
1721

1822

@@ -60,33 +64,33 @@ def parallel_assimilate(self, rootpath):
6064
status["count"] = 0
6165
status["total"] = len(valid_paths)
6266
logger.info(f"{len(valid_paths)} valid paths found.")
63-
with Pool(self._num_drones) as p:
64-
p.map(
67+
with Pool(self._num_drones) as pool:
68+
pool.map(
6569
order_assimilation,
6670
((path, self._drone, data, status) for path in valid_paths),
6771
)
68-
for d in data:
69-
self._data.append(json.loads(d, cls=MontyDecoder))
72+
for string in data:
73+
self._data.append(json.loads(string, cls=MontyDecoder))
7074

71-
def serial_assimilate(self, rootpath):
75+
def serial_assimilate(self, root: str | Path) -> None:
7276
"""Assimilate the entire subdirectory structure in rootpath serially."""
7377
valid_paths = []
74-
for parent, subdirs, files in os.walk(rootpath):
78+
for parent, subdirs, files in os.walk(root):
7579
valid_paths.extend(self._drone.get_valid_paths((parent, subdirs, files)))
76-
data = []
80+
data: list[str] = []
7781
total = len(valid_paths)
7882
for idx, path in enumerate(valid_paths, 1):
7983
new_data = self._drone.assimilate(path)
8084
self._data.append(new_data)
81-
logger.info(f"{idx}/{total} ({idx / total:.2%}) done")
85+
logger.info(f"{idx}/{total} ({idx / total:.1%}) done")
8286
for json_str in data:
8387
self._data.append(json.loads(json_str, cls=MontyDecoder))
8488

8589
def get_data(self):
8690
"""Returns an list of assimilated objects."""
8791
return self._data
8892

89-
def save_data(self, filename):
93+
def save_data(self, filename: str | Path) -> None:
9094
"""Save the assimilated data to a file.
9195
9296
Args:

pymatgen/util/testing/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# fake POTCARs have original header information, meaning properties like number of electrons,
3232
# nuclear charge, core radii, etc. are unchanged (important for testing) while values of the and
3333
# pseudopotential kinetic energy corrections are scrambled to avoid VASP copyright infringement
34-
FAKE_POTCAR_DIR = TEST_FILES_DIR / "fake_potcars"
34+
FAKE_POTCAR_DIR = f"{VASP_IN_DIR}/fake_potcars"
3535

3636

3737
class PymatgenTest(unittest.TestCase):

tests/analysis/ferroelectricity/test_polarization.py

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

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

tests/analysis/magnetism/test_analyzer.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ def setUp(self):
3030

3131
self.Fe3O4 = Structure.from_file(f"{TEST_FILES_DIR}/Fe3O4.cif", primitive=True)
3232

33-
self.GdB4 = Structure.from_file(f"{TEST_FILES_DIR}/magnetic.ncl.example.GdB4.mcif", primitive=True)
33+
self.GdB4 = Structure.from_file(f"{TEST_FILES_DIR}/mcif/magnetic.ncl.example.GdB4.mcif", primitive=True)
3434

35-
self.NiO_expt = Structure.from_file(f"{TEST_FILES_DIR}/magnetic.example.NiO.mcif", primitive=True)
35+
self.NiO_expt = Structure.from_file(f"{TEST_FILES_DIR}/mcif/magnetic.example.NiO.mcif", primitive=True)
3636

3737
# CuO.mcif sourced from https://www.cryst.ehu.es/magndata/index.php?index=1.62
3838
# doi: 10.1088/0022-3719/21/15/023
39-
self.CuO_expt = Structure.from_file(f"{TEST_FILES_DIR}/magnetic.example.CuO.mcif.gz", primitive=True)
39+
self.CuO_expt = Structure.from_file(f"{TEST_FILES_DIR}/mcif/magnetic.example.CuO.mcif.gz", primitive=True)
4040

4141
lattice = Lattice.cubic(4.17)
4242
species = ["Ni", "O"]

tests/analysis/test_local_env.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ def test_get_nn(self):
287287
class TestOpenBabelNN(PymatgenTest):
288288
def setUp(self):
289289
pytest.importorskip("openbabel")
290-
self.benzene = Molecule.from_file(f"{TEST_FILES_DIR}/benzene.xyz")
291-
self.acetylene = Molecule.from_file(f"{TEST_FILES_DIR}/acetylene.xyz")
290+
self.benzene = Molecule.from_file(f"{TEST_FILES_DIR}/xyz/benzene.xyz")
291+
self.acetylene = Molecule.from_file(f"{TEST_FILES_DIR}/xyz/acetylene.xyz")
292292

293293
def test_nn_orders(self):
294294
strategy = OpenBabelNN()
@@ -318,8 +318,8 @@ def test_nn_length(self):
318318

319319
class TestCovalentBondNN(PymatgenTest):
320320
def setUp(self):
321-
self.benzene = Molecule.from_file(f"{TEST_FILES_DIR}/benzene.xyz")
322-
self.acetylene = Molecule.from_file(f"{TEST_FILES_DIR}/acetylene.xyz")
321+
self.benzene = Molecule.from_file(f"{TEST_FILES_DIR}/xyz/benzene.xyz")
322+
self.acetylene = Molecule.from_file(f"{TEST_FILES_DIR}/xyz/acetylene.xyz")
323323

324324
def test_nn_orders(self):
325325
strategy = CovalentBondNN()

tests/analysis/test_transition_state.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
__date__ = "2/5/16"
2121

2222

23-
TEST_DIR = f"{TEST_FILES_DIR}/neb_analysis"
23+
TEST_DIR = f"{TEST_FILES_DIR}/vasp/fixtures/neb_analysis"
2424

2525

2626
class TestNEBAnalysis(PymatgenTest):

tests/apps/borg/test_hive.py

+21-26
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os
44
import unittest
55

6-
from monty.tempfile import ScratchDir
76
from pytest import approx
87

98
from pymatgen.apps.borg.hive import (
@@ -26,25 +25,21 @@ def test_get_valid_paths(self):
2625
assert len(self.drone.get_valid_paths(path)) > 0
2726

2827
def test_assimilate(self):
29-
"""Test assimilate data from "vasprun.xe.xml.gz" file."""
30-
31-
with ScratchDir("."):
32-
# Need to rename the test file to "vasprun.xml.xe.gz" as
33-
# hive is looking for pattern "vasprun.xml*"
34-
os.symlink(f"{VASP_OUT_DIR}/vasprun.xe.xml.gz", "vasprun.xml.xe.gz")
35-
entry = self.drone.assimilate(".")
36-
37-
for param in ("hubbards", "is_hubbard", "potcar_spec", "run_type"):
38-
assert param in entry.parameters
39-
assert entry.data["efermi"] == approx(-6.62148548)
40-
assert entry.reduced_formula == "Xe"
41-
assert entry.energy == approx(0.5559329)
42-
43-
entry = self.structure_drone.assimilate(".")
44-
assert entry.reduced_formula == "Xe"
45-
assert entry.energy == approx(0.5559329)
46-
assert isinstance(entry, ComputedStructureEntry)
47-
assert entry.structure is not None
28+
"""Test assimilate data from "vasprun.xml.xe.gz" file."""
29+
30+
entry = self.drone.assimilate(f"{TEST_FILES_DIR}/app_borg/test_dir")
31+
32+
for param in ("hubbards", "is_hubbard", "potcar_spec", "run_type"):
33+
assert param in entry.parameters
34+
assert entry.data["efermi"] == approx(-6.62148548)
35+
assert entry.reduced_formula == "Xe"
36+
assert entry.energy == approx(0.5559329)
37+
38+
entry = self.structure_drone.assimilate(f"{TEST_FILES_DIR}/app_borg/test_dir")
39+
assert entry.reduced_formula == "Xe"
40+
assert entry.energy == approx(0.5559329)
41+
assert isinstance(entry, ComputedStructureEntry)
42+
assert entry.structure is not None
4843

4944
def test_as_from_dict(self):
5045
dct = self.structure_drone.as_dict()
@@ -81,16 +76,16 @@ def test_get_valid_paths(self):
8176
def test_assimilate(self):
8277
test_file = f"{TEST_FILES_DIR}/molecules/methane.log"
8378
entry = self.drone.assimilate(test_file)
84-
for p in [
79+
for param in [
8580
"functional",
8681
"basis_set",
8782
"charge",
8883
"spin_multiplicity",
8984
"route_parameters",
9085
]:
91-
assert p in entry.parameters
92-
for p in ["corrections"]:
93-
assert p in entry.data
86+
assert param in entry.parameters
87+
for param in ["corrections"]:
88+
assert param in entry.data
9489

9590
assert entry.reduced_formula == "H4C"
9691
assert entry.energy == approx(-39.9768775602)
@@ -99,8 +94,8 @@ def test_assimilate(self):
9994
assert entry.energy == approx(-39.9768775602)
10095
assert isinstance(entry, ComputedStructureEntry)
10196
assert entry.structure is not None
102-
for p in ["properly_terminated", "stationary_type"]:
103-
assert p in entry.data
97+
for param in ["properly_terminated", "stationary_type"]:
98+
assert param in entry.data
10499

105100
def test_as_from_dict(self):
106101
dct = self.structure_drone.as_dict()

tests/apps/borg/test_queen.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"""Created on Mar 18, 2012."""
2-
31
from __future__ import annotations
42

53
import unittest
@@ -12,16 +10,20 @@
1210
__copyright__ = "Copyright 2012, The Materials Project"
1311
__date__ = "Mar 18, 2012"
1412

13+
TEST_DIR = f"{TEST_FILES_DIR}/app_borg"
14+
1515

1616
class TestBorgQueen(unittest.TestCase):
1717
def test_get_data(self):
18+
"""Test get data from vasprun.xml.xe.gz file."""
1819
drone = VaspToComputedEntryDrone()
19-
self.queen = BorgQueen(drone, TEST_FILES_DIR, 1)
20-
data = self.queen.get_data()
21-
assert len(data) == 16
20+
queen = BorgQueen(drone, TEST_DIR, 1)
21+
data = queen.get_data()
22+
assert len(data) == 1
23+
assert data[0].energy == 0.5559329
2224

2325
def test_load_data(self):
2426
drone = VaspToComputedEntryDrone()
2527
queen = BorgQueen(drone)
26-
queen.load_data(f"{TEST_FILES_DIR}/assimilated.json")
28+
queen.load_data(f"{TEST_DIR}/assimilated.json")
2729
assert len(queen.get_data()) == 1

tests/command_line/test_gulp_caller.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def test_get_energy(self):
245245
def test_get_relaxed_structure(self):
246246
# Output string obtained from running GULP on a terminal
247247

248-
with open(f"{TEST_FILES_DIR}/example21.gout") as file:
248+
with open(f"{TEST_FILES_DIR}/gulp/example21.gout") as file:
249249
out_str = file.read()
250250
struct = self.gio.get_relaxed_structure(out_str)
251251
assert isinstance(struct, Structure)

tests/core/test_structure.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -874,12 +874,12 @@ def test_to_from_file_and_string(self):
874874

875875
# test CIF file with unicode error
876876
# https://github.com/materialsproject/pymatgen/issues/2947
877-
struct = Structure.from_file(f"{TEST_FILES_DIR}/bad-unicode-gh-2947.mcif")
877+
struct = Structure.from_file(f"{TEST_FILES_DIR}/mcif/bad-unicode-gh-2947.mcif")
878878
assert struct.formula == "Ni32 O32"
879879

880880
# make sure CIfParser.parse_structures() and Structure.from_file() are consistent
881881
# i.e. uses same merge_tol for site merging, same primitive=False, etc.
882-
assert struct == CifParser(f"{TEST_FILES_DIR}/bad-unicode-gh-2947.mcif").parse_structures()[0]
882+
assert struct == CifParser(f"{TEST_FILES_DIR}/mcif/bad-unicode-gh-2947.mcif").parse_structures()[0]
883883

884884
# https://github.com/materialsproject/pymatgen/issues/3551
885885
json_path = Path("test-with-path.json")
@@ -1559,7 +1559,7 @@ def test_charge(self):
15591559
assert super_cell.charge == 25, "Set charge not properly modifying _charge"
15601560

15611561
def test_vesta_lattice_matrix(self):
1562-
silica_zeolite = Molecule.from_file(f"{TEST_FILES_DIR}/CON_vesta.xyz")
1562+
silica_zeolite = Molecule.from_file(f"{TEST_FILES_DIR}/xyz/CON_vesta.xyz")
15631563

15641564
s_vesta = Structure(
15651565
lattice=Lattice.from_parameters(22.6840, 13.3730, 12.5530, 90, 69.479, 90, vesta=True),

tests/electronic_structure/test_plotter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def test_methods(self):
249249

250250
class TestPlotBZ(unittest.TestCase):
251251
def setUp(self):
252-
self.rec_latt = Structure.from_file(f"{TEST_FILES_DIR}/Si.cssr").lattice.reciprocal_lattice
252+
self.rec_latt = Structure.from_file(f"{TEST_FILES_DIR}/cssr/Si.cssr").lattice.reciprocal_lattice
253253
self.kpath = [[[0.0, 0.0, 0.0], [0.5, 0.0, 0.5], [0.5, 0.25, 0.75], [0.375, 0.375, 0.75]]]
254254
self.labels = {
255255
"\\Gamma": [0.0, 0.0, 0.0],

0 commit comments

Comments
 (0)