Skip to content

Commit

Permalink
one last ruff format call
Browse files Browse the repository at this point in the history
  • Loading branch information
mcocdawc committed Nov 20, 2024
1 parent 5792835 commit 0365aee
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 50 deletions.
14 changes: 7 additions & 7 deletions example/molbe_dmrg_block2.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@

# Next, run BE-DMRG with default parameters and maxM=100.
mybe.oneshot(
solver='block2', # or 'DMRG', 'DMRGSCF', 'DMRGCI'
scratch_dir=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_dir=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 Down Expand Up @@ -136,5 +136,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.
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
package_dir={"": "src"},
python_requires=">=3.7",
install_requires=[
'numpy>=1.22.0',
'scipy>=1.7.0',
'pyscf>=2.0.0',
'matplotlib',
'libdmet @ git+https://github.com/gkclab/libdmet_preview.git',
"numpy>=1.22.0",
"scipy>=1.7.0",
"pyscf>=2.0.0",
"matplotlib",
"libdmet @ git+https://github.com/gkclab/libdmet_preview.git",
],
)
1 change: 0 additions & 1 deletion src/molbe/external/lo_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def get_symm_mat_pow(A, p, check_symm=True, thresh=1.0e-8):


def get_aoind_by_atom(mol, atomind_by_motif=None):

natom = mol.natm
aoslice_by_atom = mol.aoslice_by_atom()
aoshift_by_atom = [0] + [aoslice_by_atom[ia][-1] for ia in range(natom)]
Expand Down
2 changes: 0 additions & 2 deletions src/molbe/lo.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ def localize(
self.lmo_coeff = self.W.T @ self.S @ self.C[:, self.ncore :]

elif lo_method == "iao":

loc_type = "SO"
val_basis = "sto-3g"

Expand Down Expand Up @@ -468,7 +467,6 @@ def localize(
self.lmo_coeff = self.W.T @ self.S @ self.C[:, self.ncore :]

elif lo_method == "boys":

es_, vs_ = eigh(self.S)
edx = es_ > 1.0e-15
W_ = numpy.dot(vs_[:, edx] / numpy.sqrt(es_[edx]), vs_[:, edx].T)
Expand Down
1 change: 1 addition & 0 deletions src/molbe/mbe.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class BE:
lo_method : str
Method for orbital localization, default is 'lowdin'.
"""

def __init__(
self,
mf,
Expand Down
1 change: 0 additions & 1 deletion src/molbe/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ def be2puffin(
use_df = False
jk = None
elif use_df and jk is None:

mf = scf.RHF(mol).density_fit(auxbasis=df_aux_basis)
else:
mf = scf.RHF(mol)
Expand Down
1 change: 0 additions & 1 deletion src/molbe/pfrag.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ def scf(
Alpha (0) or beta (1) spin for unrestricted calculation, by default None
"""


if self._mf is not None:
self._mf = None
if self._mc is not None:
Expand Down
1 change: 0 additions & 1 deletion src/molbe/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ def be_func(
rdm1_tmp = make_rdm1_ccsd_t1(fobj.t1)

elif solver == "FCI":

mc = fci.FCI(fobj._mf, fobj._mf.mo_coeff)
efci, civec = mc.kernel()
rdm1_tmp = mc.make_rdm1(civec, mc.norb, mc.nelec)
Expand Down
12 changes: 10 additions & 2 deletions src/molbe/ube.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,16 @@ def oneshot(
print(flush=True)

self.ebe_tot = E + self.uhf_full_e
print("Total Energy : {:>12.8f} Ha".format((self.ebe_tot), ))
print("Corr Energy : {:>12.8f} Ha".format((E), ))
print(
"Total Energy : {:>12.8f} Ha".format(
(self.ebe_tot),
)
)
print(
"Corr Energy : {:>12.8f} Ha".format(
(E),
)
)

if clean_eri == True:
try:
Expand Down
6 changes: 4 additions & 2 deletions tests/dmrg_molBE_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ class TestBE_DMRG(unittest.TestCase):
except ImportError:
dmrgscf = None

@unittest.skipIf(not os.getenv("QUEMB_DO_KNOWN_TO_FAIL_TESTS") == "true",
reason="This test is known to fail.")
@unittest.skipIf(
not os.getenv("QUEMB_DO_KNOWN_TO_FAIL_TESTS") == "true",
reason="This test is known to fail.",
)
def test_h8_sto3g_pipek(self):
mol = gto.M()
mol.atom = [["H", (0.0, 0.0, i * 1.2)] for i in range(8)]
Expand Down
6 changes: 3 additions & 3 deletions tests/molbe_h8_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def prepare_system():
return mol, mf


def do_BE(mol, mf, be_type : str, only_chem : bool):
def do_BE(mol, mf, be_type: str, only_chem: bool):
fobj = fragpart(be_type=be_type, mol=mol)
mybe = BE(mf, fobj)
mybe.optimize(solver="FCI", only_chem=only_chem)
Expand Down Expand Up @@ -64,6 +64,6 @@ def test_BE_chemical_potential():
assert np.isclose(BE3.ebe_tot - BE3.ebe_hf, -0.1332017928466369)


if __name__ == '__main__':
if __name__ == "__main__":
test_BE_chemical_potential()
test_BE_density_matching()
test_BE_density_matching()
29 changes: 18 additions & 11 deletions tests/molbe_io_fcidump_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ def prepare_system():
# Read in molecular integrals expressed in libint basis ordering
# numpy.loadtxt takes care of the input under the hood
mol, mf = libint2pyscf(
"data/distorted_octane.xyz", "data/hcore_libint_octane.dat",
"STO-3G", hcore_skiprows=1
"data/distorted_octane.xyz",
"data/hcore_libint_octane.dat",
"STO-3G",
hcore_skiprows=1,
)
with with_omp_threads(1):
# multi-threaded HF execution can lead to non-deterministic
Expand All @@ -34,7 +36,7 @@ def prepare_system():
return oct_be


def verify_fcidump_writing(kind_of_MO : str):
def verify_fcidump_writing(kind_of_MO: str):
oct_be = prepare_system()
tmp_dir = Path(mkdtemp())
data_dir = Path("data/octane_FCIDUMPs/")
Expand All @@ -44,27 +46,32 @@ def verify_fcidump_writing(kind_of_MO : str):
be2fcidump(oct_be, str(tmp_dir / kind_of_MO / "octane"), kind_of_MO)

for i in range(6):
reference = fcidump.read(data_dir / kind_of_MO / f'octanef{i}')
new = fcidump.read(tmp_dir / kind_of_MO / f'octanef{i}')
reference = fcidump.read(data_dir / kind_of_MO / f"octanef{i}")
new = fcidump.read(tmp_dir / kind_of_MO / f"octanef{i}")

for key in ['H1', 'H2']:
for key in ["H1", "H2"]:
if not np.allclose(new[key], reference[key]):
print(abs(new[key] - reference[key]).max())
raise ValueError("too large difference")
rmtree(tmp_dir)


@pytest.mark.skipif(not os.getenv("QUEMB_DO_KNOWN_TO_FAIL_TESTS") == "true",
reason="This test is known to fail.")
@pytest.mark.skipif(
not os.getenv("QUEMB_DO_KNOWN_TO_FAIL_TESTS") == "true",
reason="This test is known to fail.",
)
def test_embedding():
verify_fcidump_writing("embedding")


@pytest.mark.skipif(not os.getenv("QUEMB_DO_KNOWN_TO_FAIL_TESTS") == "true",
reason="This test is known to fail.")
@pytest.mark.skipif(
not os.getenv("QUEMB_DO_KNOWN_TO_FAIL_TESTS") == "true",
reason="This test is known to fail.",
)
def test_fragment_mo():
verify_fcidump_writing("fragment_mo")

if __name__ == '__main__':

if __name__ == "__main__":
test_embedding()
test_fragment_mo()
8 changes: 5 additions & 3 deletions tests/molbe_octane_get_rdms_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
# energies etc.
# At the moment the test fails already for technical reasons.

@pytest.mark.skipif(not os.getenv("QUEMB_DO_KNOWN_TO_FAIL_TESTS") == "true",
reason="This test is known to fail.")

@pytest.mark.skipif(
not os.getenv("QUEMB_DO_KNOWN_TO_FAIL_TESTS") == "true",
reason="This test is known to fail.",
)
def test_rdm():
# Perform pyscf HF calculation to get mol & mf objects
mol = gto.M(
Expand Down Expand Up @@ -48,7 +51,6 @@ def test_rdm():
charge=0,
)


mf = scf.RHF(mol)
mf.conv_tol = 1e-12
mf.kernel()
Expand Down
8 changes: 5 additions & 3 deletions tests/molbe_octane_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
# TODO: actually add meaningful tests for energies etc.
# At the moment the test fails already for technical reasons.

@pytest.mark.skipif(not os.getenv("QUEMB_DO_KNOWN_TO_FAIL_TESTS") == "true",
reason="This test is known to fail.")

@pytest.mark.skipif(
not os.getenv("QUEMB_DO_KNOWN_TO_FAIL_TESTS") == "true",
reason="This test is known to fail.",
)
def test_octane_molbe():
# Perform pyscf HF calculation to get mol & mf objects
mol = gto.M(
Expand Down Expand Up @@ -48,7 +51,6 @@ def test_octane_molbe():
charge=0,
)


mf = scf.RHF(mol)
mf.conv_tol = 1e-12
mf.kernel()
Expand Down
8 changes: 4 additions & 4 deletions tests/molbe_oneshot_rbe_qmmm-fromchk_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
# misc/be2puffin



@pytest.mark.skipif(not os.getenv("QUEMB_DO_KNOWN_TO_FAIL_TESTS") == "true",
reason="This test is known to fail because the check file "
"does not exist.")
@pytest.mark.skipif(
not os.getenv("QUEMB_DO_KNOWN_TO_FAIL_TESTS") == "true",
reason="This test is known to fail because the check file " "does not exist.",
)
def test_rbe_qmmm_fromchk():
charges = [-0.2, -0.1, 0.15, 0.2]
coords = [(-3, -8, -2), (-2, 6, 1), (2, -5, 2), (1, 8, 1.5)]
Expand Down
8 changes: 4 additions & 4 deletions tests/ube-oneshot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class TestOneShot_Unrestricted(unittest.TestCase):
@unittest.skipIf(
not os.getenv("QUEMB_DO_KNOWN_TO_FAIL_TESTS") == "true",
"This test is known to fail."
"This test is known to fail.",
)
def test_hexene_anion_sto3g_frz_ben(self):
# Linear Equidistant (r=1Å) H8 Chain, STO-3G
Expand All @@ -39,7 +39,7 @@ def test_hexene_anion_sto3g_frz_ben(self):

@unittest.skipIf(
not os.getenv("QUEMB_DO_KNOWN_TO_FAIL_TESTS") == "true",
"This test is known to fail."
"This test is known to fail.",
)
def test_hexene_cation_sto3g_frz_ben(self):
# Linear Equidistant (r=1Å) H8 Chain, cc-pVDZ
Expand All @@ -61,7 +61,7 @@ def test_hexene_cation_sto3g_frz_ben(self):

@unittest.skipIf(
not os.getenv("QUEMB_DO_KNOWN_TO_FAIL_TESTS") == "true",
"This test is known to fail."
"This test is known to fail.",
)
def test_hexene_anion_sto3g_unfrz_ben(self):
# Octane, STO-3G
Expand All @@ -83,7 +83,7 @@ def test_hexene_anion_sto3g_unfrz_ben(self):

@unittest.skipIf(
not os.getenv("QUEMB_DO_KNOWN_TO_FAIL_TESTS") == "true",
"This test is known to fail."
"This test is known to fail.",
)
def test_hexene_cation_sto3g_unfrz_ben(self):
mol = gto.M()
Expand Down

0 comments on commit 0365aee

Please sign in to comment.