#!/usr/bin/env python # coding: utf-8 # # Introduction # # This notebook demonstrates how to carry out an ordering of a disordered structure using pymatgen. # In[1]: # Let us start by creating a disordered CuAu fcc structure. from pymatgen import Structure, Lattice specie = {"Cu0+": 0.5, "Au0+": 0.5} cuau = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.677), [specie], [[0, 0, 0]]) print cuau # Note that each site is now 50% occupied by Cu and Au. Because the ordering algorithms uses an Ewald summation to rank the structures, you need to explicitly specify the oxidation state for each species, even if it is 0. Let us now perform ordering of these sites using two methods. # ## Method 1 - Using the OrderDisorderedStructureTransformation # # The first method is to use the OrderDisorderedStructureTransformation. # In[2]: from pymatgen.transformations.standard_transformations import OrderDisorderedStructureTransformation trans = OrderDisorderedStructureTransformation() ss = trans.apply_transformation(cuau, return_ranked_list=100) print(len(ss)) print(ss[0]) # Note that the OrderDisorderedTransformation (with a sufficiently large return_ranked_list parameter) returns all orderings, including duplicates without accounting for symmetry. A computed ewald energy is returned together with each structure. To eliminate duplicates, the best way is to use StructureMatcher's group_structures method, as demonstrated below. # In[3]: from pymatgen.analysis.structure_matcher import StructureMatcher matcher = StructureMatcher() groups = matcher.group_structures([d["structure"] for d in ss]) print(len(groups)) print(groups[0][0]) # ## Method 2 - Using the EnumerateStructureTransformation # # If you have enumlib installed, you can use the EnumerateStructureTransformation. This automatically takes care of symmetrically equivalent orderings and can enumerate supercells, but is much more prone to parameter sensitivity and cannot handle very large structures. The example below shows an enumerate of CuAu up to cell sizes of 4. # In[4]: from pymatgen.transformations.advanced_transformations import EnumerateStructureTransformation specie = {"Cu": 0.5, "Au": 0.5} cuau = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.677), [specie], [[0, 0, 0]]) trans = EnumerateStructureTransformation(max_cell_size=3) ss = trans.apply_transformation(cuau, return_ranked_list=1000) # In[5]: print(len(ss)) print("cell sizes are %s" % ([len(d["structure"]) for d in ss])) # Note that structures with cell sizes ranging from 1-3x the unit cell size is generated. # ## Conclusion # # This notebook illustrates two basic ordering/enumeration approaches. In general, OrderDisorderedTransformation works better for large cells and is useful if you need just any quick plausible ordering. EnumerateStructureTransformation is more rigorous, but is prone to sensitivity errors and may require fiddling with various parameters.