本文整理汇总了Python中pymatgen.core.structure_modifier.StructureEditor.apply_operation方法的典型用法代码示例。如果您正苦于以下问题:Python StructureEditor.apply_operation方法的具体用法?Python StructureEditor.apply_operation怎么用?Python StructureEditor.apply_operation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.core.structure_modifier.StructureEditor
的用法示例。
在下文中一共展示了StructureEditor.apply_operation方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fit
# 需要导入模块: from pymatgen.core.structure_modifier import StructureEditor [as 别名]
# 或者: from pymatgen.core.structure_modifier.StructureEditor import apply_operation [as 别名]
def test_fit(self):
"""
Take two known matched structures
1) Ensure match
2) Ensure match after translation and rotations
3) Ensure no-match after large site translation
4) Ensure match after site shuffling
"""
sm = StructureMatcher()
self.assertTrue(sm.fit(self.struct_list[0], self.struct_list[1]))
# Test rotational/translational invariance
op = SymmOp.from_axis_angle_and_translation([0, 0, 1], 30, False,
np.array([0.4, 0.7, 0.9]))
editor = StructureEditor(self.struct_list[1])
editor.apply_operation(op)
self.assertTrue(sm.fit(self.struct_list[0], editor.modified_structure))
#Test failure under large atomic translation
editor.translate_sites([0], [.4, .4, .2], frac_coords=True)
self.assertFalse(sm.fit(self.struct_list[0],
editor.modified_structure))
editor.translate_sites([0], [-.4, -.4, -.2], frac_coords=True)
# random.shuffle(editor._sites)
self.assertTrue(sm.fit(self.struct_list[0], editor.modified_structure))
#Test FrameworkComporator
sm2 = StructureMatcher(comparator=FrameworkComparator())
lfp = read_structure(os.path.join(test_dir, "LiFePO4.cif"))
nfp = read_structure(os.path.join(test_dir, "NaFePO4.cif"))
self.assertTrue(sm2.fit(lfp, nfp))
self.assertFalse(sm.fit(lfp, nfp))
#Test anonymous fit.
self.assertEqual(sm.fit_anonymous(lfp, nfp),
{Composition("Li"): Composition("Na")})
self.assertAlmostEqual(sm.get_minimax_rms_anonymous(lfp, nfp)[0],
0.096084154118549828)
#Test partial occupancies.
s1 = Structure([[3, 0, 0], [0, 3, 0], [0, 0, 3]],
[{"Fe": 0.5}, {"Fe": 0.5}, {"Fe": 0.5}, {"Fe": 0.5}],
[[0, 0, 0], [0.25, 0.25, 0.25],
[0.5, 0.5, 0.5], [0.75, 0.75, 0.75]])
s2 = Structure([[3, 0, 0], [0, 3, 0], [0, 0, 3]],
[{"Fe": 0.25}, {"Fe": 0.5}, {"Fe": 0.5}, {"Fe": 0.75}],
[[0, 0, 0], [0.25, 0.25, 0.25],
[0.5, 0.5, 0.5], [0.75, 0.75, 0.75]])
self.assertFalse(sm.fit(s1, s2))
self.assertFalse(sm.fit(s2, s1))
s2 = Structure([[3, 0, 0], [0, 3, 0], [0, 0, 3]],
[{"Fe": 0.25}, {"Fe": 0.25}, {"Fe": 0.25},
{"Fe": 0.25}],
[[0, 0, 0], [0.25, 0.25, 0.25],
[0.5, 0.5, 0.5], [0.75, 0.75, 0.75]])
self.assertEqual(sm.fit_anonymous(s1, s2),
{Composition("Fe0.5"): Composition("Fe0.25")})
self.assertAlmostEqual(sm.get_minimax_rms_anonymous(s1, s2)[0], 0)
示例2: test_init
# 需要导入模块: from pymatgen.core.structure_modifier import StructureEditor [as 别名]
# 或者: from pymatgen.core.structure_modifier.StructureEditor import apply_operation [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!")
示例3: apply_transformation
# 需要导入模块: from pymatgen.core.structure_modifier import StructureEditor [as 别名]
# 或者: from pymatgen.core.structure_modifier.StructureEditor import apply_operation [as 别名]
def apply_transformation(self, structure):
editor = StructureEditor(structure)
editor.apply_operation(self._symmop)
return editor.modified_structure
示例4: apply_operation
# 需要导入模块: from pymatgen.core.structure_modifier import StructureEditor [as 别名]
# 或者: from pymatgen.core.structure_modifier.StructureEditor import apply_operation [as 别名]
def apply_operation(structure, symmop):
editor = StructureEditor(structure)
editor.apply_operation(symmop)
return editor.modified_structure