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

Fix long lines #13

Merged
merged 4 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[lint]
# see the rules [here](https://docs.astral.sh/ruff/rules/)
select = ["E", "F", "I", "NPY", "ARG"]
# select = ["E501"]
ignore = [
"S101",
# https://docs.astral.sh/ruff/rules/assert/
Expand Down
22 changes: 12 additions & 10 deletions example/molbe_dmrg_block2.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
# fragment DMRG calculation finishes. DMRG tempfiles can be quite large, so
# be sure to keep an eye on them if `force_cleanup=False` (default).

# NOTE: This does *not* delete the log files `dmrg.conf` and `dmrg.out`for each frag,
# which can still be found in `/scratch/`.
# NOTE: This does *not* delete the log files `dmrg.conf` and `dmrg.out`for
# each frag, which can still be found in `/scratch/`.

# Finally, plot the resulting potential energy curves:
fig, ax = plt.subplots()
Expand All @@ -94,10 +94,11 @@
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:
# 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
# to the Fiedler vector procedure, along with a few other tweaks:

mybe.optimize(
solver="block2", # or 'DMRG', 'DMRGSCF', 'DMRGCI'
Expand Down Expand Up @@ -132,9 +133,10 @@
only_chem=True,
)

# To make sure the calculation is proceeding as expected, make sure to check `[scratch]/dmrg.conf`
# and `[scratch]/dmrg.out`, which are the fragment DMRG inputs and outputs, respectively, used
# by `block2`.
# To make sure the calculation is proceeding as expected, make sure to check
# `[scratch]/dmrg.conf` # 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: The DMRG schedule kwargs and related syntax follows the standard notation
# used in block2.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
setup(
name="quemb",
version="1.0",
description="QuEmb: A framework for efficient simulation of large molecules, surfaces, and solids via Bootstrap Embedding",
description="QuEmb: A framework for efficient simulation of large molecules, "
"surfaces, and solids via Bootstrap Embedding",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/oimeitei/quemb",
Expand Down
20 changes: 14 additions & 6 deletions src/kbe/_opt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Author(s): Oinam Romesh Meitei

import sys

from molbe._opt import BEOPT


Expand Down Expand Up @@ -27,22 +29,27 @@ def optimize(
method : str, optional
Optimization method, by default 'QN'
only_chem : bool, optional
If true, density matching is not performed -- only global chemical potential is optimized, by default False
If true, density matching is not performed -- only global chemical potential is
optimized, by default False
conv_tol : _type_, optional
Convergence tolerance, by default 1.e-6
relax_density : bool, optional
Whether to use relaxed or unrelaxed densities, by default False
This option is for using CCSD as solver. Relaxed density here uses Lambda amplitudes, whereas unrelaxed density only uses T amplitudes.
c.f. See http://classic.chem.msu.su/cgi-bin/ceilidh.exe/gran/gamess/forum/?C34df668afbHW-7216-1405+00.htm for the distinction between the two
This option is for using CCSD as solver. Relaxed density here uses
Lambda amplitudes, whereas unrelaxed density only uses T amplitudes.
c.f. See http://classic.chem.msu.su/cgi-bin/ceilidh.exe/gran/gamess/forum/?C34df668afbHW-7216-1405+00.htm
for the distinction between the two
use_cumulant : bool, optional
Use cumulant-based energy expression, by default True
max_iter : int, optional
Maximum number of optimization steps, by default 500
nproc : int
Total number of processors assigned for the optimization. Defaults to 1. When nproc > 1, Python multithreading
Total number of processors assigned for the optimization. Defaults to 1.
When nproc > 1, Python multithreading
is invoked.
ompnum : int
If nproc > 1, ompnum sets the number of cores for OpenMP parallelization. Defaults to 4
If nproc > 1, ompnum sets the number of cores for OpenMP parallelization.
Defaults to 4
J0 : list of list of float
Initial Jacobian.
"""
Expand All @@ -53,7 +60,8 @@ def optimize(
pot = self.pot
if self.be_type == "be1":
sys.exit(
"BE1 only works with chemical potential optimization. Set only_chem=True"
"BE1 only works with chemical potential optimization. "
"Set only_chem=True"
)
else:
pot = [0.0]
Expand Down
44 changes: 29 additions & 15 deletions src/kbe/autofrag.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,35 +263,45 @@ def autogen(
"""
Automatic cell partitioning

Partitions a unitcell into overlapping fragments as defined in BE atom-based fragmentations.
It automatically detects branched chemical chains and ring systems and partitions accordingly.
For efficiency, it only checks two atoms for connectivity (chemical bond) if they are within 3.5 Angstrom.
This value is hardcoded as normdist. Two atoms are defined as bonded if they are within 1.8 Angstrom (1.2 for Hydrogen atom).
This is also hardcoded as bond & hbond. Neighboring unitcells are used in the fragmentation, exploiting translational symmetry.
Partitions a unitcell into overlapping fragments as defined in
BE atom-based fragmentations. It automatically detects branched chemical chains
and ring systems and partitions accordingly.
For efficiency, it only checks two atoms for connectivity (chemical bond)
if they are within 3.5 Angstrom. This value is hardcoded as normdist.
Two atoms are defined as bonded if they are within 1.8 Angstrom
(1.2 for Hydrogen atom).
This is also hardcoded as bond & hbond. Neighboring unitcells are used in the
fragmentation, exploiting translational symmetry.

Parameters
----------
mol : pyscf.pbc.gto.Cell
pyscf.pbc.gto.Cell object. This is required for the options, 'autogen' and 'chain' as frag_type.
pyscf.pbc.gto.Cell object. This is required for the options, 'autogen',
and 'chain' as frag_type.
kpt : list of int
Number of k-points in each lattice vector dimension.
frozen_core : bool, optional
Whether to invoke frozen core approximation. Defaults to True.
be_type : str, optional
Specifies the order of bootstrap calculation in the atom-based fragmentation. Supported values are 'be1', 'be2', 'be3', and 'be4'.
Specifies the order of bootstrap calculation in the atom-based fragmentation.
Supported values are 'be1', 'be2', 'be3', and 'be4'.
Defaults to 'be2'.
write_geom : bool, optional
Whether to write a 'fragment.xyz' file which contains all the fragments in Cartesian coordinates. Defaults to False.
Whether to write a 'fragment.xyz' file which contains all the fragments in
Cartesian coordinates. Defaults to False.
valence_basis : str, optional
Name of minimal basis set for IAO scheme. 'sto-3g' is sufficient for most cases. Defaults to None.
Name of minimal basis set for IAO scheme. 'sto-3g' is sufficient for most cases.
Defaults to None.
valence_only : bool, optional
If True, all calculations will be performed in the valence basis in the IAO partitioning. This is an experimental feature. Defaults to False.
If True, all calculations will be performed in the valence basis in
the IAO partitioning. This is an experimental feature. Defaults to False.
print_frags : bool, optional
Whether to print out the list of resulting fragments. Defaults to True.
interlayer : bool
Whether the periodic system has two stacked monolayers.
long_bond : bool
For systems with longer than 1.8 Angstrom covalent bond, set this to True otherwise the fragmentation might fail.
For systems with longer than 1.8 Angstrom covalent bond,
set this to True otherwise the fragmentation might fail.


Returns
Expand All @@ -303,13 +313,16 @@ def autogen(
center : list of list of int
List of center indices for each edge.
edge_idx : list of list of list of int
List of edge indices for each fragment where each edge index is a list of LO indices.
List of edge indices for each fragment where each edge index is a list of
LO indices.
center_idx : list of list of list of int
List of center indices for each fragment where each center index is a list of LO indices.
List of center indices for each fragment where each center index is a list of
LO indices.
centerf_idx : list of list of int
List of center fragment indices.
ebe_weight : list of list
Weights for each fragment. Each entry contains a weight and a list of LO indices.
Weights for each fragment. Each entry contains a weight and a list of LO
indices.
"""
from pyscf import lib

Expand Down Expand Up @@ -344,7 +357,8 @@ def autogen(
if n_ > kpt[idx]:
print("Use a larger number of k-points; ", flush=True)
print(
"Fragment cell larger than all k-points combined is not supported",
"Fragment cell larger than all k-points combined "
"is not supported",
flush=True,
)
sys.exit()
Expand Down
3 changes: 2 additions & 1 deletion src/kbe/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def findH(mol, nh, tmphlist=[]):

def polychain(self, mol, frozen_core=False, unitcell=1):
"""
Hard coded fragmentation for polymer chains. This is not recommended for any production level calculations.
Hard coded fragmentation for polymer chains. This is not recommended
for any production level calculations.
"""

# group H
Expand Down
29 changes: 19 additions & 10 deletions src/kbe/fragment.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,41 +40,50 @@ def __init__(
):
"""Fragment/partitioning definition

Interfaces two main fragmentation functions (autogen & polychain) in MolBE. It defines edge &
center for density matching and energy estimation. It also forms the base for IAO/PAO partitioning for
a large basis set bootstrap calculation. Fragments are constructed based on atoms within a unitcell.
Interfaces two main fragmentation functions (autogen & polychain) in MolBE.
It defines edge & center for density matching and energy estimation.
It also forms the base for IAO/PAO partitioning for
a large basis set bootstrap calculation. Fragments are constructed based
on atoms within a unitcell.

Parameters
----------
frag_type : str
Name of fragmentation function. 'autogen', 'hchain_simple', and 'chain' are supported. Defaults to 'autogen'
For systems with only hydrogen, use 'chain'; everything else should use 'autogen'
Name of fragmentation function. 'autogen', 'hchain_simple', and 'chain' are
supported. Defaults to 'autogen'
For systems with only hydrogen, use 'chain';
everything else should use 'autogen'
be_type : str
Specifies order of bootsrap calculation in the atom-based fragmentation. 'be1', 'be2', 'be3', & 'be4' are supported.
Specifies order of bootsrap calculation in the atom-based fragmentation.
'be1', 'be2', 'be3', & 'be4' are supported.
Defaults to 'be2'
For a simple linear system A-B-C-D,
be1 only has fragments [A], [B], [C], [D]
be2 has [A, B, C], [B, C, D]
ben ...
mol : pyscf.pbc.gto.Cell
pyscf.pbc.gto.Cell object. This is required for the options, 'autogen' and 'chain' as frag_type.
pyscf.pbc.gto.Cell object. This is required for the options, 'autogen',
and 'chain' as frag_type.
valence_basis: str
Name of minimal basis set for IAO scheme. 'sto-3g' suffice for most cases.
valence_only: bool
If this option is set to True, all calculation will be performed in the valence basis in the IAO partitioning.
If this option is set to True, all calculation will be performed in the
valence basis in the IAO partitioning.
This is an experimental feature.
frozen_core: bool
Whether to invoke frozen core approximation. This is set to False by default
print_frags: bool
Whether to print out list of resulting fragments. True by default
write_geom: bool
Whether to write 'fragment.xyz' file which contains all the fragments in cartesian coordinates.
Whether to write 'fragment.xyz' file which contains all the fragments in
cartesian coordinates.
kpt : list of int
No. of k-points in each lattice vector direction. This is the same as kmesh.
interlayer : bool
Whether the periodic system has two stacked monolayers.
long_bond : bool
For systems with longer than 1.8 Angstrom covalent bond, set this to True otherwise the fragmentation might fail.
For systems with longer than 1.8 Angstrom covalent bond, set this to True
otherwise the fragmentation might fail.
"""
# No. of unitcells to use for fragment construction
self.unitcell = unitcell
Expand Down
7 changes: 4 additions & 3 deletions src/kbe/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ def get_veff(eri_, dm, S, TA, hf_veff, return_veff0=False):
from pyscf import scf

"""
Calculate the effective HF potential (Veff) for a given density matrix and electron repulsion integrals.
Calculate the effective HF potential (Veff) for a given density matrix
and electron repulsion integrals.

This function computes the effective potential by transforming the density matrix, computing the Coulomb (J) and
exchange (K) integrals.
This function computes the effective potential by transforming the density matrix,
computing the Coulomb (J) and exchange (K) integrals.

Parameters
----------
Expand Down
13 changes: 8 additions & 5 deletions src/kbe/lo.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,21 @@ def localize(
):
"""Orbital localization

Performs orbital localization computations for periodic systems. For large basis, IAO is recommended
augmented with PAO orbitals.
Performs orbital localization computations for periodic systems. For large basis,
IAO is recommended augmented with PAO orbitals.

Parameters
----------
lo_method : str
Localization method in quantum chemistry. 'lowdin', 'boys','iao', and 'wannier' are supported.
Localization method in quantum chemistry. 'lowdin', 'boys','iao', and 'wannier'
are supported.
mol : pyscf.gto.Molecule
pyscf.gto.Molecule object.
valence_basis: str
Name of minimal basis set for IAO scheme. 'sto-3g' suffice for most cases.
valence_only: bool
If this option is set to True, all calculation will be performed in the valence basis in the IAO partitioning.
If this option is set to True, all calculation will be performed in the valence
basis in the IAO partitioning.
This is an experimental feature.
iao_wannier : bool
Whether to perform Wannier localization in the IAO space
Expand Down Expand Up @@ -239,7 +241,8 @@ def localize(
c_core_val[k] = numpy.hstack((ciao_core[k], Ciao_[k]))

arrange_by_atom = True
# tmp - aos are not rearrange and so below is not necessary (iaoind_by_atom is used to stack iao|pao later)
# tmp - aos are not rearrange and so below is not necessary
# (iaoind_by_atom is used to stack iao|pao later)
if arrange_by_atom:
nk, nao, nlo = c_core_val.shape
for k in range(self.nkpt):
Expand Down
5 changes: 3 additions & 2 deletions src/kbe/lo_k.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ def get_symm_orth_mat_k(A, thr=1.0e-7, ovlp=None):
e, u = scipy.linalg.eigh(S)
if int(numpy.sum(e < thr)) > 0:
raise ValueError(
"Linear dependence is detected in the column space of A: smallest eigenvalue (%.3E) is less than thr (%.3E). Please use 'cano_orth' instead."
% (numpy.min(e), thr)
"Linear dependence is detected in the column space of A: "
"smallest eigenvalue (%.3E) is less than thr (%.3E). "
"Please use 'cano_orth' instead." % (numpy.min(e), thr)
)
U = reduce(numpy.dot, (u, numpy.diag(e**-0.5), u.conj().T))
# U = reduce(numpy.dot, (u/numpy.sqrt(e), u.conj().T))
Expand Down
Loading