Beispiel #1
0
    def from_dict(cls, d):
        """

        Parameters
        ----------
        d: dict

        Returns
        -------
        site_centers: list
            Center coordinates at each groups
        groups: list
            List of groups
        """
        site_centers = read_matrix(d["coords"])
        groups = []
        for g in d["groups"]:
            name = g["name"]
            species = g.get("species", [name])
            n = len(species)

            coords = read_tensor(g.get("coords", [[[0, 0, 0]]]), rank=3)
            m = coords.shape[1]
            if n != 0 and m != n:
                raise InputError(
                    'number of atoms mismatch in group [{}]: "species"={}, "coords"={}'
                    .format(name, n, m))

            relaxation = read_matrix(g.get("relaxation", np.ones((n, 3))),
                                     dtype=bool)
            m = relaxation.shape[0]
            if n != 0 and m != n:
                raise InputError(
                    'number of atoms mismatch in group [{}]: "species"={}, "relaxation"={}'
                    .format(name, n, m))

            mag = read_vector(g.get("magnetization", np.zeros(n)))
            m = len(mag)
            if n != 0 and m != n:
                raise InputError(
                    'number of atoms mismatch in group [{}]: "species"={}, "magnetization"={}'
                    .format(name, n, m))
            groups.append(
                group(
                    name,
                    species,
                    coords=coords,
                    relaxations=relaxation,
                    magnetizations=mag,
                ))
        return cls(site_centers, groups)
Beispiel #2
0
    def __init__(self, dconfig):
        """
        Get information from dictionary

        Parameters
        ----------
        dconfig: dict
            Dictionary
        """

        if "config" in dconfig:
            dconfig = dconfig["config"]

        if "unitcell" not in dconfig:
            raise InputError(
                '"unitcell" is not found in the "config" section.')
        self.lat = Lattice(read_matrix(dconfig["unitcell"]))

        self.supercell = dconfig.get("supercell", [1, 1, 1])
        if "base_structure" not in dconfig:
            raise InputError(
                '"base_structure" is not found in the "config" section.')
        self.base_structure = base_structure(self.lat,
                                             dconfig["base_structure"])

        if "defect_structure" not in dconfig:
            raise InputError(
                '"defect_structure" is not found in the "config" section.')
        self.defect_sublattices = [
            defect_sublattice.from_dict(ds)
            for ds in dconfig["defect_structure"]
        ]
        self.num_defects = [{g["name"]: g["num"]
                             for g in ds["groups"]}
                            for ds in dconfig["defect_structure"]]
Beispiel #3
0
def base_structure(lat, dict_str):
    """

    Parameters
    ----------
    lat: pymatgen.Lattice
    dict_str: dict
        Dictionary of base structure

    Returns
    -------
    st: pymatgen.Structure
    """
    if len(dict_str) == 1 and not dict_str[0]:
        return Structure(
            lattice=lat,
            species=[],
            coords=[],
            site_properties={
                "seldyn": np.zeros((0, 3), dtype=bool),
                "magnetization": np.zeros(0),
            },
        )
    elems = []
    coords = []
    relaxations = []
    magnetizations = []
    for tc in dict_str:
        if "type" not in tc:
            raise InputError('"type" is not found in "base_structure"')
        sp = tc["type"]
        crds = read_matrix(tc["coords"])
        n = crds.shape[0]

        if "relaxation" in tc:
            relax = read_matrix(tc["relaxation"], dtype=bool)
            m = relax.shape[0]
            if m != n:
                raise InputError(
                    'number of base atoms mismatch: "coords"={}, "relaxation"={}'
                    .format(n, m))
        else:
            relax = np.ones((n, 3), dtype=bool)  # all True

        if "magnetization" in tc:
            mag = tc["magnetization"]
            if not isinstance(mag, list):
                raise InputError('"magnetization" should be a list of floats')
            try:
                mag = [float(x) for x in mag]
            except ValueError:
                raise InputError('"magnetization" should be a list of floats')
            m = len(mag)
            if m != n:
                raise InputError(
                    'number of base atoms mismatch: "coords"={}, "magnetization"={}'
                    .format(n, m))
        else:
            mag = np.zeros(n)

        elems.append([sp] * n)
        coords.append(crds)
        relaxations.append(relax)
        magnetizations.append(mag)
    elems = sum(elems, [])
    coords = np.concatenate(coords, axis=0)
    relaxations = np.concatenate(relaxations, axis=0)
    magnetizations = np.concatenate(magnetizations, axis=0)

    return Structure(
        lattice=lat,
        species=elems,
        coords=coords,
        site_properties={
            "seldyn": relaxations,
            "magnetization": magnetizations
        },
    )