def test_rotate_all_grgrid_double_addresses(): """ Primitive cell of TiO2 anataze, body centred tetragonal. Shifts have to be limited to (0, 0, 0), (1, 1, 0), (0, 0, 1), (1, 1, 1). Other shifts can fail rotating grid points, but not necessarily always failing. """ D_diag = tio2_snf['D_diag'] P = tio2_snf['P'] grgrid_addresses = get_all_grgrid_addresses(D_diag) ids = np.arange(len(grgrid_addresses)) for shift in ((0, 0, 0), (1, 1, 0), (0, 0, 1), (1, 1, 1)): PS = np.dot(P, shift) d_addresses = [ get_double_grgrid_address(adrs, D_diag, PS=PS) for adrs in grgrid_addresses ] for r in np.reshape(tio2_transformed_rots, (-1, 3, 3)): rot_addresses = np.dot(d_addresses, r.T) gps = [ get_double_grgrid_index(adrs, D_diag, PS=PS) for adrs in rot_addresses ] np.testing.assert_array_equal(np.sort(gps), ids)
def test_rotate_all_grgrid_addresses(): D_diag = tio2_snf['D_diag'] grgrid_addresses = get_all_grgrid_addresses(D_diag) ids = np.arange(len(grgrid_addresses)) for r in np.reshape(tio2_transformed_rots, (-1, 3, 3)): rot_addresses = np.dot(grgrid_addresses, r.T) gps = [get_grgrid_index(adrs, D_diag) for adrs in rot_addresses] np.testing.assert_array_equal(np.sort(gps), ids)
def test_get_double_grid_index(): D_diag = tio2_snf['D_diag'] P = tio2_snf['P'] grgrid_addresses = get_all_grgrid_addresses(D_diag) for shift in np.ndindex((2, 2, 2)): PS = np.dot(P, shift) for i, address in enumerate(grgrid_addresses): d_ga = get_double_grgrid_address(address, D_diag, PS=PS) d_gp = get_double_grgrid_index(d_ga, D_diag, PS=PS) assert i == d_gp
def test_get_thm_integration_weight_tio2(tio2_lattice, tio2_phonon_frequences_grg): dos_str_df_1 = """0.0 0.00000000 0.00000000 2.5 0.33432705 0.22888315 5.0 2.51042492 2.94515722 7.5 0.85214354 5.32809578 10.0 1.22209820 8.51697799 12.5 1.36331347 10.72763736 15.0 1.84840716 13.72854085 17.5 0.25849856 14.98248161 20.0 0.05704757 16.04840272 22.5 0.40515558 16.44481785 25.0 0.00814283 17.99947146""" dos_ref = np.fromstring(dos_str_df_1, sep=' ').reshape(-1, 3) freqs = tio2_phonon_frequences_grg grid_matrix = [[0, 11, 11], [11, 0, 11], [4, 4, 0]] D_diag = [1, 11, 88] P = [[0, -1, 3], [1, 0, 0], [-4, 4, -11]] num_gps = np.prod(D_diag) num_bands = freqs.shape[1] shift = [0, 0, 0] rec_lat = np.linalg.inv(tio2_lattice) microzone = np.dot(rec_lat, np.linalg.inv(grid_matrix)) grid_addresses = get_all_grgrid_addresses(D_diag) # print(grid_addresses[:20]) relative_addresses = get_thm_relative_grid_addresses(microzone) gr_relative_addresses = np.dot(relative_addresses, np.transpose(P)) fpoints = dos_ref[:, 0] dos = np.zeros_like(fpoints) acc = np.zeros_like(fpoints) for ga in grid_addresses: tetrahedra_gps = _get_tetrahedra_grgrid_indices( ga + gr_relative_addresses, D_diag, shift) tetrahedra_freqs = freqs[tetrahedra_gps] for i, fpt in enumerate(fpoints): for j in range(num_bands): dos[i] += get_thm_integration_weight(fpt, tetrahedra_freqs[:, :, j]) acc[i] += get_thm_integration_weight(fpt, tetrahedra_freqs[:, :, j], function='J') dos_dat = np.array([fpoints, dos / num_gps, acc / num_gps]).T np.testing.assert_allclose(dos_dat, dos_ref, atol=1e-5)
def _test_rotate_grgrid_index(lattice, snf, trans_rots, rots, shifts): """ rotate_grgrid_index returns grid point index by r_gp_index = rotate_grgrid_index(gp_index, r, D_diag, PS=PS) When we want to see q-point in the original coordinates, we need three steps from the rotated grid point index: r_adrs = get_grgrid_address_from_index(r_gp_index, D_diag) r_dadrs = get_double_grgrid_address(r_adrs, D_diag, PS=PS) r_q = np.dot(QD_inv, r_dadrs) / 2 """ reclat = np.linalg.inv(lattice) D_diag = snf['D_diag'] P = snf['P'] Q = snf['Q'] QD_inv = Q / np.array(D_diag, dtype=float) for shift in shifts: PS = np.dot(P, shift) grgrid_addresses = get_all_grgrid_addresses(D_diag) for gp_index, adrs in enumerate(grgrid_addresses): for r, orig_r in zip(trans_rots, rots): dadrs = get_double_grgrid_address(adrs, D_diag, PS=PS) q = np.dot(QD_inv, dadrs) / 2 q -= np.rint(q) Rq = np.dot(orig_r, q) Rq -= np.rint(Rq) r_gp_index = rotate_grgrid_index(gp_index, r, D_diag, PS=PS) r_adrs = get_grgrid_address_from_index(r_gp_index, D_diag) r_dadrs = get_double_grgrid_address(r_adrs, D_diag, PS=PS) r_q = np.dot(QD_inv, r_dadrs) / 2 r_q -= np.rint(r_q) diff = Rq - r_q diff -= np.rint(diff) assert (np.dot(reclat, diff)**2).sum() < 1e-5
def test_get_grgrid_address_from_index(): D_diag = tio2_snf['D_diag'] grgrid_addresses = get_all_grgrid_addresses(D_diag) for gp_index, address in enumerate(grgrid_addresses): adrs = get_grgrid_address_from_index(gp_index, D_diag) np.testing.assert_array_equal(adrs, address)
def test_get_grid_index(): D_diag = tio2_snf['D_diag'] grgrid_addresses = get_all_grgrid_addresses(D_diag) for i, address in enumerate(grgrid_addresses): s_gp = get_grgrid_index(address, D_diag) assert i == s_gp
def test_get_all_grgrid_addresses(): D_diag = [2, 4, 4] grgrid_addresses = get_all_grgrid_addresses(D_diag) # for v in grgrid_addresses: # print("[%d, %d, %d]," % tuple(v)) np.testing.assert_array_equal(grgrid_addresses, addresses_244)