本文整理汇总了Python中pymatgen.Structure.append方法的典型用法代码示例。如果您正苦于以下问题:Python Structure.append方法的具体用法?Python Structure.append怎么用?Python Structure.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.Structure
的用法示例。
在下文中一共展示了Structure.append方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: is_equivalent
# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import append [as 别名]
def is_equivalent(structure : Structure, atoms_1 : tuple, atoms_2 : tuple , eps=0.05):
"""
Find Vacancy Strucutres for diffusion into and out of the specified atom_i site.
:param structure: Structure
Structure to calculate diffusion pathways
:param atom_i: int
Atom to get diffion path from
:return: [ Structure ]
"""
# To Find Pathway, look for voronoi edges
structure = structure.copy() # type: Structure
coords = get_midpoint(structure, atoms_1[0], atoms_1[1])
structure.append('H', coords)
coords = get_midpoint(structure, atoms_2[0], atoms_2[1])
structure.append('H', coords)
dist_1 = structure.get_neighbors(structure[-2], 3)
dist_2 = structure.get_neighbors(structure[-1], 3)
dist_1.sort(key=lambda x: x[1])
dist_2.sort(key=lambda x: x[1])
for (site_a, site_b) in zip(dist_1, dist_2):
if abs(site_a[1] - site_b[1]) > eps:
return False
elif site_a[0].specie != site_b[0].specie:
return False
return True
示例2: adsorb_both_surfaces
# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import append [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
示例3: finite_size_scale
# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import append [as 别名]
def finite_size_scale(standard, ssize, primordial, fsize, psize=[1,1,1]):
"""Function to perform finite size scaling for defect structure relaxation
Inputs:
standard = POSCAR file of structure containing defect
ssize = Supercell size of structure with defect (list of size 3)
primordial = POSCAR file of structure for basic unit of perfect cell
psize = Supercell size of structure for padding. Default = [1,1,1] (list of size 3)
fsize = Desired supercell size of final structure (list of size 3)
Outputs:
POSCAR file of structure containing defect and padding"""
# Check if the input sizes work out with the desired final size
padding = [0,0,0]
for i in range(3):
diff = fsize[i] - ssize[i]
if diff < 0:
raise RuntimeError('Desired final size of the structure must be larger than \
existing defect structure size. Defect Size = '+repr(ssize)+' Final Size = '+repr(fsize))
elif diff >= 0:
if math.fmod(diff,psize[i]):
raise RuntimeError('Primordial structure and defect structure sizes cannot \
be used to form desired final size. Reduce size of primordial structure. Defect Size = '+
repr(ssize)+' Final Size = '+repr(fsize)+' Primordial size = '+repr(psize))
else:
padding[i] = diff/psize[i]
# Load the defect structure and primordial structure
try:
defst = read_structure(standard)
except:
raise RuntimeError('Error: Unable to read standard structure. Please check file. Filename: '+\
standard)
try:
pst = read_structure(primordial)
except:
raise RuntimeError('Error: Unable to read primordial structure. Please check file. Filename: '+\
primordial)
# Pad the structure
positions = [site.coords for site in pst]
syms = [str(site.specie.symbol) for site in pst]
lv = [one/ssize for one in defst.lattice.matrix]
vect = []
for m0 in range(padding[0]):
for m1 in numpy.arange(0,fsize[1],psize[1]):
for m2 in numpy.arange(0,fsize[2],psize[2]):
vect.append([ssize[0]+m0*psize[0],m1,m2])
for m1 in range(padding[1]):
for m0 in numpy.arange(0,ssize[0],psize[0]):
for m2 in numpy.arange(0,fsize[2],psize[2]):
vect.append([m0,ssize[1]+m1*psize[1],m2])
for m2 in range(padding[2]):
for m0 in numpy.arange(0,ssize[0],psize[0]):
for m1 in numpy.arange(0,ssize[1],psize[1]):
vect.append([m0,m1,ssize[2]+m2*psize[2]])
#Construct a new structure with desired size
new_lat = Lattice(numpy.array([fsize[c] * lv[c] for c in range(3)]))
final = Structure(new_lat, defst.species_and_occu,defst.cart_coords,
coords_are_cartesian=True)
for m0,m1,m2 in vect:
npos = positions + numpy.dot((m0, m1, m2), lv)
for i in range(len(npos)):
final.append(syms[i],npos[i],coords_are_cartesian=True)
#Check for periodic issues in final structure
final = check_periodic(final,defst)
# Write output as POSCAR
write_structure(final, 'POSCAR_Final')
return final
示例4: get_vacancy_diffusion_pathways_from_cell
# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import append [as 别名]
def get_vacancy_diffusion_pathways_from_cell(structure : Structure, atom_i : int, vis=False, get_midpoints=False):
"""
Find Vacancy Strucutres for diffusion into and out of the specified atom_i site.
:param structure: Structure
Structure to calculate diffusion pathways
:param atom_i: int
Atom to get diffion path from
:return: [ Structure ]
"""
# To Find Pathway, look for voronoi edges
orig_structure = structure.copy()
structure = structure.copy() # type: Structure
target_atom = structure[atom_i].specie
vnn = VoronoiNN(targets=[target_atom])
edges = vnn.get_nn_info(structure, atom_i)
base_coords = structure[atom_i].coords
# Add H in middle of the discovered pathways. Use symmetry analysis to elminate equivlent H and therfore
# equivalent pathways
site_dir = {}
for edge in edges:
coords = np.round((base_coords + edge['site'].coords)/2,3)
structure.append('H', coords, True)
# site_dir[tuple(np.round(coords))] = structure.index(edge['site']) # Use Tuple for indexing dict, need to round
site_dir[tuple(np.round(coords))] = [list(x) for x in np.round(structure.frac_coords % 1,2) ].index(list(np.round(edge['site'].frac_coords % 1, 2))) # Use Tuple for indexing dict, need to round
# Add H for all other diffusion atoms, so symmetry is preserved
for i in get_atom_i(orig_structure, target_atom):
sym_edges = vnn.get_nn_info(orig_structure, i)
base_coords = structure[i].coords
for edge in sym_edges:
coords = (base_coords + edge['site'].coords) / 2
try:
structure.append('H', coords, True, True)
except:
pass
# Remove symmetrically equivalent pathways:
sga = SpacegroupAnalyzer(structure, 0.5, angle_tolerance=20)
ss = sga.get_symmetrized_structure()
final_structure = structure.copy()
indices = []
for i in range(len(orig_structure), len(orig_structure)+len(edges)): # get all 'original' edge sites
sites = ss.find_equivalent_sites(ss[i])
new_indices = [ss.index(site) for site in sites if ss.index(site) < len(orig_structure) + len(edges)] # Check if symmetrically equivalent to other original edge sites
new_indices.remove(i)
if i not in indices: # Don't duplicate effort
indices = indices + new_indices
indices.sort()
indices = indices + list(range(len(orig_structure)+len(edges), len(final_structure)))
final_structure.remove_sites(indices)
diffusion_elements = [ site_dir[tuple(np.round(h.coords))] for h in final_structure[len(orig_structure):] ]
if vis:
view(final_structure, 'VESTA')
print(diffusion_elements)
if get_midpoints:
centers = [h.frac_coords for h in final_structure[len(orig_structure):]]
return (diffusion_elements, centers)
return diffusion_elements