Exemplo n.º 1
0
def main():
    xyzfile = sys.argv[1]
    state_id = []
    for i in range(2, len(sys.argv)):
        state_id.append(int(sys.argv[i]) - 1)

    mol = readmol(xyzfile, qm_config.basis)
    coeff = np.load(xyzfile + '.mo.npy')
    X = np.load(xyzfile + '.X.npy')
    occ = mol.nelectron // 2

    for i in range(len(state_id)):
        x = X[state_id[i]]
        hole_mo = np.dot(x, x.T)
        part_mo = np.dot(x.T, x)
        hole_ao = mo2ao(hole_mo, coeff[:, :occ])
        part_ao = mo2ao(part_mo, coeff[:, occ:])
        hole_coulomb = np.array([compute_j(mol, hole_ao)])
        part_coulomb = np.array([compute_j(mol, part_ao)])
        np.savetxt(xyzfile + ".st" + str(i + 1) + "_dm_hole.dat", hole_ao)
        np.savetxt(xyzfile + ".st" + str(i + 1) + "_dm_part.dat", part_ao)
        np.savetxt(xyzfile + ".st" + str(i + 1) + "_coulomb_hole.dat",
                   hole_coulomb)
        np.savetxt(xyzfile + ".st" + str(i + 1) + "_coulomb_part.dat",
                   part_coulomb)
def main():
    xyzfile = sys.argv[1]
    mol = readmol(xyzfile, qm_config.basis)
    try:
        dm0 = np.loadtxt(xyzfile + '.dm.dat')
        (mf, dm) = do_scf(mol, qm_config.func, dm0)
    except:
        (mf, dm) = do_scf(mol, qm_config.func)
        coulomb = np.array([compute_j(mf, dm)])
        np.savetxt(xyzfile + ".coulomb.dat", coulomb)
        np.savetxt(xyzfile + '.dm.dat', dm)
        np.save(xyzfile + '.mo.npy', mf.mo_coeff)
    td = do_ci(mf, qm_config.nstates)
    X = np.sqrt(2.0) * np.array([xy[0] for xy in td.xy])
    np.save(xyzfile + '.X.npy', X)
Exemplo n.º 3
0
def main():
    xyz_file = sys.argv[1]
    frag_file = sys.argv[2]
    hole_file = sys.argv[3]
    part_file = sys.argv[4]

    # load molecule
    mol = readmol(xyz_file, qm_config.basis2)
    # load fragment definition
    fragments = readfrag(frag_file)
    # load fields
    hole = np.loadtxt(hole_file)
    part = np.loadtxt(part_file)

    # construct integration grid
    g = dft.gen_grid.Grids(mol)
    g.level = qm_config.grid_level
    g.build()

    # load atomic DMs
    dm_atoms = {}
    for q in qm_config.elements:
        dm_atoms[q] = np.load(qm_config.path_sph + q + '.npy')

    # compute atomic weights
    h_weights = hirshfeld_weights(mol, g.coords, dm_atoms)
    tot_weights = np.einsum('p,ap->ap', g.weights, h_weights)

    # atom partitioning
    ao = dft.numint.eval_ao(mol, g.coords)
    omega_hole_atom = atom_contributions(hole, ao, tot_weights)
    omega_part_atom = atom_contributions(part, ao, tot_weights)

    # fragment partitioning
    omega_hole_frag = np.zeros(len(fragments))
    omega_part_frag = np.zeros_like(omega_hole_frag)
    for i, k in enumerate(fragments):
        omega_hole_frag[i] = omega_hole_atom[k].sum()
        omega_part_frag[i] = omega_part_atom[k].sum()

    # normalized fragment partitioning
    tot_hole = omega_hole_frag.sum()  # should be close to 1
    tot_part = omega_part_frag.sum()  # should be close to 1
    omega_hole_frag *= 100.0 / tot_hole
    omega_part_frag *= 100.0 / tot_part

    with np.printoptions(formatter={'float': '{:6.3f}'.format}):
        print(xyz_file, 'H', omega_hole_frag, 'P', omega_part_frag)
def main():
    xyzfile = sys.argv[1]
    hole = np.loadtxt(sys.argv[2])
    part = np.loadtxt(sys.argv[3])
    mol = readmol(xyzfile, qm_config.basis2)

    hole_N, hole_r, hole_r2 = r2_c(hole, mol)
    part_N, part_r, part_r2 = r2_c(part, mol)

    dist = np.linalg.norm(hole_r - part_r)
    hole_extent = np.sqrt(hole_r2 - hole_r @ hole_r)
    part_extent = np.sqrt(part_r2 - part_r @ part_r)

    print(
        xyzfile, "\tdist = %e  hole_size = %e  part_size = %e" %
        (dist, hole_extent, part_extent))
Exemplo n.º 5
0
def main():
    xyzfile = sys.argv[1]
    state_id = int(sys.argv[2]) - 1
    sign = float(sys.argv[3])

    mol = readmol(xyzfile, qm_config.basis)
    coeff = np.load(xyzfile + '.mo.npy')
    X = np.load(xyzfile + '.X.npy')
    occ = mol.nelectron // 2
    x_mo = X[state_id]
    x_ao = coeff[:, :occ] @ x_mo @ coeff[:, occ:].T

    with mol.with_common_orig((0, 0, 0)):
        ao_dip = mol.intor_symmetric('int1e_r', comp=3)
    el_dip = np.einsum('xij,ji->x', ao_dip, x_ao)
    if sign < 0:
        el_dip *= -1.0

    with np.printoptions(formatter={'float': '{: .5f}'.format}):
        print(xyzfile, el_dip)
Exemplo n.º 6
0
def main():
    xyzfile = sys.argv[1]
    state_id = [int(sys.argv[2]) - 1, int(sys.argv[3]) - 1]
    azo_id = [int(sys.argv[4]) - 1, int(sys.argv[5]) - 1]

    mol = readmol(xyzfile, qm_config.basis)
    coeff = np.load(xyzfile + '.mo.npy')
    X = np.load(xyzfile + '.X.npy')

    auxmol = df.make_auxmol(mol, qm_config.basis2)
    eri3c = eri_pqi(mol, auxmol)
    eri2c = auxmol.intor('int2c2e_sph')

    occ = mol.nelectron // 2
    azo_ao = auxmol.offset_ao_by_atom()[azo_id[0]:azo_id[1] + 1, 2:]
    q = number_of_electrons_vec(auxmol)

    for i, state in enumerate(state_id):

        x_mo = X[state]
        x_ao = coeff[:, :occ] @ x_mo @ coeff[:, occ:].T

        coulomb = compute_j(mol, x_ao)
        b = np.einsum('ijp,ij->p', eri3c, x_ao)
        c = np.linalg.solve(eri2c, b)
        error = coulomb - np.dot(c, b)

        cq = c * q
        n = sum(cq)
        n1 = sum(cq[azo_ao[0, 0]:azo_ao[0, 1]])
        n2 = sum(cq[azo_ao[1, 0]:azo_ao[1, 1]])
        if (n1 < 0.0):
            c = -c

        print(
            xyzfile, 'state' + str(i + 1),
            "Error: % .3e Eh ( %.1e %%)  Electrons: % .1e total, % .2e left N, % .2e right N"
            % (error, error / coulomb * 100.0, n, n1, n2))
        np.savetxt(xyzfile + '.st' + str(i + 1) + '_transition_fit.dat', c)
Exemplo n.º 7
0
def main():
    xyzfile = sys.argv[1]
    mol = readmol(xyzfile, qm_config.basis)
    auxmol = df.make_auxmol(mol, qm_config.basis2)

    eri3c = eri_pqi(mol, auxmol)
    eri2c = auxmol.intor('int2c2e_sph')
    np.save(xyzfile + '.jmat.npy', eri2c)

    N = mol.nelectron
    files = (('ground', xyzfile + '.coulomb.dat', xyzfile + '.dm.dat', N,
              xyzfile + '.dm_fit.dat'), ('hole_1',
                                         xyzfile + '.st1_coulomb_hole.dat',
                                         xyzfile + '.st1_dm_hole.dat', 1,
                                         xyzfile + '.st1_dm_hole_fit.dat'),
             ('part_1', xyzfile + '.st1_coulomb_part.dat',
              xyzfile + '.st1_dm_part.dat', 1,
              xyzfile + '.st1_dm_part_fit.dat'),
             ('hole_2', xyzfile + '.st2_coulomb_hole.dat',
              xyzfile + '.st2_dm_hole.dat', 1,
              xyzfile + '.st2_dm_hole_fit.dat'),
             ('part_2', xyzfile + '.st2_coulomb_part.dat',
              xyzfile + '.st2_dm_part.dat', 1,
              xyzfile + '.st2_dm_part_fit.dat'))

    for i in files:
        (title, file_coul, file_dm, n_correct, file_out) = i
        dm = np.loadtxt(file_dm)
        ej = np.loadtxt(file_coul)
        b = np.einsum('ijp,ij->p', eri3c, dm)
        c = np.linalg.solve(eri2c, b)
        error = ej - np.dot(c, b)
        n = number_of_electrons(c, auxmol)
        print(
            xyzfile + '\t' + title,
            "Error: % .3e Eh ( %.1e %%)  Electrons: %.3e ( % .1e )" %
            (error, error / ej * 100.0, n, n - n_correct))
        np.savetxt(file_out, c)
def main():
    xyzfile = sys.argv[1]
    hole_D = np.loadtxt(sys.argv[2])
    part_D = np.loadtxt(sys.argv[3])
    mol = readmol(xyzfile, qm_config.basis)

    with mol.with_common_orig((0, 0, 0)):
        ao_r = mol.intor_symmetric('int1e_r', comp=3)
    ao_r2 = mol.intor_symmetric('int1e_r2')
    ao_u = mol.intor_symmetric('int1e_ovlp')

    hole_r = np.einsum('xij,ji->x', ao_r, hole_D)
    part_r = np.einsum('xij,ji->x', ao_r, part_D)
    hole_r2 = np.einsum('ij,ji', ao_r2, hole_D)
    part_r2 = np.einsum('ij,ji', ao_r2, part_D)

    dist = np.linalg.norm(hole_r - part_r)
    hole_extent = np.sqrt(hole_r2 - hole_r @ hole_r)
    part_extent = np.sqrt(part_r2 - part_r @ part_r)

    print(
        xyzfile, "\tdist = %e  hole_size = %e  part_size = %e" %
        (dist, hole_extent, part_extent))
#!/usr/bin/env python3

import sys
import numpy as np
from utils import readmol, r_c
import qm_config

xyzfile = sys.argv[1]
c = np.loadtxt(sys.argv[2])
mol = readmol(xyzfile, qm_config.basis2)
el_dip = r_c(c, mol)
with np.printoptions(formatter={'float': '{: .5f}'.format}):
    print(xyzfile, el_dip)