Ejemplo n.º 1
0
    def transform_(cint_coeff, orig_bas, bas_to_append, env, pexp, pcoeff):
        np1, nc1 = cint_coeff.shape
        l = orig_bas[gto.ANG_OF]
        if cell.cart:
            degen = (l + 1) * (l + 2) // 2
        else:
            degen = 2 * l + 1
        if np1 >= nc1:
            bas = orig_bas.copy()
            bas[NPRIM_OF] = np1
            bas[PTR_EXP] = pexp
            bas[PTR_COEFF] = pcoeff
            bas_to_append.append(bas)
            coeff = np.eye(nc1 * degen)
        else:
            bas = np.repeat(orig_bas.copy()[None, :], np1, axis=0)
            bas[:, NPRIM_OF] = 1
            bas[:, NCTR_OF] = 1
            bas[:, PTR_EXP] = pexp + np.arange(np1)
            bas[:, PTR_COEFF] = pcoeff + np.arange(np1)
            bas_to_append.extend(bas)

            exps = _env[pexp:pexp + np1]
            cs = gto.gto_norm(l, exps)
            _env[pcoeff:pcoeff + np1] = cs
            unit_coeff = np.eye(degen)
            coeff = np.einsum('p,mn,pc->pmcn', 1 / cs, unit_coeff, cint_coeff)
            coeff = coeff.reshape(np1 * degen, nc1 * degen)
        return coeff
Ejemplo n.º 2
0
def integral_one_gaussian_from_overlap(mol):
    """
  Outputs the integral of only one Gaussian
  using as second Gaussian in <i|j> an 1s
  basis funtion of an He atom with
  alpha=1e-15 and coeff=1.00000. The result
  is divided by the norm of the He function.
  """
    # Creating auxiliar Molecule
    intmol = gto.Mole()
    intmol.atom = '''He  0. 0. 0.'''
    intmol.basis = He_flat_basis
    intmol.build()

    # Merging molecules
    atm_x, bas_x, env_x = gto.conc_env(intmol._atm, intmol._bas, intmol._env,
                                       mol._atm, mol._bas, mol._env)
    # Computing the overlap
    HF_partial = gto.moleintor.getints('cint1e_ovlp_sph',
                                       atm_x,
                                       bas_x,
                                       env_x,
                                       comp=1,
                                       hermi=0,
                                       aosym='s1',
                                       out=None)
    return np.hstack(HF_partial[:, :1])[1:] / gto.gto_norm(0, He_exp_flt)
Ejemplo n.º 3
0
def hellmann_feynman_df(mol, ia):
    """
  Outputs the integral
        Z_I*<i|(r-R_I)/|r-R_I|^3|j>
  of only one Gaussian using as second Gaussian
  an 1s basis funtion of an He atom with
  alpha=1e-15 and coeff=1.00000. The result
  is divided by the norm of the He function.
  """

    # Creating auxiliar Molecule
    intmol = gto.Mole()
    intmol.atom = '''He  0. 0. 0.'''
    intmol.basis = He_flat_basis
    intmol.build()

    # Merging molecules
    atm_x, bas_x, env_x = gto.conc_env(intmol._atm, intmol._bas, intmol._env,\
                                          mol._atm,    mol._bas,    mol._env)

    PTR_RINV_ORIG = 4
    env_x[PTR_RINV_ORIG:PTR_RINV_ORIG + 3] = mol.atom_coord(ia)
    HF_partial = gto.moleintor.getints('cint1e_drinv_sph',
                                       atm_x,
                                       bas_x,
                                       env_x,
                                       comp=3,
                                       hermi=0,
                                       aosym='s1',
                                       out=None)

    return -mol.atom_charge(ia)*\
            np.hstack(HF_partial[:,:,:1])[1:]/gto.gto_norm(0,He_exp_flt)
Ejemplo n.º 4
0
def integral_one_gaussian_polarization(mol):
    """
  Outputs the integral <i|r|j> with the only-one-Gaussian trick
  using as second Gaussian an 1s basis funtion of an He atom with
  alpha=1e-15 and coeff=1.00000. The result is divided by the
  norm of the 'dummy' He function.
  """
    # Creating auxiliar Molecule
    intmol = gto.Mole()
    intmol.atom = '''He  0. 0. 0.'''
    intmol.basis = He_flat_basis
    intmol.build()

    # Merging molecules
    atm_x, bas_x, env_x = gto.conc_env(intmol._atm, intmol._bas, intmol._env,
                                       mol._atm, mol._bas, mol._env)
    # Computing the overlap
    PTR_COMMON_ORIG = 1
    env_x[PTR_COMMON_ORIG:PTR_COMMON_ORIG + 3] = (
        0., 0., 0.)  #(mol.atom_coord(1)-mol.atom_coord(0))/2.
    #mol.set_common_orig((1.,0.,0.))
    HF_partial = gto.moleintor.getints('cint1e_r_sph',
                                       atm_x,
                                       bas_x,
                                       env_x,
                                       comp=3,
                                       hermi=0,
                                       aosym='s1',
                                       out=None)

    return np.hstack(HF_partial[:, :, :1])[1:] / gto.gto_norm(0, He_exp_flt)
Ejemplo n.º 5
0
def fake_cell_vnl(cell):
    '''Generate fake cell for V_{nl}.

    gaussian function p_i^l Y_{lm}
    '''
    fake_env = [cell.atom_coords().ravel()]
    fake_atm = cell._atm.copy()
    fake_atm[:, gto.PTR_COORD] = numpy.arange(0, cell.natm * 3, 3)
    ptr = cell.natm * 3
    fake_bas = []
    hl_blocks = []
    for ia in range(cell.natm):
        if cell.atom_charge(ia) == 0:  # pass ghost atoms
            continue

        symb = cell.atom_symbol(ia)
        if symb in cell._pseudo:
            pp = cell._pseudo[symb]
            # nproj_types = pp[4]
            for l, (rl, nl, hl) in enumerate(pp[5:]):
                if nl > 0:
                    alpha = .5 / rl**2
                    norm = gto.gto_norm(l, alpha)
                    fake_env.append([alpha, norm])
                    fake_bas.append([ia, l, 1, 1, 0, ptr, ptr + 1, 0])

                    #
                    # Function p_i^l (PRB, 58, 3641 Eq 3) is (r^{2(i-1)})^2 square normalized to 1.
                    # But here the fake basis is square normalized to 1.  A factor ~ p_i^l / p_1^l
                    # is attached to h^l_ij (for i>1,j>1) so that (factor * fake-basis * r^{2(i-1)})
                    # is normalized to 1.  The factor is
                    #       r_l^{l+(4-1)/2} sqrt(Gamma(l+(4-1)/2))      sqrt(Gamma(l+3/2))
                    #     ------------------------------------------ = ----------------------------------
                    #      r_l^{l+(4i-1)/2} sqrt(Gamma(l+(4i-1)/2))     sqrt(Gamma(l+2i-1/2)) r_l^{2i-2}
                    #
                    fac = numpy.array(
                        [_PLI_FAC[l, i] / rl**(i * 2) for i in range(nl)])
                    hl = numpy.einsum('i,ij,j->ij', fac, numpy.asarray(hl),
                                      fac)
                    hl_blocks.append(hl)
                    ptr += 2

    fakecell = copy.copy(cell)
    fakecell._atm = numpy.asarray(fake_atm, dtype=numpy.int32)
    fakecell._bas = numpy.asarray(fake_bas, dtype=numpy.int32)
    fakecell._env = numpy.asarray(numpy.hstack(fake_env), dtype=numpy.double)
    return fakecell, hl_blocks
Ejemplo n.º 6
0
def fake_cell_vnl(cell):
    '''Generate fake cell for V_{nl}.

    gaussian function p_i^l Y_{lm}
    '''
    fake_env = [cell.atom_coords().ravel()]
    fake_atm = cell._atm.copy()
    fake_atm[:,gto.PTR_COORD] = numpy.arange(0, cell.natm*3, 3)
    ptr = cell.natm * 3
    fake_bas = []
    hl_blocks = []
    for ia in range(cell.natm):
        if cell.atom_charge(ia) == 0:  # pass ghost atoms
            continue

        symb = cell.atom_symbol(ia)
        if symb in cell._pseudo:
            pp = cell._pseudo[symb]
            nproj_types = pp[4]
            for l, (rl, nl, hl) in enumerate(pp[5:]):
                if nl > 0:
                    alpha = .5 / rl**2
                    norm = gto.gto_norm(l, alpha)
                    fake_env.append([alpha, norm])
                    fake_bas.append([ia, l, 1, 1, 0, ptr, ptr+1, 0])
# Function p_i^l (PRB, 58, 3641 Eq 3) is (r^{2(i-1)})^2 square normalized to 1.
# But here the fake basis is square normalized to 1.  A factor ~ p_i^l / p_1^l
# is attached to h^l_ij (for i>1,j>1) so that (factor * fake-basis * r^{2(i-1)})
# is normalized to 1.  The factor is
#       r_l^{l+(4-1)/2} sqrt(Gamma(l+(4-1)/2))      sqrt(Gamma(l+3/2))
#     ------------------------------------------ = ----------------------------------
#      r_l^{l+(4i-1)/2} sqrt(Gamma(l+(4i-1)/2))     sqrt(Gamma(l+2i-1/2)) r_l^{2i-2}
                    fac = numpy.array([_PLI_FAC[l,i]/rl**(i*2) for i in range(nl)])
                    hl = numpy.einsum('i,ij,j->ij', fac, numpy.asarray(hl), fac)
                    hl_blocks.append(hl)
                    ptr += 2

    fakecell = copy.copy(cell)
    fakecell._atm = numpy.asarray(fake_atm, dtype=numpy.int32)
    fakecell._bas = numpy.asarray(fake_bas, dtype=numpy.int32)
    fakecell._env = numpy.asarray(numpy.hstack(fake_env), dtype=numpy.double)
    #fakecell.nimgs = [2]*3
    return fakecell, hl_blocks
Ejemplo n.º 7
0
  mol.atom =molstr
  mol.basis = '631g'
  mol.build()

  F11=force_en_1Gz(2.02525091,mol.atom_coord(0),
                              mol.atom_coord(1),1)*1.000000
  F2=force_nn_1Gz(mol.atom_coord(0),
                  mol.atom_coord(1),1)
  F1=0.3570601*F11
  F_Total=F1+F2

  print '\nF_EN  = %12.6f' % (F1)
  print   'F_NN  = %12.6f' % (F2)
  print   'F_Tot = %12.6f' % (F_Total)
  print   'Norm  = %12.6f' % (np.power(np.pi/2.0252509,3/2.)*0.3570601*3.5447)
  print   'Norm  = %12.6f' % (gto.gto_norm(0,2.0252509)*0.3570601*3.5447)


  print '''
=====Example 2:=====
  '''

  mol.basis = 'sto3g'
    

  F11=force_en_1Gz(15.6752927,mol.atom_coord(0),
                              mol.atom_coord(1),1)*0.0186886
  F12=force_en_1Gz(3.6063578 ,mol.atom_coord(0),
                              mol.atom_coord(1),1)*0.0631670
  F13=force_en_1Gz(1.2080016 ,mol.atom_coord(0),
                              mol.atom_coord(1),1)*0.1204609
Ejemplo n.º 8
0
     The integral cint1e_ovlp_sph <He_aux|H_orbital> have to
     give N/M^2, where N and M are defined below
     in the example (M1, M2, M3, N1, N2 and N3)
     N is the norm of the Gaussian \int exp(-2*alpha*r^2)dr.

     The basis xxx set for He is
     H    S
          1e-15                  1.00000000
     The sto-3g basis set for H is
     H    S
          3.42525091             0.15432897
          0.62391373             0.53532814
          0.16885540             0.44463454
  '''
    # Computing the norms:
    N1 = gto.gto_norm(0, 3.42525091)
    M1 = gto.gto_norm(0, 3.42525091 / 2)
    N2 = gto.gto_norm(0, 0.62391373)
    M2 = gto.gto_norm(0, 0.62391373 / 2)
    N3 = gto.gto_norm(0, 0.16885540)
    M3 = gto.gto_norm(0, 0.16885540 / 2)
    print 'From the Norms M,N:', 0.15432897 * N1 / M1 / M1 + 0.53532814 * N2 / M2 / M2 + 0.44463454 * N3 / M3 / M3
    print 'From the integrals:', integral_one_gaussian_from_overlap(mol)[0]
    print ''

    print '''
=====Example 3:=====
  '''

    # Creating auxiliar Molecule
    intmol = gto.Mole()
Ejemplo n.º 9
0
def write_mo(fout, mol, mo_coeff, mo_energy=None, mo_occ=None):
    nmo = mo_coeff.shape[1]
    mo_cart = []
    centers = []
    types = []
    exps = []
    p0 = 0
    for ib in range(mol.nbas):
        ia = mol.bas_atom(ib)
        l = mol.bas_angular(ib)
        es = mol.bas_exp(ib)
        c = numpy.einsum('pi,p->pi', mol.bas_ctr_coeff(ib),
                         1 / gto.gto_norm(l, es))
        np, nc = c.shape
        nd = nc * (2 * l + 1)
        mosub = mo_coeff[p0:p0 + nd].reshape(-1, nc, nmo)
        c2s = gto.cart2sph(l)
        mosub = numpy.einsum('yki,cy,pk->pci', mosub, c2s, c)
        mo_cart.append(mosub.reshape(-1, nmo))

        for t in TYPE_MAP[l]:
            types.append([t] * np)
        ncart = gto.len_cart(l)
        exps.extend([es] * ncart)
        centers.extend([ia + 1] * (np * ncart))
        p0 += nd
    mo_cart = numpy.vstack(mo_cart)
    centers = numpy.hstack(centers)
    types = numpy.hstack(types)
    exps = numpy.hstack(exps)
    nprim, nmo = mo_cart.shape

    fout.write('title line\n')
    fout.write(
        'GAUSSIAN            %3d MOL ORBITALS    %3d PRIMITIVES      %3d NUCLEI\n'
        % (mo_cart.shape[1], mo_cart.shape[0], mol.natm))
    for ia in range(mol.natm):
        x, y, z = mol.atom_coord(ia)
        fout.write(
            '%-4s %-4d (CENTRE%3d) %12.8f %12.8f %12.8f  CHARGE = %.1f\n' %
            (mol.atom_pure_symbol(ia), ia, ia, x, y, z, mol.atom_charge(ia)))
    for i0, i1 in lib.prange(0, nprim, 20):
        fout.write('CENTRE ASSIGNMENTS  %s\n' %
                   ''.join('%3d' % x for x in centers[i0:i1]))
    for i0, i1 in lib.prange(0, nprim, 20):
        fout.write('TYPE ASSIGNMENTS    %s\n' % ''.join('%3d' % x
                                                        for x in types[i0:i1]))
    for i0, i1 in lib.prange(0, nprim, 5):
        fout.write('EXPONENTS %s\n' % ' '.join('%14.7E' % x
                                               for x in exps[i0:i1]))

    for k in range(nmo):
        mo = mo_cart[:, k]
        if mo_energy is None or mo_occ is None:
            fout.write('CANMO %d\n' (k, mo_occ[k], mo_energy[k]))
        else:
            fout.write(
                'MO  %-4d                  OCC NO = %12.8f ORB. ENERGY = %12.8f\n'
                % (k, mo_occ[k], mo_energy[k]))
        for i0, i1 in lib.prange(0, nprim, 5):
            fout.write('%s\n' % ' '.join('%15.8E' % x for x in mo[i0:i1]))