def test_cartesian_Euclidean_dot_product(): basis = np.array([ [1., 0., 0.], [0., 1., 0.], [0., 0., 1.] ]).astype('d') mydot = get_Euclidean_dot_product(basis) for i in range(100): m1, m2, m3 = np.random.randint(0, 100, size=3) n1, n2, n3 = np.random.randint(0, 100, size=3) expected_dot = m1*n1+m2*n2+m3*n3 actual_dot = mydot([m1, m2, m3], [n1, n2, n3]) assert abs(expected_dot - actual_dot) < 1e-6 return
def test_reciprocal_Euclidean_dot_product_of_ZnS(): basis = 0.5 * np.array([ [0., 1., 1.], [1., 0., 1.], [1., 1., 0.] ]).astype('d') reciprocal_basis = get_reciprocal_space_elementary_vectors(basis) rs_dot = get_Euclidean_dot_product(reciprocal_basis) for i in range(100): m1, m2, m3 = np.random.randint(0, 100, size=3) expected_norm_sq = (2*pi) ** 2 * (3.*(m1**2+m2**2+m3**2) - 2.*(m1*m2+m1*m3+m2*m3)) norm_sq = rs_dot([m1, m2, m3], [m1, m2, m3]) assert abs(expected_norm_sq - norm_sq) < 1e-6 return
def band_structure( direct_space_basis, pseudo_fname, k_list_fname, G_norm_cutoff, n_bands, ): # -- get all necessary objects needed to compute the band structure pseudo_Gs, pseudo_coefficients = read_pseudo(pseudo_fname) k_vectors = read_kpoints(k_list_fname) reciprocal_space_basis = \ get_reciprocal_space_elementary_vectors(direct_space_basis) rs_dot = get_Euclidean_dot_product(reciprocal_space_basis) assert pseudo_Gs.shape[0] == pseudo_coefficients.size assert k_vectors.shape[1] == 3 # -- Basis of G vectors used for the matrix diagonalization G_basis = get_ordered_stars(reciprocal_space_basis, G_norm_cutoff) # -- generate potential matrix, which is k-independent potential_matrix = build_potential_matrix( G_basis, pseudo_Gs, pseudo_coefficients ) # -- loop over the k points to compute the band energies band_energies = [] for idx, k_vec in enumerate(k_vectors): kinetic_matrix = build_kinetic_matrix(k_vec, G_basis, rs_dot) hamiltonian = kinetic_matrix + potential_matrix eigvals = np.sort(eigvalsh(hamiltonian))[:n_bands] band_energies += [eigvals] # -- simple check to see if the eigenvalues are real band_energies = np.array(band_energies) assert np.abs(band_energies.imag).sum() < 1e-3 return band_energies