|
12 | 12 | from numpy.testing import assert_allclose
|
13 | 13 | from pytest import approx
|
14 | 14 |
|
| 15 | +from pymatgen.alchemy.transmuters import StandardTransmuter |
15 | 16 | from pymatgen.core import Element, PeriodicSite
|
16 | 17 | from pymatgen.core.lattice import Lattice
|
17 | 18 | from pymatgen.symmetry.structure import SymmetrizedStructure
|
@@ -427,6 +428,38 @@ def test_random_sample(self):
|
427 | 428 | output = trafo.apply_transformation(struct * [2, 2, 2], return_ranked_list=False)
|
428 | 429 | assert output.composition.reduced_formula == struct.composition.reduced_formula
|
429 | 430 |
|
| 431 | + def test_occ_tol_with_supercell(self): |
| 432 | + """Test occ_tol parameter behavior with supercell structures.""" |
| 433 | + # Create a disordered structure |
| 434 | + coords = [[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]] |
| 435 | + lattice = Lattice( |
| 436 | + [ |
| 437 | + [2.9823991724941643, 0.0, 1.8261928001873466e-16], |
| 438 | + [4.796063659664723e-16, 2.9823991724941643, 1.8261928001873466e-16], |
| 439 | + [0.0, 0.0, 2.9823991724941643], |
| 440 | + ] |
| 441 | + ) |
| 442 | + struct = Structure(lattice, [{"V": 0.75, "Ti": 0.25}, {"V": 0.75, "Ti": 0.25}], coords) |
| 443 | + |
| 444 | + # Create a 5x5x5 supercell structure |
| 445 | + supercell = struct * [5, 5, 5] |
| 446 | + |
| 447 | + # Test 1: Default occ_tol (0.25) should raise error |
| 448 | + ts_strict = OrderDisorderedStructureTransformation(algo=-1, no_oxi_states=True, occ_tol=0.25) |
| 449 | + with pytest.raises(ValueError, match="Occupancy fractions not consistent with size of unit cell"): |
| 450 | + StandardTransmuter.from_structures([supercell], transformations=[ts_strict], extend_collection=3) |
| 451 | + |
| 452 | + # Test 2: Relaxed occ_tol (0.5) should work |
| 453 | + ts_relaxed = OrderDisorderedStructureTransformation(algo=-1, no_oxi_states=True, occ_tol=0.5) |
| 454 | + transmuter = StandardTransmuter.from_structures([supercell], transformations=[ts_relaxed], extend_collection=3) |
| 455 | + |
| 456 | + # Verify the transformation worked and produced expected composition |
| 457 | + transformed_structs = transmuter.transformed_structures |
| 458 | + assert len(transformed_structs) == 3 |
| 459 | + # Check composition matches expected Ti31V94 |
| 460 | + composition = transformed_structs[0].final_structure.composition |
| 461 | + assert composition.reduced_formula == "Ti31V94" |
| 462 | + |
430 | 463 |
|
431 | 464 | class TestPrimitiveCellTransformation:
|
432 | 465 | def test_apply_transformation(self):
|
|
0 commit comments