Пример #1
0
 def get_all_nn_info_old(self, structure: Structure) -> List[Dict]:
     nn_info = []
     all_neighbors = structure.get_all_neighbors(self.cutoff,
                                                 include_index=True,
                                                 include_image=True)
     for n, neighd_dists in enumerate(all_neighbors):
         siw = []
         for _, dist, ind, image in neighd_dists:
             siw.append({'image': image, 'weight': dist, 'site_index': ind})
         nn_info.append(siw)
     return nn_info
def get_neighbor_distances_data_frame(cell_structure: Structure,
                                      r: float) -> DataFrame:
    """Get data frame of pairwise neighbor distances for each atom in the unit cell,
    out to a distance ``r``.

    :param cell_structure: A pymatgen ``Structure`` object.
    :param r: Radius of sphere.
    :return: A pandas ``DataFrame`` of pairwise neighbor distances.
    """
    all_neighbors: AllNeighborDistances = cell_structure.get_all_neighbors(
        r=r, include_index=True)

    neighbor_distances: NeighborDistances = extract_neighbor_distance_data(
        cell_structure=cell_structure, all_neighbors=all_neighbors)

    return DataFrame(data=neighbor_distances)
Пример #3
0
def gii_fun(x, *args):

    cations = args[0]
    anions = args[1]
    lattice = args[2]
    Species_list = args[3]
    num_atoms = args[4]
    cutoff_distance = args[5]
    BVpara = args[6]
    Formal_Valence = args[7]
    wycks = args[8]
    space_group = args[9]
    b0 = args[10]
    center_atom_in_regular_poly = args[11]
    max_angle = args[12]
    nearest_neighbor_distance = args[13]

    struct = Structure(lattice, Species_list, x.reshape(num_atoms, 3))

    pymat_neighbors = struct.get_all_neighbors(cutoff_distance,
                                               include_index=True)

    values_BV = []

    for atom_indx, neigh_data in enumerate(pymat_neighbors):
        bv = 0
        for pair_data in neigh_data:

            atom = struct.species[atom_indx].symbol
            neighbor = struct.species[pair_data[2]].symbol

            if iscation(atom, cations) and isanion(neighbor, anions):
                #
                bv += np.exp((BVpara[atom][neighbor] - pair_data[1]) / b0)
            elif iscation(neighbor, cations) and isanion(atom, anions):

                bv += np.exp((BVpara[neighbor][atom] - pair_data[1]) / b0)
        values_BV.append(
            (Formal_Valence[struct.species[atom_indx].symbol] - bv)**2)

    GII_val = np.sqrt((sum(values_BV[:])) / struct.composition.num_atoms)
    #print "curent GII = {}".format(GII_val)
    return GII_val
Пример #4
0
    def _GetSiteEnvironments(cls,
                             coord,
                             cell,
                             SiteTypes,
                             cutoff,
                             pbc,
                             get_permutations=True,
                             eigen_tol=1e-5):
        """Extract local environments from primitive cell
        
        Parameters
        ----------
        coord : n x 3 list or numpy array of scaled positions. n is the number 
            of atom.
        cell : 3 x 3 list or numpy array
        SiteTypes : n list of string. String must be S or A followed by a 
            number. S indicates a spectator sites and A indicates a active 
            sites.
        cutoff : float. cutoff distance in angstrom for collecting local
            environment.
        pbc : list of boolean. Periodic boundary condition
        get_permutations : boolean. Whether to find permutatated neighbor list or not.
        eigen_tol : tolerance for eigenanalysis of point group analysis in
            pymatgen.
        
        Returns
        ------
        list of local_env : list of local_env class
        """
        #%% Check error
        assert isinstance(coord, (list, np.ndarray))
        assert isinstance(cell, (list, np.ndarray))
        assert len(coord) == len(SiteTypes)
        #%% Initialize
        # TODO: Technically, user doesn't even have to supply site index, because
        #       pymatgen can be used to automatically categorize sites..
        coord = np.mod(coord, 1)
        pbc = np.array(pbc)
        #%% Map sites to other elements..
        # TODO: Available pymatgne functions are very limited when DummySpecie is
        #       involved. This may be perhaps fixed in the future. Until then, we
        #       simply bypass this by mapping site to an element
        # Find available atomic number to map site to it
        availableAN = [i + 1 for i in reversed(range(0, 118))]

        # Organize Symbols and record mapping
        symbols = []
        site_idxs = []
        SiteSymMap = {}  # mapping
        SymSiteMap = {}
        for i, SiteType in enumerate(SiteTypes):
            if SiteType not in SiteSymMap:
                symbol = Element.from_Z(availableAN.pop())
                SiteSymMap[SiteType] = symbol
                SymSiteMap[symbol] = SiteType

            else:
                symbol = SiteSymMap[SiteType]
            symbols.append(symbol)
            if 'A' in SiteType:
                site_idxs.append(i)
        #%% Get local environments of each site
        # Find neighbors and permutations using pymatgen
        lattice = Lattice(cell)
        structure = Structure(lattice, symbols, coord)
        neighbors = structure.get_all_neighbors(cutoff, include_index=True)
        site_envs = []
        for site_idx in site_idxs:
            local_env_sym = [symbols[site_idx]]
            local_env_xyz = [structure[site_idx].coords]
            local_env_dist = [0.0]
            local_env_sitemap = [site_idx]
            for n in neighbors[site_idx]:
                # if PBC condition is fulfilled..
                c = np.around(n[0].frac_coords, 10)
                withinPBC = np.logical_and(0 <= c, c < 1)
                if np.all(withinPBC[~pbc]):
                    local_env_xyz.append(n[0].coords)
                    local_env_sym.append(n[0].specie)
                    local_env_dist.append(n[1])
                    local_env_sitemap.append(n[2])
            local_env_xyz = np.subtract(local_env_xyz,
                                        np.mean(local_env_xyz, 0))

            perm = []
            if get_permutations:
                finder = PointGroupAnalyzer(Molecule(local_env_sym,
                                                     local_env_xyz),
                                            eigen_tolerance=eigen_tol)
                pg = finder.get_pointgroup()
                for i, op in enumerate(pg):
                    newpos = op.operate_multi(local_env_xyz)
                    perm.append(
                        np.argmin(cdist(local_env_xyz, newpos),
                                  axis=1).tolist())

            site_env = {
                'pos': local_env_xyz,
                'sitetypes': [SymSiteMap[s] for s in local_env_sym],
                'env2config': local_env_sitemap,
                'permutations': perm,
                'dist': local_env_dist
            }
            site_envs.append(site_env)
        return site_envs