예제 #1
0
def get_effective_potential(rr, n, N_electrons, xc_type):
    ## Get external potential
    V_ext = -Z / rr[1:-1]

    ## Get single electron Hartree potential
    V_sH = get_hartree_potential(rr[1:-1], n[1:-1])

    ## Get total Hartree potential
    V_H = N_electrons * V_sH

    ## Get exchange correlation potential, type depends on function input
    if xc_type == 0:
        V_xc = 0
    elif xc_type == 1:
        V_xc = get_V_x(n[1:-1])
    elif xc_type == 2:
        V_xc = get_V_xc(n[1:-1])
    elif xc_type == 3:
        V_xc = get_V_xc_Vosko(n[1:-1])
    else:
        raise ValueError('Invalid exchange correlation type argument.')

    ## Add the potential terms to form the effective potential
    V_eff = V_ext + V_H + V_xc
    V_eff_diag = np.diagflat(V_eff)

    return V_eff_diag
예제 #2
0
def test_helium_xc(rr, psi, tol, max_iter, verbose):
    print(
        "Calculating helium wave function and ground state energy with xc-Perdew..."
    )
    Z = 2
    iteration_number = 0
    E = 0
    E_prev = E + 1
    T0 = time.clock()
    while abs(E - E_prev) > tol and iteration_number < max_iter:
        iteration_number += 1
        if verbose:
            print("####### Iteration", iteration_number, "#######")
        n = get_n(psi)
        V_sH = get_hartree_potential(rr, n)
        V_H = 2 * V_sH
        V_xc = get_V_xc(n)
        E_prev = E
        E, psi = solve_ks(rr, Z, V_H, V_xc)
        if verbose:
            print("E =", E, "[Ha]")
            print("ΔE =", E - E_prev, "[Ha]")
            print("Time =", time.clock() - T0, "s")
            print()
    return psi, E