|
| 1 | +# Requires a separate JAX installation. |
| 2 | + |
| 3 | +import os |
| 4 | + |
| 5 | +os.environ["OMP_NUM_THREADS"] = ( |
| 6 | + "1" # For reproducibility. LNO makes slightly different orbitals every time. |
| 7 | +) |
| 8 | +import sys |
| 9 | + |
| 10 | +import numpy as np |
| 11 | +from pyscf.data.elements import chemcore |
| 12 | + |
| 13 | +from pyscf import gto, mp, scf |
| 14 | +from pyscf.afqmc.lnoafqmc import LNOAFQMC, prep_local_orbitals |
| 15 | +from pyscf.lib import logger |
| 16 | + |
| 17 | +log = logger.Logger(sys.stdout, 6) |
| 18 | + |
| 19 | + |
| 20 | +# water dimer |
| 21 | +atom = """ |
| 22 | +O -1.485163346097 -0.114724564047 0.000000000000 |
| 23 | +H -1.868415346097 0.762298435953 0.000000000000 |
| 24 | +H -0.533833346097 0.040507435953 0.000000000000 |
| 25 | +O 1.416468653903 0.111264435953 0.000000000000 |
| 26 | +H 1.746241653903 -0.373945564047 -0.758561000000 |
| 27 | +H 1.746241653903 -0.373945564047 0.758561000000 |
| 28 | +""" |
| 29 | + |
| 30 | +basis = "631g" |
| 31 | + |
| 32 | +mol = gto.M(atom=atom, basis=basis) |
| 33 | +mol.verbose = 3 |
| 34 | +frozen = chemcore(mol) |
| 35 | + |
| 36 | +mf = scf.RHF(mol).density_fit() |
| 37 | +mf.kernel() # type: ignore |
| 38 | + |
| 39 | +# canonical |
| 40 | +mmp = mp.MP2(mf, frozen=frozen) |
| 41 | +mmp.kernel() |
| 42 | +efull_mp2 = mmp.e_corr |
| 43 | + |
| 44 | +lo_coeff, frag_lolist = prep_local_orbitals(mf, frozen=frozen) |
| 45 | +# frag_lolist = [[0]] # One can run a particular fragment like this |
| 46 | +# LNO-AFQMC calculation: here we can scan over a list of thresholds |
| 47 | +mcc = LNOAFQMC(mf, lo_coeff, frag_lolist, frozen=frozen).set(verbose=5) |
| 48 | +mcc.seed = 1234 |
| 49 | +mcc.n_blocks = 100 |
| 50 | +mcc.n_walkers = 200 |
| 51 | + |
| 52 | +gamma = 10 # thresh_occ / thresh_vir |
| 53 | +threshs = np.asarray([1e-5]) |
| 54 | +elno_afqmc_uncorr = np.zeros_like(threshs) |
| 55 | +stocherr_afqmc = np.zeros_like(threshs) |
| 56 | +elno_mp2 = np.zeros_like(threshs) |
| 57 | +elno_afqmc = np.zeros_like(threshs) |
| 58 | +for i, thresh in enumerate(threshs): |
| 59 | + mcc.lno_thresh = [thresh * gamma, thresh] |
| 60 | + mcc.kernel() |
| 61 | + stocherr_afqmc[i] = mcc.afqmc_error_ecorr |
| 62 | + elno_afqmc_uncorr[i] = mcc.e_corr_afqmc |
| 63 | + elno_mp2[i] = mcc.e_corr_pt2 |
| 64 | + elno_afqmc[i] = mcc.e_corr_afqmc - elno_mp2[i] + efull_mp2 |
| 65 | + |
| 66 | +log.info("") |
| 67 | +for i, thresh in enumerate(threshs): |
| 68 | + e0 = elno_afqmc_uncorr[i] |
| 69 | + err = stocherr_afqmc[i] |
| 70 | + e1 = elno_afqmc[i] |
| 71 | + log.info( |
| 72 | + "thresh = %.3e E_corr(LNO-AFQMC) = %.15g +/- %.15g E_corr(LNO-AFQMC+∆PT2) = %.15g +/- %.15g", |
| 73 | + thresh, |
| 74 | + e0, |
| 75 | + err, |
| 76 | + e1, |
| 77 | + err, |
| 78 | + ) |
0 commit comments