Пример #1
0
 def test_oh(self):
     bfs = basisset(oh,'sto-3g')
     hamiltonian = uhf(bfs)
     iterator = USCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     self.assertAlmostEqual(iterator.energy, -74.360233544941, 4)
Пример #2
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)
Пример #3
0
def plot_orbs():
    bfs = basisset(h2,'sto3g')
    orbs = np.array([[1.0,1.0],
                     [1.0,-1.0]],'d')
    
    vtk_orbital(h2,orbs,bfs)
    return
Пример #4
0
 def test_li(self):
     bfs = basisset(li,'sto-3g')
     hamiltonian = uhf(bfs)
     iterator = USCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     self.assertAlmostEqual(iterator.energy, -7.315525981280, 6)
Пример #5
0
 def test_he_triplet_xlda(self):
     from pyquante2.geo.samples import he
     he.multiplicity = 3
     bfs = basisset(he,'sto-3g')
     solver = dft(he,bfs,'xs')
     ens = solver.converge()
     self.assertAlmostEqual(solver.energy,-1.7819689849)
Пример #6
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
Пример #7
0
 def test_oh(self):
     bfs = basisset(oh,'sto-3g')
     hamiltonian = rohf(bfs)
     iterator = ROSCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     self.assertAlmostEqual(iterator.energy, -74.359151530162, 5)
Пример #8
0
def pyq2_dft(atomtuples=[(2,0,0,0)],basis = '6-31G**',maxit=10,xcname='svwn'):
    import pyquante2 as pyq2
    print ("pyq2 DFT run")
    geo = pyq2.molecule(atomtuples)
    bfs = pyq2.basisset(geo,name=basis)
    i1 = pyq2.onee_integrals(bfs,geo)
    i2 = pyq2.twoe_integrals(bfs)
    grid = pyq2.grid(geo)
    h = i1.T + i1.V
    orbe,orbs = pyq2.geigh(h,i1.S)
    eold = 0
    grid.setbfamps(bfs)
    E0 = geo.nuclear_repulsion()

    for i in range(maxit):
        D = pyq2.dmat(orbs,geo.nocc())
        E1 = 2*pyq2.trace2(h,D)

        J = i2.get_j(D)
        Ej = 2*pyq2.trace2(J,D)

        Exc,Vxc = pyq2.get_xc(grid,0.5*D,xcname=xcname)

        energy = E0+E1+Ej+Exc
        F = h+2*J+Vxc

        orbe,orbs = pyq2.geigh(F,i1.S)

        print (i,energy,E1,Ej,Exc,E0)
        if np.isclose(energy,eold):
            break
        eold = energy
    return energy
Пример #9
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)
Пример #10
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)
Пример #11
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)
Пример #12
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)
Пример #13
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
Пример #14
0
def plot_orb2():
    from pyquante2 import basisset,h2
    bfs = basisset(h2,'sto3g')
    orbs = np.array([[1.0,1.0],
                     [1.0,-1.0]],'d')
    
    vtk_orbs(h2,orbs,bfs)
    return
Пример #15
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)
Пример #16
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)
Пример #17
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)
Пример #18
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)
Пример #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)
Пример #20
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)
Пример #21
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)
Пример #22
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)
Пример #23
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)
Пример #24
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)
Пример #25
0
 def test_CH3(self):
     """CH3 radical"""
     CH3 = read_xyz('./molfiles/CH3.xyz')
     bfs = basisset(CH3,'sto-3g')
     hamiltonian = cuhf(bfs, twoe_factory=libint_twoe_integrals)
     iterator = USCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     self.assertAlmostEqual(iterator.energy, -38.952023222533, 5)
Пример #26
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)
Пример #27
0
 def test_CF3(self):
     """CF3 radical"""
     CF3 = read_xyz('./molfiles/CF3.xyz')
     bfs = basisset(CF3,'sto-3g')
     hamiltonian = cuhf(bfs, twoe_factory=libint_twoe_integrals)
     iterator = USCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     self.assertAlmostEqual(iterator.energy, -331.480688906400, 5)
Пример #28
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)
Пример #29
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)
Пример #30
0
 def test_N8(self):
     """N8"""
     N8 = read_xyz('./molfiles/N8.xyz')
     bfs = basisset(N8,'cc-pvdz')
     hamiltonian = rohf(bfs, twoe_factory=libint_twoe_integrals)
     iterator = ROSCFIterator(hamiltonian)
     iterator.converge()
     self.assertTrue(iterator.converged)
     self.assertAlmostEqual(iterator.energy, -434.992755329296, 5)
Пример #31
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)
Пример #32
0
 def test_lih(self):
     bfs = basisset(lih, 'sto3g')
     solver = rhf(lih, bfs)
     ens = solver.converge()
     self.assertAlmostEqual(solver.energy, -7.8607437, match_digits)
Пример #33
0
 def test_h2o(self):
     bfs = basisset(h2o, 'sto3g')
     solver = rhf(h2o, bfs)
     ens = solver.converge()
     self.assertAlmostEqual(solver.energy, -74.959856675848712,
                            match_digits)
Пример #34
0
 def test_oh_uhf(self):
     from pyquante2 import oh
     bfs = basisset(oh, 'sto3g')
     solver = uhf(oh, bfs)
     Es = solver.converge()
     self.assertAlmostEqual(solver.energy, -74.3602416207, match_digits)
Пример #35
0
 def test_h2(self):
     bfs = basisset(h2, 'sto3g')
     solver = rhf(h2, bfs)
     ens = solver.converge()
     self.assertAlmostEqual(solver.energy, -1.117099582955609, match_digits)
Пример #36
0
 def test_oh_rohf(self):
     from pyquante2 import oh
     bfs = basisset(oh, 'sto3g')
     solver = rohf(oh, bfs)
     Es = solver.converge()
     self.assertAlmostEqual(solver.energy, -74.3591663559, match_digits)
Пример #37
0
 def test_li_rohf(self):
     from pyquante2 import li
     bfs = basisset(li, 'sto3g')
     solver = rohf(li, bfs)
     Es = solver.converge()
     self.assertAlmostEqual(solver.energy, -7.31552591799, match_digits)
Пример #38
0
def _calculate_integrals(molecule,
                         basis="sto3g",
                         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
        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 method == "rhf":
        solver = rhf(molecule, bfs)
    elif method == "rohf":
        solver = rohf(molecule, bfs)
    elif method == "uhf":
        solver = uhf(molecule, bfs)
    else:
        raise QiskitNatureError(f"Invalid method type: {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
    warnings.filterwarnings("ignore", category=DeprecationWarning)
    _q_ = QMolecule()
    warnings.filterwarnings("default", category=DeprecationWarning)
    _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_
def test_dipole_hydroxyl_radical_HF_STO_3G():
    """Example: OH^{.}, neutral doublet, UHF/STO-3G
    """

    qchem_final_energy = -74.3626375184
    # Dipole Moment (Debye)
    #      X       0.0000      Y      -0.0000      Z      -1.2788
    #    Tot       1.2788
    qchem_total_components_debye = np.array([0.0000, 0.0000, -1.2788])
    qchem_total_norm_debye = 1.2788

    dalton_final_energy = -74.361530725817
    #                             Dipole moment
    #                             -------------

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

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

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

    # x     -0.00000000        -0.00000000        -0.00000000
    # y     -0.00000000        -0.00000000        -0.00000000
    # z     -0.50228316        -1.27667636        -4.25853394

    # Units:   1 a.u. =   2.54175 Debye
    #          1 a.u. =   8.47835 (10**-30) C m (SI)
    dalton_total_components_debye = np.array([0.0, 0.0, -1.27667636])
    dalton_total_norm_debye = 1.276676
    dalton_total_components_au = np.array([0.0, 0.0, -0.50228316])
    dalton_total_norm_au = 0.502283
    dalton_center_of_mass_au = np.array([0.0, 0.0, 1.723849254747])

    # ORCA uses the center of mass by default.
    orca_final_energy = -74.362637379044
    # Electronic contribution:      0.00000      -0.00000       0.35185
    # Nuclear contribution   :      0.00000       0.00000      -0.85498
    #                         -----------------------------------------
    # Total Dipole Moment    :      0.00000      -0.00000      -0.50312
    #                         -----------------------------------------
    # Magnitude (a.u.)       :      0.50312
    # Magnitude (Debye)      :      1.27884
    orca_electronic_components_au = np.array([0.0, 0.0, 0.35185])
    orca_nuclear_components_au = np.array([0.0, 0.0, -0.85498])
    orca_total_components_au = np.array([0.0, 0.0, -0.50312])
    assert np.all(
        ((orca_nuclear_components_au + orca_electronic_components_au) -
         orca_total_components_au) < 1.0e-14)
    orca_total_norm_au = 0.50312
    assert abs(orca_total_norm_au -
               npl.norm(orca_total_components_au)) < 1.0e-5
    orca_total_norm_debye = 1.27884

    # prop_orca_coe.out
    # 505:Coordinates of the origin    ...    0.00000000   -0.00000000    1.68476265 (bohrs)

    # prop_orca_com.out
    # 505:Coordinates of the origin    ...    0.00000000    0.00000000    1.72385761 (bohrs)

    # prop_orca_con.out
    # 505:Coordinates of the origin    ...    0.00000000    0.00000000    1.62885994 (bohrs)
    orca_center_of_electronic_charge_au = np.array(
        [0.00000000, 0.00000000, 1.68476265])
    orca_center_of_mass_au = np.array([0.00000000, 0.00000000, 1.72385761])
    orca_center_of_nuclear_charge_au = np.array(
        [0.00000000, 0.00000000, 1.62885994])

    psi4_final_energy = -74.3626375190713986
    # Origin is the Cartesian origin
    # Nuclear Dipole Moment: (a.u.)
    #    X:     0.0000      Y:     0.0000      Z:    14.6597

    # Electronic Dipole Moment: (a.u.)
    #    X:    -0.0000      Y:     0.0000      Z:   -15.1629

    # Dipole Moment: (a.u.)
    #    X:    -0.0000      Y:     0.0000      Z:    -0.5031     Total:     0.5031

    # Dipole Moment: (Debye)
    #    X:    -0.0000      Y:     0.0000      Z:    -1.2788     Total:     1.2788
    psi4_nuclear_components_au = np.array([0.0, 0.0, 14.6597])
    psi4_electronic_components_au = np.array([0.0, 0.0, -15.1629])
    psi4_total_components_au = np.array([0.0, 0.0, -0.5031])
    assert np.all(
        ((psi4_nuclear_components_au + psi4_electronic_components_au) -
         psi4_total_components_au) < 1.0e-14)
    psi4_total_norm_au = 0.5031
    assert abs(psi4_total_norm_au -
               npl.norm(psi4_total_components_au)) < 1.0e-4
    psi4_total_components_debye = np.array([0.0, 0.0, -1.2788])
    psi4_total_norm_debye = 1.2788
    assert abs(psi4_total_norm_debye -
               npl.norm(psi4_total_components_debye)) < 1.0e-4

    mol = molecule([(1, 0.000, 0.000, 0.000), (8, 0.000, 0.000, 0.9697)],
                   units='Angstrom',
                   charge=0,
                   multiplicity=2,
                   name='hydroxyl_radical')

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

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

    C_alph = solver.orbsa
    C_beta = solver.orbsb
    NOa = mol.nup()
    NOb = mol.ndown()
    D_alph = np.dot(C_alph[:, :NOa], C_alph[:, :NOa].T)
    D_beta = np.dot(C_beta[:, :NOb], C_beta[:, :NOb].T)
    D = D_alph + D_beta

    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])

    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(orca_center_of_mass_au)))
    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(
        np.equal(np.sign(ncc), np.sign(orca_center_of_nuclear_charge_au)))
    assert np.all((ncc - orca_center_of_nuclear_charge_au) < 1.0e-8)
    ecc = screen(calc_center_of_electronic_charge_pyquante(D, mol_basis))
    assert np.all(
        np.equal(np.sign(ecc), np.sign(orca_center_of_electronic_charge_au)))
    assert np.all((ecc - orca_center_of_electronic_charge_au) < 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)

    # For an uncharged system, these should all be identical.
    my_ref = np.array([0.0, 0.0, -0.5031245309396919])
    for res in (dipole_zero, dipole_com, dipole_ncc, dipole_ecc):
        assert (np.absolute(my_ref - res) < 1.0e-8).all()

    return
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