From 0365aeeba0ff05d3ca2a9eccc7857adaeabb81ca Mon Sep 17 00:00:00 2001 From: Oskar Weser Date: Wed, 20 Nov 2024 11:35:06 -0500 Subject: [PATCH] one last `ruff format` call --- example/molbe_dmrg_block2.py | 14 +++++----- setup.py | 10 +++---- src/molbe/external/lo_helper.py | 1 - src/molbe/lo.py | 2 -- src/molbe/mbe.py | 1 + src/molbe/misc.py | 1 - src/molbe/pfrag.py | 1 - src/molbe/solver.py | 1 - src/molbe/ube.py | 12 ++++++-- tests/dmrg_molBE_test.py | 6 ++-- tests/molbe_h8_test.py | 6 ++-- tests/molbe_io_fcidump_test.py | 29 ++++++++++++-------- tests/molbe_octane_get_rdms_test.py | 8 ++++-- tests/molbe_octane_test.py | 8 ++++-- tests/molbe_oneshot_rbe_qmmm-fromchk_test.py | 8 +++--- tests/ube-oneshot_test.py | 8 +++--- 16 files changed, 66 insertions(+), 50 deletions(-) diff --git a/example/molbe_dmrg_block2.py b/example/molbe_dmrg_block2.py index 2f121746..e1aa4a0a 100644 --- a/example/molbe_dmrg_block2.py +++ b/example/molbe_dmrg_block2.py @@ -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 @@ -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. diff --git a/setup.py b/setup.py index c78a9b0d..e8bb6d95 100644 --- a/setup.py +++ b/setup.py @@ -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", ], ) diff --git a/src/molbe/external/lo_helper.py b/src/molbe/external/lo_helper.py index 8e298cd5..4d5dad11 100644 --- a/src/molbe/external/lo_helper.py +++ b/src/molbe/external/lo_helper.py @@ -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)] diff --git a/src/molbe/lo.py b/src/molbe/lo.py index 16d0b522..a5023d0e 100644 --- a/src/molbe/lo.py +++ b/src/molbe/lo.py @@ -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" @@ -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) diff --git a/src/molbe/mbe.py b/src/molbe/mbe.py index eb670192..680019b1 100644 --- a/src/molbe/mbe.py +++ b/src/molbe/mbe.py @@ -67,6 +67,7 @@ class BE: lo_method : str Method for orbital localization, default is 'lowdin'. """ + def __init__( self, mf, diff --git a/src/molbe/misc.py b/src/molbe/misc.py index 2d1ac67e..629c809f 100644 --- a/src/molbe/misc.py +++ b/src/molbe/misc.py @@ -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) diff --git a/src/molbe/pfrag.py b/src/molbe/pfrag.py index 5e8ba0ab..fddd63ea 100644 --- a/src/molbe/pfrag.py +++ b/src/molbe/pfrag.py @@ -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: diff --git a/src/molbe/solver.py b/src/molbe/solver.py index ae26e33b..dbc09dfd 100644 --- a/src/molbe/solver.py +++ b/src/molbe/solver.py @@ -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) diff --git a/src/molbe/ube.py b/src/molbe/ube.py index 3f556fc8..214c4a4d 100644 --- a/src/molbe/ube.py +++ b/src/molbe/ube.py @@ -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: diff --git a/tests/dmrg_molBE_test.py b/tests/dmrg_molBE_test.py index ff7a9505..cb151a9e 100644 --- a/tests/dmrg_molBE_test.py +++ b/tests/dmrg_molBE_test.py @@ -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)] diff --git a/tests/molbe_h8_test.py b/tests/molbe_h8_test.py index fb88bcd2..d3cdb86f 100644 --- a/tests/molbe_h8_test.py +++ b/tests/molbe_h8_test.py @@ -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) @@ -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() \ No newline at end of file + test_BE_density_matching() diff --git a/tests/molbe_io_fcidump_test.py b/tests/molbe_io_fcidump_test.py index 9d4d9a7b..98b9e091 100644 --- a/tests/molbe_io_fcidump_test.py +++ b/tests/molbe_io_fcidump_test.py @@ -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 @@ -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/") @@ -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() diff --git a/tests/molbe_octane_get_rdms_test.py b/tests/molbe_octane_get_rdms_test.py index 84beb843..01a2c0b3 100644 --- a/tests/molbe_octane_get_rdms_test.py +++ b/tests/molbe_octane_get_rdms_test.py @@ -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( @@ -48,7 +51,6 @@ def test_rdm(): charge=0, ) - mf = scf.RHF(mol) mf.conv_tol = 1e-12 mf.kernel() diff --git a/tests/molbe_octane_test.py b/tests/molbe_octane_test.py index fb400b37..83db9839 100644 --- a/tests/molbe_octane_test.py +++ b/tests/molbe_octane_test.py @@ -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( @@ -48,7 +51,6 @@ def test_octane_molbe(): charge=0, ) - mf = scf.RHF(mol) mf.conv_tol = 1e-12 mf.kernel() diff --git a/tests/molbe_oneshot_rbe_qmmm-fromchk_test.py b/tests/molbe_oneshot_rbe_qmmm-fromchk_test.py index a204ac66..0940a538 100644 --- a/tests/molbe_oneshot_rbe_qmmm-fromchk_test.py +++ b/tests/molbe_oneshot_rbe_qmmm-fromchk_test.py @@ -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)] diff --git a/tests/ube-oneshot_test.py b/tests/ube-oneshot_test.py index ba6fdaeb..3eda36ad 100644 --- a/tests/ube-oneshot_test.py +++ b/tests/ube-oneshot_test.py @@ -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 @@ -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 @@ -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 @@ -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()