def _test_flip_de_AlCutetra(self): """ flip de を total energy の変化量と比較 single サイト """ fcc = FCCXtal.from_pickle_ecis( os.path.join(self.PATH, "AlCu/tetra_stress30/cluster.pickle"), arrange='FCC_A', size=6) fcc.cell[1, 2, 1, 3] = 0 fcc.cell[1, 1, 1, 3] = 0 fcc.cell[2, 2, 1, 0] = 0 fcc.cell[1, 2, 1, 0] = 0 pred_de = fcc.get_flip_de()[2, 2, 1, 3]/fcc.size**3/4 print("before") before = fcc.get_energy() print(before) fcc.cell[2, 2, 1, 3] = 0 # fcc.cell[1, 2, 1, 2] = 0 print((fcc.get_flip_de() == np.min(fcc.get_flip_de())).sum()) after = fcc.get_energy() print(after) print("de") de = after - before print(de) print("Predict de") print(pred_de) print((de - pred_de) ** 2 < 1e-6)
def exe(size, conc, restart): """ LW MonteCarlo を実行 """ #システム生成 # path = "/Users/enoki/Researches/Analysis/Codes/01_testRun/montecarlo/AlCu/voldep/4.0" # path = "/Users/enoki/Researches/Analysis/Codes/01_testRun/montecarlo/AlCu/wien/TO/" # fcc = FCCXtal.from_pickle_ecis(os.path.join(path, 'cluster.pickle'), # arrange='random', conc=0.25, size=4) fcc = FCCXtal.from_pickle_ecis('cluster.pickle', arrange='random', conc=conc, size=size) fcc.adjast_conc_fine(conc) x = System(fcc) #収束計算の許容範囲 eps_log_modification_factor = 10 ** (-8) #状態密度計算 if restart: fname = "work/save.pickle" with open(fname, 'rb') as rbfile: restart = pickle.load(rbfile) x.state.cell = restart["current_state"] x.state.energy = x.state.get_energy() log_density_of_state = EstimateDOS(x, eps_log_modification_factor, restart) print(log_density_of_state)
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)
def _test_order_AlCu_TO(self): """ 規則相のエネルギーを icvm と比較 null clucter は含まれていないので注意 """ path = os.path.join(self.PATH, "AlCu/wien/TO") fcc = FCCXtal.from_pickle_ecis(os.path.join(path, 'cluster.pickle'), arrange='L12_A', size=10) print("L12_A3B: -40.7461") print(fcc.get_energy()) fcc = FCCXtal.from_pickle_ecis(os.path.join(path, 'cluster.pickle'), arrange='L10', size=10) print("L10_AB -148.668") print(fcc.get_energy()) fcc = FCCXtal.from_pickle_ecis(os.path.join(path, 'cluster.pickle'), arrange='L12_B', size=10) print("L12_AB3 -183.749") print(fcc.get_energy())
def _test_AlCu_mc_grand_TO(self): """ グランドカノニカルの計算テスト TO 近似 """ fcc = FCCXtal.from_pickle_ecis( os.path.join(self.PATH, "cluster_AlCu_TO.pickle"), arrange='random', conc=0.6, size=30) # fcc.from_pickle_cell(os.path.join(self.PATH, 'AlCu.pickle')) mc = MonteCarlo(fcc, T=1000) mc.loop_fcc_grand(100) fcc.make_poscar(os.path.join(self.PATH, 'POSCAR')) fcc.save_cell(os.path.join(self.PATH, 'AlCu'))
def _test_mc_fcc_micoro_single(self): """ loop_fcc_mciro_single の テスト benchmarker で速度計測 """ # path = os.path.join(self.PATH, "AlCu/voldep/4.0/") path = os.path.join(self.PATH, "AlCu/wien/") fcc = FCCXtal.from_pickle_ecis(os.path.join(path, 'cluster.pickle'), arrange='random', conc=0.90, size=10) print(len(fcc.ecis)) mc = MonteCarlo(fcc, T=300) with Benchmarker(width=20, loop=3) as bench: @bench("simple") def _(bm): #pylint: disable=W0613,C0111 mc.loop_fcc_micro_single(10)
def _test_AlCu_mc_grand(self): """ グランドカノニカルの計算テスト """ fcc = FCCXtal.from_pickle_ecis( os.path.join(self.PATH, "cluster_AlCu_09.pickle"), arrange='random', conc=0.05, size=10) # fcc.from_pickle_cell(os.path.join(self.PATH, 'AlCu.pickle')) # eci_point = - 454.351346 # -3250 @ 1500 # -3800 @ 8000 0.92 # -4000 @ 10000 0.92 # -4700 @ 13500 fcc.eci_point = 89.45 mc = MonteCarlo(fcc, T=0) mc.loop_fcc_grand(20) fcc.make_poscar(os.path.join(self.PATH, 'POSCAR')) fcc.save_cell(os.path.join(self.PATH, 'AlCu'))
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 _test_flip_de_fcc(self): """ flip de を total energy の変化量と比較 一致すれば O.K. cell size が 3 以上ならうまくいく それより小さい場合は direct にエネルギーを求めた方が良い """ path = os.path.join(self.PATH, "AlCu/voldep/4.0/") # path = os.path.join(self.PATH, "AlCu/wien/TO/") fcc = FCCXtal.from_pickle_ecis(os.path.join(path, 'cluster.pickle'), arrange='random', conc=0.8, size=3) for _ in range(10): # s=0, s=1 のサイトを無作為に抽出 print("random flip") s0 = fcc.cell == 0 select_s0 = np.random.choice(range((s0).sum()), 1, replace=False) site_s0 = (np.array(np.where(s0)))[:, select_s0[0]] s1 = fcc.cell == 1 select_s1 = np.random.choice( range((s1).sum()), 1, replace=False) site_s1 = (np.array(np.where(s1)))[:, select_s1[0]] print("before energy") before = fcc.get_energy() print(before) pred_de = fcc.get_exchange_de_small(site_s0, site_s1)/fcc.size**3/4 pred_de = fcc.get_exchange_de(site_s0, site_s1)/fcc.size**3/4 fcc.cell[tuple(site_s0.T)] = 1 fcc.cell[tuple(site_s1.T)] = 0 after = fcc.get_energy() print("after energy") print(after) print("de") de = after - before print(de) print("Predict de") print(pred_de) assert (de - pred_de) ** 2 < 1e-6
def __test_poscar(self): fname = 'POSCAR_ini' path = '/Users/enoki/Dropbox/poscar' path = '/Users/enoki/poscar2' fcc = FCCXtal.from_pickle_ecis(os.path.join(path, 'cluster.pickle'), arrange='random', conc=0.5, size=12) fcc.load_poscar(os.path.join(path, fname), 0, 1) fcc.get_histogram() # fname = 'POSCAR_99' # fcc.load_poscar(os.path.join(path, fname), 0, 1) # fcc.get_histogram() # fname = 'POSCAR_199' # fcc.load_poscar(os.path.join(path, fname), 0, 1) # fcc.get_histogram() # fname = 'POSCAR_299' # fcc.load_poscar(os.path.join(path, fname), 0, 1) # fcc.get_histogram() # fname = 'POSCAR_399' # fcc.load_poscar(os.path.join(path, fname), 0, 1) # fcc.get_histogram() # fname = 'POSCAR_499' # fcc.load_poscar(os.path.join(path, fname), 0, 1) # fcc.get_histogram() fname = 'POSCAR_4086' fcc.load_poscar(os.path.join(path, fname), 0, 1) fcc.get_histogram() fname = 'POSCAR_699' fcc.load_poscar(os.path.join(path, fname), 0, 1) fcc.get_histogram() pylab.show()
def calc_dos(): fname = "work/analysis/save.pickle" with open(fname, 'rb') as rbfile: conditions = pickle.load(rbfile) path = "/Users/enoki/Researches/Analysis/Codes/01_testRun/montecarlo/AlCu/voldep/4.0" system = FCCXtal.from_pickle_ecis(os.path.join(path, 'cluster.pickle'), arrange='random', conc=0.5, size=4) print(conditions['log_DOS'][:20]) print(max(conditions['log_DOS'][:20])) ldos = [numpy.exp(x-max(conditions['log_DOS'][:20])) for x in conditions['log_DOS'][:20]] print(ldos) minimum = conditions['minimum_state'][0] maximum = conditions['maximum_state'][0] de = (maximum[0] - minimum[0])/(maximum[1] - minimum[1] - 1) energies = numpy.array([minimum[0] + de * (i - 0.5) for i in range(len(ldos))]) print(energies) print(minimum[0], maximum[0]) # index = [i + 1 for i in range(len(ldos))] # width = 0.35 # pos = matplotlib.pyplot.bar(energies, ldos, width, color = 'r', align = 'center') # matplotlib.pyplot.ylabel('Ratio(normalized)') # matplotlib.pyplot.title('Density of states') # matplotlib.pyplot.show() def get_energy(T, kb=8.6171e-2): beta = 1/(kb*T) bunbo = ldos * numpy.exp(-beta*energies*32) bunshi = energies*ldos*32 * numpy.exp(-beta*energies*32) energy = bunshi.sum() / bunbo.sum() print(T, energy) print("energy") for i in range(200): get_energy(10*(i+1))
def test_mc_fcc_micoro_single(self): """ loop_fcc_mciro_single の テスト benchmarker で速度計測 """ # path = os.path.join(self.PATH, "AlCu/voldep/4.0/") path = os.path.join(self.PATH, "AlCu/wien/") fcc = FCCXtal.from_pickle_ecis(os.path.join(path, 'cluster.pickle'), arrange='random', conc=0.50, size=5) print(len(fcc.ecis)) mc = MonteCarlo(fcc, T=100) # print(fcc._get_site_energy2()) print(fcc.get_energy()) # fcc.get_histogram() # pylab.show() # inter = fcc.get_histogram_inter(T=100) # get_de = fcc.get_exchange_de2(inter) # mc._loop_fcc_micro_single(10000, get_de) # fcc.get_histogram() # mc._loop_fcc_micro_single(10000, get_de) # fcc.get_histogram() # mc._loop_fcc_micro_single(10000, get_de) # fcc.get_histogram() # pylab.show() with Benchmarker(width=20, loop=3) as bench: @bench("simple") def t(bm): #pylint: disable=W0613,C0111 for _ in range(50): fcc.get_energy() fcc.ecis = np.array(fcc.ecis).reshape(1, -1) with Benchmarker(width=20, loop=3) as bench: @bench("simple2") def m(bm): #pylint: disable=W0613,C0111 for _ in range(50): fcc.get_energy2()
def rerun(): fname = "work/analysis/save.pickle" with open(fname, 'rb') as rbfile: conditions = pickle.load(rbfile) system = FCCXtal.from_pickle_ecis(os.path.join(path, 'cluster.pickle'), arrange='random', conc=0.25, size=4)
def analysis(): fname = "work/analysis/save.pickle" with open(fname, 'rb') as rbfile: conditions = pickle.load(rbfile) # path = "/Users/enoki/Researches/Analysis/Codes/01_testRun/montecarlo/AlCu/voldep/4.0" # system = FCCXtal.from_pickle_ecis(os.path.join(path, 'cluster.pickle'), # arrange='random', conc=0.5, size=2) system = FCCXtal(size=2) print(conditions['maximum_state'][0]) system.cell = conditions['maximum_state'][1] system.make_poscar('work/analysis/POSCAR_max') print(conditions['minimum_state'][0]) system.cell = conditions['minimum_state'][1] # system.load_poscar('work/analysis/POSCAR_min2', 1, 0) # system.load_poscar('work/analysis/POSCAR_min2', 0, 1) # print(system.get_energy()) # mc = MonteCarlo(system, 0) # mc.loop_fcc_micro_single(50000) # print(system.get_energy()) system.make_poscar('work/analysis/POSCAR_min') return system.cell = conditions['current_state'] print(system.get_energy()) print(system.get_conc()) system.adjast_conc_fine(0.5) print(system.get_energy()) print(system.get_conc()) system.cell[:, :, :, :] = 0 system.cell[:, :, 0, :] = 1 system.cell[:, :, 1, :] = 1 print(system.get_conc()) print(system.get_energy()) path = "/Users/enoki/Researches/Analysis/Codes/01_testRun/montecarlo/AlCu/voldep/4.0" system = FCCXtal.from_pickle_ecis(os.path.join(path, 'cluster.pickle'), arrange='random', conc=0.5, size=2) system.cell[:, :, :, :] = 0 system.cell[:, :, 0, :] = 1 print(system.get_conc()) print(system.get_energy()) system.cell[:, :, :, :] = 0 system.cell[0, 0, 0, :] = 1 system.cell[1, 1, 0, :] = 1 print(system.get_conc()) print(system.get_energy()) system.make_poscar('work/analysis/POSCAR_top_state')