本文整理汇总了Python中pymatgen.core.structure_modifier.StructureEditor.add_oxidation_state_by_element方法的典型用法代码示例。如果您正苦于以下问题:Python StructureEditor.add_oxidation_state_by_element方法的具体用法?Python StructureEditor.add_oxidation_state_by_element怎么用?Python StructureEditor.add_oxidation_state_by_element使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.core.structure_modifier.StructureEditor
的用法示例。
在下文中一共展示了StructureEditor.add_oxidation_state_by_element方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_init
# 需要导入模块: from pymatgen.core.structure_modifier import StructureEditor [as 别名]
# 或者: from pymatgen.core.structure_modifier.StructureEditor import add_oxidation_state_by_element [as 别名]
def test_init(self):
filepath = os.path.join(test_dir, 'POSCAR')
p = Poscar.from_file(filepath)
original_s = p.structure
modifier = StructureEditor(original_s)
modifier.add_oxidation_state_by_element({"Li": 1, "Fe": 2,
"P": 5, "O":-2})
s = modifier.modified_structure
ham = EwaldSummation(s)
self.assertAlmostEqual(ham.real_space_energy, -354.91294268, 4,
"Real space energy incorrect!")
self.assertAlmostEqual(ham.reciprocal_space_energy, 25.475754801, 4)
self.assertAlmostEqual(ham.point_energy, -790.463835033, 4,
"Point space energy incorrect!")
self.assertAlmostEqual(ham.total_energy, -1119.90102291, 2,
"Total space energy incorrect!")
self.assertAlmostEqual(ham.forces[0,0], -1.98818620e-01, 4,
"Forces incorrect")
self.assertAlmostEqual(sum(sum(abs(ham.forces))), 915.925354346, 4,
"Forces incorrect")
self.assertAlmostEqual(sum(sum(ham.real_space_energy_matrix)),
- 354.91294268, 4,
"Real space energy matrix incorrect!")
self.assertAlmostEqual(sum(sum(ham.reciprocal_space_energy_matrix)),
25.475754801, 4,
"Reciprocal space energy matrix incorrect!")
self.assertAlmostEqual(sum(ham.point_energy_matrix), -790.463835033,
4, "Point space energy matrix incorrect!")
self.assertAlmostEqual(sum(sum(ham.total_energy_matrix)),
- 1119.90102291, 2,
"Total space energy matrix incorrect!")
#note that forces are not individually tested, but should work fine.
self.assertRaises(ValueError, EwaldSummation, original_s)
#try sites with charge.
charges = []
for site in original_s:
if site.specie.symbol == "Li":
charges.append(1)
elif site.specie.symbol == "Fe":
charges.append(2)
elif site.specie.symbol == "P":
charges.append(5)
else:
charges.append(-2)
editor = StructureEditor(original_s)
editor.add_site_property('charge', charges)
ham2 = EwaldSummation(editor.modified_structure)
self.assertAlmostEqual(ham2.real_space_energy, -354.91294268, 4,
"Real space energy incorrect!")
示例2: test_add_oxidation_states
# 需要导入模块: from pymatgen.core.structure_modifier import StructureEditor [as 别名]
# 或者: from pymatgen.core.structure_modifier.StructureEditor import add_oxidation_state_by_element [as 别名]
def test_add_oxidation_states(self):
si = Element("Si")
fe = Element("Fe")
coords = list()
coords.append([0, 0, 0])
coords.append([0.75, 0.5, 0.75])
lattice = Lattice.cubic(10)
s = Structure(lattice, [si, fe], coords)
oxidation_states = {"Fe": 2, "Si": -4}
mod = StructureEditor(s)
mod.add_oxidation_state_by_element(oxidation_states)
mod_s = mod.modified_structure
for site in mod_s:
for k in site.species_and_occu.keys():
self.assertEqual(k.oxi_state, oxidation_states[k.symbol],
"Wrong oxidation state assigned!")
oxidation_states = {"Fe": 2}
self.assertRaises(ValueError, mod.add_oxidation_state_by_element,
oxidation_states)
mod.add_oxidation_state_by_site([2, -4])
mod_s = mod.modified_structure
self.assertEqual(mod_s[0].specie.oxi_state, 2)
self.assertRaises(ValueError, mod.add_oxidation_state_by_site,
[1])
示例3: apply_transformation
# 需要导入模块: from pymatgen.core.structure_modifier import StructureEditor [as 别名]
# 或者: from pymatgen.core.structure_modifier.StructureEditor import add_oxidation_state_by_element [as 别名]
def apply_transformation(self, structure):
editor = StructureEditor(structure)
editor.add_oxidation_state_by_element(self.oxi_states)
return editor.modified_structure