当前位置: 首页>>代码示例>>Python>>正文


Python Structure.remove_sites方法代码示例

本文整理汇总了Python中pymatgen.Structure.remove_sites方法的典型用法代码示例。如果您正苦于以下问题:Python Structure.remove_sites方法的具体用法?Python Structure.remove_sites怎么用?Python Structure.remove_sites使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymatgen.Structure的用法示例。


在下文中一共展示了Structure.remove_sites方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: remove_unstable_interstitials

# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import remove_sites [as 别名]
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
开发者ID:rtrottie,项目名称:VTST-Tools,代码行数:40,代码来源:get_migration.py

示例2: adsorb_both_surfaces

# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import remove_sites [as 别名]
    def adsorb_both_surfaces(self, molecule, repeat=None, min_lw=5.0,
                             reorient=True, find_args={}, ltol=0.1,
                             stol=0.1, angle_tol=0.01):

        """
        Function that generates all adsorption structures for a given
        molecular adsorbate on both surfaces of a slab.

        Args:
            molecule (Molecule): molecule corresponding to adsorbate
            repeat (3-tuple or list): repeat argument for supercell generation
            min_lw (float): minimum length and width of the slab, only used
                if repeat is None
            reorient (bool): flag on whether or not to reorient adsorbate
                along the miller index
            find_args (dict): dictionary of arguments to be passed to the
                call to self.find_adsorption_sites, e.g. {"distance":2.0}
            ltol (float): Fractional length tolerance. Default is 0.2.
            stol (float): Site tolerance. Defined as the fraction of the
                average free length per atom := ( V / Nsites ) ** (1/3)
                Default is 0.3.
            angle_tol (float): Angle tolerance in degrees. Default is 5 degrees.
        """

        # First get all possible adsorption configurations for this surface
        adslabs = self.generate_adsorption_structures(molecule, repeat=repeat, min_lw=min_lw,
                                                      reorient=reorient, find_args=find_args)

        # Now we need to sort the sites by their position along
        # c as well as whether or not they are adsorbate
        single_ads = []
        for i, slab in enumerate(adslabs):
            sorted_sites = sorted(slab, key=lambda site: site.frac_coords[2])
            ads_indices = [site_index for site_index, site in enumerate(sorted_sites) \
                           if site.surface_properties == "adsorbate"]
            non_ads_indices = [site_index for site_index, site in enumerate(sorted_sites) \
                               if site.surface_properties != "adsorbate"]

            species, fcoords, props = [], [], {"surface_properties": []}
            for site in sorted_sites:
                species.append(site.specie)
                fcoords.append(site.frac_coords)
                props["surface_properties"].append(site.surface_properties)

            slab_other_side = Structure(slab.lattice, species,
                                        fcoords, site_properties=props)

            # For each adsorbate, get its distance from the surface and move it
            # to the other side with the same distance from the other surface
            for ads_index in ads_indices:
                props["surface_properties"].append("adsorbate")
                adsite = sorted_sites[ads_index]
                diff = abs(adsite.frac_coords[2] - \
                           sorted_sites[non_ads_indices[-1]].frac_coords[2])
                slab_other_side.append(adsite.specie, [adsite.frac_coords[0],
                                                       adsite.frac_coords[1],
                                                       sorted_sites[0].frac_coords[2] - diff],
                                       properties={"surface_properties": "adsorbate"})
                # slab_other_side[-1].add

            # Remove the adsorbates on the original side of the slab
            # to create a slab with one adsorbate on the other side
            slab_other_side.remove_sites(ads_indices)

            # Put both slabs with adsorption on one side
            # and the other in a list of slabs for grouping
            single_ads.extend([slab, slab_other_side])

        # Now group the slabs.
        matcher = StructureMatcher(ltol=ltol, stol=stol,
                                   angle_tol=angle_tol)
        groups = matcher.group_structures(single_ads)

        # Each group should be a pair with adsorbate on one side and the other.
        # If a slab has no equivalent adsorbed slab on the other side, skip.
        adsorb_both_sides = []
        for i, group in enumerate(groups):
            if len(group) != 2:
                continue
            ads1 = [site for site in group[0] if \
                    site.surface_properties == "adsorbate"][0]
            group[1].append(ads1.specie, ads1.frac_coords,
                            properties={"surface_properties": "adsorbate"})
            # Build the slab object
            species, fcoords, props = [], [], {"surface_properties": []}
            for site in group[1]:
                species.append(site.specie)
                fcoords.append(site.frac_coords)
                props["surface_properties"].append(site.surface_properties)
            s = Structure(group[1].lattice, species, fcoords, site_properties=props)
            adsorb_both_sides.append(s)

        return adsorb_both_sides
开发者ID:setten,项目名称:pymatgen,代码行数:95,代码来源:adsorption.py


注:本文中的pymatgen.Structure.remove_sites方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。