def test_coulomb_calc_electric_potential_energy_returns_correct_potential_energy_of_hydrogen(self):
     nuclei_a = Nuclei('HYDROGEN', 1, 1, (0, 0, 0.70))
     nuclei_b = Nuclei('HYDROGEN', 1, 1, (0, 0, -0.7))
     nuclei_array = [nuclei_a, nuclei_b]
     energy = coulomb_matrix(nuclei_array)
     testing.assert_approx_equal(energy.item(0, 1), 0.7143, 4)
Exemplo n.º 2
0
def start(mol, basis, method, processes, symmetry=False):
    np.set_printoptions(linewidth=100000, threshold=np.inf)
    start_time = time.clock()
    electron_energy = correlation = 0.0

    nuclei_array, electrons, multiplicity = read_mol_file(mol)

    if symmetry:
        molecule = MoleculeFactory().point_group(nuclei_array)
    else:
        molecule = Molecule(nuclei_array, PointGroup([], [], [], [], 'C_{1}'))

    basis_set_array = read_basis_set_file(basis, molecule.nuclei_array)
    symmetry_object = Symmetry(molecule.point_group, basis_set_array)

    coulomb_law_matrix = coulomb_matrix(nuclei_array)
    nuclear_repulsion = coulomb_law_matrix.sum() / 2

    print('\n*************************************************************************************************')
    print('\nA BASIC QUANTUM CHEMICAL PROGRAM IN PYTHON\n\n\n{}'.format([x.element for x in nuclei_array]))
    print('\nNUCLEAR REPULSION ARRAY\n{}'.format(coulomb_law_matrix))

    if method == 'RHF':
        electron_energy = RestrictedHF(molecule.nuclei_array, basis_set_array, electrons, symmetry_object,
        processes).begin_scf()[0]
    if method == 'UHF':
        electron_energy = UnrestrictedHF(molecule.nuclei_array, basis_set_array, electrons, multiplicity,
        symmetry_object, processes).begin_scf()[0]
    if method == 'GUHF':
        electron_energy = BlockedHartreeFock(molecule.nuclei_array, basis_set_array, electrons, multiplicity,
        symmetry_object, processes).begin_scf()[0]
    if method == 'MP2':
        mp2 = MoellerPlesset(
        RestrictedHF(molecule.nuclei_array, basis_set_array, electrons, symmetry_object, processes))
        electron_energy = mp2.hartree_fock_energy
        correlation = mp2.second_order()
    if method == 'TDHF':
        electron_energy = TimeDependentHartreeFock(
        RestrictedHF(molecule.nuclei_array, basis_set_array, electrons, symmetry_object, processes)
        ).calculate(tda=False)
    if method == 'CIS':
        electron_energy = TimeDependentHartreeFock(
        RestrictedHF(molecule.nuclei_array, basis_set_array, electrons, symmetry_object, processes)
        ).calculate(tda=True)
    if method[0] == 'DFT':
        electron_energy = RestrictedKohnSham(molecule.nuclei_array, basis_set_array, electrons,
        symmetry_object, processes, method[1], method[2]).begin_scf()[0]
    if method == 'CCSD':
        ccsd = CoupledClusterSinglesDoubles(
        RestrictedHF(molecule.nuclei_array, basis_set_array, electrons, symmetry_object, processes))
        electron_energy = ccsd.hartree_fock_energy
        correlation = ccsd.calculate_singles_doubles()[0]
    if method == 'CCSD(T)':
        ccsd = CoupledClusterPerturbativeTriples(
        RestrictedHF(molecule.nuclei_array, basis_set_array, electrons, symmetry_object, processes))
        electron_energy = ccsd.hartree_fock_energy
        correlation = ccsd.calculate_perturbative_triples()

    total_energy = electron_energy + nuclear_repulsion + correlation
    print('NUCLEAR REPULSION ENERGY:    ' + str(nuclear_repulsion) + ' a.u.')
    print('SCF ENERGY:                  ' + str(electron_energy) + ' a.u.')
    print('CORRELATION ENERGY:          ' + str(correlation) + ' a.u.')
    print('TOTAL ENERGY:                ' + str(total_energy) + ' a.u.')
    print('\n*************************************************************************************************')
    print('\nTIME TAKEN: ' + str(time.clock() - start_time) + 's')
    print("\nWhat I cannot create I cannot understand - Richard Feynman\n")

    return total_energy
 def test_coulomb_calc_electric_potential_energy_returns_correct_potential_energy_of_heh_anion(self):
     nuclei_a = Nuclei('HYDROGEN', 1, 1, (0, 0, 0.7316))
     nuclei_b = Nuclei('HELIUM', 2, 4, (0, 0, -0.7316))
     nuclei_array = [nuclei_a, nuclei_b]
     energy = coulomb_matrix(nuclei_array)
     testing.assert_approx_equal(energy.item(0, 1), 1.366867, 7)