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


Python structure.IStructure类代码示例

本文整理汇总了Python中pymatgen.core.structure.IStructure的典型用法代码示例。如果您正苦于以下问题:Python IStructure类的具体用法?Python IStructure怎么用?Python IStructure使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_interpolate_lattice

    def test_interpolate_lattice(self):
        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.75, 0.5, 0.75])
        struct = IStructure(self.lattice, ["Si"] * 2, coords)
        coords2 = list()
        coords2.append([0, 0, 0])
        coords2.append([0.5, 0.5, 0.5])
        l2 = Lattice.from_lengths_and_angles([3,4,4], [100,100,70])
        struct2 = IStructure(l2, ["Si"] * 2, coords2)
        int_s = struct.interpolate(struct2, 2, interpolate_lattices=True)
        self.assertArrayAlmostEqual(struct.lattice.abc,
                                    int_s[0].lattice.abc)
        self.assertArrayAlmostEqual(struct.lattice.angles,
                                    int_s[0].lattice.angles)
        self.assertArrayAlmostEqual(struct2.lattice.abc,
                                    int_s[2].lattice.abc)
        self.assertArrayAlmostEqual(struct2.lattice.angles,
                                    int_s[2].lattice.angles)
        int_angles = [110.3976469, 94.5359731, 64.5165856]
        self.assertArrayAlmostEqual(int_angles,
                                    int_s[1].lattice.angles)

        # Assert that volume is monotonic
        self.assertTrue(struct2.lattice.volume >= int_s[1].lattice.volume)
        self.assertTrue(int_s[1].lattice.volume >= struct.lattice.volume)
开发者ID:gpetretto,项目名称:pymatgen,代码行数:26,代码来源:test_structure.py

示例2: test_from_dict

    def test_from_dict(self):

        d = self.propertied_structure.as_dict()
        s = IStructure.from_dict(d)
        self.assertEqual(s[0].magmom, 5)
        d = self.propertied_structure.as_dict(0)
        s2 = IStructure.from_dict(d)
        self.assertEqual(s, s2)

        d = {'lattice': {'a': 3.8401979337, 'volume': 40.044794644251596,
                         'c': 3.8401979337177736, 'b': 3.840198994344244,
                         'matrix': [[3.8401979337, 0.0, 0.0],
                                    [1.9200989668, 3.3257101909, 0.0],
                                    [0.0, -2.2171384943, 3.1355090603]],
                         'alpha': 119.9999908639842, 'beta': 90.0,
                         'gamma': 60.000009137322195},
             'sites': [{'properties': {'magmom': 5}, 'abc': [0.0, 0.0, 0.0],
                        'occu': 1.0, 'species': [{'occu': 1.0,
                                                  'oxidation_state': -2,
                                                  'properties': {'spin': 3},
                                                  'element': 'O'}],
                        'label': 'O2-', 'xyz': [0.0, 0.0, 0.0]},
                       {'properties': {'magmom': -5},
                        'abc': [0.75, 0.5, 0.75],
                        'occu': 0.8, 'species': [{'occu': 0.8,
                                                  'oxidation_state': 2,
                                                  'properties': {'spin': 2},
                                                  'element': 'Mg'}],
                        'label': 'Mg2+:0.800',
                        'xyz': [3.8401979336749994, 1.2247250003039056e-06,
                                2.351631795225]}]}
        s = IStructure.from_dict(d)
        self.assertEqual(s[0].magmom, 5)
        self.assertEqual(s[0].specie.spin, 3)
        self.assertEqual(type(s), IStructure)
开发者ID:Lightslayer,项目名称:pymatgen,代码行数:35,代码来源:test_structure.py

示例3: test_get_primitive_structure

 def test_get_primitive_structure(self):
     coords = [[0, 0, 0], [0.5, 0.5, 0], [0, 0.5, 0.5], [0.5, 0, 0.5]]
     fcc_ag = IStructure(Lattice.cubic(4.09), ["Ag"] * 4, coords)
     self.assertEqual(len(fcc_ag.get_primitive_structure()), 1)
     coords = [[0, 0, 0], [0.5, 0.5, 0.5]]
     bcc_li = IStructure(Lattice.cubic(4.09), ["Li"] * 2, coords)
     self.assertEqual(len(bcc_li.get_primitive_structure()), 1)
开发者ID:leicheng,项目名称:pymatgen,代码行数:7,代码来源:test_structure.py

示例4: test_primitive_structure_volume_check

 def test_primitive_structure_volume_check(self):
     l = Lattice.tetragonal(10, 30)
     coords = [[0.5, 0.8, 0], [0.5, 0.2, 0],
               [0.5, 0.8, 0.333], [0.5, 0.5, 0.333],
               [0.5, 0.5, 0.666], [0.5, 0.2, 0.666]]
     s = IStructure(l, ["Ag"] * 6, coords)
     sprim = s.get_primitive_structure(tolerance=0.1)
     self.assertEqual(len(sprim), 6)
开发者ID:Lightslayer,项目名称:pymatgen,代码行数:8,代码来源:test_structure.py

示例5: test_interpolate_lattice_rotation

    def test_interpolate_lattice_rotation(self):
        l1 = Lattice([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
        l2 = Lattice([[-1.01, 0, 0], [0, -1.01, 0], [0, 0, 1]])
        coords = [[0, 0, 0], [0.75, 0.5, 0.75]]
        struct1 = IStructure(l1, ["Si"] * 2, coords)
        struct2 = IStructure(l2, ["Si"] * 2, coords)
        int_s = struct1.interpolate(struct2, 2, interpolate_lattices=True)

        # Assert that volume is monotonic
        self.assertTrue(struct2.lattice.volume >= int_s[1].lattice.volume)
        self.assertTrue(int_s[1].lattice.volume >= struct1.lattice.volume)
开发者ID:gpetretto,项目名称:pymatgen,代码行数:11,代码来源:test_structure.py

示例6: test_get_sorted_structure

 def test_get_sorted_structure(self):
     coords = list()
     coords.append([0, 0, 0])
     coords.append([0.75, 0.5, 0.75])
     s = IStructure(self.lattice, ["O", "Li"], coords, site_properties={"charge": [-2, 1]})
     sorted_s = s.get_sorted_structure()
     self.assertEqual(sorted_s[0].species_and_occu, Composition("Li"))
     self.assertEqual(sorted_s[1].species_and_occu, Composition("O"))
     self.assertEqual(sorted_s[0].charge, 1)
     self.assertEqual(sorted_s[1].charge, -2)
     s = IStructure(self.lattice, ["Se", "C", "Se", "C"], [[0] * 3, [0.5] * 3, [0.25] * 3, [0.75] * 3])
     self.assertEqual([site.specie.symbol for site in s.get_sorted_structure()], ["C", "C", "Se", "Se"])
开发者ID:richardtran415,项目名称:pymatgen,代码行数:12,代码来源:test_structure.py

示例7: test_interpolate

    def test_interpolate(self):
        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.75, 0.5, 0.75])
        struct = IStructure(self.lattice, ["Si"] * 2, coords)
        coords2 = list()
        coords2.append([0, 0, 0])
        coords2.append([0.5, 0.5, 0.5])
        struct2 = IStructure(self.struct.lattice, ["Si"] * 2, coords2)
        int_s = struct.interpolate(struct2, 10)
        for s in int_s:
            self.assertIsNotNone(s, "Interpolation Failed!")
            self.assertEqual(int_s[0].lattice, s.lattice)
        self.assertArrayEqual(int_s[1][1].frac_coords, [0.725, 0.5, 0.725])

        badlattice = [[1, 0.00, 0.00], [0, 1, 0.00], [0.00, 0, 1]]
        struct2 = IStructure(badlattice, ["Si"] * 2, coords2)
        self.assertRaises(ValueError, struct.interpolate, struct2)

        coords2 = list()
        coords2.append([0, 0, 0])
        coords2.append([0.5, 0.5, 0.5])
        struct2 = IStructure(self.struct.lattice, ["Si", "Fe"], coords2)
        self.assertRaises(ValueError, struct.interpolate, struct2)

        # Test autosort feature.
        s1 = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3),
                                       ["Fe"], [[0, 0, 0]])
        s1.pop(0)
        s2 = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3),
                                       ["Fe"], [[0, 0, 0]])
        s2.pop(2)
        random.shuffle(s2)

        for s in s1.interpolate(s2, autosort_tol=0.5):
            self.assertArrayAlmostEqual(s1[0].frac_coords, s[0].frac_coords)
            self.assertArrayAlmostEqual(s1[2].frac_coords, s[2].frac_coords)

        # Make sure autosort has no effect on simpler interpolations,
        # and with shuffled sites.
        s1 = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3),
                                       ["Fe"], [[0, 0, 0]])
        s2 = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3),
                                       ["Fe"], [[0, 0, 0]])
        s2[0] = "Fe", [0.01, 0.01, 0.01]
        random.shuffle(s2)

        for s in s1.interpolate(s2, autosort_tol=0.5):
            self.assertArrayAlmostEqual(s1[1].frac_coords, s[1].frac_coords)
            self.assertArrayAlmostEqual(s1[2].frac_coords, s[2].frac_coords)
            self.assertArrayAlmostEqual(s1[3].frac_coords, s[3].frac_coords)
开发者ID:Lightslayer,项目名称:pymatgen,代码行数:51,代码来源:test_structure.py

示例8: setUp

 def setUp(self):
     coords = list()
     coords.append([0, 0, 0])
     coords.append([0.75, 0.5, 0.75])
     self.lattice = Lattice(
         [[3.8401979337, 0.00, 0.00], [1.9200989668, 3.3257101909, 0.00], [0.00, -2.2171384943, 3.1355090603]]
     )
     self.struct = IStructure(self.lattice, ["Si"] * 2, coords)
     self.assertEqual(len(self.struct), 2, "Wrong number of sites in structure!")
     self.assertTrue(self.struct.is_ordered)
     self.assertTrue(self.struct.ntypesp == 1)
     coords = list()
     coords.append([0, 0, 0])
     coords.append([0.0, 0, 0.0000001])
     self.assertRaises(StructureError, IStructure, self.lattice, ["Si"] * 2, coords, True)
     self.propertied_structure = IStructure(self.lattice, ["Si"] * 2, coords, site_properties={"magmom": [5, -5]})
开发者ID:richardtran415,项目名称:pymatgen,代码行数:16,代码来源:test_structure.py

示例9: test_to_from_file_string

    def test_to_from_file_string(self):
        for fmt in ["cif", "json", "poscar", "cssr"]:
            s = self.struct.to(fmt=fmt)
            self.assertIsNotNone(s)
            ss = IStructure.from_str(s, fmt=fmt)
            self.assertArrayAlmostEqual(
                ss.lattice.lengths_and_angles,
                self.struct.lattice.lengths_and_angles, decimal=5)
            self.assertArrayAlmostEqual(ss.frac_coords, self.struct.frac_coords)
            self.assertIsInstance(ss, IStructure)

        self.struct.to(filename="POSCAR.testing")
        self.assertTrue(os.path.exists("POSCAR.testing"))
        os.remove("POSCAR.testing")

        self.struct.to(filename="Si_testing.yaml")
        self.assertTrue(os.path.exists("Si_testing.yaml"))
        s = Structure.from_file("Si_testing.yaml")
        self.assertEqual(s, self.struct)
        os.remove("Si_testing.yaml")

        self.struct.to(filename="POSCAR.testing.gz")
        s = Structure.from_file("POSCAR.testing.gz")
        self.assertEqual(s, self.struct)
        os.remove("POSCAR.testing.gz")
开发者ID:xhqu1981,项目名称:pymatgen,代码行数:25,代码来源:test_structure.py

示例10: test_interpolate_lattice

 def test_interpolate_lattice(self):
     coords = list()
     coords.append([0, 0, 0])
     coords.append([0.75, 0.5, 0.75])
     struct = IStructure(self.lattice, ["Si"] * 2, coords)
     coords2 = list()
     coords2.append([0, 0, 0])
     coords2.append([0.5, 0.5, 0.5])
     l2 = Lattice.from_lengths_and_angles([3, 4, 4], [100, 100, 70])
     struct2 = IStructure(l2, ["Si"] * 2, coords2)
     int_s = struct.interpolate(struct2, 2, interpolate_lattices=True)
     self.assertArrayAlmostEqual(struct.lattice.abc, int_s[0].lattice.abc)
     self.assertArrayAlmostEqual(struct.lattice.angles, int_s[0].lattice.angles)
     self.assertArrayAlmostEqual(struct2.lattice.abc, int_s[2].lattice.abc)
     self.assertArrayAlmostEqual(struct2.lattice.angles, int_s[2].lattice.angles)
     int_angles = [(a + struct2.lattice.angles[i]) / 2 for i, a in enumerate(struct.lattice.angles)]
     self.assertArrayAlmostEqual(int_angles, int_s[1].lattice.angles)
开发者ID:richardtran415,项目名称:pymatgen,代码行数:17,代码来源:test_structure.py

示例11: test_copy

    def test_copy(self):
        new_struct = self.propertied_structure.copy(site_properties={"charge": [2, 3]})
        self.assertEqual(new_struct[0].magmom, 5)
        self.assertEqual(new_struct[1].magmom, -5)
        self.assertEqual(new_struct[0].charge, 2)
        self.assertEqual(new_struct[1].charge, 3)

        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.0, 0, 0.0000001])

        structure = IStructure(self.lattice, ["O", "Si"], coords, site_properties={"magmom": [5, -5]})

        new_struct = structure.copy(site_properties={"charge": [2, 3]}, sanitize=True)
        self.assertEqual(new_struct[0].magmom, -5)
        self.assertEqual(new_struct[1].magmom, 5)
        self.assertEqual(new_struct[0].charge, 3)
        self.assertEqual(new_struct[1].charge, 2)
        self.assertAlmostEqual(new_struct.volume, structure.volume)
开发者ID:richardtran415,项目名称:pymatgen,代码行数:19,代码来源:test_structure.py

示例12: test_from_dict

 def test_from_dict(self):
     d = self.propertied_structure.to_dict
     s = IStructure.from_dict(d)
     self.assertEqual(s[0].magmom, 5)
     d = {
         "lattice": {
             "a": 3.8401979337,
             "volume": 40.044794644251596,
             "c": 3.8401979337177736,
             "b": 3.840198994344244,
             "matrix": [
                 [3.8401979337, 0.0, 0.0],
                 [1.9200989668, 3.3257101909, 0.0],
                 [0.0, -2.2171384943, 3.1355090603],
             ],
             "alpha": 119.9999908639842,
             "beta": 90.0,
             "gamma": 60.000009137322195,
         },
         "sites": [
             {
                 "properties": {"magmom": 5},
                 "abc": [0.0, 0.0, 0.0],
                 "occu": 1.0,
                 "species": [{"occu": 1.0, "oxidation_state": -2, "properties": {"spin": 3}, "element": "O"}],
                 "label": "O2-",
                 "xyz": [0.0, 0.0, 0.0],
             },
             {
                 "properties": {"magmom": -5},
                 "abc": [0.75, 0.5, 0.75],
                 "occu": 0.8,
                 "species": [{"occu": 0.8, "oxidation_state": 2, "properties": {"spin": 2}, "element": "Mg"}],
                 "label": "Mg2+:0.800",
                 "xyz": [3.8401979336749994, 1.2247250003039056e-06, 2.351631795225],
             },
         ],
     }
     s = IStructure.from_dict(d)
     self.assertEqual(s[0].magmom, 5)
     self.assertEqual(s[0].specie.spin, 3)
     self.assertEqual(type(s), IStructure)
开发者ID:richardtran415,项目名称:pymatgen,代码行数:42,代码来源:test_structure.py

示例13: featurize

    def featurize(self, structure):
        """Convert a pymatgen Structure to an immutable IStructure,

        Args:
            structure (`pymatgen.core.structure.Structure`): A structure.

        Returns:
            (`pymatgen.core.structure.IStructure`): An immutable IStructure
                object.
        """
        return [IStructure.from_sites(structure)]
开发者ID:ardunn,项目名称:MatMiner,代码行数:11,代码来源:conversions.py

示例14: test_as_dict

    def test_as_dict(self):
        si = Specie("Si", 4)
        mn = Element("Mn")
        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.75, 0.5, 0.75])
        struct = IStructure(self.lattice, [{si: 0.5, mn: 0.5}, {si: 0.5}],
                            coords)
        self.assertIn("lattice", struct.as_dict())
        self.assertIn("sites", struct.as_dict())
        d = self.propertied_structure.as_dict()
        self.assertEqual(d['sites'][0]['properties']['magmom'], 5)
        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.75, 0.5, 0.75])
        s = IStructure(self.lattice, [{Specie('O', -2,
                                              properties={"spin": 3}): 1.0},
                                      {Specie('Mg', 2,
                                              properties={"spin": 2}): 0.8}],
                       coords, site_properties={'magmom': [5, -5]})
        d = s.as_dict()
        self.assertEqual(d['sites'][0]['properties']['magmom'], 5)
        self.assertEqual(d['sites'][0]['species'][0]['properties']['spin'], 3)

        d = s.as_dict(0)
        self.assertNotIn("volume", d['lattice'])
        self.assertNotIn("xyz", d['sites'][0])
开发者ID:Lightslayer,项目名称:pymatgen,代码行数:27,代码来源:test_structure.py

示例15: test_interpolate

    def test_interpolate(self):
        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.75, 0.5, 0.75])
        struct = IStructure(self.lattice, ["Si"] * 2, coords)
        coords2 = list()
        coords2.append([0, 0, 0])
        coords2.append([0.5, 0.5, 0.5])
        struct2 = IStructure(self.struct.lattice, ["Si"] * 2, coords2)
        int_s = struct.interpolate(struct2, 10)
        for s in int_s:
            self.assertIsNotNone(s, "Interpolation Failed!")
        self.assertArrayEqual(int_s[1][1].frac_coords, [0.725, 0.5, 0.725])

        badlattice = [[1, 0.00, 0.00], [0, 1, 0.00], [0.00, 0, 1]]
        struct2 = IStructure(badlattice, ["Si"] * 2, coords2)
        self.assertRaises(ValueError, struct.interpolate, struct2)

        coords2 = list()
        coords2.append([0, 0, 0])
        coords2.append([0.5, 0.5, 0.5])
        struct2 = IStructure(self.struct.lattice, ["Si", "Fe"], coords2)
        self.assertRaises(ValueError, struct.interpolate, struct2)
开发者ID:miaoliu,项目名称:pymatgen,代码行数:23,代码来源:test_structure.py


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