def test_create_basis_set_array_returns_basis_array_with_correct_coordinates_for_3_21g(self): basis_file = os.path.join(os.path.dirname(__file__), '3-21G.gbs') basis_array = read_basis_set_file(basis_file, self.nuclei_array) testing.assert_array_equal(basis_array[0].coordinates, (0.000000, 0.000000, 0.7316)) testing.assert_array_equal(basis_array[1].coordinates, (0.000000, 0.000000, 0.7316)) testing.assert_array_equal(basis_array[2].coordinates, (0.000000, 0.000000, -0.7316)) testing.assert_array_equal(basis_array[3].coordinates, (0.000000, 0.000000, -0.7316))
def start(mol_file, basis_file, method, processors, symmetry=False, geometry_optimization=None): np.set_printoptions(linewidth=100000, threshold=np.inf) start_time = time.perf_counter() nuclei_list, electrons, multiplicity = read_mol_file(mol_file) energy_object = Energy(electrons, multiplicity, processors, method) print( '\n*************************************************************************************************' ) print('\nA BASIC QUANTUM CHEMICAL PROGRAM IN PYTHON\n\n\n{}'.format( [x.element for x in nuclei_list])) if geometry_optimization is not None: nelder_mead = NelderMead(basis_file, energy_object, nuclei_list) energy = nelder_mead.optimize() else: nuclei_list, point_group = MoleculeFactory(symmetry).create( nuclei_list) basis_set = read_basis_set_file(basis_file, nuclei_list) energy_object.symmetry_object = Symmetry(point_group, basis_set) energy = energy_object.calculate_energy(nuclei_list, basis_set) print( '\n*************************************************************************************************' ) print('\nTIME TAKEN: ' + str(time.perf_counter() - start_time) + 's') print("\nWhat I cannot create I cannot understand - Richard Feynman\n") return energy
def test_create_basis_set_array_returns_basis_array_with_exponents_for_sto_3g(self): basis_file = os.path.join(os.path.dirname(__file__), 'STO-3G.gbs') basis_array = read_basis_set_file(basis_file, self.nuclei_array) self.assertEqual(basis_array[0].primitive_gaussian_array[0].exponent, 6.36242139) self.assertEqual(basis_array[0].primitive_gaussian_array[1].exponent, 1.15892300) self.assertEqual(basis_array[0].primitive_gaussian_array[2].exponent, 0.31364979) self.assertEqual(basis_array[1].primitive_gaussian_array[0].exponent, 3.42525091) self.assertEqual(basis_array[1].primitive_gaussian_array[1].exponent, 0.62391373) self.assertEqual(basis_array[1].primitive_gaussian_array[2].exponent, 0.16885540)
def test_create_basis_set_array_returns_basis_array_with_contraction_coefficients_for_sto_3g(self): basis_file = os.path.join(os.path.dirname(__file__), 'STO-3G.gbs') basis_array = read_basis_set_file(basis_file, self.nuclei_array) self.assertEqual(basis_array[0].primitive_gaussian_array[0].contraction, 0.15432897) self.assertEqual(basis_array[0].primitive_gaussian_array[1].contraction, 0.53532814) self.assertEqual(basis_array[0].primitive_gaussian_array[2].contraction, 0.44463454) self.assertEqual(basis_array[1].primitive_gaussian_array[0].contraction, 0.15432897) self.assertEqual(basis_array[1].primitive_gaussian_array[1].contraction, 0.53532814) self.assertEqual(basis_array[1].primitive_gaussian_array[2].contraction, 0.44463454)
def test_create_basis_set_array_returns_basis_array_with_primitives_with_s_orbital_type_exponents_for_sto_3g(self): basis_file = os.path.join(os.path.dirname(__file__), 'STO-3G.gbs') basis_array = read_basis_set_file(basis_file, self.nuclei_array) self.assertEqual(basis_array[0].primitive_gaussian_array[0].integral_exponents, (0, 0, 0)) self.assertEqual(basis_array[0].primitive_gaussian_array[1].integral_exponents, (0, 0, 0)) self.assertEqual(basis_array[0].primitive_gaussian_array[2].integral_exponents, (0, 0, 0)) self.assertEqual(basis_array[1].primitive_gaussian_array[0].integral_exponents, (0, 0, 0)) self.assertEqual(basis_array[1].primitive_gaussian_array[1].integral_exponents, (0, 0, 0)) self.assertEqual(basis_array[1].primitive_gaussian_array[2].integral_exponents, (0, 0, 0))
def test_create_basis_set_array_returns_basis_array_with_primitives_with_coordinates_for_sto_3g(self): basis_file = os.path.join(os.path.dirname(__file__), 'STO-3G.gbs') basis_array = read_basis_set_file(basis_file, self.nuclei_array) self.assertEqual(basis_array[0].primitive_gaussian_array[0].coordinates, (0.000000, 0.000000, 0.7316)) self.assertEqual(basis_array[0].primitive_gaussian_array[1].coordinates, (0.000000, 0.000000, 0.7316)) self.assertEqual(basis_array[0].primitive_gaussian_array[2].coordinates, (0.000000, 0.000000, 0.7316)) self.assertEqual(basis_array[1].primitive_gaussian_array[0].coordinates, (0.000000, 0.000000, -0.7316)) self.assertEqual(basis_array[1].primitive_gaussian_array[1].coordinates, (0.000000, 0.000000, -0.7316)) self.assertEqual(basis_array[1].primitive_gaussian_array[2].coordinates, (0.000000, 0.000000, -0.7316))
def calculate_energy(self, coordinate_list): j = 0 for i, nuclei in enumerate(self.nuclei_list): if i == 0: nuclei.coordinates = (0.0, 0.0, coordinate_list.item(j)) j += 1 elif i == 1: nuclei.coordinates = (0.0, coordinate_list.item(j), coordinate_list.item(j+1)) j += 2 else: nuclei.coordinates = (coordinate_list.item(j), coordinate_list.item(j+1), coordinate_list.item(j+2)) j += 3 with redirect_stdout(open(os.devnull, "w")): basis_set = read_basis_set_file(self.basis_file, self.first_nuclei + self.nuclei_list) energy = self.energy_object.calculate_energy(self.first_nuclei + self.nuclei_list, basis_set) return energy