-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into variational_embedding
- Loading branch information
Showing
49 changed files
with
2,191 additions
and
479 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import pyscf | ||
import pyscf.gto | ||
import pyscf.scf | ||
import pyscf.mcscf | ||
|
||
import vayesta | ||
import vayesta.ewf | ||
|
||
mol = pyscf.gto.Mole() | ||
mol.atom = ['N 0 0 0', 'N 0 0 2'] | ||
mol.basis = 'aug-cc-pvdz' | ||
mol.output = 'pyscf.out' | ||
mol.build() | ||
|
||
# Hartree-Fock | ||
mf = pyscf.scf.RHF(mol) | ||
mf.kernel() | ||
|
||
# Reference CASCI | ||
casci = pyscf.mcscf.CASCI(mf, 8, 10) | ||
casci.kernel() | ||
|
||
# Reference CASSCF | ||
casscf = pyscf.mcscf.CASSCF(mf, 8, 10) | ||
casscf.kernel() | ||
|
||
def get_emb_result(ansatz, bathtype='full'): | ||
# Uses fastest available solver for given ansatz; PySCF if available, otherwise ebcc. | ||
emb = vayesta.ewf.EWF(mf, solver=ansatz, bath_options=dict(bathtype=bathtype), | ||
solver_options=dict(solve_lambda=False)) | ||
# Both these alternative specifications will always use an ebcc solver. | ||
# Note that the capitalization of the solver name other than the ansatz is arbitrary. | ||
#emb = vayesta.ewf.EWF(mf, solver=f'EB{ansatz}', bath_options=dict(bathtype=bathtype), | ||
# solver_options=dict(solve_lambda=False)) | ||
#emb = vayesta.ewf.EWF(mf, solver='ebcc', bath_options=dict(bathtype=bathtype), | ||
# solver_options=dict(solve_lambda=False, ansatz=ansatz)) | ||
|
||
with emb.iao_fragmentation() as f: | ||
with f.rotational_symmetry(2, "y", center=(0, 0, 1)): | ||
f.add_atomic_fragment(0) | ||
emb.kernel() | ||
return emb.e_tot | ||
|
||
e_ccsd = get_emb_result('CCSD', 'full') | ||
e_ccsdt = get_emb_result('CCSDT', 'dmet') | ||
e_ccsdtprime = get_emb_result("CCSDt'", 'full') | ||
|
||
print("E(HF)= %+16.8f Ha" % mf.e_tot) | ||
print("E(CASCI)= %+16.8f Ha" % casci.e_tot) | ||
print("E(CASSCF)= %+16.8f Ha" % casscf.e_tot) | ||
print("E(CCSD, complete)= %+16.8f Ha" % e_ccsd) | ||
print("E(emb. CCSDT, DMET CAS)= %+16.8f Ha" % e_ccsdt) | ||
print("E(emb. CCSDt', complete+DMET active space)= %+16.8f Ha" % e_ccsdtprime) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import pyscf.gto | ||
import pyscf.scf | ||
import pyscf.cc | ||
import vayesta.ewf | ||
|
||
|
||
mol = pyscf.gto.Mole() | ||
mol.atom = """ | ||
O 0.0000 0.0000 0.1173 | ||
H 0.0000 0.7572 -0.4692 | ||
H 0.0000 -0.7572 -0.4692 | ||
""" | ||
mol.basis = 'cc-pVTZ' | ||
mol.output = 'pyscf.out' | ||
mol.build() | ||
|
||
# Hartree-Fock | ||
mf = pyscf.scf.RHF(mol).density_fit() | ||
mf.kernel() | ||
|
||
# Reference full system CCSD: | ||
cc = pyscf.cc.CCSD(mf) | ||
cc.kernel() | ||
|
||
eta = 1e-6 | ||
|
||
# Embedded CCSD calculation with bare interactions and no energy correction. | ||
emb_bare = vayesta.ewf.EWF(mf, bath_options=dict(threshold=eta)) | ||
emb_bare.kernel() | ||
|
||
# Embedded CCSD with mRPA screened interactions and RPA cumulant approximation for nonlocal correlations. | ||
emb = vayesta.ewf.EWF(mf, bath_options=dict(threshold=eta), screening="mrpa", ext_rpa_correction="cumulant") | ||
emb.kernel() | ||
e_nonlocal_cumulant = emb.e_nonlocal | ||
# Embedded CCSD with mRPA screened interactions and delta RPA approximation for nonlocal correlations. | ||
emb = vayesta.ewf.EWF(mf, bath_options=dict(threshold=eta), screening="mrpa", ext_rpa_correction="erpa") | ||
emb.kernel() | ||
e_nonlocal_erpa = emb.e_nonlocal | ||
|
||
# Note that mRPA screening and external corrections often cancel with each other in the case of the energy. | ||
print("E(CCSD)= %+16.8f Ha" % cc.e_tot) | ||
print("E(RPA)= %+16.8f Ha (error= %+.8f Ha)" % (emb.e_mf + emb.e_rpa, | ||
emb.e_mf + emb.e_rpa - cc.e_tot)) | ||
print("E(Emb. CCSD)= %+16.8f Ha (error= %+.8f Ha)" % (emb_bare.e_tot, emb_bare.e_tot-cc.e_tot)) | ||
print("E(Emb. Screened CCSD)= %+16.8f Ha (error= %+.8f Ha)" % (emb.e_tot, emb.e_tot-cc.e_tot)) | ||
print("E(Emb. Screened CCSD + \Delta E_k)= %+16.8f Ha (error= %+.8f Ha)" % (emb.e_tot+e_nonlocal_cumulant, | ||
emb.e_tot+e_nonlocal_cumulant-cc.e_tot)) | ||
print("E(Emb. Screened CCSD + \Delta RPA)= %+16.8f Ha (error= %+.8f Ha)" % (emb.e_tot+e_nonlocal_erpa, | ||
emb.e_tot+e_nonlocal_erpa-cc.e_tot)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import pyscf.gto | ||
import pyscf.scf | ||
import pyscf.cc | ||
import pyscf.mcscf | ||
import vayesta.ewf | ||
from vayesta.misc import molecules | ||
|
||
mol = pyscf.gto.Mole() | ||
mol.atom = molecules.arene(6) | ||
mol.basis = 'cc-pVDZ' | ||
mol.output = 'pyscf.out' | ||
mol.build() | ||
|
||
mf = pyscf.scf.RHF(mol).density_fit() | ||
mf.kernel() | ||
|
||
ncas = (4,4) | ||
|
||
# Reference CASCI | ||
mycasci = pyscf.mcscf.CASCI(mf, *ncas) | ||
mycasci.kernel() | ||
|
||
# Equivalent CAS calculation with bare interactions | ||
casci_bare = vayesta.ewf.EWF(mf, bath_options=dict(bathtype="dmet"), screening=None, solver="FCI") | ||
with casci_bare.cas_fragmentation() as f: | ||
f.add_cas_fragment(*ncas) | ||
casci_bare.kernel() | ||
|
||
# CAS calculation with cRPA screening | ||
casci_crpa = vayesta.ewf.EWF(mf, bath_options=dict(bathtype="dmet"), screening="crpa", solver="FCI") | ||
with casci_crpa.cas_fragmentation() as f: | ||
f.add_cas_fragment(*ncas) | ||
casci_crpa.kernel() | ||
|
||
# CAS calculation with mRPA screening | ||
casci_mrpa = vayesta.ewf.EWF(mf, bath_options=dict(bathtype="dmet"), screening="mrpa", solver="FCI") | ||
with casci_mrpa.cas_fragmentation() as f: | ||
f.add_cas_fragment(*ncas) | ||
casci_mrpa.kernel() | ||
|
||
print("E(HF)= %+16.8f Ha" % mf.e_tot) | ||
print("ΔE(CASCI)= %+16.8f Ha" % (mycasci.e_tot-mf.e_tot)) | ||
print("ΔE(Emb. CASCI, bare interactions)= %+16.8f Ha (diff= %+.8f Ha)" % (casci_bare.e_tot-mf.e_tot, casci_bare.e_tot-mycasci.e_tot)) | ||
print("ΔE(Emb. CASCI, cRPA screening)= %+16.8f Ha (diff= %+.8f Ha)" % (casci_crpa.e_tot-mf.e_tot, casci_crpa.e_tot-mycasci.e_tot)) | ||
print("ΔE(Emb. CASCI, mRPA screening)= %+16.8f Ha (diff= %+.8f Ha)" % (casci_mrpa.e_tot-mf.e_tot, casci_mrpa.e_tot-mycasci.e_tot)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import pyscf | ||
import pyscf.pbc | ||
import pyscf.pbc.scf | ||
import pyscf.pbc.dft | ||
import pyscf.pbc.cc | ||
|
||
import vayesta | ||
import vayesta.ewf | ||
from vayesta.misc import solids | ||
|
||
cell = pyscf.pbc.gto.Cell() | ||
cell.a, cell.atom = solids.graphene() | ||
cell.basis = 'sto-3g' | ||
cell.output = 'pyscf.out' | ||
cell.dimension = 2 | ||
cell.space_group_symmetry = True | ||
cell.symmorphic = True | ||
cell.build() | ||
|
||
# HF | ||
kmesh = [2,2,1] | ||
kpts = cell.make_kpts(kmesh, space_group_symmetry=True, time_reversal_symmetry=True, symmorphic=True) | ||
hf = pyscf.pbc.scf.KRHF(cell, cell.make_kpts([2,2,1])) | ||
hf = hf.density_fit() | ||
hf.kernel() | ||
# This may be required to avoid issues discussed in 01-simple-sym.py. | ||
hf.mol.space_group_symmetry = False | ||
# Run embedded | ||
emb_bare = vayesta.ewf.EWF(hf, bath_options=dict(bathtype="rpa", threshold=1e-2), screening=None) | ||
emb_bare.kernel() | ||
# Run calculation using screened interactions and cumulant correction for nonlocal energy. | ||
emb_mrpa = vayesta.ewf.EWF(hf, bath_options=dict(bathtype="rpa", threshold=1e-2), screening="mrpa", | ||
ext_rpa_correction="cumulant") | ||
emb_mrpa.kernel() | ||
|
||
# Reference full system CCSD: | ||
cc = pyscf.pbc.cc.KCCSD(hf) | ||
cc.kernel() | ||
|
||
print("Error(HF)= %+16.8f Ha" % (hf.e_tot - cc.e_tot)) | ||
print("Error(Emb. bare CCSD)= %+16.8f Ha" % (emb_bare.e_tot - cc.e_tot)) | ||
print("Error(Emb. mRPA CCSD)= %+16.8f Ha" % (emb_mrpa.e_tot - cc.e_tot)) | ||
print("Error(Emb. mRPA CCSD + ΔE_k)= %+16.8f Ha" % (emb_mrpa.e_tot+emb_mrpa.e_nonlocal-cc.e_tot)) | ||
print("E(CCSD)= %+16.8f Ha" % cc.e_tot) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from vayesta.core.bath.bno import BNO_Threshold, BNO_Bath | ||
|
||
from vayesta.core.util import AbstractMethodError, brange, dot, einsum, fix_orbital_sign, hstack, time_string, timer | ||
from vayesta.core.types import Cluster | ||
|
||
from vayesta.rpa.rirpa import ssRIdRRPA | ||
|
||
from vayesta.core.eris import get_cderi | ||
from vayesta.core import spinalg | ||
from vayesta.core.bath import helper | ||
|
||
|
||
import numpy as np | ||
|
||
class RPA_BNO_Bath(BNO_Bath): | ||
|
||
def __init__(self, *args, project_dmet_order=0, project_dmet_mode='full', project_dmet=None, **kwargs): | ||
self.project_dmet_order = project_dmet_order | ||
self.project_dmet_mode = project_dmet_mode | ||
super().__init__(*args, **kwargs) | ||
|
||
|
||
def make_bno_coeff(self, cderis=None): | ||
"""Construct RPA bath natural orbital coefficients and occupation numbers. | ||
This routine works for both for spin-restricted and unrestricted. | ||
Parameters | ||
---------- | ||
cderis: cderis in the particle-hole space. | ||
Returns | ||
------- | ||
c_bno: (n(AO), n(BNO)) array | ||
Bath natural orbital coefficients. | ||
n_bno: (n(BNO)) array | ||
Bath natural orbital occupation numbers. | ||
""" | ||
|
||
t_init = timer() | ||
|
||
if cderis is None: | ||
cderis = get_cderi(self.base, (self.base.mo_coeff_occ, self.base.mo_coeff_vir), compact=False) | ||
|
||
if self.occtype == "occupied": | ||
proj = dot(self.dmet_bath.c_cluster_vir.T, self.base.get_ovlp(), self.fragment.c_frag, | ||
self.fragment.c_frag.T, self.base.get_ovlp(), self.dmet_bath.c_cluster_vir) | ||
|
||
rot_vir = dot(self.dmet_bath.c_cluster_vir.T, self.base.get_ovlp(), self.base.mo_coeff_vir) | ||
rot_occ = np.eye(self.base.nocc) | ||
else: | ||
proj = dot(self.dmet_bath.c_cluster_occ.T, self.base.get_ovlp(), self.fragment.c_frag, self.fragment.c_frag.T, | ||
self.base.get_ovlp(), self.dmet_bath.c_cluster_occ) | ||
rot_occ = dot(self.dmet_bath.c_cluster_occ.T, self.base.get_ovlp(), self.base.mo_coeff_occ) | ||
rot_vir = np.eye(self.base.nvir) | ||
|
||
loc_excit_shape = (rot_occ.shape[0], rot_vir.shape[0]) | ||
|
||
# Get target rotation in particle-hole excitation space. | ||
# This is of size O(N), so this whole procedure scales as O(N^4) | ||
|
||
target_rot = einsum("ij,ab->iajb", rot_occ, rot_vir) | ||
target_rot = target_rot.reshape(np.product(target_rot.shape[:2]), np.product(target_rot.shape[2:])) | ||
|
||
t0 = timer() | ||
myrpa = ssRIdRRPA(self.base.mf, lov=cderis) | ||
# This initially calculates the spin-summed zeroth moment, then deducts the spin-dependent component and | ||
# accounts for factor of two from different spin channels. | ||
m0 = (myrpa.kernel_moms(0, target_rot=target_rot, return_spatial=True)[0][0] - target_rot) / 2.0 | ||
m0 = -dot(m0, target_rot.T).reshape(loc_excit_shape + loc_excit_shape) | ||
if self.occtype == "occupied": | ||
corr_dm = einsum("iajb,ab->ij", m0, proj) | ||
else: | ||
corr_dm = einsum("iajb,ij->ab", m0, proj) | ||
t_eval = timer()-t0 | ||
|
||
corr_dm = (corr_dm + corr_dm.T) / 2 | ||
|
||
# --- Diagonalize environment-environment block | ||
if self.occtype == 'occupied': | ||
corr_dm = self._rotate_dm(corr_dm, dot(self.dmet_bath.c_env_occ.T, self.base.get_ovlp(), self.base.mo_coeff_occ)) | ||
elif self.occtype == 'virtual': | ||
corr_dm = self._rotate_dm(corr_dm, dot(self.dmet_bath.c_env_vir.T, self.base.get_ovlp(), self.base.mo_coeff_vir)) | ||
t0 = timer() | ||
r_bno, n_bno = self._diagonalize_dm(corr_dm) | ||
t_diag = timer()-t0 | ||
c_bno = spinalg.dot(self.c_env, r_bno) | ||
c_bno = fix_orbital_sign(c_bno)[0] | ||
|
||
self.log.timing("Time RPA bath: evaluation= %s diagonal.= %s total= %s", | ||
*map(time_string, (t_eval, t_diag, (timer()-t_init)))) | ||
|
||
if min(n_bno) < 0.0: | ||
self.log.critical("Negative bath occupation number encountered: %s", n_bno) | ||
|
||
return c_bno, n_bno, 0.0 |
Oops, something went wrong.