19
19
from pymatgen .core .operations import SymmOp
20
20
from pymatgen .core .structure import Lattice , Structure
21
21
from pymatgen .symmetry .analyzer import SpacegroupAnalyzer
22
+ from pymatgen .symmetry .structure import SymmetrizedStructure
22
23
from pymatgen .transformations .site_transformations import PartialRemoveSitesTransformation
23
24
from pymatgen .transformations .transformation_abc import AbstractTransformation
24
25
@@ -454,7 +455,15 @@ class OrderDisorderedStructureTransformation(AbstractTransformation):
454
455
ALGO_BEST_FIRST = 2
455
456
ALGO_RANDOM = - 1
456
457
457
- def __init__ (self , algo = ALGO_FAST , symmetrized_structures = False , no_oxi_states = False , occ_tol = 0.25 ):
458
+ def __init__ (
459
+ self ,
460
+ algo : int = ALGO_FAST ,
461
+ symmetrized_structures : bool = False ,
462
+ no_oxi_states : bool = False ,
463
+ occ_tol : float = 0.25 ,
464
+ symprec : float | None = None ,
465
+ angle_tolerance : float | None = None ,
466
+ ):
458
467
"""
459
468
Args:
460
469
algo (int): Algorithm to use.
@@ -466,15 +475,23 @@ def __init__(self, algo=ALGO_FAST, symmetrized_structures=False, no_oxi_states=F
466
475
occ_tol (float): Occupancy tolerance. If the total occupancy of a group is within this value
467
476
of an integer, it will be rounded to that integer otherwise raise a ValueError.
468
477
Defaults to 0.25.
478
+ symprec : float or None (default)
479
+ If a float, and symmetrized_structures is True, the linear tolerance
480
+ used to symmetrize structures with SpacegroupAnalyzer.
481
+ angle_tolerance : float or None (default)
482
+ If a float, and symmetrized_structures is True, the angle tolerance
483
+ used to symmetrize structures with SpacegroupAnalyzer.
469
484
"""
470
485
self .algo = algo
471
486
self ._all_structures : list = []
472
487
self .no_oxi_states = no_oxi_states
473
488
self .symmetrized_structures = symmetrized_structures
489
+ self .symprec = symprec
490
+ self .angle_tolerance = angle_tolerance
474
491
self .occ_tol = occ_tol
475
492
476
493
def apply_transformation (
477
- self , structure : Structure , return_ranked_list : bool | int = False
494
+ self , structure : Structure | SymmetrizedStructure , return_ranked_list : bool | int = False
478
495
) -> Structure | list [Structure ] | list [dict [str , Any ]]:
479
496
"""For this transformation, the apply_transformation method will return
480
497
only the ordered structure with the lowest Ewald energy, to be
@@ -510,6 +527,11 @@ def apply_transformation(
510
527
for idx , site in enumerate (structure ):
511
528
structure [idx ] = {f"{ k .symbol } 0+" : v for k , v in site .species .items ()} # type: ignore[assignment]
512
529
530
+ if self .symmetrized_structures and not isinstance (structure , SymmetrizedStructure ):
531
+ structure = SpacegroupAnalyzer (
532
+ structure , ** {k : getattr (self , k ) for k in ("symprec" , "angle_tolerance" ) if getattr (self , k , None )}
533
+ ).get_symmetrized_structure ()
534
+
513
535
equivalent_sites : list [list [int ]] = []
514
536
exemplars : list [PeriodicSite ] = []
515
537
# generate list of equivalent sites to order
0 commit comments