Exemple #1
0
def test_load_wfn_lif_fci():
    fn_wfn = context.get_fn('test/lif_fci.wfn')
    sys = System.from_file(fn_wfn)
    assert isinstance(sys.wfn, RestrictedWFN)
    assert sys.natom == 2
    assert sys.obasis.nbasis == 44
    sys.wfn.exp_alpha.check_normalization(sys.get_overlap(), 1e-5) #Check normalization
    assert sys.wfn.exp_alpha.occupations.shape == (18,)
    assert abs(sys.wfn.exp_alpha.occupations.sum() - 6.0) < 1.e-6
    assert sys.wfn.exp_alpha.occupations[0] == 2.00000000/2
    assert sys.wfn.exp_alpha.occupations[10] == 0.00128021/2
    assert sys.wfn.exp_alpha.occupations[-1] == 0.00000054/2
    assert sys.wfn.exp_alpha.energies.shape == (18,)
    assert sys.wfn.exp_alpha.energies[0] == -26.09321253
    assert sys.wfn.exp_alpha.energies[15] == 1.70096290
    assert sys.wfn.exp_alpha.energies[-1] == 2.17434072
    assert sys.wfn.exp_alpha.coeffs.shape == (44, 18)
    ham = Hamiltonian(sys, [HartreeFockExchange()])
    energy = ham.compute() #cannot be compared!
    kin = sys.extra['energy_kin']
    nn = sys.extra['energy_nn']
    expected_kin = 106.9326884815  #FCI kinetic energy
    expected_nn = 9.1130265227
    assert (kin - expected_kin) < 1.e-6
    assert (nn - expected_nn) < 1.e-6
    charges = compute_mulliken_charges(sys)   #Check charges
    expected_charge = np.array([-0.645282, 0.645282])
    assert (abs(charges - expected_charge) < 1e-5).all()
    points = np.array([[0.0, 0.0,-0.17008], [0.0, 0.0, 0.0], [0.0, 0.0, 0.03779]])
    density = sys.compute_grid_density(points)
    assert (abs(density - [0.492787, 0.784545, 0.867723]) < 1.e-4).all()
Exemple #2
0
def test_load_wfn_li_sp_virtual():
    fn_wfn = context.get_fn('test/li_sp_virtual.wfn')
    sys = System.from_file(fn_wfn)
    assert isinstance(sys.wfn, UnrestrictedWFN)
    assert sys.obasis.nbasis == 8
    sys.wfn.exp_alpha.check_normalization(sys.get_overlap(),
                                          1e-5)  #Check normalization
    sys.wfn.exp_beta.check_normalization(sys.get_overlap(),
                                         1e-5)  #Check normalization
    assert abs(sys.wfn.exp_alpha.occupations.sum() - 2.0) < 1.e-6
    assert abs(sys.wfn.exp_beta.occupations.sum() - 1.0) < 1.e-6
    assert (sys.wfn.exp_alpha.occupations == [
        1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
    ]).all()
    assert (sys.wfn.exp_beta.occupations == [
        1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
    ]).all()
    assert (abs(sys.wfn.exp_alpha.energies - [
        -0.087492, -0.080310, 0.158784, 0.158784, 1.078773, 1.090891, 1.090891,
        49.643670
    ]) < 1.e-6).all()
    assert (abs(sys.wfn.exp_beta.energies - [
        -0.079905, 0.176681, 0.176681, 0.212494, 1.096631, 1.096631, 1.122821,
        49.643827
    ]) < 1.e-6).all()
    assert sys.wfn.exp_alpha.coeffs.shape == (8, 8)
    assert sys.wfn.exp_beta.coeffs.shape == (8, 8)
    ham = Hamiltonian(sys, [HartreeFockExchange()])
    energy = ham.compute()
    assert abs(energy - (
        -3.712905542719)) < 1.e-6  #Compare to the energy printed in wfn file
    charges = compute_mulliken_charges(sys)  #Check charges
    expected_charge = np.array([0.0, 0.0])
    assert (abs(charges - expected_charge) < 1e-5).all()
Exemple #3
0
def test_load_wfn_lif_fci():
    fn_wfn = context.get_fn('test/lif_fci.wfn')
    sys = System.from_file(fn_wfn)
    assert isinstance(sys.wfn, RestrictedWFN)
    assert sys.natom == 2
    assert sys.obasis.nbasis == 44
    sys.wfn.exp_alpha.check_normalization(sys.get_overlap(),
                                          1e-5)  #Check normalization
    assert sys.wfn.exp_alpha.occupations.shape == (18, )
    assert abs(sys.wfn.exp_alpha.occupations.sum() - 6.0) < 1.e-6
    assert sys.wfn.exp_alpha.occupations[0] == 2.00000000 / 2
    assert sys.wfn.exp_alpha.occupations[10] == 0.00128021 / 2
    assert sys.wfn.exp_alpha.occupations[-1] == 0.00000054 / 2
    assert sys.wfn.exp_alpha.energies.shape == (18, )
    assert sys.wfn.exp_alpha.energies[0] == -26.09321253
    assert sys.wfn.exp_alpha.energies[15] == 1.70096290
    assert sys.wfn.exp_alpha.energies[-1] == 2.17434072
    assert sys.wfn.exp_alpha.coeffs.shape == (44, 18)
    ham = Hamiltonian(sys, [HartreeFockExchange()])
    energy = ham.compute()  #cannot be compared!
    kin = sys.extra['energy_kin']
    nn = sys.extra['energy_nn']
    expected_kin = 106.9326884815  #FCI kinetic energy
    expected_nn = 9.1130265227
    assert (kin - expected_kin) < 1.e-6
    assert (nn - expected_nn) < 1.e-6
    charges = compute_mulliken_charges(sys)  #Check charges
    expected_charge = np.array([-0.645282, 0.645282])
    assert (abs(charges - expected_charge) < 1e-5).all()
    points = np.array([[0.0, 0.0, -0.17008], [0.0, 0.0, 0.0],
                       [0.0, 0.0, 0.03779]])
    density = sys.compute_grid_density(points)
    assert (abs(density - [0.492787, 0.784545, 0.867723]) < 1.e-4).all()
Exemple #4
0
def test_load_wfn_h2_ccpvqz_virtual():
    fn_wfn = context.get_fn('test/h2_ccpvqz.wfn')
    sys = System.from_file(fn_wfn)
    assert isinstance(sys.wfn, RestrictedWFN)
    assert sys.obasis.nbasis == 74
    sys.wfn.exp_alpha.check_normalization(sys.get_overlap(),
                                          1e-5)  #Chech normalization
    assert (abs(sys.obasis.alphas[:5] -
                [82.64000, 12.41000, 2.824000, 0.7977000, 0.2581000]) <
            1.e-5).all()
    assert (sys.wfn.exp_alpha.energies[:5] == [
        -0.596838, 0.144565, 0.209605, 0.460401, 0.460401
    ]).all()
    assert (sys.wfn.exp_alpha.energies[-5:] == [
        12.859067, 13.017471, 16.405834, 25.824716, 26.100443
    ]).all()
    assert (sys.wfn.exp_alpha.occupations[:5] == [1.0, 0.0, 0.0, 0.0,
                                                  0.0]).all()
    assert abs(sys.wfn.exp_alpha.occupations.sum() - 1.0) < 1.e-6
    ham = Hamiltonian(sys, [HartreeFockExchange()])
    energy = ham.compute()
    assert abs(energy - (
        -1.133504568400)) < 1.e-5  #Compare to the energy printed in wfn file
    charges = compute_mulliken_charges(sys)  #Check charges
    expected_charge = np.array([0.0, 0.0])
    assert (abs(charges - expected_charge) < 1e-5).all()
Exemple #5
0
def test_load_wfn_he_spd():
    sys, energy = check_load_wfn('he_spd_orbital')
    assert isinstance(sys.wfn, RestrictedWFN)
    assert abs(energy - (-2.855319016184)) < 1.e-6     #Compare to the energy printed in wfn file
    charges = compute_mulliken_charges(sys)                    #Check charges
    expected_charge = np.array([0.0])
    assert (abs(charges - expected_charge) < 1e-5).all()
Exemple #6
0
def test_load_wfn_he_spdfgh_virtual():
    sys, energy = check_load_wfn('he_spdfgh_virtual')
    assert isinstance(sys.wfn, RestrictedWFN)
    assert abs(energy - (-1.048675168346)) < 1.e-6   #Compare to the energy printed in wfn file
    charges = compute_mulliken_charges(sys)                  #Check charges
    expected_charge = np.array([0.0])
    assert (abs(charges - expected_charge) < 1e-5).all()
Exemple #7
0
def check_load_wfn(name):
    # system out of *.wfn file
    mol1 = IOData.from_file(context.get_fn('test/%s.wfn' % name))
    # system out of *.fchk file
    mol2 = IOData.from_file(context.get_fn('test/%s.fchk' % name))
    # Coordinates check:
    assert (abs(mol1.coordinates - mol2.coordinates) < 1e-6).all()
    # Numbers check
    numbers1 = mol1.numbers
    numbers2 = mol2.numbers
    assert (numbers1 == numbers2).all()
    # Basis Set check:
    obasis1 = mol1.obasis
    obasis2 = mol2.obasis
    assert obasis1.nbasis == obasis2.nbasis
    assert (obasis1.shell_map == obasis2.shell_map).all()
    assert (obasis1.shell_types == obasis2.shell_types).all()
    assert (obasis1.nprims == obasis2.nprims).all()
    assert (abs(obasis1.alphas - obasis2.alphas) < 1.e-4).all()
    # Comparing MOs (*.wfn might not contain virtual orbitals):
    n_mo = mol1.orb_alpha.nfn
    assert (abs(mol1.orb_alpha.energies - mol2.orb_alpha.energies[:n_mo]) <
            1.e-5).all()
    assert (
        mol1.orb_alpha.occupations == mol2.orb_alpha.occupations[:n_mo]).all()
    assert (abs(mol1.orb_alpha.coeffs - mol2.orb_alpha.coeffs[:, :n_mo]) <
            1.e-7).all()
    # Check overlap
    olp1 = obasis1.compute_overlap()
    olp2 = obasis2.compute_overlap()
    obasis2.compute_overlap(olp2)
    assert (abs(olp1 - olp2) < 1e-6).all()
    # Check normalization
    mol1.orb_alpha.check_normalization(olp1, 1e-5)
    # Check charges
    dm_full1 = mol1.get_dm_full()
    charges1 = compute_mulliken_charges(obasis1, numbers1, dm_full1)
    dm_full2 = mol2.get_dm_full()
    charges2 = compute_mulliken_charges(obasis2, numbers2, dm_full2)
    assert (abs(charges1 - charges2) < 1e-6).all()
    # Check energy
    energy1 = compute_hf_energy(mol1)
    energy2 = compute_hf_energy(mol2)
    # check loaded & computed energy from wfn file
    assert abs(energy1 - mol1.energy) < 1.e-5
    assert abs(energy1 - energy2) < 1e-5
    return energy1, charges1
Exemple #8
0
def test_load_molden_neon_turbomole():
    # The file tested here is created with Turbomole 7.1.
    fn_molden = context.get_fn('test/neon_turbomole_def2-qzvp.molden')
    mol = IOData.from_file(fn_molden)
    # Check Mulliken charges.
    dm_full = mol.get_dm_full()
    charges = compute_mulliken_charges(mol.obasis, mol.pseudo_numbers, dm_full)
    assert abs(charges).max() < 1e-3
Exemple #9
0
def test_load_wfn_he_spd():
    sys, energy = check_load_wfn('he_spd_orbital')
    assert isinstance(sys.wfn, RestrictedWFN)
    assert abs(energy - (
        -2.855319016184)) < 1.e-6  #Compare to the energy printed in wfn file
    charges = compute_mulliken_charges(sys)  #Check charges
    expected_charge = np.array([0.0])
    assert (abs(charges - expected_charge) < 1e-5).all()
Exemple #10
0
def test_load_wfn_he_spdfgh_virtual():
    sys, energy = check_load_wfn('he_spdfgh_virtual')
    assert isinstance(sys.wfn, RestrictedWFN)
    assert abs(energy - (
        -1.048675168346)) < 1.e-6  #Compare to the energy printed in wfn file
    charges = compute_mulliken_charges(sys)  #Check charges
    expected_charge = np.array([0.0])
    assert (abs(charges - expected_charge) < 1e-5).all()
Exemple #11
0
def test_load_molden_neon_turbomole():
    # The file tested here is created with Turbomole 7.1.
    fn_molden = context.get_fn('test/neon_turbomole_def2-qzvp.molden')
    mol = IOData.from_file(fn_molden)
    # Check Mulliken charges.
    dm_full = mol.get_dm_full()
    charges = compute_mulliken_charges(mol.obasis, mol.lf, mol.pseudo_numbers, dm_full)
    assert abs(charges).max() < 1e-3
Exemple #12
0
def test_load_molden_nh3_molpro2012():
    # The file tested here is created with MOLPRO2012.
    fn_molden = context.get_fn('test/nh3_molpro2012.molden')
    mol = IOData.from_file(fn_molden)
    # Check Mulliken charges. Comparison with numbers from the Molden program output.
    dm_full = mol.get_dm_full()
    charges = compute_mulliken_charges(mol.obasis, mol.lf, mol.pseudo_numbers, dm_full)
    molden_charges = np.array([0.0381, -0.2742, 0.0121, 0.2242])
    assert abs(charges - molden_charges).max() < 1e-3
Exemple #13
0
def test_load_molden_nh3_molpro2012():
    # The file tested here is created with MOLPRO2012.
    fn_molden = context.get_fn('test/nh3_molpro2012.molden')
    mol = IOData.from_file(fn_molden)
    # Check Mulliken charges. Comparison with numbers from the Molden program output.
    dm_full = mol.get_dm_full()
    charges = compute_mulliken_charges(mol.obasis, mol.pseudo_numbers, dm_full)
    molden_charges = np.array([0.0381, -0.2742, 0.0121, 0.2242])
    assert abs(charges - molden_charges).max() < 1e-3
Exemple #14
0
def check_load_wfn(name):
    # system out of *.wfn file
    mol1 = IOData.from_file(context.get_fn('test/%s.wfn' % name))
    # system out of *.fchk file
    mol2 = IOData.from_file(context.get_fn('test/%s.fchk' % name))
    # Coordinates check:
    assert (abs(mol1.coordinates - mol2.coordinates) < 1e-6).all()
    # Numbers check
    numbers1 = mol1.numbers
    numbers2 = mol2.numbers
    assert (numbers1 == numbers2).all()
    # Basis Set check:
    obasis1 = mol1.obasis
    obasis2 = mol2.obasis
    assert obasis1.nbasis == obasis2.nbasis
    assert (obasis1.shell_map == obasis2.shell_map).all()
    assert (obasis1.shell_types == obasis2.shell_types).all()
    assert (obasis1.nprims == obasis2.nprims).all()
    assert (abs(obasis1.alphas - obasis2.alphas) < 1.e-4).all()
    # Comparing MOs (*.wfn might not contain virtual orbitals):
    n_mo = mol1.orb_alpha.nfn
    assert (abs(mol1.orb_alpha.energies - mol2.orb_alpha.energies[:n_mo]) < 1.e-5).all()
    assert (mol1.orb_alpha.occupations == mol2.orb_alpha.occupations[:n_mo]).all()
    assert (abs(mol1.orb_alpha.coeffs - mol2.orb_alpha.coeffs[:, :n_mo]) < 1.e-7).all()
    # Check overlap
    olp1 = obasis1.compute_overlap()
    olp2 = obasis2.compute_overlap()
    obasis2.compute_overlap(olp2)
    assert (abs(olp1 - olp2) < 1e-6).all()
    # Check normalization
    mol1.orb_alpha.check_normalization(olp1, 1e-5)
    # Check charges
    dm_full1 = mol1.get_dm_full()
    charges1 = compute_mulliken_charges(obasis1, numbers1, dm_full1)
    dm_full2 = mol2.get_dm_full()
    charges2 = compute_mulliken_charges(obasis2, numbers2, dm_full2)
    assert (abs(charges1 - charges2) < 1e-6).all()
    # Check energy
    energy1 = compute_hf_energy(mol1)
    energy2 = compute_hf_energy(mol2)
    # check loaded & computed energy from wfn file
    assert abs(energy1 - mol1.energy) < 1.e-5
    assert abs(energy1 - energy2) < 1e-5
    return energy1, charges1
Exemple #15
0
def test_load_molden_nh3_psi4_1():
    # The file tested here is created with PSI4 (version 1.0). It should be read in
    # properly by renormalizing the contractions.
    fn_molden = context.get_fn('test/nh3_psi4_1.0.molden')
    mol = IOData.from_file(fn_molden)
    # Check Mulliken charges. Comparison with numbers from the Molden program output.
    dm_full = mol.get_dm_full()
    charges = compute_mulliken_charges(mol.obasis, mol.lf, mol.pseudo_numbers, dm_full)
    molden_charges = np.array([0.0381, -0.2742, 0.0121, 0.2242])
    assert abs(charges - molden_charges).max() < 1e-3
Exemple #16
0
def test_load_molden_nh3_psi4_1():
    # The file tested here is created with PSI4 (version 1.0). It should be read in
    # properly by renormalizing the contractions.
    fn_molden = context.get_fn('test/nh3_psi4_1.0.molden')
    mol = IOData.from_file(fn_molden)
    # Check Mulliken charges. Comparison with numbers from the Molden program output.
    dm_full = mol.get_dm_full()
    charges = compute_mulliken_charges(mol.obasis, mol.pseudo_numbers, dm_full)
    molden_charges = np.array([0.0381, -0.2742, 0.0121, 0.2242])
    assert abs(charges - molden_charges).max() < 1e-3
Exemple #17
0
def test_load_molden_nh3_orca():
    # The file tested here is created with ORCA. It should be read in
    # properly by altering normalization and sign conventions.
    fn_molden = context.get_fn('test/nh3_orca.molden')
    mol = IOData.from_file(fn_molden)
    # Check Mulliken charges. Comparison with numbers from the Molden program output.
    dm_full = mol.get_dm_full()
    charges = compute_mulliken_charges(mol.obasis, mol.lf, mol.pseudo_numbers, dm_full)
    molden_charges = np.array([0.0381, -0.2742, 0.0121, 0.2242])
    assert abs(charges - molden_charges).max() < 1e-3
Exemple #18
0
def test_load_molden_nh3_orca():
    # The file tested here is created with ORCA. It should be read in
    # properly by altering normalization and sign conventions.
    fn_molden = context.get_fn('test/nh3_orca.molden')
    mol = IOData.from_file(fn_molden)
    # Check Mulliken charges. Comparison with numbers from the Molden program output.
    dm_full = mol.get_dm_full()
    charges = compute_mulliken_charges(mol.obasis, mol.pseudo_numbers, dm_full)
    molden_charges = np.array([0.0381, -0.2742, 0.0121, 0.2242])
    assert abs(charges - molden_charges).max() < 1e-3
Exemple #19
0
def test_load_mkl_ethanol():
    fn_mkl = context.get_fn('test/ethanol.mkl')
    mol = IOData.from_file(fn_mkl)

    # Direct checks with mkl file
    assert mol.numbers.shape == (9, )
    assert mol.numbers[0] == 1
    assert mol.numbers[4] == 6
    assert mol.coordinates.shape == (9, 3)
    assert abs(mol.coordinates[2, 1] / angstrom - 2.239037) < 1e-5
    assert abs(mol.coordinates[5, 2] / angstrom - 0.948420) < 1e-5
    assert mol.obasis.nbasis == 39
    assert mol.obasis.alphas[0] == 18.731137000
    assert mol.obasis.alphas[10] == 7.868272400
    assert mol.obasis.alphas[-3] == 2.825393700
    #assert mol.obasis.con_coeffs[5] == 0.989450608
    #assert mol.obasis.con_coeffs[7] == 2.079187061
    #assert mol.obasis.con_coeffs[-1] == 0.181380684
    assert (mol.obasis.shell_map[:5] == [0, 0, 1, 1, 1]).all()
    assert (mol.obasis.shell_types[:5] == [0, 0, 0, 0, 1]).all()
    assert (mol.obasis.nprims[-5:] == [3, 1, 1, 3, 1]).all()
    assert mol.exp_alpha.coeffs.shape == (39, 39)
    assert mol.exp_alpha.energies.shape == (39, )
    assert mol.exp_alpha.occupations.shape == (39, )
    assert (mol.exp_alpha.occupations[:13] == 1.0).all()
    assert (mol.exp_alpha.occupations[13:] == 0.0).all()
    assert mol.exp_alpha.energies[4] == -1.0206976
    assert mol.exp_alpha.energies[-1] == 2.0748685
    assert mol.exp_alpha.coeffs[0, 0] == 0.0000119
    assert mol.exp_alpha.coeffs[1, 0] == -0.0003216
    assert mol.exp_alpha.coeffs[-1, -1] == -0.1424743

    # Comparison of derived properties with ORCA output file

    # nuclear-nuclear repulsion
    assert abs(
        compute_nucnuc(mol.coordinates, mol.pseudo_numbers) -
        81.87080034) < 1e-5

    # Check normalization
    olp = mol.obasis.compute_overlap(mol.lf)
    mol.exp_alpha.check_normalization(olp, 1e-5)

    # Mulliken charges
    dm_full = mol.get_dm_full()
    charges = compute_mulliken_charges(mol.obasis, mol.lf, mol.numbers,
                                       dm_full)
    expected_charges = np.array([
        0.143316, -0.445861, 0.173045, 0.173021, 0.024542, 0.143066, 0.143080,
        -0.754230, 0.400021
    ])
    assert abs(charges - expected_charges).max() < 1e-5

    # Compute HF energy
    assert abs(compute_hf_energy(mol) - -154.01322894) < 1e-4
Exemple #20
0
def test_load_wfn_h2o_sto3g():
    fn_wfn = context.get_fn('test/h2o_sto3g.wfn')
    sys = System.from_file(fn_wfn)
    assert isinstance(sys.wfn, RestrictedWFN)
    sys.wfn.exp_alpha.check_normalization(sys.get_overlap(), 1e-5) #Check normalization
    ham = Hamiltonian(sys, [HartreeFockExchange()])
    energy = ham.compute()
    assert abs(energy - (-74.965901217080)) < 1.e-5   #Compare to the energy printed in wfn file
    charges = compute_mulliken_charges(sys)   #Check charges
    expected_charge = np.array([-0.330532, 0.165266, 0.165266])
    assert (abs(charges - expected_charge) < 1e-5).all()
Exemple #21
0
def test_load_molden_h2o():
    fn_mkl = context.get_fn('test/h2o.molden.input')
    sys = System.from_file(fn_mkl)

    # Check normalization
    sys.wfn.exp_alpha.check_normalization(sys.get_overlap(), 1e-5)

    # Check charges
    charges = compute_mulliken_charges(sys)
    expected_charges = np.array([-0.816308, 0.408154, 0.408154])
    assert abs(charges - expected_charges).max() < 1e-5
Exemple #22
0
def test_load_molden_he2_ghost_psi4_1():
    # The file tested here is created with PSI4 (version 1.0). It should be read in
    # properly by ignoring the ghost atoms.
    fn_molden = context.get_fn('test/he2_ghost_psi4_1.0.molden')
    mol = IOData.from_file(fn_molden)
    np.testing.assert_equal(mol.pseudo_numbers, np.array([2.0]))
    # Check Mulliken charges. Comparison with numbers from the Molden program output.
    dm_full = mol.get_dm_full()
    charges = compute_mulliken_charges(mol.obasis, mol.lf, np.array([0.0, 2.0]), dm_full)
    molden_charges = np.array([-0.0041, 0.0041])
    assert abs(charges - molden_charges).max() < 5e-4
Exemple #23
0
def test_load_molden_nh3_turbomole():
    # The file tested here is created with Turbomole 7.1
    fn_molden = context.get_fn('test/nh3_turbomole.molden')
    mol = IOData.from_file(fn_molden)
    # Check Mulliken charges. Comparison with numbers from the Turbomole output. These
    # are slightly different than in the other tests because we are using Cartesian
    # functions.
    dm_full = mol.get_dm_full()
    charges = compute_mulliken_charges(mol.obasis, mol.lf, mol.pseudo_numbers, dm_full)
    molden_charges = np.array([0.03801, -0.27428, 0.01206, 0.22421])
    assert abs(charges - molden_charges).max() < 1e-3
Exemple #24
0
def test_load_molden_nh3_molden_cart():
    # The file tested here is created with molden. It should be read in
    # properly without altering normalization and sign conventions.
    fn_molden = context.get_fn('test/nh3_molden_cart.molden')
    mol = IOData.from_file(fn_molden)
    # Check Mulliken charges. Comparison with numbers from the Molden program output.
    dm_full = mol.get_dm_full()
    charges = compute_mulliken_charges(mol.obasis, mol.lf, mol.pseudo_numbers, dm_full)
    print charges
    molden_charges = np.array([0.3138, -0.4300, -0.0667, 0.1829])
    assert abs(charges - molden_charges).max() < 1e-3
Exemple #25
0
def test_load_molden_nh3_molden_cart():
    # The file tested here is created with molden. It should be read in
    # properly without altering normalization and sign conventions.
    fn_molden = context.get_fn('test/nh3_molden_cart.molden')
    mol = IOData.from_file(fn_molden)
    # Check Mulliken charges. Comparison with numbers from the Molden program output.
    dm_full = mol.get_dm_full()
    charges = compute_mulliken_charges(mol.obasis, mol.pseudo_numbers, dm_full)
    print charges
    molden_charges = np.array([0.3138, -0.4300, -0.0667, 0.1829])
    assert abs(charges - molden_charges).max() < 1e-3
Exemple #26
0
def test_load_molden_h2o():
    fn_mkl = context.get_fn('test/h2o.molden.input')
    sys = System.from_file(fn_mkl)

    # Check normalization
    sys.wfn.exp_alpha.check_normalization(sys.get_overlap(), 1e-5)

    # Check charges
    charges = compute_mulliken_charges(sys)
    expected_charges = np.array([-0.816308, 0.408154, 0.408154])
    assert abs(charges - expected_charges).max() < 1e-5
Exemple #27
0
def test_load_molden_nh3_turbomole():
    # The file tested here is created with Turbomole 7.1
    fn_molden = context.get_fn('test/nh3_turbomole.molden')
    mol = IOData.from_file(fn_molden)
    # Check Mulliken charges. Comparison with numbers from the Turbomole output. These
    # are slightly different than in the other tests because we are using Cartesian
    # functions.
    dm_full = mol.get_dm_full()
    charges = compute_mulliken_charges(mol.obasis, mol.pseudo_numbers, dm_full)
    molden_charges = np.array([0.03801, -0.27428, 0.01206, 0.22421])
    assert abs(charges - molden_charges).max() < 1e-3
Exemple #28
0
def test_load_wfn_h2o_sto3g_decontracted():
    fn_wfn = context.get_fn('test/h2o_sto3g_decontracted.wfn')
    sys = System.from_file(fn_wfn)
    assert isinstance(sys.wfn, RestrictedWFN)
    assert sys.obasis.nbasis == 21
    sys.wfn.exp_alpha.check_normalization(sys.get_overlap(), 1e-5)  #Chech normalization
    ham = Hamiltonian(sys, [HartreeFockExchange()])  #Compare to the energy printed in wfn file
    energy = ham.compute()
    assert abs(energy - (-75.162231674351)) < 1.e-5
    charges = compute_mulliken_charges(sys)                  #Check charges
    expected_charge = np.array([-0.546656, 0.273328, 0.273328])
    assert (abs(charges - expected_charge) < 1e-5).all()
Exemple #29
0
def test_load_mkl_li2():
    fn_mkl = context.get_fn('test/li2.mkl')
    sys = System.from_file(fn_mkl)

    # Check normalization
    sys.wfn.exp_alpha.check_normalization(sys.get_overlap(), 1e-5)
    sys.wfn.exp_beta.check_normalization(sys.get_overlap(), 1e5)

    # Check charges
    charges = compute_mulliken_charges(sys)
    expected_charges = np.array([0.5, 0.5])
    assert abs(charges - expected_charges).max() < 1e-5
Exemple #30
0
def test_load_molden_he2_ghost_psi4_1():
    # The file tested here is created with PSI4 (version 1.0). It should be read in
    # properly by ignoring the ghost atoms.
    fn_molden = context.get_fn('test/he2_ghost_psi4_1.0.molden')
    mol = IOData.from_file(fn_molden)
    np.testing.assert_equal(mol.pseudo_numbers, np.array([2.0]))
    # Check Mulliken charges. Comparison with numbers from the Molden program output.
    dm_full = mol.get_dm_full()
    charges = compute_mulliken_charges(mol.obasis, np.array([0.0, 2.0]),
                                       dm_full)
    molden_charges = np.array([-0.0041, 0.0041])
    assert abs(charges - molden_charges).max() < 5e-4
Exemple #31
0
def test_load_mkl_li2():
    fn_mkl = context.get_fn('test/li2.mkl')
    sys = System.from_file(fn_mkl)

    # Check normalization
    sys.wfn.exp_alpha.check_normalization(sys.get_overlap(), 1e-5)
    sys.wfn.exp_beta.check_normalization(sys.get_overlap(), 1e5)

    # Check charges
    charges = compute_mulliken_charges(sys)
    expected_charges = np.array([0.5, 0.5])
    assert abs(charges - expected_charges).max() < 1e-5
Exemple #32
0
def test_load_mkl_ethanol():
    fn_mkl = context.get_fn('test/ethanol.mkl')
    sys = System.from_file(fn_mkl)

    # Direct checks with mkl file
    assert sys.natom == 9
    assert sys.coordinates.shape == (9,3)
    assert sys.numbers[0] == 1
    assert sys.numbers[4] == 6
    assert abs(sys.coordinates[2,1]/angstrom - 2.239037) < 1e-5
    assert abs(sys.coordinates[5,2]/angstrom - 0.948420) < 1e-5
    assert sys.obasis.nbasis == 39
    assert sys.obasis.alphas[0] == 18.731137000
    assert sys.obasis.alphas[10] == 7.868272400
    assert sys.obasis.alphas[-3] == 2.825393700
    #assert sys.obasis.con_coeffs[5] == 0.989450608
    #assert sys.obasis.con_coeffs[7] == 2.079187061
    #assert sys.obasis.con_coeffs[-1] == 0.181380684
    assert (sys.obasis.shell_map[:5] == [0, 0, 1, 1, 1]).all()
    assert (sys.obasis.shell_types[:5] == [0, 0, 0, 0, 1]).all()
    assert (sys.obasis.nprims[-5:] == [3, 1, 1, 3, 1]).all()
    assert sys.wfn.exp_alpha.coeffs.shape == (39,39)
    assert sys.wfn.exp_alpha.energies.shape == (39,)
    assert sys.wfn.exp_alpha.occupations.shape == (39,)
    assert (sys.wfn.exp_alpha.occupations[:13] == 1.0).all()
    assert (sys.wfn.exp_alpha.occupations[13:] == 0.0).all()
    assert sys.wfn.exp_alpha.energies[4] == -1.0206976
    assert sys.wfn.exp_alpha.energies[-1] == 2.0748685
    assert sys.wfn.exp_alpha.coeffs[0,0] == 0.0000119
    assert sys.wfn.exp_alpha.coeffs[1,0] == -0.0003216
    assert sys.wfn.exp_alpha.coeffs[-1,-1] == -0.1424743

    # Comparison of derived properties with ORCA output file

    # nuclear-nuclear repulsion
    assert abs(sys.compute_nucnuc() - 81.87080034) < 1e-5

    # Check normalization
    sys.wfn.exp_alpha.check_normalization(sys.get_overlap(), 1e-5)

    # Mulliken charges
    charges = compute_mulliken_charges(sys)
    expected_charges = np.array([
        0.143316, -0.445861, 0.173045, 0.173021, 0.024542, 0.143066, 0.143080,
        -0.754230, 0.400021
    ])
    assert abs(charges - expected_charges).max() < 1e-5

    # Compute HF energy
    ham = Hamiltonian(sys, [HartreeFockExchange()])
    energy = ham.compute()
    assert abs(energy - -154.01322894) < 1e-4
Exemple #33
0
def test_load_mkl_ethanol():
    fn_mkl = context.get_fn('test/ethanol.mkl')
    mol = IOData.from_file(fn_mkl)

    # Direct checks with mkl file
    assert mol.numbers.shape == (9,)
    assert mol.numbers[0] == 1
    assert mol.numbers[4] == 6
    assert mol.coordinates.shape == (9,3)
    assert abs(mol.coordinates[2,1]/angstrom - 2.239037) < 1e-5
    assert abs(mol.coordinates[5,2]/angstrom - 0.948420) < 1e-5
    assert mol.obasis.nbasis == 39
    assert mol.obasis.alphas[0] == 18.731137000
    assert mol.obasis.alphas[10] == 7.868272400
    assert mol.obasis.alphas[-3] == 2.825393700
    #assert mol.obasis.con_coeffs[5] == 0.989450608
    #assert mol.obasis.con_coeffs[7] == 2.079187061
    #assert mol.obasis.con_coeffs[-1] == 0.181380684
    assert (mol.obasis.shell_map[:5] == [0, 0, 1, 1, 1]).all()
    assert (mol.obasis.shell_types[:5] == [0, 0, 0, 0, 1]).all()
    assert (mol.obasis.nprims[-5:] == [3, 1, 1, 3, 1]).all()
    assert mol.exp_alpha.coeffs.shape == (39,39)
    assert mol.exp_alpha.energies.shape == (39,)
    assert mol.exp_alpha.occupations.shape == (39,)
    assert (mol.exp_alpha.occupations[:13] == 1.0).all()
    assert (mol.exp_alpha.occupations[13:] == 0.0).all()
    assert mol.exp_alpha.energies[4] == -1.0206976
    assert mol.exp_alpha.energies[-1] == 2.0748685
    assert mol.exp_alpha.coeffs[0,0] == 0.0000119
    assert mol.exp_alpha.coeffs[1,0] == -0.0003216
    assert mol.exp_alpha.coeffs[-1,-1] == -0.1424743

    # Comparison of derived properties with ORCA output file

    # nuclear-nuclear repulsion
    assert abs(compute_nucnuc(mol.coordinates, mol.pseudo_numbers) - 81.87080034) < 1e-5

    # Check normalization
    olp = mol.obasis.compute_overlap(mol.lf)
    mol.exp_alpha.check_normalization(olp, 1e-5)

    # Mulliken charges
    dm_full = mol.get_dm_full()
    charges = compute_mulliken_charges(mol.obasis, mol.lf, mol.numbers, dm_full)
    expected_charges = np.array([
        0.143316, -0.445861, 0.173045, 0.173021, 0.024542, 0.143066, 0.143080,
        -0.754230, 0.400021
    ])
    assert abs(charges - expected_charges).max() < 1e-5

    # Compute HF energy
    assert abs(compute_hf_energy(mol) - -154.01322894) < 1e-4
Exemple #34
0
def test_load_mkl_ethanol():
    fn_mkl = context.get_fn('test/ethanol.mkl')
    sys = System.from_file(fn_mkl)

    # Direct checks with mkl file
    assert sys.natom == 9
    assert sys.coordinates.shape == (9, 3)
    assert sys.numbers[0] == 1
    assert sys.numbers[4] == 6
    assert abs(sys.coordinates[2, 1] / angstrom - 2.239037) < 1e-5
    assert abs(sys.coordinates[5, 2] / angstrom - 0.948420) < 1e-5
    assert sys.obasis.nbasis == 39
    assert sys.obasis.alphas[0] == 18.731137000
    assert sys.obasis.alphas[10] == 7.868272400
    assert sys.obasis.alphas[-3] == 2.825393700
    #assert sys.obasis.con_coeffs[5] == 0.989450608
    #assert sys.obasis.con_coeffs[7] == 2.079187061
    #assert sys.obasis.con_coeffs[-1] == 0.181380684
    assert (sys.obasis.shell_map[:5] == [0, 0, 1, 1, 1]).all()
    assert (sys.obasis.shell_types[:5] == [0, 0, 0, 0, 1]).all()
    assert (sys.obasis.nprims[-5:] == [3, 1, 1, 3, 1]).all()
    assert sys.wfn.exp_alpha.coeffs.shape == (39, 39)
    assert sys.wfn.exp_alpha.energies.shape == (39, )
    assert sys.wfn.exp_alpha.occupations.shape == (39, )
    assert (sys.wfn.exp_alpha.occupations[:13] == 1.0).all()
    assert (sys.wfn.exp_alpha.occupations[13:] == 0.0).all()
    assert sys.wfn.exp_alpha.energies[4] == -1.0206976
    assert sys.wfn.exp_alpha.energies[-1] == 2.0748685
    assert sys.wfn.exp_alpha.coeffs[0, 0] == 0.0000119
    assert sys.wfn.exp_alpha.coeffs[1, 0] == -0.0003216
    assert sys.wfn.exp_alpha.coeffs[-1, -1] == -0.1424743

    # Comparison of derived properties with ORCA output file

    # nuclear-nuclear repulsion
    assert abs(sys.compute_nucnuc() - 81.87080034) < 1e-5

    # Check normalization
    sys.wfn.exp_alpha.check_normalization(sys.get_overlap(), 1e-5)

    # Mulliken charges
    charges = compute_mulliken_charges(sys)
    expected_charges = np.array([
        0.143316, -0.445861, 0.173045, 0.173021, 0.024542, 0.143066, 0.143080,
        -0.754230, 0.400021
    ])
    assert abs(charges - expected_charges).max() < 1e-5

    # Compute HF energy
    ham = Hamiltonian(sys, [HartreeFockExchange()])
    energy = ham.compute()
    assert abs(energy - -154.01322894) < 1e-4
Exemple #35
0
def test_load_wfn_h2o_sto3g():
    fn_wfn = context.get_fn('test/h2o_sto3g.wfn')
    sys = System.from_file(fn_wfn)
    assert isinstance(sys.wfn, RestrictedWFN)
    sys.wfn.exp_alpha.check_normalization(sys.get_overlap(),
                                          1e-5)  #Check normalization
    ham = Hamiltonian(sys, [HartreeFockExchange()])
    energy = ham.compute()
    assert abs(energy - (
        -74.965901217080)) < 1.e-5  #Compare to the energy printed in wfn file
    charges = compute_mulliken_charges(sys)  #Check charges
    expected_charge = np.array([-0.330532, 0.165266, 0.165266])
    assert (abs(charges - expected_charge) < 1e-5).all()
Exemple #36
0
def test_load_mkl_li2():
    fn_mkl = context.get_fn('test/li2.mkl')
    mol = IOData.from_file(fn_mkl)

    # Check normalization
    olp = mol.obasis.compute_overlap(mol.lf)
    mol.exp_alpha.check_normalization(olp, 1e-5)
    mol.exp_beta.check_normalization(olp, 1e-5)

    # Check charges
    dm_full = mol.get_dm_full()
    charges = compute_mulliken_charges(mol.obasis, mol.lf, mol.numbers, dm_full)
    expected_charges = np.array([0.5, 0.5])
    assert abs(charges - expected_charges).max() < 1e-5
Exemple #37
0
def test_load_wfn_h2o_sto3g_decontracted():
    fn_wfn = context.get_fn('test/h2o_sto3g_decontracted.wfn')
    sys = System.from_file(fn_wfn)
    assert isinstance(sys.wfn, RestrictedWFN)
    assert sys.obasis.nbasis == 21
    sys.wfn.exp_alpha.check_normalization(sys.get_overlap(),
                                          1e-5)  #Chech normalization
    ham = Hamiltonian(
        sys,
        [HartreeFockExchange()])  #Compare to the energy printed in wfn file
    energy = ham.compute()
    assert abs(energy - (-75.162231674351)) < 1.e-5
    charges = compute_mulliken_charges(sys)  #Check charges
    expected_charge = np.array([-0.546656, 0.273328, 0.273328])
    assert (abs(charges - expected_charge) < 1e-5).all()
Exemple #38
0
def test_load_molden_h2o_orca():
    fn_molden = context.get_fn('test/h2o.molden.input')
    mol = IOData.from_file(fn_molden)

    # Checkt title
    assert mol.title == 'Molden file created by orca_2mkl for BaseName=h2o'

    # Check normalization
    olp = mol.obasis.compute_overlap()
    mol.orb_alpha.check_normalization(olp, 1e-5)

    # Check Mulliken charges
    dm_full = mol.get_dm_full()
    charges = compute_mulliken_charges(mol.obasis, mol.pseudo_numbers, dm_full)
    expected_charges = np.array([-0.816308, 0.408154, 0.408154])
    assert abs(charges - expected_charges).max() < 1e-5
Exemple #39
0
def test_load_molden_h2o_orca():
    fn_molden = context.get_fn('test/h2o.molden.input')
    mol = IOData.from_file(fn_molden)

    # Checkt title
    assert mol.title == 'Molden file created by orca_2mkl for BaseName=h2o'

    # Check normalization
    olp = mol.obasis.compute_overlap(mol.lf)
    mol.exp_alpha.check_normalization(olp, 1e-5)

    # Check Mulliken charges
    dm_full = mol.get_dm_full()
    charges = compute_mulliken_charges(mol.obasis, mol.lf, mol.pseudo_numbers, dm_full)
    expected_charges = np.array([-0.816308, 0.408154, 0.408154])
    assert abs(charges - expected_charges).max() < 1e-5
Exemple #40
0
def test_load_wfn_h2_ccpvqz_virtual():
    fn_wfn = context.get_fn('test/h2_ccpvqz.wfn')
    sys = System.from_file(fn_wfn)
    assert isinstance(sys.wfn, RestrictedWFN)
    assert sys.obasis.nbasis == 74
    sys.wfn.exp_alpha.check_normalization(sys.get_overlap(), 1e-5)  #Chech normalization
    assert (abs(sys.obasis.alphas[:5] - [82.64000, 12.41000, 2.824000, 0.7977000, 0.2581000]) < 1.e-5).all()
    assert (sys.wfn.exp_alpha.energies[:5] == [-0.596838, 0.144565, 0.209605, 0.460401, 0.460401]).all()
    assert (sys.wfn.exp_alpha.energies[-5:] == [12.859067, 13.017471, 16.405834, 25.824716, 26.100443]).all()
    assert (sys.wfn.exp_alpha.occupations[:5] == [1.0, 0.0, 0.0, 0.0, 0.0] ).all()
    assert abs(sys.wfn.exp_alpha.occupations.sum() - 1.0) < 1.e-6
    ham = Hamiltonian(sys, [HartreeFockExchange()])
    energy = ham.compute()
    assert abs(energy - (-1.133504568400)) < 1.e-5   #Compare to the energy printed in wfn file
    charges = compute_mulliken_charges(sys)     #Check charges
    expected_charge = np.array([0.0, 0.0])
    assert (abs(charges - expected_charge) < 1e-5).all()
Exemple #41
0
def check_wfn(fn_wfn, restricted, nbasis, energy, charges):
    fn_wfn = context.get_fn(fn_wfn)
    mol = IOData.from_file(fn_wfn)
    assert mol.obasis.nbasis == nbasis
    olp = mol.obasis.compute_overlap(mol.lf)
    if restricted:
        mol.exp_alpha.check_normalization(olp, 1e-5)
        assert not hasattr(mol, 'exp_beta')
    else:
        mol.exp_alpha.check_normalization(olp, 1e-5)
        mol.exp_beta.check_normalization(olp, 1e-5)
    if energy is not None:
        myenergy = compute_hf_energy(mol)
        assert abs(energy - myenergy) < 1e-5
    dm_full = mol.get_dm_full()
    mycharges = compute_mulliken_charges(mol.obasis, mol.lf, mol.numbers, dm_full)
    assert (abs(charges - mycharges) < 1e-5).all()
    return mol.obasis, mol.lf, mol.coordinates, mol.numbers, dm_full, mol.exp_alpha, getattr(mol, 'exp_beta', None)
Exemple #42
0
def test_load_molden_li2_orca():
    fn_molden = context.get_fn('test/li2.molden.input')
    mol = IOData.from_file(fn_molden)

    # Checkt title
    assert mol.title == 'Molden file created by orca_2mkl for BaseName=li2'

    # Check normalization
    olp = mol.obasis.compute_overlap(mol.lf)
    mol.exp_alpha.check_normalization(olp, 1e-5)
    mol.exp_beta.check_normalization(olp, 1e-5)

    # Check Mulliken charges
    dm_full = mol.get_dm_full()
    charges = compute_mulliken_charges(mol.obasis, mol.lf, mol.numbers,
                                       dm_full)
    expected_charges = np.array([0.5, 0.5])
    assert abs(charges - expected_charges).max() < 1e-5
Exemple #43
0
def test_load_wfn_lih_cation_fci():
    fn_wfn = context.get_fn('test/lih_cation_fci.wfn')
    sys = System.from_file(fn_wfn)
    assert sys.natom == 2
    assert sys.obasis.nbasis == 26
    assert (sys.numbers == [3, 1]).all()
    sys.wfn.exp_alpha.check_normalization(sys.get_overlap(), 1e-5) #Check normalization
    ham = Hamiltonian(sys, [HartreeFockExchange()])
    energy = ham.compute() #cannot be compared!
    kin = sys.extra['energy_kin']
    nn = sys.extra['energy_nn']
    expected_kin = 7.7989675958  #FCI kinetic energy
    expected_nn = 0.9766607347
    assert (kin - expected_kin) < 1.e-6
    assert (nn - expected_nn) < 1.e-6
    assert sys.wfn.exp_alpha.occupations.shape == (11,)
    assert abs(sys.wfn.exp_alpha.occupations.sum() - 1.5) < 1.e-6
    charges = compute_mulliken_charges(sys)   #Check charges
    expected_charge = np.array([0.913206, 0.086794])
    assert (abs(charges - expected_charge) < 1e-5).all()
    point = np.array([])
Exemple #44
0
def test_load_wfn_li_sp_virtual():
    fn_wfn = context.get_fn('test/li_sp_virtual.wfn')
    sys = System.from_file(fn_wfn)
    assert isinstance(sys.wfn, UnrestrictedWFN)
    assert sys.obasis.nbasis == 8
    sys.wfn.exp_alpha.check_normalization(sys.get_overlap(), 1e-5) #Check normalization
    sys.wfn.exp_beta.check_normalization(sys.get_overlap(), 1e-5)  #Check normalization
    assert abs(sys.wfn.exp_alpha.occupations.sum() - 2.0) < 1.e-6
    assert abs(sys.wfn.exp_beta.occupations.sum()  - 1.0) < 1.e-6
    assert (sys.wfn.exp_alpha.occupations == [1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]).all()
    assert (sys.wfn.exp_beta.occupations  == [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]).all()
    assert (abs(sys.wfn.exp_alpha.energies - [-0.087492, -0.080310, 0.158784, 0.158784, 1.078773, 1.090891, 1.090891, 49.643670]) < 1.e-6).all()
    assert (abs(sys.wfn.exp_beta.energies  - [-0.079905, 0.176681, 0.176681, 0.212494, 1.096631, 1.096631, 1.122821, 49.643827]) < 1.e-6).all()
    assert sys.wfn.exp_alpha.coeffs.shape == (8, 8)
    assert sys.wfn.exp_beta.coeffs.shape  == (8, 8)
    ham = Hamiltonian(sys, [HartreeFockExchange()])
    energy = ham.compute()
    assert abs(energy - (-3.712905542719)) < 1.e-6   #Compare to the energy printed in wfn file
    charges = compute_mulliken_charges(sys)   #Check charges
    expected_charge = np.array([0.0, 0.0])
    assert (abs(charges - expected_charge) < 1e-5).all()
Exemple #45
0
def test_load_wfn_lih_cation_fci():
    fn_wfn = context.get_fn('test/lih_cation_fci.wfn')
    sys = System.from_file(fn_wfn)
    assert sys.natom == 2
    assert sys.obasis.nbasis == 26
    assert (sys.numbers == [3, 1]).all()
    sys.wfn.exp_alpha.check_normalization(sys.get_overlap(),
                                          1e-5)  #Check normalization
    ham = Hamiltonian(sys, [HartreeFockExchange()])
    energy = ham.compute()  #cannot be compared!
    kin = sys.extra['energy_kin']
    nn = sys.extra['energy_nn']
    expected_kin = 7.7989675958  #FCI kinetic energy
    expected_nn = 0.9766607347
    assert (kin - expected_kin) < 1.e-6
    assert (nn - expected_nn) < 1.e-6
    assert sys.wfn.exp_alpha.occupations.shape == (11, )
    assert abs(sys.wfn.exp_alpha.occupations.sum() - 1.5) < 1.e-6
    charges = compute_mulliken_charges(sys)  #Check charges
    expected_charge = np.array([0.913206, 0.086794])
    assert (abs(charges - expected_charge) < 1e-5).all()
    point = np.array([])