Skip to content

Commit

Permalink
Clean up test files: VASP outputs (#3653)
Browse files Browse the repository at this point in the history
* move vasprun to dedicated dir

* move OUTCAR to dedicated dir

* fix vasp output file paths

* move CHGCAR to dedicated dir

* relocate DOSCAR

* relocate EIGENVAL

* relocate PROCAR

* relocate WAVECAR

* relocate XDATCAR

* relocate LOCPOT

* relocate DYNMAT

* relocate ELFCAR

* relocate CONTCAR

* relocate IBZKPT

* relocate WAVEDER and WAVEDERF

* relocate trajectory XDATCAR

* relocate OSZICAR

* temp fix: borg

* rename trajectory test files

* remove duplicate OUTCARs

* compress some CHGCAR OUTCAR PROCAR

* compress formatted WAVEDER

* pre-commit auto-fixes

* sort import

* compress OUTCAR and remove duplicate

* compress more vasp output files

* add missing gz extension

* rename some vasprun to respect extension name

* rename more vasprun to respect file extension

* remove remaining vasprun to respect file extension

* fix some paths after rename

* redirect borg to output dir for efermi search

* pre-commit auto-fixes

* fix borg error

* add test note

* fix test_xe

* rename vasprun.xe and use ScratchDir

* define VASP_OUT_DIR = f"{TEST_FILES_DIR}/vasp/outputs" for shorter file paths

---------

Signed-off-by: Haoyu (Daniel) <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Janosh Riebesell <[email protected]>
  • Loading branch information
3 people committed Mar 7, 2024
1 parent d1c3e3d commit 8c5829b
Show file tree
Hide file tree
Showing 157 changed files with 319 additions and 1,082,056 deletions.
2 changes: 1 addition & 1 deletion pymatgen/io/vasp/sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2746,7 +2746,7 @@ def get_vasprun_outcar(path: str | Path, parse_dos: bool = True, parse_eigen: bo
if len(vruns) == 0 or len(outcars) == 0:
raise ValueError(f"Unable to get vasprun.xml/OUTCAR from prev calculation in {path}")
vsfile_fullpath = str(path / "vasprun.xml")
outcarfile_fullpath = str(path / "OUTCAR")
outcarfile_fullpath = str(path / "OUTCAR.gz")
vsfile = vsfile_fullpath if vsfile_fullpath in vruns else sorted(vruns)[-1]
outcarfile = outcarfile_fullpath if outcarfile_fullpath in outcars else sorted(outcars)[-1]
return (
Expand Down
1 change: 1 addition & 0 deletions pymatgen/util/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
MODULE_DIR = Path(__file__).absolute().parent
STRUCTURES_DIR = MODULE_DIR / ".." / "structures"
TEST_FILES_DIR = Path(SETTINGS.get("PMG_TEST_FILES_DIR", f"{ROOT}/tests/files"))
VASP_OUT_DIR = f"{TEST_FILES_DIR}/vasp/outputs"
# fake POTCARs have original header information, meaning properties like number of electrons,
# nuclear charge, core radii, etc. are unchanged (important for testing) while values of the and
# pseudopotential kinetic energy corrections are scrambled to avoid VASP copyright infringement
Expand Down
8 changes: 4 additions & 4 deletions tests/analysis/test_structure_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
)
from pymatgen.core import Element, Lattice, Structure
from pymatgen.io.vasp.outputs import Xdatcar
from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest
from pymatgen.util.testing import TEST_FILES_DIR, VASP_OUT_DIR, PymatgenTest


class TestVoronoiAnalyzer(PymatgenTest):
def setUp(self):
self.ss = Xdatcar(f"{TEST_FILES_DIR}/XDATCAR.MD").structures
self.ss = Xdatcar(f"{VASP_OUT_DIR}/XDATCAR.MD").structures
self.s = self.ss[1]
self.va = VoronoiAnalyzer(cutoff=4)

Expand All @@ -40,7 +40,7 @@ def test_analyze(self):
class TestRelaxationAnalyzer(unittest.TestCase):
def setUp(self):
s1 = Structure.from_file(f"{TEST_FILES_DIR}/POSCAR.Li2O")
s2 = Structure.from_file(f"{TEST_FILES_DIR}/CONTCAR.Li2O")
s2 = Structure.from_file(f"{VASP_OUT_DIR}/CONTCAR.Li2O")
self.analyzer = RelaxationAnalyzer(s1, s2)

def test_vol_and_para_changes(self):
Expand Down Expand Up @@ -77,7 +77,7 @@ def test_connectivity_array(self):

class TestMiscFunction(PymatgenTest):
def test_average_coordination_number(self):
xdatcar = Xdatcar(f"{TEST_FILES_DIR}/XDATCAR.MD")
xdatcar = Xdatcar(f"{VASP_OUT_DIR}/XDATCAR.MD")
coordination_numbers = average_coordination_number(xdatcar.structures, freq=1)
assert coordination_numbers["Fe"] == approx(
4.771903318390836, 5
Expand Down
4 changes: 2 additions & 2 deletions tests/analysis/test_xps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from pymatgen.analysis.xps import XPS
from pymatgen.io.vasp import Vasprun
from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest
from pymatgen.util.testing import VASP_OUT_DIR, PymatgenTest


class XPSTestCase(PymatgenTest):
def test_from_dos(self):
vasp_run = Vasprun(f"{TEST_FILES_DIR}/vasprun.xml.LiF.gz")
vasp_run = Vasprun(f"{VASP_OUT_DIR}/vasprun.LiF.xml.gz")
dos = vasp_run.complete_dos
xps = XPS.from_dos(dos)
assert len(xps) == 301
Expand Down
42 changes: 25 additions & 17 deletions tests/apps/borg/test_hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import unittest

from monty.tempfile import ScratchDir
from pytest import approx

from pymatgen.apps.borg.hive import (
Expand All @@ -11,7 +12,7 @@
VaspToComputedEntryDrone,
)
from pymatgen.entries.computed_entries import ComputedStructureEntry
from pymatgen.util.testing import TEST_FILES_DIR
from pymatgen.util.testing import TEST_FILES_DIR, VASP_OUT_DIR


class TestVaspToComputedEntryDrone(unittest.TestCase):
Expand All @@ -20,23 +21,30 @@ def setUp(self):
self.structure_drone = VaspToComputedEntryDrone(inc_structure=True)

def test_get_valid_paths(self):
for path in os.walk(TEST_FILES_DIR):
if path[0] == TEST_FILES_DIR:
for path in os.walk(VASP_OUT_DIR):
if path[0] == VASP_OUT_DIR:
assert len(self.drone.get_valid_paths(path)) > 0

def test_assimilate(self):
entry = self.drone.assimilate(TEST_FILES_DIR)
for param in ("hubbards", "is_hubbard", "potcar_spec", "run_type"):
assert param in entry.parameters
assert entry.data["efermi"] == approx(-6.62148548)
assert entry.reduced_formula == "Xe"
assert entry.energy == approx(0.5559329)
entry = self.structure_drone.assimilate(TEST_FILES_DIR)
assert entry.reduced_formula == "Xe"
assert entry.energy == approx(0.5559329)
assert isinstance(entry, ComputedStructureEntry)
assert entry.structure is not None
# assert len(entry.parameters["history"]) == 2
"""Test assimilate data from "vasprun.xe.xml.gz" file."""

with ScratchDir("."):
# Need to rename the test file to "vasprun.xml.xe.gz" as
# hive is looking for pattern "vasprun.xml*"
os.symlink(f"{VASP_OUT_DIR}/vasprun.xe.xml.gz", "vasprun.xml.xe.gz")
entry = self.drone.assimilate(".")

for param in ("hubbards", "is_hubbard", "potcar_spec", "run_type"):
assert param in entry.parameters
assert entry.data["efermi"] == approx(-6.62148548)
assert entry.reduced_formula == "Xe"
assert entry.energy == approx(0.5559329)

entry = self.structure_drone.assimilate(".")
assert entry.reduced_formula == "Xe"
assert entry.energy == approx(0.5559329)
assert isinstance(entry, ComputedStructureEntry)
assert entry.structure is not None

def test_as_from_dict(self):
dct = self.structure_drone.as_dict()
Expand All @@ -50,8 +58,8 @@ def setUp(self):
self.structure_drone = SimpleVaspToComputedEntryDrone(inc_structure=True)

def test_get_valid_paths(self):
for path in os.walk(TEST_FILES_DIR):
if path[0] == TEST_FILES_DIR:
for path in os.walk(VASP_OUT_DIR):
if path[0] == VASP_OUT_DIR:
assert len(self.drone.get_valid_paths(path)) > 0

def test_as_from_dict(self):
Expand Down
14 changes: 7 additions & 7 deletions tests/command_line/test_bader_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pytest import approx

from pymatgen.command_line.bader_caller import BaderAnalysis, bader_analysis_from_path
from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest
from pymatgen.util.testing import TEST_FILES_DIR, VASP_OUT_DIR, PymatgenTest


@unittest.skipIf(not which("bader"), "bader executable not present")
Expand All @@ -23,9 +23,9 @@ def setUp(self):
def test_init(self):
# test with reference file
analysis = BaderAnalysis(
chgcar_filename=f"{TEST_FILES_DIR}/CHGCAR.Fe3O4",
chgcar_filename=f"{VASP_OUT_DIR}/CHGCAR.Fe3O4.gz",
potcar_filename=f"{TEST_FILES_DIR}/POTCAR.Fe3O4",
chgref_filename=f"{TEST_FILES_DIR}/CHGCAR.Fe3O4_ref",
chgref_filename=f"{VASP_OUT_DIR}/CHGCAR.Fe3O4_ref.gz",
)
assert len(analysis.data) == 14
assert analysis.data[0]["charge"] == approx(6.6136782, abs=1e-3)
Expand Down Expand Up @@ -55,7 +55,7 @@ def test_init(self):
assert struct[0].specie.oxi_state == approx(1.3863218, abs=1e-3)

# make sure bader still runs without reference file
analysis = BaderAnalysis(chgcar_filename=f"{TEST_FILES_DIR}/CHGCAR.Fe3O4")
analysis = BaderAnalysis(chgcar_filename=f"{VASP_OUT_DIR}/CHGCAR.Fe3O4.gz")
assert len(analysis.data) == 14

# Test Cube file format parsing
Expand Down Expand Up @@ -118,9 +118,9 @@ def test_bader_analysis_from_path(self):
def test_atom_parsing(self):
# test with reference file
analysis = BaderAnalysis(
chgcar_filename=f"{TEST_FILES_DIR}/CHGCAR.Fe3O4",
chgcar_filename=f"{VASP_OUT_DIR}/CHGCAR.Fe3O4.gz",
potcar_filename=f"{TEST_FILES_DIR}/POTCAR.Fe3O4",
chgref_filename=f"{TEST_FILES_DIR}/CHGCAR.Fe3O4_ref",
chgref_filename=f"{VASP_OUT_DIR}/CHGCAR.Fe3O4_ref.gz",
parse_atomic_densities=True,
)

Expand All @@ -139,4 +139,4 @@ def test_missing_file_bader_exe_path(self):
RuntimeError, match="BaderAnalysis requires the executable bader be in the PATH or the full path "
),
):
BaderAnalysis(chgcar_filename=f"{TEST_FILES_DIR}/CHGCAR.Fe3O4", bader_path="")
BaderAnalysis(chgcar_filename=f"{VASP_OUT_DIR}/CHGCAR.Fe3O4.gz", bader_exe_path="")
12 changes: 6 additions & 6 deletions tests/core/test_trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
from pymatgen.core.trajectory import Trajectory
from pymatgen.io.qchem.outputs import QCOutput
from pymatgen.io.vasp.outputs import Xdatcar
from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest
from pymatgen.util.testing import TEST_FILES_DIR, VASP_OUT_DIR, PymatgenTest


class TestTrajectory(PymatgenTest):
def setUp(self):
xdatcar = Xdatcar(f"{TEST_FILES_DIR}/Traj_XDATCAR")
self.traj = Trajectory.from_file(f"{TEST_FILES_DIR}/Traj_XDATCAR")
xdatcar = Xdatcar(f"{VASP_OUT_DIR}/XDATCAR_traj")
self.traj = Trajectory.from_file(f"{VASP_OUT_DIR}/XDATCAR_traj")
self.structures = xdatcar.structures

out = QCOutput(f"{TEST_FILES_DIR}/molecules/new_qchem_files/ts.out")
Expand Down Expand Up @@ -221,15 +221,15 @@ def test_extend(self):
traj = copy.deepcopy(self.traj)

# Case of compatible trajectories
compatible_traj = Trajectory.from_file(f"{TEST_FILES_DIR}/Traj_Combine_Test_XDATCAR_1")
compatible_traj = Trajectory.from_file(f"{VASP_OUT_DIR}/XDATCAR_traj_combine_test_1")
traj.extend(compatible_traj)

full_traj = Trajectory.from_file(f"{TEST_FILES_DIR}/Traj_Combine_Test_XDATCAR_Full")
full_traj = Trajectory.from_file(f"{VASP_OUT_DIR}/XDATCAR_traj_combine_test_full")
compatible_success = self._check_traj_equality(self.traj, full_traj)

# Case of incompatible trajectories
traj = copy.deepcopy(self.traj)
incompatible_traj = Trajectory.from_file(f"{TEST_FILES_DIR}/Traj_Combine_Test_XDATCAR_2")
incompatible_traj = Trajectory.from_file(f"{VASP_OUT_DIR}/XDATCAR_traj_combine_test_2")
incompatible_test_success = False
try:
traj.extend(incompatible_traj)
Expand Down
4 changes: 2 additions & 2 deletions tests/electronic_structure/test_bandstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from pymatgen.electronic_structure.core import Orbital, Spin
from pymatgen.electronic_structure.plotter import BSPlotterProjected
from pymatgen.io.vasp import BSVasprun
from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest
from pymatgen.util.testing import TEST_FILES_DIR, VASP_OUT_DIR, PymatgenTest


class TestKpoint(unittest.TestCase):
Expand Down Expand Up @@ -264,7 +264,7 @@ def test_reconstruct_band_structure(self):

def test_vasprun_bs(self):
bsv = BSVasprun(
f"{TEST_FILES_DIR}/vasprun.xml.gz",
f"{VASP_OUT_DIR}/vasprun.xml.gz",
parse_projected_eigen=True,
parse_potcar_file=True,
)
Expand Down
4 changes: 2 additions & 2 deletions tests/electronic_structure/test_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
plot_ellipsoid,
)
from pymatgen.io.vasp import Vasprun
from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest
from pymatgen.util.testing import TEST_FILES_DIR, VASP_OUT_DIR, PymatgenTest

rc("text", usetex=False) # Disabling latex is needed for this test to work.

Expand Down Expand Up @@ -212,7 +212,7 @@ class TestBSDOSPlotter(unittest.TestCase):
# Minimal baseline testing for get_plot. not a true test. Just checks that
# it can actually execute.
def test_methods(self):
vasp_run = Vasprun(f"{TEST_FILES_DIR}/vasprun_Si_bands.xml.gz")
vasp_run = Vasprun(f"{VASP_OUT_DIR}/vasprun_Si_bands.xml.gz")
plotter = BSDOSPlotter()
band_struct = vasp_run.get_band_structure(kpoints_filename=f"{TEST_FILES_DIR}/KPOINTS_Si_bands")
ax = plotter.get_plot(band_struct)
Expand Down
5 changes: 2 additions & 3 deletions tests/entries/test_computed_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
TemperatureEnergyAdjustment,
)
from pymatgen.io.vasp.outputs import Vasprun
from pymatgen.util.testing import TEST_FILES_DIR
from pymatgen.util.testing import TEST_FILES_DIR, VASP_OUT_DIR

filepath = f"{TEST_FILES_DIR}/vasprun.xml.gz"
vasp_run = Vasprun(filepath)
vasp_run = Vasprun(f"{VASP_OUT_DIR}/vasprun.xml.gz")


def test_energy_adjustment():
Expand Down
Loading

0 comments on commit 8c5829b

Please sign in to comment.