Skip to content

Commit

Permalink
added selected CI example for molecules
Browse files Browse the repository at this point in the history
  • Loading branch information
sunchong137 authored and sunqm committed Oct 31, 2023
1 parent 4df5e29 commit c19cacc
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions examples/fci/02-selected_ci_mol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

#!/usr/bin/env python
#
# Author: Chong Sun <[email protected]>
#
'''
Selected CI for molecules.
'''

from pyscf import gto, scf, ao2mo, fci

mol = gto.Mole()
mol.atom = "H 0 0 0; H 0 0 1.2; H 0 0 2.4; H 0 0 3.6"
mol.unit='angstrom'
mol.basis = "631g"
mol.build()

# Run RHF
# No need to run UHF because SHCI is very accurate.
mf = scf.RHF(mol)
mf.kernel()

# Rotate the Hamiltonians
norb = mol.nao
nelec = mol.nelectron
mo_coeff = mf.mo_coeff
h1e = mf.get_hcore()
eri = mf._eri
h1e_mo = mo_coeff.T @ h1e @ mo_coeff
eri_mo = ao2mo.kernel(eri, mo_coeff, compact=False).reshape(norb, norb, norb, norb)
e_nuc = mf.energy_nuc()

# Run SCI
scisolver = fci.SCI()
scisolver.max_cycle = 100
scisolver.conv_tol = 1e-8
e, civec = scisolver.kernel(h1e_mo, eri_mo, norb, nelec)
e_sci = e + e_nuc # add nuclear energy
print("Selected CI energy: {}".format(e_sci))

# Compared to FCI
fcisolver = fci.FCI(mf)
e_fci, fcivec = fcisolver.kernel()
print("Difference compared to FCI: {}".format(e_fci - e_sci))

0 comments on commit c19cacc

Please sign in to comment.