Skip to content

Commit

Permalink
Add new examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sunqm committed Nov 30, 2019
1 parent e4f27fa commit 2a42989
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
32 changes: 32 additions & 0 deletions examples/ao2mo/04-dirac_hf_mo_integrals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python

'''
MO integral transformation for spinor integrals
'''

import h5py
from pyscf import gto
from pyscf import scf
from pyscf import lib
from pyscf.ao2mo import r_outcore

mol = gto.M(
atom = '''
O 0. 0. 0.
H 0. -0.757 0.587
H 0. 0.757 0.587
''',
basis = 'sto3g',
)

mf = scf.DHF(mol).run()

n4c, nmo = mf.mo_coeff.shape
n2c = n4c // 2
nNeg = nmo // 2
mo = mf.mo_coeff[:n2c,nNeg:]
r_outcore.general(mol, (mo, mo, mo, mo), 'llll.h5', intor='int2e_spinor')
with h5py.File('llll.h5', 'r') as f:
print('Number of DHF molecular orbitals %s' % (nmo//2))
print('MO integrals for large component orbitals. Shape = %s'
% str(f['eri_mo'].shape))
68 changes: 68 additions & 0 deletions examples/ao2mo/22-rkb_no_pair_ints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python

'''
Integral transformation to compute 2-electron integrals for no-pair
Dirac-Coulomb Hamiltonian. The molecular orbitals are based on RKB basis.
'''

import h5py
from pyscf import gto
from pyscf import scf
from pyscf import lib
from pyscf.ao2mo import r_outcore

mol = gto.M(
atom = '''
O 0. 0. 0.
H 0. -0.757 0.587
H 0. 0.757 0.587
''',
basis = 'ccpvdz',
)

mf = scf.DHF(mol).run()

def no_pair_ovov(mol, mo_coeff, erifile):
'''
2-electron integrals ( o v | o v ) for no-pair Hamiltonian under RKB basis
'''
c = lib.param.LIGHT_SPEED
n4c, nmo = mo_coeff.shape
n2c = n4c // 2
nNeg = nmo // 2
nocc = mol.nelectron
nvir = nmo // 2 - nocc
mo_pos_l = mo_coeff[:n2c,nNeg:]
mo_pos_s = mo_coeff[n2c:,nNeg:] * (.5/c)
Lo = mo_pos_l[:,:nocc]
So = mo_pos_s[:,:nocc]
Lv = mo_pos_l[:,nocc:]
Sv = mo_pos_s[:,nocc:]

dataname = 'dhf_ovov'
def run(mos, intor):
r_outcore.general(mol, mos, erifile,
dataname='tmp', intor=intor)
blksize = 400
nij = mos[0].shape[1] * mos[1].shape[1]
with h5py.File(erifile) as feri:
for i0, i1 in lib.prange(0, nij, blksize):
buf = feri[dataname][i0:i1]
buf += feri['tmp'][i0:i1]
feri[dataname][i0:i1] = buf

r_outcore.general(mol, (Lo, Lv, Lo, Lv), erifile,
dataname=dataname, intor='int2e_spinor')
run((So, Sv, So, Sv), 'int2e_spsp1spsp2_spinor')
run((So, Sv, Lo, Lv), 'int2e_spsp1_spinor' )
run((Lo, Lv, So, Sv), 'int2e_spsp2_spinor' )

no_pair_ovov(mol, mf.mo_coeff, 'dhf_ovov.h5')
with h5py.File('dhf_ovov.h5', 'r') as f:
nocc = mol.nelectron
nvir = mol.nao * 2 - nocc
print('Number of DHF occupied orbitals %s' % nocc)
print('Number of DHF virtual orbitals in positive states %s' % nvir)
print('No-pair MO integrals (ov|ov) have shape %s' % str(f['dhf_ovov'].shape))


0 comments on commit 2a42989

Please sign in to comment.