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


Python TransformedStructure.as_dict方法代码示例

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


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

示例1: TransformedStructureTest

# 需要导入模块: from pymatgen.alchemy.materials import TransformedStructure [as 别名]
# 或者: from pymatgen.alchemy.materials.TransformedStructure import as_dict [as 别名]

#.........这里部分代码省略.........
                    "label": "Fe",
                },
                {
                    "occu": 1,
                    "abc": [0.5218619395656168, 0.25000080611787734, 0.7814492408373795],
                    "xyz": [2.48101, 1.52258, 8.17597],
                    "species": [{"occu": 1, "element": "Fe"}],
                    "label": "Fe",
                },
            ],
        }
        structure = Structure.from_dict(structure_dict)
        self.structure = structure
        trans = [SubstitutionTransformation({"Li": "Na"})]
        self.trans = TransformedStructure(structure, trans)

    def test_append_transformation(self):
        t = SubstitutionTransformation({"Fe": "Mn"})
        self.trans.append_transformation(t)
        self.assertEqual("NaMnPO4", self.trans.final_structure.composition.reduced_formula)
        self.assertEqual(len(self.trans.structures), 3)
        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.75, 0.5, 0.75])
        lattice = [[3.8401979337, 0.00, 0.00], [1.9200989668, 3.3257101909, 0.00], [0.00, -2.2171384943, 3.1355090603]]
        struct = Structure(lattice, ["Si4+", "Si4+"], coords)
        ts = TransformedStructure(struct, [])
        ts.append_transformation(SupercellTransformation.from_scaling_factors(2, 1, 1))
        alt = ts.append_transformation(
            PartialRemoveSpecieTransformation("Si4+", 0.5, algo=PartialRemoveSpecieTransformation.ALGO_COMPLETE), 5
        )
        self.assertEqual(len(alt), 2)

    def test_append_filter(self):
        f3 = ContainsSpecieFilter(["O2-"], strict_compare=True, AND=False)
        self.trans.append_filter(f3)

    def test_get_vasp_input(self):
        SETTINGS["VASP_PSP_DIR"] = os.path.abspath(
            os.path.join(os.path.dirname(__file__), "..", "..", "..", "test_files")
        )
        potcar = self.trans.get_vasp_input(MPRelaxSet)["POTCAR"]
        self.assertEqual("Na_pv\nFe_pv\nP\nO", "\n".join([p.symbol for p in potcar]))
        self.assertEqual(len(self.trans.structures), 2)

    def test_final_structure(self):
        self.assertEqual("NaFePO4", self.trans.final_structure.composition.reduced_formula)

    def test_from_dict(self):
        d = json.load(open(os.path.join(test_dir, "transformations.json"), "r"))
        d["other_parameters"] = {"tags": ["test"]}
        ts = TransformedStructure.from_dict(d)
        ts.other_parameters["author"] = "Will"
        ts.append_transformation(SubstitutionTransformation({"Fe": "Mn"}))
        self.assertEqual("MnPO4", ts.final_structure.composition.reduced_formula)
        self.assertEqual(ts.other_parameters, {"author": "Will", "tags": ["test"]})

    def test_undo_and_redo_last_change(self):
        trans = [SubstitutionTransformation({"Li": "Na"}), SubstitutionTransformation({"Fe": "Mn"})]
        ts = TransformedStructure(self.structure, trans)
        self.assertEqual("NaMnPO4", ts.final_structure.composition.reduced_formula)
        ts.undo_last_change()
        self.assertEqual("NaFePO4", ts.final_structure.composition.reduced_formula)
        ts.undo_last_change()
        self.assertEqual("LiFePO4", ts.final_structure.composition.reduced_formula)
        self.assertRaises(IndexError, ts.undo_last_change)
        ts.redo_next_change()
        self.assertEqual("NaFePO4", ts.final_structure.composition.reduced_formula)
        ts.redo_next_change()
        self.assertEqual("NaMnPO4", ts.final_structure.composition.reduced_formula)
        self.assertRaises(IndexError, ts.redo_next_change)
        # Make sure that this works with filters.
        f3 = ContainsSpecieFilter(["O2-"], strict_compare=True, AND=False)
        ts.append_filter(f3)
        ts.undo_last_change()
        ts.redo_next_change()

    def test_as_dict(self):
        self.trans.set_parameter("author", "will")
        d = self.trans.as_dict()
        self.assertIn("last_modified", d)
        self.assertIn("history", d)
        self.assertIn("version", d)
        self.assertIn("author", d["other_parameters"])
        self.assertEqual(Structure.from_dict(d).formula, "Na4 Fe4 P4 O16")

    def test_snl(self):
        self.trans.set_parameter("author", "will")
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            snl = self.trans.to_snl([("will", "[email protected]")])
            self.assertEqual(len(w), 1, "Warning not raised on type conversion " "with other_parameters")
        ts = TransformedStructure.from_snl(snl)
        self.assertEqual(ts.history[-1]["@class"], "SubstitutionTransformation")

        h = ("testname", "testURL", {"test": "testing"})
        snl = StructureNL(ts.final_structure, [("will", "[email protected]")], history=[h])
        snl = TransformedStructure.from_snl(snl).to_snl([("notwill", "[email protected]")])
        self.assertEqual(snl.history, [h])
        self.assertEqual(snl.authors, [("notwill", "[email protected]")])
开发者ID:shyamd,项目名称:pymatgen,代码行数:104,代码来源:test_materials.py

示例2: TransformedStructureTest

# 需要导入模块: from pymatgen.alchemy.materials import TransformedStructure [as 别名]
# 或者: from pymatgen.alchemy.materials.TransformedStructure import as_dict [as 别名]
class TransformedStructureTest(PymatgenTest):

    def setUp(self):
        structure = PymatgenTest.get_structure("LiFePO4")
        self.structure = structure
        trans = [SubstitutionTransformation({"Li": "Na"})]
        self.trans = TransformedStructure(structure, trans)

    def test_append_transformation(self):
        t = SubstitutionTransformation({"Fe": "Mn"})
        self.trans.append_transformation(t)
        self.assertEqual("NaMnPO4",
                         self.trans.final_structure.composition
                         .reduced_formula)
        self.assertEqual(len(self.trans.structures), 3)
        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.75, 0.5, 0.75])
        lattice = [[3.8401979337, 0.00, 0.00],
                   [1.9200989668, 3.3257101909, 0.00],
                   [0.00, -2.2171384943, 3.1355090603]]
        struct = Structure(lattice, ["Si4+", "Si4+"], coords)
        ts = TransformedStructure(struct, [])
        ts.append_transformation(SupercellTransformation
                                 .from_scaling_factors(2, 1, 1))
        alt = ts.append_transformation(
            PartialRemoveSpecieTransformation(
                'Si4+', 0.5,
                algo=PartialRemoveSpecieTransformation.ALGO_COMPLETE), 5)
        self.assertEqual(len(alt), 2)

    def test_append_filter(self):
        f3 = ContainsSpecieFilter(['O2-'], strict_compare=True, AND=False)
        self.trans.append_filter(f3)

    def test_get_vasp_input(self):
        SETTINGS["PMG_VASP_PSP_DIR"] = os.path.abspath(
                os.path.join(os.path.dirname(__file__), "..", "..", "..",
                             "test_files"))
        potcar = self.trans.get_vasp_input(MPRelaxSet)['POTCAR']
        self.assertEqual("Na_pv\nFe_pv\nP\nO",
                         "\n".join([p.symbol for p in potcar]))
        self.assertEqual(len(self.trans.structures), 2)

    def test_final_structure(self):
        self.assertEqual("NaFePO4", self.trans.final_structure.composition
                         .reduced_formula)

    def test_from_dict(self):
        d = json.load(open(os.path.join(test_dir, 'transformations.json'),
                           'r'))
        d['other_parameters'] = {'tags': ['test']}
        ts = TransformedStructure.from_dict(d)
        ts.other_parameters['author'] = 'Will'
        ts.append_transformation(SubstitutionTransformation({"Fe": "Mn"}))
        self.assertEqual("MnPO4",
                         ts.final_structure.composition.reduced_formula)
        self.assertEqual(ts.other_parameters, {'author': 'Will',
                                               'tags': ['test']})

    def test_undo_and_redo_last_change(self):
        trans = [SubstitutionTransformation({"Li": "Na"}),
                 SubstitutionTransformation({"Fe": "Mn"})]
        ts = TransformedStructure(self.structure, trans)
        self.assertEqual("NaMnPO4",
                         ts.final_structure.composition.reduced_formula)
        ts.undo_last_change()
        self.assertEqual("NaFePO4",
                         ts.final_structure.composition.reduced_formula)
        ts.undo_last_change()
        self.assertEqual("LiFePO4",
                         ts.final_structure.composition.reduced_formula)
        self.assertRaises(IndexError, ts.undo_last_change)
        ts.redo_next_change()
        self.assertEqual("NaFePO4",
                         ts.final_structure.composition.reduced_formula)
        ts.redo_next_change()
        self.assertEqual("NaMnPO4",
                         ts.final_structure.composition.reduced_formula)
        self.assertRaises(IndexError, ts.redo_next_change)
        #Make sure that this works with filters.
        f3 = ContainsSpecieFilter(['O2-'], strict_compare=True, AND=False)
        ts.append_filter(f3)
        ts.undo_last_change()
        ts.redo_next_change()

    def test_as_dict(self):
        self.trans.set_parameter('author', 'will')
        d = self.trans.as_dict()
        self.assertIn('last_modified', d)
        self.assertIn('history', d)
        self.assertIn('version', d)
        self.assertIn('author', d['other_parameters'])
        self.assertEqual(Structure.from_dict(d).formula, 'Na4 Fe4 P4 O16')

    def test_snl(self):
        self.trans.set_parameter('author', 'will')
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            snl = self.trans.to_snl([('will', '[email protected]')])
#.........这里部分代码省略.........
开发者ID:albalu,项目名称:pymatgen,代码行数:103,代码来源:test_materials.py


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