本文整理汇总了Python中pymatgen.core.structure_modifier.StructureEditor.delete_site方法的典型用法代码示例。如果您正苦于以下问题:Python StructureEditor.delete_site方法的具体用法?Python StructureEditor.delete_site怎么用?Python StructureEditor.delete_site使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.core.structure_modifier.StructureEditor
的用法示例。
在下文中一共展示了StructureEditor.delete_site方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_init
# 需要导入模块: from pymatgen.core.structure_modifier import StructureEditor [as 别名]
# 或者: from pymatgen.core.structure_modifier.StructureEditor import delete_site [as 别名]
def test_init(self):
fitter = StructureFitter(self.b, self.a)
self.assertTrue(fitter.mapping_op != None, "No fit found!")
#Now to try with rotated structure
op = SymmOp.from_axis_angle_and_translation([0, 0, 1], 30, False, np.array([0, 0, 1]))
editor = StructureEditor(self.a)
editor.apply_operation(op)
fitter = StructureFitter(self.b, editor.modified_structure)
self.assertTrue(fitter.mapping_op != None, "No fit found!")
#test with a supercell
mod = SupercellMaker(self.a, scaling_matrix=[[2, 0, 0], [0, 1, 0], [0, 0, 1]])
a_super = mod.modified_structure
fitter = StructureFitter(self.b, a_super)
self.assertTrue(fitter.mapping_op != None, "No fit found!")
# Test with a structure with a translated point
editor = StructureEditor(self.a)
site = self.a[0]
editor.delete_site(0)
trans = np.random.randint(0, 1000, 3)
editor.insert_site(0, site.species_and_occu, site.frac_coords + trans, False, False)
fitter = StructureFitter(self.b, editor.modified_structure)
self.assertTrue(fitter.mapping_op != None, "No fit found for translation {}!".format(trans))
parser = CifParser(os.path.join(test_dir, "FePO4a.cif"))
a = parser.get_structures()[0]
parser = CifParser(os.path.join(test_dir, "FePO4b.cif"))
b = parser.get_structures()[0]
fitter = StructureFitter(b, a)
self.assertTrue(fitter.mapping_op != None, "No fit found!")
示例2: setUp
# 需要导入模块: from pymatgen.core.structure_modifier import StructureEditor [as 别名]
# 或者: from pymatgen.core.structure_modifier.StructureEditor import delete_site [as 别名]
def setUp(self):
p = Poscar.from_file(os.path.join(test_dir, 'POSCAR'))
self.structure = p.struct
self.sg = SymmetryFinder(self.structure, 0.001)
parser = CifParser(os.path.join(test_dir, 'Li10GeP2S12.cif'))
self.disordered_structure = parser.get_structures()[0]
self.disordered_sg = SymmetryFinder(self.disordered_structure, 0.001)
s = p.struct
editor = StructureEditor(p.struct)
site = s[0]
editor.delete_site(0)
editor.append_site(site.species_and_occu, site.frac_coords)
self.sg3 = SymmetryFinder(editor.modified_structure, 0.001)
示例3: StructureEditorTest
# 需要导入模块: from pymatgen.core.structure_modifier import StructureEditor [as 别名]
# 或者: from pymatgen.core.structure_modifier.StructureEditor import delete_site [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)
示例4: StructureEditorTest
# 需要导入模块: from pymatgen.core.structure_modifier import StructureEditor [as 别名]
# 或者: from pymatgen.core.structure_modifier.StructureEditor import delete_site [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)
#.........这里部分代码省略.........