Skip to content

gemdat.io

This module contains functions to read and write data.

get_list_of_known_materials()

Return list of known materials.

Returns:

  • list[str] –

    List with names of known materials

Source code in src/gemdat/io.py
 92
 93
 94
 95
 96
 97
 98
 99
100
def get_list_of_known_materials() -> list[str]:
    """Return list of known materials.

    Returns
    -------
    list[str]
        List with names of known materials
    """
    return [fn.stem for fn in DATA.glob('*.cif')]

load_known_material(name, supercell=None)

Load known material from internal database.

Parameters:

  • name (str) –

    Name of the material

  • supercell (tuple(int, int, int) | None, default: None ) –

    Optionally, scale the lattice by a sequence of three factors. For example, (2, 1, 1) specifies that the supercell should have dimensions \(2a \times b \times c\).

Returns:

  • structure ( Structure ) –

    Output structure

Source code in src/gemdat/io.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def load_known_material(
    name: str,
    supercell: tuple[int, int, int] | None = None,
) -> Structure:
    """Load known material from internal database.

    Parameters
    ----------
    name : str
        Name of the material
    supercell : tuple(int, int, int) | None, optional
        Optionally, scale the lattice by a sequence of three factors.
        For example, `(2, 1, 1)` specifies that the supercell should have
        dimensions $2a \\times b \\times c$.

    Returns
    -------
    structure : pymatgen.core.structure.Structure
        Output structure
    """
    filename = (DATA / name).with_suffix('.cif')

    if not filename.exists():
        raise ValueError(f'Unknown material: {name}')

    structure = read_cif(filename)

    if supercell:
        structure.make_supercell(supercell)

    return structure

read_cif(filename)

Load cif file and return first item as pymatgen.core.structure.Structure.

Parameters:

  • filename (Path | str) –

    Filename of the structure in CIF format of

Returns:

  • structure ( Structure ) –

    Output structure

Source code in src/gemdat/io.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def read_cif(filename: Path | str) -> Structure:
    """Load cif file and return first item as
    [pymatgen.core.structure.Structure][].

    Parameters
    ----------
    filename : Path | str
        Filename of the structure in CIF format of

    Returns
    -------
    structure : pymatgen.core.structure.Structure
        Output structure
    """
    with warnings.catch_warnings():
        # Hide warning from https://github.com/materialsproject/pymatgen/pull/3419
        warnings.simplefilter('ignore')
        structure = Structure.from_file(filename, primitive=False)

    return structure

write_cif(structure, filename)

Write structure to cif file using pymatgen.io.cif.CifWriter.

Parameters:

  • structure (Structure) –

    Structure to save

  • filename (Path | str) –

    Filename to write to

Source code in src/gemdat/io.py
23
24
25
26
27
28
29
30
31
32
33
34
def write_cif(structure: Structure, filename: Path | str):
    """Write structure to cif file using [pymatgen.io.cif.CifWriter][].

    Parameters
    ----------
    structure : pymatgen.core.structure.Structure
        Structure to save
    filename : Path | str
        Filename to write to
    """
    filename = Path(filename).with_suffix('.cif')
    structure.to_file(filename)