Skip to content

Commit

Permalink
Merge branch 'materialsproject:master' into install_data_files
Browse files Browse the repository at this point in the history
  • Loading branch information
drew-parsons committed Aug 24, 2021
2 parents 8a3f596 + 405a0b2 commit fd9004d
Show file tree
Hide file tree
Showing 20 changed files with 45 additions and 135 deletions.
4 changes: 1 addition & 3 deletions pymatgen/alchemy/tests/test_materials.py
Expand Up @@ -55,9 +55,7 @@ def test_append_filter(self):
self.trans.append_filter(f3)

def test_get_vasp_input(self):
SETTINGS["PMG_VASP_PSP_DIR"] = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "..", "..", "test_files")
)
SETTINGS["PMG_VASP_PSP_DIR"] = PymatgenTest.TEST_FILES_DIR
potcar = self.trans.get_vasp_input(MPRelaxSet)["POTCAR"]
self.assertEqual("Na_pv\nFe_pv\nP\nO", "\n".join([p.symbol for p in potcar]))
self.assertEqual(len(self.trans.structures), 2)
Expand Down
Expand Up @@ -20,13 +20,7 @@
bson = None

json_files_dir = os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"..",
"..",
"test_files",
PymatgenTest.TEST_FILES_DIR,
"chemenv",
"json_test_files",
)
Expand Down
Expand Up @@ -19,13 +19,7 @@
from pymatgen.util.testing import PymatgenTest

json_files_dir = os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"..",
"..",
"test_files",
PymatgenTest.TEST_FILES_DIR,
"chemenv",
"json_test_files",
)
Expand Down
Expand Up @@ -31,26 +31,15 @@
DetailedVoronoiContainer,
)
from pymatgen.core.structure import Structure
from pymatgen.util.testing import PymatgenTest

json_files_dir = os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"..",
"..",
"test_files",
PymatgenTest.TEST_FILES_DIR,
"chemenv",
"json_test_files",
)
se_files_dir = os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"..",
"..",
"test_files",
PymatgenTest.TEST_FILES_DIR,
"chemenv",
"structure_environments_files",
)
Expand Down
Expand Up @@ -23,13 +23,7 @@
from pymatgen.util.testing import PymatgenTest

se_files_dir = os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"..",
"..",
"test_files",
PymatgenTest.TEST_FILES_DIR,
"chemenv",
"structure_environments_files",
)
Expand Down
Expand Up @@ -19,24 +19,12 @@
from pymatgen.util.testing import PymatgenTest

json_files_dir = os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"..",
"..",
"test_files",
PymatgenTest.TEST_FILES_DIR,
"chemenv",
"json_test_files",
)
img_files_dir = os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"..",
"..",
"test_files",
PymatgenTest.TEST_FILES_DIR,
"chemenv",
"images",
)
Expand Down
Expand Up @@ -23,13 +23,7 @@
from pymatgen.util.testing import PymatgenTest

se_files_dir = os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"..",
"..",
"test_files",
PymatgenTest.TEST_FILES_DIR,
"chemenv",
"structure_environments_files",
)
Expand Down
9 changes: 2 additions & 7 deletions pymatgen/analysis/chemenv/utils/tests/test_chemenv_config.py
Expand Up @@ -11,15 +11,10 @@

from pymatgen.core import SETTINGS
from pymatgen.analysis.chemenv.utils.chemenv_config import ChemEnvConfig
from pymatgen.util.testing import PymatgenTest

config_file_dir = os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"..",
"..",
"test_files",
PymatgenTest.TEST_FILES_DIR,
"chemenv",
"config",
)
Expand Down
Expand Up @@ -13,6 +13,7 @@
SubstitutionProbability,
)
from pymatgen.core.periodic_table import Species
from pymatgen.util.testing import PymatgenTest


def get_table():
Expand All @@ -22,12 +23,7 @@ def get_table():
default lambda table.
"""
data_dir = os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"..",
"test_files",
PymatgenTest.TEST_FILES_DIR,
"struct_predictor",
)

Expand Down
Expand Up @@ -20,12 +20,7 @@ def get_table():
default lambda table.
"""
data_dir = os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"..",
"test_files",
PymatgenTest.TEST_FILES_DIR,
"struct_predictor",
)
json_file = os.path.join(data_dir, "test_lambda.json")
Expand Down
63 changes: 19 additions & 44 deletions pymatgen/analysis/tests/test_graphs.py
Expand Up @@ -37,7 +37,7 @@
__date__ = "August 2017"

module_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)))
molecule_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..", "test_files", "molecules")
molecule_dir = os.path.join(PymatgenTest.TEST_FILES_DIR, "molecules")


class StructureGraphTest(PymatgenTest):
Expand Down Expand Up @@ -83,21 +83,15 @@ def setUp(self):
# MoS2 example, structure graph obtained from critic2
# (not ground state, from mp-1023924, single layer)
stdout_file = os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"test_files/critic2/MoS2_critic2_stdout.txt",
PymatgenTest.TEST_FILES_DIR,
"critic2/MoS2_critic2_stdout.txt",
)
with open(stdout_file, "r") as f:
reference_stdout = f.read()
self.structure = Structure.from_file(
os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"test_files/critic2/MoS2.cif",
PymatgenTest.TEST_FILES_DIR,
"critic2/MoS2.cif",
)
)
c2o = Critic2Analysis(self.structure, reference_stdout)
Expand Down Expand Up @@ -229,9 +223,7 @@ def test_insert_remove(self):
self.assertEqual(square_copy.graph.number_of_edges(), 3)

def test_substitute(self):
structure = Structure.from_file(
os.path.join(os.path.dirname(__file__), "..", "..", "..", "test_files", "Li2O.cif")
)
structure = Structure.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "Li2O.cif"))
molecule = FunctionalGroups["methyl"]

structure_copy = copy.deepcopy(structure)
Expand Down Expand Up @@ -471,11 +463,8 @@ def test_from_edges(self):
def test_extract_molecules(self):

structure_file = os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"test_files/H6PbCI3N_mp-977013_symmetrized.cif",
PymatgenTest.TEST_FILES_DIR,
"H6PbCI3N_mp-977013_symmetrized.cif",
)

s = Structure.from_file(structure_file)
Expand Down Expand Up @@ -539,11 +528,8 @@ def setUp(self):

cyclohexene = Molecule.from_file(
os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"test_files/graphs/cyclohexene.xyz",
PymatgenTest.TEST_FILES_DIR,
"graphs/cyclohexene.xyz",
)
)
self.cyclohexene = MoleculeGraph.with_empty_graph(
Expand All @@ -568,11 +554,8 @@ def setUp(self):

butadiene = Molecule.from_file(
os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"test_files/graphs/butadiene.xyz",
PymatgenTest.TEST_FILES_DIR,
"graphs/butadiene.xyz",
)
)
self.butadiene = MoleculeGraph.with_empty_graph(butadiene, edge_weight_name="strength", edge_weight_units="")
Expand All @@ -588,11 +571,8 @@ def setUp(self):

ethylene = Molecule.from_file(
os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"test_files/graphs/ethylene.xyz",
PymatgenTest.TEST_FILES_DIR,
"graphs/ethylene.xyz",
)
)
self.ethylene = MoleculeGraph.with_empty_graph(ethylene, edge_weight_name="strength", edge_weight_units="")
Expand All @@ -602,7 +582,7 @@ def setUp(self):
self.ethylene.add_edge(1, 4, weight=1.0)
self.ethylene.add_edge(1, 5, weight=1.0)

self.pc = Molecule.from_file(os.path.join(module_dir, "..", "..", "..", "test_files", "graphs", "PC.xyz"))
self.pc = Molecule.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "graphs", "PC.xyz"))
self.pc_edges = [
[5, 10],
[5, 12],
Expand All @@ -618,11 +598,9 @@ def setUp(self):
[6, 0],
[6, 2],
]
self.pc_frag1 = Molecule.from_file(
os.path.join(module_dir, "..", "..", "..", "test_files", "graphs", "PC_frag1.xyz")
)
self.pc_frag1 = Molecule.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "graphs", "PC_frag1.xyz"))
self.pc_frag1_edges = [[0, 2], [4, 2], [2, 1], [1, 3]]
self.tfsi = Molecule.from_file(os.path.join(module_dir, "..", "..", "..", "test_files", "graphs", "TFSI.xyz"))
self.tfsi = Molecule.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "graphs", "TFSI.xyz"))
self.tfsi_edges = (
[14, 1],
[1, 4],
Expand Down Expand Up @@ -920,11 +898,8 @@ def test_find_rings(self):
def test_isomorphic(self):
ethylene = Molecule.from_file(
os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"test_files/graphs/ethylene.xyz",
PymatgenTest.TEST_FILES_DIR,
"graphs/ethylene.xyz",
)
)
# switch carbons
Expand Down
3 changes: 2 additions & 1 deletion pymatgen/analysis/tests/test_path_finder.py
Expand Up @@ -9,6 +9,7 @@
from pymatgen.analysis.path_finder import ChgcarPotential, NEBPathfinder
from pymatgen.core.periodic_table import Element
from pymatgen.io.vasp import Chgcar, Poscar
from pymatgen.util.testing import PymatgenTest

__author__ = "Ziqin (Shaun) Rong"
__version__ = "0.1"
Expand All @@ -23,7 +24,7 @@ class PathFinderTest(unittest.TestCase):

def test_image_num(self):
module_dir = os.path.dirname(os.path.abspath(__file__))
test_file_dir = os.path.join(module_dir, "..", "..", "..", "test_files", "path_finder")
test_file_dir = os.path.join(PymatgenTest.TEST_FILES_DIR, "path_finder")
start_s = Poscar.from_file(os.path.join(test_file_dir, "LFP_POSCAR_s")).structure
end_s = Poscar.from_file(os.path.join(test_file_dir, "LFP_POSCAR_e")).structure
mid_s = start_s.interpolate(end_s, nimages=2, interpolate_lattices=False)[1]
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/tests/test_surface_analysis.py
Expand Up @@ -25,7 +25,7 @@

def get_path(path_str):
cwd = os.path.abspath(os.path.dirname(__file__))
path = os.path.join(cwd, "..", "..", "..", "test_files", "surface_tests", path_str)
path = os.path.join(PymatgenTest.TEST_FILES_DIR, "surface_tests", path_str)
return path


Expand Down
7 changes: 2 additions & 5 deletions pymatgen/command_line/tests/test_critic2_caller.py
Expand Up @@ -62,11 +62,8 @@ def test_from_structure(self):
# uses promolecular density
structure = Structure.from_file(
os.path.join(
os.path.dirname(__file__),
"..",
"..",
"..",
"test_files/critic2/MoS2.cif",
PymatgenTest.TEST_FILES_DIR,
"critic2/MoS2.cif",
)
)

Expand Down
2 changes: 1 addition & 1 deletion pymatgen/core/tests/test_surface.py
Expand Up @@ -29,7 +29,7 @@

def get_path(path_str):
cwd = os.path.abspath(os.path.dirname(__file__))
path = os.path.join(cwd, "..", "..", "..", "test_files", "surface_tests", path_str)
path = os.path.join(PymatgenTest.TEST_FILES_DIR, "surface_tests", path_str)
return path


Expand Down
2 changes: 1 addition & 1 deletion pymatgen/entries/computed_entries.py
Expand Up @@ -701,7 +701,7 @@ def normalize(self, mode: str = "formula_unit") -> "ComputedStructureEntry":
d = super().normalize(mode).as_dict()
d["structure"] = self.structure.as_dict()
entry = self.from_dict(d)
entry._composition /= factor # type: ignore
entry._composition /= factor # pylint: disable=E1101
return entry


Expand Down
2 changes: 1 addition & 1 deletion pymatgen/io/abinit/tests/test_inputs.py
Expand Up @@ -21,7 +21,7 @@
)
from pymatgen.util.testing import PymatgenTest

_test_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", "test_files", "abinit")
_test_dir = os.path.join(PymatgenTest.TEST_FILES_DIR, "abinit")


def abiref_file(filename):
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/io/abinit/tests/test_netcdf.py
Expand Up @@ -16,7 +16,7 @@
except ImportError:
netCDF4 = None

_test_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", "test_files", "abinit")
_test_dir = os.path.join(PymatgenTest.TEST_FILES_DIR, "abinit")


def ref_file(filename):
Expand Down

0 comments on commit fd9004d

Please sign in to comment.