示例#1
0
def test_energy_hydrogen():
    fn_fchk = context.get_fn('test/h_sto3g.fchk')
    mol = IOData.from_file(fn_fchk)
    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)
    terms = [
        UTwoIndexTerm(kin, 'kin'),
        UDirectTerm(er, 'hartree'),
        UExchangeTerm(er, 'x_hf'),
        UTwoIndexTerm(na, 'ne'),
    ]
    external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
    ham = UEffHam(terms, external)
    helper_compute(ham, mol.lf, mol.exp_alpha, mol.exp_beta)
    assert abs(ham.cache['energy'] - -4.665818503844346E-01) < 1e-8
示例#2
0
def test_energy_hydrogen():
    fn_fchk = context.get_fn('test/h_sto3g.fchk')
    mol = IOData.from_file(fn_fchk)
    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)
    terms = [
        UTwoIndexTerm(kin, 'kin'),
        UDirectTerm(er, 'hartree'),
        UExchangeTerm(er, 'x_hf'),
        UTwoIndexTerm(na, 'ne'),
    ]
    external = {'nn': compute_nucnuc(mol.coordinates, mol.pseudo_numbers)}
    ham = UEffHam(terms, external)
    helper_compute(ham, mol.lf, mol.exp_alpha, mol.exp_beta)
    assert abs(ham.cache['energy'] - -4.665818503844346E-01) < 1e-8
示例#3
0
def test_project_msg_larger():
    # Load STO3G system and keep essential results
    mol = IOData.from_file(context.get_fn('test/water_sto3g_hf_g03.fchk'))
    obasis0 = mol.obasis
    exp0 = mol.exp_alpha

    # Upgrade the basis to 3-21G and project
    obasis1 = get_gobasis(mol.coordinates, mol.numbers, '3-21G')
    lf1 = DenseLinalgFactory(obasis1.nbasis)
    exp1 = lf1.create_expansion()
    project_orbitals_mgs(obasis0, obasis1, exp0, exp1)
    assert (exp1.energies == 0.0).all()
    assert exp0.occupations.sum() == exp1.occupations.sum()
    assert (exp1.coeffs[:, 5:] == 0.0).all()

    # Check the normalization of the projected orbitals
    olp = obasis1.compute_overlap(lf1)
    exp1.check_orthonormality(olp)

    # Setup HF hamiltonian and compute energy
    kin = obasis1.compute_kinetic(lf1)
    na = obasis1.compute_nuclear_attraction(mol.coordinates,
                                            mol.pseudo_numbers, lf1)
    er = obasis1.compute_electron_repulsion(lf1)
    terms = [
        RTwoIndexTerm(kin, 'kin'),
        RDirectTerm(er, 'hartree'),
        RExchangeTerm(er, 'x_hf'),
        RTwoIndexTerm(na, 'ne'),
    ]
    ham = REffHam(terms)

    # Compute energy after projection
    energy1 = helper_compute(ham, lf1, exp1)[0]

    # Optimize wfn
    scf_solver = PlainSCFSolver(1e-6)
    occ_model = AufbauOccModel(5)
    scf_solver(ham, lf1, olp, occ_model, exp1)
    energy2 = ham.cache['energy']
    assert energy2 < energy1  # the energy should decrease after scf convergence

    # Construct a core initial guess
    guess_core_hamiltonian(olp, kin, na, exp1)
    energy3 = helper_compute(ham, lf1, exp1)[0]
    assert energy3 > energy1  # the projected guess should be better than the core guess
示例#4
0
def test_project_msg_larger():
    # Load STO3G system and keep essential results
    mol = IOData.from_file(context.get_fn('test/water_sto3g_hf_g03.fchk'))
    obasis0 = mol.obasis
    exp0 = mol.exp_alpha

    # Upgrade the basis to 3-21G and project
    obasis1 = get_gobasis(mol.coordinates, mol.numbers, '3-21G')
    lf1 = DenseLinalgFactory(obasis1.nbasis)
    exp1 = lf1.create_expansion()
    project_orbitals_mgs(obasis0, obasis1, exp0, exp1)
    assert (exp1.energies == 0.0).all()
    assert exp0.occupations.sum() == exp1.occupations.sum()
    assert (exp1.coeffs[:,5:] == 0.0).all()

    # Check the normalization of the projected orbitals
    olp = obasis1.compute_overlap(lf1)
    exp1.check_orthonormality(olp)

    # Setup HF hamiltonian and compute energy
    kin = obasis1.compute_kinetic(lf1)
    na = obasis1.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers, lf1)
    er = obasis1.compute_electron_repulsion(lf1)
    terms = [
        RTwoIndexTerm(kin, 'kin'),
        RDirectTerm(er, 'hartree'),
        RExchangeTerm(er, 'x_hf'),
        RTwoIndexTerm(na, 'ne'),
    ]
    ham = REffHam(terms)

    # Compute energy after projection
    energy1 = helper_compute(ham, lf1, exp1)[0]

    # Optimize wfn
    scf_solver = PlainSCFSolver(1e-6)
    occ_model = AufbauOccModel(5)
    scf_solver(ham, lf1, olp, occ_model, exp1)
    energy2 = ham.cache['energy']
    assert energy2 < energy1 # the energy should decrease after scf convergence

    # Construct a core initial guess
    guess_core_hamiltonian(olp, kin, na, exp1)
    energy3 = helper_compute(ham, lf1, exp1)[0]
    assert energy3 > energy1 # the projected guess should be better than the core guess
示例#5
0
def test_project_msg_smaller():
    # Load 3-21G system and keep essential results
    mol = IOData.from_file(context.get_fn('test/li_h_3-21G_hf_g09.fchk'))
    obasis0 = mol.obasis
    exp0_alpha = mol.exp_alpha
    exp0_beta = mol.exp_beta

    # Downgrade the basis to sto-3g and project
    obasis1 = get_gobasis(mol.coordinates, mol.numbers, 'sto-3g')
    lf1 = DenseLinalgFactory(obasis1.nbasis)
    exp1_alpha = lf1.create_expansion()
    exp1_beta = lf1.create_expansion()
    project_orbitals_mgs(obasis0, obasis1, exp0_alpha, exp1_alpha)
    project_orbitals_mgs(obasis0, obasis1, exp0_beta, exp1_beta)
    assert (exp1_alpha.energies == 0.0).all()
    assert (exp1_beta.energies == 0.0).all()
    assert exp1_alpha.occupations.sum() == 2
    assert exp1_beta.occupations.sum() == 1
    assert (exp1_alpha.coeffs[:, 2:] == 0.0).all()
    assert (exp1_beta.coeffs[:, 1:] == 0.0).all()

    # Check the normalization of the projected orbitals
    olp = obasis1.compute_overlap(lf1)
    exp1_alpha.check_orthonormality(olp)
    exp1_beta.check_orthonormality(olp)

    # Setup HF hamiltonian and compute energy
    kin = obasis1.compute_kinetic(lf1)
    na = obasis1.compute_nuclear_attraction(mol.coordinates,
                                            mol.pseudo_numbers, lf1)
    er = obasis1.compute_electron_repulsion(lf1)
    terms = [
        UTwoIndexTerm(kin, 'kin'),
        UDirectTerm(er, 'hartree'),
        UExchangeTerm(er, 'x_hf'),
        UTwoIndexTerm(na, 'ne'),
    ]
    ham = UEffHam(terms)

    # Compute energy before SCF
    energy1 = helper_compute(ham, lf1, exp1_alpha, exp1_beta)[0]

    scf_solver = PlainSCFSolver(1e-6)
    occ_model = AufbauOccModel(2, 1)
    scf_solver(ham, lf1, olp, occ_model, exp1_alpha, exp1_beta)
    energy2 = ham.cache['energy']
    assert energy2 < energy1  # the energy should decrease after scf convergence
示例#6
0
def test_project_msg_smaller():
    # Load 3-21G system and keep essential results
    mol = IOData.from_file(context.get_fn('test/li_h_3-21G_hf_g09.fchk'))
    obasis0 = mol.obasis
    exp0_alpha = mol.exp_alpha
    exp0_beta = mol.exp_beta

    # Downgrade the basis to sto-3g and project
    obasis1 = get_gobasis(mol.coordinates, mol.numbers, 'sto-3g')
    lf1 = DenseLinalgFactory(obasis1.nbasis)
    exp1_alpha = lf1.create_expansion()
    exp1_beta = lf1.create_expansion()
    project_orbitals_mgs(obasis0, obasis1, exp0_alpha, exp1_alpha)
    project_orbitals_mgs(obasis0, obasis1, exp0_beta, exp1_beta)
    assert (exp1_alpha.energies == 0.0).all()
    assert (exp1_beta.energies == 0.0).all()
    assert exp1_alpha.occupations.sum() == 2
    assert exp1_beta.occupations.sum() == 1
    assert (exp1_alpha.coeffs[:,2:] == 0.0).all()
    assert (exp1_beta.coeffs[:,1:] == 0.0).all()

    # Check the normalization of the projected orbitals
    olp = obasis1.compute_overlap(lf1)
    exp1_alpha.check_orthonormality(olp)
    exp1_beta.check_orthonormality(olp)

    # Setup HF hamiltonian and compute energy
    kin = obasis1.compute_kinetic(lf1)
    na = obasis1.compute_nuclear_attraction(mol.coordinates, mol.pseudo_numbers, lf1)
    er = obasis1.compute_electron_repulsion(lf1)
    terms = [
        UTwoIndexTerm(kin, 'kin'),
        UDirectTerm(er, 'hartree'),
        UExchangeTerm(er, 'x_hf'),
        UTwoIndexTerm(na, 'ne'),
    ]
    ham = UEffHam(terms)

    # Compute energy before SCF
    energy1 = helper_compute(ham, lf1, exp1_alpha, exp1_beta)[0]

    scf_solver = PlainSCFSolver(1e-6)
    occ_model = AufbauOccModel(2, 1)
    scf_solver(ham, lf1, olp, occ_model, exp1_alpha, exp1_beta)
    energy2 = ham.cache['energy']
    assert energy2 < energy1 # the energy should decrease after scf convergence