From e39a14d1e231d76865a26c8213d946c5812553b2 Mon Sep 17 00:00:00 2001 From: Wong Zi Cheng <70616433+chmwzc@users.noreply.github.com> Date: Wed, 20 Dec 2023 03:43:24 +0000 Subject: [PATCH] Comment out run_psi4 code Also cleaned up conf.py in the docs --- doc/source/conf.py | 9 +- src/qibochem/driver/molecule.py | 154 +++++++++++++++----------------- 2 files changed, 73 insertions(+), 90 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index dd9062a..d2fd561 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -13,7 +13,6 @@ import sys from recommonmark.transform import AutoStructify -from sphinx.ext.autodoc import between sys.path.insert(0, os.path.abspath("..")) @@ -36,16 +35,14 @@ extensions = [ "sphinx.ext.autodoc", - "sphinx.ext.napoleon", "sphinx.ext.doctest", "sphinx.ext.coverage", - "recommonmark", - "sphinxcontrib.katex", "sphinx.ext.napoleon", "sphinx.ext.intersphinx", "sphinx_copybutton", "recommonmark", "nbsphinx", + "sphinxcontrib.katex", ] # Add any paths that contain templates here, relative to this directory. @@ -134,10 +131,6 @@ def setup(app): app.add_config_value("recommonmark_config", {"enable_eval_rst": True}, True) app.add_transform(AutoStructify) app.add_css_file("css/style.css") - # Register a sphinx.ext.autodoc.between listener to ignore everything - # between lines that contain the word IGNORE - app.connect("autodoc-process-docstring", between("^.*IGNORE.*$", exclude=True)) - return app html_show_sourcelink = False diff --git a/src/qibochem/driver/molecule.py b/src/qibochem/driver/molecule.py index 7f56e3b..a75007a 100644 --- a/src/qibochem/driver/molecule.py +++ b/src/qibochem/driver/molecule.py @@ -169,88 +169,78 @@ def run_pyscf(self, max_scf_cycles=50): tei = np.einsum("pqrs->prsq", eri4) self.tei = tei - """ - IGNORE - def run_psi4(self, output=None): - IGNORE - """ - """ - IGNORE - Run a Hartree-Fock calculation with PSI4 to obtain the molecular quantities and - molecular integrals - - Args: - output: Name of PSI4 output file. ``None`` suppresses the output on non-Windows systems, - and uses ``psi4_output.dat`` otherwise - IGNORE - """ - """ - IGNORE - import psi4 # pylint: disable=import-error - - # PSI4 input string - chgmul_string = f"{self.charge} {self.multiplicity} \n" - geom_string = "\n".join("{} {:.6f} {:.6f} {:.6f}".format(_atom[0], *_atom[1]) for _atom in self.geometry) - opt1_string = "\n\nunits angstrom\nsymmetry c1\n" - mol_string = f"{chgmul_string}{geom_string}{opt1_string}" - # PSI4 calculation options - opts = {"basis": self.basis, "scf_type": "direct", "reference": "rhf", "save_jk": True} - psi4.core.clean() - psi4.set_memory("500 MB") - psi4.set_options(opts) - # Keep the output file of the PSI4 calculation? - if output is None: - # Doesn't work on Windows! - # See: https://psicode.org/psi4manual/master/api/psi4.core.be_quiet.html - try: - psi4.core.be_quiet() - except RuntimeError: - psi4.core.set_output_file("psi4_output.dat", False) - else: - psi4.core.set_output_file(output, False) - - # Run HF calculation with PSI4 - psi4_mol = psi4.geometry(mol_string) - ehf, wavefn = psi4.energy("hf", return_wfn=True) - - # Save 1- and 2-body integrals - ca = wavefn.Ca() # MO coefficients - self.ca = np.asarray(ca) - # 1- electron integrals - oei = wavefn.H() # 'Core' (potential + kinetic) integrals - # Convert from AO->MO basis - oei = np.einsum("ab,bc->ac", oei, self.ca) - oei = np.einsum("ab,ac->bc", self.ca, oei) - - # 2- electron integrals - mints = psi4.core.MintsHelper(wavefn.basisset()) - tei = np.asarray(mints.mo_eri(ca, ca, ca, ca)) # Need original C_a array, not a np.array - tei = np.einsum("pqrs->prsq", tei) - - # Fill in the class attributes - self.nelec = (wavefn.nalpha(), wavefn.nbeta()) - self.nalpha = self.nelec[0] - self.nbeta = self.nelec[1] - self.e_hf = ehf - self.e_nuc = psi4_mol.nuclear_repulsion_energy() - self.norb = wavefn.nmo() - self.nso = 2 * self.norb - self.oei = oei - self.tei = tei - self.aoeri = np.asarray(mints.ao_eri()) - self.overlap = np.asarray(wavefn.S()) - self.eps = np.asarray(wavefn.epsilon_a()) - self.fa = np.asarray(wavefn.Fa()) - self.hcore = np.asarray(wavefn.H()) - - self.ja = np.asarray(wavefn.jk().J()[0]) - self.ka = np.asarray(wavefn.jk().K()[0]) - - ca_occ = self.ca[:, 0 : self.nalpha] - self.pa = ca_occ @ ca_occ.T - self.da = self.ca.T @ self.overlap @ self.pa @ self.overlap @ self.ca - IGNORE - """ + # def run_psi4(self, output=None): + # """ + # Run a Hartree-Fock calculation with PSI4 to obtain the molecular quantities and + # molecular integrals + + # Args: + # output: Name of PSI4 output file. ``None`` suppresses the output on non-Windows systems, + # and uses ``psi4_output.dat`` otherwise + # """ + # import psi4 # pylint: disable=import-error + + # # PSI4 input string + # chgmul_string = f"{self.charge} {self.multiplicity} \n" + # geom_string = "\n".join("{} {:.6f} {:.6f} {:.6f}".format(_atom[0], *_atom[1]) for _atom in self.geometry) + # opt1_string = "\n\nunits angstrom\nsymmetry c1\n" + # mol_string = f"{chgmul_string}{geom_string}{opt1_string}" + # # PSI4 calculation options + # opts = {"basis": self.basis, "scf_type": "direct", "reference": "rhf", "save_jk": True} + # psi4.core.clean() + # psi4.set_memory("500 MB") + # psi4.set_options(opts) + # # Keep the output file of the PSI4 calculation? + # if output is None: + # # Doesn't work on Windows! + # # See: https://psicode.org/psi4manual/master/api/psi4.core.be_quiet.html + # try: + # psi4.core.be_quiet() + # except RuntimeError: + # psi4.core.set_output_file("psi4_output.dat", False) + # else: + # psi4.core.set_output_file(output, False) + + # # Run HF calculation with PSI4 + # psi4_mol = psi4.geometry(mol_string) + # ehf, wavefn = psi4.energy("hf", return_wfn=True) + + # # Save 1- and 2-body integrals + # ca = wavefn.Ca() # MO coefficients + # self.ca = np.asarray(ca) + # # 1- electron integrals + # oei = wavefn.H() # 'Core' (potential + kinetic) integrals + # # Convert from AO->MO basis + # oei = np.einsum("ab,bc->ac", oei, self.ca) + # oei = np.einsum("ab,ac->bc", self.ca, oei) + + # # 2- electron integrals + # mints = psi4.core.MintsHelper(wavefn.basisset()) + # tei = np.asarray(mints.mo_eri(ca, ca, ca, ca)) # Need original C_a array, not a np.array + # tei = np.einsum("pqrs->prsq", tei) + + # # Fill in the class attributes + # self.nelec = (wavefn.nalpha(), wavefn.nbeta()) + # self.nalpha = self.nelec[0] + # self.nbeta = self.nelec[1] + # self.e_hf = ehf + # self.e_nuc = psi4_mol.nuclear_repulsion_energy() + # self.norb = wavefn.nmo() + # self.nso = 2 * self.norb + # self.oei = oei + # self.tei = tei + # self.aoeri = np.asarray(mints.ao_eri()) + # self.overlap = np.asarray(wavefn.S()) + # self.eps = np.asarray(wavefn.epsilon_a()) + # self.fa = np.asarray(wavefn.Fa()) + # self.hcore = np.asarray(wavefn.H()) + + # self.ja = np.asarray(wavefn.jk().J()[0]) + # self.ka = np.asarray(wavefn.jk().K()[0]) + + # ca_occ = self.ca[:, 0 : self.nalpha] + # self.pa = ca_occ @ ca_occ.T + # self.da = self.ca.T @ self.overlap @ self.pa @ self.overlap @ self.ca # HF embedding functions def _inactive_fock_matrix(self, frozen):