当前位置: 首页>>代码示例>>Python>>正文


Python StructureEditor.add_site_property方法代码示例

本文整理汇总了Python中pymatgen.core.structure_modifier.StructureEditor.add_site_property方法的典型用法代码示例。如果您正苦于以下问题:Python StructureEditor.add_site_property方法的具体用法?Python StructureEditor.add_site_property怎么用?Python StructureEditor.add_site_property使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymatgen.core.structure_modifier.StructureEditor的用法示例。


在下文中一共展示了StructureEditor.add_site_property方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_add_site_property

# 需要导入模块: from pymatgen.core.structure_modifier import StructureEditor [as 别名]
# 或者: from pymatgen.core.structure_modifier.StructureEditor import add_site_property [as 别名]
    def test_add_site_property(self):
        self.modifier.add_site_property("charge", [4.1, 5])
        s = self.modifier.modified_structure
        self.assertEqual(s[0].charge, 4.1)
        self.assertEqual(s[1].charge, 5)

        #test adding multiple properties.
        mod2 = StructureEditor(s)
        mod2.add_site_property("magmom", [3, 2])
        s = mod2.modified_structure
        self.assertEqual(s[0].charge, 4.1)
        self.assertEqual(s[0].magmom, 3)
开发者ID:chenweis,项目名称:pymatgen,代码行数:14,代码来源:test_structure_modifier.py

示例2: test_init

# 需要导入模块: from pymatgen.core.structure_modifier import StructureEditor [as 别名]
# 或者: from pymatgen.core.structure_modifier.StructureEditor import add_site_property [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!")
开发者ID:jesuansito,项目名称:pymatgen,代码行数:54,代码来源:test_ewald.py

示例3: StructureEditorTest

# 需要导入模块: from pymatgen.core.structure_modifier import StructureEditor [as 别名]
# 或者: from pymatgen.core.structure_modifier.StructureEditor import add_site_property [as 别名]
class StructureEditorTest(unittest.TestCase):

    def setUp(self):

        self.si = Element("Si")
        self.fe = Element("Fe")
        self.ge = Element("Ge")
        coords = list()
        coords.append(np.array([0, 0, 0]))
        coords.append(np.array([0.75, 0.5, 0.75]))
        lattice = Lattice.cubic(10)
        s = Structure(lattice, [self.si, self.fe], coords)
        self.modifier = StructureEditor(s)

    def test_translate_sites(self):
        self.modifier.translate_sites([0, 1], [0.5, 0.5, 0.5], frac_coords=True)
        self.assertTrue(np.array_equal(self.modifier.modified_structure.frac_coords[0], np.array([ 0.5, 0.5, 0.5])))

        self.modifier.translate_sites([0], [0.5, 0.5, 0.5], frac_coords=False)
        self.assertTrue(np.array_equal(self.modifier.modified_structure.cart_coords[0], np.array([ 5.5, 5.5, 5.5])))

    def test_append_site(self):
        self.modifier.append_site(self.si, [0, 0.5, 0])
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Si2", "Wrong formula!")
        self.assertRaises(ValueError, self.modifier.append_site, self.si, np.array([0, 0.5, 0]))

    def test_modified_structure(self):
        self.modifier.insert_site(1, self.si, [0, 0.25, 0])
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Si2", "Wrong formula!")

        self.modifier.delete_site(0)
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Si1", "Wrong formula!")

        self.modifier.replace_site(0, self.ge)
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Ge1", "Wrong formula!")

        self.modifier.append_site(self.si, [0, 0.75, 0])
        self.modifier.replace_species({self.si: self.ge})
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Ge2", "Wrong formula!")

        self.modifier.replace_species({self.ge: {self.ge:0.5, self.si:0.5}})
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Si1 Ge1", "Wrong formula!")

        #this should change the .5Si .5Ge sites to .75Si .25Ge
        self.modifier.replace_species({self.ge: {self.ge:0.5, self.si:0.5}})
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Si1.5 Ge0.5", "Wrong formula!")

        d = 0.1
        pre_perturbation_sites = self.modifier.modified_structure.sites
        self.modifier.perturb_structure(distance=d)
        post_perturbation_sites = self.modifier.modified_structure.sites

        for i, x in enumerate(pre_perturbation_sites):
            self.assertAlmostEqual(x.distance(post_perturbation_sites[i]), d, 3, "Bad perturbation distance")

    def test_add_site_property(self):
        self.modifier.add_site_property("charge", [4.1, 5])
        s = self.modifier.modified_structure
        self.assertEqual(s[0].charge, 4.1)
        self.assertEqual(s[1].charge, 5)

        #test adding multiple properties.
        mod2 = StructureEditor(s)
        mod2.add_site_property("magmom", [3, 2])
        s = mod2.modified_structure
        self.assertEqual(s[0].charge, 4.1)
        self.assertEqual(s[0].magmom, 3)
开发者ID:chenweis,项目名称:pymatgen,代码行数:69,代码来源:test_structure_modifier.py

示例4: StructureEditorTest

# 需要导入模块: from pymatgen.core.structure_modifier import StructureEditor [as 别名]
# 或者: from pymatgen.core.structure_modifier.StructureEditor import add_site_property [as 别名]
class StructureEditorTest(unittest.TestCase):

    def setUp(self):
        self.si = Element("Si")
        self.fe = Element("Fe")
        self.ge = Element("Ge")
        coords = list()
        coords.append(np.array([0, 0, 0]))
        coords.append(np.array([0.75, 0.5, 0.75]))
        lattice = Lattice.cubic(10)
        s = Structure(lattice, ["Si", "Fe"], coords)
        self.modifier = StructureEditor(s)

    def test_to_unit_cell(self):
        self.modifier.append_site(self.fe, [1.75, 0.5, 0.75],
                                  validate_proximity=False)
        self.modifier.to_unit_cell()
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Si1",
                         "Wrong formula!")

    def test_to_unit_cell(self):
        self.modifier.apply_strain(0.01)
        self.assertEqual(self.modifier.modified_structure.lattice.abc,
                         (10.1, 10.1, 10.1))

    def test_translate_sites(self):
        self.modifier.translate_sites([0, 1], [0.5, 0.5, 0.5],
                                      frac_coords=True)
        self.assertTrue(np.array_equal(self.modifier.modified_structure
                                       .frac_coords[0],
                                       np.array([0.5, 0.5, 0.5])))

        self.modifier.translate_sites([0], [0.5, 0.5, 0.5], frac_coords=False)
        self.assertTrue(np.array_equal(self.modifier.modified_structure
                                       .cart_coords[0],
                                       np.array([5.5, 5.5, 5.5])))

    def test_append_site(self):
        self.modifier.append_site(self.si, [0, 0.5, 0])
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Si2",
                         "Wrong formula!")
        self.assertRaises(ValueError, self.modifier.append_site, self.si,
                          np.array([0, 0.5, 0]))

    def test_modified_structure(self):
        self.modifier.insert_site(1, self.si, [0, 0.25, 0])
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Si2",
                         "Wrong formula!")

        self.modifier.delete_site(0)
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Si1",
                         "Wrong formula!")

        self.modifier.replace_site(0, self.ge)
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Ge1",
                         "Wrong formula!")

        self.modifier.append_site(self.si, [0, 0.75, 0])
        self.modifier.replace_species({self.si: self.ge})
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Ge2",
                         "Wrong formula!")

        self.modifier.replace_species({self.ge: {self.ge: 0.5, self.si: 0.5}})
        self.assertEqual(self.modifier.modified_structure.formula,
                         "Fe1 Si1 Ge1", "Wrong formula!")

        #this should change the .5Si .5Ge sites to .75Si .25Ge
        self.modifier.replace_species({self.ge: {self.ge: 0.5, self.si: 0.5}})
        self.assertEqual(self.modifier.modified_structure.formula,
                         "Fe1 Si1.5 Ge0.5", "Wrong formula!")

        d = 0.1
        pre_perturbation_sites = self.modifier.modified_structure.sites
        self.modifier.perturb_structure(distance=d)
        post_perturbation_sites = self.modifier.modified_structure.sites

        for i, x in enumerate(pre_perturbation_sites):
            self.assertAlmostEqual(x.distance(post_perturbation_sites[i]), d,
                                   3, "Bad perturbation distance")

    def test_add_site_property(self):
        self.modifier.add_site_property("charge", [4.1, 5])
        s = self.modifier.modified_structure
        self.assertEqual(s[0].charge, 4.1)
        self.assertEqual(s[1].charge, 5)

        #test adding multiple properties.
        mod2 = StructureEditor(s)
        mod2.add_site_property("magmom", [3, 2])
        s = mod2.modified_structure
        self.assertEqual(s[0].charge, 4.1)
        self.assertEqual(s[0].magmom, 3)

    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)
#.........这里部分代码省略.........
开发者ID:jesuansito,项目名称:pymatgen,代码行数:103,代码来源:test_structure_modifier.py


注:本文中的pymatgen.core.structure_modifier.StructureEditor.add_site_property方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。