|
14 | 14 | from __future__ import absolute_import |
15 | 15 |
|
16 | 16 | import numpy |
17 | | -import unittest |
18 | 17 |
|
19 | 18 | from openfermionpyscf import prepare_pyscf_molecule |
20 | 19 | from openfermionpyscf import PyscfMolecularData |
21 | 20 | from pyscf import scf, mp, ci, cc, fci |
22 | 21 |
|
23 | 22 |
|
24 | | -class PyscfMolecularDataTest(unittest.TestCase): |
| 23 | +geometry = [('H', (0., 0., 0.)), ('H', (0., 0., 0.7414))] |
| 24 | +basis = '6-31g' |
| 25 | +multiplicity = 1 |
| 26 | +charge = 0 |
| 27 | +molecule = PyscfMolecularData(geometry, |
| 28 | + basis, |
| 29 | + multiplicity, |
| 30 | + charge) |
25 | 31 |
|
26 | | - def setUp(self): |
27 | | - geometry = [('H', (0., 0., 0.)), ('H', (0., 0., 0.7414))] |
28 | | - basis = '6-31g' |
29 | | - multiplicity = 1 |
30 | | - charge = 0 |
31 | | - self.molecule = PyscfMolecularData(geometry, |
32 | | - basis, |
33 | | - multiplicity, |
34 | | - charge) |
| 32 | +mol = prepare_pyscf_molecule(molecule) |
| 33 | +mol.verbose = 0 |
| 34 | +molecule._pyscf_data['mol'] = mol |
| 35 | +molecule._pyscf_data['scf'] = mf = scf.RHF(mol).run() |
| 36 | +molecule._pyscf_data['mp2'] = mp.MP2(mf).run() |
| 37 | +molecule._pyscf_data['cisd'] = ci.CISD(mf).run() |
| 38 | +molecule._pyscf_data['ccsd'] = cc.CCSD(mf).run() |
| 39 | +molecule._pyscf_data['fci'] = fci.FCI(mf).run() |
35 | 40 |
|
36 | | - mol = prepare_pyscf_molecule(self.molecule) |
37 | | - mol.verbose = 0 |
38 | | - self.molecule._pyscf_data['mol'] = mol |
39 | | - self.molecule._pyscf_data['scf'] = mf = scf.RHF(mol).run() |
40 | | - self.molecule._pyscf_data['mp2'] = mp.MP2(mf).run() |
41 | | - self.molecule._pyscf_data['cisd'] = ci.CISD(mf).run() |
42 | | - self.molecule._pyscf_data['ccsd'] = cc.CCSD(mf).run() |
43 | | - self.molecule._pyscf_data['fci'] = fci.FCI(mf).run() |
44 | 41 |
|
45 | | - def test_accessing_rdm(self): |
46 | | - molecule = self.molecule |
47 | | - mo = molecule.canonical_orbitals |
48 | | - overlap = molecule.overlap_integrals |
49 | | - h1 = molecule.one_body_integrals |
50 | | - h2 = molecule.two_body_integrals |
51 | | - mf = molecule._pyscf_data['scf'] |
52 | | - e_core = mf.energy_nuc() |
| 42 | +def test_accessing_rdm(): |
| 43 | + mo = molecule.canonical_orbitals |
| 44 | + overlap = molecule.overlap_integrals |
| 45 | + h1 = molecule.one_body_integrals |
| 46 | + h2 = molecule.two_body_integrals |
| 47 | + mf = molecule._pyscf_data['scf'] |
| 48 | + e_core = mf.energy_nuc() |
53 | 49 |
|
54 | | - rdm1 = molecule.cisd_one_rdm |
55 | | - rdm2 = molecule.cisd_two_rdm |
56 | | - e_ref = molecule._pyscf_data['cisd'].e_tot |
57 | | - e_tot = (numpy.einsum('pq,pq', h1, rdm1) + |
58 | | - numpy.einsum('pqrs,pqrs', h2, rdm2) * .5 + e_core) |
59 | | - self.assertAlmostEqual(e_tot, e_ref, 9) |
| 50 | + rdm1 = molecule.cisd_one_rdm |
| 51 | + rdm2 = molecule.cisd_two_rdm |
| 52 | + e_ref = molecule._pyscf_data['cisd'].e_tot |
| 53 | + e_tot = (numpy.einsum('pq,pq', h1, rdm1) + |
| 54 | + numpy.einsum('pqrs,pqrs', h2, rdm2) * .5 + e_core) |
| 55 | + numpy.testing.assert_almost_equal(e_tot, e_ref, 9) |
60 | 56 |
|
61 | | - rdm1 = molecule.ccsd_one_rdm |
62 | | - rdm2 = molecule.ccsd_two_rdm |
63 | | - e_ref = molecule._pyscf_data['ccsd'].e_tot |
64 | | - e_tot = (numpy.einsum('pq,pq', h1, rdm1) + |
65 | | - numpy.einsum('pqrs,pqrs', h2, rdm2) * .5 + e_core) |
66 | | - self.assertAlmostEqual(e_tot, e_ref, 7) |
| 57 | + rdm1 = molecule.ccsd_one_rdm |
| 58 | + rdm2 = molecule.ccsd_two_rdm |
| 59 | + e_ref = molecule._pyscf_data['ccsd'].e_tot |
| 60 | + e_tot = (numpy.einsum('pq,pq', h1, rdm1) + |
| 61 | + numpy.einsum('pqrs,pqrs', h2, rdm2) * .5 + e_core) |
| 62 | + numpy.testing.assert_almost_equal(e_tot, e_ref, 7) |
67 | 63 |
|
68 | | - rdm1 = molecule.fci_one_rdm |
69 | | - rdm2 = molecule.fci_two_rdm |
70 | | - #e_ref = molecule._pyscf_data['fci'].e_tot |
71 | | - e_tot = (numpy.einsum('pq,pq', h1, rdm1) + |
72 | | - numpy.einsum('pqrs,pqrs', h2, rdm2) * .5 + e_core) |
73 | | - self.assertAlmostEqual(e_tot, -1.1516827321, 9) |
| 64 | + rdm1 = molecule.fci_one_rdm |
| 65 | + rdm2 = molecule.fci_two_rdm |
| 66 | + #e_ref = molecule._pyscf_data['fci'].e_tot |
| 67 | + e_tot = (numpy.einsum('pq,pq', h1, rdm1) + |
| 68 | + numpy.einsum('pqrs,pqrs', h2, rdm2) * .5 + e_core) |
| 69 | + numpy.testing.assert_almost_equal(e_tot, -1.1516827321, 9) |
| 70 | + |
| 71 | + ccsd_t1 = molecule.ccsd_single_amps |
| 72 | + ccsd_t2 = molecule.ccsd_double_amps |
74 | 73 |
|
75 | | - ccsd_t1 = molecule.ccsd_single_amps |
76 | | - ccsd_t2 = molecule.ccsd_double_amps |
77 | 74 |
|
0 commit comments