Skip to content

Commit

Permalink
apply ruff format
Browse files Browse the repository at this point in the history
purely cosmetic PEP8 conformance
  • Loading branch information
mcocdawc committed Nov 20, 2024
1 parent b6bce7d commit 1f9f657
Show file tree
Hide file tree
Showing 55 changed files with 6,314 additions and 3,715 deletions.
14 changes: 7 additions & 7 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@

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

project = 'QuEmb'
copyright = '2024, Oinam Romesh Meitei'
author = 'Oinam Romesh Meitei'
sys.path.insert(0, os.path.abspath("../.."))

project = "QuEmb"
copyright = "2024, Oinam Romesh Meitei"
author = "Oinam Romesh Meitei"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = ['sphinx.ext.autodoc', 'sphinx.ext.napoleon','sphinx_rtd_theme']
extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon", "sphinx_rtd_theme"]
napoleon_google_docstring = False
napoleon_include_init_with_doc = True
napoleon_numpy_docstring = True
exclude_patterns = []



# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"
30 changes: 14 additions & 16 deletions example/kbe_polyacetylene.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
kpt = [1, 1, 3]
cell = gto.Cell()

a = 8.
b = 8.
c = 2.455 *2.
a = 8.0
b = 8.0
c = 2.455 * 2.0

lat = numpy.eye(3)
lat[0,0] = a
lat[1,1] = b
lat[2,2] = c
lat[0, 0] = a
lat[1, 1] = b
lat[2, 2] = c

cell.a = lat

cell.atom='''
cell.atom = """
H 1.4285621630072645 0.0 -0.586173422487319
C 0.3415633681566205 0.0 -0.5879921146011252
H -1.4285621630072645 0.0 0.586173422487319
Expand All @@ -29,11 +29,11 @@
C 0.3415633681566205 0.0 1.867007885398875
H -1.4285621630072645 0.0 3.041173422487319
C -0.3415633681566205 0.0 3.0429921146011254
'''
"""

cell.unit='Angstrom'
cell.basis = 'sto-3g'
cell.verbose=0
cell.unit = "Angstrom"
cell.basis = "sto-3g"
cell.verbose = 0
cell.build()

kpts = cell.make_kpts(kpt, wrap_around=True)
Expand All @@ -47,11 +47,9 @@
kpoint_energy = kmf.kernel()

# Define fragment in the supercell
kfrag = fragpart(be_type='be2', mol=cell,
kpt=kpt, frozen_core=True)
kfrag = fragpart(be_type="be2", mol=cell, kpt=kpt, frozen_core=True)
# Initialize BE
mykbe = BE(kmf, fobj,
kpts=kpts)
mykbe = BE(kmf, fobj, kpts=kpts)

# Perform BE density matching
mykbe.optimize(solver='CCSD')
mykbe.optimize(solver="CCSD")
85 changes: 40 additions & 45 deletions example/molbe_dmrg_block2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
for a in seps:
# Hartree-Fock serves as the starting point for all BE calculations:
mol = gto.M()
mol.atom = [['H', (0.,0.,i*a)] for i in range(8)]
mol.basis = 'sto-3g'
mol.atom = [["H", (0.0, 0.0, i * a)] for i in range(8)]
mol.basis = "sto-3g"
mol.charge = 0
mol.spin = 0
mol.build()
Expand All @@ -43,21 +43,21 @@
# any clear advantage to using any one scheme over another,
# the Pipek-Mezey scheme continues to be the most popular. With
# BE-DMRG, localization takes place prior to fragmentation:
fobj = fragpart(be_type='be1', mol=mol)
fobj = fragpart(be_type="be1", mol=mol)
mybe = BE(
mf,
fobj,
lo_method='pipek-mezey', # or 'lowdin', 'iao', 'boys'
pop_method='lowdin' # or 'meta-lowdin', 'mulliken', 'iao', 'becke'
)
lo_method="pipek-mezey", # or 'lowdin', 'iao', 'boys'
pop_method="lowdin", # or 'meta-lowdin', 'mulliken', 'iao', 'becke'
)

# Next, run BE-DMRG with default parameters and maxM=100.
mybe.oneshot(
solver='block2', # or 'DMRG', 'DMRGSCF', 'DMRGCI'
scratch=scratch, # Scratch dir for fragment DMRG
maxM=100, # Max fragment bond dimension
force_cleanup=True, # Remove all fragment DMRG tmpfiles
)
solver="block2", # or 'DMRG', 'DMRGSCF', 'DMRGCI'
scratch=scratch, # Scratch dir for fragment DMRG
maxM=100, # Max fragment bond dimension
force_cleanup=True, # Remove all fragment DMRG tmpfiles
)

bedmrg_ecorr.append(mybe.ebe_tot - mf.e_tot)
# Setting `force_cleanup=True` will clean the scratch directory after each
Expand All @@ -70,66 +70,61 @@
# Finally, plot the resulting potential energy curves:
fig, ax = plt.subplots()

ax.plot(seps, fci_ecorr, 'o-', linewidth=1, label='FCI')
ax.plot(seps, ccsd_ecorr, 'o-', linewidth=1, label='CCSD')
ax.plot(seps, ccsdt_ecorr, 'o-', linewidth=1, label='CCSD(T)')
ax.plot(seps, bedmrg_ecorr, 'o-', linewidth=1, label='BE1-DMRG')
ax.plot(seps, fci_ecorr, "o-", linewidth=1, label="FCI")
ax.plot(seps, ccsd_ecorr, "o-", linewidth=1, label="CCSD")
ax.plot(seps, ccsdt_ecorr, "o-", linewidth=1, label="CCSD(T)")
ax.plot(seps, bedmrg_ecorr, "o-", linewidth=1, label="BE1-DMRG")
ax.legend()

plt.savefig(os.path.join(scratch, f'BEDMRG_H8_PES{num_points}.png'))
plt.savefig(os.path.join(scratch, f"BEDMRG_H8_PES{num_points}.png"))

# (See ../quemb/example/figures/BEDMRG_H8_PES20.png for an example.)

# For larger fragments, you'll want greater control over the fragment
# DMRG calculations. Using the same setup as above for a single geometry:
mol = gto.M()
mol.atom = [['H', (0.,0.,i*1.2)] for i in range(8)]
mol.basis = 'sto-3g'
mol.atom = [["H", (0.0, 0.0, i * 1.2)] for i in range(8)]
mol.basis = "sto-3g"
mol.charge = 0
mol.spin = 0
mol.build()
fobj = fragpart(be_type='be2', mol=mol)
mybe = BE(
mf,
fobj,
lo_method='pipek-mezey',
pop_method='lowdin'
)
fobj = fragpart(be_type="be2", mol=mol)
mybe = BE(mf, fobj, lo_method="pipek-mezey", pop_method="lowdin")

# We automatically construct the fragment DMRG schedules based on user keywords. The following
# input, for example, yields a 60 sweep schedule which uses the two-dot algorithm from sweeps 0-49,
# and the one-dot algo from 50-60. The fragment orbitals are also reordered according the Fiedler
# vector procedure, along with a few other tweaks:

mybe.optimize(
solver='block2', # or 'DMRG', 'DMRGSCF', 'DMRGCI'
scratch=scratch, # Scratch dir for fragment DMRG
startM=20, # Initial fragment bond dimension (1st sweep)
maxM=200, # Maximum fragment bond dimension
max_iter=60, # Max number of sweeps
twodot_to_onedot=50, # Sweep num to switch from two- to one-dot algo.
max_mem=40, # Max memory (in GB) allotted to fragment DMRG
max_noise=1e-3, # Max MPS noise introduced per sweep
min_tol=1e-8, # Tighest Davidson tolerance per sweep
block_extra_keyword=['fiedler'], # Specify orbital reordering algorithm
force_cleanup=True, # Remove all fragment DMRG tmpfiles
solver="block2", # or 'DMRG', 'DMRGSCF', 'DMRGCI'
scratch=scratch, # Scratch dir for fragment DMRG
startM=20, # Initial fragment bond dimension (1st sweep)
maxM=200, # Maximum fragment bond dimension
max_iter=60, # Max number of sweeps
twodot_to_onedot=50, # Sweep num to switch from two- to one-dot algo.
max_mem=40, # Max memory (in GB) allotted to fragment DMRG
max_noise=1e-3, # Max MPS noise introduced per sweep
min_tol=1e-8, # Tighest Davidson tolerance per sweep
block_extra_keyword=["fiedler"], # Specify orbital reordering algorithm
force_cleanup=True, # Remove all fragment DMRG tmpfiles
only_chem=True,
)

# Or, alternatively, we can construct a full schedule by hand:
schedule={
'scheduleSweeps': [0, 10, 20, 30, 40, 50], # Sweep indices
'scheduleMaxMs': [25, 50, 100, 200, 500, 500], # Sweep maxMs
'scheduleTols': [1e-5,1e-5, 1e-6, 1e-6, 1e-8, 1e-8], # Sweep Davidson tolerances
'scheduleNoises': [0.01, 0.01, 0.001, 0.001, 1e-4, 0.0], # Sweep MPS noise
schedule = {
"scheduleSweeps": [0, 10, 20, 30, 40, 50], # Sweep indices
"scheduleMaxMs": [25, 50, 100, 200, 500, 500], # Sweep maxMs
"scheduleTols": [1e-5, 1e-5, 1e-6, 1e-6, 1e-8, 1e-8], # Sweep Davidson tolerances
"scheduleNoises": [0.01, 0.01, 0.001, 0.001, 1e-4, 0.0], # Sweep MPS noise
}

# and pass it to the fragment solver through `schedule_kwargs`:
mybe.optimize(
solver='block2',
solver="block2",
scratch=scratch,
schedule_kwargs=schedule,
block_extra_keyword=['fiedler'],
block_extra_keyword=["fiedler"],
force_cleanup=True,
only_chem=True,
)
Expand All @@ -138,5 +133,5 @@
# and `[scratch]/dmrg.out`, which are the fragment DMRG inputs and outputs, respectively, used
# by `block2`.

#NOTE: Parameters in `schedule_kwargs` will overwrite any other DMRG kwargs.
#NOTE: The DMRG schedule kwargs and related syntax follows the standard notation used in block2.
# NOTE: Parameters in `schedule_kwargs` will overwrite any other DMRG kwargs.
# NOTE: The DMRG schedule kwargs and related syntax follows the standard notation used in block2.
37 changes: 20 additions & 17 deletions example/molbe_h8_chemical_potential.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Illustrates a simple molecular BE calculation with chemical
# potential matching

from pyscf import gto,scf, fci
from pyscf import gto, scf, fci
from molbe import BE, fragpart

# PySCF HF generated mol & mf (molecular desciption & HF object)
mol = gto.M(atom='''
mol = gto.M(
atom="""
H 0. 0. 0.
H 0. 0. 1.
H 0. 0. 2.
Expand All @@ -14,7 +15,10 @@
H 0. 0. 5.
H 0. 0. 6.
H 0. 0. 7.
''',basis='sto-3g', charge=0)
""",
basis="sto-3g",
charge=0,
)

mf = scf.RHF(mol)
mf.conv_tol = 1e-12
Expand All @@ -23,39 +27,38 @@
# Perform PySCF FCI to get reference energy
mc = fci.FCI(mf)
fci_ecorr = mc.kernel()[0] - mf.e_tot
print(f'*** FCI Correlation Energy: {fci_ecorr:>14.8f} Ha', flush=True)
print(f"*** FCI Correlation Energy: {fci_ecorr:>14.8f} Ha", flush=True)

# Perform BE calculations with different fragment schemes:

# Define BE1 fragments
fobj = fragpart(be_type='be1', mol=mol)
fobj = fragpart(be_type="be1", mol=mol)
# Initialize BE
mybe = BE(mf, fobj)
# Perform chemical potential optimization
mybe.optimize(solver='FCI', only_chem=True)
mybe.optimize(solver="FCI", only_chem=True)

# Compute BE error
be_ecorr = mybe.ebe_tot - mybe.ebe_hf
err_ = (fci_ecorr - be_ecorr)*100./fci_ecorr
print(f'*** BE1 Correlation Energy Error (%) : {err_:>8.4f} %')
err_ = (fci_ecorr - be_ecorr) * 100.0 / fci_ecorr
print(f"*** BE1 Correlation Energy Error (%) : {err_:>8.4f} %")

# Define BE2 fragments
fobj = fragpart(be_type='be2', mol=mol)
fobj = fragpart(be_type="be2", mol=mol)
mybe = BE(mf, fobj)
mybe.optimize(solver='FCI', only_chem=True)
mybe.optimize(solver="FCI", only_chem=True)

# Compute BE error
be_ecorr = mybe.ebe_tot - mybe.ebe_hf
err_ = (fci_ecorr - be_ecorr)*100./fci_ecorr
print(f'*** BE2 Correlation Energy Error (%) : {err_:>8.4f} %')
err_ = (fci_ecorr - be_ecorr) * 100.0 / fci_ecorr
print(f"*** BE2 Correlation Energy Error (%) : {err_:>8.4f} %")

# Define BE3 fragments
fobj = fragpart(be_type='be3', mol=mol)
fobj = fragpart(be_type="be3", mol=mol)
mybe = BE(mf, fobj)
mybe.optimize(solver='FCI', only_chem=True)
mybe.optimize(solver="FCI", only_chem=True)

# Compute BE error
be_ecorr = mybe.ebe_tot - mybe.ebe_hf
err_ = (fci_ecorr - be_ecorr)*100./fci_ecorr
print(f'*** BE3 Correlation Energy Error (%) : {err_:>8.4f} %')

err_ = (fci_ecorr - be_ecorr) * 100.0 / fci_ecorr
print(f"*** BE3 Correlation Energy Error (%) : {err_:>8.4f} %")
37 changes: 20 additions & 17 deletions example/molbe_h8_density_matching.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Illustrates a simple molecular BE calculation with BE
# density matching between edge & centers of fragments.

from pyscf import gto,scf, fci
from pyscf import gto, scf, fci
from molbe import BE, fragpart

# PySCF HF generated mol & mf (molecular desciption & HF object)
mol = gto.M(atom='''
mol = gto.M(
atom="""
H 0. 0. 0.
H 0. 0. 1.
H 0. 0. 2.
Expand All @@ -14,7 +15,10 @@
H 0. 0. 5.
H 0. 0. 6.
H 0. 0. 7.
''',basis='sto-3g', charge=0)
""",
basis="sto-3g",
charge=0,
)

mf = scf.RHF(mol)
mf.conv_tol = 1e-12
Expand All @@ -23,39 +27,38 @@
# Perform PySCF FCI to get reference energy
mc = fci.FCI(mf)
fci_ecorr = mc.kernel()[0] - mf.e_tot
print(f'*** FCI Correlation Energy: {fci_ecorr:>14.8f} Ha', flush=True)
print(f"*** FCI Correlation Energy: {fci_ecorr:>14.8f} Ha", flush=True)

# Perform BE calculations with different fragment schemes:

# Define BE1 fragments
fobj = fragpart(be_type='be1', mol=mol)
fobj = fragpart(be_type="be1", mol=mol)
# Initialize BE
mybe = BE(mf, fobj)
# Density matching in BE
mybe.optimize(solver='FCI')
mybe.optimize(solver="FCI")

# Compute BE error
be_ecorr = mybe.ebe_tot - mybe.ebe_hf
err_ = (fci_ecorr - be_ecorr)*100./fci_ecorr
print(f'*** BE1 Correlation Energy Error (%) : {err_:>8.4f} %')
err_ = (fci_ecorr - be_ecorr) * 100.0 / fci_ecorr
print(f"*** BE1 Correlation Energy Error (%) : {err_:>8.4f} %")

# Define BE2 fragments
fobj = fragpart(be_type='be2', mol=mol)
fobj = fragpart(be_type="be2", mol=mol)
mybe = BE(mf, fobj)
mybe.optimize(solver='FCI')
mybe.optimize(solver="FCI")

# Compute BE error
be_ecorr = mybe.ebe_tot - mybe.ebe_hf
err_ = (fci_ecorr - be_ecorr)*100./fci_ecorr
print(f'*** BE2 Correlation Energy Error (%) : {err_:>8.4f} %')
err_ = (fci_ecorr - be_ecorr) * 100.0 / fci_ecorr
print(f"*** BE2 Correlation Energy Error (%) : {err_:>8.4f} %")

# Define BE3 fragments
fobj = fragpart(be_type='be3', mol=mol)
fobj = fragpart(be_type="be3", mol=mol)
mybe = BE(mf, fobj)
mybe.optimize(solver='FCI')
mybe.optimize(solver="FCI")

# Compute BE error
be_ecorr = mybe.ebe_tot - mybe.ebe_hf
err_ = (fci_ecorr - be_ecorr)*100./fci_ecorr
print(f'*** BE3 Correlation Energy Error (%) : {err_:>8.4f} %')

err_ = (fci_ecorr - be_ecorr) * 100.0 / fci_ecorr
print(f"*** BE3 Correlation Energy Error (%) : {err_:>8.4f} %")
Loading

0 comments on commit 1f9f657

Please sign in to comment.