Ejemplo n.º 1
0
    def get_string(self):
        """
        Returns a string representation of atomic shell coordinates.

        Returns:
            String representation of Atomic Coordinate Shells.
        """
        center_index = self.struct.indices_from_symbol(self.central_atom)[0]
        center = self.struct[center_index].coords
        sphere = Structure.get_sites_in_sphere(self.struct, center, self.radius)

        row = []
        for i, site_dist in enumerate(sphere):
            site_symbol = re.sub(r"[^aA-zZ]+", "", site_dist[0].species_string)
            ipot = self.pot_dict[site_symbol]
            coords = site_dist[0].coords - center
            row.append(["{:f}".format(coords[0]), "{:f}".format(coords[1]),
                        "{:f}".format(coords[2]), ipot, site_symbol,
                        "{:f}".format(site_dist[1]), i])

        row_sorted = str(tabulate(sorted(row, key=itemgetter(5)),
                                  headers=["*       x", "y", "z", "ipot",
                                           "Atom", "Distance", "Number"]))
        atom_list = row_sorted.replace("--", "**")

        return ''.join(["ATOMS\n", atom_list, "\nEND\n"])
Ejemplo n.º 2
0
def get_supercell_site(unit: Structure, supercell: Structure, site_i: int, image: tuple):
    coords = unit[site_i].frac_coords # get coords from unit_cell
    scale = np.array(unit.lattice.abc) / supercell.lattice.abc
    coords = coords * scale # Scale coords from supercell
    coords = coords + (scale * image) # scale coords to image
    sites = supercell.get_sites_in_sphere(supercell.lattice.get_cartesian_coords(coords), 0.001, include_index=True)
    if len(sites) != 1:
        raise Exception('Wrong number of sites at supercell destination {}'.format(sites))
    new_site = sites[0][2]
    return new_site
Ejemplo n.º 3
0
def get_center_i(structure : Structure, element : Element, skew_positive=True, delta=0.05):
    center_coords = structure.lattice.get_cartesian_coords([0.5, 0.5, 0.5])
    sites = structure.get_sites_in_sphere(center_coords, 4, include_index=True)
    sites.sort(key=lambda x : x[1])
    best_i = None
    best_dist = 999999
    best_location = 3
    for (site, dist, i) in sites: #type: PeriodicSite
        if site.specie == element:
            if dist < best_dist+delta:
                if sum(1 - (site.frac_coords % 1)) < best_location:
                    best_i = i
                    best_dist = best_dist
                    best_location = sum(1 - site.frac_coords)
    if best_i:
        return best_i
    raise Exception('Could not find specified {}'.format(element))
Ejemplo n.º 4
0
def remove_unstable_interstitials(structure: Structure, relaxed_interstitials: list, dist=0.2, site_indices=None):
    """

    :param structure: Structure decorated with all interstitials
    :param relaxed_interstitials: list of structures with interstitial as last index
    :param dist: tolerance for determining if site belongs to another site
    :return:
    """
    to_keep = list(range(len(relaxed_interstitials[0])-1))
    try:
        sga = SpacegroupAnalyzer(structure, symprec=0.1)
        structure = sga.get_symmetrized_structure()
    except TypeError:
        sga = SpacegroupAnalyzer(structure, symprec=0.01)
        structure = sga.get_symmetrized_structure()
    for ri in relaxed_interstitials:  #type:  Structure
        sites=structure.get_sites_in_sphere(ri.cart_coords[-1], dist, include_index=True)

        for indices in structure.equivalent_indices:  #look at all sets of equivalent indices
            index = sites[0][2]
            if index in to_keep: # Already keeping this index
                continue
            if index in indices:
                to_keep = to_keep + indices  #keep equivalent indices
                break

        if len(sites) != 1: # make sure only one site is found
            okay = False
            if len(sites) > 1:
                if all([ x[2] in indices for x in sites]):
                    okay = True
            if not okay:
                if site_indices:
                    raise Exception('Found {} sites for {}'.format(len(sites), site_indices[relaxed_interstitials.index(ri)]))
                raise Exception('Found {} sites'.format(len(sites)))
    to_remove = [i for i in range(len(structure)) if i not in to_keep]
    structure.remove_sites(to_remove)
    return structure
Ejemplo n.º 5
0
def perturb_structure(structure: Structure, center: List[float],
                      cutoff: float) -> Structure:
    """ structure perturbation

    Args:
        structure: pmg Structure class object
        center: Fractional coordinates of a central position.
        cutoff: Radius of a sphere in which atoms are perturbed.
    """
    result = structure.copy()
    cartesian_coords = structure.lattice.get_cartesian_coords(center)
    neighboring_atoms = structure.get_sites_in_sphere(pt=cartesian_coords,
                                                      r=cutoff,
                                                      include_index=True)

    #    assert cutoff < min(structure.lattice.lengths) / 2.0

    # neighboring_atom is composed of (PeriodicSite, distance, index)
    for _, _, site_index in neighboring_atoms:
        vector = random_3d_vector(defaults.displace_distance)
        result.translate_sites(site_index, vector, frac_coords=False)

    return result