def _add_dummy_species(structure, order_parameters):
        """
        :param structure: ordered Structure
        :param order_parameters: list of MagOrderParameterConstraints
        :return: A structure decorated with disordered
        DummySpecies on which to perform the enumeration.
        Note that the DummySpecies are super-imposed on
        to the original sites, to make it easier to
        retrieve the original site after enumeration is
        performed (this approach is preferred over a simple
        mapping since multiple species may have the same
        DummySpecie, depending on the constraints specified).
        This approach can also preserve site properties even after
        enumeration.
        """

        dummy_struct = structure.copy()

        def generate_dummy_specie():
            """
            Generator which returns DummySpecie symbols Mma, Mmb, etc.
            """
            subscript_length = 1
            while True:
                for subscript in product(ascii_lowercase, repeat=subscript_length):
                    yield "Mm" + "".join(subscript)
                subscript_length += 1

        dummy_species_gen = generate_dummy_specie()

        # one dummy species for each order parameter constraint
        dummy_species_symbols = [next(dummy_species_gen) for i in range(len(order_parameters))]
        dummy_species = [{
                             DummySpecie(symbol, properties={'spin': Spin.up}): constraint.order_parameter,
                             DummySpecie(symbol, properties={'spin': Spin.down}): 1 - constraint.order_parameter
                         } for symbol, constraint in zip(dummy_species_symbols, order_parameters)]

        sites_to_add = []

        for idx, site in enumerate(dummy_struct):
            satisfies_constraints = [c.satisfies_constraint(site) for c in order_parameters]
            if satisfies_constraints.count(True) > 1:
                # site should either not satisfy any constraints, or satisfy
                # one constraint
                raise ValueError("Order parameter constraints conflict for site: {}, {}"
                                 .format(str(site.specie), site.properties))
            elif any(satisfies_constraints):
                dummy_specie_idx = satisfies_constraints.index(True)
                dummy_struct.append(
                    dummy_species[dummy_specie_idx],
                    site.coords,
                    site.lattice
                )

        return dummy_struct
def _add_dummy_species ( structure , order_parameters ) : dummy_struct = structure . copy ( ) def generate_dummy_specie ( ) : subscript_length = 1 while True : for subscript in product ( ascii_lowercase , repeat = subscript_length ) : yield "Mm" + "" . join ( subscript ) subscript_length += 1 dummy_species_gen = generate_dummy_specie ( ) dummy_species_symbols = [ next ( dummy_species_gen ) for i in range ( len ( order_parameters ) ) ] dummy_species = [ { DummySpecie ( symbol , properties = { 'spin' : Spin . up } ) : constraint . order_parameter , DummySpecie ( symbol , properties = { 'spin' : Spin . down } ) : 1 - constraint . order_parameter } for symbol , constraint in zip ( dummy_species_symbols , order_parameters ) ] sites_to_add = [ ] for idx , site in enumerate ( dummy_struct ) : satisfies_constraints = [ c . satisfies_constraint ( site ) for c in order_parameters ] if satisfies_constraints . count ( True ) > 1 : raise ValueError ( "Order parameter constraints conflict for site: {}, {}" . format ( str ( site . specie ) , site . properties ) ) elif any ( satisfies_constraints ) : dummy_specie_idx = satisfies_constraints . index ( True ) dummy_struct . append ( dummy_species [ dummy_specie_idx ] , site . coords , site . lattice ) return dummy_struct
:param structure: ordered Structure
        :param order_parameters: list of MagOrderParameterConstraints
        :return: A structure decorated with disordered
        DummySpecies on which to perform the enumeration.
        Note that the DummySpecies are super-imposed on
        to the original sites, to make it easier to
        retrieve the original site after enumeration is
        performed (this approach is preferred over a simple
        mapping since multiple species may have the same
        DummySpecie, depending on the constraints specified).
        This approach can also preserve site properties even after
        enumeration.