Exemple #1
0
def plot_h2_lineplot():
    bfs = basisset(h2,'6-31G')
    solver = rhf(h2,bfs)
    solver.converge()
    points = [(0,0,z) for z in np.linspace(-5,5)]
    lineplot_orbs(points,solver.orbs[:,:2],bfs,True)
    return
Exemple #2
0
 def test_h2o_averaging(self):
     from pyquante2.scf.iterators import AveragingIterator
     bfs = basisset(h2o, 'sto3g')
     solver = rhf(h2o, bfs)
     ens = solver.converge(AveragingIterator)
     self.assertAlmostEqual(solver.energy, -74.959847457272502,
                            match_digits)
Exemple #3
0
 def test_lih_averaging(self):
     from pyquante2.scf.iterators import AveragingIterator
     bfs = basisset(lih, 'sto3g')
     solver = rhf(lih, bfs)
     ens = solver.converge(AveragingIterator)
     self.assertAlmostEqual(solver.energy, -7.8607375733271088,
                            match_digits)
Exemple #4
0
 def test_lih_averaging(self):
     bfs = basisset(lih,'sto-3g')
     hamiltonian = rhf(bfs)
     iterator = AveragingIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     self.assertAlmostEqual(iterator.energy, -7.860746149768, 6)
Exemple #5
0
 def test_h2_631(self):
     bfs = basisset(h2,'6-31gss')
     hamiltonian = rhf(bfs)
     iterator = SCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     self.assertAlmostEqual(iterator.energy, -1.131333590574, 7)
Exemple #6
0
 def test_h2(self):
     bfs = basisset(h2,'sto-3g')
     hamiltonian = rhf(bfs)
     iterator = SCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     self.assertAlmostEqual(iterator.energy, -1.117099435262, 7)
Exemple #7
0
 def test_h2o_averaging(self):
     bfs = basisset(h2o,'sto-3g')
     hamiltonian = rhf(bfs)
     iterator = AveragingIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     self.assertAlmostEqual(iterator.energy, -74.959857776754, 5)
    def run_pyquante(self):
        """Runs the PyQuante calculation.

        This method is part of the public interface to allow the user to easily overwrite it in a
        subclass to further tailor the behavior to some specific use case.

        Raises:
            QiskitNatureError: If an invalid HF method type was supplied.
        """
        # pylint: disable=import-error
        from pyquante2 import rhf, uhf, rohf, basisset

        self._bfs = basisset(self._mol, self.basis.value)

        if self.method == MethodType.RHF:
            self._calc = rhf(self._mol, self._bfs)
        elif self.method == MethodType.ROHF:
            self._calc = rohf(self._mol, self._bfs)
        elif self.method == MethodType.UHF:
            self._calc = uhf(self._mol, self._bfs)
        else:
            raise QiskitNatureError(f"Invalid method type: {self.method}")

        self._calc.converge(tol=self.tol, maxiters=self.maxiters)
        logger.debug("PyQuante2 processing information:\n%s", self._calc)
Exemple #9
0
 def test_h2(self):
     bfs = basisset(h2,'6-31g**')
     solver=rhf(h2,bfs)
     solver.converge()
     nvirt = len(bfs)-h2.nocc()
     emp2 = mp2(solver.i2,solver.orbs,solver.orbe,h2.nocc(),len(bfs)-h2.nocc())
     self.assertAlmostEqual(emp2,-0.02632654197486595)
     return
Exemple #10
0
 def test_CH4(self):
     """CH4 symmetry Td"""
     bfs = basisset(ch4,'sto-3g')
     hamiltonian = rhf(bfs, twoe_factory=libint_twoe_integrals)
     iterator = SCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     self.assertAlmostEqual(iterator.energy, -39.726862723517, 6)
Exemple #11
0
 def test_CH4(self):
     """CH4 symmetry Td"""
     bfs = basisset(CH4, "sto-3g")
     solver = rhf(CH4, bfs, libint=True)
     ens = solver.converge()
     hp5("Ham.h5", solver.i1.V + solver.i1.T)
     hp5("TwoS.h5", solver.i2._2e_ints)
     self.assertPrecisionEqual(solver.energy, -39.72591203477140)
Exemple #12
0
 def test_H2(self):
     bfs = basisset(h2,'cc-pvdz')
     hamiltonian = rhf(bfs, twoe_factory=libint_twoe_integrals)
     iterator = SCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     nvirt = len(bfs)-h2.nocc()
     eccsd = ccsd(hamiltonian, iterator.orbs, iterator.orbe, h2.nocc(), nvirt)
     self.assertAlmostEqual(eccsd, -0.034544318453406, 8)
Exemple #13
0
 def test_CH4(self):
     bfs = basisset(ch4,'cc-pvdz')
     hamiltonian = rhf(bfs, twoe_factory=libint_twoe_integrals)
     iterator = SCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     nvirt = len(bfs)-ch4.nocc()
     eccsd = ccsd(hamiltonian, iterator.orbs, iterator.orbe, ch4.nocc(), nvirt)
     self.assertAlmostEqual(eccsd, -0.189626419684193, 7)
Exemple #14
0
 def test_LiH(self):
     bfs = basisset(lih,'cc-pvdz')
     hamiltonian = rhf(bfs, twoe_factory=libint_twoe_integrals)
     iterator = SCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     nvirt = len(bfs)-lih.nocc()
     eccsd = ccsd(hamiltonian, iterator.orbs, iterator.orbe, lih.nocc(), nvirt)
     self.assertAlmostEqual(eccsd, -0.032399770519793, 7)
Exemple #15
0
def plot_h2_vtk():
    bfs = basisset(h2,'sto3g')
    solver = rhf(h2,bfs)
    ens = solver.converge()

    # Note: these orbitals are not coming out symmetric. Why not??
    print(solver)
    print(solver.orbs)
    vtk_orbs(h2,solver.orbs,bfs,npts=10)
Exemple #16
0
 def test_H2(self):
     bfs = basisset(h2,'cc-pvdz')
     hamiltonian=rhf(bfs, twoe_factory=libint_twoe_integrals)
     iterator = SCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     nvirt = len(bfs)-h2.nocc()
     emp2 = mp2(hamiltonian, iterator.orbs, iterator.orbe, h2.nocc(), nvirt)
     self.assertAlmostEqual(emp2, -0.026304104341, 6)
Exemple #17
0
 def test_BrF5(self):
     """BrF5 symmetry C4v"""
     BrF5 = read_xyz('./molfiles/BrF5.xyz')
     bfs = basisset(BrF5,'sto-3g')
     hamiltonian = rhf(bfs, twoe_factory=libint_twoe_integrals)
     iterator = SCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     self.assertAlmostEqual(iterator.energy, -3035.015731331871, 4)
Exemple #18
0
 def test_HBr(self):
     """HBr"""
     HBr = read_xyz('./molfiles/HBr.xyz')
     bfs = basisset(HBr,'sto-3g')
     hamiltonian = rhf(bfs, twoe_factory=libint_twoe_integrals)
     iterator = SCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     self.assertAlmostEqual(iterator.energy, -2545.887434128302, 4)
Exemple #19
0
 def test_C2H2Cl2(self):
     """C2H2Cl2 symmetry C2H"""
     C2H2Cl2 = read_xyz('./molfiles/C2H2Cl2.xyz')
     bfs = basisset(C2H2Cl2,'sto-3g')
     hamiltonian = rhf(bfs, twoe_factory=libint_twoe_integrals)
     iterator = SCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     self.assertAlmostEqual(iterator.energy, -967.533150337277, 4)
Exemple #20
0
 def test_H2O_4(self):
     """H2O tethramer symmetry S4"""
     H2O4 = read_xyz('./molfiles/H2O_4.xyz')
     bfs = basisset(H2O4,'sto-3g')
     hamiltonian = rhf(bfs, twoe_factory=libint_twoe_integrals)
     iterator = SCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     self.assertAlmostEqual(iterator.energy, -299.909789863537, 5)
Exemple #21
0
 def test_h2(self):
     bfs = basisset(h2, '6-31g**')
     solver = rhf(h2, bfs)
     solver.converge()
     nvirt = len(bfs) - h2.nocc()
     emp2 = mp2(solver.i2, solver.orbs, solver.orbe, h2.nocc(),
                len(bfs) - h2.nocc())
     self.assertAlmostEqual(emp2, -0.02632654197486595)
     return
Exemple #22
0
 def test_N8(self):
     """N8"""
     N8 = read_xyz('./molfiles/N8.xyz')
     bfs = basisset(N8,'cc-pvdz')
     hamiltonian = rhf(bfs, twoe_factory=libint_twoe_integrals)
     iterator = SCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     self.assertAlmostEqual(iterator.energy, -434.992755329296, 5)
Exemple #23
0
 def test_LiH(self):
     bfs = basisset(lih,'cc-pvdz')
     hamiltonian=rhf(bfs, twoe_factory=libint_twoe_integrals)
     iterator = SCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     nvirt = len(bfs)-lih.nocc()
     emp2 = mp2(hamiltonian, iterator.orbs, iterator.orbe, lih.nocc(), nvirt)
     self.assertAlmostEqual(emp2, -0.023948620832, 5)
Exemple #24
0
 def test_CH4(self):
     bfs = basisset(ch4,'cc-pvdz')
     hamiltonian=rhf(bfs, twoe_factory=libint_twoe_integrals)
     iterator = SCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     nvirt = len(bfs)-ch4.nocc()
     emp2 = mp2(hamiltonian, iterator.orbs, iterator.orbe, ch4.nocc(), nvirt)
     self.assertAlmostEqual(emp2, -0.166640105042, 5)
Exemple #25
0
 def test_C8H8(self):
     """C8H8"""
     C8H8 = read_xyz('./molfiles/C8H8.xyz')
     bfs = basisset(C8H8,'sto-6g')
     hamiltonian = rhf(bfs, twoe_factory=libint_twoe_integrals)
     iterator = SCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     self.assertAlmostEqual(iterator.energy, -306.765545547300, 5)
Exemple #26
0
 def test_B12(self):
     """B12 symmetry Ih"""
     B12 = read_xyz('./molfiles/B12.xyz')
     bfs = basisset(B12,'sto-3g')
     hamiltonian = rhf(bfs, twoe_factory=libint_twoe_integrals)
     iterator = SCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     self.assertAlmostEqual(iterator.energy, -290.579419642829, 0)
def _calculate_integrals(molecule, basis='sto3g', calc_type='rhf'):
    """Function to calculate the one and two electron terms. Perform a Hartree-Fock calculation in
        the given basis.
    Args:
        molecule : A pyquante2 molecular object.
        basis : The basis set for the electronic structure computation
        calc_type: rhf, uhf, rohf
    Returns:
        ehf : Hartree-Fock energy
        enuke: Nuclear repulsion energy
        norbs : Number of orbitals
        mohij : One electron terms of the Hamiltonian.
        mohijkl : Two electron terms of the Hamiltonian.
        orbs: Molecular orbital coefficients
        orbs_energy: Orbital energies
    """
    bfs = basisset(molecule, basis)
    integrals = onee_integrals(bfs, molecule)
    hij = integrals.T + integrals.V
    hijkl_compressed = twoe_integrals(bfs)

    # convert overlap integrals to molecular basis
    # calculate the Hartree-Fock solution of the molecule

    if calc_type == 'rhf':
        solver = rhf(molecule, bfs)
    elif calc_type == 'rohf':
        solver = rohf(molecule, bfs)
    elif calc_type == 'uhf':
        solver = uhf(molecule, bfs)
    else:
        raise QiskitChemistryError('Invalid calc_type: {}'.format(calc_type))
    logger.debug('Solver name {}'.format(solver.name))
    ehf = solver.converge()
    if hasattr(solver, 'orbs'):
        orbs = solver.orbs
    else:
        orbs = solver.orbsa
    norbs = len(orbs)
    if hasattr(solver, 'orbe'):
        orbs_energy = solver.orbe
    else:
        orbs_energy = solver.orbea
    enuke = molecule.nuclear_repulsion()
    # Get ints in molecular orbital basis
    mohij = simx(hij, orbs)
    mohijkl_compressed = transformintegrals(hijkl_compressed, orbs)
    mohijkl = np.zeros((norbs, norbs, norbs, norbs))
    for i in range(norbs):
        for j in range(norbs):
            for k in range(norbs):
                for l in range(norbs):
                    mohijkl[i, j, k,
                            l] = mohijkl_compressed[ijkl2intindex(i, j, k, l)]

    return ehf[0], enuke, norbs, mohij, mohijkl, orbs, orbs_energy
Exemple #28
0
 def test_HBr(self):
     HBr = read_xyz('./molfiles/HBr.xyz')
     bfs = basisset(HBr,'cc-pvdz')
     hamiltonian=rhf(bfs, twoe_factory=libint_twoe_integrals)
     iterator = SCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     nvirt = len(bfs)-HBr.nocc()
     emp2 = mp2(hamiltonian, iterator.orbs, iterator.orbe, HBr.nocc(), nvirt)
     self.assertAlmostEqual(emp2, -0.153284373119, 6)
Exemple #29
0
 def test_C24(self):
     # FAIL
     """C24 symmetry Th"""
     C24 = read_xyz('./molfiles/C24.xyz')
     bfs = basisset(C24,'sto-3g')
     hamiltonian = rhf(bfs, twoe_factory=libint_twoe_integrals)
     iterator = SCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     self.assertAlmostEqual(iterator.energy, -890.071915453874, 0)
Exemple #30
0
 def test_N8(self):
     # 2.8 Gb memory needed
     N8 = read_xyz('./molfiles/N8.xyz')
     bfs = basisset(N8,'cc-pvdz')
     hamiltonian=rhf(bfs, twoe_factory=libint_twoe_integrals)
     iterator = SCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     nvirt = len(bfs)-N8.nocc()
     emp2 = mp2(hamiltonian, iterator.orbs, iterator.orbe, N8.nocc(), nvirt)
     self.assertAlmostEqual(emp2, -1.328348475507, 6)
Exemple #31
0
    def test_makepyquante(self):
        # Test pyquante2 bridge
        from pyquante2 import molecule, rhf, h2o, basisset

        bfs = basisset(h2o)
        # Copied from water_ccsd.log
        refmol = molecule(
            [(8, 0.0, 0.0, 0.119159), (1, 0, 0.790649, -0.476637),
             (1, 0, -0.790649, -0.476637)],
            units="Angstroms",
        )
        refsolver = rhf(refmol, bfs)
        refsolver.converge()

        pyqmol = cclib2pyquante.makepyquante(self.data)
        pyqsolver = rhf(pyqmol, bfs)
        pyqsolver.converge()

        assert_array_almost_equal(refsolver.energies[-1],
                                  pyqsolver.energies[-1],
                                  decimal=6)
Exemple #32
0
 def test_h4(self):
     h4 = molecule([
         (1,  0.00000000,     0.00000000,     0.36628549),
         (1,  0.00000000,     0.00000000,    -0.36628549),
         (1,  0.00000000,     4.00000000,     0.36628549),
         (1,  0.00000000,     4.00000000,    -0.36628549),
         ],
                   units='Angstrom')
     bfs = basisset(h4,'sto3g')
     solver = rhf(h4,bfs)
     ens = solver.converge()
     self.assertAlmostEqual(solver.energy,-2.234185653441159,6)
Exemple #33
0
 def test_h4(self):
     h4 = molecule([
         (1, 0.00000000, 0.00000000, 0.36628549),
         (1, 0.00000000, 0.00000000, -0.36628549),
         (1, 0.00000000, 4.00000000, 0.36628549),
         (1, 0.00000000, 4.00000000, -0.36628549),
     ],
                   units='Angstrom')
     bfs = basisset(h4, 'sto3g')
     solver = rhf(h4, bfs)
     ens = solver.converge()
     self.assertAlmostEqual(solver.energy, -2.234185653441159, match_digits)
Exemple #34
0
    def test_h4(self):
        h4 = molecule([
            (1,  0.00000000,     0.00000000,     0.36628549),
            (1,  0.00000000,     0.00000000,    -0.36628549),
            (1,  0.00000000,     4.00000000,     0.36628549),
            (1,  0.00000000,     4.00000000,    -0.36628549),
            ],
                      units='Angstrom')

        bfs = basisset(h4,'sto-3g')
        hamiltonian = rhf(bfs)
        iterator = SCFIterator(hamiltonian)
        iterator.converge()
        self.assertTrue(iterator.converged)
        self.assertAlmostEqual(iterator.energy, -2.234185358600, 7)
Exemple #35
0
 def test_lih(self):
     bfs = basisset(lih, 'sto3g')
     solver = rhf(lih, bfs)
     ens = solver.converge()
     self.assertAlmostEqual(solver.energy, -7.8607437, match_digits)
Exemple #36
0
def _calculate_integrals(molecule,
                         basis="sto3g",
                         hf_method="rhf",
                         tol=1e-8,
                         maxiters=100):
    """Function to calculate the one and two electron terms. Perform a Hartree-Fock calculation in
        the given basis.
    Args:
        molecule (pyQuante2.molecule): A pyquante2 molecular object.
        basis (str) : The basis set for the electronic structure computation
        hf_method (str): rhf, uhf, rohf
        tol (float): tolerance
        maxiters (int): max. iterations
    Returns:
        QMolecule: QMolecule populated with driver integrals etc
    Raises:
        QiskitNatureError: Invalid hf methods type
    """
    bfs = basisset(molecule, basis)
    integrals = onee_integrals(bfs, molecule)
    hij = integrals.T + integrals.V
    hijkl = twoe_integrals(bfs)

    # convert overlap integrals to molecular basis
    # calculate the Hartree-Fock solution of the molecule

    if hf_method == "rhf":
        solver = rhf(molecule, bfs)
    elif hf_method == "rohf":
        solver = rohf(molecule, bfs)
    elif hf_method == "uhf":
        solver = uhf(molecule, bfs)
    else:
        raise QiskitNatureError("Invalid hf_method type: {}".format(hf_method))
    ehf = solver.converge(tol=tol, maxiters=maxiters)
    logger.debug("PyQuante2 processing information:\n%s", solver)
    if hasattr(solver, "orbs"):
        orbs = solver.orbs
        orbs_b = None
    else:
        orbs = solver.orbsa
        orbs_b = solver.orbsb
    norbs = len(orbs)
    if hasattr(solver, "orbe"):
        orbs_energy = solver.orbe
        orbs_energy_b = None
    else:
        orbs_energy = solver.orbea
        orbs_energy_b = solver.orbeb
    enuke = molecule.nuclear_repulsion()
    # Get ints in molecular orbital basis
    mohij = simx(hij, orbs)
    mohij_b = None
    if orbs_b is not None:
        mohij_b = simx(hij, orbs_b)

    eri = hijkl.transform(np.identity(norbs))
    mohijkl = hijkl.transform(orbs)
    mohijkl_bb = None
    mohijkl_ba = None
    if orbs_b is not None:
        mohijkl_bb = hijkl.transform(orbs_b)
        mohijkl_ba = np.einsum("aI,bJ,cK,dL,abcd->IJKL", orbs_b, orbs_b, orbs,
                               orbs, hijkl[...])

    # Create driver level molecule object and populate
    _q_ = QMolecule()
    _q_.origin_driver_version = "?"  # No version info seems available to access
    # Energies and orbits
    _q_.hf_energy = ehf[0]
    _q_.nuclear_repulsion_energy = enuke
    _q_.num_molecular_orbitals = norbs
    _q_.num_alpha = molecule.nup()
    _q_.num_beta = molecule.ndown()
    _q_.mo_coeff = orbs
    _q_.mo_coeff_b = orbs_b
    _q_.orbital_energies = orbs_energy
    _q_.orbital_energies_b = orbs_energy_b
    # Molecule geometry
    _q_.molecular_charge = molecule.charge
    _q_.multiplicity = molecule.multiplicity
    _q_.num_atoms = len(molecule)
    _q_.atom_symbol = []
    _q_.atom_xyz = np.empty([len(molecule), 3])
    atoms = molecule.atoms
    for n_i in range(0, _q_.num_atoms):
        atuple = atoms[n_i].atuple()
        _q_.atom_symbol.append(QMolecule.symbols[atuple[0]])
        _q_.atom_xyz[n_i][0] = atuple[1]
        _q_.atom_xyz[n_i][1] = atuple[2]
        _q_.atom_xyz[n_i][2] = atuple[3]
    # 1 and 2 electron integrals
    _q_.hcore = hij
    _q_.hcore_b = None
    _q_.kinetic = integrals.T
    _q_.overlap = integrals.S
    _q_.eri = eri
    _q_.mo_onee_ints = mohij
    _q_.mo_onee_ints_b = mohij_b
    _q_.mo_eri_ints = mohijkl
    _q_.mo_eri_ints_bb = mohijkl_bb
    _q_.mo_eri_ints_ba = mohijkl_ba

    return _q_
Exemple #37
0
from pyquante2 import molecule, rhf, uhf, h2, lih, basisset
from pyquante2.graphics.maya import view_mol, view_orb, view_bonds

bfs = basisset(h2)
solver = rhf(h2, bfs)
ens = solver.converge()
orbs = solver.orbs

view_mol(h2, doshow=False)
view_bonds(h2, doshow=False)
view_orb(h2, orbs[:, 1], bfs, planes=[('x', False)])
Exemple #38
0
from pyquante2 import molecule,rhf,uhf,h2,lih,basisset
from pyquante2.graphics.maya import view_mol, view_orb, view_bonds

bfs = basisset(h2)
solver = rhf(h2,bfs)
ens = solver.converge()
orbs = solver.orbs

view_mol(h2,doshow=False)
view_bonds(h2,doshow=False)
view_orb(h2,orbs[:,1],bfs,planes=[('x',False)])
Exemple #39
0
 def test_h2o(self):
     bfs = basisset(h2o, 'sto3g')
     solver = rhf(h2o, bfs)
     ens = solver.converge()
     self.assertAlmostEqual(solver.energy, -74.959856675848712,
                            match_digits)
Exemple #40
0
 def test_h2o(self):
     bfs = basisset(h2o,'sto3g')
     solver = rhf(h2o,bfs)
     ens = solver.converge()
     self.assertAlmostEqual(solver.energy,-74.959856675848712)
Exemple #41
0
 def test_h2o_averaging(self):
     from pyquante2.scf.iterators import AveragingIterator
     bfs = basisset(h2o,'sto3g')
     solver = rhf(h2o,bfs)
     ens = solver.converge(AveragingIterator)
     self.assertAlmostEqual(solver.energy,-74.959847457272502)
Exemple #42
0
 def test_h2_631(self):
     bfs = basisset(h2, '6-31G**')
     solver = rhf(h2, bfs)
     ens = solver.converge()
     self.assertAlmostEqual(solver.energy, -1.1313335790123258,
                            match_digits)
def _calculate_integrals(molecule, basis='sto3g', hf_method='rhf', tol=1e-8, maxiters=100):
    """Function to calculate the one and two electron terms. Perform a Hartree-Fock calculation in
        the given basis.
    Args:
        molecule : A pyquante2 molecular object.
        basis : The basis set for the electronic structure computation
        hf_method: rhf, uhf, rohf
    Returns:
        QMolecule: QMolecule populated with driver integrals etc
    """
    bfs = basisset(molecule, basis)
    integrals = onee_integrals(bfs, molecule)
    hij = integrals.T + integrals.V
    hijkl = twoe_integrals(bfs)

    # convert overlap integrals to molecular basis
    # calculate the Hartree-Fock solution of the molecule

    if hf_method == 'rhf':
        solver = rhf(molecule, bfs)
    elif hf_method == 'rohf':
        solver = rohf(molecule, bfs)
    elif hf_method == 'uhf':
        solver = uhf(molecule, bfs)
    else:
        raise QiskitChemistryError('Invalid hf_method type: {}'.format(hf_method))
    ehf = solver.converge(tol=tol, maxiters=maxiters)
    logger.debug('PyQuante2 processing information:\n{}'.format(solver))
    if hasattr(solver, 'orbs'):
        orbs = solver.orbs
        orbs_B = None
    else:
        orbs = solver.orbsa
        orbs_B = solver.orbsb
    norbs = len(orbs)
    if hasattr(solver, 'orbe'):
        orbs_energy = solver.orbe
        orbs_energy_B = None
    else:
        orbs_energy = solver.orbea
        orbs_energy_B = solver.orbeb
    enuke = molecule.nuclear_repulsion()
    # Get ints in molecular orbital basis
    mohij = simx(hij, orbs)
    mohij_B = None
    if orbs_B is not None:
        mohij_B = simx(hij, orbs_B)

    eri = hijkl.transform(np.identity(norbs))
    mohijkl = hijkl.transform(orbs)
    mohijkl_BB = None
    mohijkl_BA = None
    if orbs_B is not None:
        mohijkl_BB = hijkl.transform(orbs_B)
        mohijkl_BA = np.einsum('aI,bJ,cK,dL,abcd->IJKL', orbs_B, orbs_B, orbs, orbs, hijkl[...])

    # Create driver level molecule object and populate
    _q_ = QMolecule()
    _q_.origin_driver_version = '?'  # No version info seems available to access
    # Energies and orbits
    _q_.hf_energy = ehf[0]
    _q_.nuclear_repulsion_energy = enuke
    _q_.num_orbitals = norbs
    _q_.num_alpha = molecule.nup()
    _q_.num_beta = molecule.ndown()
    _q_.mo_coeff = orbs
    _q_.mo_coeff_B = orbs_B
    _q_.orbital_energies = orbs_energy
    _q_.orbital_energies_B = orbs_energy_B
    # Molecule geometry
    _q_.molecular_charge = molecule.charge
    _q_.multiplicity = molecule.multiplicity
    _q_.num_atoms = len(molecule)
    _q_.atom_symbol = []
    _q_.atom_xyz = np.empty([len(molecule), 3])
    atoms = molecule.atoms
    for _n in range(0, _q_.num_atoms):
        atuple = atoms[_n].atuple()
        _q_.atom_symbol.append(QMolecule.symbols[atuple[0]])
        _q_.atom_xyz[_n][0] = atuple[1]
        _q_.atom_xyz[_n][1] = atuple[2]
        _q_.atom_xyz[_n][2] = atuple[3]
    # 1 and 2 electron integrals
    _q_.hcore = hij
    _q_.hcore_B = None
    _q_.kinetic = integrals.T
    _q_.overlap = integrals.S
    _q_.eri = eri
    _q_.mo_onee_ints = mohij
    _q_.mo_onee_ints_B = mohij_B
    _q_.mo_eri_ints = mohijkl
    _q_.mo_eri_ints_BB = mohijkl_BB
    _q_.mo_eri_ints_BA = mohijkl_BA

    return _q_
def test_dipole_LiH_H2_HF_STO_3G():
    """Example: LiH--H2, neutral singlet, RHF/STO-3G
    """

    #   X      -4.8174      Y       0.9597      Z      -0.0032
    # Tot       4.9121
    qchem_total_components_debye = np.array([-4.8174, 0.9597, -0.0032])
    qchem_total_norm_debye = 4.9121

    #      DX          DY          DZ         /D/  (DEBYE)
    # -4.817430    0.959709   -0.003226    4.912096
    gamess_total_components_debye = np.array([-4.817430, 0.959709, -0.003226])
    gamess_total_norm_debye = 4.912096

    #                                Dipole moment
    #                                -------------

    #               au               Debye          C m (/(10**-30)
    #            1.932564           4.912086          16.384956

    #                           Dipole moment components
    #                           ------------------------

    #               au               Debye          C m (/(10**-30)

    #    x     -1.89531979        -4.81742209       -16.06919039
    #    y      0.37757524         0.95970046         3.20121617
    #    z     -0.00126928        -0.00322619        -0.01076141

    # Units:   1 a.u. =   2.54175 Debye
    #          1 a.u. =   8.47835 (10**-30) C m (SI)
    dalton_total_components_debye = np.array(
        [-4.81742209, 0.95970046, -0.00322619])
    dalton_total_norm_debye = 4.912086
    dalton_total_components_au = np.array(
        [-1.89531979, 0.37757524, -0.00126928])
    dalton_total_norm_au = 1.932564
    dalton_center_of_mass_au = np.array(
        [-2.468120057069, 2.168586684080, -0.007311931664])

    # ORCA uses the center of mass by default.

    # Electronic contribution:     -4.65190      -3.56492       0.02433
    # Nuclear contribution   :      2.75658       3.94249      -0.02560
    #                         -----------------------------------------
    # Total Dipole Moment    :     -1.89532       0.37758      -0.00127
    #                         -----------------------------------------
    # Magnitude (a.u.)       :      1.93256
    # Magnitude (Debye)      :      4.91219
    orca_electronic_components_au = np.array([-4.65190, -3.56492, 0.02433])
    orca_nuclear_components_au = np.array([2.75658, 3.94249, -0.02560])
    orca_total_components_au = np.array([-1.89532, 0.37758, -0.00127])
    assert np.all(
        ((orca_nuclear_components_au + orca_electronic_components_au) -
         orca_total_components_au) < 1.0e-14)
    orca_total_norm_au = 1.93256
    assert abs(orca_total_norm_au -
               npl.norm(orca_total_components_au)) < 1.0e-5
    orca_total_norm_debye = 4.91219

    # Origin is the Cartesian origin
    # Nuclear Dipole Moment: (a.u.)
    #    X:   -12.0198      Y:    17.0002      Z:    -0.0698

    # Electronic Dipole Moment: (a.u.)
    #    X:    10.1245      Y:   -16.6226      Z:     0.0685

    # Dipole Moment: (a.u.)
    #    X:    -1.8953      Y:     0.3776      Z:    -0.0013     Total:     1.9326

    # Dipole Moment: (Debye)
    #    X:    -4.8174      Y:     0.9597      Z:    -0.0032     Total:     4.9121
    psi4_nuclear_components_au = np.array([-12.0198, 17.0002, -0.0698])
    psi4_electronic_components_au = np.array([10.1245, -16.6226, 0.0685])
    psi4_total_components_au = np.array([-1.8953, 0.3776, -0.0013])
    assert np.all(
        ((psi4_nuclear_components_au + psi4_electronic_components_au) -
         psi4_total_components_au) < 1.0e-14)
    psi4_total_norm_au = 1.9326
    assert abs(psi4_total_norm_au -
               npl.norm(psi4_total_components_au)) < 1.0e-4
    psi4_total_components_debye = np.array([-4.8174, 0.9597, -0.0032])
    psi4_total_norm_debye = 4.9121
    assert abs(psi4_total_norm_debye -
               npl.norm(psi4_total_components_debye)) < 1.0e-4

    # pylint: disable=bad-whitespace
    mol = molecule([(3, -1.67861, 0.61476, -0.00041),
                    (1, -0.01729, 0.38654, -0.00063),
                    (1, -0.84551, 3.08551, -0.00236),
                    (1, -0.46199, 3.67980, -0.03270)],
                   units='Angstrom',
                   charge=0,
                   multiplicity=1,
                   name='LiH_H2')

    nuccoords = np.array([atom.r for atom in mol.atoms])
    nuccharges = np.array([atom.Z for atom in mol.atoms])[..., np.newaxis]
    masses = get_isotopic_masses(nuccharges[:, 0])

    mol_basis = pyquante2.basisset(mol, 'STO-3G'.lower())

    solver = pyquante2.rhf(mol, mol_basis)
    solver.converge(tol=1e-11, maxiters=1000)

    C = solver.orbs
    NOa = mol.nup()
    NOb = mol.ndown()
    assert NOa == NOb
    D = 2 * np.dot(C[:, :NOa], C[:, :NOa].T)

    origin_zero = np.array([0.0, 0.0, 0.0])

    ref = psi4_nuclear_components_au
    res = nuclear_dipole_contribution(nuccoords, nuccharges, origin_zero)
    abs_diff = np.absolute(ref - res)
    assert np.all(abs_diff < 1.0e-4)

    ref = psi4_electronic_components_au
    res = electronic_dipole_contribution_pyquante(D, mol_basis, origin_zero)
    abs_diff = np.absolute(ref - res)
    assert np.all(abs_diff < 1.0e-4)

    res1 = nuclear_dipole_contribution(nuccoords, nuccharges, origin_zero)
    res2 = nuclear_dipole_contribution_pyquante(mol, origin_zero)
    assert np.all((res1 - res2) < 1.0e-15)

    ref = dalton_center_of_mass_au
    res = calc_center_of_mass_pyquante(mol)
    abs_diff = np.absolute(ref - res)
    assert np.all(abs_diff < 1.0e-6)
    com = res

    assert np.all(np.equal(np.sign(com), np.sign(ref)))

    res1 = calc_center_of_mass_pyquante(mol)
    res2 = calc_center_of_mass(nuccoords, masses)
    assert np.all((res1 - res2) < 1.0e-15)

    ncc = calc_center_of_nuclear_charge(nuccoords, nuccharges)
    assert np.all(
        (ncc - np.array([-2.00330482, 2.83337011, -0.01162811])) < 1.0e-8)
    ecc = calc_center_of_electronic_charge_pyquante(D, mol_basis)
    assert np.all(
        (ecc - np.array([-1.68741793, 2.77044101, -0.01141657])) < 1.0e-8)

    origin_zero = calculate_origin_pyquante('zero',
                                            nuccoords,
                                            nuccharges,
                                            D,
                                            mol_basis,
                                            do_print=True)
    dipole_zero = calculate_dipole_pyquante(nuccoords,
                                            nuccharges,
                                            origin_zero,
                                            D,
                                            mol_basis,
                                            do_print=True)
    origin_com = calculate_origin_pyquante('com',
                                           nuccoords,
                                           nuccharges,
                                           D,
                                           mol_basis,
                                           do_print=True)
    dipole_com = calculate_dipole_pyquante(nuccoords,
                                           nuccharges,
                                           origin_com,
                                           D,
                                           mol_basis,
                                           do_print=True)
    origin_ncc = calculate_origin_pyquante('ncc',
                                           nuccoords,
                                           nuccharges,
                                           D,
                                           mol_basis,
                                           do_print=True)
    dipole_ncc = calculate_dipole_pyquante(nuccoords,
                                           nuccharges,
                                           origin_ncc,
                                           D,
                                           mol_basis,
                                           do_print=True)
    origin_ecc = calculate_origin_pyquante('ecc',
                                           nuccoords,
                                           nuccharges,
                                           D,
                                           mol_basis,
                                           do_print=True)
    dipole_ecc = calculate_dipole_pyquante(nuccoords,
                                           nuccharges,
                                           origin_ecc,
                                           D,
                                           mol_basis,
                                           do_print=True)

    # ORCA: center of mass; TODO why is the answer so different?
    n_dipole_com_au = nuclear_dipole_contribution(nuccoords, nuccharges,
                                                  origin_com)
    assert np.all(
        np.equal(np.sign(n_dipole_com_au),
                 np.sign(orca_nuclear_components_au)))
    print(np.absolute(orca_nuclear_components_au - n_dipole_com_au))
    e_dipole_com_au = electronic_dipole_contribution_pyquante(
        D, mol_basis, origin_com)
    assert np.all(
        np.equal(np.sign(e_dipole_com_au),
                 np.sign(orca_electronic_components_au)))
    print(np.absolute(orca_electronic_components_au - e_dipole_com_au))

    # For an uncharged system, these should all be identical.
    my_ref = np.array([-1.89532134e+00, 3.77574623e-01, -1.26926571e-03])
    for res in (dipole_zero, dipole_com, dipole_ncc, dipole_ecc):
        assert np.all(np.absolute(my_ref - res) < 1.0e-8)

    return
Exemple #45
0
 def test_h2(self):
     bfs = basisset(h2, 'sto3g')
     solver = rhf(h2, bfs)
     ens = solver.converge()
     self.assertAlmostEqual(solver.energy, -1.117099582955609, match_digits)