Esempio n. 1
0
def project_mo_r2r(mol1, mo1, mol2):
    nbas1 = len(mol1._bas)
    nbas2 = len(mol2._bas)
    atm, bas, env = mole.conc_env(mol2._atm, mol2._bas, mol2._env,
                                  mol1._atm, mol1._bas, mol1._env)
    bras = kets = range(nbas2)
    s22 = moleintor.getints('cint1e_ovlp', atm, bas, env,
                            bras, kets, comp=1, hermi=1)
    t22 = moleintor.getints('cint1e_spsp', atm, bas, env,
                            bras, kets, comp=1, hermi=1)
    bras = range(nbas2)
    kets = range(nbas2, nbas1+nbas2)
    s21 = moleintor.getints('cint1e_ovlp', atm, bas, env,
                            bras, kets, comp=1, hermi=0)
    t21 = moleintor.getints('cint1e_spsp', atm, bas, env,
                            bras, kets, comp=1, hermi=0)
    n2c = s21.shape[1]
    pl = numpy.linalg.solve(s22, s21)
    ps = numpy.linalg.solve(t22, t21)
    return numpy.vstack((numpy.dot(pl, mo1[:n2c]),
                         numpy.dot(ps, mo1[n2c:])))
Esempio n. 2
0
def intor_cross(intor, cell1, cell2, comp=1, hermi=0, kpts=None, kpt=None):
    r'''1-electron integrals from two cells like

    .. math::

        \langle \mu | intor | \nu \rangle, \mu \in cell1, \nu \in cell2
    '''
    if kpts is None:
        if kpt is not None:
            kpts_lst = np.reshape(kpt, (1, 3))
        else:
            kpts_lst = np.zeros((1, 3))
    else:
        kpts_lst = np.reshape(kpts, (-1, 3))
    nkpts = len(kpts_lst)

    atm, bas, env = conc_env(cell1._atm, cell1._bas, cell1._env, cell2._atm,
                             cell2._bas, cell2._env)
    atm = np.asarray(atm, dtype=np.int32)
    bas = np.asarray(bas, dtype=np.int32)
    env = np.asarray(env, dtype=np.double)
    natm = len(atm)
    nbas = len(bas)
    shls_slice = (0, cell1.nbas, cell1.nbas, nbas)
    ao_loc = moleintor.make_loc(bas, intor)
    ni = ao_loc[shls_slice[1]] - ao_loc[shls_slice[0]]
    nj = ao_loc[shls_slice[3]] - ao_loc[shls_slice[2]]
    out = [
        np.zeros((ni, nj, comp), order='F', dtype=np.complex128)
        for k in range(nkpts)
    ]
    out_ptrs = (ctypes.c_void_p *
                nkpts)(*[x.ctypes.data_as(ctypes.c_void_p) for x in out])

    if hermi == 0:
        aosym = 's1'
    else:
        aosym = 's2'
    if '2c2e' in intor:
        fill = getattr(libpbc, 'PBCnr2c2e_fill_' + aosym)
    else:
        assert ('2e' not in intor)
        fill = getattr(libpbc, 'PBCnr2c_fill_' + aosym)

    fintor = getattr(moleintor.libcgto, intor)
    intopt = lib.c_null_ptr()

    Ls = cell1.get_lattice_Ls(rcut=max(cell1.rcut, cell2.rcut))
    expLk = np.asarray(np.exp(1j * np.dot(Ls, kpts_lst.T)), order='C')
    xyz = np.asarray(cell2.atom_coords(), order='C')
    ptr_coords = np.asarray(atm[cell1.natm:, mole.PTR_COORD],
                            dtype=np.int32,
                            order='C')
    drv = libpbc.PBCnr2c_drv
    drv(fintor, fill, out_ptrs, xyz.ctypes.data_as(ctypes.c_void_p),
        ptr_coords.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(cell2.natm),
        Ls.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(len(Ls)),
        expLk.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(nkpts),
        ctypes.c_int(comp), (ctypes.c_int * 4)(*(shls_slice[:4])),
        ao_loc.ctypes.data_as(ctypes.c_void_p), intopt,
        atm.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(natm),
        bas.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(nbas),
        env.ctypes.data_as(ctypes.c_void_p))

    def trans(out):
        out = out.transpose(2, 0, 1)
        if hermi == lib.HERMITIAN:
            # GTOint2c fills the upper triangular of the F-order array.
            idx = np.triu_indices(ni)
            for i in range(comp):
                out[i, idx[1], idx[0]] = out[i, idx[0], idx[1]].conj()
        elif hermi == lib.ANTIHERMI:
            idx = np.triu_indices(ni)
            for i in range(comp):
                out[i, idx[1], idx[0]] = -out[i, idx[0], idx[1]].conj()
        elif hermi == lib.SYMMETRIC:
            idx = np.triu_indices(ni)
            for i in range(comp):
                out[i, idx[1], idx[0]] = out[i, idx[0], idx[1]]
        if comp == 1:
            out = out.reshape(ni, nj)
        return out

    for k, kpt in enumerate(kpts_lst):
        if abs(kpt).sum() < 1e-9:  # gamma_point
            out[k] = np.asarray(trans(out[k].real), order='C')
        else:
            out[k] = np.asarray(trans(out[k]), order='C')
    if kpts is None or np.shape(kpts) == (3, ):
        # A single k-point
        out = out[0]
    return out
Esempio n. 3
0
def intor_cross(intor, cell1, cell2, comp=1, hermi=0, kpts=None, kpt=None):
    r'''1-electron integrals from two cells like

    .. math::

        \langle \mu | intor | \nu \rangle, \mu \in cell1, \nu \in cell2
    '''
    if kpts is None:
        if kpt is not None:
            kpts_lst = np.reshape(kpt, (1,3))
        else:
            kpts_lst = np.zeros((1,3))
    else:
        kpts_lst = np.reshape(kpts, (-1,3))
    nkpts = len(kpts_lst)

    atm, bas, env = conc_env(cell1._atm, cell1._bas, cell1._env,
                             cell2._atm, cell2._bas, cell2._env)
    atm = np.asarray(atm, dtype=np.int32)
    bas = np.asarray(bas, dtype=np.int32)
    env = np.asarray(env, dtype=np.double)
    natm = len(atm)
    nbas = len(bas)
    shls_slice = (0, cell1.nbas, cell1.nbas, nbas)
    ao_loc = moleintor.make_loc(bas, intor)
    ni = ao_loc[shls_slice[1]] - ao_loc[shls_slice[0]]
    nj = ao_loc[shls_slice[3]] - ao_loc[shls_slice[2]]
    out = [np.zeros((ni,nj,comp), order='F', dtype=np.complex128)
           for k in range(nkpts)]
    out_ptrs = (ctypes.c_void_p*nkpts)(
            *[x.ctypes.data_as(ctypes.c_void_p) for x in out])

    if hermi == 0:
        aosym = 's1'
    else:
        aosym = 's2'
    if '2c2e' in intor:
        fill = getattr(libpbc, 'PBCnr2c2e_fill_'+aosym)
    else:
        assert('2e' not in intor)
        fill = getattr(libpbc, 'PBCnr2c_fill_'+aosym)

    fintor = moleintor._fpointer(intor)
    intopt = lib.c_null_ptr()

    nimgs = np.max((cell1.nimgs, cell2.nimgs), axis=0)
    Ls = np.asarray(cell1.get_lattice_Ls(nimgs), order='C')
    expLk = np.asarray(np.exp(1j*np.dot(Ls, kpts_lst.T)), order='C')
    xyz = np.asarray(cell2.atom_coords(), order='C')
    ptr_coords = np.asarray(atm[cell1.natm:,mole.PTR_COORD],
                            dtype=np.int32, order='C')
    drv = libpbc.PBCnr2c_drv
    drv(fintor, fill, out_ptrs, xyz.ctypes.data_as(ctypes.c_void_p),
        ptr_coords.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(cell2.natm),
        Ls.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(len(Ls)),
        expLk.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(nkpts),
        ctypes.c_int(comp), (ctypes.c_int*4)(*(shls_slice[:4])),
        ao_loc.ctypes.data_as(ctypes.c_void_p), intopt,
        atm.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(natm),
        bas.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(nbas),
        env.ctypes.data_as(ctypes.c_void_p))

    def trans(out):
        out = out.transpose(2,0,1)
        if hermi == lib.HERMITIAN:
            # GTOint2c fills the upper triangular of the F-order array.
            idx = np.triu_indices(ni)
            for i in range(comp):
                out[i,idx[1],idx[0]] = out[i,idx[0],idx[1]].conj()
        elif hermi == lib.ANTIHERMI:
            idx = np.triu_indices(ni)
            for i in range(comp):
                out[i,idx[1],idx[0]] = -out[i,idx[0],idx[1]].conj()
        elif hermi == lib.SYMMETRIC:
            idx = np.triu_indices(ni)
            for i in range(comp):
                out[i,idx[1],idx[0]] = out[i,idx[0],idx[1]]
        if comp == 1:
            out = out.reshape(ni,nj)
        return out

    for k, kpt in enumerate(kpts_lst):
        if abs(kpt).sum() < 1e-9:  # gamma_point
            out[k] = np.asarray(trans(out[k].real), order='C')
        else:
            out[k] = np.asarray(trans(out[k]), order='C')
    if kpts is None or np.shape(kpts) == (3,):
# A single k-point
        out = out[0]
    return out
Esempio n. 4
0
File: cell.py Progetto: pulkin/pyscf
def intor_cross(intor, cell1, cell2, comp=1, hermi=0, kpts=None, kpt=None):
    r'''1-electron integrals from two cells like

    .. math::

        \langle \mu | intor | \nu \rangle, \mu \in cell1, \nu \in cell2
    '''
    intor = moleintor.ascint3(intor)
    if kpts is None:
        if kpt is not None:
            kpts_lst = np.reshape(kpt, (1, 3))
        else:
            kpts_lst = np.zeros((1, 3))
    else:
        kpts_lst = np.reshape(kpts, (-1, 3))
    nkpts = len(kpts_lst)

    atm, bas, env = conc_env(cell1._atm, cell1._bas, cell1._env, cell2._atm,
                             cell2._bas, cell2._env)
    atm = np.asarray(atm, dtype=np.int32)
    bas = np.asarray(bas, dtype=np.int32)
    env = np.asarray(env, dtype=np.double)
    natm = len(atm)
    nbas = len(bas)
    shls_slice = (0, cell1.nbas, cell1.nbas, nbas)
    ao_loc = moleintor.make_loc(bas, intor)
    ni = ao_loc[shls_slice[1]] - ao_loc[shls_slice[0]]
    nj = ao_loc[shls_slice[3]] - ao_loc[shls_slice[2]]
    out = np.empty((nkpts, comp, ni, nj), dtype=np.complex128)

    if hermi == 0:
        aosym = 's1'
    else:
        aosym = 's2'
    fill = getattr(libpbc, 'PBCnr2c_fill_k' + aosym)
    fintor = getattr(moleintor.libcgto, intor)
    intopt = lib.c_null_ptr()

    Ls = cell1.get_lattice_Ls(rcut=max(cell1.rcut, cell2.rcut))
    expkL = np.asarray(np.exp(1j * np.dot(kpts_lst, Ls.T)), order='C')
    drv = libpbc.PBCnr2c_drv
    drv(fintor, fill, out.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(nkpts),
        ctypes.c_int(comp), ctypes.c_int(len(Ls)),
        Ls.ctypes.data_as(ctypes.c_void_p),
        expkL.ctypes.data_as(ctypes.c_void_p),
        (ctypes.c_int * 4)(*(shls_slice[:4])),
        ao_loc.ctypes.data_as(ctypes.c_void_p), intopt,
        atm.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(natm),
        bas.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(nbas),
        env.ctypes.data_as(ctypes.c_void_p))

    mat = []
    for k, kpt in enumerate(kpts_lst):
        v = out[k]
        if hermi != 0:
            for ic in range(comp):
                lib.hermi_triu(v[ic], hermi=hermi, inplace=True)
        if comp == 1:
            v = v[0]
        if abs(kpt).sum() < 1e-9:  # gamma_point
            v = v.real
        mat.append(v)

    if kpts is None or np.shape(kpts) == (3, ):  # A single k-point
        mat = mat[0]
    return mat