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

Python lattice.Lattice类代码示例

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

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



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

示例1: test_is_compatible

 def test_is_compatible(self):
     cubic = Lattice.cubic(1)
     hexagonal = Lattice.hexagonal(1, 2)
     rhom = Lattice.rhombohedral(3, 80)
     tet = Lattice.tetragonal(1, 2)
     ortho = Lattice.orthorhombic(1, 2, 3)
     sg = SpaceGroup("Fm-3m")
     self.assertTrue(sg.is_compatible(cubic))
     self.assertFalse(sg.is_compatible(hexagonal))
     sg = SpaceGroup("R-3mH")
     self.assertFalse(sg.is_compatible(cubic))
     self.assertTrue(sg.is_compatible(hexagonal))
     sg = SpaceGroup("R-3m")
     self.assertTrue(sg.is_compatible(cubic))
     self.assertTrue(sg.is_compatible(rhom))
     self.assertFalse(sg.is_compatible(hexagonal))
     sg = SpaceGroup("Pnma")
     self.assertTrue(sg.is_compatible(cubic))
     self.assertTrue(sg.is_compatible(tet))
     self.assertTrue(sg.is_compatible(ortho))
     self.assertFalse(sg.is_compatible(rhom))
     self.assertFalse(sg.is_compatible(hexagonal))
     sg = SpaceGroup("P12/c1")
     self.assertTrue(sg.is_compatible(cubic))
     self.assertTrue(sg.is_compatible(tet))
     self.assertTrue(sg.is_compatible(ortho))
     self.assertFalse(sg.is_compatible(rhom))
     self.assertFalse(sg.is_compatible(hexagonal))
     sg = SpaceGroup("P-1")
     self.assertTrue(sg.is_compatible(cubic))
     self.assertTrue(sg.is_compatible(tet))
     self.assertTrue(sg.is_compatible(ortho))
     self.assertTrue(sg.is_compatible(rhom))
     self.assertTrue(sg.is_compatible(hexagonal))
开发者ID:orex,项目名称:pymatgen,代码行数:34,代码来源:test_groups.py


示例2: test_get_slabs

    def test_get_slabs(self):
        gen = SlabGenerator(self.get_structure("CsCl"), [0, 0, 1], 10, 10)

        #Test orthogonality of some internal variables.
        a, b, c = gen.oriented_unit_cell.lattice.matrix
        self.assertAlmostEqual(np.dot(a, gen._normal), 0)
        self.assertAlmostEqual(np.dot(b, gen._normal), 0)

        self.assertEqual(len(gen.get_slabs()), 1)

        s = self.get_structure("LiFePO4")
        gen = SlabGenerator(s, [0, 0, 1], 10, 10)
        self.assertEqual(len(gen.get_slabs()), 5)

        self.assertEqual(len(gen.get_slabs(bonds={("P", "O"): 3})), 2)

        # There are no slabs in LFP that does not break either P-O or Fe-O
        # bonds for a miller index of [0, 0, 1].
        self.assertEqual(len(gen.get_slabs(
            bonds={("P", "O"): 3, ("Fe", "O"): 3})), 0)

        #If we allow some broken bonds, there are a few slabs.
        self.assertEqual(len(gen.get_slabs(
            bonds={("P", "O"): 3, ("Fe", "O"): 3},
            max_broken_bonds=2)), 2)

        # At this threshold, only the origin and center Li results in
        # clustering. All other sites are non-clustered. So the of
        # slabs is of sites in LiFePO4 unit cell - 2 + 1.
        self.assertEqual(len(gen.get_slabs(tol=1e-4)), 15)

        LiCoO2=Structure.from_file(get_path("icsd_LiCoO2.cif"),
                                          primitive=False)
        gen = SlabGenerator(LiCoO2, [0, 0, 1], 10, 10)
        lco = gen.get_slabs(bonds={("Co", "O"): 3})
        self.assertEqual(len(lco), 1)
        a, b, c = gen.oriented_unit_cell.lattice.matrix
        self.assertAlmostEqual(np.dot(a, gen._normal), 0)
        self.assertAlmostEqual(np.dot(b, gen._normal), 0)

        scc = Structure.from_spacegroup("Pm-3m", Lattice.cubic(3), ["Fe"],
                                        [[0, 0, 0]])
        gen = SlabGenerator(scc, [0, 0, 1], 10, 10)
        slabs = gen.get_slabs()
        self.assertEqual(len(slabs), 1)
        gen = SlabGenerator(scc, [1, 1, 1], 10, 10, max_normal_search=1)
        slabs = gen.get_slabs()
        self.assertEqual(len(slabs), 1)

        # Test whether using units of hkl planes instead of Angstroms for
        # min_slab_size and min_vac_size will give us the same number of atoms
        natoms = []
        for a in [1, 1.4, 2.5, 3.6]:
            s = Structure.from_spacegroup("Im-3m", Lattice.cubic(a), ["Fe"], [[0,0,0]])
            slabgen = SlabGenerator(s, (1,1,1), 10, 10, in_unit_planes=True,
                                    max_normal_search=2)
            natoms.append(len(slabgen.get_slab()))
        n = natoms[0]
        for i in natoms:
            self.assertEqual(n, i)
开发者ID:ExpHP,项目名称:pymatgen,代码行数:60,代码来源:test_surface.py


示例3: get_aligned_lattices

def get_aligned_lattices(slab_sub, slab_2d, max_area=200,
                         max_mismatch=0.05,
                         max_angle_diff=1, r1r2_tol=0.2):
    """
    given the 2 slab structures and the alignment paramters, return
    slab structures with lattices that are aligned with respect to each
    other
    """
    # get the matching substrate and 2D material lattices
    uv_substrate, uv_mat2d = get_matching_lattices(slab_sub, slab_2d,
                                                   max_area=max_area,
                                                   max_mismatch=max_mismatch,
                                                   max_angle_diff=max_angle_diff,
                                                   r1r2_tol=r1r2_tol)
    if not uv_substrate and not uv_mat2d:
        print("no matching u and v, trying adjusting the parameters")
        sys.exit()
    substrate = Structure.from_sites(slab_sub)
    mat2d = Structure.from_sites(slab_2d)
    # map the intial slabs to the newly found matching lattices
    substrate_latt = Lattice(np.array(
            [
                uv_substrate[0][:],
                uv_substrate[1][:],
                substrate.lattice.matrix[2, :]
            ]))
    # to avoid numerical issues with find_mapping
    mat2d_fake_c = mat2d.lattice.matrix[2, :] / np.linalg.norm(mat2d.lattice.matrix[2, :]) * 5.0
    mat2d_latt = Lattice(np.array(
            [
                uv_mat2d[0][:],
                uv_mat2d[1][:],
                mat2d_fake_c
            ]))
    mat2d_latt_fake = Lattice(np.array(
            [
                mat2d.lattice.matrix[0, :],
                mat2d.lattice.matrix[1, :],
                mat2d_fake_c
            ]))
    _, __, scell = substrate.lattice.find_mapping(substrate_latt,
                                                  ltol=0.05,
                                                  atol=1)
    scell[2] = np.array([0, 0, 1])
    substrate.make_supercell(scell)
    _, __, scell = mat2d_latt_fake.find_mapping(mat2d_latt,
                                                ltol=0.05,
                                                atol=1)
    scell[2] = np.array([0, 0, 1])
    mat2d.make_supercell(scell)
    # modify the substrate lattice so that the 2d material can be
    # grafted on top of it
    lmap = Lattice(np.array(
            [
                substrate.lattice.matrix[0, :],
                substrate.lattice.matrix[1, :],
                mat2d.lattice.matrix[2, :]
            ]))
    mat2d.modify_lattice(lmap)
    return substrate, mat2d
开发者ID:JARVIS-Unifies,项目名称:MPInterfaces,代码行数:60,代码来源:transformations.py


示例4: test_normal_search

    def test_normal_search(self):
        fcc = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3), ["Fe"],
                                        [[0, 0, 0]])
        for miller in [(1, 0, 0), (1, 1, 0), (1, 1, 1), (2, 1, 1)]:
            gen = SlabGenerator(fcc, miller, 10, 10)
            gen_normal = SlabGenerator(fcc, miller, 10, 10,
                                       max_normal_search=max(miller))
            slab = gen_normal.get_slab()
            self.assertAlmostEqual(slab.lattice.alpha, 90)
            self.assertAlmostEqual(slab.lattice.beta, 90)
            self.assertGreaterEqual(len(gen_normal.oriented_unit_cell),
                                    len(gen.oriented_unit_cell))

        graphite = self.get_structure("Graphite")
        for miller in [(1, 0, 0), (1, 1, 0), (0, 0, 1), (2, 1, 1)]:
            gen = SlabGenerator(graphite, miller, 10, 10)
            gen_normal = SlabGenerator(graphite, miller, 10, 10,
                                       max_normal_search=max(miller))
            self.assertGreaterEqual(len(gen_normal.oriented_unit_cell),
                                    len(gen.oriented_unit_cell))

        sc = Structure(Lattice.hexagonal(3.32, 5.15), ["Sc", "Sc"],
                       [[1/3, 2/3, 0.25], [2/3, 1/3, 0.75]])
        gen = SlabGenerator(sc, (1, 1, 1), 10, 10, max_normal_search=1)
        self.assertAlmostEqual(gen.oriented_unit_cell.lattice.angles[1], 90)
开发者ID:tallakahath,项目名称:pymatgen,代码行数:25,代码来源:test_surface.py


示例5: setUp

    def setUp(self):
        zno1 = Structure.from_file(get_path("ZnO-wz.cif"), primitive=False)
        zno55 = SlabGenerator(zno1, [1, 0, 0], 5, 5, lll_reduce=False,
                              center_slab=False).get_slab()

        Ti = Structure(Lattice.hexagonal(4.6, 2.82), ["Ti", "Ti", "Ti"],
                       [[0.000000, 0.000000, 0.000000],
                       [0.333333, 0.666667, 0.500000],
                       [0.666667, 0.333333, 0.500000]])

        Ag_fcc = Structure(Lattice.cubic(4.06), ["Ag", "Ag", "Ag", "Ag"],
                           [[0.000000, 0.000000, 0.000000],
                           [0.000000, 0.500000, 0.500000],
                           [0.500000, 0.000000, 0.500000],
                           [0.500000, 0.500000, 0.000000]])

        laue_groups = ["-1", "2/m", "mmm", "4/m",
                       "4/mmm", "-3", "-3m", "6/m",
                       "6/mmm", "m-3", "m-3m"]

        self.ti = Ti
        self.agfcc = Ag_fcc
        self.zno1 = zno1
        self.zno55 = zno55
        self.h = Structure(Lattice.cubic(3), ["H"],
                            [[0, 0, 0]])
        self.libcc = Structure(Lattice.cubic(3.51004), ["Li", "Li"],
                               [[0, 0, 0], [0.5, 0.5, 0.5]])
        self.laue_groups = laue_groups
开发者ID:tallakahath,项目名称:pymatgen,代码行数:29,代码来源:test_surface.py


示例6: test_from_magnetic_spacegroup

    def test_from_magnetic_spacegroup(self):

        # AFM MnF
        s1 = Structure.from_magnetic_spacegroup("P4_2'/mnm'", Lattice.tetragonal(4.87, 3.30),
                                                ["Mn", "F"],
                                                [[0, 0, 0],
                                                 [0.30, 0.30, 0.00]],
                                                {'magmom': [4, 0]})

        self.assertEqual(s1.formula, "Mn2 F4")
        self.assertEqual(sum(map(float, s1.site_properties['magmom'])), 0)
        self.assertEqual(max(map(float, s1.site_properties['magmom'])), 4)
        self.assertEqual(min(map(float, s1.site_properties['magmom'])), -4)

        # AFM LaMnO3, ordered on (001) planes
        s2 = Structure.from_magnetic_spacegroup("Pn'ma'", Lattice.orthorhombic(5.75, 7.66, 5.53),
                                                ["La", "Mn", "O", "O"],
                                                [[0.05, 0.25, 0.99],
                                                 [0.00, 0.00, 0.50],
                                                 [0.48, 0.25, 0.08],
                                                 [0.31, 0.04, 0.72]],
                                                {'magmom': [0, Magmom([4, 0, 0]), 0, 0]})

        self.assertEqual(s2.formula, "La4 Mn4 O12")
        self.assertEqual(sum(map(float, s2.site_properties['magmom'])), 0)
        self.assertEqual(max(map(float, s2.site_properties['magmom'])), 4)
        self.assertEqual(min(map(float, s2.site_properties['magmom'])), -4)
开发者ID:xhqu1981,项目名称:pymatgen,代码行数:27,代码来源:test_structure.py


示例7: test_get_xrd_data

    def test_get_xrd_data(self):
        a = 4.209
        latt = Lattice.cubic(a)
        structure = Structure(latt, ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]])
        c = XRDCalculator()
        data = c.get_xrd_data(structure, two_theta_range=(0, 90))
        #Check the first two peaks
        self.assertAlmostEqual(data[0][0], 21.107738329639844)
        self.assertAlmostEqual(data[0][1], 36.483184003748946)
        self.assertEqual(data[0][2], {(1, 0, 0): 6})
        self.assertAlmostEqual(data[0][3], 4.2089999999999996)
        self.assertAlmostEqual(data[1][0], 30.024695921112777)
        self.assertAlmostEqual(data[1][1], 100)
        self.assertEqual(data[1][2], {(1, 1, 0): 12})
        self.assertAlmostEqual(data[1][3], 2.976212442014178)

        s = read_structure(os.path.join(test_dir, "LiFePO4.cif"))
        data = c.get_xrd_data(s, two_theta_range=(0, 90))
        self.assertAlmostEqual(data[1][0], 17.03504233621785)
        self.assertAlmostEqual(data[1][1], 50.400928948337075)

        s = read_structure(os.path.join(test_dir, "Li10GeP2S12.cif"))
        data = c.get_xrd_data(s, two_theta_range=(0, 90))
        self.assertAlmostEqual(data[1][0], 14.058274883353876)
        self.assertAlmostEqual(data[1][1], 4.4111123641667671)

        # Test a hexagonal structure.
        s = read_structure(os.path.join(test_dir, "Graphite.cif"),
                           primitive=False)
        data = c.get_xrd_data(s, two_theta_range=(0, 90))
        self.assertAlmostEqual(data[0][0], 7.929279053132362)
        self.assertAlmostEqual(data[0][1], 100)
        self.assertAlmostEqual(len(list(data[0][2].keys())[0]), 4)

        #Add test case with different lengths of coefficients.
        #Also test d_hkl.
        coords = [[0.25, 0.25, 0.173], [0.75, 0.75, 0.827], [0.75, 0.25, 0],
                  [0.25, 0.75, 0], [0.25, 0.25, 0.676], [0.75, 0.75, 0.324]]
        sp = ["Si", "Si", "Ru", "Ru", "Pr", "Pr"]
        s = Structure(Lattice.tetragonal(4.192, 6.88), sp, coords)
        data = c.get_xrd_data(s)
        self.assertAlmostEqual(data[0][0], 12.86727341476735)
        self.assertAlmostEqual(data[0][1], 31.448239816769796)
        self.assertAlmostEqual(data[0][3], 6.88)
        self.assertEqual(len(data), 42)
        data = c.get_xrd_data(s, two_theta_range=[0, 60])
        self.assertEqual(len(data), 18)

        #Test with and without Debye-Waller factor
        tungsten = Structure(Lattice.cubic(3.1653), ["W"] * 2,
                             [[0, 0, 0], [0.5, 0.5, 0.5]])
        data = c.get_xrd_data(tungsten, scaled=False)
        self.assertAlmostEqual(data[0][0], 40.294828554672264)
        self.assertAlmostEqual(data[0][1], 2414237.5633093244)
        self.assertAlmostEqual(data[0][3], 2.2382050944897789)
        c = XRDCalculator(debye_waller_factors={"W": 0.1526})
        data = c.get_xrd_data(tungsten, scaled=False)
        self.assertAlmostEqual(data[0][0], 40.294828554672264)
        self.assertAlmostEqual(data[0][1], 2377745.2296686019)
        self.assertAlmostEqual(data[0][3], 2.2382050944897789)
开发者ID:NadezhdaBzhilyanskaya,项目名称:pymatgen,代码行数:60,代码来源:test_xrd.py


示例8: get_lattice_quanta

    def get_lattice_quanta(self, convert_to_muC_per_cm2=True, all_in_polar=True):
        """
        Returns the dipole / polarization quanta along a, b, and c for
        all structures.
        """
        lattices = [s.lattice for s in self.structures]
        volumes = np.array([s.lattice.volume for s in self.structures])

        L = len(self.structures)

        e_to_muC = -1.6021766e-13
        cm2_to_A2 = 1e16
        units = 1.0 / np.array(volumes)
        units *= e_to_muC * cm2_to_A2

        # convert polarizations and lattice lengths prior to adjustment
        if convert_to_muC_per_cm2 and not all_in_polar:
            # adjust lattices
            for i in range(L):
                lattice = lattices[i]
                l, a = lattice.lengths_and_angles
                lattices[i] = Lattice.from_lengths_and_angles(
                    np.array(l) * units.ravel()[i], a)
        elif convert_to_muC_per_cm2 and all_in_polar:
            for i in range(L):
                lattice = lattices[-1]
                l, a = lattice.lengths_and_angles
                lattices[i] = Lattice.from_lengths_and_angles(
                    np.array(l) * units.ravel()[-1], a)

        quanta = np.array(
            [np.array(l.lengths_and_angles[0]) for l in lattices])

        return quanta
开发者ID:ExpHP,项目名称:pymatgen,代码行数:34,代码来源:polarization.py


示例9: __init__

 def __init__(self, structure, scaling_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1))):
     """
     Create a supercell.
     
     Arguments:
         structure:
             pymatgen.core.structure Structure object.
         scaling_matrix:
             a matrix of transforming the lattice vectors. Defaults to the
             identity matrix. Has to be all integers. e.g.,
             [[2,1,0],[0,3,0],[0,0,1]] generates a new structure with
             lattice vectors a' = 2a + b, b' = 3b, c' = c where a, b, and c
             are the lattice vectors of the original structure. 
     """
     self._original_structure = structure
     old_lattice = structure.lattice
     scale_matrix = np.array(scaling_matrix)
     new_lattice = Lattice(np.dot(scale_matrix, old_lattice.matrix))
     new_species = []
     new_fcoords = []
     def range_vec(i):
         return range(max(scale_matrix[:][:, i]) - min(scale_matrix[:][:, i]))
     for site in structure.sites:
         for (i, j, k) in itertools.product(range_vec(0), range_vec(1), range_vec(2)):
             new_species.append(site.species_and_occu)
             fcoords = site.frac_coords
             coords = old_lattice.get_cartesian_coords(fcoords + np.array([i, j, k]))
             new_fcoords.append(new_lattice.get_fractional_coords(coords))
     self._modified_structure = Structure(new_lattice, new_species, new_fcoords, False)
开发者ID:chenweis,项目名称:pymatgen,代码行数:29,代码来源:structure_modifier.py


示例10: test_merge_sites

    def test_merge_sites(self):
        species = [{'Ag': 0.5}, {'Cl': 0.25}, {'Cl': 0.1},
                   {'Ag': 0.5}, {'F': 0.15}, {'F': 0.1}]
        coords = [[0, 0, 0], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5],
                  [0, 0, 0], [0.5, 0.5, 1.501], [0.5, 0.5, 1.501]]
        s = Structure(Lattice.cubic(1), species, coords)
        s.merge_sites(mode="s")
        self.assertEqual(s[0].specie.symbol, 'Ag')
        self.assertEqual(s[1].species_and_occu,
                         Composition({'Cl': 0.35, 'F': 0.25}))
        self.assertArrayAlmostEqual(s[1].frac_coords, [.5, .5, .5005])

        # Test for TaS2 with spacegroup 166 in 160 setting.
        l = Lattice.from_lengths_and_angles([3.374351, 3.374351, 20.308941],
                                            [90.000000, 90.000000, 120.000000])
        species = ["Ta", "S", "S"]
        coords = [[0.000000, 0.000000, 0.944333], [0.333333, 0.666667, 0.353424],
                  [0.666667, 0.333333, 0.535243]]
        tas2 = Structure.from_spacegroup(160, l, species, coords)
        assert len(tas2) == 13
        tas2.merge_sites(mode="d")
        assert len(tas2) == 9

        l = Lattice.from_lengths_and_angles([3.587776, 3.587776, 19.622793],
                                            [90.000000, 90.000000, 120.000000])
        species = ["Na", "V", "S", "S"]
        coords = [[0.333333, 0.666667, 0.165000], [0.000000, 0.000000, 0.998333],
                  [0.333333, 0.666667, 0.399394], [0.666667, 0.333333, 0.597273]]
        navs2 = Structure.from_spacegroup(160, l, species, coords)
        assert len(navs2) == 18
        navs2.merge_sites(mode="d")
        assert len(navs2) == 12
开发者ID:gpetretto,项目名称:pymatgen,代码行数:32,代码来源:test_structure.py


示例11: test_get_pattern

    def test_get_pattern(self):
        s = self.get_structure("CsCl")
        c = XRDCalculator()
        xrd = c.get_pattern(s, two_theta_range=(0, 90))
        self.assertTrue(xrd.to_json())  # Test MSONAble property
        # Check the first two peaks
        self.assertAlmostEqual(xrd.x[0], 21.107738329639844)
        self.assertAlmostEqual(xrd.y[0], 36.483184003748946)
        self.assertEqual(xrd.hkls[0], [{'hkl': (1, 0, 0), 'multiplicity': 6}])
        self.assertAlmostEqual(xrd.d_hkls[0], 4.2089999999999996)
        self.assertAlmostEqual(xrd.x[1], 30.024695921112777)
        self.assertAlmostEqual(xrd.y[1], 100)
        self.assertEqual(xrd.hkls[1], [{"hkl": (1, 1, 0), "multiplicity": 12}])
        self.assertAlmostEqual(xrd.d_hkls[1], 2.976212442014178)

        s = self.get_structure("LiFePO4")
        xrd = c.get_pattern(s, two_theta_range=(0, 90))
        self.assertAlmostEqual(xrd.x[1], 17.03504233621785)
        self.assertAlmostEqual(xrd.y[1], 50.400928948337075)

        s = self.get_structure("Li10GeP2S12")
        xrd = c.get_pattern(s, two_theta_range=(0, 90))
        self.assertAlmostEqual(xrd.x[1], 14.058274883353876)
        self.assertAlmostEqual(xrd.y[1], 4.4111123641667671)

        # Test a hexagonal structure.
        s = self.get_structure("Graphite")

        xrd = c.get_pattern(s, two_theta_range=(0, 90))
        self.assertAlmostEqual(xrd.x[0], 26.21057350859598)
        self.assertAlmostEqual(xrd.y[0], 100)
        self.assertAlmostEqual(len(xrd.hkls[0][0]["hkl"]), 4)

        # Add test case with different lengths of coefficients.
        # Also test d_hkl.
        coords = [[0.25, 0.25, 0.173], [0.75, 0.75, 0.827], [0.75, 0.25, 0],
                  [0.25, 0.75, 0], [0.25, 0.25, 0.676], [0.75, 0.75, 0.324]]
        sp = ["Si", "Si", "Ru", "Ru", "Pr", "Pr"]
        s = Structure(Lattice.tetragonal(4.192, 6.88), sp, coords)
        xrd = c.get_pattern(s)
        self.assertAlmostEqual(xrd.x[0], 12.86727341476735)
        self.assertAlmostEqual(xrd.y[0], 31.448239816769796)
        self.assertAlmostEqual(xrd.d_hkls[0], 6.88)
        self.assertEqual(len(xrd), 42)
        xrd = c.get_pattern(s, two_theta_range=[0, 60])
        self.assertEqual(len(xrd), 18)

        # Test with and without Debye-Waller factor
        tungsten = Structure(Lattice.cubic(3.1653), ["W"] * 2,
                             [[0, 0, 0], [0.5, 0.5, 0.5]])
        xrd = c.get_pattern(tungsten, scaled=False)
        self.assertAlmostEqual(xrd.x[0], 40.294828554672264)
        self.assertAlmostEqual(xrd.y[0], 2414237.5633093244)
        self.assertAlmostEqual(xrd.d_hkls[0], 2.2382050944897789)
        c = XRDCalculator(debye_waller_factors={"W": 0.1526})
        xrd = c.get_pattern(tungsten, scaled=False)
        self.assertAlmostEqual(xrd.x[0], 40.294828554672264)
        self.assertAlmostEqual(xrd.y[0], 2377745.2296686019)
        self.assertAlmostEqual(xrd.d_hkls[0], 2.2382050944897789)
        c.get_plot(tungsten).show()
开发者ID:ExpHP,项目名称:pymatgen,代码行数:60,代码来源:test_xrd.py


示例12: setUp

    def setUp(self):

        lattice = Lattice.cubic(3.010)
        frac_coords = [[0.00000, 0.00000, 0.00000],
                       [0.00000, 0.50000, 0.50000],
                       [0.50000, 0.00000, 0.50000],
                       [0.50000, 0.50000, 0.00000],
                       [0.50000, 0.00000, 0.00000],
                       [0.50000, 0.50000, 0.50000],
                       [0.00000, 0.00000, 0.50000],
                       [0.00000, 0.50000, 0.00000]]
        species = ['Mg', 'Mg', 'Mg', 'Mg', 'O', 'O', 'O', 'O']
        self.MgO = Structure(lattice, species, frac_coords)
        self.MgO.add_oxidation_state_by_element({"Mg": 2, "O": -6})

        lattice_Dy = Lattice.hexagonal(3.58, 25.61)
        frac_coords_Dy = [[0.00000, 0.00000, 0.00000],
                          [0.66667, 0.33333, 0.11133],
                          [0.00000, 0.00000, 0.222],
                          [0.66667, 0.33333, 0.33333],
                          [0.33333, 0.66666, 0.44467],
                          [0.66667, 0.33333, 0.55533],
                          [0.33333, 0.66667, 0.66667],
                          [0.00000, 0.00000, 0.778],
                          [0.33333, 0.66667, 0.88867]]
        species_Dy = ['Dy', 'Dy', 'Dy', 'Dy', 'Dy', 'Dy', 'Dy', 'Dy', 'Dy']
        self.Dy = Structure(lattice_Dy, species_Dy, frac_coords_Dy)
开发者ID:gmatteo,项目名称:pymatgen,代码行数:27,代码来源:test_surface.py


示例13: 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 = Structure(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 = Structure(Lattice.cubic(4.09), ["Li"] * 2, coords)
     self.assertEqual(len(bcc_li.get_primitive_structure()), 1)
开发者ID:thuwangming,项目名称:pymatgen,代码行数:7,代码来源:test_structure.py


示例14: TestLattice

class TestLattice(unittest.TestCase):
    def setUp(self):
        # fixture 
        matrix = [ 100,0,0,0,100,0,0,0,100 ]
        self.lat = Lattice(matrix)
        
        self.assertEqual(self.lat._lengths[0],100.0)
        self.assertEqual(self.lat._lengths[1],100.0)
        self.assertEqual(self.lat._lengths[2],100.0)

        self.assertEqual(self.lat._angles[0],90.0)
        self.assertEqual(self.lat._angles[1],90.0)
        self.assertEqual(self.lat._angles[2],90.0)
        
    def test_changematrix(self):
        matrix = [ 132,0,0,0,127,0,0,0,150 ]
        self.lat.set_matrix(matrix)
        self.assertEqual(self.lat._lengths[0],132.0)
        self.assertEqual(self.lat._lengths[1],127.0)
        self.assertEqual(self.lat._lengths[2],150.0)

        self.assertEqual(self.lat._angles[0],90.0)
        self.assertEqual(self.lat._angles[1],90.0)
        self.assertEqual(self.lat._angles[2],90.0)
        

    def tearDown(self):
        del self.lat 
        self.lat = None
开发者ID:traviskemper,项目名称:pymatgen,代码行数:29,代码来源:test_lattice.py


示例15: test_get_slab

    def test_get_slab(self):
        s = self.get_structure("LiFePO4")
        gen = SlabGenerator(s, [0, 0, 1], 10, 10)
        s = gen.get_slab(0.25)
        self.assertAlmostEqual(s.lattice.abc[2], 20.820740000000001)

        fcc = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3), ["Fe"],
                                        [[0, 0, 0]])
        gen = SlabGenerator(fcc, [1, 1, 1], 10, 10)
        slab = gen.get_slab()
        gen = SlabGenerator(fcc, [1, 1, 1], 10, 10, primitive=False)
        slab_non_prim = gen.get_slab()
        self.assertEqual(len(slab), 6)
        self.assertEqual(len(slab_non_prim), len(slab) * 4)

        #Some randomized testing of cell vectors
        for i in range(1, 231):
            i = random.randint(1, 230)
            sg = SpaceGroup.from_int_number(i)
            if sg.crystal_system == "hexagonal" or (sg.crystal_system == \
                    "trigonal" and sg.symbol.endswith("H")):
                latt = Lattice.hexagonal(5, 10)
            else:
                #Cubic lattice is compatible with all other space groups.
                latt = Lattice.cubic(5)
            s = Structure.from_spacegroup(i, latt, ["H"], [[0, 0, 0]])
            miller = (0, 0, 0)
            while miller == (0, 0, 0):
                miller = (random.randint(0, 6), random.randint(0, 6),
                          random.randint(0, 6))
            gen = SlabGenerator(s, miller, 10, 10)
            a, b, c = gen.oriented_unit_cell.lattice.matrix
            self.assertAlmostEqual(np.dot(a, gen._normal), 0)
            self.assertAlmostEqual(np.dot(b, gen._normal), 0)
开发者ID:tallakahath,项目名称:pymatgen,代码行数:34,代码来源:test_surface.py


示例16: test_distance_and_image

 def test_distance_and_image(self):
     other_site = PeriodicSite("Fe", np.array([1, 1, 1]), self.lattice)
     (distance, image) = self.site.distance_and_image(other_site)
     self.assertAlmostEqual(distance, 6.22494979899, 5)
     self.assertTrue(([-1, -1, -1] == image).all())
     (distance, image) = self.site.distance_and_image(other_site, [1, 0, 0])
     self.assertAlmostEqual(distance, 19.461500456028563, 5)
     # Test that old and new distance algo give the same ans for
     # "standard lattices"
     lattice = Lattice(np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]))
     site1 = PeriodicSite("Fe", np.array([0.01, 0.02, 0.03]), lattice)
     site2 = PeriodicSite("Fe", np.array([0.99, 0.98, 0.97]), lattice)
     self.assertAlmostEqual(get_distance_and_image_old(site1, site2)[0],
                            site1.distance_and_image(site2)[0])
     lattice = Lattice.from_parameters(1, 0.01, 1, 10, 10, 10)
     site1 = PeriodicSite("Fe", np.array([0.01, 0.02, 0.03]), lattice)
     site2 = PeriodicSite("Fe", np.array([0.99, 0.98, 0.97]), lattice)
     self.assertTrue(get_distance_and_image_old(site1, site2)[0] >
                     site1.distance_and_image(site2)[0])
     site2 = PeriodicSite("Fe", np.random.rand(3), lattice)
     (dist_old, jimage_old) = get_distance_and_image_old(site1, site2)
     (dist_new, jimage_new) = site1.distance_and_image(site2)
     self.assertTrue(dist_old - dist_new > -1e-8,
                     "New distance algo should give smaller answers!")
     self.assertFalse((abs(dist_old - dist_new) < 1e-8) ^
                      (jimage_old == jimage_new).all(),
                      "If old dist == new dist, images must be the same!")
     latt = Lattice.from_parameters(3.0, 3.1, 10.0, 2.96, 2.0, 1.0)
     site = PeriodicSite("Fe", [0.1, 0.1, 0.1], latt)
     site2 = PeriodicSite("Fe", [0.99, 0.99, 0.99], latt)
     (dist, img) = site.distance_and_image(site2)
     self.assertAlmostEqual(dist, 0.15495358379511573)
     self.assertEqual(list(img), [-11, 6, 0])
开发者ID:albalu,项目名称:pymatgen,代码行数:33,代码来源:test_sites.py


示例17: setUp

    def setUp(self):

        l = Lattice.cubic(3.51)
        species = ["Ni"]
        coords = [[0,0,0]]
        self.Ni = Structure.from_spacegroup("Fm-3m", l, species, coords)
        self.Si = Structure.from_spacegroup("Fd-3m", Lattice.cubic(5.430500),
                                            ["Si"], [(0, 0, 0.5)])
开发者ID:navnidhirajput,项目名称:pymatgen,代码行数:8,代码来源:test_surface.py


示例18: test_mapping_symmetry

 def test_mapping_symmetry(self):
     l = Lattice.cubic(1)
     l2 = Lattice.orthorhombic(1.1001, 1, 1)
     self.assertEqual(l.find_mapping(l2, ltol=0.1), None)
     self.assertEqual(l2.find_mapping(l, ltol=0.1), None)
     l2 = Lattice.orthorhombic(1.0999, 1, 1)
     self.assertNotEqual(l2.find_mapping(l, ltol=0.1), None)
     self.assertNotEqual(l.find_mapping(l2, ltol=0.1), None)
开发者ID:zulissi,项目名称:pymatgen,代码行数:8,代码来源:test_lattice.py


示例19: setUp

    def setUp(self):
        zno1 = Structure.from_file(get_path("ZnO-wz.cif"), primitive=False)
        zno55 = SlabGenerator(zno1, [1, 0, 0], 5, 5, lll_reduce=False,
                              center_slab=False).get_slab()

        self.zno1 = zno1
        self.zno55 = zno55
        self.h = Structure(Lattice.cubic(3), ["H"],
                            [[0, 0, 0]])
        self.libcc = Structure(Lattice.cubic(3.51004), ["Li", "Li"],
                               [[0, 0, 0], [0.5, 0.5, 0.5]])
开发者ID:anhhv,项目名称:pymatgen,代码行数:11,代码来源:test_surface.py


示例20: test_get_points_in_sphere

    def test_get_points_in_sphere(self):
        # This is a non-niggli representation of a cubic lattice
        latt = Lattice([[1,5,0],[0,1,0],[5,0,1]])
        # evenly spaced points array between 0 and 1
        pts = np.array(list(itertools.product(range(5), repeat=3))) / 5
        pts = latt.get_fractional_coords(pts)

        self.assertEqual(len(latt.get_points_in_sphere(
            pts, [0, 0, 0], 0.20001)), 7)
        self.assertEqual(len(latt.get_points_in_sphere(
            pts, [0.5, 0.5, 0.5], 1.0001)), 552)
开发者ID:zulissi,项目名称:pymatgen,代码行数:11,代码来源:test_lattice.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python operations.SymmOp类代码示例发布时间:2022-05-25
下一篇:
Python ion.Ion类代码示例发布时间: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