Пример #1
0
def check_hf_cs_hf(scf_solver):
    fn_fchk = context.get_fn('test/hf_sto3g.fchk')
    mol = IOData.from_file(fn_fchk)

    olp = mol.obasis.compute_overlap(mol.lf)
    kin = mol.obasis.compute_kinetic(mol.lf)
    na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers, mol.lf)
    er = mol.obasis.compute_electron_repulsion(mol.lf)
    external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
    terms = [
        RTwoIndexTerm(kin, 'kin'),
        RDirectTerm(er, 'hartree'),
        RExchangeTerm(er, 'x_hf'),
        RTwoIndexTerm(na, 'ne'),
    ]
    ham = REffHam(terms, external)
    occ_model = AufbauOccModel(5)

    check_solve(ham, scf_solver, occ_model, mol.lf, olp, kin, na, mol.exp_alpha)

    # test orbital energies
    expected_energies = np.array([
        -2.59083334E+01, -1.44689996E+00, -5.57467136E-01, -4.62288194E-01,
        -4.62288194E-01, 5.39578910E-01,
    ])
    assert abs(mol.exp_alpha.energies - expected_energies).max() < 1e-5

    ham.compute_energy()
    # compare with g09
    assert abs(ham.cache['energy'] - -9.856961609951867E+01) < 1e-8
    assert abs(ham.cache['energy_kin'] - 9.766140786239E+01) < 2e-7
    assert abs(ham.cache['energy_hartree'] + ham.cache['energy_x_hf'] - 4.561984106482E+01) < 1e-6
    assert abs(ham.cache['energy_ne'] - -2.465756615329E+02) < 1e-6
    assert abs(ham.cache['energy_nn'] - 4.7247965053) < 1e-8
Пример #2
0
def check_hf_cs_hf(scf_solver):
    fn_fchk = context.get_fn('test/hf_sto3g.fchk')
    mol = IOData.from_file(fn_fchk)

    olp = mol.obasis.compute_overlap()
    kin = mol.obasis.compute_kinetic()
    na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
    er = mol.obasis.compute_electron_repulsion()
    external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
    terms = [
        RTwoIndexTerm(kin, 'kin'),
        RDirectTerm(er, 'hartree'),
        RExchangeTerm(er, 'x_hf'),
        RTwoIndexTerm(na, 'ne'),
    ]
    ham = REffHam(terms, external)
    occ_model = AufbauOccModel(5)

    check_solve(ham, scf_solver, occ_model, olp, kin, na, mol.orb_alpha)

    # test orbital energies
    expected_energies = np.array([
        -2.59083334E+01, -1.44689996E+00, -5.57467136E-01, -4.62288194E-01,
        -4.62288194E-01, 5.39578910E-01,
    ])
    assert abs(mol.orb_alpha.energies - expected_energies).max() < 1e-5

    ham.compute_energy()
    # compare with g09
    assert abs(ham.cache['energy'] - -9.856961609951867E+01) < 1e-8
    assert abs(ham.cache['energy_kin'] - 9.766140786239E+01) < 2e-7
    assert abs(ham.cache['energy_hartree'] + ham.cache['energy_x_hf'] - 4.561984106482E+01) < 1e-6
    assert abs(ham.cache['energy_ne'] - -2.465756615329E+02) < 1e-6
    assert abs(ham.cache['energy_nn'] - 4.7247965053) < 1e-8
Пример #3
0
def check_co_cs_pbe(scf_solver):
    fn_fchk = context.get_fn('test/co_pbe_sto3g.fchk')
    mol = IOData.from_file(fn_fchk)
    grid = BeckeMolGrid(mol.coordinates,
                        mol.numbers,
                        mol.pseudo_numbers,
                        'fine',
                        random_rotate=False)
    olp = mol.obasis.compute_overlap(mol.lf)
    kin = mol.obasis.compute_kinetic(mol.lf)
    na = mol.obasis.compute_nuclear_attraction(mol.coordinates,
                                               mol.pseudo_numbers, mol.lf)
    er = mol.obasis.compute_electron_repulsion(mol.lf)
    external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
    terms = [
        RTwoIndexTerm(kin, 'kin'),
        RDirectTerm(er, 'hartree'),
        RGridGroup(mol.obasis, grid, [
            RLibXCGGA('x_pbe'),
            RLibXCGGA('c_pbe'),
        ]),
        RTwoIndexTerm(na, 'ne'),
    ]
    ham = REffHam(terms, external)

    # Test energy before scf
    energy, focks = helper_compute(ham, mol.lf, mol.exp_alpha)
    assert abs(energy - -1.116465967841901E+02) < 1e-4

    # The convergence should be reasonable, not perfect because of limited
    # precision in Gaussian fchk file:
    assert convergence_error_eigen(ham, mol.lf, olp, mol.exp_alpha) < 1e-5

    # Converge from scratch
    occ_model = AufbauOccModel(7)
    check_solve(ham, scf_solver, occ_model, mol.lf, olp, kin, na,
                mol.exp_alpha)

    # test orbital energies
    expected_energies = np.array([
        -1.86831122E+01, -9.73586915E+00, -1.03946082E+00, -4.09331776E-01,
        -3.48686522E-01, -3.48686522E-01, -2.06049056E-01, 5.23730418E-02,
        5.23730418E-02, 6.61093726E-01
    ])
    assert abs(mol.exp_alpha.energies - expected_energies).max() < 1e-2

    ham.compute_energy()
    # compare with g09
    assert abs(ham.cache['energy_ne'] - -3.072370116827E+02) < 1e-2
    assert abs(ham.cache['energy_kin'] - 1.103410779827E+02) < 1e-2
    assert abs(ham.cache['energy_hartree'] +
               ham.cache['energy_libxc_gga_x_pbe'] +
               ham.cache['energy_libxc_gga_c_pbe'] - 6.273115782683E+01) < 1e-2
    assert abs(ham.cache['energy'] - -1.116465967841901E+02) < 1e-4
    assert abs(ham.cache['energy_nn'] - 22.5181790889) < 1e-7
Пример #4
0
def check_water_cs_hfs(scf_solver):
    fn_fchk = context.get_fn('test/water_hfs_321g.fchk')
    mol = IOData.from_file(fn_fchk)

    grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False)
    olp = mol.obasis.compute_overlap(mol.lf)
    kin = mol.obasis.compute_kinetic(mol.lf)
    na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers, mol.lf)
    er = mol.obasis.compute_electron_repulsion(mol.lf)
    external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
    terms = [
        RTwoIndexTerm(kin, 'kin'),
        RDirectTerm(er, 'hartree'),
        RGridGroup(mol.obasis, grid, [
            RDiracExchange(),
        ]),
        RTwoIndexTerm(na, 'ne'),
    ]
    ham = REffHam(terms, external)

    # The convergence should be reasonable, not perfect because of limited
    # precision in Gaussian fchk file and different integration grids:
    assert convergence_error_eigen(ham, mol.lf, olp, mol.exp_alpha) < 3e-5

    # Recompute the orbitals and orbital energies. This should be reasonably OK.
    dm_alpha = mol.exp_alpha.to_dm()
    ham.reset(dm_alpha)
    ham.compute_energy()
    fock_alpha = mol.lf.create_two_index()
    ham.compute_fock(fock_alpha)
    mol.exp_alpha.from_fock(fock_alpha, olp)

    expected_energies = np.array([
        -1.83691041E+01, -8.29412411E-01, -4.04495188E-01, -1.91740814E-01,
        -1.32190590E-01, 1.16030419E-01, 2.08119657E-01, 9.69825207E-01,
        9.99248500E-01, 1.41697384E+00, 1.47918828E+00, 1.61926596E+00,
        2.71995350E+00
    ])

    assert abs(mol.exp_alpha.energies - expected_energies).max() < 2e-4
    assert abs(ham.cache['energy_ne'] - -1.977921986200E+02) < 1e-7
    assert abs(ham.cache['energy_kin'] - 7.525067610865E+01) < 1e-9
    assert abs(ham.cache['energy_hartree'] + ham.cache['energy_x_dirac'] - 3.864299848058E+01) < 2e-4
    assert abs(ham.cache['energy'] - -7.474134898935590E+01) < 2e-4
    assert abs(ham.cache['energy_nn'] - 9.1571750414) < 2e-8

    # Converge from scratch and check energies
    occ_model = AufbauOccModel(5)
    check_solve(ham, scf_solver, occ_model, mol.lf, olp, kin, na, mol.exp_alpha)

    ham.compute_energy()
    assert abs(ham.cache['energy_ne'] - -1.977921986200E+02) < 1e-4
    assert abs(ham.cache['energy_kin'] - 7.525067610865E+01) < 1e-4
    assert abs(ham.cache['energy_hartree'] + ham.cache['energy_x_dirac'] - 3.864299848058E+01) < 2e-4
    assert abs(ham.cache['energy'] - -7.474134898935590E+01) < 2e-4
Пример #5
0
def check_water_cs_m05(scf_solver):
    """Try to converge the SCF for the water molecule with the M05 functional.

    Parameters
    ----------
    scf_solver : one of the SCFSolver types in HORTON
                 A configured SCF solver that must be tested.
    """
    fn_fchk = context.get_fn('test/water_m05_321g.fchk')
    mol = IOData.from_file(fn_fchk)
    grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, 'fine',
                        random_rotate=False)
    olp = mol.obasis.compute_overlap()
    kin = mol.obasis.compute_kinetic()
    na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
    er = mol.obasis.compute_electron_repulsion()
    external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
    libxc_term = RLibXCHybridMGGA('xc_m05')
    terms = [
        RTwoIndexTerm(kin, 'kin'),
        RDirectTerm(er, 'hartree'),
        RGridGroup(mol.obasis, grid, [libxc_term]),
        RExchangeTerm(er, 'x_hf', libxc_term.get_exx_fraction()),
        RTwoIndexTerm(na, 'ne'),
    ]
    ham = REffHam(terms, external)

    # compute the energy before converging
    dm_alpha = mol.orb_alpha.to_dm()
    ham.reset(dm_alpha)
    ham.compute_energy()
    assert abs(ham.cache['energy'] - -75.9532086800) < 1e-3

    # The convergence should be reasonable, not perfect because of limited
    # precision in the molden file:
    assert convergence_error_eigen(ham, olp, mol.orb_alpha) < 1e-3

    # keep a copy of the orbital energies
    expected_alpha_energies = mol.orb_alpha.energies.copy()

    # Converge from scratch
    occ_model = AufbauOccModel(5)
    check_solve(ham, scf_solver, occ_model, olp, kin, na, mol.orb_alpha)

    # test orbital energies
    assert abs(mol.orb_alpha.energies - expected_alpha_energies).max() < 2e-3

    ham.compute_energy()
    # compare with
    assert abs(ham.cache['energy_kin'] - 75.54463056278) < 1e-2
    assert abs(ham.cache['energy_ne'] - -198.3003887880) < 1e-2
    assert abs(ham.cache['energy_hartree'] + ham.cache['energy_x_hf'] +
               ham.cache['energy_libxc_hyb_mgga_xc_m05'] - 3.764537450376E+01) < 1e-2
    assert abs(ham.cache['energy'] - -75.9532086800) < 1e-3
    assert abs(ham.cache['energy_nn'] - 9.1571750414) < 1e-5
Пример #6
0
def check_water_cs_hfs(scf_solver):
    fn_fchk = context.get_fn('test/water_hfs_321g.fchk')
    mol = IOData.from_file(fn_fchk)

    grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, random_rotate=False)
    olp = mol.obasis.compute_overlap()
    kin = mol.obasis.compute_kinetic()
    na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers)
    er = mol.obasis.compute_electron_repulsion()
    external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
    terms = [
        RTwoIndexTerm(kin, 'kin'),
        RDirectTerm(er, 'hartree'),
        RGridGroup(mol.obasis, grid, [
            RDiracExchange(),
        ]),
        RTwoIndexTerm(na, 'ne'),
    ]
    ham = REffHam(terms, external)

    # The convergence should be reasonable, not perfect because of limited
    # precision in Gaussian fchk file and different integration grids:
    assert convergence_error_eigen(ham, olp, mol.orb_alpha) < 3e-5

    # Recompute the orbitals and orbital energies. This should be reasonably OK.
    dm_alpha = mol.orb_alpha.to_dm()
    ham.reset(dm_alpha)
    ham.compute_energy()
    fock_alpha = np.zeros(dm_alpha.shape)
    ham.compute_fock(fock_alpha)
    mol.orb_alpha.from_fock(fock_alpha, olp)

    expected_energies = np.array([
        -1.83691041E+01, -8.29412411E-01, -4.04495188E-01, -1.91740814E-01,
        -1.32190590E-01, 1.16030419E-01, 2.08119657E-01, 9.69825207E-01,
        9.99248500E-01, 1.41697384E+00, 1.47918828E+00, 1.61926596E+00,
        2.71995350E+00
    ])

    assert abs(mol.orb_alpha.energies - expected_energies).max() < 2e-4
    assert abs(ham.cache['energy_ne'] - -1.977921986200E+02) < 1e-7
    assert abs(ham.cache['energy_kin'] - 7.525067610865E+01) < 1e-9
    assert abs(ham.cache['energy_hartree'] + ham.cache['energy_x_dirac'] - 3.864299848058E+01) < 2e-4
    assert abs(ham.cache['energy'] - -7.474134898935590E+01) < 2e-4
    assert abs(ham.cache['energy_nn'] - 9.1571750414) < 2e-8

    # Converge from scratch and check energies
    occ_model = AufbauOccModel(5)
    check_solve(ham, scf_solver, occ_model, olp, kin, na, mol.orb_alpha)

    ham.compute_energy()
    assert abs(ham.cache['energy_ne'] - -1.977921986200E+02) < 1e-4
    assert abs(ham.cache['energy_kin'] - 7.525067610865E+01) < 1e-4
    assert abs(ham.cache['energy_hartree'] + ham.cache['energy_x_dirac'] - 3.864299848058E+01) < 2e-4
    assert abs(ham.cache['energy'] - -7.474134898935590E+01) < 2e-4
Пример #7
0
def check_co_cs_pbe(scf_solver):
    fn_fchk = context.get_fn('test/co_pbe_sto3g.fchk')
    mol = IOData.from_file(fn_fchk)
    grid = BeckeMolGrid(mol.coordinates, mol.numbers, mol.pseudo_numbers, 'fine', random_rotate=False)
    olp = mol.obasis.compute_overlap(mol.lf)
    kin = mol.obasis.compute_kinetic(mol.lf)
    na = mol.obasis.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers, mol.lf)
    er = mol.obasis.compute_electron_repulsion(mol.lf)
    external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
    terms = [
        RTwoIndexTerm(kin, 'kin'),
        RDirectTerm(er, 'hartree'),
        RGridGroup(mol.obasis, grid, [
            RLibXCGGA('x_pbe'),
            RLibXCGGA('c_pbe'),
        ]),
        RTwoIndexTerm(na, 'ne'),
    ]
    ham = REffHam(terms, external)

    # Test energy before scf
    energy, focks = helper_compute(ham, mol.lf, mol.exp_alpha)
    assert abs(energy - -1.116465967841901E+02) < 1e-4

    # The convergence should be reasonable, not perfect because of limited
    # precision in Gaussian fchk file:
    assert convergence_error_eigen(ham, mol.lf, olp, mol.exp_alpha) < 1e-5

    # Converge from scratch
    occ_model = AufbauOccModel(7)
    check_solve(ham, scf_solver, occ_model, mol.lf, olp, kin, na, mol.exp_alpha)

    # test orbital energies
    expected_energies = np.array([
         -1.86831122E+01, -9.73586915E+00, -1.03946082E+00, -4.09331776E-01,
         -3.48686522E-01, -3.48686522E-01, -2.06049056E-01, 5.23730418E-02,
         5.23730418E-02, 6.61093726E-01
    ])
    assert abs(mol.exp_alpha.energies - expected_energies).max() < 1e-2

    ham.compute_energy()
    # compare with g09
    assert abs(ham.cache['energy_ne'] - -3.072370116827E+02) < 1e-2
    assert abs(ham.cache['energy_kin'] - 1.103410779827E+02) < 1e-2
    assert abs(ham.cache['energy_hartree'] + ham.cache['energy_libxc_gga_x_pbe'] + ham.cache['energy_libxc_gga_c_pbe'] - 6.273115782683E+01) < 1e-2
    assert abs(ham.cache['energy'] - -1.116465967841901E+02) < 1e-4
    assert abs(ham.cache['energy_nn'] - 22.5181790889) < 1e-7