Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
huizheng7174 committed Jan 28, 2025
1 parent 35e2a22 commit df17820
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/transformations/test_standard_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
SubstitutionTransformation,
SupercellTransformation,
)
from pymatgen.alchemy.transmuters import StandardTransmuter
from pymatgen.util.testing import TEST_FILES_DIR, VASP_IN_DIR

enumlib_present = which("enum.x") and which("makestr.x")
Expand Down Expand Up @@ -427,6 +428,43 @@ def test_random_sample(self):
output = trafo.apply_transformation(struct * [2, 2, 2], return_ranked_list=False)
assert output.composition.reduced_formula == struct.composition.reduced_formula

def test_occ_tol_with_supercell(self):
"""Test occ_tol parameter behavior with supercell structures."""
# Create a disordered structure
coords = [[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]]
lattice = Lattice(
[[2.9823991724941643, 0.0, 1.8261928001873466e-16],
[4.796063659664723e-16, 2.9823991724941643, 1.8261928001873466e-16],
[0.0, 0.0, 2.9823991724941643]]
)
struct = Structure(lattice, [{"V": 0.75, "Ti": 0.25}, {"V": 0.75, "Ti": 0.25}], coords)

# Create a 5x5x5 supercell structure
supercell = struct * [5, 5, 5]

# Test 1: Default occ_tol (0.25) should raise error
ts_strict = OrderDisorderedStructureTransformation(algo=-1, no_oxi_states=True, occ_tol=0.25)
with pytest.raises(ValueError, match="Occupancy fractions not consistent with size of unit cell"):
StandardTransmuter.from_structures(
[supercell],
transformations=[ts_strict],
extend_collection=3
)

# Test 2: Relaxed occ_tol (0.5) should work
ts_relaxed = OrderDisorderedStructureTransformation(algo=-1, no_oxi_states=True, occ_tol=0.5)
transmuter = StandardTransmuter.from_structures(
[supercell],
transformations=[ts_relaxed],
extend_collection=3
)

# Verify the transformation worked and produced expected composition
transformed_structs = transmuter.transformed_structures
assert len(transformed_structs) == 3
# Check composition matches expected Ti31V94
composition = transformed_structs[0].final_structure.composition
assert composition.reduced_formula== "Ti31V94"

class TestPrimitiveCellTransformation:
def test_apply_transformation(self):
Expand Down

0 comments on commit df17820

Please sign in to comment.