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_SymmetryOperator(self): """ SymmetryOperator """ path = os.path.join(self.PATH, "UnitCell") unitcell = UnitCell.from_file(os.path.join(path, "log.txt")) # opertate_symm ## 160412 clus = [[1/2, 1/2, 0]] clus_dst = SymmetryOperator.operate_symm(clus, unitcell) assert np.array(clus_dst).shape == (6, 1, 4) clus = [[0, 1/2, 1/2], [3/4, 1/2, 1/4]] clus_dst = SymmetryOperator.operate_symm(clus, unitcell) assert np.array(clus_dst).shape == (48, 2, 4) clus = [[0, 1/2, 1/2], [1/2, 1/2, 0]] assert np.array( SymmetryOperator.operate_symm(clus, unitcell)).shape == (12, 2, 4) # centering ## 160412 clus = [[0, 1/2, 1/2], [1/2, 1/2, 0]] out = [[[0.5, 0, -0.5]]] assert (np.array( SymmetryOperator.centerings(clus, unitcell)[6]) == out).all() out = [[[-0.5, 0, 0.5]]] assert (np.array( SymmetryOperator.centerings(clus, unitcell)[8]) == out).all() clus = [[3/4, 1/2, 1/4]] assert not SymmetryOperator.centerings(clus, unitcell)[0][0] # get_symmetrized_clusters ## 160412 clus = [[1/2, 1/2, 0], [-1/2, -1/2, 0]] # delta = [1, 0, 0] out = [[[0, -1, -1, 0]], [[0, 1, 1, 0]]] assert SymmetryOperator.get_equiv_clusters( clus, unitcell)[6] == out clus = [[1/2, 0, 1/2], [3/4, 1/2, 1/4]] dst = SymmetryOperator.get_equiv_clusters(clus, unitcell) assert set(dst.keys()) == set(range(9)) # centerings_idx ## 160307 clus = [unitcell.site2idx(site) for site in [[0, 1/2, 1/2], [1/2, 1/2, 0]]] out = {8: [np.array([[0, 0, 0, -2]])], 6: [np.array([[0, 0, 0, 2]])]} assert (SymmetryOperator.centerings_idx(clus)[8][0] == out[8][0]).all() assert (SymmetryOperator.centerings_idx(clus)[6][0] == out[6][0]).all()
def test_UnitCell(self): """ UnitCell """ path = os.path.join(self.PATH, "UnitCell") # from_file unitcell = UnitCell.from_file(os.path.join(path, "log.txt")) # cell ## 160305 out = np.array( [[1.414893, 1.414893, 1.414893], [1.414893, -1.414893, -1.414893], [-1.414893, 1.414893, -1.414893]]) assert (unitcell.atoms.cell == out).all() # site ## 160305 out = np.array( [[0.75, 0.50, 0.25], [0.75, 0.25, 0.50], [0.50, 0.25, 0.75], [0.25, 0.75, 0.50], [0.50, 0.75, 0.25], [0.25, 0.50, 0.75], [0.00, 0.50, 0.50], [0.50, 1.00, 0.50], [0.50, 0.50, 0.00]]) assert np.allclose(unitcell.atoms.get_scaled_positions(), out) # out = ['symmorphic', '48'] # assert xtal.symm == out out = [0, 0, 0, 0, 0, 0, 6, 6, 6] assert (unitcell.symm['equivalent_atoms'] == out).all() # site2idx ## 160305 site = np.array([-0.75, -0.5, -0.25]) assert (unitcell.site2idx(site) == [-1, -1, -1, 5]) site = [1/2, 0, 1/2] assert (unitcell.site2idx(site) == [0, -1, 0, 7]) site = [1, 1/2, 1/2] assert (unitcell.site2idx(site) == [1, 0, 0, 6]) site = np.array([-0.75, -0.5, 0.25]) try: unitcell.site2idx(site) assert False except KeyError: assert True # site2pos ## 160306 site = np.array([3/4, 1/2, 1/4]) out = [1/2, 1/4, 0] pos = unitcell.site2pos(site) / unitcell.atoms.cell[0, 0] / 2 assert np.allclose(pos, out) site = np.array([3/4, 1/4, 1/2]) out = [1/4, 1/2, 0] pos = unitcell.site2pos(site) / unitcell.atoms.cell[0, 0] / 2 assert np.allclose(pos, out) site = np.array([1/2, 1/4, 3/4]) out = [0, 1/2, -1/4] pos = unitcell.site2pos(site) / unitcell.atoms.cell[0, 0] / 2 assert np.allclose(pos, out) site = np.array([1/4, 3/4, 1/2]) out = [1/4, 0, -1/2] pos = unitcell.site2pos(site) / unitcell.atoms.cell[0, 0] / 2 assert np.allclose(pos, out) site = np.array([1/2, 3/4, 1/4]) out = [1/2, 0, -1/4] pos = unitcell.site2pos(site) / unitcell.atoms.cell[0, 0] / 2 assert np.allclose(pos, out) site = np.array([1/4, 1/2, 3/4]) out = [0, 1/4, -1/2] pos = unitcell.site2pos(site) / unitcell.atoms.cell[0, 0] / 2 assert np.allclose(pos, out) site = [1/2, 1/2, 0] pos = unitcell.site2pos(site) / unitcell.atoms.cell[0, 0] / 2 assert np.allclose(pos, [1/2, 0, 0]) site = [-1/2, -1/2, 0] pos = unitcell.site2pos(site) / unitcell.atoms.cell[0, 0] / 2 assert np.allclose(pos, [-1/2, 0, 0]) site = np.array([1, 1/2, 1/2]) pos = unitcell.site2pos(site) / unitcell.atoms.cell[0, 0] / 2 assert np.allclose(pos, [1/2, 1/2, 0]) # get_ineq_group ## 160305 assert unitcell.get_ineq_group([-0.75, -0.5, -0.25]) == 0 assert unitcell.get_ineq_group([1, -0.5, -0.5]) == 6 assert unitcell.get_ineq_group([3/4, 1/2, 1/4]) == 0 try: unitcell.get_ineq_group([0.0, 1.0, -0.5]) assert False except KeyError: assert True
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"))