Пример #1
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
Пример #2
0
def test_load_mkl_h2():
    fn_mkl = context.get_fn('test/h2_sto3g.mkl')
    mol = IOData.from_file(fn_mkl)
    olp = mol.obasis.compute_overlap(mol.lf)
    mol.exp_alpha.check_normalization(olp, 1e-5)

    # Compute HF energy
    assert abs(compute_hf_energy(mol) - -1.11750589) < 1e-4
Пример #3
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
Пример #4
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
Пример #5
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
Пример #6
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)