Esempio n. 1
0
def prepare(conc, size, temp):
    path = "."
    unitcell = UnitCell.from_file("log.txt")
    ecis = Ecis.from_dirc(".")
    matrix = Matrix(conc, unitcell, ecis, size)
    matrix.adjust_conc_fine(conc)
    mc = MonteCarlo(matrix, temp)
    return mc
    def _test_montecalro(self):
        """ montecalro """
        path = os.path.join(self.PATH, "MonteCarlo", "FeH_BCCI")
        unitcell = UnitCell.from_file(os.path.join(path, "log.txt"))
        conc = 0.2
        ecis = Ecis.from_dirc(path)
        matrix = Matrix(conc, unitcell, ecis, 20)
        mc = MonteCarlo(matrix, 5000)
        pairs = mc.get_exchange_pairs([1, 3, 5])
        assert pairs[0].sum() == pairs[1].sum()
        assert (matrix.matrix[pairs[0]] == 0).all()
        assert (matrix.matrix[pairs[1]] == 1).all()
        mc.exe_flip(pairs)

        mc.loop_test(1)
    def test_Matrix(self):
        """ Matrix """
        # __init__
        # TO
        ## 160309
        path = os.path.join(self.PATH, "Matrix", "AlCu_TO")
        unitcell = UnitCell.from_file(os.path.join(path, "log.txt"))
        ecis = Ecis.from_dirc(path)
        conc = 0
        matrix = Matrix(conc, unitcell, ecis, 2)
        # FCC (HCP0*A1B0*TO)

        matrix.matrix[:] = 1
        assert np.allclose(matrix.get_energy(), -1.440741)
        # FCC (HCP0*A0B1*TO)
        matrix.matrix[:] = 0
        assert np.allclose(matrix.get_energy(), -115.824971)
        # L10 (HCP3*A1B1)
        matrix.matrix[:] = 0
        matrix.matrix[0, 0, 0, 0] = 1
        matrix.matrix[1, 1, 1, 0] = 1
        matrix.matrix[0, 1, 0, 0] = 1
        matrix.matrix[1, 0, 1, 0] = 1
        assert np.allclose(matrix.get_energy(), -211.482477833)
        # L12 (HCP27*A1B3)
        matrix.matrix[0, 0, 0, 0] = 0
        matrix.matrix[1, 1, 1, 0] = 0
        assert np.allclose(matrix.get_energy(), -173.72808675)
        # L12 (HCP28*A3B1)
        matrix.matrix[:] = 1
        matrix.matrix[0, 1, 0, 0] = 0
        matrix.matrix[1, 0, 1, 0] = 0
        assert np.allclose(matrix.get_energy(), -172.812058)

        # BCCI 2N
        ## 160311
        path = os.path.join(self.PATH, "Matrix", "FeH_BCCI_2N")
        unitcell = UnitCell.from_file(os.path.join(path, "log.txt"))
        conc = 0.5
        ecis = Ecis.from_dirc(path)
        # BCCI (HCP0*A9B0*OP)
        matrix = Matrix(conc, unitcell, ecis, 1,
                        order=[1, 1, 1, 1, 1, 1, 1, 1, 1])
        assert np.allclose(matrix.get_energy(), -17.1659116)

        # FeH6 (HCP99999*A6B3*OP)
        matrix = Matrix(conc, unitcell, ecis, 2,
                        order=[1, 1, 1, 1, 1, 1, 0, 0, 0])
        assert np.allclose(matrix.get_energy(), 0)
        # FeH3 (HCP10*A3B6*OP)
        matrix = Matrix(conc, unitcell, ecis, 3,
                        order=[0, 0, 0, 0, 0, 0, 1, 1, 1])
        assert np.allclose(matrix.get_energy(), 0)

        # FeH5 (HCP99998*5B4*OP)
        matrix = Matrix(conc, unitcell, ecis, 4,
                        order=[1, 0, 1, 0, 1, 0, 1, 0, 1])
        assert np.allclose(matrix.get_energy(), -.572197E+01)
        # FeH6 (HCP99997*A6B3*OP)
        matrix = Matrix(conc, unitcell, ecis, 5,
                        order=[1, 1, 1, 0, 0, 0, 1, 1, 1])
        assert np.allclose(matrix.get_energy(), -.858296E+01)



        # # BCCI
        # ## 160309
        path = os.path.join(self.PATH, "Matrix", "FeH_BCCI")
        unitcell = UnitCell.from_file(os.path.join(path, "log.txt"))
        conc = 0.5
        ecis = Ecis.from_dirc(path)
        # BCCI (HCP0*A9B0*OP)
        matrix = Matrix(conc, unitcell, ecis, 1,
                        order=[1, 1, 1, 1, 1, 1, 1, 1, 1])
        assert np.allclose(matrix.get_energy(), 0.132641E+01)
        # FeH6 (HCP99999*A6B3*OP)
        matrix = Matrix(conc, unitcell, ecis, 2,
                        order=[1, 1, 1, 1, 1, 1, 0, 0, 0])
        assert np.allclose(matrix.get_energy(), -.243349E+02)
        # FeH3 (HCP10*A3B6*OP)
        matrix = Matrix(conc, unitcell, ecis, 3,
                        order=[0, 0, 0, 0, 0, 0, 1, 1, 1])
        assert np.allclose(matrix.get_energy(), -.848994E+02)
        # FeH5 (HCP99998*A5B4*OP)
        matrix = Matrix(conc, unitcell, ecis, 4,
                        order=[1, 0, 1, 0, 1, 0, 1, 0, 1])
        assert np.allclose(matrix.get_energy(), -.565030E+02)
        # FeH6 (HCP99997*A6B3*OP)
        matrix = Matrix(conc, unitcell, ecis, 5,
                        order=[1, 1, 1, 0, 0, 0, 1, 1, 1])
        assert np.allclose(matrix.get_energy(), -.100641E+03)

        # get_de
        matrix = Matrix(conc, unitcell, ecis, 5)
        # [0, 0, 0, 0] のみの de
        de = matrix.get_delta_energy([[[[True]]]])
        # 全てのサイト
        de_matrix = matrix.get_delta_energy(
            matrix.matrix[:, :, :, :] != 0.5).reshape(5, 5, 5, 9)
        before = matrix.get_energy()
        matrix.matrix[0, 0, 0, 0] = 1 - matrix.matrix[0, 0, 0, 0]
        after = matrix.get_energy()
        assert np.allclose(de, (after - before)*(matrix.matrix.size))
        assert np.allclose(de_matrix[0, 0, 0, 0],
                           (after - before)*(matrix.matrix.size))

        # adjust_conc_fine
        ## 160329
        matrix = Matrix(conc, unitcell, ecis, 4)
        matrix.adjust_conc_fine(conc)
        assert matrix.conc == 0.5
    def test_Ecis(self):
        """ Ecis """
        path = os.path.join(self.PATH, "Ecis")
        unitcell = UnitCell.from_file(os.path.join(path, "log.txt"))
        # parse_ecitxt
        ## 160305
        ecis = Ecis.parse_ecitxt(os.path.join(path, "eci.txt"))
        out = {0: 0.680236051, 1: -673.192307, 2: -208.572905, 3: 1752.08986,
               4: 306.073297, 5: 147.11169, 6: 129.361349, 7: 233.347231,
               8: 237.242402, 9: -4.14835143, 10: -44.2051374, 11: -1652.97108,
               12: -286.755208, 13: -668.664112, 14: -714.67382, 16: 1227.364,
               17: -707.7569, 19: -8.39681819, 20: -20.1496428, 22: 26.7883166,
               24: -118.547219, 26: -6.21356756, 27: 1404.19369, 28: 1180.73395,
               29: 95.1228157, 31: 100.481087, 35: -1089.71922, 36: 150.635303,
               38: -845.97957, 44: -312.645058, 45: -134.730871, 47: -244.485361,
               48: -117.505334, 49: 444.617266, 52: 294.931568, 53: -274.314461,
               54: 407.711243}
        assert ecis == out
        # parse_logtxt
        ## 160305
        clus = Ecis.parse_logtxt(os.path.join(path, "log.txt"))
        assert len(clus) == 54
        out = np.array([[0.75, 0.5, 0.25], [0.5, 0.25, -0.25]])
        assert (clus[3] == out).all()

        # get_clusters_from_logtxt
        ## 160306
        clus = Ecis.get_clusters_from_logtxt(os.path.join(path, "log.txt"))
        assert len(clus) == 54
        for i in range(len(clus)):
            for idx in clus[i]:
                equiv = unitcell.symm['equivalent_atoms'][idx]
                assert len(clus[i][idx]) == len(clus[i][equiv])
        # get_diff_clusters
        ## 160306
        out = Ecis.get_diff_clusters(os.path.join(path, "eci.txt"),
                                     os.path.join(path, "log.txt"),
                                     os.path.join(path, "logN6.txt"),
                                     msg=False)
        test = ("16 13 11 0 44 3 17 24 7 29 2 4 19 34 45 36 9 21 1 54 \n"
                "26 5 6 49 15 48 8 10 53 52 27 12 28 47 20 38 31 \n")
        assert out.split() == test.split()
        # form_dirc
        ## 160308
        ecis = Ecis.from_dirc(path)

        # Al-Cu_TO_P
        ## 160330
        """
        BRAV=F の構造だとうまくいかない
        log.txt の構造表記の部分は P, F で変化しないが、
        cluster を記述する後半の部分が変わるので、そこで齟齬が生じる
        """
        path = os.path.join(self.PATH, "Ecis", "Al-Cu_TO_P")
        # path = os.path.join(self.PATH, "Ecis", "Al-Cu_TO_F")

        unitcell = UnitCell.from_file(os.path.join(path, "log.txt"))
        ecis = Ecis.parse_ecitxt(os.path.join(path, "eci.txt"))
        clus = Ecis.parse_logtxt(os.path.join(path, "log.txt"))
        # print(clus)
        clus = Ecis.get_clusters_from_logtxt(os.path.join(path, "log.txt"))