Exemple #1
0
def test_orca_water():
    coord, atom = read_xyz.easy_read("test_coord.xyz", None, False, False)
    coord = coord[0, :, :]
    coord = read_xyz.xyz_to_bohr(coord)
    zoa = read_xyz.atom_to_zoa(atom)
    noa = atom.shape[0]
    noo, orb_coord, orb_type, coef_mat, exp_mat = create_basis.basisset(
        noa, zoa, coord)
    read_xyz.plot_initial_orbs(noo, orb_coord, orb_type, coef_mat, exp_mat)

    over_mat = eval_over.get_overlap_mat(noo, orb_coord, orb_type, coef_mat,
                                         exp_mat)
    np.set_printoptions(precision=4, suppress=True)
    kin_mat = eval_kin.get_kin_mat(noo, orb_coord, orb_type, coef_mat, exp_mat)
    nuc_mat = eval_nuc.get_nuc_mat(noo, orb_coord, orb_type, coef_mat, exp_mat,
                                   coord, zoa)

    dip_matx = eval_dipole.get_dip_mat(noo, orb_coord, orb_type, coef_mat,
                                       exp_mat, 0)
    dip_maty = eval_dipole.get_dip_mat(noo, orb_coord, orb_type, coef_mat,
                                       exp_mat, 1)
    dip_matz = eval_dipole.get_dip_mat(noo, orb_coord, orb_type, coef_mat,
                                       exp_mat, 2)
    dip_mat = np.array([dip_matx, dip_maty, dip_matz])

    four_mat = eval_four.get_four_mat(noo, orb_coord, orb_type, coef_mat,
                                      exp_mat)
    h = kin_mat + nuc_mat
    ##diagonalisation of S
    #eig, u = np.linalg.eig(over_mat)
    ##creation of matrix x via canonical orthogonalisation
    #x = u / (eig) ** 0.5
    ## xt is transposed of x
    #xt = x.T
    x = scf.ortho_basis(over_mat)
    noe = zoa.sum()
    #print("number of electron:", noe)
    #en, p, c = scf.scf(four_mat, noe, noo, x, xt, h)
    en, p, c, coeff = scf.scf(four_mat, noe, noo, x, h)
    etot = scf.calc_tot_en(noa, en, coord, zoa)
    #print(etot)
    #dipole = dip_mat * p
    #dipole = dipole.sum(axis=1)
    #dipole = dipole.sum(axis=1)
    dipole = eval_dipole.get_el_dipole(p, dip_mat)
    nuc_pole = eval_dipole.get_nuc_pole(coord, zoa)
    tot_dip = nuc_pole - dipole
    orca_en = -74.962919685003
    orca_dip = np.array([0.000000, 0.678999, -0.000000])
    assert etot == pytest.approx(orca_en, rel=1e-5, abs=1e-4)
    assert tot_dip == pytest.approx(orca_dip, rel=1e-5, abs=1e-3)
Exemple #2
0
def test_nuc():
    coord, atom = read_xyz.easy_read("test_coord.xyz", None, False, False)
    coord = coord[0,:,:]
    coord = read_xyz.xyz_to_bohr(coord)
    zoa = read_xyz.atom_to_zoa(atom)
    noa = atom.shape[0]
    noo, orb_coord, orb_type, coef_mat, exp_mat = create_basis.basisset(noa, zoa, coord)
#NUCLEAR-ATTRACTION MATRIX
    nuc_mat = eval_nuc.get_nuc_mat(noo, orb_coord, orb_type, coef_mat, exp_mat, coord, zoa)
    #print("nuclear attraction  matrix: ")
    nuc_ref = np.array([[-61.72413,  -7.44477,   0.00000,  -0.01900,   0.00000,  -1.74672,  -1.74672],
 [-7.44477, -10.14287,   0.00000,  -0.22350,   0.00000,  -3.86944,  -3.86944],
 [ 0.00000,   0.00000, -10.14262,   0.00000,   0.00000,  -2.25477,   2.25477],
 [-0.01900,  -0.22350,   0.00000, -10.07996,   0.00000,  -1.81819,  -1.81819],
 [ 0.00000,   0.00000,   0.00000,   0.00000,  -9.98632,   0.00000,   0.00000],
 [-1.74672,  -3.86944,  -2.25477,  -1.81819,   0.00000,  -5.83642,  -1.61650],
 [-1.74672,  -3.86944,   2.25477,  -1.81819,   0.00000,  -1.61650,  -5.83642]])
    
    np.set_printoptions(precision=4, suppress=True)
    print(nuc_ref - nuc_mat)
    print(nuc_mat)
    assert nuc_mat == pytest.approx(nuc_ref.astype('float64'), rel = 0.001)
Exemple #3
0
def test_form_g_mat():
    #dens_xxx_01  fock_xxx_01 coord_xxx_01.xyz
    orca_dens = np.loadtxt("../data/dens_xxx_01")
    orca_fock = np.loadtxt("../data/fock_xxx_01")
    orca_h = np.loadtxt("../data/h_xxx_01")
    orca_fock2 = np.zeros(orca_fock.shape)
    orca_dens2 = np.zeros(orca_dens.shape)
    orca_h2 = np.zeros(orca_h.shape)

    dict1 = {}
    dict1[0] = 0
    dict1[1] = 1
    dict1[2] = 4
    dict1[3] = 2
    dict1[4] = 3
    dict1[5] = 5
    dict1[6] = 6

    for i in range(orca_fock2.shape[0]):
        for j in range(orca_fock2.shape[1]):
            #k = i
            #l = j
            #if i  =
            orca_fock2[dict1[i], dict1[j]] = orca_fock[i, j]
            orca_dens2[dict1[i], dict1[j]] = orca_dens[i, j]
            orca_h2[dict1[i], dict1[j]] = orca_h[i, j]
    p = orca_dens2
    #p =np.array([[2.10625, -0.44603, 0.00000, 0.10859, 0.00000, -0.02843, -0.02843],
    # [-0.44603, 1.96730, 0.00000,-0.61771, 0.00000, -0.03406, -0.03406],
    # [0.00000,  0.00000, 0.73554, 0.00000, 0.00000,  0.53974, -0.53974],
    # [0.10859, -0.61771, 0.00000, 1.24023, 0.00000,  0.47272,  0.47272],
    # [0.00000,  0.00000, 0.00000, 0.00000, 2.00000,  0.00000,  0.00000],
    # [-0.02843,-0.03406, 0.53974, 0.47272, 0.00000,  0.60093, -0.19120],
    # [-0.02843,-0.03406,-0.53974, 0.47272, 0.00000, -0.19120,  0.60093]])
    coord, atom = read_xyz.easy_read("../data/coord_xxx_01.xyz", None, False,
                                     False)
    coord = coord[0, :, :]
    coord = read_xyz.xyz_to_bohr(coord)
    zoa = read_xyz.atom_to_zoa(atom)
    noa = atom.shape[0]
    #basisset(noa, zoa, coord)
    noo, orb_coord, orb_type, coef_mat, exp_mat = create_basis.basisset(
        noa, zoa, coord)
    #print(noo)
    #print(orb_coord)
    #print(orb_type)
    #print(coef_mat)
    #print(exp_mat)
    read_xyz.plot_initial_orbs(noo, orb_coord, orb_type, coef_mat, exp_mat)
    #    print(coef_mat.dtype)

    over_mat = eval_over.get_overlap_mat(noo, orb_coord, orb_type, coef_mat,
                                         exp_mat)
    np.set_printoptions(precision=5, suppress=True)
    kin_mat = eval_kin.get_kin_mat(noo, orb_coord, orb_type, coef_mat, exp_mat)
    nuc_mat = eval_nuc.get_nuc_mat(noo, orb_coord, orb_type, coef_mat, exp_mat,
                                   coord, zoa)

    print("pre_noo:", noo)
    four_mat = eval_four.get_four_mat(noo, orb_coord, orb_type, coef_mat,
                                      exp_mat)

    h = kin_mat + nuc_mat
    g = scf.formg(noo, four_mat, p)
    f = h + g
    #fock_ref = np.loadtxt("../data/fock.data")
    #print()
    #print(f - fock_ref)
    #print()
    #print((f - fock_ref)/fock_ref)
    #print()
    #print(f )
    #print()
    #print(fock_ref)

    #../data/orca_dens_eq ../data/orca_fock_eq
    #assert f == pytest.approx(fock_ref, rel=1e-3, abs=1e-5)

    print(f - orca_fock2)
    print()
    #print((f - orca_fock2)/f)
    print()
    print(f)
    print()
    print(orca_fock2)

    assert h == pytest.approx(orca_h2, rel=1e-3, abs=1e-4)
    assert f == pytest.approx(orca_fock2, rel=1e-3, abs=1e-4)
    assert p == pytest.approx(orca_dens2, rel=1e-3, abs=1e-4)
Exemple #4
0
def main():
    print("sonntag")
    print(
        "Performing a  self-consistent HF calculation of the molecule given by the file  coord.xyz in this directory ... "
    )
    print("Reading coordinates ... ")
    coord, atom = read_xyz.easy_read("coord.xyz", None, False, False)
    coord = coord[0, :, :]
    coord = read_xyz.xyz_to_bohr(coord)
    zoa = read_xyz.atom_to_zoa(atom)
    noa = atom.shape[0]
    noo, orb_coord, orb_type, coef_mat, exp_mat = create_basis.basisset(
        noa, zoa, coord)
    read_xyz.plot_initial_orbs(noo, orb_coord, orb_type, coef_mat, exp_mat)

    over_mat = eval_over.get_overlap_mat(noo, orb_coord, orb_type, coef_mat,
                                         exp_mat)
    print("overlap matrix: ")
    np.set_printoptions(precision=4, suppress=True)
    print(over_mat.astype('float64'))

    kin_mat = eval_kin.get_kin_mat(noo, orb_coord, orb_type, coef_mat, exp_mat)
    print("kinetic energy  matrix: ")
    print(kin_mat.astype('float64'))

    nuc_mat = eval_nuc.get_nuc_mat(noo, orb_coord, orb_type, coef_mat, exp_mat,
                                   coord, zoa)
    print("nuclear attraction  matrix: ")
    print(nuc_mat.astype('float64'))

    dip_matx = eval_dipole.get_dip_mat(noo, orb_coord, orb_type, coef_mat,
                                       exp_mat, 0)
    dip_maty = eval_dipole.get_dip_mat(noo, orb_coord, orb_type, coef_mat,
                                       exp_mat, 1)
    dip_matz = eval_dipole.get_dip_mat(noo, orb_coord, orb_type, coef_mat,
                                       exp_mat, 2)
    dip_mat = np.array([dip_matx, dip_maty, dip_matz])
    print("dipole moment matrix: ")
    print(dip_mat.astype('float64'))

    print("calculate four center  integrals.... ")
    four_mat = eval_four.get_four_mat(noo, orb_coord, orb_type, coef_mat,
                                      exp_mat)
    #print(four_mat[0,0,0,0])
    #print(four_mat[5,5,5,3])

    #create core hamiltonian
    h = kin_mat + nuc_mat

    x = scf.ortho_basis(over_mat)
    noe = zoa.sum()
    print("number of electron:", noe)
    en, p, coeff, energy_orb = scf.scf(four_mat, noe, noo, x, h)
    print()
    print("#######################################################")
    print("final orbital energies:", energy_orb)
    print("#######################################################")
    #print()
    print()
    print("#######################################################")
    print("final electronic energy:", en)
    print("#######################################################")
    print()

    etot = scf.calc_tot_en(noa, en, coord, zoa)
    print("#######################################################")
    print("final total energy:", etot)
    print("#######################################################")
    #print(etot)
    dipole = eval_dipole.get_el_dipole(p, dip_mat)
    print()
    print()
    print()
    print("#######################################################")
    print("electronic contribution dipole moment:", dipole)
    nuc_pole = eval_dipole.get_nuc_pole(coord, zoa)
    print("nucear contribution dipole moment:", nuc_pole)
    print("total dipole moment:", nuc_pole - dipole,
          np.linalg.norm(nuc_pole - dipole))
    print("#######################################################")

    np.savetxt("coefficients", coeff[:int(noe / 2), :])
    np.savetxt("density_mat", p)
Exemple #5
0
def main():
    original_stdout = sys.stdout
    print("Calculation of the first three moment expanded states")
    print()
    print("initalize system and calculating one and two electron matrices...")
    with open('detailed_output_moment_expansion.txt', 'w') as f:
        sys.stdout = f
        print("Reading coordinates ... ")
        coord, atom = read_xyz.easy_read("coord.xyz", None, False, False)
        coord = coord[0, :, :]
        coord = read_xyz.xyz_to_bohr(coord)
        zoa = read_xyz.atom_to_zoa(atom)
        noa = atom.shape[0]
        noo, orb_coord, orb_type, coef_mat, exp_mat = create_basis.basisset(
            noa, zoa, coord)
        read_xyz.plot_initial_orbs(noo, orb_coord, orb_type, coef_mat, exp_mat)

        over_mat = eval_over.get_overlap_mat(noo, orb_coord, orb_type,
                                             coef_mat, exp_mat)
        print("overlap matrix: ")
        np.set_printoptions(precision=4, suppress=True)
        print(over_mat.astype('float64'))

        kin_mat = eval_kin.get_kin_mat(noo, orb_coord, orb_type, coef_mat,
                                       exp_mat)
        print("kinetic energy  matrix: ")
        print(kin_mat.astype('float64'))

        nuc_mat = eval_nuc.get_nuc_mat(noo, orb_coord, orb_type, coef_mat,
                                       exp_mat, coord, zoa)
        print("nuclear attraction  matrix: ")
        print(nuc_mat.astype('float64'))

        dip_matx = eval_dipole.get_dip_mat(noo, orb_coord, orb_type, coef_mat,
                                           exp_mat, 0)
        dip_maty = eval_dipole.get_dip_mat(noo, orb_coord, orb_type, coef_mat,
                                           exp_mat, 1)
        dip_matz = eval_dipole.get_dip_mat(noo, orb_coord, orb_type, coef_mat,
                                           exp_mat, 2)
        dip_mat = np.array([dip_matx, dip_maty, dip_matz])
        print("dipole moment matrix: ")
        print(dip_mat.astype('float64'))

        print("calculate four center  integrals.... ")
        four_mat = eval_four.get_four_mat(noo, orb_coord, orb_type, coef_mat,
                                          exp_mat)
        #print(four_mat[0,0,0,0])
        #print(four_mat[5,5,5,3])

        #create core hamiltonian
        h = kin_mat + nuc_mat

        x = scf.ortho_basis(over_mat)
        noe = zoa.sum()
        print("number of electron:", noe)
        diff_dens_list = []
        #for i in range([0,1,2,3]):
        sys.stdout = original_stdout
        print(
            "performing single point calculation with and without external potentials"
        )
        sys.stdout = f
        for i in [0, 1, 2, 3]:
            if i == 0:
                ext = None
            else:
                ext = 0.0001 * dip_mat[i - 1, :, :]

            print()
            print()
            print()
            print()
            print()
            print("#######################################################",
                  file=f)
            print("start of new single point calculation for the " + str(i) +
                  "-th moment expanded state",
                  file=f)
            print("#######################################################")
            print()

            h = kin_mat + nuc_mat
            en, p, coeff, energy_orb = scf.scf(four_mat, noe, noo, x, h, ext)
            print()
            print("#######################################################")
            print("final orbital energies:", energy_orb)
            print("#######################################################")
            #print()
            print()
            print("#######################################################")
            print("final electronic energy:", en)
            print("#######################################################")
            print()

            etot = scf.calc_tot_en(noa, en, coord, zoa)
            print("#######################################################")
            print("final total energy:", etot)
            print("#######################################################")
            #print(etot)
            dipole = eval_dipole.get_el_dipole(p, dip_mat)
            print()
            print()
            print()
            print("#######################################################")
            print("electronic contribution dipole moment:", dipole)
            nuc_pole = eval_dipole.get_nuc_pole(coord, zoa)
            print("nucear contribution dipole moment:", nuc_pole)
            print("total dipole moment:", nuc_pole - dipole)
            print("#######################################################")

            str1 = "coefficients" + str(i)
            #np.savetxt("coefficients", coeff[:int(noe/2),:])
            np.savetxt(str1, coeff[:int(noe / 2), :])
            str4 = "density_mat" + str(i)
            #np.savetxt("coefficients", coeff[:int(noe/2),:])
            np.savetxt(str4, p)

            print()
            print("#######################################################")
            #print("coefficients matrix of  " + str(i)+"th single point")
            #print(coeff[:int(noe/2),:])
            print("density matrix obtained by  " + str(i) +
                  "-th single point calculation")
            print(p)
            print("#######################################################")
            print()

            if i == 0:
                equi_coeff = np.copy(coeff[:int(noe / 2), :])
                equi_p = np.copy(p)
            else:
                str2 = "coefficients_mes" + str(i)
                str3 = "denstiy_mes" + str(i)
                diff = coeff[:int(noe / 2), :] - equi_coeff
                diff_p = p - equi_p
                np.savetxt(str2, diff)
                np.savetxt(str3, diff_p)
                diff_dens_list.append(diff_p)
                print()
                #print("#######################################################")
                #print("coefficients matrix of equilibrium single point")
                #print(equi_coeff)
                #print("#######################################################")
                #print("coefficients matrix of" + str(i)+"th moment expanded state")
                #print(diff)
                #print("#######################################################")
                print(
                    "#######################################################")
                print(
                    "density matrix from obtained from single point calculation without applied external potentials"
                )
                print(equi_p)
                print(
                    "#######################################################")
                #print("density matrix of" + str(i)+"-th moment expanded state")
                print(
                    "density matrix of electron density difference obtained by  single point calculations with the "
                    + str(i) + "-th  and without an external potential")
                print(diff_p)
                print(
                    "#######################################################")

            print()
            print("#######################################################")
            print("end of single point calculation for the " + str(i) +
                  "-th moment expanded state")
            print("#######################################################")
            print()
            print(
                "#########################################################################################################################"
            )
            print()
    sys.stdout = original_stdout
    print(
        "post processing of response densities obtained by the external potential"
    )
    diff_dens_list = np.array(diff_dens_list)
    diff_dens_list2 = np.copy(diff_dens_list)
    #print(diff_dens_list.shape, dip_mat.shape)
    #print(
    dip_mat2 = np.copy(dip_mat)
    tilde_mom = diff_dens_list[np.newaxis, :, :, :] * dip_mat[:,
                                                              np.newaxis, :, :]
    tilde_mom = tilde_mom.sum(axis=(2, 3))
    print()
    print("#######################################################")
    print(
        "moment matrix of response densities obtained by the electron density difference of  single point calculation with and without an external potential "
    )
    print(tilde_mom * 10000)
    print("#######################################################")
    tilde_mom = diff_dens_list2[
        np.newaxis, :, :, :] * dip_mat2[:, np.newaxis, :, :]
    tilde_mom = tilde_mom.sum(axis=(2, 3))
    tilde_mom = (tilde_mom + tilde_mom.T) / 2
    chol_left = np.linalg.cholesky(tilde_mom * -1)
    #chol_right = chol_left
    chol_right = chol_left.T
    inv_chol_right = np.linalg.inv(chol_right)
    print("#######################################################")
    print("MES moment  matrix from choleky decompostion:")
    print("#######################################################")
    print(chol_right * 10000)
    #print()
    #print(inv_chol_right)
    mom_states = np.zeros(diff_dens_list2.shape)
    #for k in range(3)
    for i in range(3):
        for j in range(3):
            #mom_states[i] = inv_chol_right[i,j] * diff_dens_list[j]
            mom_states[i] += inv_chol_right[j, i] * diff_dens_list2[j]
    print("MES moment matrix obtaned by integrating over MES")
    #mom_mat = mom_states[np.newaxis,:,:,:] * dip_mat2[:, np.newaxis ,:,:]
    mom_mat = dip_mat2[np.newaxis, :, :, :] * mom_states[:, np.newaxis, :, :]
    mom_mat = mom_mat.sum(axis=(2, 3))
    print(mom_mat * 10000)

    #tilde_mom = diff_dens_list2[np.newaxis, :,:,:] * dip_mat2[:, np.newaxis ,:,:]
    #tilde_mom = tilde_mom.sum(axis = (2,3))
    #print("HIST")
    #print(tilde_mom*10000)
    print()
    print("saving density matrix of moment expanded states ... ")
    for j in range(mom_states.shape[0]):
        fn_mes = "mes_" + str(j + 1)
        np.savetxt(fn_mes, mom_states[j])
        print(fn_mes)