Skip to content

Commit

Permalink
More CSF configuration printout and example (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewRHermes committed Sep 18, 2024
1 parent 5c4cd25 commit eb17fdf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
25 changes: 25 additions & 0 deletions examples/csf/csf_fci.py
Original file line number Diff line number Diff line change
@@ -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)


7 changes: 5 additions & 2 deletions my_pyscf/fci/csf.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,17 +530,20 @@ 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 ()
if self.transformer is None:
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
Expand Down

0 comments on commit eb17fdf

Please sign in to comment.