From 93cf65c3287a647426a58abaac0675a15cb05938 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 11 Jan 2024 21:01:48 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- gbasis/contractions.py | 19 +++-- gbasis/evals/stress_tensor.py | 8 +- gbasis/integrals/electron_repulsion.py | 4 +- .../integrals/nuclear_electron_attraction.py | 8 +- gbasis/integrals/point_charge.py | 4 +- tests/test_angular_momentum.py | 12 +-- tests/test_base.py | 20 +++-- tests/test_base_four_symm.py | 66 +++++++++++---- tests/test_base_one.py | 44 +++++++--- tests/test_base_two_asymm.py | 64 ++++++++++---- tests/test_base_two_symm.py | 84 +++++++++++++------ tests/test_contractions.py | 22 +++-- tests/test_density.py | 20 ++--- tests/test_electron_repulsion.py | 37 ++++---- tests/test_electrostatic_potential.py | 46 ++++++---- tests/test_eval.py | 42 ++++++---- tests/test_eval_deriv.py | 38 ++++----- tests/test_kinetic_energy.py | 30 +++---- tests/test_moment.py | 12 +-- tests/test_momentum.py | 12 +-- tests/test_nuclear_electron_attraction.py | 36 +++----- tests/test_one_elec_int.py | 24 ++++-- tests/test_overlap.py | 32 +++---- tests/test_overlap_asymm.py | 55 +++++++----- tests/test_parsers.py | 18 ++-- tests/test_point_charge.py | 32 +++---- tests/test_stress_tensor.py | 6 +- 27 files changed, 480 insertions(+), 315 deletions(-) diff --git a/gbasis/contractions.py b/gbasis/contractions.py index 92e4c46d..f8c742a4 100644 --- a/gbasis/contractions.py +++ b/gbasis/contractions.py @@ -519,14 +519,17 @@ def coord_type(self, coord_type): - 'spherical' """ - if not isinstance(coord_type, str): raise TypeError("Coordinate type must be given as a string.") if coord_type not in ["c", "cartesian", "p", "spherical"]: - raise ValueError("`coord_type` is incorrectly specified. It must be either 'c' " - "or 'cartesian' for Cartesian coordinates, or 'p' or 'spherical' " - "for spherical coordinates.") - self._coord_type = {"c": "cartesian", - "cartesian": "cartesian", - "spherical": "spherical", - "p": "spherical"}[coord_type] + raise ValueError( + "`coord_type` is incorrectly specified. It must be either 'c' " + "or 'cartesian' for Cartesian coordinates, or 'p' or 'spherical' " + "for spherical coordinates." + ) + self._coord_type = { + "c": "cartesian", + "cartesian": "cartesian", + "spherical": "spherical", + "p": "spherical", + }[coord_type] diff --git a/gbasis/evals/stress_tensor.py b/gbasis/evals/stress_tensor.py index 629b88ed..722289a3 100644 --- a/gbasis/evals/stress_tensor.py +++ b/gbasis/evals/stress_tensor.py @@ -9,9 +9,7 @@ # TODO: need to be tested against reference -def evaluate_stress_tensor( - one_density_matrix, basis, points, alpha=1, beta=0, transform=None -): +def evaluate_stress_tensor(one_density_matrix, basis, points, alpha=1, beta=0, transform=None): r"""Return the stress tensor evaluated at the given coordinates. Stress tensor is defined here as: @@ -129,9 +127,7 @@ def evaluate_stress_tensor( # TODO: need to be tested against reference -def evaluate_ehrenfest_force( - one_density_matrix, basis, points, alpha=1, beta=0, transform=None -): +def evaluate_ehrenfest_force(one_density_matrix, basis, points, alpha=1, beta=0, transform=None): r"""Return the Ehrenfest force. Ehrenfest force is the negative of the divergence of the stress tensor: diff --git a/gbasis/integrals/electron_repulsion.py b/gbasis/integrals/electron_repulsion.py index 8d441833..8ac4b63f 100644 --- a/gbasis/integrals/electron_repulsion.py +++ b/gbasis/integrals/electron_repulsion.py @@ -204,9 +204,7 @@ def construct_array_contraction(cls, cont_one, cont_two, cont_three, cont_four): return integrals -def electron_repulsion_integral( - basis, transform=None, notation="physicist" -): +def electron_repulsion_integral(basis, transform=None, notation="physicist"): """Return the electron repulsion integrals fo the given basis set. Parameters diff --git a/gbasis/integrals/nuclear_electron_attraction.py b/gbasis/integrals/nuclear_electron_attraction.py index bf50c129..d6e96d96 100644 --- a/gbasis/integrals/nuclear_electron_attraction.py +++ b/gbasis/integrals/nuclear_electron_attraction.py @@ -4,9 +4,7 @@ from gbasis.integrals.point_charge import point_charge_integral -def nuclear_electron_attraction_integral( - basis, nuclear_coords, nuclear_charges, transform=None -): +def nuclear_electron_attraction_integral(basis, nuclear_coords, nuclear_charges, transform=None): """Return the nuclear electron attraction integrals of the basis set in the Cartesian form. Parameters @@ -33,8 +31,6 @@ def nuclear_electron_attraction_integral( """ return np.sum( - point_charge_integral( - basis, nuclear_coords, nuclear_charges, transform=transform - ), + point_charge_integral(basis, nuclear_coords, nuclear_charges, transform=transform), axis=2, ) diff --git a/gbasis/integrals/point_charge.py b/gbasis/integrals/point_charge.py index 28b2af10..9730ea47 100644 --- a/gbasis/integrals/point_charge.py +++ b/gbasis/integrals/point_charge.py @@ -269,9 +269,7 @@ def construct_array_contraction( return output -def point_charge_integral( - basis, points_coords, points_charge, transform=None -): +def point_charge_integral(basis, points_coords, points_charge, transform=None): r"""Return the point-charge interaction integrals of basis set in the given coordinate systems. Parameters diff --git a/tests/test_angular_momentum.py b/tests/test_angular_momentum.py index 82407e00..0ebcf476 100644 --- a/tests/test_angular_momentum.py +++ b/tests/test_angular_momentum.py @@ -15,10 +15,10 @@ def test_angular_momentum_construct_array_contraction(): """Test integrals.angular_momentum.angular_momentumIntegral.construct_array_contraction.""" test_one = GeneralizedContractionShell( - 1, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.01]), 'spherical' + 1, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.01]), "spherical" ) test_two = GeneralizedContractionShell( - 2, np.array([1.5, 2, 3]), np.array([3.0, 4.0]), np.array([0.2, 0.02]), 'spherical' + 2, np.array([1.5, 2, 3]), np.array([3.0, 4.0]), np.array([0.2, 0.02]), "spherical" ) # copied the code it is testing @@ -370,7 +370,7 @@ def test_angular_momentum_construct_array_contraction(): def test_angular_momentum_integral_cartesian(): """Test gbasis.integrals.angular_momentum.angular_momentum_integral_cartesian.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'cartesian') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "cartesian") angular_momentum_integral_obj = AngularMomentumIntegral(basis) assert np.allclose( angular_momentum_integral_obj.construct_array_cartesian(), @@ -382,7 +382,7 @@ def test_angular_momentum_integral_spherical(): """Test gbasis.integrals.angular_momentum.angular_momentum_integral_spherical.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "spherical") angular_momentum_integral_obj = AngularMomentumIntegral(basis) assert np.allclose( angular_momentum_integral_obj.construct_array_spherical(), @@ -394,7 +394,7 @@ def test_angular_momentum_integral_mix(): """Test gbasis.integrals.angular_momentum.angular_momentum_integral_mix.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), ['spherical'] * 8) + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), ["spherical"] * 8) angular_momentum_integral_obj = AngularMomentumIntegral(basis) assert np.allclose( angular_momentum_integral_obj.construct_array_mix(["spherical"] * 8), @@ -405,7 +405,7 @@ def test_angular_momentum_integral_mix(): def test_angular_momentum_integral_lincomb(): """Test gbasis.integrals.angular_momentum.angular_momentum_integral_lincomb.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "spherical") angular_momentum_integral_obj = AngularMomentumIntegral(basis) transform = np.random.rand(14, 18) assert np.allclose( diff --git a/tests/test_base.py b/tests/test_base.py index 0fd17bd5..e43854c5 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -11,7 +11,9 @@ def test_init(): """Test base.BaseGaussianRelatedArray.""" Test = disable_abstract(BaseGaussianRelatedArray) test = skip_init(Test) - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) assert not hasattr(test, "_axes_contractions") with pytest.raises(TypeError): Test.__init__(test, set([contractions])) @@ -39,7 +41,9 @@ def test_contruct_array_contraction(): "construct_array_contraction": BaseGaussianRelatedArray.construct_array_contraction }, ) - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) with pytest.raises(TypeError): Test([contractions]) @@ -53,7 +57,9 @@ def test_contruct_array_cartesian(): "construct_array_cartesian": BaseGaussianRelatedArray.construct_array_cartesian }, ) - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) with pytest.raises(TypeError): Test([contractions]) @@ -67,7 +73,9 @@ def test_contruct_array_spherical(): "construct_array_spherical": BaseGaussianRelatedArray.construct_array_spherical }, ) - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) with pytest.raises(TypeError): Test([contractions]) @@ -81,6 +89,8 @@ def test_contruct_array_lincomb(): "construct_array_lincomb": BaseGaussianRelatedArray.construct_array_lincomb }, ) - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) with pytest.raises(TypeError): Test([contractions]) diff --git a/tests/test_base_four_symm.py b/tests/test_base_four_symm.py index ae2a76fb..4a1aba9e 100644 --- a/tests/test_base_four_symm.py +++ b/tests/test_base_four_symm.py @@ -12,7 +12,9 @@ def test_init(): """Test BaseFourIndexSymmetric.__init__.""" Test = disable_abstract(BaseFourIndexSymmetric) test = skip_init(Test) - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) Test.__init__(test, [contractions]) assert test._axes_contractions[0][0] == contractions with pytest.raises(TypeError): @@ -22,7 +24,7 @@ def test_init(): def test_contractions(): """Test BaseFourIndexSymmetric.contractions.""" Test = disable_abstract(BaseFourIndexSymmetric) - cont = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + cont = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical") test = Test([cont]) assert test.contractions[0] == cont @@ -36,15 +38,21 @@ def test_construct_array_contraction(): "construct_array_contraction": BaseFourIndexSymmetric.construct_array_contraction }, ) - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) with pytest.raises(TypeError): Test([contractions]) def test_construct_array_cartesian(): """Test BaseFourIndexSymmetric.construct_array_cartesian.""" - cont_one = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones((1, 1)), np.ones(1), 'spherical') - cont_two = GeneralizedContractionShell(2, np.array([2, 3, 4]), np.ones((1, 1)), 2 * np.ones(1), 'spherical') + cont_one = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones((1, 1)), np.ones(1), "spherical" + ) + cont_two = GeneralizedContractionShell( + 2, np.array([2, 3, 4]), np.ones((1, 1)), 2 * np.ones(1), "spherical" + ) Test = disable_abstract( BaseFourIndexSymmetric, dict_overwrite={ @@ -92,7 +100,9 @@ def test_construct_array_cartesian(): def test_construct_array_spherical(): """Test BaseFourIndexSymmetric.construct_array_spherical.""" - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) transform = generate_transformation( 1, contractions.angmom_components_cart, contractions.angmom_components_sph, "left" ) @@ -128,8 +138,12 @@ def test_construct_array_spherical(): with pytest.raises(TypeError): test.construct_array_spherical(bad_keyword=3) - cont_one = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') - cont_two = GeneralizedContractionShell(2, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + cont_one = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) + cont_two = GeneralizedContractionShell( + 2, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) transform_one = generate_transformation( 1, cont_one.angmom_components_cart, cont_one.angmom_components_sph, "left" ) @@ -401,7 +415,9 @@ def test_construct_array_spherical(): def test_construct_array_mix(): """Test BaseFourIndex.construct_array_mix.""" - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) Test = disable_abstract( BaseFourIndexSymmetric, @@ -424,8 +440,12 @@ def test_construct_array_mix(): test.construct_array_cartesian(a=3), test.construct_array_mix(["cartesian"], a=3) ) - cont_one = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') - cont_two = GeneralizedContractionShell(2, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + cont_one = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) + cont_two = GeneralizedContractionShell( + 2, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) Test = disable_abstract( BaseFourIndexSymmetric, @@ -567,8 +587,12 @@ def construct_array_cont(self, cont_one, cont_two, cont_three, cont_four): BaseFourIndexSymmetric, dict_overwrite={"construct_array_contraction": construct_array_cont}, ) - cont_one = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') - cont_two = GeneralizedContractionShell(2, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + cont_one = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) + cont_two = GeneralizedContractionShell( + 2, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) # Remove the dependence on norm constants. cont_one.norm_cont = np.ones((1, cont_one.num_cart)) @@ -657,7 +681,9 @@ def construct_array_cont(self, cont_one, cont_two, cont_three, cont_four): def test_construct_array_lincomb(): """Test BaseFourIndexSymmetric.construct_array_lincomb.""" - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) sph_transform = generate_transformation( 1, contractions.angmom_components_cart, contractions.angmom_components_sph, "left" ) @@ -733,8 +759,12 @@ def test_construct_array_lincomb(): ) }, ) - cont_one = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') - cont_two = GeneralizedContractionShell(2, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + cont_one = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) + cont_two = GeneralizedContractionShell( + 2, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) cont_one.norm_cont = np.ones((1, cont_one.num_cart)) cont_two.norm_cont = np.ones((1, cont_two.num_cart)) test = Test([cont_one, cont_two]) @@ -1251,8 +1281,8 @@ def angmom_components_sph(self): """Raise error in case undefined conventions are accessed.""" raise NotImplementedError - contractions = SpecialShell(1, np.array([1, 2, 3]), np.ones((1, 2)), np.ones(1), 'spherical') - Test = disable_abstract( + contractions = SpecialShell(1, np.array([1, 2, 3]), np.ones((1, 2)), np.ones(1), "spherical") + Test = disable_abstract( BaseFourIndexSymmetric, dict_overwrite={ "construct_array_contraction": ( diff --git a/tests/test_base_one.py b/tests/test_base_one.py index fde9ec82..c40af30c 100644 --- a/tests/test_base_one.py +++ b/tests/test_base_one.py @@ -12,7 +12,9 @@ def test_init(): """Test BaseOneIndex.__init__.""" Test = disable_abstract(BaseOneIndex) test = skip_init(Test) - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) Test.__init__(test, [contractions]) assert test._axes_contractions == ((contractions,),) with pytest.raises(TypeError): @@ -22,7 +24,9 @@ def test_init(): def test_contractions(): """Test BaseOneIndex.constractions.""" Test = disable_abstract(BaseOneIndex) - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) test = Test([contractions]) assert test.contractions[0] == contractions @@ -34,14 +38,18 @@ def test_contruct_array_contraction(): BaseOneIndex, dict_overwrite={"construct_array_contraction": BaseOneIndex.construct_array_contraction}, ) - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) with pytest.raises(TypeError): Test([contractions]) def test_contruct_array_cartesian(): """Test BaseOneIndex.construct_array_cartesian.""" - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) contractions.norm_cont = np.ones((1, 5)) Test = disable_abstract( BaseOneIndex, @@ -79,7 +87,9 @@ def test_contruct_array_cartesian(): def test_contruct_array_spherical(): """Test BaseOneIndex.construct_array_spherical.""" - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) transform = generate_transformation( 1, contractions.angmom_components_cart, contractions.angmom_components_sph, "left" ) @@ -109,8 +119,10 @@ def test_contruct_array_spherical(): np.vstack([transform.dot(np.arange(9).reshape(3, 3)) * 2] * 2), ) - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones((1, 2)), np.ones(1), 'spherical') - Test = disable_abstract( + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones((1, 2)), np.ones(1), "spherical" + ) + Test = disable_abstract( BaseOneIndex, dict_overwrite={ "construct_array_contraction": ( @@ -156,7 +168,9 @@ def test_contruct_array_spherical(): def test_contruct_array_mix(): """Test BaseOneIndex.construct_array_mix.""" - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) Test = disable_abstract( BaseOneIndex, @@ -191,8 +205,10 @@ def test_contruct_array_mix(): test.construct_array_cartesian(a=3), test.construct_array_mix(["cartesian"] * 2, a=3) ) - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones((1, 2)), np.ones(1), 'spherical') - Test = disable_abstract( + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones((1, 2)), np.ones(1), "spherical" + ) + Test = disable_abstract( BaseOneIndex, dict_overwrite={ "construct_array_contraction": ( @@ -244,8 +260,8 @@ def angmom_components_sph(self): """Raise error in case undefined conventions are accessed.""" raise NotImplementedError - contractions = SpecialShell(1, np.array([1, 2, 3]), np.ones((1, 2)), np.ones(1), 'spherical') - Test = disable_abstract( + contractions = SpecialShell(1, np.array([1, 2, 3]), np.ones((1, 2)), np.ones(1), "spherical") + Test = disable_abstract( BaseOneIndex, dict_overwrite={ "construct_array_contraction": ( @@ -261,7 +277,9 @@ def angmom_components_sph(self): def test_contruct_array_lincomb(): """Test BaseOneIndex.construct_array_lincomb.""" - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) sph_transform = generate_transformation( 1, contractions.angmom_components_cart, contractions.angmom_components_sph, "left" ) diff --git a/tests/test_base_two_asymm.py b/tests/test_base_two_asymm.py index f2d155ec..d30fb9b5 100644 --- a/tests/test_base_two_asymm.py +++ b/tests/test_base_two_asymm.py @@ -12,7 +12,9 @@ def test_init(): """Test BaseTwoIndexAsymmetric.__init__.""" Test = disable_abstract(BaseTwoIndexAsymmetric) test = skip_init(Test) - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) Test.__init__(test, [contractions], [contractions]) assert test._axes_contractions == ((contractions,), (contractions,)) with pytest.raises(TypeError): @@ -24,17 +26,25 @@ def test_init(): def test_contractions_one(): """Test BaseTwoIndexAsymmetric.constractions_one.""" Test = disable_abstract(BaseTwoIndexAsymmetric) - cont_one = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') - cont_two = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + cont_one = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) + cont_two = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) test = Test([cont_one], [cont_two]) assert test.contractions_one[0] == cont_one def test_contractions_two(): """Test BaseTwoIndexAsymmetric.constractions_two.""" - Test = disable_abstract(BaseTwoIndexAsymmetric) - cont_one = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') - cont_two = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + Test = disable_abstract(BaseTwoIndexAsymmetric) + cont_one = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) + cont_two = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) test = Test([cont_one], [cont_two]) assert test.contractions_two[0] == cont_two @@ -48,15 +58,19 @@ def test_contruct_array_contraction(): "construct_array_contraction": BaseTwoIndexAsymmetric.construct_array_contraction }, ) - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) with pytest.raises(TypeError): Test([contractions]) def test_contruct_array_cartesian(): """Test BaseTwoIndexAsymmetric.construct_array_cartesian.""" - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') - Test = disable_abstract( + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) + Test = disable_abstract( BaseTwoIndexAsymmetric, dict_overwrite={ "construct_array_contraction": lambda self, cont1, cont2, a=2: np.ones((1, 2, 1, 2)) * a @@ -81,8 +95,12 @@ def test_contruct_array_cartesian(): ) }, ) - cont_one = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') - cont_two = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + cont_one = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) + cont_two = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) cont_one.norm_cont = np.ones((1, 2)) cont_two.norm_cont = np.ones((1, 5)) test = Test([cont_one, cont_one], [cont_two]) @@ -106,7 +124,9 @@ def test_contruct_array_cartesian(): def test_contruct_array_spherical(): """Test BaseTwoIndexAsymmetric.construct_array_spherical.""" - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) transform = generate_transformation( 1, contractions.angmom_components_cart, contractions.angmom_components_sph, "left" ) @@ -195,7 +215,9 @@ def test_contruct_array_spherical(): def test_contruct_array_mix(): """Test BaseTwoIndexAsymmetric.construct_array_mix.""" - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) Test = disable_abstract( BaseTwoIndexAsymmetric, @@ -348,8 +370,12 @@ def construct_array_cont(self, cont_one, cont_two): BaseTwoIndexAsymmetric, dict_overwrite={"construct_array_contraction": construct_array_cont}, ) - cont_one = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') - cont_two = GeneralizedContractionShell(2, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + cont_one = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) + cont_two = GeneralizedContractionShell( + 2, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) # Remove the dependence on norm constants. cont_one.norm_cont = np.ones((1, cont_one.num_cart)) @@ -394,7 +420,9 @@ def construct_array_cont(self, cont_one, cont_two): def test_contruct_array_lincomb(): """Test BaseTwoIndexAsymmetric.construct_array_lincomb.""" - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) sph_transform = generate_transformation( 1, contractions.angmom_components_cart, contractions.angmom_components_sph, "left" ) @@ -557,8 +585,8 @@ def angmom_components_sph(self): """Raise error in case undefined conventions are accessed.""" raise NotImplementedError - contractions = SpecialShell(1, np.array([1, 2, 3]), np.ones((1, 2)), np.ones(1), 'spherical') - Test = disable_abstract( + contractions = SpecialShell(1, np.array([1, 2, 3]), np.ones((1, 2)), np.ones(1), "spherical") + Test = disable_abstract( BaseTwoIndexAsymmetric, dict_overwrite={ "construct_array_contraction": ( diff --git a/tests/test_base_two_symm.py b/tests/test_base_two_symm.py index cedeee0c..5fec61f6 100644 --- a/tests/test_base_two_symm.py +++ b/tests/test_base_two_symm.py @@ -13,7 +13,9 @@ def test_init(): """Test BaseTwoIndexSymmetric.__init__.""" Test = disable_abstract(BaseTwoIndexSymmetric) test = skip_init(Test) - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) Test.__init__(test, [contractions]) assert test._axes_contractions[0][0] == contractions with pytest.raises(TypeError): @@ -22,8 +24,8 @@ def test_init(): def test_contractions(): """Test BaseTwoIndexSymmetric.constractions.""" - Test = disable_abstract(BaseTwoIndexSymmetric) - cont = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + Test = disable_abstract(BaseTwoIndexSymmetric) + cont = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical") test = Test([cont]) assert test.contractions[0] == cont @@ -37,7 +39,9 @@ def test_contruct_array_contraction(): "construct_array_contraction": BaseTwoIndexSymmetric.construct_array_contraction }, ) - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) with pytest.raises(TypeError): Test([contractions]) @@ -50,8 +54,10 @@ def test_contruct_array_contraction(): # to the tril blocks because the ordering is different. def test_contruct_array_cartesian(): """Test BaseTwoIndexSymmetric.construct_array_cartesian.""" - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') - Test = disable_abstract( + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) + Test = disable_abstract( BaseTwoIndexSymmetric, dict_overwrite={ "construct_array_contraction": lambda self, cont1, cont2, a=2: np.ones((1, 2, 1, 2)) * a @@ -68,9 +74,13 @@ def test_contruct_array_cartesian(): assert np.allclose(test.construct_array_cartesian(), np.ones((4, 4)) * 2) assert np.allclose(test.construct_array_cartesian(a=3), np.ones((4, 4)) * 3) - cont_one = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') - cont_two = GeneralizedContractionShell(2, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') - Test = disable_abstract( + cont_one = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) + cont_two = GeneralizedContractionShell( + 2, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) + Test = disable_abstract( BaseTwoIndexSymmetric, dict_overwrite={ "construct_array_contraction": lambda self, cont_one, cont_two, a=2: ( @@ -230,7 +240,9 @@ def test_contruct_array_cartesian(): # to the tril blocks because the ordering is different. def test_contruct_array_spherical(): """Test BaseTwoIndexSymmetric.construct_array_spherical.""" - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) transform = generate_transformation( 1, contractions.angmom_components_cart, contractions.angmom_components_sph, "left" ) @@ -257,8 +269,12 @@ def test_contruct_array_spherical(): with pytest.raises(TypeError): test.construct_array_spherical(bad_keyword=3) - cont_one = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') - cont_two = GeneralizedContractionShell(2, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + cont_one = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) + cont_two = GeneralizedContractionShell( + 2, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) transform_one = generate_transformation( 1, cont_one.angmom_components_cart, cont_one.angmom_components_sph, "left" ) @@ -401,7 +417,9 @@ def test_contruct_array_spherical(): def test_contruct_array_mix(): """Test BaseTwoIndex.construct_array_mix.""" - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) Test = disable_abstract( BaseTwoIndexSymmetric, @@ -422,8 +440,12 @@ def test_contruct_array_mix(): test.construct_array_cartesian(a=3), test.construct_array_mix(["cartesian"], a=3) ) - cont_one = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') - cont_two = GeneralizedContractionShell(2, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + cont_one = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) + cont_two = GeneralizedContractionShell( + 2, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) Test = disable_abstract( BaseTwoIndexSymmetric, @@ -490,7 +512,9 @@ def test_contruct_array_mix(): def test_contruct_array_lincomb(): """Test BaseTwoIndexSymmetric.construct_array_lincomb.""" - contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + contractions = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) sph_transform = generate_transformation( 1, contractions.angmom_components_cart, contractions.angmom_components_sph, "left" ) @@ -549,8 +573,12 @@ def test_contruct_array_lincomb(): ) }, ) - cont_one = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') - cont_two = GeneralizedContractionShell(2, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + cont_one = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) + cont_two = GeneralizedContractionShell( + 2, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) cont_one.norm_cont = np.ones((1, cont_one.num_cart)) cont_two.norm_cont = np.ones((1, cont_two.num_cart)) test = Test([cont_one, cont_two]) @@ -734,8 +762,12 @@ def construct_array_cont(self, cont_one, cont_two): BaseTwoIndexSymmetric, dict_overwrite={"construct_array_contraction": construct_array_cont}, ) - cont_one = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') - cont_two = GeneralizedContractionShell(2, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + cont_one = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) + cont_two = GeneralizedContractionShell( + 2, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) # Remove the dependence on norm constants. cont_one.norm_cont = np.ones((1, cont_one.num_cart)) @@ -778,8 +810,12 @@ def construct_array_cont(self, cont_one, cont_two): def test_compare_two_asymm(): """Test BaseTwoIndexSymmetric by comparing it against BaseTwoIndexAsymmetric.""" - cont_one = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') - cont_two = GeneralizedContractionShell(2, np.array([1, 2, 3]), np.ones(1), np.ones(1), 'spherical') + cont_one = GeneralizedContractionShell( + 1, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) + cont_two = GeneralizedContractionShell( + 2, np.array([1, 2, 3]), np.ones(1), np.ones(1), "spherical" + ) sph_orb_transform = np.random.rand(8, 8) cart_orb_transform = np.random.rand(9, 9) @@ -853,8 +889,8 @@ def angmom_components_sph(self): """Raise error in case undefined conventions are accessed.""" raise NotImplementedError - contractions = SpecialShell(1, np.array([1, 2, 3]), np.ones((1, 2)), np.ones(1), 'spherical') - Test = disable_abstract( + contractions = SpecialShell(1, np.array([1, 2, 3]), np.ones((1, 2)), np.ones(1), "spherical") + Test = disable_abstract( BaseTwoIndexSymmetric, dict_overwrite={ "construct_array_contraction": ( diff --git a/tests/test_contractions.py b/tests/test_contractions.py index d08ab7f3..bb57fa89 100644 --- a/tests/test_contractions.py +++ b/tests/test_contractions.py @@ -170,7 +170,7 @@ def tests_init(): np.array([0, 1, 2]), np.array([1, 2, 3, 4], dtype=float), np.array([5, 6, 7, 8], dtype=float), - 'spherical' + "spherical", ) assert test._angmom == 1 assert np.allclose(test._coord, np.array([0, 1, 2])) @@ -227,9 +227,13 @@ def test_angmom_components_sph(): # TODO: add more tests def test_norm_prim_cart(): """Test GeneralizedContractionShell.norm_prim_cart.""" - test = GeneralizedContractionShell(0, np.array([0, 0, 0]), np.array([1.0]), np.array([0.25]), 'spherical') + test = GeneralizedContractionShell( + 0, np.array([0, 0, 0]), np.array([1.0]), np.array([0.25]), "spherical" + ) assert np.isclose(test.norm_prim_cart, 0.2519794355383807303479140) - test = GeneralizedContractionShell(3, np.array([0, 0, 0]), np.array([1.0]), np.array([0.5]), 'spherical') + test = GeneralizedContractionShell( + 3, np.array([0, 0, 0]), np.array([1.0]), np.array([0.5]), "spherical" + ) assert np.isclose(test.norm_prim_cart[7], 0.6920252830162908851679097) @@ -262,14 +266,20 @@ def test_num_seg_cont(): def test_assign_norm_cont(): """Test GeneralizedContractionShell.assign_norm_cont.""" - test = GeneralizedContractionShell(0, np.array([0, 0, 0]), np.array([1.0]), np.array([0.25]), 'spherical') + test = GeneralizedContractionShell( + 0, np.array([0, 0, 0]), np.array([1.0]), np.array([0.25]), "spherical" + ) test.assign_norm_cont() assert np.allclose(test.norm_cont, 1) - test = GeneralizedContractionShell(1, np.array([0, 0, 0]), np.array([1.0]), np.array([0.25]), 'spherical') + test = GeneralizedContractionShell( + 1, np.array([0, 0, 0]), np.array([1.0]), np.array([0.25]), "spherical" + ) test.assign_norm_cont() assert np.allclose(test.norm_cont, 1) - test = GeneralizedContractionShell(2, np.array([0, 0, 0]), np.array([1.0]), np.array([0.25]), 'spherical') + test = GeneralizedContractionShell( + 2, np.array([0, 0, 0]), np.array([1.0]), np.array([0.25]), "spherical" + ) test.assign_norm_cont() assert np.allclose(test.norm_cont, 1) diff --git a/tests/test_density.py b/tests/test_density.py index 69df7426..598f07d4 100644 --- a/tests/test_density.py +++ b/tests/test_density.py @@ -63,7 +63,7 @@ def test_evaluate_density_using_evaluated_orbs(): def test_evaluate_density(): """Test gbasis.evals.density.evaluate_density.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "spherical") transform = np.random.rand(14, 18) density = np.random.rand(14, 14) density += density.T @@ -78,7 +78,7 @@ def test_evaluate_density(): def test_evaluate_deriv_density(): """Test gbasis.evals.density.evaluate_deriv_density.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "spherical") transform = np.random.rand(14, 18) density = np.random.rand(14, 14) density += density.T @@ -222,7 +222,7 @@ def test_evaluate_deriv_density(): def test_evaluate_density_gradient(): """Test gbasis.evals.density.evaluate_density_gradient.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "spherical") transform = np.random.rand(14, 18) density = np.random.rand(14, 14) density += density.T @@ -282,7 +282,7 @@ def test_evaluate_density_horton(): basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) # NOTE: used HORTON's conversion factor for angstroms to bohr points = np.array([[0, 0, 0], [0.8 * 1.0 / 0.5291772083, 0, 0]]) - basis = make_contractions(basis_dict, ["H", "He"], points, 'spherical') + basis = make_contractions(basis_dict, ["H", "He"], points, "spherical") basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in basis] horton_density = np.load(find_datafile("data_horton_hhe_sph_density.npy")) @@ -305,7 +305,7 @@ def test_evaluate_density_gradient_horton(): basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) # NOTE: used HORTON's conversion factor for angstroms to bohr points = np.array([[0, 0, 0], [0.8 * 1.0 / 0.5291772083, 0, 0]]) - basis = make_contractions(basis_dict, ["H", "He"], points, 'spherical') + basis = make_contractions(basis_dict, ["H", "He"], points, "spherical") basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in basis] horton_density_gradient = np.load(find_datafile("data_horton_hhe_sph_density_gradient.npy")) @@ -329,7 +329,7 @@ def test_evaluate_hessian_deriv_horton(): basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) # NOTE: used HORTON's conversion factor for angstroms to bohr points = np.array([[0, 0, 0], [0.8 * 1.0 / 0.5291772083, 0, 0]]) - basis = make_contractions(basis_dict, ["H", "He"], points, 'spherical') + basis = make_contractions(basis_dict, ["H", "He"], points, "spherical") basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in basis] horton_density_hessian = np.zeros((10**3, 3, 3)) @@ -359,7 +359,7 @@ def test_evaluate_laplacian_deriv_horton(): basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) # NOTE: used HORTON's conversion factor for angstroms to bohr points = np.array([[0, 0, 0], [0.8 * 1.0 / 0.5291772083, 0, 0]]) - basis = make_contractions(basis_dict, ["H", "He"], points, 'spherical') + basis = make_contractions(basis_dict, ["H", "He"], points, "spherical") basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in basis] horton_density_laplacian = np.load(find_datafile("data_horton_hhe_sph_density_laplacian.npy")) @@ -383,7 +383,7 @@ def test_evaluate_posdef_kinetic_energy_density(): basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) # NOTE: used HORTON's conversion factor for angstroms to bohr points = np.array([[0, 0, 0], [0.8 * 1.0 / 0.5291772083, 0, 0]]) - basis = make_contractions(basis_dict, ["H", "He"], points, 'spherical') + basis = make_contractions(basis_dict, ["H", "He"], points, "spherical") basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in basis] horton_density_kinetic_density = np.load( @@ -410,7 +410,7 @@ def test_evaluate_general_kinetic_energy_density_horton(): basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) # NOTE: used HORTON's conversion factor for angstroms to bohr points = np.array([[0, 0, 0], [0.8 * 1.0 / 0.5291772083, 0, 0]]) - basis = make_contractions(basis_dict, ["H", "He"], points, 'spherical') + basis = make_contractions(basis_dict, ["H", "He"], points, "spherical") basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in basis] horton_density_kinetic_density = np.load( @@ -433,7 +433,7 @@ def test_evaluate_general_kinetic_energy_density(): """Test density.evaluate_general_kinetic_energy_density.""" basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) points = np.array([[0, 0, 0]]) - basis = make_contractions(basis_dict, ["H"], points, 'spherical') + basis = make_contractions(basis_dict, ["H"], points, "spherical") points = np.random.rand(10, 3) with pytest.raises(TypeError): diff --git a/tests/test_electron_repulsion.py b/tests/test_electron_repulsion.py index 22046245..91a25bed 100644 --- a/tests/test_electron_repulsion.py +++ b/tests/test_electron_repulsion.py @@ -18,13 +18,21 @@ def test_construct_array_contraction(): """Test integrals.electron_repulsion.ElectronRepulsionIntegral.construct_array_contraction.""" coord_one = np.array([0.5, 1, 1.5]) - cont_one = GeneralizedContractionShell(0, coord_one, np.array([1.0]), np.array([0.1]), 'spherical') + cont_one = GeneralizedContractionShell( + 0, coord_one, np.array([1.0]), np.array([0.1]), "spherical" + ) coord_two = np.array([1.5, 2, 3]) - cont_two = GeneralizedContractionShell(0, coord_two, np.array([3.0]), np.array([0.2]), 'spherical') + cont_two = GeneralizedContractionShell( + 0, coord_two, np.array([3.0]), np.array([0.2]), "spherical" + ) coord_three = np.array([2.5, 3, 4]) - cont_three = GeneralizedContractionShell(0, coord_three, np.array([3.0]), np.array([0.2]), 'spherical') + cont_three = GeneralizedContractionShell( + 0, coord_three, np.array([3.0]), np.array([0.2]), "spherical" + ) coord_four = np.array([3.5, 4, 5]) - cont_four = GeneralizedContractionShell(0, coord_four, np.array([3.0]), np.array([0.2]), 'spherical') + cont_four = GeneralizedContractionShell( + 0, coord_four, np.array([3.0]), np.array([0.2]), "spherical" + ) with pytest.raises(TypeError): ElectronRepulsionIntegral.construct_array_contraction(None, cont_two, cont_three, cont_four) @@ -100,13 +108,11 @@ def test_electron_repulsion_cartesian_horton_sto6g_bec(): """ basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) coords = np.array([[0, 0, 0], [1.0, 0, 0]]) - basis = make_contractions(basis_dict, ["Be", "C"], coords, 'cartesian') + basis = make_contractions(basis_dict, ["Be", "C"], coords, "cartesian") basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in basis] horton_elec_repulsion = np.load(find_datafile("data_horton_bec_cart_elec_repulsion.npy")) - assert np.allclose( - horton_elec_repulsion, electron_repulsion_integral(basis) - ) + assert np.allclose(horton_elec_repulsion, electron_repulsion_integral(basis)) def test_electron_repulsion_cartesian_horton_custom_hhe(): @@ -121,8 +127,11 @@ def test_electron_repulsion_cartesian_horton_custom_hhe(): """ basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) coords = np.array([[0, 0, 0], [0.8, 0, 0]]) - basis = make_contractions(basis_dict, ["H", "He"], coords, 'cartesian') - basis = [HortonContractions(i.angmom, i.coord, i.coeffs[:, 0], i.exps, i.coord_type) for i in basis[:8]] + basis = make_contractions(basis_dict, ["H", "He"], coords, "cartesian") + basis = [ + HortonContractions(i.angmom, i.coord, i.coeffs[:, 0], i.exps, i.coord_type) + for i in basis[:8] + ] basis[0] = HortonContractions( basis[0].angmom, basis[0].coord, basis[0].coeffs[3:], basis[0].exps[3:], basis[0].coord_type ) @@ -133,15 +142,13 @@ def test_electron_repulsion_cartesian_horton_custom_hhe(): basis.pop(2) horton_elec_repulsion = np.load(find_datafile("data_horton_hhe_cart_elec_repulsion.npy")) - assert np.allclose( - horton_elec_repulsion, electron_repulsion_integral(basis) - ) + assert np.allclose(horton_elec_repulsion, electron_repulsion_integral(basis)) def test_electron_repulsion_cartesian(): """Test gbasis.integrals.electron_repulsion.electron_repulsion_cartesian.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["C"], np.array([[0, 0, 0]]), 'cartesian') + basis = make_contractions(basis_dict, ["C"], np.array([[0, 0, 0]]), "cartesian") erep_obj = ElectronRepulsionIntegral(basis) assert np.allclose( @@ -159,7 +166,7 @@ def test_electron_repulsion_cartesian(): def test_electron_repulsion_spherical(): """Test gbasis.integrals.electron_repulsion.electron_repulsion_spherical.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["C"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["C"], np.array([[0, 0, 0]]), "spherical") erep_obj = ElectronRepulsionIntegral(basis) assert np.allclose( diff --git a/tests/test_electrostatic_potential.py b/tests/test_electrostatic_potential.py index 16959f27..831a8dbf 100644 --- a/tests/test_electrostatic_potential.py +++ b/tests/test_electrostatic_potential.py @@ -15,12 +15,20 @@ def test_electrostatic_potential(): """ basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) coords = np.array([[0, 0, 0], [0.8 * 1.0 / 0.5291772083, 0, 0]]) - cartesian_basis = make_contractions(basis_dict, ["H", "He"], coords, 'cartesian') - cartesian_basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in cartesian_basis] - spherical_basis = make_contractions(basis_dict, ["H", "He"], coords, 'spherical') - spherical_basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in spherical_basis] - mixed_basis = make_contractions(basis_dict, ["H", "He"], coords, ['spherical'] * 9) - mixed_basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in mixed_basis] + cartesian_basis = make_contractions(basis_dict, ["H", "He"], coords, "cartesian") + cartesian_basis = [ + HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) + for i in cartesian_basis + ] + spherical_basis = make_contractions(basis_dict, ["H", "He"], coords, "spherical") + spherical_basis = [ + HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) + for i in spherical_basis + ] + mixed_basis = make_contractions(basis_dict, ["H", "He"], coords, ["spherical"] * 9) + mixed_basis = [ + HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in mixed_basis + ] # check density_matrix type with pytest.raises(TypeError): @@ -147,7 +155,7 @@ def test_electrostatic_potential_cartesian(): basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) # NOTE: used HORTON's conversion factor for angstroms to bohr coords = np.array([[0, 0, 0], [0.8 * 1.0 / 0.5291772083, 0, 0]]) - basis = make_contractions(basis_dict, ["H", "He"], coords, 'cartesian') + basis = make_contractions(basis_dict, ["H", "He"], coords, "cartesian") basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in basis] grid_1d = np.linspace(-2, 2, num=5) @@ -156,9 +164,7 @@ def test_electrostatic_potential_cartesian(): horton_nucattract = np.load(find_datafile("data_horton_hhe_cart_esp.npy")) assert np.allclose( - electrostatic_potential( - basis, np.identity(103), grid_3d, coords, np.array([1, 2]) - ), + electrostatic_potential(basis, np.identity(103), grid_3d, coords, np.array([1, 2])), horton_nucattract, ) @@ -173,7 +179,7 @@ def test_electrostatic_potential_spherical(): basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) # NOTE: used HORTON's conversion factor for angstroms to bohr coords = np.array([[0, 0, 0], [0.8 * 1.0 / 0.5291772083, 0, 0]]) - basis = make_contractions(basis_dict, ["H", "He"], coords, 'spherical') + basis = make_contractions(basis_dict, ["H", "He"], coords, "spherical") basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in basis] grid_1d = np.linspace(-2, 2, num=5) @@ -182,9 +188,7 @@ def test_electrostatic_potential_spherical(): horton_nucattract = np.load(find_datafile("data_horton_hhe_sph_esp.npy")) assert np.allclose( - electrostatic_potential( - basis, np.identity(88), grid_3d, coords, np.array([1, 2]) - ), + electrostatic_potential(basis, np.identity(88), grid_3d, coords, np.array([1, 2])), horton_nucattract, ) @@ -199,10 +203,16 @@ def test_electrostatic_potential_mix(): basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) # NOTE: used HORTON's conversion factor for angstroms to bohr coords = np.array([[0, 0, 0], [0.8 * 1.0 / 0.5291772083, 0, 0]]) - spherical_basis = make_contractions(basis_dict, ["H", "He"], coords, ['spherical'] * 9) - spherical_basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in spherical_basis] - cartesian_basis = make_contractions(basis_dict, ["H", "He"], coords, ['cartesian'] * 9) - cartesian_basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in cartesian_basis] + spherical_basis = make_contractions(basis_dict, ["H", "He"], coords, ["spherical"] * 9) + spherical_basis = [ + HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) + for i in spherical_basis + ] + cartesian_basis = make_contractions(basis_dict, ["H", "He"], coords, ["cartesian"] * 9) + cartesian_basis = [ + HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) + for i in cartesian_basis + ] grid_1d = np.linspace(-2, 2, num=5) grid_x, grid_y, grid_z = np.meshgrid(grid_1d, grid_1d, grid_1d) diff --git a/tests/test_eval.py b/tests/test_eval.py index f7bff06d..bbc07120 100644 --- a/tests/test_eval.py +++ b/tests/test_eval.py @@ -13,7 +13,7 @@ def test_evaluate_construct_array_contraction(): """Test gbasis.evals.eval.Eval.construct_array_contraction.""" test = GeneralizedContractionShell( - 1, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.01]), 'spherical' + 1, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.01]), "spherical" ) answer = np.array( [ @@ -57,7 +57,7 @@ def test_evaluate_construct_array_contraction(): def test_evaluate_basis_cartesian(): """Test gbasis.evals.eval.evaluate_basis_cartesian.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["H"], np.array([[0, 0, 0]]), 'cartesian') + basis = make_contractions(basis_dict, ["H"], np.array([[0, 0, 0]]), "cartesian") evaluate_obj = Eval(basis) assert np.allclose( evaluate_obj.construct_array_cartesian(points=np.array([[0, 0, 0]])), @@ -70,21 +70,21 @@ def test_evaluate_basis_spherical(): basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) # cartesian and spherical are the same for s orbital - basis = make_contractions(basis_dict, ["H"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["H"], np.array([[0, 0, 0]]), "spherical") evaluate_obj = Eval(basis) assert np.allclose( evaluate_obj.construct_array_cartesian(points=np.array([[0, 0, 0]])), evaluate_basis(basis, np.array([[0, 0, 0]])), ) # p orbitals are zero at center - basis = make_contractions(basis_dict, ["Li"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["Li"], np.array([[0, 0, 0]]), "spherical") evaluate_obj = Eval(basis) assert np.allclose( evaluate_obj.construct_array_cartesian(points=np.array([[0, 0, 0]])), evaluate_basis(basis, np.array([[0, 0, 0]])), ) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "spherical") evaluate_obj = Eval(basis) assert np.allclose( evaluate_obj.construct_array_spherical(points=np.array([[1, 1, 1]])), @@ -98,28 +98,36 @@ def test_evaluate_basis_mix(): # cartesian and spherical are the same for s orbital spherical_basis = make_contractions(basis_dict, ["H"], np.array([[0, 0, 0]]), "spherical") - spherical_basis_list = make_contractions(basis_dict, ["H"], np.array([[0, 0, 0]]), ["spherical"]) + spherical_basis_list = make_contractions( + basis_dict, ["H"], np.array([[0, 0, 0]]), ["spherical"] + ) assert np.allclose( evaluate_basis(spherical_basis, np.array([[0, 0, 0]])), evaluate_basis(spherical_basis_list, np.array([[0, 0, 0]])), ) cartesian_basis = make_contractions(basis_dict, ["H"], np.array([[0, 0, 0]]), "cartesian") - cartesian_basis_list = make_contractions(basis_dict, ["H"], np.array([[0, 0, 0]]), ["cartesian"]) + cartesian_basis_list = make_contractions( + basis_dict, ["H"], np.array([[0, 0, 0]]), ["cartesian"] + ) assert np.allclose( evaluate_basis(cartesian_basis, np.array([[0, 0, 0]])), evaluate_basis(cartesian_basis_list, np.array([[0, 0, 0]])), ) spherical_basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "spherical") - spherical_basis_list = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), ["spherical"] * 8) + spherical_basis_list = make_contractions( + basis_dict, ["Kr"], np.array([[0, 0, 0]]), ["spherical"] * 8 + ) assert np.allclose( evaluate_basis(spherical_basis, np.array([[1, 1, 1]])), evaluate_basis(spherical_basis_list, np.array([[1, 1, 1]])), ) cartesian_basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "cartesian") - cartesian_basis_list = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), ["cartesian"] * 8) + cartesian_basis_list = make_contractions( + basis_dict, ["Kr"], np.array([[0, 0, 0]]), ["cartesian"] * 8 + ) assert np.allclose( evaluate_basis(cartesian_basis, np.array([[1, 1, 1]])), evaluate_basis(cartesian_basis_list, np.array([[1, 1, 1]])), @@ -129,11 +137,13 @@ def test_evaluate_basis_mix(): def test_evaluate_basis_lincomb(): """Test gbasis.evals.eval.evaluate_basis_lincomb.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "spherical") evaluate_obj = Eval(basis) transform = np.random.rand(14, 18) assert np.allclose( - evaluate_obj.construct_array_lincomb(transform, ["spherical"], points=np.array([[1, 1, 1]])), + evaluate_obj.construct_array_lincomb( + transform, ["spherical"], points=np.array([[1, 1, 1]]) + ), evaluate_basis(basis, np.array([[1, 1, 1]]), transform=transform), ) @@ -142,9 +152,13 @@ def test_evaluate_basis_horton(): """Test gbasis.evals.eval.evaluate_basis against horton results.""" basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) points = np.array([[0, 0, 0], [0.8, 0, 0]]) - basis = make_contractions(basis_dict, ["H", "He"], points, 'spherical') - cartesian_basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, 'cartesian') for i in basis] - spherical_basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, 'spherical') for i in basis] + basis = make_contractions(basis_dict, ["H", "He"], points, "spherical") + cartesian_basis = [ + HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, "cartesian") for i in basis + ] + spherical_basis = [ + HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, "spherical") for i in basis + ] horton_eval_cart = np.load(find_datafile("data_horton_hhe_cart_eval.npy")) horton_eval_sph = np.load(find_datafile("data_horton_hhe_sph_eval.npy")) diff --git a/tests/test_eval_deriv.py b/tests/test_eval_deriv.py index b01a793b..f5701b60 100644 --- a/tests/test_eval_deriv.py +++ b/tests/test_eval_deriv.py @@ -17,7 +17,7 @@ def test_evaluate_deriv_construct_array_contraction(): points = np.array([[2, 3, 4]]) orders = np.array([0, 0, 0]) contractions = GeneralizedContractionShell( - 1, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.01]), 'spherical' + 1, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.01]), "spherical" ) with pytest.raises(TypeError): EvalDeriv.construct_array_contraction( @@ -54,7 +54,7 @@ def test_evaluate_deriv_construct_array_contraction(): orders[k] = 1 test = GeneralizedContractionShell( - 1, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.01]), 'spherical' + 1, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.01]), "spherical" ) answer = np.array( [ @@ -94,7 +94,7 @@ def test_evaluate_deriv_construct_array_contraction(): orders[l] += 1 test = GeneralizedContractionShell( - 1, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.01]), 'spherical' + 1, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.01]), "spherical" ) answer = np.array( [ @@ -138,17 +138,13 @@ def test_evaluate_deriv_basis_cartesian(): evaluate_obj.construct_array_cartesian( points=np.array([[1, 1, 1]]), orders=np.array([0, 0, 0]) ), - evaluate_deriv_basis( - basis, np.array([[1, 1, 1]]), orders=np.array([0, 0, 0]) - ), + evaluate_deriv_basis(basis, np.array([[1, 1, 1]]), orders=np.array([0, 0, 0])), ) assert np.allclose( evaluate_obj.construct_array_cartesian( points=np.array([[1, 1, 1]]), orders=np.array([2, 1, 0]) ), - evaluate_deriv_basis( - basis, np.array([[1, 1, 1]]), orders=np.array([2, 1, 0]) - ), + evaluate_deriv_basis(basis, np.array([[1, 1, 1]]), orders=np.array([2, 1, 0])), ) @@ -161,42 +157,38 @@ def test_evaluate_deriv_basis_spherical(): evaluate_obj.construct_array_spherical( points=np.array([[1, 1, 1]]), orders=np.array([0, 0, 0]) ), - evaluate_deriv_basis( - basis, np.array([[1, 1, 1]]), np.array([0, 0, 0]) - ), + evaluate_deriv_basis(basis, np.array([[1, 1, 1]]), np.array([0, 0, 0])), ) assert np.allclose( evaluate_obj.construct_array_spherical( points=np.array([[1, 1, 1]]), orders=np.array([2, 1, 0]) ), - evaluate_deriv_basis( - basis, np.array([[1, 1, 1]]), np.array([2, 1, 0]) - ), + evaluate_deriv_basis(basis, np.array([[1, 1, 1]]), np.array([2, 1, 0])), ) def test_evaluate_deriv_basis_mix(): """Test gbasis.evals.eval.evaluate_deriv_basis_mix.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - cartesian_basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), ["cartesian"] * 8) - spherical_basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), ["spherical"] * 8) + cartesian_basis = make_contractions( + basis_dict, ["Kr"], np.array([[0, 0, 0]]), ["cartesian"] * 8 + ) + spherical_basis = make_contractions( + basis_dict, ["Kr"], np.array([[0, 0, 0]]), ["spherical"] * 8 + ) evaluate_obj_cartesian = EvalDeriv(cartesian_basis) evaluate_obj_spherical = EvalDeriv(spherical_basis) assert np.allclose( evaluate_obj_cartesian.construct_array_mix( ["cartesian"] * 8, points=np.array([[1, 1, 1]]), orders=np.array([0, 0, 0]) ), - evaluate_deriv_basis( - cartesian_basis, np.array([[1, 1, 1]]), np.array([0, 0, 0]) - ), + evaluate_deriv_basis(cartesian_basis, np.array([[1, 1, 1]]), np.array([0, 0, 0])), ) assert np.allclose( evaluate_obj_spherical.construct_array_mix( ["spherical"] * 8, points=np.array([[1, 1, 1]]), orders=np.array([2, 1, 0]) ), - evaluate_deriv_basis( - spherical_basis, np.array([[1, 1, 1]]), np.array([2, 1, 0]) - ), + evaluate_deriv_basis(spherical_basis, np.array([[1, 1, 1]]), np.array([2, 1, 0])), ) diff --git a/tests/test_kinetic_energy.py b/tests/test_kinetic_energy.py index 8453848b..40e360ef 100644 --- a/tests/test_kinetic_energy.py +++ b/tests/test_kinetic_energy.py @@ -13,10 +13,10 @@ def test_kinetic_energy_construct_array_contraction(): """Test gbasis.integrals.kinetic_energy.KineticEnergyIntegral.construct_array_contraction.""" test_one = GeneralizedContractionShell( - 1, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.01]), 'spherical' + 1, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.01]), "spherical" ) test_two = GeneralizedContractionShell( - 2, np.array([1.5, 2, 3]), np.array([3.0, 4.0]), np.array([0.2, 0.02]), 'spherical' + 2, np.array([1.5, 2, 3]), np.array([3.0, 4.0]), np.array([0.2, 0.02]), "spherical" ) answer = np.array( [ @@ -161,7 +161,7 @@ def test_kinetic_energy_construct_array_contraction(): def test_kinetic_energy_integral_cartesian(): """Test gbasis.integrals.kinetic_energy.kinetic_energy_integral_cartesian.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'cartesian') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "cartesian") kinetic_energy_integral_obj = KineticEnergyIntegral(basis) assert np.allclose( kinetic_energy_integral_obj.construct_array_cartesian(), @@ -173,7 +173,7 @@ def test_kinetic_energy_integral_spherical(): """Test gbasis.integrals.kinetic_energy.kinetic_energy_integral_spherical.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "spherical") kinetic_energy_integral_obj = KineticEnergyIntegral(basis) assert np.allclose( kinetic_energy_integral_obj.construct_array_spherical(), @@ -185,7 +185,7 @@ def test_kinetic_energy_integral_mix(): """Test gbasis.integrals.kinetic_energy.kinetic_energy_integral_mix.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), ['spherical'] * 8) + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), ["spherical"] * 8) kinetic_energy_integral_obj = KineticEnergyIntegral(basis) assert np.allclose( kinetic_energy_integral_obj.construct_array_mix(["spherical"] * 8), @@ -196,7 +196,7 @@ def test_kinetic_energy_integral_mix(): def test_kinetic_energy_integral_lincomb(): """Test gbasis.integrals.kinetic_energy.kinetic_energy_integral_lincomb.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "spherical") kinetic_energy_integral_obj = KineticEnergyIntegral(basis) transform = np.random.rand(14, 18) assert np.allclose( @@ -214,16 +214,17 @@ def test_kinetic_energy_integral_horton_anorcc_hhe(): basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) # NOTE: used HORTON's conversion factor for angstroms to bohr basis = make_contractions( - basis_dict, ["H", "He"], np.array([[0, 0, 0], [0.8 * 1.0 / 0.5291772083, 0, 0]]), 'cartesian' + basis_dict, + ["H", "He"], + np.array([[0, 0, 0], [0.8 * 1.0 / 0.5291772083, 0, 0]]), + "cartesian", ) basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in basis] horton_kinetic_energy_integral = np.load( find_datafile("data_horton_hhe_cart_kinetic_energy_integral.npy") ) - assert np.allclose( - kinetic_energy_integral(basis), horton_kinetic_energy_integral - ) + assert np.allclose(kinetic_energy_integral(basis), horton_kinetic_energy_integral) def test_kinetic_energy_integral_horton_anorcc_bec(): @@ -235,13 +236,14 @@ def test_kinetic_energy_integral_horton_anorcc_bec(): basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) # NOTE: used HORTON's conversion factor for angstroms to bohr basis = make_contractions( - basis_dict, ["Be", "C"], np.array([[0, 0, 0], [1.0 * 1.0 / 0.5291772083, 0, 0]]), 'cartesian' + basis_dict, + ["Be", "C"], + np.array([[0, 0, 0], [1.0 * 1.0 / 0.5291772083, 0, 0]]), + "cartesian", ) basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in basis] horton_kinetic_energy_integral = np.load( find_datafile("data_horton_bec_cart_kinetic_energy_integral.npy") ) - assert np.allclose( - kinetic_energy_integral(basis), horton_kinetic_energy_integral - ) + assert np.allclose(kinetic_energy_integral(basis), horton_kinetic_energy_integral) diff --git a/tests/test_moment.py b/tests/test_moment.py index 01373571..7733d32d 100644 --- a/tests/test_moment.py +++ b/tests/test_moment.py @@ -13,10 +13,10 @@ def test_moment_construct_array_contraction(): """Test gbasis.integrals.moment.Moment.construct_array_contraction.""" test_one = GeneralizedContractionShell( - 1, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.01]), 'spherical' + 1, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.01]), "spherical" ) test_two = GeneralizedContractionShell( - 2, np.array([1.5, 2, 3]), np.array([3.0, 4.0]), np.array([0.2, 0.02]), 'spherical' + 2, np.array([1.5, 2, 3]), np.array([3.0, 4.0]), np.array([0.2, 0.02]), "spherical" ) answer = np.array( [ @@ -135,7 +135,7 @@ def test_moment_construct_array_contraction(): def test_moment_cartesian(): """Test gbasis.integrals.moment.moment_cartesian.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'cartesian') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "cartesian") moment_obj = Moment(basis) assert np.allclose( @@ -181,7 +181,7 @@ def test_moment_spherical(): """Test gbasis.integrals.moment.moment_spherical.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "spherical") moment_obj = Moment(basis) assert np.allclose( moment_obj.construct_array_spherical( @@ -226,7 +226,7 @@ def test_moment_mix(): """Test gbasis.integrals.moment.moment_mix.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), ['spherical'] * 8) + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), ["spherical"] * 8) moment_obj = Moment(basis) assert np.allclose( moment_obj.construct_array_mix( @@ -271,7 +271,7 @@ def test_moment_mix(): def test_moment_spherical_lincomb(): """Test gbasis.integrals.moment.moment_spherical_lincomb.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "spherical") moment_obj = Moment(basis) transform = np.random.rand(14, 18) assert np.allclose( diff --git a/tests/test_momentum.py b/tests/test_momentum.py index fd433764..b9259f5e 100644 --- a/tests/test_momentum.py +++ b/tests/test_momentum.py @@ -13,10 +13,10 @@ def test_momentum_construct_array_contraction(): """Test gbasis.integrals.momentum.MomentumIntegral.construct_array_contraction.""" test_one = GeneralizedContractionShell( - 1, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.01]), 'spherical' + 1, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.01]), "spherical" ) test_two = GeneralizedContractionShell( - 2, np.array([1.5, 2, 3]), np.array([3.0, 4.0]), np.array([0.2, 0.02]), 'spherical' + 2, np.array([1.5, 2, 3]), np.array([3.0, 4.0]), np.array([0.2, 0.02]), "spherical" ) test = MomentumIntegral.construct_array_contraction(test_one, test_two).squeeze() answer = np.array( @@ -163,7 +163,7 @@ def test_momentum_construct_array_contraction(): def test_momentum_integral_cartesian(): """Test gbasis.integrals.momentum.momentum_integral_cartesian.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'cartesian') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "cartesian") momentum_integral_obj = MomentumIntegral(basis) assert np.allclose( momentum_integral_obj.construct_array_cartesian(), @@ -175,7 +175,7 @@ def test_momentum_integral_spherical(): """Test gbasis.integrals.momentum.momentum_integral_spherical.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "spherical") momentum_integral_obj = MomentumIntegral(basis) assert np.allclose( momentum_integral_obj.construct_array_spherical(), @@ -187,7 +187,7 @@ def test_momentum_integral_mix(): """Test gbasis.integrals.momentum.momentum_integral_mix.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), ['spherical'] * 8) + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), ["spherical"] * 8) momentum_integral_obj = MomentumIntegral(basis) assert np.allclose( momentum_integral_obj.construct_array_mix(["spherical"] * 8), @@ -198,7 +198,7 @@ def test_momentum_integral_mix(): def test_momentum_integral_lincomb(): """Test gbasis.integrals.momentum.momentum_integral_lincomb.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "spherical") momentum_integral_obj = MomentumIntegral(basis) transform = np.random.rand(14, 18) assert np.allclose( diff --git a/tests/test_nuclear_electron_attraction.py b/tests/test_nuclear_electron_attraction.py index d7b922f8..d6c68085 100644 --- a/tests/test_nuclear_electron_attraction.py +++ b/tests/test_nuclear_electron_attraction.py @@ -16,14 +16,12 @@ def test_nuclear_electron_attraction_horton_anorcc_hhe(): basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) # NOTE: used HORTON's conversion factor for angstroms to bohr coords = np.array([[0, 0, 0], [0.8 * 1.0 / 0.5291772083, 0, 0]]) - basis = make_contractions(basis_dict, ["H", "He"], coords, 'cartesian') + basis = make_contractions(basis_dict, ["H", "He"], coords, "cartesian") basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in basis] horton_nucattract = np.load(find_datafile("data_horton_hhe_cart_nucattract.npy")) assert np.allclose( - nuclear_electron_attraction_integral( - basis, coords, np.array([1, 2]) - ), + nuclear_electron_attraction_integral(basis, coords, np.array([1, 2])), horton_nucattract, ) @@ -37,14 +35,12 @@ def test_nuclear_electron_attraction_horton_anorcc_bec(): basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) # NOTE: used HORTON's conversion factor for angstroms to bohr coords = np.array([[0, 0, 0], [1.0 * 1.0 / 0.5291772083, 0, 0]]) - basis = make_contractions(basis_dict, ["Be", "C"], coords, 'cartesian') + basis = make_contractions(basis_dict, ["Be", "C"], coords, "cartesian") basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in basis] horton_nucattract = np.load(find_datafile("data_horton_bec_cart_nucattract.npy")) assert np.allclose( - nuclear_electron_attraction_integral( - basis, coords, np.array([4, 6]) - ), + nuclear_electron_attraction_integral(basis, coords, np.array([4, 6])), horton_nucattract, ) @@ -52,57 +48,49 @@ def test_nuclear_electron_attraction_horton_anorcc_bec(): def test_nuclear_electron_attraction_cartesian(): """Test gbasis.integrals.nuclear_electron_attraction.nuclear_electron_attraction_cartesian.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'cartesian') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "cartesian") nuclear_coords = np.random.rand(5, 3) nuclear_charges = np.random.rand(5) ref = point_charge_integral(basis, nuclear_coords, nuclear_charges) assert np.allclose( ref[:, :, 0] + ref[:, :, 1] + ref[:, :, 2] + ref[:, :, 3] + ref[:, :, 4], - nuclear_electron_attraction_integral( - basis, nuclear_coords, nuclear_charges - ), + nuclear_electron_attraction_integral(basis, nuclear_coords, nuclear_charges), ) def test_nuclear_electron_attraction_spherical(): """Test gbasis.integrals.nuclear_electron_attraction.nuclear_electron_attraction_spherical.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "spherical") nuclear_coords = np.random.rand(5, 3) nuclear_charges = np.random.rand(5) ref = point_charge_integral(basis, nuclear_coords, nuclear_charges) assert np.allclose( ref[:, :, 0] + ref[:, :, 1] + ref[:, :, 2] + ref[:, :, 3] + ref[:, :, 4], - nuclear_electron_attraction_integral( - basis, nuclear_coords, nuclear_charges - ), + nuclear_electron_attraction_integral(basis, nuclear_coords, nuclear_charges), ) def test_nuclear_electron_attraction_mix(): """Test gbasis.integrals.nuclear_electron_attraction.nuclear_electron_attraction_mix.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), ['spherical'] * 8) + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), ["spherical"] * 8) nuclear_coords = np.random.rand(5, 3) nuclear_charges = np.random.rand(5) - ref = point_charge_integral( - basis, nuclear_coords, nuclear_charges - ) + ref = point_charge_integral(basis, nuclear_coords, nuclear_charges) assert np.allclose( ref[:, :, 0] + ref[:, :, 1] + ref[:, :, 2] + ref[:, :, 3] + ref[:, :, 4], - nuclear_electron_attraction_integral( - basis, nuclear_coords, nuclear_charges - ), + nuclear_electron_attraction_integral(basis, nuclear_coords, nuclear_charges), ) def test_nuclear_electron_attraction_lincomb(): """Test gbasis.integrals.nuclear_electron_attraction.nuclear_electron_attraction_lincomb.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "spherical") nuclear_coords = np.random.rand(5, 3) nuclear_charges = np.random.rand(5) diff --git a/tests/test_one_elec_int.py b/tests/test_one_elec_int.py index a0aefda4..82a8cf23 100644 --- a/tests/test_one_elec_int.py +++ b/tests/test_one_elec_int.py @@ -47,10 +47,10 @@ def boys_func(order, weighted_dist): def test_compute_one_elec_int_v_recursion(): """Test vertical recursion in _one_elec_int._compute_one_elec_integrals.""" contr_one = GeneralizedContractionShell( - 3, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.25]), 'spherical' + 3, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.25]), "spherical" ) contr_two = GeneralizedContractionShell( - 2, np.array([1.5, 2, 3]), np.array([3.0, 4.0]), np.array([0.02, 0.01]), 'spherical' + 2, np.array([1.5, 2, 3]), np.array([3.0, 4.0]), np.array([0.02, 0.01]), "spherical" ) coord_a = contr_one.coord angmom_a = contr_one.angmom @@ -99,10 +99,10 @@ def test_compute_one_elec_int_s_type(): """Test _one_elec_int._compute_one_electron_integrals for s-type primitives.""" # GeneralizedContractionShell(angmom, coord, charge, coeffs, exps) s_type_one = GeneralizedContractionShell( - 1, np.array([0.5, 1, 1.5]), np.array([1.0]), np.array([0.1]), 'spherical' + 1, np.array([0.5, 1, 1.5]), np.array([1.0]), np.array([0.1]), "spherical" ) s_type_two = GeneralizedContractionShell( - 1, np.array([1.5, 2, 3]), np.array([3.0]), np.array([0.02]), 'spherical' + 1, np.array([1.5, 2, 3]), np.array([3.0]), np.array([0.02]), "spherical" ) coord_a = s_type_one.coord angmom_a = s_type_one.angmom @@ -183,10 +183,10 @@ def test_compute_one_elec_int_multiple_contractions(): """Test _one_elec_int._compute_one_electron_integrals for s-type contractions.""" # GeneralizedContractionShell(angmom, coord, charge, coeffs, exps) contr_one = GeneralizedContractionShell( - 1, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.25]), 'spherical' + 1, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.25]), "spherical" ) contr_two = GeneralizedContractionShell( - 1, np.array([1.5, 2, 3]), np.array([3.0, 4.0]), np.array([0.02, 0.01]), 'spherical' + 1, np.array([1.5, 2, 3]), np.array([3.0, 4.0]), np.array([0.02, 0.01]), "spherical" ) coord_a = contr_one.coord angmom_a = contr_one.angmom @@ -228,10 +228,18 @@ def test_compute_one_elec_int_multiple_contractions(): def test_compute_one_elec_int_generalized_contraction(): """Test _one_elec_int._compute_one_electron_integrals for generalized contractions.""" contr_one = GeneralizedContractionShell( - 3, np.array([0.5, 1, 1.5]), np.array([[1.0, 2.0], [1.5, 2.5]]), np.array([0.1, 0.25]), 'spherical' + 3, + np.array([0.5, 1, 1.5]), + np.array([[1.0, 2.0], [1.5, 2.5]]), + np.array([0.1, 0.25]), + "spherical", ) contr_two = GeneralizedContractionShell( - 2, np.array([1.5, 2, 3]), np.array([[3.0, 4.0], [3.5, 4.5]]), np.array([0.02, 0.01]), 'spherical' + 2, + np.array([1.5, 2, 3]), + np.array([[3.0, 4.0], [3.5, 4.5]]), + np.array([0.02, 0.01]), + "spherical", ) coord_a = contr_one.coord angmom_a = contr_one.angmom diff --git a/tests/test_overlap.py b/tests/test_overlap.py index a885559f..e8969b7c 100644 --- a/tests/test_overlap.py +++ b/tests/test_overlap.py @@ -13,10 +13,10 @@ def test_overlap_construct_array_contraction(): """Test gbasis.integrals.overlap.Overlap.construct_array_contraction.""" test_one = GeneralizedContractionShell( - 1, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.01]), 'spherical' + 1, np.array([0.5, 1, 1.5]), np.array([1.0, 2.0]), np.array([0.1, 0.01]), "spherical" ) test_two = GeneralizedContractionShell( - 2, np.array([1.5, 2, 3]), np.array([3.0, 4.0]), np.array([0.2, 0.02]), 'spherical' + 2, np.array([1.5, 2, 3]), np.array([3.0, 4.0]), np.array([0.2, 0.02]), "spherical" ) answer = np.array( [ @@ -77,9 +77,7 @@ def test_overlap_cartesian(): basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "cartesian") overlap_obj = Overlap(basis) - assert np.allclose( - overlap_obj.construct_array_cartesian(), overlap_integral(basis) - ) + assert np.allclose(overlap_obj.construct_array_cartesian(), overlap_integral(basis)) def test_overlap_spherical(): @@ -88,9 +86,7 @@ def test_overlap_spherical(): basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "spherical") overlap_obj = Overlap(basis) - assert np.allclose( - overlap_obj.construct_array_spherical(), overlap_integral(basis) - ) + assert np.allclose(overlap_obj.construct_array_spherical(), overlap_integral(basis)) def test_overlap_mix(): @@ -125,7 +121,7 @@ def test_overlap_cartesian_norm_anorcc(): """ basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'cartesian') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "cartesian") overlap_obj = Overlap(basis) assert np.allclose(np.diag(overlap_obj.construct_array_cartesian()), 1) @@ -139,7 +135,7 @@ def test_overlap_spherical_norm_sto6g(): """ basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "spherical") overlap_obj = Overlap(basis) assert np.allclose(np.diag(overlap_obj.construct_array_spherical()), 1) @@ -152,11 +148,11 @@ def test_overlap_spherical_norm_anorcc(): """ basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) - basis = make_contractions(basis_dict, ["C"], np.array([[0, 0, 0]]), 'cartesian') + basis = make_contractions(basis_dict, ["C"], np.array([[0, 0, 0]]), "cartesian") overlap_obj = Overlap(basis) assert np.allclose(np.diag(overlap_obj.construct_array_cartesian()), 1) - basis = make_contractions(basis_dict, ["Xe"], np.array([[0, 0, 0]]), 'cartesian') + basis = make_contractions(basis_dict, ["Xe"], np.array([[0, 0, 0]]), "cartesian") overlap_obj = Overlap(basis) assert np.allclose(np.diag(overlap_obj.construct_array_cartesian()), 1) @@ -170,7 +166,7 @@ def test_overlap_cartesian_norm_sto6g(): """ basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'cartesian') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "cartesian") overlap_obj = Overlap(basis) assert np.allclose(np.diag(overlap_obj.construct_array_cartesian()), 1) @@ -184,7 +180,10 @@ def test_overlap_horton_anorcc_hhe(): basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) # NOTE: used HORTON's conversion factor for angstroms to bohr basis = make_contractions( - basis_dict, ["H", "He"], np.array([[0, 0, 0], [0.8 * 1.0 / 0.5291772083, 0, 0]]), "cartesian" + basis_dict, + ["H", "He"], + np.array([[0, 0, 0], [0.8 * 1.0 / 0.5291772083, 0, 0]]), + "cartesian", ) basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in basis] @@ -201,7 +200,10 @@ def test_overlap_horton_anorcc_bec(): basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) # NOTE: used HORTON's conversion factor for angstroms to bohr basis = make_contractions( - basis_dict, ["Be", "C"], np.array([[0, 0, 0], [1.0 * 1.0 / 0.5291772083, 0, 0]]), "cartesian" + basis_dict, + ["Be", "C"], + np.array([[0, 0, 0], [1.0 * 1.0 / 0.5291772083, 0, 0]]), + "cartesian", ) basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in basis] diff --git a/tests/test_overlap_asymm.py b/tests/test_overlap_asymm.py index 21e1a67c..28410609 100644 --- a/tests/test_overlap_asymm.py +++ b/tests/test_overlap_asymm.py @@ -16,15 +16,16 @@ def test_overlap_integral_asymmetric_horton_anorcc_hhe(): basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) # NOTE: used HORTON's conversion factor for angstroms to bohr basis = make_contractions( - basis_dict, ["H", "He"], np.array([[0, 0, 0], [0.8 * 1.0 / 0.5291772083, 0, 0]]), "cartesian" + basis_dict, + ["H", "He"], + np.array([[0, 0, 0], [0.8 * 1.0 / 0.5291772083, 0, 0]]), + "cartesian", ) basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in basis] horton_overlap_integral_asymmetric = np.load(find_datafile("data_horton_hhe_cart_overlap.npy")) assert np.allclose( - overlap_integral_asymmetric( - basis, basis - ), + overlap_integral_asymmetric(basis, basis), horton_overlap_integral_asymmetric, ) @@ -38,15 +39,16 @@ def test_overlap_integral_asymmetric_horton_anorcc_bec(): basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) # NOTE: used HORTON's conversion factor for angstroms to bohr basis = make_contractions( - basis_dict, ["Be", "C"], np.array([[0, 0, 0], [1.0 * 1.0 / 0.5291772083, 0, 0]]), "cartesian" + basis_dict, + ["Be", "C"], + np.array([[0, 0, 0], [1.0 * 1.0 / 0.5291772083, 0, 0]]), + "cartesian", ) basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in basis] horton_overlap_integral_asymmetric = np.load(find_datafile("data_horton_bec_cart_overlap.npy")) assert np.allclose( - overlap_integral_asymmetric( - basis, basis - ), + overlap_integral_asymmetric(basis, basis), horton_overlap_integral_asymmetric, ) @@ -54,24 +56,37 @@ def test_overlap_integral_asymmetric_horton_anorcc_bec(): def test_overlap_integral_asymmetric_compare(): """Test overlap_asymm.overlap_integral_asymmetric against overlap.overlap_integral.""" basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) - cartesian_basis = make_contractions(basis_dict, ["Kr", "Kr"], np.array([[0, 0, 0], [1.0, 0, 0]]), "cartesian") - spherical_basis = make_contractions(basis_dict, ["Kr", "Kr"], np.array([[0, 0, 0], [1.0, 0, 0]]), "spherical") - mixed_basis = make_contractions(basis_dict, ["Kr", "Kr"], np.array([[0, 0, 0], [1.0, 0, 0]]), ['spherical'] * 9 + ['cartesian']) - cartesian_basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in cartesian_basis] - spherical_basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in spherical_basis] - mixed_basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in mixed_basis] + cartesian_basis = make_contractions( + basis_dict, ["Kr", "Kr"], np.array([[0, 0, 0], [1.0, 0, 0]]), "cartesian" + ) + spherical_basis = make_contractions( + basis_dict, ["Kr", "Kr"], np.array([[0, 0, 0], [1.0, 0, 0]]), "spherical" + ) + mixed_basis = make_contractions( + basis_dict, + ["Kr", "Kr"], + np.array([[0, 0, 0], [1.0, 0, 0]]), + ["spherical"] * 9 + ["cartesian"], + ) + cartesian_basis = [ + HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) + for i in cartesian_basis + ] + spherical_basis = [ + HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) + for i in spherical_basis + ] + mixed_basis = [ + HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in mixed_basis + ] assert np.allclose( overlap_integral(cartesian_basis), - overlap_integral_asymmetric( - cartesian_basis, cartesian_basis - ), + overlap_integral_asymmetric(cartesian_basis, cartesian_basis), ) assert np.allclose( overlap_integral(spherical_basis), - overlap_integral_asymmetric( - spherical_basis, spherical_basis - ), + overlap_integral_asymmetric(spherical_basis, spherical_basis), ) assert np.allclose( overlap_integral(spherical_basis, transform=np.identity(218)), diff --git a/tests/test_parsers.py b/tests/test_parsers.py index a9dcac3d..9144cd13 100644 --- a/tests/test_parsers.py +++ b/tests/test_parsers.py @@ -763,24 +763,28 @@ def test_make_contractions(): """Test gbasis.contractions.make_contractions.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) with pytest.raises(TypeError): - make_contractions(basis_dict, {"H", "H"}, np.array([[0, 0, 0], [1, 1, 1]]), 'spherical') + make_contractions(basis_dict, {"H", "H"}, np.array([[0, 0, 0], [1, 1, 1]]), "spherical") with pytest.raises(TypeError): - make_contractions(basis_dict, [0, 0], np.array([[0, 0, 0], [1, 1, 1]]), 'spherical') + make_contractions(basis_dict, [0, 0], np.array([[0, 0, 0], [1, 1, 1]]), "spherical") with pytest.raises(TypeError): - make_contractions(basis_dict, ["H", "H"], [[0, 0, 0], [1, 1, 1]], 'spherical') + make_contractions(basis_dict, ["H", "H"], [[0, 0, 0], [1, 1, 1]], "spherical") with pytest.raises(TypeError): - make_contractions(basis_dict, ["H", "H"], np.array([0, 0, 0, 1, 1, 1]), 'spherical') + make_contractions(basis_dict, ["H", "H"], np.array([0, 0, 0, 1, 1, 1]), "spherical") with pytest.raises(TypeError): - make_contractions(basis_dict, ["H", "H"], np.array([[0, 0, 0, 2], [1, 1, 1, 2]]), 'spherical') + make_contractions( + basis_dict, ["H", "H"], np.array([[0, 0, 0, 2], [1, 1, 1, 2]]), "spherical" + ) with pytest.raises(ValueError): - make_contractions(basis_dict, ["H", "H", "H"], np.array([[0, 0, 0], [1, 1, 1]]), 'spherical') + make_contractions( + basis_dict, ["H", "H", "H"], np.array([[0, 0, 0], [1, 1, 1]]), "spherical" + ) with pytest.raises(TypeError): make_contractions(basis_dict, ["H", "H"], np.array([[0, 0, 0], [1, 1, 1]]), [0, 0]) - test = make_contractions(basis_dict, ["H", "H"], np.array([[0, 0, 0], [1, 1, 1]]), 'spherical') + test = make_contractions(basis_dict, ["H", "H"], np.array([[0, 0, 0], [1, 1, 1]]), "spherical") assert isinstance(test, tuple) assert len(test) == 2 assert test[0].angmom == 0 diff --git a/tests/test_point_charge.py b/tests/test_point_charge.py index f3a7e425..4870bd23 100644 --- a/tests/test_point_charge.py +++ b/tests/test_point_charge.py @@ -34,9 +34,13 @@ def test_boys_func(): def test_construct_array_contraction(): """Test gbasis.integrals.point_charge.PointChargeIntegral.construct_array_contraction.""" coord_one = np.array([0.5, 1, 1.5]) - test_one = GeneralizedContractionShell(0, coord_one, np.array([1.0]), np.array([0.1]), 'spherical') + test_one = GeneralizedContractionShell( + 0, coord_one, np.array([1.0]), np.array([0.1]), "spherical" + ) coord_two = np.array([1.5, 2, 3]) - test_two = GeneralizedContractionShell(0, coord_two, np.array([3.0]), np.array([0.2]), 'spherical') + test_two = GeneralizedContractionShell( + 0, coord_two, np.array([3.0]), np.array([0.2]), "spherical" + ) coord = np.array([[0, 0, 0]]) charge = np.array([1]) coord_wac = (0.1 * coord_one + 0.2 * coord_two) / (0.1 + 0.2) @@ -71,10 +75,10 @@ def test_construct_array_contraction(): ) test_one = GeneralizedContractionShell( - 1, np.array([0.5, 1, 1.5]), np.array([1.0]), np.array([0.1]), 'spherical' + 1, np.array([0.5, 1, 1.5]), np.array([1.0]), np.array([0.1]), "spherical" ) test_two = GeneralizedContractionShell( - 0, np.array([1.5, 2, 3]), np.array([3.0]), np.array([0.2]), 'spherical' + 0, np.array([1.5, 2, 3]), np.array([3.0]), np.array([0.2]), "spherical" ) v_000_000 = [ 2 @@ -98,10 +102,10 @@ def test_construct_array_contraction(): ) test_one = GeneralizedContractionShell( - 0, np.array([0.5, 1, 1.5]), np.array([1.0]), np.array([0.1]), 'spherical' + 0, np.array([0.5, 1, 1.5]), np.array([1.0]), np.array([0.1]), "spherical" ) test_two = GeneralizedContractionShell( - 1, np.array([1.5, 2, 3]), np.array([3.0]), np.array([0.2]), 'spherical' + 1, np.array([1.5, 2, 3]), np.array([3.0]), np.array([0.2]), "spherical" ) assert np.allclose( PointChargeIntegral.construct_array_contraction(test_one, test_two, coord, charge).ravel(), @@ -120,7 +124,7 @@ def test_construct_array_contraction(): def test_point_charge_cartesian(): """Test gbasis.integrals.point_charge.point_charge_cartesian.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'cartesian') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "cartesian") point_charge_obj = PointChargeIntegral(basis) points_coords = np.random.rand(5, 3) @@ -129,16 +133,14 @@ def test_point_charge_cartesian(): point_charge_obj.construct_array_cartesian( points_coords=points_coords, points_charge=points_charge ), - point_charge_integral( - basis, points_coords=points_coords, points_charge=points_charge - ), + point_charge_integral(basis, points_coords=points_coords, points_charge=points_charge), ) def test_point_charge_spherical(): """Test gbasis.integrals.point_charge.point_charge_spherical.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "spherical") point_charge_obj = PointChargeIntegral(basis) points_coords = np.random.rand(5, 3) @@ -147,9 +149,7 @@ def test_point_charge_spherical(): point_charge_obj.construct_array_spherical( points_coords=points_coords, points_charge=points_charge ), - point_charge_integral( - basis, points_coords=points_coords, points_charge=points_charge - ), + point_charge_integral(basis, points_coords=points_coords, points_charge=points_charge), ) @@ -165,14 +165,14 @@ def test_point_charge_mix(): point_charge_obj.construct_array_mix( ["spherical"] * 8, points_coords=points_coords, points_charge=points_charge ), - point_charge_integral(basis, points_coords, points_charge) + point_charge_integral(basis, points_coords, points_charge), ) def test_point_charge_lincomb(): """Test gbasis.integrals.point_charge.point_charge_lincomb.""" basis_dict = parse_nwchem(find_datafile("data_sto6g.nwchem")) - basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), 'spherical') + basis = make_contractions(basis_dict, ["Kr"], np.array([[0, 0, 0]]), "spherical") point_charge_obj = PointChargeIntegral(basis) points_coords = np.random.rand(5, 3) diff --git a/tests/test_stress_tensor.py b/tests/test_stress_tensor.py index 2ec94942..a53eed90 100644 --- a/tests/test_stress_tensor.py +++ b/tests/test_stress_tensor.py @@ -20,7 +20,7 @@ def test_evaluate_stress_tensor(): """Test gbasis.evals.stress_tensor.evaluate_stress_tensor.""" basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) coords = np.array([[0, 0, 0]]) - basis = make_contractions(basis_dict, ["H"], coords, 'spherical') + basis = make_contractions(basis_dict, ["H"], coords, "spherical") points = np.random.rand(10, 3) with pytest.raises(TypeError): @@ -79,7 +79,7 @@ def test_evaluate_ehrenfest_force(): """Test gbasis.evals.stress_tensor.evaluate_ehrenfest_force.""" basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) coords = np.array([[0, 0, 0]]) - basis = make_contractions(basis_dict, ["H"], coords, 'spherical') + basis = make_contractions(basis_dict, ["H"], coords, "spherical") points = np.random.rand(10, 3) with pytest.raises(TypeError): @@ -140,7 +140,7 @@ def test_evaluate_ehrenfest_hessian(): """Test gbasis.evals.stress_tensor.evaluate_ehrenfest_hessian.""" basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem")) coords = np.array([[0, 0, 0]]) - basis = make_contractions(basis_dict, ["H"], coords, 'spherical') + basis = make_contractions(basis_dict, ["H"], coords, "spherical") basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps, i.coord_type) for i in basis] points = np.random.rand(10, 3)