Skip to content

Commit

Permalink
Improve the example of UHF Hamiltonian customization. (pyscf#2350)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunqm committed Aug 5, 2024
1 parent 1f65ec7 commit 9f93cb7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions examples/scf/40-customizing_hamiltonian.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,17 @@
# (particularly in the MO integral transformation) may ignore the customized
# Hamiltonian if memory is not enough.
mol.incore_anyway = True

#
# In the case of spin-polarized system, the get_hcore method of UHF class
# requires a tuple for the spin-up and spin-down one-electron Hamiltonian.
# To define the number of spin-up and spin-down electrons, setting the mol.spin
# attribute and assigning a tuple to mf.nelec both work.
#
mf = scf.UHF(mol)
mf.get_hcore = lambda *args: (h1, h1)
mf.get_ovlp = lambda *args: numpy.eye(n)
mf._eri = ao2mo.restore(8, eri, n)
# Setting mf.nelec below has the same effects to setting mol.spin = 2
mf.nelec = (6, 4)
mf.kernel()

0 comments on commit 9f93cb7

Please sign in to comment.