Exemple #1
0
def check(base_structure, num_type, indices, species, name):
    for index in indices:
        se = StructureEnumerator(
            base_structure,
            index,
            num_type,
            species,
            color_exchange=True,
            leave_superperiodic=False,
        )
        list_ds = se.generate()

        stm = StructureMatcher(ltol=1e-4, stol=1e-4)
        grouped = stm.group_structures(list_ds)
        assert len(grouped) == len(list_ds)
Exemple #2
0
def test_lexicographic_with_composition(benchmark):
    setting = get_common_settings()
    setting["method"] = "lexicographic"
    setting["composition_constraints"] = [1, 3, 2]
    se = StructureEnumerator(**setting)

    benchmark.pedantic(se.generate, iterations=1)
Exemple #3
0
def test_site_constraints(method, benchmark):
    setting = {
        "base_structure":
        get_rutile_structure(),
        "index":
        4,
        "num_types":
        3,
        "base_site_constraints": [
            [2],  # 2a
            [2],  # 2a
            [0, 1],  # 4f
            [0, 1],  # 4f
            [0, 1],  # 4f
            [0, 1],  # 4f
        ],
        "remove_incomplete":
        True,
        "remove_superperiodic":
        True,
    }

    if method == "direct":
        se = StructureEnumerator(**setting)
        benchmark.pedantic(se.generate,
                           kwargs={"output": "poscar"},
                           iterations=1)
    else:
        zse = ZddStructureEnumerator(**setting)
        if method == "zdd":
            benchmark.pedantic(zse.generate,
                               kwargs={"output": "poscar"},
                               iterations=1)
        elif method == "zdd_count":
            benchmark.pedantic(zse.count, iterations=1)
def test_basic_structure(kind, index):
    base_structure = get_lattice(kind)
    num_type = 2
    species = ["Cu", "Au"]

    se = StructureEnumerator(
        base_structure,
        index,
        num_type,
        species,
        color_exchange=True,
        remove_superperiodic=True,
    )
    list_ds = se.generate()

    stm = StructureMatcher(ltol=1e-4, stol=1e-4)
    grouped = stm.group_structures(list_ds)
    assert len(grouped) == len(list_ds)
def test_poscar_string(kind):
    base_structure = get_lattice(kind)
    num_type = 2
    index = 4
    species = [Element("Cu"), Element("Au")]

    se = StructureEnumerator(
        base_structure,
        index,
        num_type,
        species,
        color_exchange=True,
        remove_superperiodic=True,
    )
    list_ds_mg = se.generate(output="pymatgen")
    list_ds_pc = se.generate(output="poscar")

    assert len(list_ds_mg) == len(list_ds_pc)
    for expect, poscar_str in zip(list_ds_mg, list_ds_pc):
        actual = Poscar.from_string(poscar_str).structure
        assert expect == actual
Exemple #6
0
def test_lexicographic_with_site(benchmark):
    setting = get_common_settings()
    setting["method"] = "lexicographic"
    setting["base_site_constraints"] = [
        [2],  # 2a
        [2],  # 2a
        [0, 1],  # 4f
        [0, 1],  # 4f
        [0, 1],  # 4f
        [0, 1],  # 4f
    ]
    se = StructureEnumerator(**setting)

    benchmark.pedantic(se.generate, iterations=1)
Exemple #7
0
def test_direct_with_composition_and_site(benchmark):
    setting = get_common_settings()
    setting["method"] = "direct"
    setting["composition_constraints"] = [1, 3, 2]
    setting["base_site_constraints"] = [
        [2],  # 2a
        [2],  # 2a
        [0, 1],  # 4f
        [0, 1],  # 4f
        [0, 1],  # 4f
        [0, 1],  # 4f
    ]
    se = StructureEnumerator(**setting)

    benchmark.pedantic(se.generate, iterations=1)
Exemple #8
0
def test_coloring_with_fixed_species():
    lattice = Lattice(3.945 * np.eye(3))
    species = ["Sr", "Ti", "O", "O", "O"]
    frac_coords = np.array([[0, 0, 0], [0.5, 0.5, 0.5], [0.0, 0.5, 0.5],
                            [0.5, 0.0, 0.5], [0.5, 0.5, 0.0]])
    aristo = Structure(lattice, species, frac_coords)
    base_structure = aristo.copy()
    base_structure.remove_species(["Sr", "Ti"])
    additional_species = species[:2]
    additional_frac_coords = frac_coords[:2]

    mapping_color_species = [DummySpecie("X"), "O"]
    num_types = len(mapping_color_species)
    index = 2

    se = StructureEnumerator(
        base_structure,
        index,
        num_types,
        mapping_color_species=mapping_color_species,
        color_exchange=False,
        leave_superperiodic=False,
        use_all_colors=False,
    )
    list_dstructs = se.generate(additional_species=additional_species,
                                additional_frac_coords=additional_frac_coords)

    # with base_site_constraints
    mapping_color_species2 = [DummySpecie("X"), "O", "Sr", "Ti"]
    num_types2 = len(mapping_color_species2)
    base_site_constraints = [
        [2],  # Sr site
        [3],  # Cu site
        [0, 1],  # O or V
        [0, 1],  # O or V
        [0, 1],  # O or V
    ]
    se2 = StructureEnumerator(
        aristo,
        index,
        num_types2,
        mapping_color_species=mapping_color_species2,
        base_site_constraints=base_site_constraints,
        color_exchange=False,
        leave_superperiodic=False,
        use_all_colors=False,
    )
    list_dstructs2 = se2.generate()

    # check uniqueness by StructureMatcher
    stm = StructureMatcher(ltol=1e-4, stol=1e-4)
    grouped = stm.group_structures(list_dstructs + list_dstructs2)
    assert len(grouped) == len(list_dstructs)
    assert all([(len(matched) == 2) for matched in grouped])
def test_coloring_with_fixed_species(sto_perovskite: Structure):
    base_structure = sto_perovskite.copy()
    base_structure.remove_species(["Sr", "Ti"])
    additional_species = sto_perovskite.species[:2]
    additional_frac_coords = sto_perovskite.frac_coords[:2]

    mapping_color_species = [DummySpecie("X"), "O"]
    num_types = len(mapping_color_species)
    index = 2

    se = StructureEnumerator(
        base_structure,
        index,
        num_types,
        mapping_color_species=mapping_color_species,
        color_exchange=False,
        remove_superperiodic=True,
        remove_incomplete=False,
    )
    list_dstructs = se.generate(additional_species=additional_species,
                                additional_frac_coords=additional_frac_coords)

    # with base_site_constraints
    mapping_color_species2 = [DummySpecie("X"), "O", "Sr", "Ti"]
    num_types2 = len(mapping_color_species2)
    base_site_constraints = [
        [2],  # Sr site
        [3],  # Cu site
        [0, 1],  # O or V
        [0, 1],  # O or V
        [0, 1],  # O or V
    ]
    se2 = StructureEnumerator(
        sto_perovskite,
        index,
        num_types2,
        mapping_color_species=mapping_color_species2,
        base_site_constraints=base_site_constraints,
        color_exchange=False,
        remove_superperiodic=True,
        remove_incomplete=False,
    )
    list_dstructs2 = se2.generate()

    # check uniqueness by StructureMatcher
    stm = StructureMatcher(ltol=1e-4, stol=1e-4)
    grouped = stm.group_structures(list_dstructs +
                                   list_dstructs2)  # type: ignore
    assert len(grouped) == len(list_dstructs)
    assert all([(len(matched) == 2) for matched in grouped])
Exemple #10
0
def test_basic_ternary(method, benchmark):
    setting = {
        "base_structure": get_lattice("fcc"),
        "index": 10,
        "num_types": 3,
        "remove_incomplete": True,
        "remove_superperiodic": True,
    }

    if method == "direct":
        se = StructureEnumerator(**setting)
        benchmark.pedantic(se.generate,
                           kwargs={"output": "poscar"},
                           iterations=1)
    else:
        zse = ZddStructureEnumerator(**setting)
        if method == "zdd":
            benchmark.pedantic(zse.generate,
                               kwargs={"output": "poscar"},
                               iterations=1)
        elif method == "zdd_count":
            benchmark.pedantic(zse.count, iterations=1)
Exemple #11
0
def test_lexicographic(benchmark):
    setting = get_common_settings()
    setting["method"] = "lexicographic"
    se = StructureEnumerator(**setting)

    benchmark.pedantic(se.generate, iterations=1)
Exemple #12
0
def test_direct(benchmark):
    setting = get_common_settings()
    setting["method"] = "direct"
    se = StructureEnumerator(**setting)

    benchmark.pedantic(se.generate, iterations=1)
Exemple #13
0
        [0, 1],  # 4f
        [0, 1],  # 4f
        [0, 1],  # 4f
    ]
    # fmt: on

    dirname = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                           "SnO1-x")
    os.makedirs(dirname, exist_ok=True)

    for index in range(1, max_index + 1):
        se = StructureEnumerator(
            rutile,
            index,
            num_types,
            mapping_color_species=mapping_color_species,
            composition_constraints=composition_constraints,
            base_site_constraints=base_site_constraints,
            color_exchange=False,
            leave_superperiodic=False,
            use_all_colors=False,
        )
        list_dstructs = se.generate()

        for i, dstruct in enumerate(list_dstructs):
            # remove void
            dstruct.remove_species([mapping_color_species[0]])

            filename = os.path.join(dirname, f"SnO1-x_{index}_{i}.cif")
            write_cif(filename, dstruct, refine_cell=True)
Exemple #14
0
                            [0.5, 0.0, 0.5], [0.5, 0.5, 0.0]])
    aristo = Structure(lattice, species, frac_coords)
    base_structure = aristo.copy()
    base_structure.remove_species(["Sr", "Ti"])
    additional_species = species[:2]
    additional_frac_coords = frac_coords[:2]

    mapping_color_species = [DummySpecie("X"), "O"]
    num_types = len(mapping_color_species)
    index = 2

    se = StructureEnumerator(
        base_structure,
        index,
        num_types,
        mapping_color_species=mapping_color_species,
        color_exchange=False,
        leave_superperiodic=False,
        use_all_colors=False,
    )
    list_dstructs = se.generate(additional_species=additional_species,
                                additional_frac_coords=additional_frac_coords)

    # leave only SrTiO_{3-x} (0 <= x <= 1)
    num_oxygen_lb = index * 2
    num_oxygen_ub = index * 3
    structures = []
    for ds in list_dstructs:
        num_oxygen = sum([(str(sp) == "O") for sp in ds.species])
        if num_oxygen_lb <= num_oxygen and num_oxygen <= num_oxygen_ub:
            structures.append(ds)