From eb17fdfe205b3798f8d8377a169c76900e173949 Mon Sep 17 00:00:00 2001 From: Matthew R Hermes Date: Wed, 18 Sep 2024 10:56:57 -0500 Subject: [PATCH] More CSF configuration printout and example (#124) --- examples/csf/csf_fci.py | 25 +++++++++++++++++++++++++ my_pyscf/fci/csf.py | 7 +++++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 examples/csf/csf_fci.py diff --git a/examples/csf/csf_fci.py b/examples/csf/csf_fci.py new file mode 100644 index 00000000..db7cb47e --- /dev/null +++ b/examples/csf/csf_fci.py @@ -0,0 +1,25 @@ +from pyscf import gto, fci, scf, lib, ao2mo +from mrh.my_pyscf.fci import csf_solver + +mol = gto.M (atom='H 0 0 0; F 0 0 1.1', basis='sto3g', output='csf_fci.log', + verbose=lib.logger.INFO) +mf = scf.RHF (mol).run () + +h0 = mf.energy_nuc () +h1 = mf.get_hcore () +h2 = ao2mo.restore (1, mf._eri, mol.nao_nr ()) + +cisolver = csf_solver (mol, smult=1) + +# Print how many CSFs, and other information, to stdout. You need to set # of orbs and electrons +print ("Singlet configuration:") +cisolver.print_transformer_cache (norb=mol.nao_nr (), nelec=mol.nelec) +print ("Singlet energy:", cisolver.kernel (h1,h2,mol.nao_nr(),mol.nelec,ecore=h0)[0]) + +# Number of orbs and electrons as well as spin multiplicity will be stored after running kernel +e = cisolver.kernel (h1,h2,mol.nao_nr(),mol.nelec,smult=3,ecore=h0)[0] +print ("\nTriplet configuration:") +cisolver.print_transformer_cache () +print ("Triplet energy:", e) + + diff --git a/my_pyscf/fci/csf.py b/my_pyscf/fci/csf.py index 14a1d02e..dc65aa37 100644 --- a/my_pyscf/fci/csf.py +++ b/my_pyscf/fci/csf.py @@ -530,7 +530,7 @@ def pspace (self, h1e, eri, norb, nelec, hdiag_det=None, hdiag_csf=None, npsp=20 return pspace (self, h1e, eri, norb, nelec, self.transformer, hdiag_det=hdiag_det, hdiag_csf=hdiag_csf, npsp=npsp, max_memory=max_memory) - def log_transformer_cache (self, tverbose=lib.logger.INFO, **kwargs): + def log_transformer_cache (self, tverbose=0, **kwargs): if len (kwargs): self.__dict__.update (kwargs) self.check_transformer_cache () @@ -538,9 +538,12 @@ def log_transformer_cache (self, tverbose=lib.logger.INFO, **kwargs): return log = lib.logger.new_logger (self, self.verbose) printer = (lambda *args, **kwargs: None, log.error, log.warn, log.note, log.info, - log.debug, log.debug1, log.debug2, log.debug3, log.debug4)[tverbose] + log.debug, log.debug1, log.debug2, log.debug3, log.debug4, print)[tverbose] self.transformer.print_config (printer) + def print_transformer_cache (self, **kwargs): + return self.log_transformer_cache (10, **kwargs) + class FCISolver (CSFFCISolver, direct_spin1.FCISolver): r''' get_init_guess uses csfstring.py and csdstring.py to construct a spin-symmetry-adapted initial guess, and the Davidson algorithm is carried out in the CSF basis. However, the ci attribute is put in the determinant basis at the end of it all, and "ci0" is also assumed