• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python structure.IStructure类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: get_all_nearest_neighbors

def get_all_nearest_neighbors(method, structure):
    """Get the nearest neighbor list of a structure

    Args:
        method (NearNeighbor) - Method used to compute nearest neighbors
        structure (IStructure) - Structure to study
    Returns:
        Output of `method.get_all_nn_info(structure)`
    """

    # pymatgen does not hash Structure objects, so we need
    #  to convert from Structure to the immutatble IStructure method
    if isinstance(structure, Structure):
        structure = IStructure.from_sites(structure)
    return _get_all_nearest_neighbors(method, structure)
开发者ID:RamyaGuru,项目名称:matminer,代码行数:15,代码来源:caching.py


示例17: apply_transformation

    def apply_transformation(self, structure):
        # get the new sites
        new_sites = self._voronoi_points(structure)
        if self._midpoints:
            dms = self._delaunay_midpoints(structure)
            for i in range(len(new_sites)):
                new_sites[i].extend(dms[i])

        # insert the new sites with dummy species
        se = structure
        dummy = DummySpecie()
        for i, sites_list in enumerate(new_sites):
            for ns in sites_list:
                if self._bl == {}:
                    se.append(self._sp, ns, coords_are_cartesian=True, validate_proximity=False)
                elif structure[i].specie in self._bl.keys():
                    bv = ns - structure[i].coords
                    bv *= self._bl[structure[i].specie] / np.linalg.norm(bv)
                    coords = structure[i].coords + bv
                    se.append_site(self._sp, coords, coords_are_cartesian=True, validate_proximity=False)
        logging.debug("Starting moving to unit cell")
        se = IStructure.get_reduced_structure(se)
        logging.debug("Finished moving to unit cell")

        structure = se  # .modified_structure

        # delete sites that are closer than the bond distance
        to_delete = []
        for sp, d in self._bl.items():
            neighbors = structure.get_all_neighbors(d * 0.999)
            for i in range(len(structure)):
                if structure[i].specie == dummy:
                    for n in neighbors[i]:
                        if n[0].specie == sp:
                            to_delete.append(i)
                            break
        se.remove_sites(to_delete)

        # replace the dummy species to get the correct composition
        if self._n:
            # amt = self._n / se.modified_structure.composition[dummy]
            amt = self._n / se.composition[dummy]
            se.replace_species({dummy: {self._sp: amt}})

        return se  # .modified_structure
开发者ID:tchen0965,项目名称:structural_descriptors_repo,代码行数:45,代码来源:voronoi.py


示例18: 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)
        bcc_prim = bcc_li.get_primitive_structure()
        self.assertEqual(len(bcc_prim), 1)
        self.assertAlmostEqual(bcc_prim.lattice.alpha, 109.47122, 3)

        coords = [[0] * 3, [0.5] * 3, [0.25] * 3, [0.26] * 3]
        s = IStructure(Lattice.cubic(4.09), ["Ag"] * 4, coords)
        self.assertEqual(len(s.get_primitive_structure()), 4)
开发者ID:Lightslayer,项目名称:pymatgen,代码行数:13,代码来源:test_structure.py


示例19: IStructureTest

class IStructureTest(PymatgenTest):

    def setUp(self):
        coords = [[0, 0, 0], [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.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]})

    def test_matches(self):
        ss = self.struct * 2
        self.assertTrue(ss.matches(self.struct))

    def test_bad_structure(self):
        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.75, 0.5, 0.75])
        coords.append([0.75, 0.5, 0.75])
        self.assertRaises(StructureError, IStructure, self.lattice,
                          ["Si"] * 3, coords, validate_proximity=True)
        #these shouldn't raise an error
        IStructure(self.lattice, ["Si"] * 2, coords[:2], True)
        IStructure(self.lattice, ["Si"], coords[:1], True)


    def test_volume_and_density(self):
        self.assertAlmostEqual(self.struct.volume, 40.04, 2, "Volume wrong!")
        self.assertAlmostEqual(self.struct.density, 2.33, 2,
                               "Incorrect density")

    def test_specie_init(self):
        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.75, 0.5, 0.75])
        s = IStructure(self.lattice, [{Specie('O', -2): 1.0},
                                      {Specie('Mg', 2): 0.8}], coords)
        self.assertEqual(s.composition.formula, 'Mg0.8 O1')

    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"])

    def test_get_spacegroup_data(self):
        self.assertEqual(self.struct.get_spacegroup_info(), ('Fd-3m', 227))

    def test_fractional_occupations(self):
        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.75, 0.5, 0.75])
        s = IStructure(self.lattice, [{'O': 1.0}, {'Mg': 0.8}],
                       coords)
        self.assertEqual(s.composition.formula, 'Mg0.8 O1')
        self.assertFalse(s.is_ordered)

    def test_get_distance(self):
        self.assertAlmostEqual(self.struct.get_distance(0, 1), 2.35, 2,
                               "Distance calculated wrongly!")
        pt = [0.9, 0.9, 0.8]
        self.assertAlmostEqual(self.struct[0].distance_from_point(pt),
                               1.50332963784, 2,
                               "Distance calculated wrongly!")

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


示例20: IStructureTest

class IStructureTest(PymatgenTest):

    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.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]})

    def test_bad_structure(self):
        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.75, 0.5, 0.75])
        coords.append([0.75, 0.5, 0.75])
        self.assertRaises(StructureError, IStructure, self.lattice,
                          ["Si"] * 3, coords, validate_proximity=True)

    def test_volume_and_density(self):
        self.assertAlmostEqual(self.struct.volume, 40.04, 2, "Volume wrong!")
        self.assertAlmostEqual(self.struct.density, 2.33, 2,
                               "Incorrect density")

    def test_specie_init(self):
        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.75, 0.5, 0.75])
        s = IStructure(self.lattice, [{Specie('O', -2): 1.0},
                                      {Specie('Mg', 2): 0.8}], coords)
        self.assertEqual(str(s.composition), 'Mg2+0.8 O2-1')

    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"])


    def test_fractional_occupations(self):
        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.75, 0.5, 0.75])
        s = IStructure(self.lattice, [{'O': 1.0}, {'Mg': 0.8}],
                       coords)
        self.assertEqual(str(s.composition), 'Mg0.8 O1')
        self.assertFalse(s.is_ordered)

    def test_get_distance(self):
        self.assertAlmostEqual(self.struct.get_distance(0, 1), 2.35, 2,
                               "Distance calculated wrongly!")
        pt = [0.9, 0.9, 0.8]
        self.assertAlmostEqual(self.struct[0].distance_from_point(pt),
                               1.50332963784, 2,
                               "Distance calculated wrongly!")

    def test_to_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.to_dict)
        self.assertIn("sites", struct.to_dict)
        d = self.propertied_structure.to_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.to_dict
#.........这里部分代码省略.........
开发者ID:leicheng,项目名称:pymatgen,代码行数:101,代码来源:test_structure.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python structure.Molecule类代码示例发布时间:2022-05-25
下一篇:
Python structure.IMolecule类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap