Skip to content

Commit

Permalink
global replace get_structure
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Dec 4, 2024
1 parent dfb616c commit 9ae0deb
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions tests/alchemy/test_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
SupercellTransformation,
)
from pymatgen.util.provenance import StructureNL
from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, PymatgenTest
from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, MatSciTest

TEST_DIR = f"{TEST_FILES_DIR}/alchemy"


class TestTransformedStructure(MatSciTest):
def setup_method(self):
structure = PymatgenTest.get_structure("LiFePO4")
structure = MatSciTest.get_structure("LiFePO4")
self.structure = structure
trafos = [SubstitutionTransformation({"Li": "Na"})]
self.trans = TransformedStructure(structure, trafos)
Expand Down
2 changes: 1 addition & 1 deletion tests/alchemy/test_transmuters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
RemoveSpeciesTransformation,
SubstitutionTransformation,
)
from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, PymatgenTest
from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, MatSciTest


class TestCifTransmuter(MatSciTest):
Expand Down
4 changes: 2 additions & 2 deletions tests/analysis/structure_prediction/test_substitutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pymatgen.analysis.structure_prediction.substitutor import Substitutor
from pymatgen.core import Composition, Species
from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest
from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest

TEST_DIR = f"{TEST_FILES_DIR}/analysis/struct_predictor"

Expand Down Expand Up @@ -32,7 +32,7 @@ def test_substitutor(self):
subs = self.substitutor.pred_from_comp(comp)
assert len(subs) == 4, "incorrect number of substitutions"

structures = [{"structure": PymatgenTest.get_structure("Li2O"), "id": "pmgtest"}]
structures = [{"structure": MatSciTest.get_structure("Li2O"), "id": "pmgtest"}]
subs = self.substitutor.pred_from_structures(["Na+", "O2-"], structures)
assert subs[0].formula == "Na2 O1"

Expand Down
24 changes: 12 additions & 12 deletions tests/analysis/structure_prediction/test_volume_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,38 @@

from pymatgen.analysis.structure_prediction.volume_predictor import DLSVolumePredictor, RLSVolumePredictor
from pymatgen.core import Structure
from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest
from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest

TEST_DIR = f"{TEST_FILES_DIR}/analysis/structure_prediction"


class TestRLSVolumePredictor(MatSciTest):
def test_predict(self):
struct = PymatgenTest.get_structure("CsCl")
nacl = PymatgenTest.get_structure("CsCl")
struct = MatSciTest.get_structure("CsCl")
nacl = MatSciTest.get_structure("CsCl")
nacl.replace_species({"Cs": "Na"})
nacl.scale_lattice(184.384551033)
predictor = RLSVolumePredictor(radii_type="ionic")
assert predictor.predict(struct, nacl) == approx(342.84905395082535)
predictor = RLSVolumePredictor(radii_type="atomic")
assert predictor.predict(struct, nacl) == approx(391.884366481)
lif = PymatgenTest.get_structure("CsCl")
lif = MatSciTest.get_structure("CsCl")
lif.replace_species({"Cs": "Li", "Cl": "F"})
predictor = RLSVolumePredictor(radii_type="ionic")
assert predictor.predict(lif, nacl) == approx(74.268402413690467)
predictor = RLSVolumePredictor(radii_type="atomic")
assert predictor.predict(lif, nacl) == approx(62.2808125839)

lfpo = PymatgenTest.get_structure("LiFePO4")
lmpo = PymatgenTest.get_structure("LiFePO4")
lfpo = MatSciTest.get_structure("LiFePO4")
lmpo = MatSciTest.get_structure("LiFePO4")
lmpo.replace_species({"Fe": "Mn"})
predictor = RLSVolumePredictor(radii_type="ionic")
assert predictor.predict(lmpo, lfpo) == approx(310.08253254420134)
predictor = RLSVolumePredictor(radii_type="atomic")
assert predictor.predict(lmpo, lfpo) == approx(299.607967711)

sto = PymatgenTest.get_structure("SrTiO3")
scoo = PymatgenTest.get_structure("SrTiO3")
sto = MatSciTest.get_structure("SrTiO3")
scoo = MatSciTest.get_structure("SrTiO3")
scoo.replace_species({"Ti4+": "Co4+"})
predictor = RLSVolumePredictor(radii_type="ionic")
assert predictor.predict(scoo, sto) == approx(56.162534974936463)
Expand All @@ -61,8 +61,8 @@ def test_predict(self):
assert predictor.predict(apo, aps) == approx(1196.31384276)

def test_modes(self):
cs_cl = PymatgenTest.get_structure("CsCl")
na_cl = PymatgenTest.get_structure("CsCl")
cs_cl = MatSciTest.get_structure("CsCl")
na_cl = MatSciTest.get_structure("CsCl")
na_cl.replace_species({"Cs": "Na"})
na_cl.scale_lattice(184.384551033)
vol_pred = RLSVolumePredictor(radii_type="ionic", use_bv=False)
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_predict(self):
assert vol_pred.predict(fen) == approx(fen.volume * 1.5)
assert p_fast.predict(fen) == approx(fen.volume * 1.5)

lfpo = PymatgenTest.get_structure("LiFePO4")
lfpo = MatSciTest.get_structure("LiFePO4")

lfpo.scale_lattice(lfpo.volume * 3.0)
assert p_nolimit.predict(lfpo) == approx(291.62094410192924)
Expand All @@ -104,6 +104,6 @@ def test_predict(self):
assert vol_pred.predict(lfpo) == approx(lfpo.volume * 1.5)
assert p_fast.predict(lfpo) == approx(lfpo.volume * 1.5)

lmpo = PymatgenTest.get_structure("LiFePO4")
lmpo = MatSciTest.get_structure("LiFePO4")
lmpo.replace_species({"Fe": "Mn"})
assert vol_pred.predict(lmpo) == approx(290.795329052)
8 changes: 4 additions & 4 deletions tests/core/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from pymatgen.io.ase import AseAtomsAdaptor
from pymatgen.io.cif import CifParser
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, PymatgenTest
from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, MatSciTest

try:
from ase.atoms import Atoms
Expand All @@ -46,7 +46,7 @@

class TestNeighbor(MatSciTest):
def test_msonable(self):
struct = PymatgenTest.get_structure("Li2O")
struct = MatSciTest.get_structure("Li2O")
nn = struct.get_neighbors(struct[0], r=3)
assert isinstance(nn[0], PeriodicNeighbor)
str_ = json.dumps(nn, cls=MontyEncoder)
Expand Down Expand Up @@ -1024,7 +1024,7 @@ def test_mutable_sequence_methods(self):
assert struct.formula == "Mn1"

# Test slice replacement.
struct = PymatgenTest.get_structure("Li2O")
struct = MatSciTest.get_structure("Li2O")
struct[:2] = "S"
assert struct.formula == "Li1 S2"

Expand Down Expand Up @@ -1267,7 +1267,7 @@ def test_remove_oxidation_states(self):
assert struct_elem == struct_specie, "Oxidation state remover failed"

def test_add_oxidation_state_by_guess(self):
struct = PymatgenTest.get_structure("Li2O")
struct = MatSciTest.get_structure("Li2O")
returned = struct.add_oxidation_state_by_guess()
assert returned is struct
expected = [Species("Li", 1), Species("O", -2)]
Expand Down
4 changes: 2 additions & 2 deletions tests/io/test_phonopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
get_pmg_structure,
get_thermal_displacement_matrices,
)
from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest
from pymatgen.util.testing import TEST_FILES_DIR, MatSciTest

try:
from phonopy import Phonopy
Expand Down Expand Up @@ -99,7 +99,7 @@ def test_get_complete_dos(self):
@pytest.mark.skipif(Phonopy is None, reason="Phonopy not present")
class TestStructureConversion(MatSciTest):
def test_structure_conversion(self):
struct_pmg = PymatgenTest.get_structure("LiFePO4")
struct_pmg = MatSciTest.get_structure("LiFePO4")
# add magmoms to site_properties
struct_pmg.add_site_property("magmom", magmoms := [1] * len(struct_pmg))
struct_ph = get_phonopy_structure(struct_pmg)
Expand Down
8 changes: 4 additions & 4 deletions tests/io/vasp/test_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
get_valid_magmom_struct,
)
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest
from pymatgen.util.testing import FAKE_POTCAR_DIR, TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, MatSciTest

TEST_DIR = f"{TEST_FILES_DIR}/io/vasp"

Expand Down Expand Up @@ -1501,7 +1501,7 @@ def test_incar(self):
class TestMVLGWSet(MatSciTest):
def setup_method(self):
self.set = MVLGWSet
self.struct = PymatgenTest.get_structure("Li2O")
self.struct = MatSciTest.get_structure("Li2O")

def test_static(self):
assert self.set.mode == "STATIC"
Expand Down Expand Up @@ -1675,7 +1675,7 @@ def test_init(self):
assert vis.reciprocal_density == 100

with pytest.warns(BadInputSetWarning, match=r"Hybrid functionals"):
vis = self.set(PymatgenTest.get_structure("Li2O"), user_incar_settings={"ALGO": "Fast"})
vis = self.set(MatSciTest.get_structure("Li2O"), user_incar_settings={"ALGO": "Fast"})
vis.incar.items()

def test_override_from_prev_calc(self):
Expand Down Expand Up @@ -1991,7 +1991,7 @@ def test_override_from_prev_calc(self):
class TestFunc(MatSciTest):
@skip_if_no_psp_dir
def test_batch_write_input(self):
structs = list(map(PymatgenTest.get_structure, ("Li2O", "LiFePO4")))
structs = list(map(MatSciTest.get_structure, ("Li2O", "LiFePO4")))

batch_write_input(structs, sanitize=True)
for formula in ("Li4Fe4P4O16_1", "Li2O1_0"):
Expand Down
8 changes: 4 additions & 4 deletions tests/symmetry/test_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
iterative_symmetrize,
)
from pymatgen.symmetry.structure import SymmetrizedStructure
from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, PymatgenTest
from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, VASP_OUT_DIR, MatSciTest

TEST_DIR = f"{TEST_FILES_DIR}/symmetry/analyzer"

Expand Down Expand Up @@ -54,7 +54,7 @@ def test_is_laue(self):
assert self.disordered_sg.is_laue()

def test_magnetic(self):
lfp = PymatgenTest.get_structure("LiFePO4")
lfp = MatSciTest.get_structure("LiFePO4")
sg = SpacegroupAnalyzer(lfp, 0.1)
assert sg.get_space_group_symbol() == "Pnma"
magmoms = [0] * len(lfp)
Expand Down Expand Up @@ -670,7 +670,7 @@ def test_symmetrize_molecule2(self):

def test_get_kpoint_weights(self):
for name in ("SrTiO3", "LiFePO4", "Graphite"):
struct = PymatgenTest.get_structure(name)
struct = MatSciTest.get_structure(name)
spga = SpacegroupAnalyzer(struct)
ir_mesh = spga.get_ir_reciprocal_mesh((4, 4, 4))
weights = [i[1] for i in ir_mesh]
Expand All @@ -679,7 +679,7 @@ def test_get_kpoint_weights(self):
assert weight == approx(expected)

for name in ("SrTiO3", "LiFePO4", "Graphite"):
struct = PymatgenTest.get_structure(name)
struct = MatSciTest.get_structure(name)
spga = SpacegroupAnalyzer(struct)
ir_mesh = spga.get_ir_reciprocal_mesh((1, 2, 3))
weights = [i[1] for i in ir_mesh]
Expand Down
6 changes: 3 additions & 3 deletions tests/transformations/test_advanced_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
OxidationStateDecorationTransformation,
SubstitutionTransformation,
)
from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, PymatgenTest
from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR, MatSciTest

try:
import hiphive
Expand Down Expand Up @@ -490,7 +490,7 @@ def test_advanced_usage(self):
@pytest.mark.skipif(not enumlib_present, reason="enum_lib not present.")
class TestDopingTransformation(MatSciTest):
def test_apply_transformation(self):
structure = PymatgenTest.get_structure("LiFePO4")
structure = MatSciTest.get_structure("LiFePO4")
spga = SpacegroupAnalyzer(structure, 0.1)
structure = spga.get_refined_structure()
trafo = DopingTransformation("Ca2+", min_length=10)
Expand Down Expand Up @@ -524,7 +524,7 @@ def test_apply_transformation(self):
assert d["structure"].charge == 0

# Make sure compensation is done with lowest oxi state
structure = PymatgenTest.get_structure("SrTiO3")
structure = MatSciTest.get_structure("SrTiO3")
trafo = DopingTransformation(
"Nb5+",
min_length=5,
Expand Down

0 comments on commit 9ae0deb

Please sign in to comment.