コード例 #1
0
ファイル: test_kpaths.py プロジェクト: matk86/pymatgen
 def test_kpath_generation(self):
     triclinic = [1, 2]
     monoclinic = range(3, 16)
     orthorhombic = range(16, 75)
     tetragonal = range(75, 143)
     rhombohedral = range(143, 168)
     hexagonal = range(168, 195)
     cubic = range(195, 231)
     
     species = ['K', 'La', 'Ti']
     coords = [[.345, 5, .77298], [.1345, 5.1, .77298], [.7, .8, .9]]
     for i in range(230):
         sg_num = i + 1
         if sg_num in triclinic:
             lattice = Lattice([[3.0233057319441246,0,0], [0,7.9850357844548681,0], [0,0,8.1136762279561818]])
         elif sg_num in monoclinic:
             lattice = Lattice.monoclinic(2, 9, 1, 99)
         elif sg_num in orthorhombic:
             lattice = Lattice.orthorhombic(2, 9, 1)
         elif sg_num in tetragonal:
             lattice = Lattice.tetragonal(2, 9)
         elif sg_num in rhombohedral:
             lattice = Lattice.hexagonal(2, 95)
         elif sg_num in hexagonal:
             lattice = Lattice.hexagonal(2, 9)
         elif sg_num in cubic:
             lattice = Lattice.cubic(2)
     
         struct = Structure.from_spacegroup(sg_num, lattice, species, coords)
         kpath = HighSymmKpath(struct) #Throws error if something doesn't work, causing test to fail.
コード例 #2
0
ファイル: test_data.py プロジェクト: zooks97/pymatgen
    def test_structure(self):
        quartz = self.quartz.structure
        np.testing.assert_array_almost_equal(
            quartz.lattice.matrix,
            [[4.913400, 0, 0], [-2.456700, 4.255129, 0], [0, 0, 5.405200]],
        )
        self.assertEqual(quartz.formula, "Si3 O6")
        self.assertNotIn("molecule-ID", self.quartz.atoms.columns)

        ethane = self.ethane.structure
        np.testing.assert_array_almost_equal(ethane.lattice.matrix, np.diag([10.0] * 3))
        lbounds = np.array(self.ethane.box.bounds)[:, 0]
        coords = self.ethane.atoms[["x", "y", "z"]].values - lbounds
        np.testing.assert_array_almost_equal(ethane.cart_coords, coords)
        np.testing.assert_array_almost_equal(ethane.site_properties["charge"], self.ethane.atoms["q"])
        tatb = self.tatb.structure
        frac_coords = tatb.frac_coords[381]
        real_frac_coords = frac_coords - np.floor(frac_coords)
        np.testing.assert_array_almost_equal(real_frac_coords, [0.01553397, 0.71487872, 0.14134139])

        co = Structure.from_spacegroup(194, Lattice.hexagonal(2.50078, 4.03333), ["Co"], [[1 / 3, 2 / 3, 1 / 4]])
        ld_co = LammpsData.from_structure(co)
        self.assertEqual(ld_co.structure.composition.reduced_formula, "Co")
        ni = Structure.from_spacegroup(225, Lattice.cubic(3.50804), ["Ni"], [[0, 0, 0]])
        ld_ni = LammpsData.from_structure(ni)
        self.assertEqual(ld_ni.structure.composition.reduced_formula, "Ni")
コード例 #3
0
ファイル: test_surface.py プロジェクト: tallakahath/pymatgen
    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
コード例 #4
0
ファイル: test_tensor.py プロジェクト: gmrigna/abipy
    def test_tensor(self):
        """Initialize Tensor"""

        lattice = Lattice.hexagonal(4, 6)
        #rprimd = np.array([[0,0.5,0.5],[0.5,0,0.5],[0.5,0.5,0]])
        #rprimd = rprimd*10
        #lattice = Lattice(rprimd)
        structure = Structure(lattice, ["Ga", "As"],
                              [[0, 0, 0], [0.5, 0.5, 0.5]])

        #finder = SymmetryFinder(structure)
        finder = SpacegroupAnalyzer(structure)

        spacegroup = finder.get_spacegroup()
        pointgroup = finder.get_point_group()

        cartesian_tensor = [[2, 3, 1.2], [3, 4, 1.0], [1.2, 1.0, 6]]

        tensor = Tensor.from_cartesian_tensor(cartesian_tensor,
                                              lattice.reciprocal_lattice,
                                              space="g")
        red_tensor = tensor.reduced_tensor
        tensor2 = Tensor(red_tensor, lattice.reciprocal_lattice, space="g")
        assert (((np.abs(tensor2.cartesian_tensor) - np.abs(cartesian_tensor))
                 < 1E-8).all())

        self.assertTrue(tensor == tensor2)
        print(tensor)

        #print("non-symmetrized cartesian_tensor = ",tensor2.cartesian_tensor)
        tensor2.symmetrize(structure)

        #print("symmetrized_cartesian_tensor = ",tensor2.cartesian_tensor)

        self.serialize_with_pickle(tensor)
コード例 #5
0
ファイル: test_surface.py プロジェクト: tallakahath/pymatgen
    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)
コード例 #6
0
ファイル: test_surface.py プロジェクト: gmatteo/pymatgen
    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)
コード例 #7
0
    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)
コード例 #8
0
ファイル: test_tensor.py プロジェクト: akakcolin/abipy
    def test_tensor(self):
        """Initialize Tensor"""

        lattice = Lattice.hexagonal(4,6)
        #rprimd = np.array([[0,0.5,0.5],[0.5,0,0.5],[0.5,0.5,0]])
        #rprimd = rprimd*10
        #lattice = Lattice(rprimd)
        structure = Structure(lattice, ["Ga", "As"],
                                      [[0, 0, 0], [0.5, 0.5, 0.5]])

        #finder = SymmetryFinder(structure)
        finder = SpacegroupAnalyzer(structure)

        spacegroup = finder.get_spacegroup()
        pointgroup = finder.get_point_group()

        cartesian_tensor = [[2,3,1.2],[3,4,1.0],[1.2,1.0,6]]

        tensor = Tensor.from_cartesian_tensor(cartesian_tensor,lattice.reciprocal_lattice,space="g")
        red_tensor = tensor.reduced_tensor
        tensor2 = Tensor(red_tensor,lattice.reciprocal_lattice,space="g")
        assert(((np.abs(tensor2.cartesian_tensor)-np.abs(cartesian_tensor)) < 1E-8).all())

        self.assertTrue(tensor==tensor2)
        print(tensor)

        #print("non-symmetrized cartesian_tensor = ",tensor2.cartesian_tensor)
        tensor2.symmetrize(structure)

        #print("symmetrized_cartesian_tensor = ",tensor2.cartesian_tensor)

        self.serialize_with_pickle(tensor)
コード例 #9
0
ファイル: test_surface.py プロジェクト: tallakahath/pymatgen
    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)
コード例 #10
0
ファイル: test_groups.py プロジェクト: orex/pymatgen
 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))
コード例 #11
0
    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)
コード例 #12
0
    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)
コード例 #13
0
    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]])

        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]])
コード例 #14
0
ファイル: test_groups.py プロジェクト: paulfons/pymatgen
 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))
コード例 #15
0
ファイル: test_wulff.py プロジェクト: ExpHP/pymatgen
    def setUp(self):

        module_dir = os.path.dirname(os.path.abspath(__file__))
        with open(
                os.path.join(module_dir, "surface_samples.json")) as data_file:
            surface_properties = json.load(data_file)

        surface_energies, miller_indices = {}, {}
        for mpid in surface_properties.keys():
            e_surf_list, miller_list = [], []
            for surface in surface_properties[mpid]["surfaces"]:
                e_surf_list.append(surface["surface_energy"])
                miller_list.append(surface["miller_index"])
            surface_energies[mpid] = e_surf_list
            miller_indices[mpid] = miller_list

        # In the case of a high anisotropy material
        # Nb: mp-8636
        latt_Nb = Lattice.cubic(2.992)
        # In the case of an fcc material
        # Ir: mp-101
        latt_Ir = Lattice.cubic(3.8312)
        # In the case of a hcp material
        # Ti: mp-72
        latt_Ti = Lattice.hexagonal(4.6000, 2.8200)
        self.ucell_Nb = Structure(latt_Nb, ["Nb", "Nb", "Nb", "Nb"],
                                  [[0, 0, 0], [0, 0.5, 0.5],
                                   [0.5, 0, 0.5], [0.5, 0.5, 0]])
        self.wulff_Nb = WulffShape(latt_Nb, miller_indices["mp-8636"],
                                   surface_energies["mp-8636"])

        self.ucell_Ir = Structure(latt_Nb, ["Ir", "Ir", "Ir", "Ir"],
                                  [[0, 0, 0], [0, 0.5, 0.5],
                                   [0.5, 0, 0.5], [0.5, 0.5, 0]])
        self.wulff_Ir = WulffShape(latt_Ir, miller_indices["mp-101"],
                                   surface_energies["mp-101"])

        self.ucell_Ti = Structure(latt_Ti, ["Ti", "Ti", "Ti"],
                                  [[0, 0, 0], [0.333333, 0.666667, 0.5],
                                   [0.666667, 0.333333, 0.5]])
        self.wulff_Ti = WulffShape(latt_Ti, miller_indices["mp-72"],
                                   surface_energies["mp-72"])
        self.cube = WulffShape(Lattice.cubic(1), [(1,0,0)], [1])
        self.hex_prism =  WulffShape(Lattice.hexagonal(2.63, 5.21),
                                     [(0,0,1), (1,0,0)], [0.35, 0.53])

        self.surface_properties = surface_properties
コード例 #16
0
ファイル: test_kpath_sc.py プロジェクト: mhsiron/pymatgen
    def test_kpath_generation(self):
        triclinic = [1, 2]
        monoclinic = range(3, 16)
        orthorhombic = range(16, 75)
        tetragonal = range(75, 143)
        rhombohedral = range(143, 168)
        hexagonal = range(168, 195)
        cubic = range(195, 231)

        species = ["K", "La", "Ti"]
        coords = [[0.345, 5, 0.77298], [0.1345, 5.1, 0.77298], [0.7, 0.8, 0.9]]
        for i in range(230):
            sg_num = i + 1
            if sg_num in triclinic:
                lattice = Lattice(
                    [
                        [3.0233057319441246, 0, 0],
                        [0, 7.9850357844548681, 0],
                        [0, 0, 8.1136762279561818],
                    ]
                )
            elif sg_num in monoclinic:
                lattice = Lattice.monoclinic(2, 9, 1, 99)
            elif sg_num in orthorhombic:
                lattice = Lattice.orthorhombic(2, 9, 1)
            elif sg_num in tetragonal:
                lattice = Lattice.tetragonal(2, 9)
            elif sg_num in rhombohedral:
                lattice = Lattice.hexagonal(2, 95)
            elif sg_num in hexagonal:
                lattice = Lattice.hexagonal(2, 9)
            elif sg_num in cubic:
                lattice = Lattice.cubic(2)

            struct = Structure.from_spacegroup(sg_num, lattice, species, coords)
            kpath = KPathSetyawanCurtarolo(
                struct
            )  # Throws error if something doesn't work, causing test to fail.

        struct_file_path = os.path.join(test_dir_structs, "ICSD_170.cif")
        struct = Structure.from_file(struct_file_path)
        hkp = KPathSetyawanCurtarolo(struct)
        self.assertEqual(hkp.name, "MCLC5")
コード例 #17
0
ファイル: test_kpaths.py プロジェクト: kjappelbaum/pymatgen
    def test_kpath_generation(self):
        triclinic = [1, 2]
        monoclinic = range(3, 16)
        orthorhombic = range(16, 75)
        tetragonal = range(75, 143)
        rhombohedral = range(143, 168)
        hexagonal = range(168, 195)
        cubic = range(195, 231)

        species = ["K", "La", "Ti"]
        coords = [[0.345, 5, 0.77298], [0.1345, 5.1, 0.77298], [0.7, 0.8, 0.9]]
        for i in range(230):
            sg_num = i + 1
            if sg_num in triclinic:
                lattice = Lattice(
                    [
                        [3.0233057319441246, 1, 0],
                        [0, 7.9850357844548681, 1],
                        [0, 1.2, 8.1136762279561818],
                    ]
                )
            elif sg_num in monoclinic:
                lattice = Lattice.monoclinic(2, 9, 1, 99)
            elif sg_num in orthorhombic:
                lattice = Lattice.orthorhombic(2, 9, 1)
            elif sg_num in tetragonal:
                lattice = Lattice.tetragonal(2, 9)
            elif sg_num in rhombohedral:
                lattice = Lattice.hexagonal(2, 95)
            elif sg_num in hexagonal:
                lattice = Lattice.hexagonal(2, 9)
            elif sg_num in cubic:
                lattice = Lattice.cubic(2)

            struct = Structure.from_spacegroup(sg_num, lattice, species, coords)

            # Throws error if something doesn't work, causing test to fail.
            kpath = HighSymmKpath(struct, path_type="all")
            kpoints = kpath.get_kpoints()
コード例 #18
0
 def test_get_weighted_average_position(self):
     latt = Lattice.hexagonal(10, 20)
     g_guess = latt.get_weighted_average_position(
         positions=[
             [0.6, 0.7, 0.5],
             [0.9, 0.8, 0.5],
             [0.1, 0.2, 0.5],
             [0.1, 0.95, 0.5],
         ],
         weights=[1, 1, 1, 1],
     )
     ref = np.sum([[0.6, 0.7, 0.5], [0.9, 0.8, 0.5], [1.1, 1.2, 0.5], [1.1, 0.95, 0.5]], axis=0) / 4
     np.testing.assert_array_almost_equal(g_guess, ref)
コード例 #19
0
ファイル: test_lattice.py プロジェクト: Tinaatucsd/pymatgen
    def setUp(self):
        self.lattice = Lattice.cubic(10.0)
        self.cubic = self.lattice
        self.tetragonal = Lattice.tetragonal(10, 20)
        self.orthorhombic = Lattice.orthorhombic(10, 20, 30)
        self.monoclinic = Lattice.monoclinic(10, 20, 30, 66)
        self.hexagonal = Lattice.hexagonal(10, 20)
        self.rhombohedral = Lattice.rhombohedral(10, 77)

        family_names = ["cubic", "tetragonal", "orthorhombic", "monoclinic",
                        "hexagonal", "rhombohedral"]

        self.families = {}
        for name in family_names:
            self.families[name] = getattr(self, name)
コード例 #20
0
ファイル: test_lattice.py プロジェクト: akashneo/pymatgen
    def setUp(self):
        self.lattice = Lattice.cubic(10.0)
        self.cubic = self.lattice
        self.tetragonal = Lattice.tetragonal(10, 20)
        self.orthorhombic = Lattice.orthorhombic(10, 20, 30)
        self.monoclinic = Lattice.monoclinic(10, 20, 30, 66)
        self.hexagonal = Lattice.hexagonal(10, 20)
        self.rhombohedral = Lattice.rhombohedral(10, 77)

        family_names = ["cubic", "tetragonal", "orthorhombic", "monoclinic",
                        "hexagonal", "rhombohedral"]

        self.families = {}
        for name in family_names:
            self.families[name] = getattr(self, name)
コード例 #21
0
ファイル: test_tem.py プロジェクト: CompRhys/pymatgen
 def test_interplanar_angle(self):
     # test interplanar angles. Reference values from KW Andrews,
     # Interpretation of Electron Diffraction pp70-90.
     c = TEMCalculator()
     latt = Lattice.cubic(4.209)
     cubic = Structure(latt, ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]])
     phi = c.get_interplanar_angle(cubic, (0, 0, -1), (0, -1, 0))
     self.assertAlmostEqual(90, phi, places=1)
     tet = self.get_structure("Li10GeP2S12")
     phi = c.get_interplanar_angle(tet, (0, 0, 1), (1, 0, 3))
     self.assertAlmostEqual(25.796, phi, places=1)
     latt = Lattice.hexagonal(2, 4)
     hex = Structure(latt, ["Ab"], [[0, 0, 0]])
     phi = c.get_interplanar_angle(hex, (0, 0, 1), (1, 0, 6))
     self.assertAlmostEqual(21.052, phi, places=1)
コード例 #22
0
 def test_selling_dist(self):
     # verification process described here: https://github.com/materialsproject/pymatgen/pull/1888#issuecomment-818072164
     np.testing.assert_(Lattice.selling_dist(Lattice.cubic(5), Lattice.cubic(5)) == 0)
     hex_lattice = Lattice.hexagonal(5, 8)
     triclinic_lattice = Lattice.from_parameters(4, 10, 11, 100, 110, 80)
     np.testing.assert_allclose(Lattice.selling_dist(hex_lattice, triclinic_lattice), 76, rtol=0.1)
     np.testing.assert_allclose(
         Lattice.selling_dist(Lattice.tetragonal(10, 12), Lattice.tetragonal(10.1, 11.9)),
         3.7,
         rtol=0.1,
     )
     np.testing.assert_allclose(
         Lattice.selling_dist(Lattice.cubic(5), Lattice.from_parameters(8, 10, 12, 80, 90, 95)),
         115.6,
         rtol=0.1,
     )
コード例 #23
0
ファイル: test_wulff.py プロジェクト: zetayue/pymatgen
    def setUp(self):

        module_dir = os.path.dirname(os.path.abspath(__file__))
        with open(
                os.path.join(module_dir, "surface_samples.json")) as data_file:
            surface_properties = json.load(data_file)

        surface_energies, miller_indices = {}, {}
        for mpid in surface_properties.keys():
            e_surf_list, miller_list = [], []
            for surface in surface_properties[mpid]["surfaces"]:
                e_surf_list.append(surface["surface_energy"])
                miller_list.append(surface["miller_index"])
            surface_energies[mpid] = e_surf_list
            miller_indices[mpid] = miller_list

        # In the case of a high anisotropy material
        # Nb: mp-8636
        latt_Nb = Lattice.cubic(2.992)
        # In the case of an fcc material
        # Ir: mp-101
        latt_Ir = Lattice.cubic(3.8312)
        # In the case of a hcp material
        # Ti: mp-72
        latt_Ti = Lattice.hexagonal(4.6000, 2.8200)
        self.ucell_Nb = Structure(latt_Nb, ["Nb", "Nb", "Nb", "Nb"],
                                  [[0, 0, 0], [0, 0.5, 0.5],
                                   [0.5, 0, 0.5], [0.5, 0.5, 0]])
        self.wulff_Nb = WulffShape(latt_Nb, miller_indices["mp-8636"],
                                   surface_energies["mp-8636"])

        self.ucell_Ir = Structure(latt_Nb, ["Ir", "Ir", "Ir", "Ir"],
                                  [[0, 0, 0], [0, 0.5, 0.5],
                                   [0.5, 0, 0.5], [0.5, 0.5, 0]])
        self.wulff_Ir = WulffShape(latt_Ir, miller_indices["mp-101"],
                                   surface_energies["mp-101"])

        self.ucell_Ti = Structure(latt_Ti, ["Ti", "Ti", "Ti"],
                                  [[0, 0, 0], [0.333333, 0.666667, 0.5],
                                   [0.666667, 0.333333, 0.5]])
        self.wulff_Ti = WulffShape(latt_Ti, miller_indices["mp-72"],
                                   surface_energies["mp-72"])

        self.surface_properties = surface_properties
コード例 #24
0
ファイル: test_surface.py プロジェクト: mturiansky/pymatgen
    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],
            ],
        )

        m = [[3.913449, 0, 0], [0, 3.913449, 0], [0, 0, 5.842644]]
        latt = Lattice(m)
        fcoords = [[0.5, 0, 0.222518], [0, 0.5, 0.777482], [0, 0, 0],
                   [0, 0, 0.5], [0.5, 0.5, 0]]
        non_laue = Structure(latt, ["Nb", "Nb", "N", "N", "N"], fcoords)

        self.ti = Ti
        self.agfcc = Ag_fcc
        self.zno1 = zno1
        self.zno55 = zno55
        self.nonlaue = non_laue
        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]])
コード例 #25
0
def generate_Ti_hex(lattice_param_a: float, lattice_param_c: float):
  return Structure(Lattice.hexagonal(lattice_param_a, lattice_param_c), 
                    ["Ti", "Ti", "Ti"], [[0.0, 0.0, 0.0],
                                         [0.66, 0.33, 0.5],
                                         [0.33, 0.66, 0.5]])
コード例 #26
0
    def test_serialization(self):
        lat = Lattice.hexagonal(a=2.0, c=2.5)
        en1 = EnvironmentNode(
            central_site=PeriodicSite("Si",
                                      coords=np.array([0.0, 0.0, 0.0]),
                                      lattice=lat),
            i_central_site=3,
            ce_symbol="T:4",
        )
        en2 = EnvironmentNode(
            central_site=PeriodicSite("Ag",
                                      coords=np.array([0.0, 0.0, 0.5]),
                                      lattice=lat),
            i_central_site=5,
            ce_symbol="T:4",
        )
        en3 = EnvironmentNode(
            central_site=PeriodicSite("Ag",
                                      coords=np.array([0.0, 0.5, 0.5]),
                                      lattice=lat),
            i_central_site=8,
            ce_symbol="O:6",
        )

        graph = nx.MultiGraph()
        graph.add_nodes_from([en1, en2, en3])

        graph.add_edge(
            en1,
            en2,
            start=en1.isite,
            end=en2.isite,
            delta=(0, 0, 0),
            ligands=[(2, (0, 0, 1), (0, 0, 1)), (1, (0, 0, 1), (0, 0, 1))],
        )
        graph.add_edge(
            en1,
            en3,
            start=en1.isite,
            end=en2.isite,
            delta=(0, 0, 0),
            ligands=[(10, (0, 0, 1), (0, 0, 1)), (11, (0, 0, 1), (0, 0, 1))],
        )

        cc = ConnectedComponent(graph=graph)
        ref_sorted_edges = [[en1, en2], [en1, en3]]
        sorted_edges = sorted([sorted(e) for e in cc.graph.edges()])
        assert sorted_edges == ref_sorted_edges

        ccfromdict = ConnectedComponent.from_dict(cc.as_dict())
        ccfromjson = ConnectedComponent.from_dict(
            json.loads(json.dumps(cc.as_dict())))
        loaded_cc_list = [ccfromdict, ccfromjson]
        if bson is not None:
            bson_data = bson.BSON.encode(cc.as_dict())
            ccfrombson = ConnectedComponent.from_dict(bson_data.decode())
            loaded_cc_list.append(ccfrombson)
        for loaded_cc in loaded_cc_list:
            assert loaded_cc.graph.number_of_nodes() == 3
            assert loaded_cc.graph.number_of_edges() == 2
            assert set(list(cc.graph.nodes())) == set(
                list(loaded_cc.graph.nodes()))
            assert sorted_edges == sorted(
                [sorted(e) for e in loaded_cc.graph.edges()])

            for ii, e in enumerate(sorted_edges):
                assert cc.graph[e[0]][e[1]] == loaded_cc.graph[e[0]][e[1]]

            for node in loaded_cc.graph.nodes():
                assert isinstance(node.central_site, PeriodicSite)
コード例 #27
0
ファイル: A2Cr3As3.py プロジェクト: ldamewood/dftscripts
import numpy

from pymatgen.core.periodic_table import Element
from pymatgen.core.lattice import Lattice
from pymatgen.symmetry.groups import SpaceGroup

from dftscripts.structure.wyckoff import wyckoff

a = 9.98329
b = 4.23044
lattice = Lattice.hexagonal(1.,1.*b/a)

positions = [
  wyckoff(187,'1c'),                            # Li (K2)
  wyckoff(187,'3k',x = 0.5387, coordinate = 0), # Li (K1)
  wyckoff(187,'3k',x = 0.5387, coordinate = 1), # Li (K1)
  wyckoff(187,'3k',x = 0.5387, coordinate = 2), # Li (K1)
  wyckoff(187,'3j',x = 0.0898, coordinate = 0), # Cr2
  wyckoff(187,'3j',x = 0.0898, coordinate = 1), # Cr2
  wyckoff(187,'3j',x = 0.0898, coordinate = 2), # Cr2
  wyckoff(187,'3k',x = 0.9127, coordinate = 0), # Cr1
  wyckoff(187,'3k',x = 0.9127, coordinate = 1), # Cr1
  wyckoff(187,'3k',x = 0.9127, coordinate = 2), # Cr1
  wyckoff(187,'3k',x = 0.1675, coordinate = 0), # As2
  wyckoff(187,'3k',x = 0.1675, coordinate = 1), # As2
  wyckoff(187,'3k',x = 0.1675, coordinate = 2), # As2
  wyckoff(187,'3j',x = 0.8339, coordinate = 0), # As1
  wyckoff(187,'3j',x = 0.8339, coordinate = 1), # As1
  wyckoff(187,'3j',x = 0.8339, coordinate = 2), # As1
]
コード例 #28
0
from pymatgen.core.structure import Structure
from pymatgen.core.lattice import Lattice
from crystal_toolkit.helpers.asymptote import write_asy_file
from crystal_toolkit.components.structure import StructureMoleculeComponent
import os

example_struct = Structure.from_spacegroup(
    "P6_3mc",
    Lattice.hexagonal(3.22, 5.24),
    ["Ga", "N"],
    [[1 / 3, 2 / 3, 0], [1 / 3, 2 / 3, 3 / 8]],
)

smc = StructureMoleculeComponent(example_struct, hide_incomplete_bonds=True)
file_name = "./asy_test/single/GaN.asy"
write_asy_file(smc, file_name)
write_asy_file(smc, "./asy_test/multi/GaN.asy")

example_struct = Structure.from_spacegroup(
    "P6_3mc",
    Lattice.hexagonal(3.22, 5.24),
    ["In", "N"],
    [[1 / 3, 2 / 3, 0], [1 / 3, 2 / 3, 3 / 8]],
)
smc = StructureMoleculeComponent(example_struct, hide_incomplete_bonds=True)
write_asy_file(smc, "./asy_test/multi/InN.asy")
example_struct = Structure.from_spacegroup(
    "P6_3mc",
    Lattice.hexagonal(3.22, 5.24),
    ["Al", "N"],
    [[1 / 3, 2 / 3, 0], [1 / 3, 2 / 3, 3 / 8]],