Exemplo n.º 1
0
/*
 * 1e integrals <i|O|j> with nuclear attraction
 * TODO: add the gaussian nuclear model
 */
FINT CINT1e_nuc_drv(double *opij, CINTEnvVars *envs, double fac,
                   void (*const f_c2s)())
{
        const FINT *shls  = envs->shls;
        const FINT *atm = envs->atm;
        const FINT *bas = envs->bas;
        const double *env = envs->env;
        const FINT i_sh = shls[0];
        const FINT j_sh = shls[1];
        const FINT i_l = envs->i_l;
        const FINT j_l = envs->j_l;
        const FINT i_ctr = envs->i_ctr;
        const FINT j_ctr = envs->j_ctr;
        const FINT nfi = envs->nfi;
        const FINT nfj = envs->nfj;
        const FINT nc = nfi * nfj * i_ctr * j_ctr * envs->ncomp_e1;
        FINT has_value = 0, has_value0;
        FINT ip, jp, nop;
        FINT n;
        double *gctr = malloc(sizeof(double) * nc * envs->ncomp_tensor);
        double *pgctr = gctr;

        CINTdset0(nc * envs->ncomp_tensor, gctr);
        for (n = 0; n < envs->natm; n++) {
                has_value0 = CINT1e_nuc_loop(gctr, envs,
                                             -fabs(atm(CHARGE_OF,n))*fac, n);
                has_value = has_value || has_value0;
        }

        if (f_c2s == c2s_sph_1e) {
                ip = CINTcgto_spheric(i_sh, bas);
                jp = CINTcgto_spheric(j_sh, bas);
                nop = ip * jp;
        } else if (f_c2s == c2s_cart_1e) {
                ip = CINTcgto_cart(i_sh, bas);
                jp = CINTcgto_cart(j_sh, bas);
                nop = ip * jp;
        } else {
                ip = CINTcgto_spinor(i_sh, bas);
                jp = CINTcgto_spinor(j_sh, bas);
                nop = ip * jp * OF_CMPLX;
        }

        if (!has_value) {
                CINTdset0(nop * envs->ncomp_tensor, opij);
        } else {
                for (n = 0; n < envs->ncomp_tensor; n++) {
                        (*f_c2s)(opij, pgctr, shls, bas);
                        opij += nop;
                        pgctr += nc;
                }
        }
        free(gctr);
        return has_value;
}
Exemplo n.º 2
0
void GTO1eintor_spinor(int (*intor)(), double complex *mat, int ncomp, int hermi,
                       int *bralst, int nbra, int *ketlst, int nket,
                       int *atm, int natm, int *bas, int nbas, double *env)
{
        int ish;
        int ilocs[nbra+1];
        int naoi = 0;
        int naoj = 0;
        for (ish = 0; ish < nbra; ish++) {
                ilocs[ish] = naoi;
                naoi += CINTcgto_spinor(bralst[ish], bas);
        }
        ilocs[nbra] = naoi;
        for (ish = 0; ish < nket; ish++) {
                naoj += CINTcgto_spinor(ketlst[ish], bas);
        }

#pragma omp parallel default(none) \
        shared(intor, mat, ncomp, hermi, bralst, nbra, ketlst, nket,\
               atm, natm, bas, nbas, env, naoi, naoj, ilocs) \
        private(ish)
{
        int jsh, jsh1, i, j, i0, j0, icomp;
        int di, dj, iloc, jloc;
        int shls[2];
        double complex *buf = malloc(sizeof(double complex)*NCTRMAX*NCTRMAX*4*ncomp);
        double complex *pmat, *pbuf;
#pragma omp for nowait schedule(dynamic)
        for (ish = 0; ish < nbra; ish++) {
                iloc = ilocs[ish];
                di = CINTcgto_spinor(bralst[ish], bas);
                if (hermi == PLAIN) {
                        jsh1 = nket;
                } else {
                        jsh1 = ish + 1;
                }
                for (jloc = 0, jsh = 0; jsh < jsh1; jsh++, jloc+=dj) {
                        dj = CINTcgto_spinor(ketlst[jsh], bas);
                        shls[0] = bralst[ish];
                        shls[1] = ketlst[jsh];
                        (*intor)(buf, shls, atm, natm, bas, nbas, env);
                        for (icomp = 0; icomp < ncomp; icomp++) {
                                pmat = mat + icomp*naoi*naoj;
                                pbuf = buf + icomp*di*dj;
                                for (i0=iloc, i=0; i < di; i++, i0++) {
                                for (j0=jloc, j=0; j < dj; j++, j0++) {
                                        pmat[i0*naoj+j0] = pbuf[j*di+i];
                                } }
                        }
                }
        }
        free(buf);
}
}
Exemplo n.º 3
0
Arquivo: breit.c Projeto: sunqm/qcint
static int _int2e_breit_drv(double complex *out, int *dims, int *shls,
                            int *atm, int natm, int *bas, int nbas, double *env,
                            CINTOpt *opt, double *cache, int ncomp_tensor,
                            int (*f_gaunt)(), int (*f_gauge_r1)(), int (*f_gauge_r2)())
{
        if (out == NULL) {
                int cache_size1 = (*f_gauge_r1)(NULL, NULL, shls,
                                atm, natm, bas, nbas, env, NULL, cache);
                int cache_size2 = (*f_gauge_r2)(NULL, NULL, shls,
                                atm, natm, bas, nbas, env, NULL, cache);
                return MAX(cache_size1, cache_size2);
        }

        int counts[4];
        counts[0] = CINTcgto_spinor(shls[0], bas);
        counts[1] = CINTcgto_spinor(shls[1], bas);
        counts[2] = CINTcgto_spinor(shls[2], bas);
        counts[3] = CINTcgto_spinor(shls[3], bas);
        int nop = counts[0] * counts[1] * counts[2] * counts[3] * ncomp_tensor;
        double complex *buf = malloc(sizeof(double complex) * nop*2);
        double complex *buf1;
        if (dims == NULL) {
                dims = counts;
                buf1 = out;
        } else {
                buf1 = buf + nop;
        }

        int has_value = (*f_gaunt)(buf1, NULL, shls, atm, natm, bas, nbas, env, NULL, cache);

        int i;
        has_value = ((*f_gauge_r1)(buf, NULL, shls, atm, natm, bas, nbas, env, NULL, cache) ||
                     has_value);
        /* [1/2 gaunt] - [1/2 xxx*\sigma1\dot r1] */
        if (has_value) {
                for (i = 0; i < nop; i++) {
                        buf1[i] = -buf1[i] - buf[i];
                }
        }
        /* ... [- 1/2 xxx*\sigma1\dot(-r2)] */
        has_value = ((*f_gauge_r2)(buf, NULL, shls, atm, natm, bas, nbas, env, NULL, cache) ||
                     has_value);
        if (has_value) {
                for (i = 0; i < nop; i++) {
                        buf1[i] = (buf1[i] + buf[i]) * .5;
                }
        }
        _copy_to_out(out, buf1, dims, counts);
        free(buf);
        return has_value;
}
Exemplo n.º 4
0
void AO2MOr_e1_drv(int (*intor)(), void (*fill)(),
                   void (*ftrans)(), int (*fmmm)(),
                   double complex *eri, double complex *mo_coeff,
                   int klsh_start, int klsh_count, int nkl,
                   int i_start, int i_count, int j_start, int j_count,
                   int ncomp, CINTOpt *cintopt, CVHFOpt *vhfopt, int *tao,
                   int *atm, int natm, int *bas, int nbas, double *env)
{
        int *ao_loc = malloc(sizeof(int)*(nbas+1));
        CINTshells_spinor_offset(ao_loc, bas, nbas);
        ao_loc[nbas] = ao_loc[nbas-1] + CINTcgto_spinor(nbas-1, bas);
        int nao = ao_loc[nbas];
        int nmo = MAX(i_start+i_count, j_start+j_count);
        int i;
        double *mo_r = malloc(sizeof(double) * nao * nmo);
        double *mo_i = malloc(sizeof(double) * nao * nmo);
        for (i = 0; i < nao*nmo; i++) {
                mo_r[i] = creal(mo_coeff[i]);
                mo_i[i] = cimag(mo_coeff[i]);
        }
        struct _AO2MOEnvs envs = {natm, nbas, atm, bas, env, nao,
                                  klsh_start, klsh_count,
                                  i_start, i_count, j_start, j_count,
                                  ncomp, tao, ao_loc, mo_coeff,
                                  mo_r, mo_i, cintopt, vhfopt};

        double complex *eri_ao = malloc(sizeof(double complex)
                                        * nao*nao*nkl*ncomp);
        int ish, kl;
        int (*fprescreen)();
        if (vhfopt) {
                fprescreen = vhfopt->fprescreen;
        } else {
                fprescreen = CVHFnoscreen;
        }

#pragma omp parallel default(none) \
        shared(fill, fprescreen, eri_ao, envs, intor, nkl, nbas) \
        private(ish)
#pragma omp for nowait schedule(dynamic)
        for (ish = 0; ish < nbas; ish++) {
                (*fill)(intor, fprescreen, eri_ao, nkl, ish, &envs, 0);
        }

#pragma omp parallel default(none) \
        shared(ftrans, fmmm, eri, eri_ao, nkl, ncomp, envs) \
        private(kl)
#pragma omp for nowait schedule(static)
        for (kl = 0; kl < nkl*ncomp; kl++) {
                (*ftrans)(fmmm, eri, eri_ao, kl, &envs);
        }

        free(ao_loc);
        free(eri_ao);
        free(mo_r);
        free(mo_i);
}
Exemplo n.º 5
0
FINT cintcgto_spinor_(const FINT *bas_id, const FINT *bas)
{
        return CINTcgto_spinor(*bas_id, bas);
}
Exemplo n.º 6
0
int main()
{
        int natm = 2;
        int nbas = 4;
        // ATM_SLOTS = 6; BAS_SLOTS = 8;
        int *atm = malloc(sizeof(int) * natm * ATM_SLOTS);
        int *bas = malloc(sizeof(int) * nbas * BAS_SLOTS);
        double *env = malloc(sizeof(double) * 10000);

        int i, n, off;
        off = PTR_ENV_START; // = 20

        i = 0;
        atm[CHARGE_OF + ATM_SLOTS * i] = 1;
        atm[PTR_COORD + ATM_SLOTS * i] = off;
        env[off + 0] =  0; // x (Bohr)
        env[off + 1] =  0; // y (Bohr)
        env[off + 2] =-.8; // z (Bohr)
        i++;
        off += 3;
        atm[CHARGE_OF + ATM_SLOTS * i] = 1;
        atm[PTR_COORD + ATM_SLOTS * i] = off;
        env[off + 0] = 0;
        env[off + 1] = 0;
        env[off + 2] =.8; // (Bohr)
        i++;
        off += 3;

        n = 0;
        /* basis #0 with kappa > 0  => p_1/2 */
        bas[ATOM_OF  + BAS_SLOTS * n]  = 0;
        bas[ANG_OF   + BAS_SLOTS * n]  = 0;
        bas[NPRIM_OF + BAS_SLOTS * n]  = 3;
        bas[NCTR_OF  + BAS_SLOTS * n]  = 2;
        bas[KAPPA_OF + BAS_SLOTS * n]  = 1;
        bas[PTR_EXP  + BAS_SLOTS * n]  = off;
        env[off + 0] = 6.;
        env[off + 1] = 2.;
        env[off + 2] = .8;
        off += 3;
        bas[PTR_COEFF+ BAS_SLOTS * n] = off;
        env[off + 0] = .7 * CINTgto_norm(bas[ANG_OF+BAS_SLOTS*n], env[bas[PTR_EXP+BAS_SLOTS*n]+0]);
        env[off + 1] = .6 * CINTgto_norm(bas[ANG_OF+BAS_SLOTS*n], env[bas[PTR_EXP+BAS_SLOTS*n]+1]);
        env[off + 2] = .5 * CINTgto_norm(bas[ANG_OF+BAS_SLOTS*n], env[bas[PTR_EXP+BAS_SLOTS*n]+2]);
        env[off + 3] = .4 * CINTgto_norm(bas[ANG_OF+BAS_SLOTS*n], env[bas[PTR_EXP+BAS_SLOTS*n]+0]);
        env[off + 4] = .3 * CINTgto_norm(bas[ANG_OF+BAS_SLOTS*n], env[bas[PTR_EXP+BAS_SLOTS*n]+1]);
        env[off + 5] = .2 * CINTgto_norm(bas[ANG_OF+BAS_SLOTS*n], env[bas[PTR_EXP+BAS_SLOTS*n]+2]);
        off += 6;
        n++;

        /* basis #1 with kappa = 0  => p_1/2, p_3/2 */
        bas[ATOM_OF  + BAS_SLOTS * n]  = 0;
        bas[ANG_OF   + BAS_SLOTS * n]  = 1;
        bas[NPRIM_OF + BAS_SLOTS * n]  = 1;
        bas[NCTR_OF  + BAS_SLOTS * n]  = 1;
        bas[KAPPA_OF + BAS_SLOTS * n]  = 0;
        bas[PTR_EXP  + BAS_SLOTS * n]  = off;
        env[off + 0] = .9;
        off += 1;
        bas[PTR_COEFF+ BAS_SLOTS * n] = off;
        env[off + 0] = 1. * CINTgto_norm(bas[ANG_OF+BAS_SLOTS*n], env[bas[PTR_EXP+BAS_SLOTS*n]]);
        off += 1;
        n++;

        /* basis #2 == basis #0 */
        bas[ATOM_OF  + BAS_SLOTS * n] = 1;
        bas[ANG_OF   + BAS_SLOTS * n] = bas[ANG_OF   + BAS_SLOTS * 0];
        bas[NPRIM_OF + BAS_SLOTS * n] = bas[NPRIM_OF + BAS_SLOTS * 0];
        bas[NCTR_OF  + BAS_SLOTS * n] = bas[NCTR_OF  + BAS_SLOTS * 0];
        bas[KAPPA_OF + BAS_SLOTS * n] = bas[KAPPA_OF + BAS_SLOTS * 0];
        bas[PTR_EXP  + BAS_SLOTS * n] = bas[PTR_EXP  + BAS_SLOTS * 0];
        bas[PTR_COEFF+ BAS_SLOTS * n] = bas[PTR_COEFF+ BAS_SLOTS * 0];
        n++;

        /* basis #3 == basis #1 */
        bas[ATOM_OF  + BAS_SLOTS * n] = 1;
        bas[ANG_OF   + BAS_SLOTS * n] = bas[ANG_OF   + BAS_SLOTS * 1];
        bas[NPRIM_OF + BAS_SLOTS * n] = bas[NPRIM_OF + BAS_SLOTS * 1];
        bas[NCTR_OF  + BAS_SLOTS * n] = bas[NCTR_OF  + BAS_SLOTS * 1];
        bas[KAPPA_OF + BAS_SLOTS * n] = bas[KAPPA_OF + BAS_SLOTS * 1];
        bas[PTR_EXP  + BAS_SLOTS * n] = bas[PTR_EXP  + BAS_SLOTS * 1];
        bas[PTR_COEFF+ BAS_SLOTS * n] = bas[PTR_COEFF+ BAS_SLOTS * 1];
        n++;

        /*
         * call one-electron spinor integrals
         */
        int j, k, l;
        int di, dj, dk, dl;
        int shls[4];
        double complex *buf;

        i = 0; shls[0] = i; di = CINTcgto_spinor(i, bas);
        j = 1; shls[1] = j; dj = CINTcgto_spinor(j, bas);
        buf = malloc(sizeof(double complex) * di * dj);
        if (0 != cint1e_spnucsp(buf, shls, atm, natm, bas, nbas, env)) {
                printf("This integral is not 0.\n");
        } else {
                printf("This integral is 0.\n");
        }
        free(buf);

        /*
         * call two-electron spinor integrals
         */
        i = 0; shls[0] = i; di = CINTcgto_spinor(i, bas);
        j = 1; shls[1] = j; dj = CINTcgto_spinor(j, bas);
        k = 2; shls[2] = k; dk = CINTcgto_spinor(k, bas);
        l = 2; shls[3] = l; dl = CINTcgto_spinor(l, bas);
        buf = malloc(sizeof(double complex) * di * dj * dk * dl);
        if (0 != cint2e_spsp1(buf, shls, atm, natm, bas, nbas, env, NULL)) {
                printf("This integral is not 0.\n");
        } else {
                printf("This integral is 0.\n");
        }
        free(buf);

        CINTOpt *opt = NULL;
        cint2e_spsp1_optimizer(&opt, atm, natm, bas, nbas, env);
        i = 0; shls[0] = i; di = CINTcgto_spinor(i, bas);
        j = 1; shls[1] = j; dj = CINTcgto_spinor(j, bas);
        k = 2; shls[2] = k; dk = CINTcgto_spinor(k, bas);
        l = 2; shls[3] = l; dl = CINTcgto_spinor(l, bas);
        buf = malloc(sizeof(double complex) * di * dj * dk * dl);
        if (0 != cint2e_spsp1(buf, shls, atm, natm, bas, nbas, env, opt)) {
                printf("This integral is not 0.\n");
        } else {
                printf("This integral is 0.\n");
        }
        free(buf);
        CINTdel_optimizer(&opt);

        free(atm);
        free(bas);
        free(env);
}