示例#1
0
 def _test_get_entropy_TO(self):
     """
     de を記録して entropy を算出する
     """
     path = os.path.join(self.PATH, "AlCu/wien/TO")
     fcc = FCCXtal.from_pickle_ecis(os.path.join(path, 'cluster.pickle'),
                                    arrange='random', conc=0.25, size=30)
     mc = MonteCarlo(fcc, T=10000)
     mc.loop_fcc_micro_single(2000)
示例#2
0
    def _test_gs(self):
        """
        基底状態探索
        エネルギーのみを出力
        """
        path = os.path.join(self.PATH, "AlCu/voldep/4.0/")

        fcc = FCCXtal.from_pickle_ecis(os.path.join(path, 'cluster.pickle'),
                                       arrange='random', conc=0.90, size=10)
        fcc.from_pickle_cell(os.path.join(path, 'AlCu.pickle'))

        # mc = MonteCarlo(fcc, T=500)
        # mc.loop_fcc_micro_single(500)
        # 90 300
        mc = MonteCarlo(fcc, T=20)
        mc.loop_fcc_micro_single(10000)

        fcc.make_poscar(os.path.join(path, 'POSCAR'))
        fcc.save_cell(os.path.join(path, 'AlCu'))
def EstimateDOS(system, eps_log_modification_factor, restart=None):
    """
    イタレーションによって DOS を求める
    """
    rand = numpy.random.mtrand.RandomState(100)  # 乱数ジェネレーター
    if not restart:
        # 各エネルギーに対してインデックスを持つヒストグラムと状態密度
        histgram = numpy.array([0 for i in range(system.number_of_energies)])
        log_density_of_state = [0 for i in range(system.number_of_energies)]
        # 修正ファクター: DOS を積み上げていくのに使用
        log_modification_factor = 1
        # モンテカルロステップカウンター 定期的にヒストグラムの平滑化具合をチェックするのに使用
        current_energy = system.GetEnergy()
        # エネルギー最小、最大の状態を保存する用意
        minimum_energy = current_energy
        maximum_energy = current_energy
        minimum_e_cell = system.state.cell.copy()
        maximum_e_cell = system.state.cell.copy()

    else:
        histgram = restart["histgram"]
        log_density_of_state = restart["log_DOS"]
        log_modification_factor = restart["log_modification_factor"]
        system.state.cell = restart["current_state"]
        current_energy = system.GetEnergy()
        minimum_energy = restart["minimum_state"][0]
        maximum_energy = restart["maximum_state"][0]
        minimum_e_cell = restart["minimum_state"][1]
        maximum_e_cell = restart["maximum_state"][1]

    counter_mc = 0
    def save_conditions():
        """状態を保存"""
        conditions = {"minimum_state":[minimum_energy, minimum_e_cell],
                      "maximum_state":[maximum_energy, maximum_e_cell],
                      "current_state": system.state.cell,
                      "log_DOS": log_density_of_state,
                      "log_modification_factor": log_modification_factor,
                      "histgram": histgram}
        fname = "work/save.pickle"
        with open(fname, 'wb') as wbfile:
            pickle.dump(conditions, wbfile)

    num = 0
    system.GoNextState()
    while log_modification_factor > eps_log_modification_factor:
        counter_mc += 1
        #状態変化前後でのエネルギー値を取得
        new_energy = system.GetEnergy()
        mc = MonteCarlo(system.state, T=0)
        try:
            log_dos_new = log_density_of_state[new_energy[1]]
        except IndexError:
            save_conditions()
            print("out of energy range !")
            print(new_energy)
            exit()
        log_dos_current = log_density_of_state[current_energy[1]]
        if rand.rand() < min(1.0, numpy.exp(log_dos_current - log_dos_new)):
            log_density_of_state[new_energy[1]] += log_modification_factor
            histgram[new_energy[1]] += 1
            current_energy = new_energy
        else:
            system.BackPreviousState()
            log_density_of_state[current_energy[1]] += log_modification_factor
            histgram[current_energy[1]] += 1

        system.GoNextState()

        if current_energy < minimum_energy:
            minimum_energy = current_energy
            minimum_e_cell = system.state.cell.copy()
            print('search_stable_state')
            print(system.state.get_energy())
            system.BackPreviousState()
            mc.trans_prob = mc.trans_prob_stable
            mc.loop_fcc_micro_single(5000)
            system.state.energy = system.state.get_energy()


        if current_energy > maximum_energy:
            maximum_energy = current_energy
            maximum_e_cell = system.state.cell.copy()
            print('search_unstable_state')
            print(current_energy)
            print(system.state.get_energy())
            system.BackPreviousState()
            mc.trans_prob = mc.trans_prob_unstable
            print(system.state.get_energy())
            mc.loop_fcc_micro_single(5000)
            system.state.energy = system.state.get_energy()

        if counter_mc % 1000 == 0:
            # print(minimum_energy, maximum_energy, log_modification_factor)
            # print(histgram)
            if counter_mc % 100000 == 0:
                counter_mc = 0
                save_conditions()

            judge = IsFlat_with_gap(histgram, num)
            if judge:
                num = judge
                histgram = numpy.array([0 for i in range(system.number_of_energies)])
                log_modification_factor *= 0.5
                # print('here')
                # print(log_modification_factor)
                save_conditions()
    return log_density_of_state