Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph theoretic fragmentation via graphgen. #86

Merged
merged 46 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
4a3a4b3
Added `graphgen` fragmentation.
ShaunWeatherly Jan 14, 2025
cacf442
Fix reference to `mf.mol` when `lo_method="pipek"`
ShaunWeatherly Jan 14, 2025
61907e2
Fix reference to `frag_scratch` when `solver=="DMRG"`
ShaunWeatherly Jan 14, 2025
17f1b84
Ruff fixes.
ShaunWeatherly Jan 14, 2025
a37a0e2
Formatting and removed unused code.
ShaunWeatherly Jan 14, 2025
1f17bcd
Final formatting
ShaunWeatherly Jan 14, 2025
865b9c2
Update dependencies.
ShaunWeatherly Jan 14, 2025
364ae2f
`mypy` static typing.
ShaunWeatherly Jan 14, 2025
f0fd882
Suppress `mypy` for `networkx` imports.
ShaunWeatherly Jan 14, 2025
cd77b7d
Remove debug prints
ShaunWeatherly Jan 14, 2025
cff391d
Added complete docstring for `graphgen`.
ShaunWeatherly Jan 14, 2025
ec70e05
Add types package for `networkx`
ShaunWeatherly Jan 15, 2025
49c20d5
Unsuppress mypy warnings
ShaunWeatherly Jan 15, 2025
24adc16
`norm`
ShaunWeatherly Jan 15, 2025
5fec9ed
New `FragmentMap` data class.
ShaunWeatherly Jan 15, 2025
7a4e53d
Edits to `FragmentMap` typing.
ShaunWeatherly Jan 15, 2025
f94c164
Remove unused kwargs.
ShaunWeatherly Jan 15, 2025
79dce30
Fix formatting
ShaunWeatherly Jan 15, 2025
a4333a6
Final formatting
ShaunWeatherly Jan 15, 2025
083e275
Additions to `nitpick_exceptions`.
ShaunWeatherly Jan 15, 2025
bfa1273
`FragmentMap` Docstring edits.
ShaunWeatherly Jan 15, 2025
31186f7
Remove unfinished code.
ShaunWeatherly Jan 15, 2025
98b4f72
Use `np.floating[Any]`
ShaunWeatherly Jan 15, 2025
7d4e7b5
Organize imports.
ShaunWeatherly Jan 15, 2025
815f0fe
Fixes for `FragmentMap`
ShaunWeatherly Jan 15, 2025
e9d5db9
Add unit tests for `autogen` and `graphgen`
ShaunWeatherly Jan 15, 2025
79a0627
Long line fix.
ShaunWeatherly Jan 15, 2025
546ee00
Suppress E501 in `fragmentation_test`
ShaunWeatherly Jan 15, 2025
d21a66a
Add ruff exclusion rule for `fragmentation_tests`
ShaunWeatherly Jan 15, 2025
c5b60d9
Ruff formatting yet again.
ShaunWeatherly Jan 15, 2025
5ebb8d4
Add `fragmentation_test` to mypy blacklist
ShaunWeatherly Jan 15, 2025
432efcc
Remove defaults in `FragmentMap` init.
ShaunWeatherly Jan 16, 2025
5a6ec5b
Add unit tests for energy comparisons across `autogen` and `graphgen`
ShaunWeatherly Jan 16, 2025
0fddbff
Add checks for IAOs in `graphgen`
ShaunWeatherly Jan 16, 2025
d9fee42
Update `graphgen` docstring
ShaunWeatherly Jan 16, 2025
1eab146
Formatting.
ShaunWeatherly Jan 16, 2025
b8f1eaa
Test `intersphinxlink`
ShaunWeatherly Jan 16, 2025
fcf5c23
More strict typing for `adjacency_mat`
ShaunWeatherly Jan 16, 2025
e07aa2d
Test removing `fragment_map` from nitpick exceptions.
ShaunWeatherly Jan 16, 2025
5b2108b
Rename `valence_basis` to `iao_valence_basis`
ShaunWeatherly Jan 16, 2025
bbbbe9b
Finish renaming `valence_basis` to `iao_valence_basis`
ShaunWeatherly Jan 16, 2025
5cc31d7
Ruff fixes.
ShaunWeatherly Jan 16, 2025
32a1eff
Final formatting.
ShaunWeatherly Jan 16, 2025
af8a8cf
Update `molbe_ppp`
ShaunWeatherly Jan 16, 2025
b4e2b5a
Address Oskar comments.
ShaunWeatherly Jan 17, 2025
8253907
Simplified check for `fragpart.mol`
ShaunWeatherly Jan 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[lint]
# see the rules [here](https://docs.astral.sh/ruff/rules/)
select = ["E", "F", "I", "NPY", "PL", "ARG"]
exclude = ["tests/fragmentation_test.py"]
ShaunWeatherly marked this conversation as resolved.
Show resolved Hide resolved
ignore = [
"S101",
# https://docs.astral.sh/ruff/rules/assert/
Expand Down
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"python": ("https://docs.python.org/3", None),
"pyscf": ("https://pyscf.org/", None),
"h5py": ("https://docs.h5py.org/en/stable/", None),
"networkx": ("https://networkx.org/documentation/stable/", None),
}


Expand Down
2 changes: 1 addition & 1 deletion example/molbe_ppp.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
mf.kernel()

# Define fragments; use IAO scheme with 'sto-3g' as the minimal basis set
fobj = fragpart(be_type="be2", mol=mol, valence_basis="sto-3g", frozen_core=True)
fobj = fragpart(be_type="be2", mol=mol, iao_valence_basis="sto-3g", frozen_core=True)

# Initialize BE
mybe = BE(mf, fobj, lo_method="iao")
Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
disallow_untyped_defs = False
check_untyped_defs = False

[mypy-tests.chem_dm_kBE_test,tests.chempot_molBE_test,tests.dm_molBE_test,tests.dmrg_molBE_test,tests.eri_onthefly_test,tests.hf-in-hf_BE_test,tests.kbe_polyacetylene_test,tests.molbe_h8_test,tests.molbe_io_fcidump_test,tests.molbe_octane_get_rdms_test,tests.molbe_oneshot_rbe_hcore_test,tests.molbe_oneshot_rbe_qmmm-fromchk_test,tests.ube-oneshot_test]
[mypy-tests.fragmentation_test,tests.chem_dm_kBE_test,tests.chempot_molBE_test,tests.dm_molBE_test,tests.dmrg_molBE_test,tests.eri_onthefly_test,tests.hf-in-hf_BE_test,tests.kbe_polyacetylene_test,tests.molbe_h8_test,tests.molbe_io_fcidump_test,tests.molbe_octane_get_rdms_test,tests.molbe_oneshot_rbe_hcore_test,tests.molbe_oneshot_rbe_qmmm-fromchk_test,tests.ube-oneshot_test]
disallow_untyped_defs = False
check_untyped_defs = False

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"numpy>=1.22.0",
"scipy>=1.7.0",
"pyscf>=2.0.0",
"networkx",
"matplotlib",
"libdmet @ git+https://github.com/gkclab/libdmet_preview.git",
"attrs",
Expand Down
8 changes: 4 additions & 4 deletions src/quemb/kbe/autofrag.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def autogen(
nx=False,
ny=False,
nz=False,
valence_basis=None,
iao_valence_basis=None,
interlayer=False,
print_frags=True,
):
Expand Down Expand Up @@ -274,7 +274,7 @@ def autogen(
write_geom : bool, optional
Whether to write a 'fragment.xyz' file which contains all the fragments in
Cartesian coordinates. Defaults to False.
valence_basis : str, optional
iao_valence_basis : str, optional
Name of minimal basis set for IAO scheme. 'sto-3g' is sufficient for most cases.
Defaults to None.
valence_only : bool, optional
Expand Down Expand Up @@ -1922,11 +1922,11 @@ def autogen(
)
w.close()

pao = valence_basis is not None
pao = iao_valence_basis is not None

if pao:
cell2 = cell.copy()
cell2.basis = valence_basis
cell2.basis = iao_valence_basis
cell2.build()

bas2list = cell2.aoslice_by_atom()
Expand Down
8 changes: 4 additions & 4 deletions src/quemb/kbe/fragment.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(
ny=False,
nz=False,
kpt=None,
valence_basis=None,
iao_valence_basis=None,
be_type="be2",
mol=None,
frozen_core=False,
Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__(
mol : pyscf.pbc.gto.cell.Cell
pyscf.pbc.gto.cell.Cell object. This is required for the options, 'autogen',
and 'chain' as frag_type.
valence_basis: str
iao_valence_basis: str
Name of minimal basis set for IAO scheme. 'sto-3g' suffice for most cases.
frozen_core: bool
Whether to invoke frozen core approximation. This is set to False by default
Expand Down Expand Up @@ -90,7 +90,7 @@ def __init__(
self.frozen_core = frozen_core
self.self_match = self_match
self.allcen = allcen
self.valence_basis = valence_basis
self.iao_valence_basis = iao_valence_basis
self.kpt = kpt
self.molecule = False # remove this

Expand All @@ -117,7 +117,7 @@ def __init__(
kpt,
be_type=be_type,
frozen_core=frozen_core,
valence_basis=valence_basis,
iao_valence_basis=iao_valence_basis,
unitcell=unitcell,
nx=nx,
ny=ny,
Expand Down
17 changes: 11 additions & 6 deletions src/quemb/kbe/lo.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Mixin_k_Localize:
def localize(
self,
lo_method,
valence_basis="sto-3g",
iao_valence_basis="sto-3g",
core_basis="sto-3g",
iao_wannier=True,
iao_val_core=True,
Expand All @@ -60,7 +60,7 @@ def localize(
lo_method : str
Localization method in quantum chemistry. 'lowdin', 'boys','iao',
and 'wannier' are supported.
valence_basis : str
iao_valence_basis : str
Name of valence basis set for IAO scheme. 'sto-3g' suffice for most cases.
core_basis : str
Name of core basis set for IAO scheme. 'sto-3g' suffice for most cases.
Expand Down Expand Up @@ -128,7 +128,7 @@ def localize(
elif lo_method == "iao":
if not iao_val_core or not self.frozen_core:
Co = self.C[:, :, : self.Nocc].copy()
S12, S2 = get_xovlp_k(self.cell, self.kpts, basis=valence_basis)
S12, S2 = get_xovlp_k(self.cell, self.kpts, basis=iao_valence_basis)
ciao_ = get_iao_k(Co, S12, self.S, S2=S2)

# tmp - aos are not rearrange and so below is not necessary
Expand All @@ -145,7 +145,7 @@ def localize(
# Cpao = get_pao_k(Ciao, self.S, S12, S2, self.cell)
# get_pao_native_k returns symm orthogonalized orbitals
cpao_ = get_pao_native_k(
Ciao_, self.S, self.cell, valence_basis, self.kpts
Ciao_, self.S, self.cell, iao_valence_basis, self.kpts
)

nk, nao, nlo = cpao_.shape
Expand Down Expand Up @@ -192,7 +192,7 @@ def localize(

# Begin valence
s12_val_, s2_val = get_xovlp_k(
self.cell, self.kpts, basis=valence_basis
self.cell, self.kpts, basis=iao_valence_basis
)
C_nocore = self.C[:, :, self.ncore :].copy()
C_nocore_occ_ = C_nocore[:, :, : self.Nocc].copy()
Expand Down Expand Up @@ -235,7 +235,12 @@ def localize(
)

cpao_ = get_pao_native_k(
c_core_val, self.S, self.cell, valence_basis, self.kpts, ortho=True
c_core_val,
self.S,
self.cell,
iao_valence_basis,
self.kpts,
ortho=True,
)
nk, nao, nlo = cpao_.shape
Cpao_ = zeros((nk, nao, nlo), dtype=complex128)
Expand Down
6 changes: 3 additions & 3 deletions src/quemb/kbe/lo_k.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def get_pao_k(Ciao, S, S12):
return asarray(Cpao)


def get_pao_native_k(Ciao, S, mol, valence_basis, ortho=True):
def get_pao_native_k(Ciao, S, mol, iao_valence_basis, ortho=True):
"""

Parameters
Expand All @@ -203,7 +203,7 @@ def get_pao_native_k(Ciao, S, mol, valence_basis, ortho=True):
ao ovlp matrix
mol :
mol object
valence_basis:
iao_valence_basis:
basis used for valence orbitals

Returns
Expand All @@ -215,7 +215,7 @@ def get_pao_native_k(Ciao, S, mol, valence_basis, ortho=True):

# Form a mol object with the valence basis for the ao_labels
mol_alt = mol.copy()
mol_alt.basis = valence_basis
mol_alt.basis = iao_valence_basis
mol_alt.build()

full_ao_labels = mol.ao_labels()
Expand Down
2 changes: 1 addition & 1 deletion src/quemb/kbe/pbe.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def __init__(
# Localize orbitals
self.localize(
lo_method,
valence_basis=fobj.valence_basis,
iao_valence_basis=fobj.iao_valence_basis,
iao_wannier=iao_wannier,
iao_val_core=iao_val_core,
)
Expand Down
Loading
Loading