def test_convert_cplx(self): nmo = 17 nelec = (3,3) h1e, chol, enuc, eri = generate_hamiltonian(nmo, nelec, cplx=True, sym=4) write_qmcpack_sparse(h1e, chol.reshape((-1,nmo*nmo)).T.copy(), nelec, nmo, e0=enuc, real_chol=False) hamil = read_qmcpack_hamiltonian('hamiltonian.h5') write_fcidump('FCIDUMP', hamil['hcore'], hamil['chol'], hamil['enuc'], hamil['nmo'], hamil['nelec'], sym=4, cplx=True) h1e_r, eri_r, enuc_r, nelec_r = read_fcidump('FCIDUMP', symmetry=4, verbose=False) dm = numpy.zeros((nmo,nmo)) dm[(0,1,2),(0,1,2)] = 1.0 eri_r = eri_r.transpose((0,1,3,2)).reshape((nmo*nmo,nmo*nmo)) chol_r = modified_cholesky_direct(eri_r, tol=1e-8, verbose=False) chol_r = chol_r.reshape((-1,nmo,nmo)) self.assertAlmostEqual(numpy.einsum('ij,ij->', dm, h1e-h1e_r).real, 0.0) self.assertAlmostEqual(numpy.einsum('ij,nij->', dm, chol-chol_r).real, 0.0) # Test integral only appears once in file. h1e_r, eri_r, enuc_r, nelec_r = read_fcidump('FCIDUMP', symmetry=1, verbose=False) i,k,j,l = (1,0,0,0) ikjl = (i,k,j,l) jlik = (j,l,i,k) kilj = (k,i,l,j) ljki = (l,j,k,i) d1 = eri_r[ikjl] - eri_r[kilj].conj() d2 = eri_r[ikjl] - eri_r[jlik] d3 = eri_r[ikjl] - eri_r[ljki].conj() self.assertAlmostEqual(d1,0.0) self.assertAlmostEqual(d2,0.0) self.assertAlmostEqual(d3,-0.00254428836-0.00238852605j)
def test_convert_real(self): nmo = 17 nelec = (3,3) h1e, chol, enuc, eri = generate_hamiltonian(nmo, nelec, cplx=False, sym=8) write_qmcpack_sparse(h1e, chol.reshape((-1,nmo*nmo)).T.copy(), nelec, nmo, e0=enuc, real_chol=True) hamil = read_qmcpack_hamiltonian('hamiltonian.h5') write_fcidump('FCIDUMP', hamil['hcore'], hamil['chol'], hamil['enuc'], hamil['nmo'], hamil['nelec'], sym=8, cplx=False) h1e_r, eri_r, enuc_r, nelec_r = read_fcidump('FCIDUMP', verbose=False) dm = numpy.zeros((nmo,nmo)) dm[(0,1,2),(0,1,2)] = 1.0 eri_r = eri_r.transpose((0,1,3,2)).reshape((nmo*nmo,nmo*nmo)) chol_r = modified_cholesky_direct(eri_r, tol=1e-8, verbose=False) chol_r = chol_r.reshape((-1,nmo,nmo)) self.assertAlmostEqual(numpy.einsum('ij,ij->', dm, h1e-h1e_r).real, 0.0) self.assertAlmostEqual(numpy.einsum('ij,nij->', dm, chol-chol_r).real, 0.0) # Test integral only appears once in file. h1e_r, eri_r, enuc_r, nelec_r = read_fcidump('FCIDUMP', symmetry=1, verbose=False) i,j,k,l = (0,1,2,3) combs = [ (i,j,k,l), (k,l,i,j), (j,i,l,k), (l,k,j,i), (j,i,k,l), (l,k,i,j), (i,j,l,k), (k,l,i,j), ] for c in combs: if abs(eri_r[c]) > 0: self.assertEqual(c,(l,k,j,i))
def main(args): """Convert FCIDUMP to QMCPACK readable Hamiltonian format. Parameters ---------- args : list of strings command-line arguments. """ options = parse_args(args) (hcore, eri, ecore, nelec) = read_fcidump(options.input_file, symmetry=options.symm, verbose=options.verbose) norb = hcore.shape[-1] # If the ERIs are complex then we need to form M_{(ik),(lj}} which is # Hermitian. For real integrals we will have 8-fold symmetry so trasposing # will have no effect. eri = numpy.transpose(eri, (0, 1, 3, 2)) chol = modified_cholesky_direct(eri.reshape(norb**2, norb**2), options.thresh, options.verbose, cmax=20).T.copy() cplx_chol = options.write_complex or numpy.any(abs(eri.imag) > 1e-14) write_qmcpack_sparse(hcore, chol, nelec, norb, e0=ecore, real_chol=(not cplx_chol), filename=options.output_file)
def test_cholesky_direct(self): atom = gto.M(atom='Ne 0 0 0', basis='sto-3g') eri = atom.intor('int2e', aosym='s1') self.assertEqual(eri.shape, (5, 5, 5, 5)) eri = eri.reshape(25, 25) chol = modified_cholesky_direct(eri, 1e-5, cmax=20) Mrecon = numpy.dot(chol.T, chol) self.assertTrue(numpy.allclose(Mrecon, eri, atol=1e-8, rtol=1e-6))
def generate_hamiltonian(nmo, nelec, cplx=False, sym=8): h1e = numpy.random.random((nmo,nmo)) if cplx: h1e = h1e + 1j*numpy.random.random((nmo,nmo)) eri = numpy.random.normal(scale=0.01, size=(nmo,nmo,nmo,nmo)) if cplx: eri = eri + 1j*numpy.random.normal(scale=0.01, size=(nmo,nmo,nmo,nmo)) # Restore symmetry to the integrals. if sym >= 4: # (ik|jl) = (jl|ik) # (ik|jl) = (ki|lj)* eri = eri + eri.transpose(2,3,0,1) eri = eri + eri.transpose(3,2,1,0).conj() if sym == 8: eri = eri + eri.transpose(1,0,2,3) # Construct hermitian matrix M_{ik,lj}. eri = eri.transpose((0,1,3,2)) eri = eri.reshape((nmo*nmo,nmo*nmo)) # Make positive semi-definite. eri = numpy.dot(eri,eri.conj().T) chol = modified_cholesky_direct(eri, tol=1e-4, verbose=False) chol = chol.reshape((-1,nmo,nmo)) enuc = numpy.random.rand() return h1e, chol, enuc, eri