Skip to content

Commit

Permalink
Merge pull request #109 from BoothGroup/formatting
Browse files Browse the repository at this point in the history
Formatting experiment
  • Loading branch information
cjcscott authored Sep 4, 2023
2 parents 3cf3f1f + 2bfab76 commit 515afec
Show file tree
Hide file tree
Showing 277 changed files with 9,915 additions and 8,393 deletions.
6 changes: 6 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Run this command to always ignore formatting commits in `git blame`
# git config blame.ignoreRevsFile .git-blame-ignore-revs

# Formatted entire existing codebase with black
3f80f568262b20fb82fbaa3d780d8a0d5cfebc3f

14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Install via pre-commit by running
# `pre-commit install`
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
# We'll need to manually update the version of black used in our pre-commits via
# `pre-commit autoupdate`.
# This is a conscious decision on the part of the pre-commit developers; for more information
# see https://pre-commit.com/#using-the-latest-version-for-a-repository
repos:
- repo: https://github.com/ambv/black
rev: 23.7.0
hooks:
- id: black
language_version: python3.10
29 changes: 13 additions & 16 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,28 @@
import sys
import vayesta

sys.path.insert(0, os.path.abspath('../vayesta/'))
sys.path.insert(0, os.path.abspath("../vayesta/"))


# -- Project information -----------------------------------------------------

project = 'Vayesta'
copyright = '2022'
author = 'All contributors'
project = "Vayesta"
copyright = "2022"
author = "All contributors"

# The full version, including alpha/beta/rc tags
release = '1.0.0'
release = "1.0.0"


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.todo',
'sphinx.ext.viewcode',
'sphinx.ext.autodoc',
'sphinx.ext.napoleon']
extensions = ["sphinx.ext.todo", "sphinx.ext.viewcode", "sphinx.ext.autodoc", "sphinx.ext.napoleon"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -51,24 +48,24 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
#html_static_path = ['_static']
# html_static_path = ['_static']
html_static_path = []

# Numbering for Figures, Tables, etc
numfig = True
numfig_format = {
'figure': 'Fig. %s',
'table': 'Table %s',
"figure": "Fig. %s",
"table": "Table %s",
}

# -- Autodoc defaults --------------------------------------------------------

autodoc_default_options = {
'member-order': 'bysource',
'inherited-members': True,
"member-order": "bysource",
"inherited-members": True,
}
16 changes: 8 additions & 8 deletions docs/source/quickstart/1d_hubbard.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
nsite = 16
nelectron = nsite
hubbard_u = 2.0
mol = vayesta.lattmod.Hubbard1D(nsite, nelectron=nelectron, hubbard_u=hubbard_u, output='pyscf.out')
mol = vayesta.lattmod.Hubbard1D(nsite, nelectron=nelectron, hubbard_u=hubbard_u, output="pyscf.out")

mf = vayesta.lattmod.LatticeMF(mol)
mf.kernel()

# Single site embedding:
ewf = vayesta.ewf.EWF(mf, bno_threshold=1e-8, fragment_type='Site')
ewf = vayesta.ewf.EWF(mf, bno_threshold=1e-8, fragment_type="Site")
ewf.site_fragmentation()
ewf.add_atomic_fragment(0, sym_factor=nsite)
ewf.kernel()
print("E(MF)= %+16.8f Ha" % (mf.e_tot/nelectron))
print("E(EWF-CCSD)= %+16.8f Ha" % (ewf.e_tot/nelectron))
print("E(MF)= %+16.8f Ha" % (mf.e_tot / nelectron))
print("E(EWF-CCSD)= %+16.8f Ha" % (ewf.e_tot / nelectron))

# Double site embedding:
ewf = vayesta.ewf.EWF(mf, bno_threshold=1e-8, fragment_type='Site')
ewf = vayesta.ewf.EWF(mf, bno_threshold=1e-8, fragment_type="Site")
ewf.site_fragmentation()
ewf.add_atomic_fragment([0,1], sym_factor=nsite/2)
ewf.add_atomic_fragment([0, 1], sym_factor=nsite / 2)

ewf.kernel()
print("E(MF)= %+16.8f Ha" % (mf.e_tot/nelectron))
print("E(EWF-CCSD)= %+16.8f Ha" % (ewf.e_tot/nelectron))
print("E(MF)= %+16.8f Ha" % (mf.e_tot / nelectron))
print("E(EWF-CCSD)= %+16.8f Ha" % (ewf.e_tot / nelectron))
23 changes: 13 additions & 10 deletions docs/source/quickstart/edmetfinite.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,39 @@
H 0.0000 0.7572 -0.4692
H 0.0000 -0.7572 -0.4692
"""
mol.basis = 'cc-pVDZ'
mol.output = 'pyscf.out'
mol.basis = "cc-pVDZ"
mol.output = "pyscf.out"
mol.build()

# LDA
lda = pyscf.dft.RKS(mol)
lda.xc = 'svwn'
lda.xc = "svwn"
lda = lda.density_fit()
lda.kernel()

# The KS object needs to be converted to a HF object:
lda = lda.to_rhf()

emb_lda = vayesta.edmet.EDMET(lda, bath_options=dict(dmet_threshold=1e-12), solver="CCSD-S-1-1",
oneshot=True, make_dd_moments=False)
emb_lda = vayesta.edmet.EDMET(
lda, bath_options=dict(dmet_threshold=1e-12), solver="CCSD-S-1-1", oneshot=True, make_dd_moments=False
)

with emb_lda.iao_fragmentation() as f:
f.add_all_atomic_fragments()
emb_lda.kernel()

# b3lyp
b3lyp = pyscf.dft.RKS(mol)
b3lyp.xc = 'b3lyp'
b3lyp.xc = "b3lyp"
b3lyp = b3lyp.density_fit()
b3lyp.kernel()

# The KS opbject needs to be converted to a HF object:
b3lyp = b3lyp.to_rhf()

emb_b3lyp = vayesta.edmet.EDMET(b3lyp, bath_options=dict(dmet_threshold=1e-12), solver="CCSD-S-1-1", oneshot=True, make_dd_moments=False)
emb_b3lyp = vayesta.edmet.EDMET(
b3lyp, bath_options=dict(dmet_threshold=1e-12), solver="CCSD-S-1-1", oneshot=True, make_dd_moments=False
)
with emb_b3lyp.iao_fragmentation() as f:
f.add_all_atomic_fragments()
emb_b3lyp.kernel()
Expand All @@ -51,8 +54,9 @@
hf = pyscf.scf.RHF(mol).density_fit()
hf.kernel()

emb_hf = vayesta.edmet.EDMET(hf, bath_options=dict(dmet_threshold=1e-12), solver="CCSD-S-1-1",
oneshot=True, make_dd_moments=False)
emb_hf = vayesta.edmet.EDMET(
hf, bath_options=dict(dmet_threshold=1e-12), solver="CCSD-S-1-1", oneshot=True, make_dd_moments=False
)

with emb_hf.iao_fragmentation() as f:
f.add_all_atomic_fragments()
Expand All @@ -71,4 +75,3 @@
print("E(HF @B3LYP)= %+16.8f Ha" % emb_b3lyp.e_mf)
print("E(Emb. CCSD @B3LYP)= %+16.8f Ha" % emb_b3lyp.e_tot)
print("E(Emb. CCSD @HF)= %+16.8f Ha" % emb_hf.e_tot)

26 changes: 13 additions & 13 deletions examples/dmet/01-simple-dmet.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

# H6 ring
mol = pyscf.gto.Mole()
mol.atom = ring(atom='H', natom=6, bond_length=2.0)
mol.basis = 'sto-6g'
mol.output = 'pyscf.out'
mol.atom = ring(atom="H", natom=6, bond_length=2.0)
mol.basis = "sto-6g"
mol.output = "pyscf.out"
mol.build()

# Hartree-Fock
Expand All @@ -22,24 +22,24 @@
fci.kernel()

# One-shot DMET
dmet = vayesta.dmet.DMET(mf, solver='FCI', maxiter=1)
dmet = vayesta.dmet.DMET(mf, solver="FCI", maxiter=1)
with dmet.sao_fragmentation() as f:
f.add_atomic_fragment([0,1])
f.add_atomic_fragment([2,3])
f.add_atomic_fragment([4,5])
f.add_atomic_fragment([0, 1])
f.add_atomic_fragment([2, 3])
f.add_atomic_fragment([4, 5])
dmet.kernel()

# Self-consistent DMET
dmet_sc = vayesta.dmet.DMET(mf, solver='FCI')
dmet_sc = vayesta.dmet.DMET(mf, solver="FCI")
with dmet_sc.sao_fragmentation() as f:
f.add_atomic_fragment([0,1])
f.add_atomic_fragment([2,3])
f.add_atomic_fragment([4,5])
f.add_atomic_fragment([0, 1])
f.add_atomic_fragment([2, 3])
f.add_atomic_fragment([4, 5])
dmet_sc.kernel()

print("Energies")
print("========")
print(" HF: %+16.8f Ha" % mf.e_tot)
print(" FCI: %+16.8f Ha" % fci.e_tot)
print(" DMET(1 iteration): %+16.8f Ha (error= %.1f mHa)" % (dmet.e_tot, 1000*(dmet.e_tot-fci.e_tot)))
print(" DMET(self-consistent): %+16.8f Ha (error= %.1f mHa)" % (dmet_sc.e_tot, 1000*(dmet_sc.e_tot-fci.e_tot)))
print(" DMET(1 iteration): %+16.8f Ha (error= %.1f mHa)" % (dmet.e_tot, 1000 * (dmet.e_tot - fci.e_tot)))
print(" DMET(self-consistent): %+16.8f Ha (error= %.1f mHa)" % (dmet_sc.e_tot, 1000 * (dmet_sc.e_tot - fci.e_tot)))
22 changes: 11 additions & 11 deletions examples/dmet/02-rotational-symmetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

# H6 ring
mol = pyscf.gto.Mole()
mol.atom = ring(atom='H', natom=6, bond_length=2.0)
mol.basis = 'sto-6g'
mol.output = 'pyscf.out'
mol.atom = ring(atom="H", natom=6, bond_length=2.0)
mol.basis = "sto-6g"
mol.output = "pyscf.out"
mol.build()

# Hartree-Fock
Expand All @@ -25,22 +25,22 @@
fci.kernel()

# One-shot DMET
dmet = vayesta.dmet.DMET(mf, solver='FCI', maxiter=1)
dmet = vayesta.dmet.DMET(mf, solver="FCI", maxiter=1)
with dmet.sao_fragmentation() as f:
with f.rotational_symmetry(3, axis=[0,0,1]):
f.add_atomic_fragment([0,1])
with f.rotational_symmetry(3, axis=[0, 0, 1]):
f.add_atomic_fragment([0, 1])
dmet.kernel()

# Self-consistent DMET
dmet_sc = vayesta.dmet.DMET(mf, solver='FCI')
dmet_sc = vayesta.dmet.DMET(mf, solver="FCI")
with dmet_sc.sao_fragmentation() as f:
with f.rotational_symmetry(3, axis=(0,0,1), center=(0,0,0)):
f.add_atomic_fragment([0,1])
with f.rotational_symmetry(3, axis=(0, 0, 1), center=(0, 0, 0)):
f.add_atomic_fragment([0, 1])
dmet_sc.kernel()

print("Energies")
print("========")
print(" HF: %+16.8f Ha" % mf.e_tot)
print(" FCI: %+16.8f Ha" % fci.e_tot)
print(" DMET(1 iteration): %+16.8f Ha (error= %.1f mHa)" % (dmet.e_tot, 1000*(dmet.e_tot-fci.e_tot)))
print(" DMET(self-consistent): %+16.8f Ha (error= %.1f mHa)" % (dmet_sc.e_tot, 1000*(dmet_sc.e_tot-fci.e_tot)))
print(" DMET(1 iteration): %+16.8f Ha (error= %.1f mHa)" % (dmet.e_tot, 1000 * (dmet.e_tot - fci.e_tot)))
print(" DMET(self-consistent): %+16.8f Ha (error= %.1f mHa)" % (dmet_sc.e_tot, 1000 * (dmet_sc.e_tot - fci.e_tot)))
16 changes: 8 additions & 8 deletions examples/dmet/03-density-matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@

# H6 ring
mol = pyscf.gto.Mole()
mol.atom = ring(atom='H', natom=6, bond_length=2.0)
mol.basis = 'sto-6g'
mol.output = 'pyscf.out'
mol.atom = ring(atom="H", natom=6, bond_length=2.0)
mol.basis = "sto-6g"
mol.output = "pyscf.out"
mol.build()

# Hartree-Fock
mf = pyscf.scf.RHF(mol)
mf.kernel()

# One-shot DMET
dmet = vayesta.dmet.DMET(mf, solver='FCI', maxiter=1)
dmet = vayesta.dmet.DMET(mf, solver="FCI", maxiter=1)
with dmet.sao_fragmentation() as f:
f.add_atomic_fragment([0,1])
f.add_atomic_fragment([2,3])
f.add_atomic_fragment([4,5])
f.add_atomic_fragment([0, 1])
f.add_atomic_fragment([2, 3])
f.add_atomic_fragment([4, 5])
dmet.kernel()

# Calculate energy from democratically-partitioned density matrices:
Expand All @@ -30,7 +30,7 @@
# One and two-electron integrals in AO basis:
h1e = dmet.get_hcore()
eris = dmet.get_eris_array(np.eye(mol.nao))
e_dmet = dmet.e_nuc + np.einsum('ij,ij->', h1e, dm1) + np.einsum('ijkl,ijkl->', eris, dm2)/2
e_dmet = dmet.e_nuc + np.einsum("ij,ij->", h1e, dm1) + np.einsum("ijkl,ijkl->", eris, dm2) / 2

print("Energies")
print("========")
Expand Down
16 changes: 7 additions & 9 deletions examples/dmet/04-h-ring-diis.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import numpy as np

import pyscf
import pyscf.scf
import pyscf.scf

import vayesta
import vayesta.dmet
from vayesta.misc.molecules import ring


mol = pyscf.gto.Mole()
mol.atom = ring('H', 6, 2.0)
mol.basis = 'sto-3g'
mol.output = 'pyscf.out'
mol.atom = ring("H", 6, 2.0)
mol.basis = "sto-3g"
mol.output = "pyscf.out"
mol.verbose = 4
mol.build()

Expand All @@ -20,24 +20,22 @@
mf.kernel()

# DMET calculation with DIIS extrapolation of the high-level correlation potential.
dmet_diis = vayesta.dmet.DMET(mf, solver='FCI', charge_consistent=False, diis=True,
max_elec_err=1e-6)
dmet_diis = vayesta.dmet.DMET(mf, solver="FCI", charge_consistent=False, diis=True, max_elec_err=1e-6)
with dmet_diis.iao_fragmentation() as f:
f.add_atomic_fragment([0, 1])
f.add_atomic_fragment([2, 3])
f.add_atomic_fragment([4, 5])
dmet_diis.kernel()

# DMET calculation without DIIS, using
dmet_mix = vayesta.dmet.DMET(mf, solver='FCI', charge_consistent=False, diis=False,
max_elec_err=1e-6)
dmet_mix = vayesta.dmet.DMET(mf, solver="FCI", charge_consistent=False, diis=False, max_elec_err=1e-6)
with dmet_mix.iao_fragmentation() as f:
f.add_atomic_fragment([0, 1])
f.add_atomic_fragment([2, 3])
f.add_atomic_fragment([4, 5])
dmet_mix.kernel()

ediff = (dmet_diis.e_dmet - dmet_mix.e_dmet)
ediff = dmet_diis.e_dmet - dmet_mix.e_dmet
vdiff = np.linalg.norm(dmet_diis.vcorr - dmet_mix.vcorr)

print("Difference between DIIS and mixing solution:")
Expand Down
10 changes: 5 additions & 5 deletions examples/dmet/63-hubbard-1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@
nsite = 10
nimp = 2
hubbard_u = 6.0
boundary = 'PBC'
boundary = "PBC"
nelectron = nsite
mol = vayesta.lattmod.Hubbard1D(nsite, nelectron=nelectron, hubbard_u=hubbard_u, boundary=boundary)
mf = vayesta.lattmod.LatticeMF(mol)
mf.kernel()

# Calculate each 2-sites fragment:
dmet = vayesta.dmet.DMET(mf, solver='FCI')
dmet = vayesta.dmet.DMET(mf, solver="FCI")
with dmet.site_fragmentation() as f:
for site in range(0, nsite, nimp):
f.add_atomic_fragment(list(range(site, site+nimp)))
f.add_atomic_fragment(list(range(site, site + nimp)))
dmet.kernel()

print(dmet.fragments)
# Calculate a single fragment and use translational symmetry:
dmet_sym = vayesta.dmet.DMET(mf, solver='FCI')
dmet_sym = vayesta.dmet.DMET(mf, solver="FCI")
# Specify the number of translational copies in direction of the three lattice vectors by passing a list with three
# integers, [n0, n1, n2]. 1D or 2D systems have their periodic dimension along the first one or two axes.
nimages = [nsite//nimp, 1, 1]
nimages = [nsite // nimp, 1, 1]
dmet_sym.symmetry.set_translations(nimages)
# Add only a single 2-sites fragment:
with dmet_sym.site_fragmentation() as f:
Expand Down
Loading

0 comments on commit 515afec

Please sign in to comment.