本文整理汇总了Python中pymatgen.core.sites.PeriodicSite.from_dict方法的典型用法代码示例。如果您正苦于以下问题:Python PeriodicSite.from_dict方法的具体用法?Python PeriodicSite.from_dict怎么用?Python PeriodicSite.from_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.core.sites.PeriodicSite
的用法示例。
在下文中一共展示了PeriodicSite.from_dict方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_to_from_dict
# 需要导入模块: from pymatgen.core.sites import PeriodicSite [as 别名]
# 或者: from pymatgen.core.sites.PeriodicSite import from_dict [as 别名]
def test_to_from_dict(self):
d = self.site2.to_dict
site = PeriodicSite.from_dict(d)
self.assertEqual(site, self.site2)
self.assertNotEqual(site, self.site)
d = self.propertied_site.to_dict
site = Site.from_dict(d)
self.assertEqual(site.magmom, 5.1)
self.assertEqual(site.charge, 4.2)
site3 = PeriodicSite({"Si": 0.5, "Fe": 0.5}, [0, 0, 0], self.lattice)
d = site3.to_dict
site = PeriodicSite.from_dict(d)
self.assertEqual(site.species_and_occu, site3.species_and_occu)
示例2: test_as_from_dict
# 需要导入模块: from pymatgen.core.sites import PeriodicSite [as 别名]
# 或者: from pymatgen.core.sites.PeriodicSite import from_dict [as 别名]
def test_as_from_dict(self):
d = self.site2.as_dict()
site = PeriodicSite.from_dict(d)
self.assertEqual(site, self.site2)
self.assertNotEqual(site, self.site)
d = self.propertied_site.as_dict()
site3 = PeriodicSite({"Si": 0.5, "Fe": 0.5}, [0, 0, 0], self.lattice)
d = site3.as_dict()
site = PeriodicSite.from_dict(d)
self.assertEqual(site.species_and_occu, site3.species_and_occu)
d = self.dummy_site.as_dict()
site = PeriodicSite.from_dict(d)
self.assertEqual(site.species_and_occu, self.dummy_site.species_and_occu)
示例3: from_dict
# 需要导入模块: from pymatgen.core.sites import PeriodicSite [as 别名]
# 或者: from pymatgen.core.sites.PeriodicSite import from_dict [as 别名]
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 Slab(
lattice=lattice,
species=s.species_and_occu, coords=s.frac_coords,
miller_index=d["miller_index"],
oriented_unit_cell=Structure.from_dict(d["oriented_unit_cell"]),
shift=d["shift"], scale_factor=d["scale_factor"],
site_properties=s.site_properties, energy=d["energy"]
)
示例4: from_dict
# 需要导入模块: from pymatgen.core.sites import PeriodicSite [as 别名]
# 或者: from pymatgen.core.sites.PeriodicSite import from_dict [as 别名]
def from_dict(d):
"""
Reconstitute a Structure object from a dict representation of Structure
created using to_dict.
Args:
d:
dict representation of structure.
Returns:
Structure object
"""
lattice = Lattice.from_dict(d["lattice"])
sites = [PeriodicSite.from_dict(sd, lattice) for sd in d["sites"]]
return Structure.from_sites(sites)
示例5: from_dict
# 需要导入模块: from pymatgen.core.sites import PeriodicSite [as 别名]
# 或者: from pymatgen.core.sites.PeriodicSite import from_dict [as 别名]
def from_dict(cls, d):
"""
Returns CompleteCohp object from dict representation.
"""
cohp_dict = {}
efermi = d["efermi"]
energies = d["energies"]
structure = Structure.from_dict(d["structure"])
if "bonds" in d.keys():
bonds = {bond: {"length": d["bonds"][bond]["length"],
"sites": tuple(PeriodicSite.from_dict(site)
for site in d["bonds"][bond]["sites"])}
for bond in d["bonds"]}
else:
bonds = None
for label in d["COHP"]:
cohp = {Spin(int(spin)): np.array(d["COHP"][label][spin])
for spin in d["COHP"][label]}
try:
icohp = {Spin(int(spin)): np.array(d["ICOHP"][label][spin])
for spin in d["ICOHP"][label]}
except KeyError:
icohp = None
if label == "average":
avg_cohp = Cohp(efermi, energies, cohp, icohp=icohp)
else:
cohp_dict[label] = Cohp(efermi, energies, cohp, icohp=icohp)
if "orb_res_cohp" in d.keys():
orb_cohp = {}
for label in d["orb_res_cohp"]:
orb_cohp[label] = {}
for orb in d["orb_res_cohp"][label]:
cohp = {Spin(int(s)): np.array(
d["orb_res_cohp"][label][orb]["COHP"][s],
dtype=float)
for s in d["orb_res_cohp"][label][orb]["COHP"]}
try:
icohp = {Spin(int(s)): np.array(
d["orb_res_cohp"][label][orb]["ICOHP"][s],
dtype=float)
for s in d["orb_res_cohp"][label][orb]["ICOHP"]}
except KeyError:
icohp = None
orbitals = [tuple((int(o[0]), Orbital[o[1]])) for o in
d["orb_res_cohp"][label][orb]["orbitals"]]
orb_cohp[label][orb] = {"COHP": cohp, "ICOHP": icohp,
"orbitals": orbitals}
# If no total COHPs are present, calculate the total
# COHPs from the single-orbital populations. Total COHPs
# may not be present when the cohpgenerator keyword is used
# in LOBSTER versions 2.2.0 and earlier.
if label not in d["COHP"] or d["COHP"][label] is None:
cohp = {Spin.up: np.sum(np.array(
[orb_cohp[label][orb]["COHP"][Spin.up]
for orb in orb_cohp[label]]), axis=0)}
try:
cohp[Spin.down] = np.sum(np.array(
[orb_cohp[label][orb]["COHP"][Spin.down]
for orb in orb_cohp[label]]), axis=0)
except KeyError:
pass
orb_res_icohp = None in [orb_cohp[label][orb]["ICOHP"]
for orb in orb_cohp[label]]
if (label not in d["ICOHP"] or
d["ICOHP"][label] is None) and orb_res_icohp:
icohp = {Spin.up: np.sum(np.array(
[orb_cohp[label][orb]["ICOHP"][Spin.up]
for orb in orb_cohp[label]]), axis=0)}
try:
icohp[Spin.down] = np.sum(np.array(
[orb_cohp[label][orb]["ICOHP"][Spin.down]
for orb in orb_cohp[label]]), axis=0)
except KeyError:
pass
else:
orb_cohp = None
if "average" not in d["COHP"].keys():
# calculate average
cohp = np.array([np.array(c)
for c in d["COHP"].values()]).mean(axis=0)
try:
icohp = np.array([np.array(c)
for c in d["ICOHP"].values()]).mean(axis=0)
except KeyError:
icohp = None
avg_cohp = Cohp(efermi, energies, cohp, icohp=icohp)
return CompleteCohp(structure, avg_cohp, cohp_dict, bonds=bonds,
are_coops=d["are_coops"], orb_res_cohp=orb_cohp)