本文整理汇总了Python中pymatgen.Structure.copy方法的典型用法代码示例。如果您正苦于以下问题:Python Structure.copy方法的具体用法?Python Structure.copy怎么用?Python Structure.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.Structure
的用法示例。
在下文中一共展示了Structure.copy方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: poscar_from_sitelist
# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import copy [as 别名]
def poscar_from_sitelist( configs, labels, sitelists, structure, subset = None ):
"""
Uses pymatgen Structure.to() method to generates POSCAR files for a set of
configurations within a parent structure.
Args:
configs (list): site configurations
labels (list): atom labels to output
sitelist (list): list of sites in fractional coords
structure (pymatgen Structure): Parent structure
subset (Optional [list]): list of atom indices to output
"""
if subset:
species_clean = [ spec for i,spec in enumerate( structure.species ) if i not in subset ]
species_config = [ spec for i,spec in enumerate( structure.species ) if i in subset ]
frac_coords_clean = [ coord for i, coord in enumerate( structure.frac_coords ) if i not in subset ]
clean_structure = Structure( structure.lattice, species_clean, frac_coords_clean )
else:
clean_structure = Structure( structure.lattice, [], [] )
species_config = structure.species
for idx, config in enumerate( configs, start=1 ):
structure_config = clean_structure.copy()
for label in labels:
for pos in config.position( label ):
for sitelist in sitelists:
structure_config.append( species_config[ pos ], sitelist[ pos ] )
structure_config.to( filename="POSCAR_{}.vasp".format( idx ) )
示例2: is_equivalent
# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import copy [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
示例3: test_supercell_subsets
# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import copy [as 别名]
def test_supercell_subsets(self):
sm = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5,
primitive_cell=False, scale=True,
attempt_supercell=True, allow_subset=True,
supercell_size='volume')
sm_no_s = StructureMatcher(ltol=0.2, stol=0.3, angle_tol=5,
primitive_cell=False, scale=True,
attempt_supercell=True, allow_subset=False,
supercell_size='volume')
l = Lattice.orthorhombic(1, 2, 3)
s1 = Structure(l, ['Ag', 'Si', 'Si'],
[[.7, .4, .5], [0, 0, 0.1], [0, 0, 0.2]])
s1.make_supercell([2, 1, 1])
s2 = Structure(l, ['Si', 'Si', 'Ag'],
[[0, 0.1, -0.95], [0, 0.1, 0], [-.7, .5, .375]])
shuffle = [0, 2, 1, 3, 4, 5]
s1 = Structure.from_sites([s1[i] for i in shuffle])
# test when s1 is exact supercell of s2
result = sm.get_s2_like_s1(s1, s2)
for a, b in zip(s1, result):
self.assertTrue(a.distance(b) < 0.08)
self.assertEqual(a.species, b.species)
self.assertTrue(sm.fit(s1, s2))
self.assertTrue(sm.fit(s2, s1))
self.assertTrue(sm_no_s.fit(s1, s2))
self.assertTrue(sm_no_s.fit(s2, s1))
rms = (0.048604032430991401, 0.059527539448807391)
self.assertTrue(np.allclose(sm.get_rms_dist(s1, s2), rms))
self.assertTrue(np.allclose(sm.get_rms_dist(s2, s1), rms))
# test when the supercell is a subset of s2
subset_supercell = s1.copy()
del subset_supercell[0]
result = sm.get_s2_like_s1(subset_supercell, s2)
self.assertEqual(len(result), 6)
for a, b in zip(subset_supercell, result):
self.assertTrue(a.distance(b) < 0.08)
self.assertEqual(a.species, b.species)
self.assertTrue(sm.fit(subset_supercell, s2))
self.assertTrue(sm.fit(s2, subset_supercell))
self.assertFalse(sm_no_s.fit(subset_supercell, s2))
self.assertFalse(sm_no_s.fit(s2, subset_supercell))
rms = (0.053243049896333279, 0.059527539448807336)
self.assertTrue(np.allclose(sm.get_rms_dist(subset_supercell, s2), rms))
self.assertTrue(np.allclose(sm.get_rms_dist(s2, subset_supercell), rms))
# test when s2 (once made a supercell) is a subset of s1
s2_missing_site = s2.copy()
del s2_missing_site[1]
result = sm.get_s2_like_s1(s1, s2_missing_site)
for a, b in zip((s1[i] for i in (0, 2, 4, 5)), result):
self.assertTrue(a.distance(b) < 0.08)
self.assertEqual(a.species, b.species)
self.assertTrue(sm.fit(s1, s2_missing_site))
self.assertTrue(sm.fit(s2_missing_site, s1))
self.assertFalse(sm_no_s.fit(s1, s2_missing_site))
self.assertFalse(sm_no_s.fit(s2_missing_site, s1))
rms = (0.029763769724403633, 0.029763769724403987)
self.assertTrue(np.allclose(sm.get_rms_dist(s1, s2_missing_site), rms))
self.assertTrue(np.allclose(sm.get_rms_dist(s2_missing_site, s1), rms))
示例4: Structure
# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import copy [as 别名]
return nfinal
# Potential issues:
# --Poor accounting of internal periodicity
# -definition of relative term can be ambiguous depending on structure
# --Assumes defect structure and primordial structures are aligned
if __name__ == "__main__":
#Sanity checks
#Test 1 - Final size cannot be constructed directly from primordial structure
ssize=[5,5,5]
fsize=[9,5,5]
psize=[2,5,5]
felat = Lattice.cubic(2.87)
primf = Structure(felat,["Fe","Fe"],[[0,0,0],[0.5,0.5,0.5]])
primordialstructure = primf.copy()
primordialstructure.make_supercell(psize)
f = primf.copy()
f.make_supercell(fsize)
write_structure(primordialstructure,'POSCAR_prim1')
final = finite_size_scale('POSCAR_Fdefect', ssize, 'POSCAR_prim1', fsize, psize)
write_structure(f,'POSCAR_F1expected')
write_structure(final,'POSCAR_F1')
#Test 2 - Test in all 3 dimensions
ssize=[5,5,5]
fsize=[8,8,8]
psize=[1,1,1]
primordialstructure = primf.copy()
primordialstructure.make_supercell(psize)
f = primf.copy()
示例5: get_vacancy_diffusion_pathways_from_cell
# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import copy [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
示例6: get_interstitial_diffusion_pathways_from_cell
# 需要导入模块: from pymatgen import Structure [as 别名]
# 或者: from pymatgen.Structure import copy [as 别名]
def get_interstitial_diffusion_pathways_from_cell(structure : Structure, interstitial_atom : str, vis=False,
get_midpoints=False, dummy='He', min_dist=0.5, weight_cutoff=0.0001,
is_interstitial_structure=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 ]
"""
vnn = VoronoiNN(targets=[interstitial_atom])
# To Find Pathway, look for voronoi edges
if not is_interstitial_structure:
orig_structure = structure.copy()
structure = structure.copy() # type: Structure
interstitial_structure = structure.copy()
interstitial_structure.DISTANCE_TOLERANCE = 0.01
if vis:
Poscar(structure).write_file(vis)
open_in_VESTA(vis)
inter_gen = list(VoronoiInterstitialGenerator(orig_structure, interstitial_atom))
if vis:
print(len(inter_gen))
for interstitial in inter_gen:
sat_structure = None
for dist_tol in [0.2, 0.15, 0.1, 0.05, 0.01, 0.001]:
try:
sat_structure = create_saturated_interstitial_structure(interstitial, dist_tol=dist_tol) # type: Structure
break
except ValueError:
continue
except TypeError:
continue
if not sat_structure:
continue
sat_structure.remove_site_property('velocities')
if vis:
Poscar(sat_structure).write_file(vis)
open_in_VESTA(vis)
time.sleep(0.5)
for site in sat_structure: # type: PeriodicSite
if site.specie == interstitial_atom:
try:
interstitial_structure.append(site.specie, site.coords, coords_are_cartesian=True, validate_proximity=True)
except StructureError:
pass
# combined_structure.merge_sites(mode='delete')
interstitial_structure.remove_site_property('velocities')
if vis:
Poscar(interstitial_structure).write_file(vis)
open_in_VESTA(vis)
else:
interstitial_structure = structure.copy()
# edges = vnn.get_nn_info(structure, atom_i)
# base_coords = structure[atom_i].coords
pathway_structure = interstitial_structure.copy() # type: Structure
pathway_structure.DISTANCE_TOLERANCE = 0.01
# Add H for all other diffusion atoms, so symmetry is preserved
for i in get_atom_i(interstitial_structure, interstitial_atom):
sym_edges = vnn.get_nn_info(interstitial_structure, i)
base = pathway_structure[i] # type: PeriodicSite
for edge in sym_edges:
dest = edge['site']
if base.distance(dest, jimage=edge['image']) > min_dist and edge['weight'] > weight_cutoff:
coords = (base.coords + dest.coords) / 2
try:
neighbors = [i, edge['site_index']]
# neighbors.sort()
pathway_structure.append(dummy, coords, True, validate_proximity=True, properties={'neighbors': neighbors, 'image' : edge['image']})
except StructureError:
pass
except ValueError:
pass
if vis:
Poscar(pathway_structure).write_file(vis)
open_in_VESTA(vis)
# Remove symmetrically equivalent pathways:
# sga = SpacegroupAnalyzer(pathway_structure, 0.1, angle_tolerance=10)
# ss = sga.get_symmetrized_structure()
return interstitial_structure, pathway_structure