Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Args:
i:
index to insert site
species:
species of inserted site
coords:
coordinates of inserted site
coords_are_cartesian:
Whether coordinates are cartesian. Defaults to False.
validate_proximity:
Whether to check if inserted site is too close to an existing
site. Defaults to True.
"""
if not coords_are_cartesian:
new_site = PeriodicSite(species, coords, self._lattice,
properties=properties)
else:
frac_coords = self._lattice.get_fractional_coords(coords)
new_site = PeriodicSite(species, frac_coords, self._lattice,
properties=properties)
if validate_proximity:
for site in self._sites:
if site.distance(new_site) < self.DISTANCE_TOLERANCE:
raise ValueError("New site is too close to an existing "
"site!")
self._sites.insert(i, new_site)
def vtk(self):
if StructureVis is None:
raise NotImplementedError("vtk must be present to view.")
lattice = self.structure.lattice
vis = StructureVis()
vis.set_structure(Structure.from_sites(self.structure))
for v in self.vnodes:
vis.add_site(PeriodicSite("K", v.frac_coords, lattice))
vis.add_polyhedron(
[PeriodicSite("S", c, lattice, coords_are_cartesian=True)
for c in v.polyhedron_coords],
PeriodicSite("Na", v.frac_coords, lattice),
color="element",
draw_edges=True,
edges_color=(0, 0, 0))
vis.show()
def vtk(self):
if StructureVis is None:
raise NotImplementedError("vtk must be present to view.")
lattice = self.structure.lattice
vis = StructureVis()
vis.set_structure(Structure.from_sites(self.structure))
for v in self.vnodes:
vis.add_site(PeriodicSite("K", v.frac_coords, lattice))
vis.add_polyhedron(
[PeriodicSite("S", c, lattice, coords_are_cartesian=True) for c
in v.polyhedron_coords],
PeriodicSite("Na", v.frac_coords, lattice),
color="element",
draw_edges=True,
edges_color=(0, 0, 0))
vis.show()
if len(species) != len(coords):
raise StructureError("The list of atomic species must be of the"
"same length as the list of fractional"
" coordinates.")
if isinstance(lattice, Lattice):
self._lattice = lattice
else:
self._lattice = Lattice(lattice)
sites = []
for i in xrange(len(species)):
prop = None
if site_properties:
prop = {k: v[i] for k, v in site_properties.items()}
sites.append(PeriodicSite(species[i], coords[i],
self._lattice, to_unit_cell,
coords_are_cartesian,
properties=prop))
if validate_proximity:
for (s1, s2) in itertools.combinations(sites, 2):
if s1.distance(s2) < SiteCollection.DISTANCE_TOLERANCE:
raise StructureError(("Structure contains sites that are ",
"less than 0.01 Angstrom apart!"))
self._sites = tuple(sites)
to avoid different arguments signatures from causing problems. If
you prefer a subclass to return its own type, you need to override
this method in the subclass.
"""
scale_matrix = np.array(scaling_matrix, np.int16)
if scale_matrix.shape != (3, 3):
scale_matrix = np.array(scale_matrix * np.eye(3), np.int16)
new_lattice = Lattice(np.dot(scale_matrix, self._lattice.matrix))
f_lat = lattice_points_in_supercell(scale_matrix)
c_lat = new_lattice.get_cartesian_coords(f_lat)
new_sites = []
for site in self:
for v in c_lat:
s = PeriodicSite(site.species_and_occu, site.coords + v,
new_lattice, properties=site.properties,
coords_are_cartesian=True, to_unit_cell=False)
new_sites.append(s)
return Structure.from_sites(new_sites)
"single int indices!")
self._sites[ii] = site
else:
if isinstance(site, six.string_types) or (
not isinstance(site, collections.Sequence)):
sp = site
frac_coords = self._sites[ii].frac_coords
properties = self._sites[ii].properties
else:
sp = site[0]
frac_coords = site[1] if len(site) > 1 else \
self._sites[ii].frac_coords
properties = site[2] if len(site) > 2 else \
self._sites[ii].properties
self._sites[ii] = PeriodicSite(sp, frac_coords, self._lattice,
properties=properties)
modstrucs : list of modified Structure objects
"""
sidx=0
slen=len(goodstrucs)
while sidx < slen:
lengoodsites=len(goodstrucs[sidx].sites)
lencoordsites=len(coordstrucs[sidx].sites)
if not (lengoodsites == lencoordsites):
raise MASTError("vasp_checker,graft_coordinates_onto_structure", "Original and coordinate structures do not have the same amount of sites.")
cct=0
newsites=list()
mylattice=goodstrucs[sidx].lattice
while cct < lengoodsites:
newcoords=coordstrucs[sidx].sites[cct].frac_coords
oldspecie=goodstrucs[sidx].sites[cct].specie
newsite=PeriodicSite(oldspecie, newcoords, mylattice)
newsites.append(newsite)
cct=cct+1
goodstrucs[sidx].remove_sites(range(0,lengoodsites))
for cct in range(0, lengoodsites):
goodstrucs[sidx].append(newsites[cct].specie,
newsites[cct].frac_coords)
sidx = sidx + 1
return goodstrucs
Add oxidation states to a structure.
Args:
structure:
pymatgen.core.structure Structure object.
oxidation_states:
dict of oxidation states.
E.g., {"Li":1, "Fe":2, "P":5, "O":-2}
"""
try:
for i, site in enumerate(self._sites):
new_sp = {}
for el, occu in site.species_and_occu.items():
sym = el.symbol
new_sp[Specie(sym, oxidation_states[sym])] = occu
new_site = PeriodicSite(new_sp, site.frac_coords,
self._lattice,
coords_are_cartesian=False,
properties=site.properties)
self._sites[i] = new_site
except KeyError:
raise ValueError("Oxidation state of all elements must be "
"specified in the dictionary.")
Add oxidation states to a structure.
Args:
structure:
pymatgen.core.structure Structure object.
oxidation_states:
dict of oxidation states.
E.g., {"Li":1, "Fe":2, "P":5, "O":-2}
"""
try:
for i, site in enumerate(self._sites):
new_sp = {}
for el, occu in site.species_and_occu.items():
sym = el.symbol
new_sp[Specie(sym, oxidation_states[sym])] = occu
new_site = PeriodicSite(new_sp, site.frac_coords,
self._lattice,
coords_are_cartesian=False,
properties=site.properties)
self._sites[i] = new_site
except KeyError:
raise ValueError("Oxidation state of all elements must be "
"specified in the dictionary.")
def from_dict(cls, d):
lattice = Lattice.from_dict(d["lattice"])
sites = [PeriodicSite.from_dict(sd, lattice) for sd in d["sites"]]
s = Structure.from_sites(sites)
return Interface(
lattice=lattice,
species=s.species_and_occu, coords=s.frac_coords,
sub_plane=d["sub_plane"], film_plane=d["film_plane"],
sub_init_cell=d["sub_init_cell"], film_init_cell=d["film_init_cell"],
modified_sub_structure=d["modified_sub_structure"], modified_film_structure=d["modified_film_structure"],
strained_sub_structure=d["strained_sub_structure"], strained_film_structure=d["strained_film_structure"],
site_properties=s.site_properties, init_inplane_shift=d["init_inplane_shift"]
)