コード例 #1
0
ファイル: test_enumeration.py プロジェクト: lan496/dsenum
def test_zdd_with_naive(kind, num_types, composition_constraints,
                        site_constraints):
    structure = get_lattice(kind)

    for index in range(1, 6 + 1):
        if composition_constraints:
            ratio_sum = sum(composition_constraints)
            if structure.num_sites * index % ratio_sum != 0:
                # Incorrect composition ratio
                continue

        se = StructureEnumerator(
            structure,
            index,
            num_types,
            composition_constraints=composition_constraints,
            base_site_constraints=site_constraints,
            color_exchange=False,
            remove_incomplete=False,
            remove_superperiodic=False,
        )
        zse = ZddStructureEnumerator(
            structure,
            index,
            num_types,
            composition_constraints=composition_constraints,
            base_site_constraints=site_constraints,
            remove_superperiodic=False,
            remove_incomplete=False,
        )

        count_naive = len(se.generate())
        count_zdd = len(zse.generate())
        assert count_zdd == count_naive
コード例 #2
0
ファイル: test_enumeration.py プロジェクト: lan496/dsenum
def test_fixed_colorings_with_polya(kind, num_types):
    structure = get_lattice(kind)
    displacement_set = structure.frac_coords
    num_sites_base = structure.num_sites

    for index in range(num_types, 5):
        list_reduced_HNF, rotations, translations = generate_symmetry_distinct_superlattices(
            index, structure, return_symops=True)
        num_sites = num_sites_base * index
        # TODO: test at more color_ratio cases
        color_ratio = [1] * (num_types - 1) + [
            num_sites - num_types + 1,
        ]
        cl_generator = FixedConcentrationColoringGenerator(
            num_sites, num_types, color_ratio)

        for hnf in tqdm(list_reduced_HNF):
            ds_permutaion = DerivativeStructurePermutation(
                hnf, displacement_set, rotations, translations)
            sc_enum = SiteColoringEnumerator(
                num_types,
                ds_permutaion,
                cl_generator,
                color_exchange=False,
                remove_superperiodic=False,
                remove_incomplete=False,
            )
            colorings = sc_enum.unique_colorings()
            cnt_polya = polya_fixed_degrees_counting(sc_enum.permutation_group,
                                                     num_types, color_ratio)
            assert len(colorings) == cnt_polya
コード例 #3
0
def test_hcp():
    base_structure = get_lattice("hcp")
    num_type = 2
    indices = [2, 3, 4]
    species = [Specie("Cu"), Specie("Au")]

    check(base_structure, num_type, indices, species, "hcp")
コード例 #4
0
def test_sc():
    base_structure = get_lattice("sc")
    num_type = 2
    indices = [2, 3, 4]
    species = [Element("Cu"), Element("Au")]

    check(base_structure, num_type, indices, species, "sc")
コード例 #5
0
def test_fcc():
    base_structure = get_lattice("fcc")
    num_type = 2
    indices = [2, 3, 4]
    species = ["Cu", "Au"]

    check(base_structure, num_type, indices, species, "fcc")
コード例 #6
0
def test_reduce_HNF_list_by_parent_lattice_symmetry(kind, list_expected):
    # Confirm table 4
    structure = get_lattice(kind)
    for index, expected in zip(range(1,
                                     len(list_expected) + 1), list_expected):
        list_reduced_HNF = generate_symmetry_distinct_superlattices(
            index, structure)
        assert len(list_reduced_HNF) == expected
コード例 #7
0
ファイル: test_permutation.py プロジェクト: lan496/dsenum
def test_permutations(kind):
    structure = get_lattice(kind)
    frac_coords = structure.frac_coords
    for index in range(1, 10 + 1):
        list_reduced_HNF, rotations, translations = generate_symmetry_distinct_superlattices(
            index, structure, return_symops=True)
        for hnf in list_reduced_HNF:
            dsperm = DerivativeStructurePermutation(hnf, frac_coords,
                                                    rotations, translations)
            assert is_permutation_group(dsperm.prm_t)
            prm_all = dsperm.get_symmetry_operation_permutations()
            assert is_permutation_group(prm_all)
コード例 #8
0
def test_reduce_HNF_list_by_parent_lattice_symmetry():
    # confirm table 4
    obj = {
        "fcc": {
            "structure": get_lattice("fcc"),
            "num_expected": [1, 2, 3, 7, 5, 10, 7, 20, 14, 18],
        },
        "bcc": {
            "structure": get_lattice("bcc"),
            "num_expected": [1, 2, 3, 7, 5, 10, 7, 20, 14, 18],
        },
        "sc": {"structure": get_lattice("sc"), "num_expected": [1, 3, 3, 9, 5, 13, 7, 24, 14, 23]},
        "hex": {
            "structure": get_lattice("hex"),
            "num_expected": [1, 3, 5, 11, 7, 19, 11, 34, 23, 33],
        },
        "tetragonal": {
            "structure": get_lattice("tet"),
            "num_expected": [1, 5, 5, 17, 9, 29, 13, 51, 28, 53],
        },
        "hcp": {
            "structure": get_lattice("hcp"),
            "num_expected": [1, 3, 5, 11, 7, 19, 11, 34, 23, 33],
        },
    }

    for name, dct in obj.items():
        structure = dct["structure"]
        for index, expected in zip(range(1, len(dct["num_expected"]) + 1), dct["num_expected"]):
            list_reduced_HNF = generate_symmetry_distinct_superlattices(index, structure)
            assert len(list_reduced_HNF) == expected
コード例 #9
0
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)
コード例 #10
0
ファイル: test_enumeration.py プロジェクト: lan496/dsenum
def test_colorings_small(kind, num_types, index_start, num_expected, method):
    # Skip too time-consuming cases...
    max_index = 7

    structure = get_lattice(kind)
    index_end = index_start + len(num_expected)
    for index, expected in zip(range(index_start, index_end), num_expected):
        if index > max_index:
            continue
        se = StructureEnumerator(
            structure,
            index,
            num_types,
            color_exchange=True,
            remove_superperiodic=True,
            method=method,
        )
        actual = se.generate()
        assert len(actual) == expected
コード例 #11
0
ファイル: test_enumeration.py プロジェクト: lan496/dsenum
def test_enumerated_structures(kind, num_types, composition_constraints,
                               site_constraints):
    structure = get_lattice(kind)

    for index in range(1, 5):
        # TODO: when remove_superperiodic = remove_incomplete = False, this test is failed.
        zse = ZddStructureEnumerator(
            structure,
            index,
            num_types,
            composition_constraints=composition_constraints,
            base_site_constraints=site_constraints,
            remove_superperiodic=True,
            remove_incomplete=True,
        )
        list_dstructs = zse.generate()

        stm = StructureMatcher(ltol=1e-4, stol=1e-4)
        grouped = stm.group_structures(list_dstructs)
        assert len(grouped) == len(list_dstructs)
コード例 #12
0
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
コード例 #13
0
ファイル: test_benchmark.py プロジェクト: lan496/dsenum
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)
コード例 #14
0
def test_permutations():
    obj = {
        "fcc": {
            "structure": get_lattice("fcc"),
            "num_type": 2,
            "indices": range(1, 10 + 1)
        },
        "bcc": {
            "structure": get_lattice("bcc"),
            "indices": range(1, 10 + 1)
        },
        "sc": {
            "structure": get_lattice("sc"),
            "indices": range(1, 10 + 1)
        },
        "hex": {
            "structure": get_lattice("hex"),
            "indices": range(1, 10 + 1)
        },
        "tetragonal": {
            "structure": get_lattice("tet"),
            "indices": range(1, 10 + 1)
        },
        "hcp": {
            "structure": get_lattice("hcp"),
            "indices": range(1, 10 + 1)
        },
    }

    for name, dct in obj.items():
        structure = dct["structure"]
        frac_coords = structure.frac_coords
        for index in dct["indices"]:
            list_reduced_HNF, rotations, translations = generate_symmetry_distinct_superlattices(
                index, structure, return_symops=True)
            for hnf in list_reduced_HNF:
                dsperm = DerivativeStructurePermutation(
                    hnf, frac_coords, rotations, translations)
                assert is_permutation_group(dsperm.prm_t)
                prm_all = dsperm.get_symmetry_operation_permutations()
                assert is_permutation_group(prm_all)
コード例 #15
0
            G = PermutationGroup(gens)
            data = {
                "index": index,
                "hnf": hnf,
                "generators": gens,
                "group": G,
                "order": G.order(),
                "orbits": G.orbits(),
            }
            list_data.append(data)

    df = pd.DataFrame(list_data)
    sns.swarmplot(x="index", y="order", data=df)
    plt.title(output_name)
    plt.savefig(output_name + ".png")
    return df


if __name__ == "__main__":
    Permutation.print_cyclic = False

    print("fcc")
    base_structure = get_lattice("fcc")
    df_fcc = plot_permutation_groups(base_structure, "fcc")
    joblib.dump(df_fcc, "fcc.df.joblib")

    print("fcc with tetragonal and octhedral sites")
    base_structure = get_fcc_with_vacancy()
    df_fcc_ot = plot_permutation_groups(base_structure, "fcc_oct_tet")
    joblib.dump(df_fcc_ot, "fcc_oct_tet.df.joblib")
コード例 #16
0
def test_reduce_HNF_list_by_parent_lattice_symmetry_fcc_bcc(kind):
    # https://oeis.org/A045790
    lst_num = [
        1,
        2,
        3,
        7,
        5,
        10,
        7,
        20,
        14,
        18,
        11,
        41,
        15,
        28,
        31,
        58,
        21,
        60,
        25,
        77,
        49,
        54,
        33,
        144,
        50,
        72,
        75,
        123,
        49,
        158,
        55,
        177,
        97,
        112,
        99,
        268,
        75,
        136,
        129,
        286,
        89,
        268,
        97,
        249,
        218,
        190,
        113,
        496,
        146,
        280,
    ]

    structure = get_lattice(kind)
    for index, expected in zip(range(1, len(lst_num) + 1), lst_num):
        if index >= 20:
            continue
        list_reduced_HNF = generate_symmetry_distinct_superlattices(
            index, structure)
        assert len(list_reduced_HNF) == expected