Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 11, 2024
1 parent 1af396b commit 93cf65c
Show file tree
Hide file tree
Showing 27 changed files with 480 additions and 315 deletions.
19 changes: 11 additions & 8 deletions gbasis/contractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
8 changes: 2 additions & 6 deletions gbasis/evals/stress_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions gbasis/integrals/electron_repulsion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions gbasis/integrals/nuclear_electron_attraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
)
4 changes: 1 addition & 3 deletions gbasis/integrals/point_charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions tests/test_angular_momentum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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),
Expand All @@ -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(
Expand Down
20 changes: 15 additions & 5 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down Expand Up @@ -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])

Expand All @@ -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])

Expand All @@ -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])

Expand All @@ -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])
66 changes: 48 additions & 18 deletions tests/test_base_four_symm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand All @@ -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={
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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": (
Expand Down
Loading

0 comments on commit 93cf65c

Please sign in to comment.