From ea6c15a9d3315713b296a4f6933eb985b2aa5c90 Mon Sep 17 00:00:00 2001 From: Ali-Tehrani Date: Wed, 10 Jan 2024 18:14:19 -0500 Subject: [PATCH 01/20] Fix using ruff fixable linters --- gbasis/base_four_symm.py | 3 +- gbasis/base_one.py | 3 +- gbasis/base_two_asymm.py | 3 +- gbasis/base_two_symm.py | 3 +- gbasis/contractions.py | 7 +-- gbasis/evals/density.py | 5 ++- gbasis/evals/electrostatic_potential.py | 3 +- gbasis/evals/eval.py | 3 +- gbasis/evals/eval_deriv.py | 3 +- gbasis/evals/stress_tensor.py | 3 +- gbasis/integrals/_diff_operator_int.py | 3 +- gbasis/integrals/_one_elec_int.py | 1 + gbasis/integrals/_two_elec_int.py | 1 + gbasis/integrals/angular_momentum.py | 3 +- gbasis/integrals/electron_repulsion.py | 3 +- gbasis/integrals/kinetic_energy.py | 3 +- gbasis/integrals/moment.py | 3 +- gbasis/integrals/momentum.py | 3 +- .../integrals/nuclear_electron_attraction.py | 3 +- gbasis/integrals/overlap.py | 3 +- gbasis/integrals/point_charge.py | 5 ++- gbasis/parsers.py | 7 +-- gbasis/spherical.py | 5 ++- gbasis/wrappers.py | 7 +-- tests/test_angular_momentum.py | 9 ++-- tests/test_base.py | 15 ++++--- tests/test_base_four_symm.py | 33 +++++++------- tests/test_base_one.py | 31 ++++++------- tests/test_base_two_asymm.py | 35 ++++++++------- tests/test_base_two_symm.py | 45 ++++++++++--------- tests/test_contractions.py | 3 +- tests/test_density.py | 7 +-- tests/test_deriv.py | 3 +- tests/test_diff_operator_int.py | 3 +- tests/test_electron_repulsion.py | 9 ++-- tests/test_electrostatic_potential.py | 7 +-- tests/test_eval.py | 9 ++-- tests/test_eval_deriv.py | 7 +-- tests/test_kinetic_energy.py | 9 ++-- tests/test_moment.py | 7 +-- tests/test_moment_int.py | 3 +- tests/test_momentum.py | 9 ++-- tests/test_nuclear_electron_attraction.py | 5 ++- tests/test_one_elec_int.py | 5 ++- tests/test_overlap.py | 8 ++-- tests/test_overlap_asymm.py | 5 ++- tests/test_parsers.py | 3 +- tests/test_point_charge.py | 7 +-- tests/test_spherical.py | 5 ++- tests/test_stress_tensor.py | 7 +-- tests/test_two_elec_int.py | 7 +-- tests/test_wrappers.py | 7 +-- tests/utils.py | 11 ++--- 53 files changed, 227 insertions(+), 173 deletions(-) diff --git a/gbasis/base_four_symm.py b/gbasis/base_four_symm.py index ecf01548..b366cb7a 100644 --- a/gbasis/base_four_symm.py +++ b/gbasis/base_four_symm.py @@ -2,9 +2,10 @@ import abc import itertools as it +import numpy as np + from gbasis.base import BaseGaussianRelatedArray from gbasis.spherical import generate_transformation -import numpy as np # pylint: disable=W0235 diff --git a/gbasis/base_one.py b/gbasis/base_one.py index e05d13fe..aaeb1e4b 100644 --- a/gbasis/base_one.py +++ b/gbasis/base_one.py @@ -1,9 +1,10 @@ """Base class for arrays that depend on one contracted Gaussian.""" import abc +import numpy as np + from gbasis.base import BaseGaussianRelatedArray from gbasis.spherical import generate_transformation -import numpy as np # pylint: disable=W0235 diff --git a/gbasis/base_two_asymm.py b/gbasis/base_two_asymm.py index 60c5f546..19df5e12 100644 --- a/gbasis/base_two_asymm.py +++ b/gbasis/base_two_asymm.py @@ -1,9 +1,10 @@ """Base class for arrays that depend on two contracted Gaussians.""" import abc +import numpy as np + from gbasis.base import BaseGaussianRelatedArray from gbasis.spherical import generate_transformation -import numpy as np # pylint: disable=W0235 diff --git a/gbasis/base_two_symm.py b/gbasis/base_two_symm.py index 990316cf..55e4991e 100644 --- a/gbasis/base_two_symm.py +++ b/gbasis/base_two_symm.py @@ -1,9 +1,10 @@ """Base class for arrays that depend on two contracted Gaussians.""" import abc +import numpy as np + from gbasis.base import BaseGaussianRelatedArray from gbasis.spherical import generate_transformation -import numpy as np # pylint: disable=W0235 diff --git a/gbasis/contractions.py b/gbasis/contractions.py index cef5251c..60480bb8 100644 --- a/gbasis/contractions.py +++ b/gbasis/contractions.py @@ -1,7 +1,8 @@ """Data class for contractions of Gaussian-type primitives.""" -from gbasis.utils import factorial2 import numpy as np +from gbasis.utils import factorial2 + class GeneralizedContractionShell: r"""Data class for generalized contractions. @@ -384,8 +385,8 @@ def angmom_components_sph(self): """ return tuple( - ["s{}".format(m) for m in range(self.angmom, 0, -1)] - + ["c{}".format(m) for m in range(self.angmom + 1)] + [f"s{m}" for m in range(self.angmom, 0, -1)] + + [f"c{m}" for m in range(self.angmom + 1)] ) @property diff --git a/gbasis/evals/density.py b/gbasis/evals/density.py index 98d09651..19351c62 100644 --- a/gbasis/evals/density.py +++ b/gbasis/evals/density.py @@ -1,9 +1,10 @@ """Density Evaluation.""" -from gbasis.evals.eval import evaluate_basis -from gbasis.evals.eval_deriv import evaluate_deriv_basis import numpy as np from scipy.special import comb +from gbasis.evals.eval import evaluate_basis +from gbasis.evals.eval_deriv import evaluate_deriv_basis + def evaluate_density_using_evaluated_orbs(one_density_matrix, orb_eval): """Return the evaluation of the density given the evaluated orbitals. diff --git a/gbasis/evals/electrostatic_potential.py b/gbasis/evals/electrostatic_potential.py index dea0f19e..468bd81e 100644 --- a/gbasis/evals/electrostatic_potential.py +++ b/gbasis/evals/electrostatic_potential.py @@ -1,7 +1,8 @@ """Module for computing electrostatic potential integrals.""" -from gbasis.integrals.point_charge import point_charge_integral import numpy as np +from gbasis.integrals.point_charge import point_charge_integral + def electrostatic_potential( basis, diff --git a/gbasis/evals/eval.py b/gbasis/evals/eval.py index 734b0abb..4adec07a 100644 --- a/gbasis/evals/eval.py +++ b/gbasis/evals/eval.py @@ -1,8 +1,9 @@ """Functions for evaluating Gaussian contractions.""" +import numpy as np + from gbasis.base_one import BaseOneIndex from gbasis.contractions import GeneralizedContractionShell from gbasis.evals._deriv import _eval_deriv_contractions -import numpy as np class Eval(BaseOneIndex): diff --git a/gbasis/evals/eval_deriv.py b/gbasis/evals/eval_deriv.py index caac9a4f..36ad8b22 100644 --- a/gbasis/evals/eval_deriv.py +++ b/gbasis/evals/eval_deriv.py @@ -1,8 +1,9 @@ """Functions for evaluating Gaussian primitives.""" +import numpy as np + from gbasis.base_one import BaseOneIndex from gbasis.contractions import GeneralizedContractionShell from gbasis.evals._deriv import _eval_deriv_contractions -import numpy as np class EvalDeriv(BaseOneIndex): diff --git a/gbasis/evals/stress_tensor.py b/gbasis/evals/stress_tensor.py index 3006df34..a3fee0f4 100644 --- a/gbasis/evals/stress_tensor.py +++ b/gbasis/evals/stress_tensor.py @@ -1,10 +1,11 @@ """Module for computing properties related to the stress tensor.""" +import numpy as np + from gbasis.evals.density import ( evaluate_density_laplacian, evaluate_deriv_density, evaluate_deriv_reduced_density_matrix, ) -import numpy as np # TODO: need to be tested against reference diff --git a/gbasis/integrals/_diff_operator_int.py b/gbasis/integrals/_diff_operator_int.py index d590d8bf..a01be2f5 100644 --- a/gbasis/integrals/_diff_operator_int.py +++ b/gbasis/integrals/_diff_operator_int.py @@ -1,9 +1,10 @@ """Integrals over differential operator involving contracted Cartesian Gaussians.""" +import numpy as np + from gbasis.integrals._moment_int import ( _cleanup_intermediate_integrals, _compute_multipole_moment_integrals_intermediate, ) -import numpy as np # FIXME: returns nan when exponent is zero diff --git a/gbasis/integrals/_one_elec_int.py b/gbasis/integrals/_one_elec_int.py index 688d7d9d..a3691be4 100644 --- a/gbasis/integrals/_one_elec_int.py +++ b/gbasis/integrals/_one_elec_int.py @@ -1,5 +1,6 @@ """One-electron integrals involving Contracted Cartesian Gaussians.""" import numpy as np + from gbasis.utils import factorial2 diff --git a/gbasis/integrals/_two_elec_int.py b/gbasis/integrals/_two_elec_int.py index 6ff2a651..526e44d5 100644 --- a/gbasis/integrals/_two_elec_int.py +++ b/gbasis/integrals/_two_elec_int.py @@ -1,5 +1,6 @@ """Two-electron integrals involving Contracted Cartesian Gaussians.""" import numpy as np + from gbasis.utils import factorial2 # pylint: disable=C0103,R0914,R0915 diff --git a/gbasis/integrals/angular_momentum.py b/gbasis/integrals/angular_momentum.py index 5d14ef55..5ce1c255 100644 --- a/gbasis/integrals/angular_momentum.py +++ b/gbasis/integrals/angular_momentum.py @@ -1,11 +1,12 @@ """Module for evaluating the integral over the angular momentum operator.""" +import numpy as np + from gbasis.base_two_symm import BaseTwoIndexSymmetric from gbasis.contractions import GeneralizedContractionShell from gbasis.integrals._diff_operator_int import ( _compute_differential_operator_integrals_intermediate, ) from gbasis.integrals._moment_int import _compute_multipole_moment_integrals_intermediate -import numpy as np # TODO: need to test against reference diff --git a/gbasis/integrals/electron_repulsion.py b/gbasis/integrals/electron_repulsion.py index b7bfad67..45461623 100644 --- a/gbasis/integrals/electron_repulsion.py +++ b/gbasis/integrals/electron_repulsion.py @@ -1,4 +1,6 @@ """Electron-electron repulsion integral.""" +import numpy as np + from gbasis.base_four_symm import BaseFourIndexSymmetric from gbasis.contractions import GeneralizedContractionShell from gbasis.integrals._two_elec_int import ( @@ -6,7 +8,6 @@ _compute_two_elec_integrals_angmom_zero, ) from gbasis.integrals.point_charge import PointChargeIntegral -import numpy as np class ElectronRepulsionIntegral(BaseFourIndexSymmetric): diff --git a/gbasis/integrals/kinetic_energy.py b/gbasis/integrals/kinetic_energy.py index 4b53b159..ecdb96c0 100644 --- a/gbasis/integrals/kinetic_energy.py +++ b/gbasis/integrals/kinetic_energy.py @@ -1,8 +1,9 @@ """Module for evaluating the kinetic energy integral.""" +import numpy as np + from gbasis.base_two_symm import BaseTwoIndexSymmetric from gbasis.contractions import GeneralizedContractionShell from gbasis.integrals._diff_operator_int import _compute_differential_operator_integrals -import numpy as np class KineticEnergyIntegral(BaseTwoIndexSymmetric): diff --git a/gbasis/integrals/moment.py b/gbasis/integrals/moment.py index 9c0a8c19..64b7cb5c 100644 --- a/gbasis/integrals/moment.py +++ b/gbasis/integrals/moment.py @@ -1,8 +1,9 @@ """Module for computing the moments of a basis set.""" +import numpy as np + from gbasis.base_two_symm import BaseTwoIndexSymmetric from gbasis.contractions import GeneralizedContractionShell from gbasis.integrals._moment_int import _compute_multipole_moment_integrals -import numpy as np class Moment(BaseTwoIndexSymmetric): diff --git a/gbasis/integrals/momentum.py b/gbasis/integrals/momentum.py index 3a341774..b3b3a651 100644 --- a/gbasis/integrals/momentum.py +++ b/gbasis/integrals/momentum.py @@ -1,8 +1,9 @@ """Module for evaluating the integral over the momentum operator.""" +import numpy as np + from gbasis.base_two_symm import BaseTwoIndexSymmetric from gbasis.contractions import GeneralizedContractionShell from gbasis.integrals._diff_operator_int import _compute_differential_operator_integrals -import numpy as np # TODO: need to test against reference diff --git a/gbasis/integrals/nuclear_electron_attraction.py b/gbasis/integrals/nuclear_electron_attraction.py index 62ee0b91..ada1c7db 100644 --- a/gbasis/integrals/nuclear_electron_attraction.py +++ b/gbasis/integrals/nuclear_electron_attraction.py @@ -1,7 +1,8 @@ """Module for computing the nuclear electron attraction.""" -from gbasis.integrals.point_charge import point_charge_integral import numpy as np +from gbasis.integrals.point_charge import point_charge_integral + def nuclear_electron_attraction_integral( basis, nuclear_coords, nuclear_charges, transform=None, coord_type="spherical" diff --git a/gbasis/integrals/overlap.py b/gbasis/integrals/overlap.py index 3404fef6..80ac5ad0 100644 --- a/gbasis/integrals/overlap.py +++ b/gbasis/integrals/overlap.py @@ -1,8 +1,9 @@ """Functions for computing overlap of a basis set.""" +import numpy as np + from gbasis.base_two_symm import BaseTwoIndexSymmetric from gbasis.contractions import GeneralizedContractionShell from gbasis.integrals._moment_int import _compute_multipole_moment_integrals -import numpy as np class Overlap(BaseTwoIndexSymmetric): diff --git a/gbasis/integrals/point_charge.py b/gbasis/integrals/point_charge.py index 4ea70955..d06254d6 100644 --- a/gbasis/integrals/point_charge.py +++ b/gbasis/integrals/point_charge.py @@ -1,9 +1,10 @@ """Module for computing point charge integrals.""" +import numpy as np +from scipy.special import hyp1f1 # pylint: disable=E0611 + from gbasis.base_two_symm import BaseTwoIndexSymmetric from gbasis.contractions import GeneralizedContractionShell from gbasis.integrals._one_elec_int import _compute_one_elec_integrals -import numpy as np -from scipy.special import hyp1f1 # pylint: disable=E0611 class PointChargeIntegral(BaseTwoIndexSymmetric): diff --git a/gbasis/parsers.py b/gbasis/parsers.py index 11d0e16f..6c148b5b 100644 --- a/gbasis/parsers.py +++ b/gbasis/parsers.py @@ -1,9 +1,10 @@ """Parsers for reading basis set files.""" import re -from gbasis.contractions import GeneralizedContractionShell import numpy as np +from gbasis.contractions import GeneralizedContractionShell + def parse_nwchem(nwchem_basis_file): """Parse nwchem basis set file. @@ -26,7 +27,7 @@ def parse_nwchem(nwchem_basis_file): """ # pylint: disable=R0914 - with open(nwchem_basis_file, "r") as basis_fh: + with open(nwchem_basis_file) as basis_fh: nwchem_basis = basis_fh.read() data = re.split(r"\n\s*(\w[\w]?)[ ]+(\w+)\s*\n", nwchem_basis) @@ -97,7 +98,7 @@ def parse_gbs(gbs_basis_file): """ # pylint: disable=R0914 - with open(gbs_basis_file, "r") as basis_fh: + with open(gbs_basis_file) as basis_fh: gbs_basis = basis_fh.read() # splits file into 'element', 'basis stuff', 'element',' basis stuff' # e.g., ['H','stuff with exponents & coefficients\n', 'C', 'stuff with etc\n'] diff --git a/gbasis/spherical.py b/gbasis/spherical.py index 610ef38a..9f606ca7 100644 --- a/gbasis/spherical.py +++ b/gbasis/spherical.py @@ -4,6 +4,7 @@ import numpy as np from scipy.special import comb, factorial + from gbasis.utils import factorial2 @@ -301,8 +302,8 @@ def generate_transformation(angmom, cartesian_order, spherical_order, apply_from # Strip out "-" from the ordering to make sure the right components are there and {x.replace("-", "") for x in spherical_order} == set( - ["s{}".format(m) for m in range(angmom, 0, -1)] - + ["c{}".format(m) for m in range(angmom + 1)] + [f"s{m}" for m in range(angmom, 0, -1)] + + [f"c{m}" for m in range(angmom + 1)] ) ): raise ValueError( diff --git a/gbasis/wrappers.py b/gbasis/wrappers.py index da274ad2..be71f324 100644 --- a/gbasis/wrappers.py +++ b/gbasis/wrappers.py @@ -1,7 +1,8 @@ """Module for interfacing to other quantum chemistry packages.""" -from gbasis.contractions import GeneralizedContractionShell import numpy as np +from gbasis.contractions import GeneralizedContractionShell + def from_iodata(mol): """Return basis set stored within the `IOData` instance in `iodata`. @@ -115,7 +116,7 @@ def angmom_components_sph(self): if self.angmom not in sph_conventions: raise ValueError( "Given convention does not support spherical contractions for the angular " - "momentum {0}".format(self.angmom) + f"momentum {self.angmom}" ) return tuple(sph_conventions[self.angmom]) @@ -123,7 +124,7 @@ def angmom_components_sph(self): if molbasis.primitive_normalization != "L2": # pragma: no cover raise ValueError( "Only L2 normalization scheme is supported in `gbasis`. Given `IOData` instance uses " - "primitive normalization scheme, {}".format(molbasis.primitive_normalization) + f"primitive normalization scheme, {molbasis.primitive_normalization}" ) basis = [] diff --git a/tests/test_angular_momentum.py b/tests/test_angular_momentum.py index 1acf5412..99615792 100644 --- a/tests/test_angular_momentum.py +++ b/tests/test_angular_momentum.py @@ -1,14 +1,15 @@ """Test gbasis.integrals.angular_momentum.""" +import numpy as np +import pytest +from utils import find_datafile + from gbasis.contractions import GeneralizedContractionShell from gbasis.integrals._diff_operator_int import ( _compute_differential_operator_integrals_intermediate, ) from gbasis.integrals._moment_int import _compute_multipole_moment_integrals_intermediate -from gbasis.integrals.angular_momentum import angular_momentum_integral, AngularMomentumIntegral +from gbasis.integrals.angular_momentum import AngularMomentumIntegral, angular_momentum_integral from gbasis.parsers import make_contractions, parse_nwchem -import numpy as np -import pytest -from utils import find_datafile def test_angular_momentum_construct_array_contraction(): diff --git a/tests/test_base.py b/tests/test_base.py index cf3c00a6..56a5b5ed 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -1,14 +1,15 @@ """Test gbasis.base.BaseGuassianRelatedArray.""" -from gbasis.base import BaseGaussianRelatedArray -from gbasis.contractions import GeneralizedContractionShell import numpy as np import pytest from utils import disable_abstract, skip_init +from gbasis.base import BaseGaussianRelatedArray +from gbasis.contractions import GeneralizedContractionShell + def test_init(): """Test base.BaseGaussianRelatedArray.""" - Test = disable_abstract(BaseGaussianRelatedArray) # noqa: N806 + Test = disable_abstract(BaseGaussianRelatedArray) test = skip_init(Test) contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) assert not hasattr(test, "_axes_contractions") @@ -32,7 +33,7 @@ def test_init(): def test_contruct_array_contraction(): """Test base.BaseGaussianRelatedArray.construct_array_contraction.""" # enable only the abstract method construct_array_contraction - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseGaussianRelatedArray, dict_overwrite={ "construct_array_contraction": BaseGaussianRelatedArray.construct_array_contraction @@ -46,7 +47,7 @@ def test_contruct_array_contraction(): def test_contruct_array_cartesian(): """Test base.BaseGaussianRelatedArray.construct_array_cartesian.""" # enable only the abstract method construct_array_cartesian - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseGaussianRelatedArray, dict_overwrite={ "construct_array_cartesian": BaseGaussianRelatedArray.construct_array_cartesian @@ -60,7 +61,7 @@ def test_contruct_array_cartesian(): def test_contruct_array_spherical(): """Test base.BaseGaussianRelatedArray.construct_array_spherical.""" # enable only the abstract method construct_array_spherical - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseGaussianRelatedArray, dict_overwrite={ "construct_array_spherical": BaseGaussianRelatedArray.construct_array_spherical @@ -74,7 +75,7 @@ def test_contruct_array_spherical(): def test_contruct_array_lincomb(): """Test base.BaseGaussianRelatedArray.construct_array_lincomb.""" # enable only the abstract method construct_array_lincomb - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseGaussianRelatedArray, dict_overwrite={ "construct_array_lincomb": BaseGaussianRelatedArray.construct_array_lincomb diff --git a/tests/test_base_four_symm.py b/tests/test_base_four_symm.py index 9f49da11..5c8f7ab2 100644 --- a/tests/test_base_four_symm.py +++ b/tests/test_base_four_symm.py @@ -1,15 +1,16 @@ """Test gbasis.base_four_symmetric.""" -from gbasis.base_four_symm import BaseFourIndexSymmetric -from gbasis.contractions import GeneralizedContractionShell -from gbasis.spherical import generate_transformation import numpy as np import pytest from utils import disable_abstract, skip_init +from gbasis.base_four_symm import BaseFourIndexSymmetric +from gbasis.contractions import GeneralizedContractionShell +from gbasis.spherical import generate_transformation + def test_init(): """Test BaseFourIndexSymmetric.__init__.""" - Test = disable_abstract(BaseFourIndexSymmetric) # noqa: N806 + Test = disable_abstract(BaseFourIndexSymmetric) test = skip_init(Test) contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) Test.__init__(test, [contractions]) @@ -20,7 +21,7 @@ def test_init(): def test_contractions(): """Test BaseFourIndexSymmetric.contractions.""" - Test = disable_abstract(BaseFourIndexSymmetric) # noqa: N806 + Test = disable_abstract(BaseFourIndexSymmetric) cont = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) test = Test([cont]) assert test.contractions[0] == cont @@ -29,7 +30,7 @@ def test_contractions(): def test_construct_array_contraction(): """Test BaseFourIndexSymmetric.construct_array_contraction.""" # enable only the abstract method construct_array_contraction - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseFourIndexSymmetric, dict_overwrite={ "construct_array_contraction": BaseFourIndexSymmetric.construct_array_contraction @@ -44,7 +45,7 @@ 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)) cont_two = GeneralizedContractionShell(2, np.array([2, 3, 4]), np.ones((1, 1)), 2 * np.ones(1)) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseFourIndexSymmetric, dict_overwrite={ "construct_array_contraction": lambda self, cont1, cont2, cont3, cont4: np.ones( @@ -101,7 +102,7 @@ def test_construct_array_spherical(): array += np.einsum("ijkl->jikl", array) array += np.einsum("ijkl->ijlk", array) array += np.einsum("ijkl->klij", array) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseFourIndexSymmetric, dict_overwrite={ "construct_array_contraction": ( @@ -136,7 +137,7 @@ def test_construct_array_spherical(): 2, cont_two.angmom_components_cart, cont_two.angmom_components_sph, "left" ) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseFourIndexSymmetric, dict_overwrite={ "construct_array_contraction": lambda self, cont_one, cont_two, cont_three, cont_four: ( @@ -402,7 +403,7 @@ def test_construct_array_mix(): """Test BaseFourIndex.construct_array_mix.""" contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseFourIndexSymmetric, dict_overwrite={ "construct_array_contraction": ( @@ -426,7 +427,7 @@ def test_construct_array_mix(): cont_one = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) cont_two = GeneralizedContractionShell(2, np.array([1, 2, 3]), np.ones(1), np.ones(1)) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseFourIndexSymmetric, dict_overwrite={ "construct_array_contraction": lambda self, cont_one, cont_two, cont_three, cont_four: ( @@ -459,7 +460,7 @@ def test_construct_array_mix(): test.construct_array_cartesian(), test.construct_array_mix(["cartesian"] * 2) ) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseFourIndexSymmetric, dict_overwrite={ "construct_array_contraction": lambda self, cont_one, cont_two, cont_three, cont_four: ( @@ -562,7 +563,7 @@ def construct_array_cont(self, cont_one, cont_two, cont_three, cont_four): ) return output * coeff_dict[identifier] - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseFourIndexSymmetric, dict_overwrite={"construct_array_contraction": construct_array_cont}, ) @@ -662,7 +663,7 @@ def test_construct_array_lincomb(): ) orb_transform = np.random.rand(3, 3) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseFourIndexSymmetric, dict_overwrite={ "construct_array_contraction": ( @@ -709,7 +710,7 @@ def test_construct_array_lincomb(): with pytest.raises(TypeError): test.construct_array_lincomb(orb_transform, "bad", keyword=3) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseFourIndexSymmetric, dict_overwrite={ "construct_array_contraction": lambda self, cont_one, cont_two, cont_three, cont_four: ( @@ -1251,7 +1252,7 @@ def angmom_components_sph(self): raise NotImplementedError contractions = SpecialShell(1, np.array([1, 2, 3]), np.ones((1, 2)), np.ones(1)) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseFourIndexSymmetric, dict_overwrite={ "construct_array_contraction": ( diff --git a/tests/test_base_one.py b/tests/test_base_one.py index 0a644825..c6969cbd 100644 --- a/tests/test_base_one.py +++ b/tests/test_base_one.py @@ -1,15 +1,16 @@ """Test gbasis.base_one.""" -from gbasis.base_one import BaseOneIndex -from gbasis.contractions import GeneralizedContractionShell -from gbasis.spherical import generate_transformation import numpy as np import pytest from utils import disable_abstract, skip_init +from gbasis.base_one import BaseOneIndex +from gbasis.contractions import GeneralizedContractionShell +from gbasis.spherical import generate_transformation + def test_init(): """Test BaseOneIndex.__init__.""" - Test = disable_abstract(BaseOneIndex) # noqa: N806 + Test = disable_abstract(BaseOneIndex) test = skip_init(Test) contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) Test.__init__(test, [contractions]) @@ -20,7 +21,7 @@ def test_init(): def test_contractions(): """Test BaseOneIndex.constractions.""" - Test = disable_abstract(BaseOneIndex) # noqa: N806 + Test = disable_abstract(BaseOneIndex) contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) test = Test([contractions]) assert test.contractions[0] == contractions @@ -29,7 +30,7 @@ def test_contractions(): def test_contruct_array_contraction(): """Test BaseOneIndex.construct_array_contraction.""" # enable only the abstract method construct_array_contraction - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseOneIndex, dict_overwrite={"construct_array_contraction": BaseOneIndex.construct_array_contraction}, ) @@ -42,7 +43,7 @@ def test_contruct_array_cartesian(): """Test BaseOneIndex.construct_array_cartesian.""" contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) contractions.norm_cont = np.ones((1, 5)) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseOneIndex, dict_overwrite={"construct_array_contraction": lambda self, cont, a=2: np.ones((1, 5)) * a}, ) @@ -56,7 +57,7 @@ def test_contruct_array_cartesian(): assert np.allclose(test.construct_array_cartesian(), np.ones(10) * 2) assert np.allclose(test.construct_array_cartesian(a=3), np.ones(10) * 3) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseOneIndex, dict_overwrite={"construct_array_contraction": lambda self, cont, a=2: np.ones((2, 5)) * a}, ) @@ -65,7 +66,7 @@ def test_contruct_array_cartesian(): assert np.allclose(test.construct_array_cartesian(), np.ones(20) * 2) assert np.allclose(test.construct_array_cartesian(a=3), np.ones(20) * 3) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseOneIndex, dict_overwrite={ "construct_array_contraction": lambda self, cont, a=2: np.ones((2, 5, 4)) * a @@ -83,7 +84,7 @@ def test_contruct_array_spherical(): 1, contractions.angmom_components_cart, contractions.angmom_components_sph, "left" ) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseOneIndex, dict_overwrite={ "construct_array_contraction": lambda self, cont, a=2: np.arange( @@ -109,7 +110,7 @@ def test_contruct_array_spherical(): ) contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones((1, 2)), np.ones(1)) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseOneIndex, dict_overwrite={ "construct_array_contraction": ( @@ -157,7 +158,7 @@ def test_contruct_array_mix(): """Test BaseOneIndex.construct_array_mix.""" contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseOneIndex, dict_overwrite={ "construct_array_contraction": lambda self, cont, a=2: np.arange( @@ -191,7 +192,7 @@ def test_contruct_array_mix(): ) contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones((1, 2)), np.ones(1)) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseOneIndex, dict_overwrite={ "construct_array_contraction": ( @@ -244,7 +245,7 @@ def angmom_components_sph(self): raise NotImplementedError contractions = SpecialShell(1, np.array([1, 2, 3]), np.ones((1, 2)), np.ones(1)) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseOneIndex, dict_overwrite={ "construct_array_contraction": ( @@ -266,7 +267,7 @@ def test_contruct_array_lincomb(): ) orb_transform = np.random.rand(3, 3) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseOneIndex, dict_overwrite={ "construct_array_contraction": lambda self, cont, a=2: np.arange( diff --git a/tests/test_base_two_asymm.py b/tests/test_base_two_asymm.py index c9dba68d..cb9c6bd3 100644 --- a/tests/test_base_two_asymm.py +++ b/tests/test_base_two_asymm.py @@ -1,15 +1,16 @@ """Test gbasis.base_two_asymm.""" -from gbasis.base_two_asymm import BaseTwoIndexAsymmetric -from gbasis.contractions import GeneralizedContractionShell -from gbasis.spherical import generate_transformation import numpy as np import pytest from utils import disable_abstract, skip_init +from gbasis.base_two_asymm import BaseTwoIndexAsymmetric +from gbasis.contractions import GeneralizedContractionShell +from gbasis.spherical import generate_transformation + def test_init(): """Test BaseTwoIndexAsymmetric.__init__.""" - Test = disable_abstract(BaseTwoIndexAsymmetric) # noqa: N806 + Test = disable_abstract(BaseTwoIndexAsymmetric) test = skip_init(Test) contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) Test.__init__(test, [contractions], [contractions]) @@ -22,7 +23,7 @@ def test_init(): def test_contractions_one(): """Test BaseTwoIndexAsymmetric.constractions_one.""" - Test = disable_abstract(BaseTwoIndexAsymmetric) # noqa: N806 + Test = disable_abstract(BaseTwoIndexAsymmetric) cont_one = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) cont_two = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) test = Test([cont_one], [cont_two]) @@ -31,7 +32,7 @@ def test_contractions_one(): def test_contractions_two(): """Test BaseTwoIndexAsymmetric.constractions_two.""" - Test = disable_abstract(BaseTwoIndexAsymmetric) # noqa: N806 + Test = disable_abstract(BaseTwoIndexAsymmetric) cont_one = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) cont_two = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) test = Test([cont_one], [cont_two]) @@ -41,7 +42,7 @@ def test_contractions_two(): def test_contruct_array_contraction(): """Test BaseTwoIndexAsymmetric.construct_array_contraction.""" # enable only the abstract method construct_array_contraction - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexAsymmetric, dict_overwrite={ "construct_array_contraction": BaseTwoIndexAsymmetric.construct_array_contraction @@ -55,7 +56,7 @@ def test_contruct_array_contraction(): def test_contruct_array_cartesian(): """Test BaseTwoIndexAsymmetric.construct_array_cartesian.""" contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexAsymmetric, dict_overwrite={ "construct_array_contraction": lambda self, cont1, cont2, a=2: np.ones((1, 2, 1, 2)) * a @@ -72,7 +73,7 @@ def test_contruct_array_cartesian(): assert np.allclose(test.construct_array_cartesian(), np.ones((4, 2)) * 2) assert np.allclose(test.construct_array_cartesian(a=3), np.ones((4, 2)) * 3) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexAsymmetric, dict_overwrite={ "construct_array_contraction": ( @@ -88,7 +89,7 @@ def test_contruct_array_cartesian(): assert np.allclose(test.construct_array_cartesian(), np.ones((4, 5)) * 2) assert np.allclose(test.construct_array_cartesian(a=3), np.ones((4, 5)) * 3) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexAsymmetric, dict_overwrite={ "construct_array_contraction": ( @@ -110,7 +111,7 @@ def test_contruct_array_spherical(): 1, contractions.angmom_components_cart, contractions.angmom_components_sph, "left" ) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexAsymmetric, dict_overwrite={ "construct_array_contraction": ( @@ -140,7 +141,7 @@ def test_contruct_array_spherical(): ) matrix = np.arange(36, dtype=float).reshape(2, 3, 2, 3) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexAsymmetric, dict_overwrite={ "construct_array_contraction": lambda self, cont_one, cont_two, a=2: matrix * a @@ -196,7 +197,7 @@ def test_contruct_array_mix(): """Test BaseTwoIndexAsymmetric.construct_array_mix.""" contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexAsymmetric, dict_overwrite={ "construct_array_contraction": ( @@ -239,7 +240,7 @@ def test_contruct_array_mix(): ) matrix = np.arange(36, dtype=float).reshape(2, 3, 2, 3) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexAsymmetric, dict_overwrite={ "construct_array_contraction": lambda self, cont_one, cont_two, a=2: matrix * a @@ -343,7 +344,7 @@ def construct_array_cont(self, cont_one, cont_two): ) return output - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexAsymmetric, dict_overwrite={"construct_array_contraction": construct_array_cont}, ) @@ -400,7 +401,7 @@ def test_contruct_array_lincomb(): orb_transform_one = np.random.rand(3, 3) orb_transform_two = np.random.rand(3, 3) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexAsymmetric, dict_overwrite={ "construct_array_contraction": ( @@ -557,7 +558,7 @@ def angmom_components_sph(self): raise NotImplementedError contractions = SpecialShell(1, np.array([1, 2, 3]), np.ones((1, 2)), np.ones(1)) - Test = disable_abstract( # noqa: N806 + 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 0aee5381..99885197 100644 --- a/tests/test_base_two_symm.py +++ b/tests/test_base_two_symm.py @@ -1,16 +1,17 @@ """Test gbasis.base_two_symm.""" +import numpy as np +import pytest +from utils import disable_abstract, skip_init + from gbasis.base_two_asymm import BaseTwoIndexAsymmetric from gbasis.base_two_symm import BaseTwoIndexSymmetric from gbasis.contractions import GeneralizedContractionShell from gbasis.spherical import generate_transformation -import numpy as np -import pytest -from utils import disable_abstract, skip_init def test_init(): """Test BaseTwoIndexSymmetric.__init__.""" - Test = disable_abstract(BaseTwoIndexSymmetric) # noqa: N806 + Test = disable_abstract(BaseTwoIndexSymmetric) test = skip_init(Test) contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) Test.__init__(test, [contractions]) @@ -21,7 +22,7 @@ def test_init(): def test_contractions(): """Test BaseTwoIndexSymmetric.constractions.""" - Test = disable_abstract(BaseTwoIndexSymmetric) # noqa: N806 + Test = disable_abstract(BaseTwoIndexSymmetric) cont = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) test = Test([cont]) assert test.contractions[0] == cont @@ -30,7 +31,7 @@ def test_contractions(): def test_contruct_array_contraction(): """Test BaseTwoIndexSymmetric.construct_array_contraction.""" # enable only the abstract method construct_array_contraction - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexSymmetric, dict_overwrite={ "construct_array_contraction": BaseTwoIndexSymmetric.construct_array_contraction @@ -50,7 +51,7 @@ def test_contruct_array_contraction(): def test_contruct_array_cartesian(): """Test BaseTwoIndexSymmetric.construct_array_cartesian.""" contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexSymmetric, dict_overwrite={ "construct_array_contraction": lambda self, cont1, cont2, a=2: np.ones((1, 2, 1, 2)) * a @@ -69,7 +70,7 @@ def test_contruct_array_cartesian(): cont_one = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) cont_two = GeneralizedContractionShell(2, np.array([1, 2, 3]), np.ones(1), np.ones(1)) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexSymmetric, dict_overwrite={ "construct_array_contraction": lambda self, cont_one, cont_two, a=2: ( @@ -102,7 +103,7 @@ def test_contruct_array_cartesian(): ), ) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexSymmetric, dict_overwrite={ "construct_array_contraction": lambda self, cont_one, cont_two, a=2: ( @@ -156,7 +157,7 @@ def test_contruct_array_cartesian(): ), ) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexSymmetric, dict_overwrite={ # NOTE: assume that cont_one and cont_two will always be cont_one and cont_two defined @@ -234,7 +235,7 @@ def test_contruct_array_spherical(): 1, contractions.angmom_components_cart, contractions.angmom_components_sph, "left" ) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexSymmetric, dict_overwrite={ "construct_array_contraction": ( @@ -265,7 +266,7 @@ def test_contruct_array_spherical(): 2, cont_two.angmom_components_cart, cont_two.angmom_components_sph, "left" ) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexSymmetric, dict_overwrite={ "construct_array_contraction": lambda self, cont_one, cont_two, a=2: ( @@ -326,7 +327,7 @@ def test_contruct_array_spherical(): ), ) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexSymmetric, dict_overwrite={ "construct_array_contraction": lambda self, cont_one, cont_two, a=2: ( @@ -402,7 +403,7 @@ def test_contruct_array_mix(): """Test BaseTwoIndex.construct_array_mix.""" contractions = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexSymmetric, dict_overwrite={ "construct_array_contraction": ( @@ -424,7 +425,7 @@ def test_contruct_array_mix(): cont_one = GeneralizedContractionShell(1, np.array([1, 2, 3]), np.ones(1), np.ones(1)) cont_two = GeneralizedContractionShell(2, np.array([1, 2, 3]), np.ones(1), np.ones(1)) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexSymmetric, dict_overwrite={ "construct_array_contraction": lambda self, cont_one, cont_two, a=2: ( @@ -449,7 +450,7 @@ def test_contruct_array_mix(): test.construct_array_cartesian(a=3), test.construct_array_mix(["cartesian"] * 2, a=3) ) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexSymmetric, dict_overwrite={ "construct_array_contraction": lambda self, cont_one, cont_two, a=2: ( @@ -495,7 +496,7 @@ def test_contruct_array_lincomb(): ) orb_transform = np.random.rand(3, 3) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexSymmetric, dict_overwrite={ "construct_array_contraction": ( @@ -537,7 +538,7 @@ def test_contruct_array_lincomb(): with pytest.raises(TypeError): test.construct_array_lincomb(orb_transform, "bad", keyword=3) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexSymmetric, dict_overwrite={ "construct_array_contraction": lambda self, cont_one, cont_two, a=2: ( @@ -729,7 +730,7 @@ def construct_array_cont(self, cont_one, cont_two): ) return output - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexSymmetric, dict_overwrite={"construct_array_contraction": construct_array_cont}, ) @@ -793,11 +794,11 @@ def construct_array_contraction(self, cont_one, cont_two, a=2): ).astype(float) return output * a - TestSymmetric = disable_abstract( # noqa: N806 + TestSymmetric = disable_abstract( BaseTwoIndexSymmetric, dict_overwrite={"construct_array_contraction": construct_array_contraction}, ) - TestAsymmetric = disable_abstract( # noqa: N806 + TestAsymmetric = disable_abstract( BaseTwoIndexAsymmetric, dict_overwrite={"construct_array_contraction": construct_array_contraction}, ) @@ -853,7 +854,7 @@ def angmom_components_sph(self): raise NotImplementedError contractions = SpecialShell(1, np.array([1, 2, 3]), np.ones((1, 2)), np.ones(1)) - Test = disable_abstract( # noqa: N806 + Test = disable_abstract( BaseTwoIndexSymmetric, dict_overwrite={ "construct_array_contraction": ( diff --git a/tests/test_contractions.py b/tests/test_contractions.py index 924e3d57..bae11426 100644 --- a/tests/test_contractions.py +++ b/tests/test_contractions.py @@ -1,9 +1,10 @@ """Test gbasis.contractions.""" -from gbasis.contractions import GeneralizedContractionShell import numpy as np import pytest from utils import skip_init +from gbasis.contractions import GeneralizedContractionShell + def test_coord_setter(): """Test setter for GeneralizedContractionShell.coord.""" diff --git a/tests/test_density.py b/tests/test_density.py index 738cab46..7bf8082c 100644 --- a/tests/test_density.py +++ b/tests/test_density.py @@ -1,4 +1,8 @@ """Test gbasis.evals.density.""" +import numpy as np +import pytest +from utils import HortonContractions, find_datafile + from gbasis.evals.density import ( evaluate_density, evaluate_density_gradient, @@ -12,9 +16,6 @@ from gbasis.evals.eval import evaluate_basis from gbasis.evals.eval_deriv import evaluate_deriv_basis from gbasis.parsers import make_contractions, parse_nwchem -import numpy as np -import pytest -from utils import find_datafile, HortonContractions def test_evaluate_density_using_evaluated_orbs(): diff --git a/tests/test_deriv.py b/tests/test_deriv.py index 0d725fd7..b8fa7547 100644 --- a/tests/test_deriv.py +++ b/tests/test_deriv.py @@ -1,10 +1,11 @@ """Test gbasis.evals._deriv.""" import itertools as it -from gbasis.evals._deriv import _eval_deriv_contractions import numpy as np from utils import partial_deriv_finite_diff +from gbasis.evals._deriv import _eval_deriv_contractions + def evaluate_deriv_prim(coord, orders, center, angmom_comps, alpha): """Return the evaluation of the derivative of a Gaussian primitive. diff --git a/tests/test_diff_operator_int.py b/tests/test_diff_operator_int.py index c5a40c56..b56f87d7 100644 --- a/tests/test_diff_operator_int.py +++ b/tests/test_diff_operator_int.py @@ -1,11 +1,12 @@ """Test gbasis.integrals._diff_operator_int.""" import itertools as it -from gbasis.integrals._diff_operator_int import _compute_differential_operator_integrals import numpy as np from scipy.special import factorial2 from test_moment_int import answer_prim as answer_prim_overlap +from gbasis.integrals._diff_operator_int import _compute_differential_operator_integrals + def answer_prim(coord_type, i, j, k): """Return the answer to the multipole moment integral tests. diff --git a/tests/test_electron_repulsion.py b/tests/test_electron_repulsion.py index 6077b817..7c72fc87 100644 --- a/tests/test_electron_repulsion.py +++ b/tests/test_electron_repulsion.py @@ -1,17 +1,18 @@ """Test gbasis.integrals.electron_repulsion.""" +import numpy as np +import pytest +from utils import HortonContractions, find_datafile + from gbasis.contractions import GeneralizedContractionShell from gbasis.integrals._two_elec_int import ( _compute_two_elec_integrals, _compute_two_elec_integrals_angmom_zero, ) from gbasis.integrals.electron_repulsion import ( - electron_repulsion_integral, ElectronRepulsionIntegral, + electron_repulsion_integral, ) from gbasis.parsers import make_contractions, parse_nwchem -import numpy as np -import pytest -from utils import find_datafile, HortonContractions def test_construct_array_contraction(): diff --git a/tests/test_electrostatic_potential.py b/tests/test_electrostatic_potential.py index a8a17532..d06e0070 100644 --- a/tests/test_electrostatic_potential.py +++ b/tests/test_electrostatic_potential.py @@ -1,9 +1,10 @@ """Tests for gbasis.evals.electrostatic_potential.""" -from gbasis.evals.electrostatic_potential import electrostatic_potential -from gbasis.parsers import make_contractions, parse_nwchem import numpy as np import pytest -from utils import find_datafile, HortonContractions +from utils import HortonContractions, find_datafile + +from gbasis.evals.electrostatic_potential import electrostatic_potential +from gbasis.parsers import make_contractions, parse_nwchem def test_electrostatic_potential(): diff --git a/tests/test_eval.py b/tests/test_eval.py index 638e2ec3..7af03aa7 100644 --- a/tests/test_eval.py +++ b/tests/test_eval.py @@ -1,12 +1,13 @@ """Test gbasis.evals.eval.""" +import numpy as np +import pytest +from utils import HortonContractions, find_datafile + from gbasis.contractions import GeneralizedContractionShell from gbasis.evals._deriv import _eval_deriv_contractions from gbasis.evals.eval import Eval, evaluate_basis from gbasis.parsers import make_contractions, parse_nwchem from gbasis.utils import factorial2 -import numpy as np -import pytest -from utils import find_datafile, HortonContractions def test_evaluate_construct_array_contraction(): @@ -152,6 +153,7 @@ def test_evaluate_basis_pyscf(): pytest.importorskip("pyscf") from pyscf import gto + from gbasis.wrappers import from_pyscf mol = gto.Mole() @@ -218,6 +220,7 @@ def test_evaluate_basis_pyscf_cart_norm(): pytest.importorskip("pyscf") from pyscf import gto + from gbasis.wrappers import from_pyscf mol = gto.Mole() diff --git a/tests/test_eval_deriv.py b/tests/test_eval_deriv.py index e38c7a54..67828d5d 100644 --- a/tests/test_eval_deriv.py +++ b/tests/test_eval_deriv.py @@ -1,14 +1,15 @@ """Test gbasis.evals.evaluate_deriv.""" import itertools as it +import numpy as np +import pytest +from utils import find_datafile + from gbasis.contractions import GeneralizedContractionShell from gbasis.evals._deriv import _eval_deriv_contractions from gbasis.evals.eval_deriv import EvalDeriv, evaluate_deriv_basis from gbasis.parsers import make_contractions, parse_nwchem from gbasis.utils import factorial2 -import numpy as np -import pytest -from utils import find_datafile def test_evaluate_deriv_construct_array_contraction(): diff --git a/tests/test_kinetic_energy.py b/tests/test_kinetic_energy.py index 0abcf005..b0422658 100644 --- a/tests/test_kinetic_energy.py +++ b/tests/test_kinetic_energy.py @@ -1,12 +1,13 @@ """Test gbasis.integrals.kinetic_energy.""" +import numpy as np +import pytest +from utils import HortonContractions, find_datafile + from gbasis.contractions import GeneralizedContractionShell from gbasis.integrals._diff_operator_int import _compute_differential_operator_integrals -from gbasis.integrals.kinetic_energy import kinetic_energy_integral, KineticEnergyIntegral +from gbasis.integrals.kinetic_energy import KineticEnergyIntegral, kinetic_energy_integral from gbasis.parsers import make_contractions, parse_nwchem from gbasis.utils import factorial2 -import numpy as np -import pytest -from utils import find_datafile, HortonContractions def test_kinetic_energy_construct_array_contraction(): diff --git a/tests/test_moment.py b/tests/test_moment.py index d57a1a66..da8a1a87 100644 --- a/tests/test_moment.py +++ b/tests/test_moment.py @@ -1,12 +1,13 @@ """Test gbasis.integrals.moment.""" +import numpy as np +import pytest +from utils import find_datafile + from gbasis.contractions import GeneralizedContractionShell from gbasis.integrals._moment_int import _compute_multipole_moment_integrals from gbasis.integrals.moment import Moment, moment_integral from gbasis.parsers import make_contractions, parse_nwchem from gbasis.utils import factorial2 -import numpy as np -import pytest -from utils import find_datafile def test_moment_construct_array_contraction(): diff --git a/tests/test_moment_int.py b/tests/test_moment_int.py index 13b1348b..eb48eaf9 100644 --- a/tests/test_moment_int.py +++ b/tests/test_moment_int.py @@ -1,9 +1,10 @@ """Test gbasis.integrals._moment_int.""" import itertools as it +import numpy as np + from gbasis.integrals._moment_int import _compute_multipole_moment_integrals from gbasis.utils import factorial2 -import numpy as np def answer_prim(coord_type, i, j, k): diff --git a/tests/test_momentum.py b/tests/test_momentum.py index b87fd3bd..7573b788 100644 --- a/tests/test_momentum.py +++ b/tests/test_momentum.py @@ -1,12 +1,13 @@ """Test gbasis.integrals.momentum.""" +import numpy as np +import pytest +from utils import find_datafile + from gbasis.contractions import GeneralizedContractionShell from gbasis.integrals._diff_operator_int import _compute_differential_operator_integrals -from gbasis.integrals.momentum import momentum_integral, MomentumIntegral +from gbasis.integrals.momentum import MomentumIntegral, momentum_integral from gbasis.parsers import make_contractions, parse_nwchem from gbasis.utils import factorial2 -import numpy as np -import pytest -from utils import find_datafile def test_momentum_construct_array_contraction(): diff --git a/tests/test_nuclear_electron_attraction.py b/tests/test_nuclear_electron_attraction.py index e306bdb0..7a35ef97 100644 --- a/tests/test_nuclear_electron_attraction.py +++ b/tests/test_nuclear_electron_attraction.py @@ -1,9 +1,10 @@ """Test gbasis.integrals.nuclear_electron_attraction.""" +import numpy as np +from utils import HortonContractions, find_datafile + from gbasis.integrals.nuclear_electron_attraction import nuclear_electron_attraction_integral from gbasis.integrals.point_charge import point_charge_integral from gbasis.parsers import make_contractions, parse_nwchem -import numpy as np -from utils import find_datafile, HortonContractions def test_nuclear_electron_attraction_horton_anorcc_hhe(): diff --git a/tests/test_one_elec_int.py b/tests/test_one_elec_int.py index f9a15a05..acedf054 100644 --- a/tests/test_one_elec_int.py +++ b/tests/test_one_elec_int.py @@ -1,10 +1,11 @@ """Test gbasis.integrals._one_elec_int.""" -from gbasis.contractions import GeneralizedContractionShell -from gbasis.integrals._one_elec_int import _compute_one_elec_integrals import numpy as np import pytest from scipy.special import hyp1f1 +from gbasis.contractions import GeneralizedContractionShell +from gbasis.integrals._one_elec_int import _compute_one_elec_integrals + def boys_func(order, weighted_dist): r"""Boys function for evaluating the one-electron Coulomb interaction integral. diff --git a/tests/test_overlap.py b/tests/test_overlap.py index 59ca1346..7e78614d 100644 --- a/tests/test_overlap.py +++ b/tests/test_overlap.py @@ -1,13 +1,13 @@ """Test gbasis.integrals.overlap.""" +import numpy as np +import pytest +from utils import HortonContractions, find_datafile + from gbasis.contractions import GeneralizedContractionShell from gbasis.integrals._moment_int import _compute_multipole_moment_integrals from gbasis.integrals.overlap import Overlap, overlap_integral from gbasis.parsers import make_contractions, parse_nwchem from gbasis.utils import factorial2 -import numpy as np -import pytest - -from utils import find_datafile, HortonContractions def test_overlap_construct_array_contraction(): diff --git a/tests/test_overlap_asymm.py b/tests/test_overlap_asymm.py index d2cd20f5..58ea7322 100644 --- a/tests/test_overlap_asymm.py +++ b/tests/test_overlap_asymm.py @@ -1,9 +1,10 @@ """Test gbasis.integrals.overlap_asymm.""" +import numpy as np +from utils import HortonContractions, find_datafile + from gbasis.integrals.overlap import overlap_integral from gbasis.integrals.overlap_asymm import overlap_integral_asymmetric from gbasis.parsers import make_contractions, parse_nwchem -import numpy as np -from utils import find_datafile, HortonContractions def test_overlap_integral_asymmetric_horton_anorcc_hhe(): diff --git a/tests/test_parsers.py b/tests/test_parsers.py index b2cde802..d5f30f06 100644 --- a/tests/test_parsers.py +++ b/tests/test_parsers.py @@ -1,9 +1,10 @@ """Test gbasis.parsers.""" -from gbasis.parsers import make_contractions, parse_gbs, parse_nwchem import numpy as np import pytest from utils import find_datafile +from gbasis.parsers import make_contractions, parse_gbs, parse_nwchem + def test_parse_nwchem_sto6g(): """Test gbasis.parsers.parse_nwchem for sto6g.""" diff --git a/tests/test_point_charge.py b/tests/test_point_charge.py index be3e6cea..c2236d90 100644 --- a/tests/test_point_charge.py +++ b/tests/test_point_charge.py @@ -1,12 +1,13 @@ """Test gbasis.integrals.point_charge.""" -from gbasis.contractions import GeneralizedContractionShell -from gbasis.integrals.point_charge import point_charge_integral, PointChargeIntegral -from gbasis.parsers import make_contractions, parse_nwchem import numpy as np import pytest from scipy.special import factorial from utils import find_datafile +from gbasis.contractions import GeneralizedContractionShell +from gbasis.integrals.point_charge import PointChargeIntegral, point_charge_integral +from gbasis.parsers import make_contractions, parse_nwchem + def boys_helgaker(n, x): """Return the Boys function as written in Helgaker, eq. 9.8.39. diff --git a/tests/test_spherical.py b/tests/test_spherical.py index d6d23ad4..936611ba 100644 --- a/tests/test_spherical.py +++ b/tests/test_spherical.py @@ -1,6 +1,9 @@ """Test gbasis.spherical.""" import itertools as it +import numpy as np +import pytest + from gbasis.spherical import ( expansion_coeff, generate_transformation, @@ -8,8 +11,6 @@ real_solid_harmonic, shift_factor, ) -import numpy as np -import pytest def test_shift_factor(): diff --git a/tests/test_stress_tensor.py b/tests/test_stress_tensor.py index 9a90ba0b..3ef568b1 100644 --- a/tests/test_stress_tensor.py +++ b/tests/test_stress_tensor.py @@ -1,4 +1,8 @@ """Test gbasis.evals.stress_tensor.""" +import numpy as np +import pytest +from utils import HortonContractions, find_datafile + from gbasis.evals.density import ( evaluate_density_laplacian, evaluate_deriv_density, @@ -10,9 +14,6 @@ evaluate_stress_tensor, ) from gbasis.parsers import make_contractions, parse_nwchem -import numpy as np -import pytest -from utils import find_datafile, HortonContractions def test_evaluate_stress_tensor(): diff --git a/tests/test_two_elec_int.py b/tests/test_two_elec_int.py index 8d98617a..a518c164 100644 --- a/tests/test_two_elec_int.py +++ b/tests/test_two_elec_int.py @@ -1,12 +1,13 @@ """Test gbasis.integrals._two_elec_int.""" +import numpy as np +import pytest +from scipy.special import hyp1f1 # pylint: disable=E0611 + from gbasis.integrals._two_elec_int import ( _compute_two_elec_integrals, _compute_two_elec_integrals_angmom_zero, ) from gbasis.utils import factorial2 -import numpy as np -import pytest -from scipy.special import hyp1f1 # pylint: disable=E0611 def boys_func(order, weighted_dist): diff --git a/tests/test_wrappers.py b/tests/test_wrappers.py index aea06ce1..fbcfe604 100644 --- a/tests/test_wrappers.py +++ b/tests/test_wrappers.py @@ -1,11 +1,12 @@ """Test gbasis.wrapper.""" -from gbasis.contractions import GeneralizedContractionShell -from gbasis.parsers import make_contractions, parse_nwchem -from gbasis.wrappers import from_iodata, from_pyscf import numpy as np import pytest from utils import find_datafile +from gbasis.contractions import GeneralizedContractionShell +from gbasis.parsers import make_contractions, parse_nwchem +from gbasis.wrappers import from_iodata, from_pyscf + def test_from_iodata(): """Test gbasis.wrapper.from_iodata.""" diff --git a/tests/utils.py b/tests/utils.py index 7ae48318..1c104b69 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -2,9 +2,10 @@ import itertools as it import os -from gbasis.contractions import GeneralizedContractionShell import numpy as np +from gbasis.contractions import GeneralizedContractionShell + def skip_init(class_obj): """Return instance of the given class without initialization. @@ -28,7 +29,7 @@ def __init__(self): """Null initialization.""" pass - NoInitClass.__name__ = "NoInit{}".format(class_obj.__name__) + NoInitClass.__name__ = f"NoInit{class_obj.__name__}" NoInitClass.__doc__ = NoInitClass.__doc__.format(class_obj.__name__) return NoInitClass() @@ -62,7 +63,7 @@ def disable_abstract(abclass, dict_overwrite={}): new_dict.update(dict_overwrite) # make subclass of the abstract class with return type( - "{} class with abstract methods disabled".format(abclass.__name__), (abclass,), new_dict + f"{abclass.__name__} class with abstract methods disabled", (abclass,), new_dict ) @@ -189,8 +190,8 @@ def angmom_components_sph(self): """Ordering of the magnetic quantum number for HORTON's convention.""" if self.angmom == 1: return ("c1", "s1", "c0") - cosines = ["c{}".format(m) for m in range(1, self.angmom + 1)] - sines = ["s{}".format(m) for m in range(1, self.angmom + 1)] + cosines = [f"c{m}" for m in range(1, self.angmom + 1)] + sines = [f"s{m}" for m in range(1, self.angmom + 1)] output = ["c0"] + [None for _ in range(2 * self.angmom)] output[1::2] = cosines output[2::2] = sines From c36d26fd27519b7298dc916908b75c585c2e0924 Mon Sep 17 00:00:00 2001 From: Ali-Tehrani Date: Wed, 10 Jan 2024 18:15:23 -0500 Subject: [PATCH 02/20] Ignore rule in ruff --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 20f8aa96..c560a2a3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -76,7 +76,7 @@ line-length = 100 # RUF is Ruff-specific rules select = ["E", "F", "UP", "B", "I", "PGH", "PL", "RUF"] line-length = 100 -ignore = ["PLR2004", "PLR0913", "PLR0912", "PLW2901", "PLR0915", "RUF013"] +ignore = ["PLR2004", "PLR0913", "PLR0912", "PLW2901", "PLR0915", "RUF013", "E741"] extend-exclude = ["doc/*", "doc/*/*"] [tool.pytest.ini_options] From 7b6ae7032d2b5b29d3c4483801cbe5fcdec5969f Mon Sep 17 00:00:00 2001 From: Ali-Tehrani Date: Wed, 10 Jan 2024 18:26:08 -0500 Subject: [PATCH 03/20] Fix remaining ruff errors --- gbasis/evals/stress_tensor.py | 3 ++- gbasis/integrals/point_charge.py | 4 +++- gbasis/spherical.py | 6 ++++-- tests/test_deriv.py | 6 ++++-- tests/test_diff_operator_int.py | 2 +- tests/test_kinetic_energy.py | 4 ++-- tests/test_moment_int.py | 2 +- tests/test_overlap_asymm.py | 2 +- tests/test_parsers.py | 2 +- tests/test_two_elec_int.py | 2 +- tests/test_wrappers.py | 2 +- tests/utils.py | 1 + 12 files changed, 22 insertions(+), 14 deletions(-) diff --git a/gbasis/evals/stress_tensor.py b/gbasis/evals/stress_tensor.py index a3fee0f4..66ef20e4 100644 --- a/gbasis/evals/stress_tensor.py +++ b/gbasis/evals/stress_tensor.py @@ -164,7 +164,8 @@ def evaluate_ehrenfest_force( - (1 - 2\alpha) \sum_i \left. - \frac{\partial^3}{\partial r_i \partial r_j \partial r'_i} \gamma(\mathbf{r}, \mathbf{r}) + \frac{\partial^3}{\partial r_i \partial r_j \partial r'_i} \gamma(\mathbf{r}, + \mathbf{r}) \right|_{\mathbf{r} = \mathbf{r}' = \mathbf{r}_n}\\ &+ \frac{1}{2} \beta \left. diff --git a/gbasis/integrals/point_charge.py b/gbasis/integrals/point_charge.py index d06254d6..43cba7ae 100644 --- a/gbasis/integrals/point_charge.py +++ b/gbasis/integrals/point_charge.py @@ -38,7 +38,9 @@ class PointChargeIntegral(BaseTwoIndexSymmetric): Boys function used to evaluate the one-electron integral. `M` is the number of orders that will be evaluated. `K_a` and `K_b` are the number of primitives on the left and right side, respectively. - construct_array_contraction(self, contractions_one, contractions_two, points_coords, points_charge) + construct_array_contraction(self, contractions_one, contractions_two, points_coords, + **points_charge)** + Return the point charge integrals for the given `GeneralizedContractionShell` instances. `M_1` is the number of segmented contractions with the same exponents (and angular momentum) associated with the first index. diff --git a/gbasis/spherical.py b/gbasis/spherical.py index 9f606ca7..113cfbbc 100644 --- a/gbasis/spherical.py +++ b/gbasis/spherical.py @@ -46,7 +46,8 @@ def expansion_coeff(angmom, mag, i, j, k): C^{angmom,mag,i,j,k} = -1^{i + k - \text{shift_factor}} * (1/4)^i * {angmom \choose i} * {(angmom - i) \choose (|mag| + i)} * {i \choose j} * {|mag| \choose 2 * k}, - where :math:`shift_factor = 0` if :math:`mag >= 0` and :math:`shift_factor = 1/2` if :math:`mag < 0` . + where :math:`shift_factor = 0` if :math:`mag >= 0` and :math:`shift_factor = 1/2` + if :math:`mag < 0`. Parameters ---------- @@ -123,7 +124,8 @@ def harmonic_norm(angmom, mag): Calculate the normalization constant of a real solid harmonic. .. math:: - N^S_{angmom,m} = 1/(2^{|m|} * angmom!) * \sqrt{2 * (angmom + |{m}|)! * (angmom - |{m}|)! / 2^{\delta_0^m}}, + N^S_{angmom,m} = 1/(2^{|m|} * angmom!) * \sqrt{2 * (angmom + |{m}|)! * (angmom - |{m}|)! / + 2^{\delta_0^m}}, where :math: `del{0, m}` is the Kronecker delta of 0 and m. diff --git a/tests/test_deriv.py b/tests/test_deriv.py index b8fa7547..93485d09 100644 --- a/tests/test_deriv.py +++ b/tests/test_deriv.py @@ -119,7 +119,8 @@ def test_evaluate_deriv_prim(): np.array([2, 3, 4]), orders, np.array([0.5, 1, 1.5]), np.array([x, y, z]), 1 ), partial_deriv_finite_diff( - lambda xyz: evaluate_prim(xyz, np.array([0.5, 1, 1.5]), np.array([x, y, z]), 1), + lambda xyz, x=x, y=y, z=z: + evaluate_prim(xyz, np.array([0.5, 1, 1.5]), np.array([x, y, z]), 1), np.array([2, 3, 4]), orders, ), @@ -135,7 +136,8 @@ def test_evaluate_deriv_prim(): np.array([2, 3, 4]), orders, np.array([0.5, 1, 1.5]), np.array([x, y, z]), 1 ), partial_deriv_finite_diff( - lambda xyz: evaluate_prim(xyz, np.array([0.5, 1, 1.5]), np.array([x, y, z]), 1), + lambda xyz, x=x, y=y, z=z: + evaluate_prim(xyz, np.array([0.5, 1, 1.5]), np.array([x, y, z]), 1), np.array([2, 3, 4]), orders, epsilon=1e-5, diff --git a/tests/test_diff_operator_int.py b/tests/test_diff_operator_int.py index b56f87d7..4459605a 100644 --- a/tests/test_diff_operator_int.py +++ b/tests/test_diff_operator_int.py @@ -314,7 +314,7 @@ def test_compute_differential_operator_integrals_multiarray(): for i, order_diff in enumerate(orders_diff): for j, angmom_a in enumerate(angmoms_a): for k, angmom_b in enumerate(angmoms_b): - _compute_differential_operator_integrals( + assert _compute_differential_operator_integrals( np.array([order_diff]), coord_a, np.array([angmom_a]), diff --git a/tests/test_kinetic_energy.py b/tests/test_kinetic_energy.py index b0422658..4fca5413 100644 --- a/tests/test_kinetic_energy.py +++ b/tests/test_kinetic_energy.py @@ -206,7 +206,7 @@ def test_kinetic_energy_integral_lincomb(): def test_kinetic_energy_integral_horton_anorcc_hhe(): - """Test gbasis.integrals.kinetic_energy.kinetic_energy_integral_cartesian against HORTON's results. + """Test gbasis.integrals.kinetic_energy.kinetic_energy_integral_cartesian against HORTON. The test case is diatomic with H and He separated by 0.8 angstroms with basis set ANO-RCC. @@ -227,7 +227,7 @@ def test_kinetic_energy_integral_horton_anorcc_hhe(): def test_kinetic_energy_integral_horton_anorcc_bec(): - """Test gbasis.integrals.kinetic_energy.kinetic_energy_integral_cartesian against HORTON's results. + """Test gbasis.integrals.kinetic_energy.kinetic_energy_integral_cartesian against HORTON. The test case is diatomic with Be and C separated by 1.0 angstroms with basis set ANO-RCC. diff --git a/tests/test_moment_int.py b/tests/test_moment_int.py index eb48eaf9..0b306e91 100644 --- a/tests/test_moment_int.py +++ b/tests/test_moment_int.py @@ -799,7 +799,7 @@ def test_compute_multipole_moment_integrals_multiarray(): for i, order_moment in enumerate(orders_moment): for j, angmom_a in enumerate(angmoms_a): for k, angmom_b in enumerate(angmoms_b): - _compute_multipole_moment_integrals( + assert _compute_multipole_moment_integrals( coord_moment, np.array([order_moment]), coord_a, diff --git a/tests/test_overlap_asymm.py b/tests/test_overlap_asymm.py index 58ea7322..3218b499 100644 --- a/tests/test_overlap_asymm.py +++ b/tests/test_overlap_asymm.py @@ -8,7 +8,7 @@ def test_overlap_integral_asymmetric_horton_anorcc_hhe(): - """Test gbasis.integrals.overlap_asymm.overlap_integral_asymmetric against HORTON's overlap matrix. + """Test gbasis.integrals.overlap_asymm.overlap_integral_asymmetric against HORTON overlap mat. The test case is diatomic with H and He separated by 0.8 angstroms with basis set ANO-RCC. diff --git a/tests/test_parsers.py b/tests/test_parsers.py index d5f30f06..ad942f39 100644 --- a/tests/test_parsers.py +++ b/tests/test_parsers.py @@ -763,7 +763,7 @@ 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]])) + make_contractions(basis_dict, {"H", "C"}, np.array([[0, 0, 0], [1, 1, 1]])) with pytest.raises(TypeError): make_contractions(basis_dict, [0, 0], np.array([[0, 0, 0], [1, 1, 1]])) diff --git a/tests/test_two_elec_int.py b/tests/test_two_elec_int.py index a518c164..b6140431 100644 --- a/tests/test_two_elec_int.py +++ b/tests/test_two_elec_int.py @@ -46,7 +46,7 @@ def boys_func(order, weighted_dist): return hyp1f1(order + 1 / 2, order + 3 / 2, -weighted_dist) / (2 * order + 1) - +# ruff: noqa: PLR0911 def two_int_brute( i_0, i_1, diff --git a/tests/test_wrappers.py b/tests/test_wrappers.py index fbcfe604..c38b9d76 100644 --- a/tests/test_wrappers.py +++ b/tests/test_wrappers.py @@ -105,7 +105,7 @@ def test_from_iodata(): with pytest.raises(ValueError): basis[2].angmom = 10 - basis[2].angmom_components_sph + _ = basis[2].angmom_components_sph with pytest.raises(ValueError): mol.obasis.primitive_normalization = "L1" diff --git a/tests/utils.py b/tests/utils.py index 1c104b69..41a13232 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -34,6 +34,7 @@ def __init__(self): return NoInitClass() +# ruff: noqa: B006 def disable_abstract(abclass, dict_overwrite={}): """Return a class that is a copy of the given abstract class without its abstract methods. From c33c30ccb32f51b2490c1449cfdf96e190feee80 Mon Sep 17 00:00:00 2001 From: Ali-Tehrani Date: Wed, 10 Jan 2024 18:40:14 -0500 Subject: [PATCH 04/20] Update pyproject so that github actions work now - pip install under editable mode didn't work --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index c560a2a3..d2400f11 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,6 +38,10 @@ dependencies = [ ] dynamic = ["version"] +[tool.setuptools.packages.find] +where = ["."] # list of folders that contain the packages (["."] by default) +include = ["gbasis"] # package names should match these glob patterns (["*"] by default) + [project.urls] Documentation = "https://gbasis.qcdevs.org" Issues = "https://github.com/theochem/gbasis/issues" From f3cbed60758cb40a01f8b4f95a944145ba5110b0 Mon Sep 17 00:00:00 2001 From: Ali-Tehrani Date: Wed, 10 Jan 2024 23:13:27 -0500 Subject: [PATCH 05/20] Comment out the test that fails, ref. the issue --- tests/test_diff_operator_int.py | 194 ++++++++++++++++--------------- tests/test_moment_int.py | 200 ++++++++++++++++---------------- 2 files changed, 201 insertions(+), 193 deletions(-) diff --git a/tests/test_diff_operator_int.py b/tests/test_diff_operator_int.py index 4459605a..35e3d224 100644 --- a/tests/test_diff_operator_int.py +++ b/tests/test_diff_operator_int.py @@ -232,98 +232,102 @@ def test_compute_differential_operator_integrals_diff_recursion(): ) -def test_compute_differential_operator_integrals_multiarray(): - """Test _compute_differential_operator_integrals for computing multiple cases simultaneously. - - Note - ---- - The function itself `_compute_differential._operator_integrals` is used to test the use case for - contractions. It assumes that this function behaves correctly for contractions. - - """ - coord_a = np.array([0.2, 0.4, 0.6]) - coord_b = np.array([0.3, 0.5, 0.7]) - angmoms_a = np.array( - [ - [3, 0, 0], - [0, 3, 0], - [0, 0, 3], - [2, 1, 0], - [2, 0, 1], - [1, 2, 0], - [0, 2, 1], - [1, 0, 2], - [0, 1, 2], - ] - ) - angmoms_b = np.array([[2, 0, 0], [0, 2, 0], [0, 0, 2], [1, 1, 0], [1, 0, 1], [0, 1, 1]]) - exps_a = np.array([5.4471780, 0.8245470]) - exps_b = np.array([0.1831920]) - coeffs_a = np.array([[0.1562850], [0.9046910]]) - coeffs_b = np.array([[1.0]]) - orders_diff = np.array( - [ - [3, 0, 0], - [0, 3, 0], - [0, 0, 3], - [2, 1, 0], - [2, 0, 1], - [1, 2, 0], - [0, 2, 1], - [1, 0, 2], - [0, 1, 2], - [2, 0, 0], - [0, 2, 0], - [0, 0, 2], - [1, 1, 0], - [1, 0, 1], - [0, 1, 1], - ] - ) - - norm_a = np.prod( - np.sqrt( - (2 * exps_a[np.newaxis, np.newaxis, :] / np.pi) ** (1 / 2) - * (4 * exps_a[np.newaxis, np.newaxis, :]) ** angmoms_a[:, :, np.newaxis] - / factorial2(2 * angmoms_a[:, :, np.newaxis] - 1) - ), - axis=1, - ) - norm_b = np.prod( - np.sqrt( - (2 * exps_b[np.newaxis, np.newaxis, :] / np.pi) ** (1 / 2) - * (4 * exps_b[np.newaxis, np.newaxis, :]) ** angmoms_b[:, :, np.newaxis] - / factorial2(2 * angmoms_b[:, :, np.newaxis] - 1) - ), - axis=1, - ) - test = _compute_differential_operator_integrals( - orders_diff, - coord_a, - angmoms_a, - exps_a, - coeffs_a, - norm_a, - coord_b, - angmoms_b, - exps_b, - coeffs_b, - norm_b, - ) - assert test.shape == (orders_diff.shape[0], 1, angmoms_a.shape[0], 1, angmoms_b.shape[0]) - for i, order_diff in enumerate(orders_diff): - for j, angmom_a in enumerate(angmoms_a): - for k, angmom_b in enumerate(angmoms_b): - assert _compute_differential_operator_integrals( - np.array([order_diff]), - coord_a, - np.array([angmom_a]), - exps_a, - coeffs_a, - norm_a, - coord_b, - np.array([angmom_b]), - exps_b, - coeffs_b, - norm_b, - ) == test[i, 0, j, 0, k] +# See issue #152: https://github.com/theochem/gbasis/issues/152 +# def test_compute_differential_operator_integrals_multiarray(): +# """Test _compute_differential_operator_integrals for computing multiple cases simultaneously. +# +# Note +# ---- +# The function itself `_compute_differential._operator_integrals` is used to test the use case for +# contractions. It assumes that this function behaves correctly for contractions. +# +# """ +# coord_a = np.array([0.2, 0.4, 0.6]) +# coord_b = np.array([0.3, 0.5, 0.7]) +# angmoms_a = np.array( +# [ +# [3, 0, 0], +# [0, 3, 0], +# [0, 0, 3], +# [2, 1, 0], +# [2, 0, 1], +# [1, 2, 0], +# [0, 2, 1], +# [1, 0, 2], +# [0, 1, 2], +# ] +# ) +# angmoms_b = np.array([[2, 0, 0], [0, 2, 0], [0, 0, 2], [1, 1, 0], [1, 0, 1], [0, 1, 1]]) +# exps_a = np.array([5.4471780, 0.8245470]) +# exps_b = np.array([0.1831920]) +# coeffs_a = np.array([[0.1562850], [0.9046910]]) +# coeffs_b = np.array([[1.0]]) +# orders_diff = np.array( +# [ +# [3, 0, 0], +# [0, 3, 0], +# [0, 0, 3], +# [2, 1, 0], +# [2, 0, 1], +# [1, 2, 0], +# [0, 2, 1], +# [1, 0, 2], +# [0, 1, 2], +# [2, 0, 0], +# [0, 2, 0], +# [0, 0, 2], +# [1, 1, 0], +# [1, 0, 1], +# [0, 1, 1], +# ] +# ) +# +# norm_a = np.prod( +# np.sqrt( +# (2 * exps_a[np.newaxis, np.newaxis, :] / np.pi) ** (1 / 2) +# * (4 * exps_a[np.newaxis, np.newaxis, :]) ** angmoms_a[:, :, np.newaxis] +# / factorial2(2 * angmoms_a[:, :, np.newaxis] - 1) +# ), +# axis=1, +# ) +# norm_b = np.prod( +# np.sqrt( +# (2 * exps_b[np.newaxis, np.newaxis, :] / np.pi) ** (1 / 2) +# * (4 * exps_b[np.newaxis, np.newaxis, :]) ** angmoms_b[:, :, np.newaxis] +# / factorial2(2 * angmoms_b[:, :, np.newaxis] - 1) +# ), +# axis=1, +# ) +# test = _compute_differential_operator_integrals( +# orders_diff, +# coord_a, +# angmoms_a, +# exps_a, +# coeffs_a, +# norm_a, +# coord_b, +# angmoms_b, +# exps_b, +# coeffs_b, +# norm_b, +# ) +# assert test.shape == (orders_diff.shape[0], 1, angmoms_a.shape[0], 1, angmoms_b.shape[0]) +# for i, order_diff in enumerate(orders_diff): +# for j, angmom_a in enumerate(angmoms_a): +# for k, angmom_b in enumerate(angmoms_b): +# assert np.allclose( +# _compute_differential_operator_integrals( +# np.array([order_diff]), +# coord_a, +# np.array([angmom_a]), +# exps_a, +# coeffs_a, +# norm_a, +# coord_b, +# np.array([angmom_b]), +# exps_b, +# coeffs_b, +# norm_b, +# ), +# test[i, 0, j, 0, k] +# ) diff --git a/tests/test_moment_int.py b/tests/test_moment_int.py index 0b306e91..c0cecd13 100644 --- a/tests/test_moment_int.py +++ b/tests/test_moment_int.py @@ -715,104 +715,108 @@ def test_compute_multipole_moment_integrals_contraction(): ) -def test_compute_multipole_moment_integrals_multiarray(): - """Test _compute_multipole_moment_integrals for computing multiple cases simultaneously. - - Note - ---- - The function itself `_compute_multipole_moment_integrals` is used to test the use case for - contractions. It assumes that this function behaves correctly for contractions. - - """ - coord_a = np.array([0.2, 0.4, 0.6]) - coord_b = np.array([0.3, 0.5, 0.7]) - angmoms_a = np.array( - [ - [3, 0, 0], - [0, 3, 0], - [0, 0, 3], - [2, 1, 0], - [2, 0, 1], - [1, 2, 0], - [0, 2, 1], - [1, 0, 2], - [0, 1, 2], - ] - ) - angmoms_b = np.array([[2, 0, 0], [0, 2, 0], [0, 0, 2], [1, 1, 0], [1, 0, 1], [0, 1, 1]]) - exps_a = np.array([5.4471780, 0.8245470]) - exps_b = np.array([0.1831920]) - coeffs_a = np.array([[0.1562850], [0.9046910]]) - coeffs_b = np.array([[1.0]]) - coord_moment = np.array([0.25, 0.45, 0.65]) - orders_moment = np.array( - [ - [3, 0, 0], - [0, 3, 0], - [0, 0, 3], - [2, 1, 0], - [2, 0, 1], - [1, 2, 0], - [0, 2, 1], - [1, 0, 2], - [0, 1, 2], - [2, 0, 0], - [0, 2, 0], - [0, 0, 2], - [1, 1, 0], - [1, 0, 1], - [0, 1, 1], - ] - ) - - norm_a = np.prod( - np.sqrt( - (2 * exps_a[np.newaxis, np.newaxis, :] / np.pi) ** (1 / 2) - * (4 * exps_a[np.newaxis, np.newaxis, :]) ** angmoms_a[:, :, np.newaxis] - / factorial2(2 * angmoms_a[:, :, np.newaxis] - 1) - ), - axis=1, - ) - norm_b = np.prod( - np.sqrt( - (2 * exps_b[np.newaxis, np.newaxis, :] / np.pi) ** (1 / 2) - * (4 * exps_b[np.newaxis, np.newaxis, :]) ** angmoms_b[:, :, np.newaxis] - / factorial2(2 * angmoms_b[:, :, np.newaxis] - 1) - ), - axis=1, - ) - test = _compute_multipole_moment_integrals( - coord_moment, - orders_moment, - coord_a, - angmoms_a, - exps_a, - coeffs_a, - norm_a, - coord_b, - angmoms_b, - exps_b, - coeffs_b, - norm_b, - ) - assert test.shape == (orders_moment.shape[0], 1, angmoms_a.shape[0], 1, angmoms_b.shape[0]) - for i, order_moment in enumerate(orders_moment): - for j, angmom_a in enumerate(angmoms_a): - for k, angmom_b in enumerate(angmoms_b): - assert _compute_multipole_moment_integrals( - coord_moment, - np.array([order_moment]), - coord_a, - np.array([angmom_a]), - exps_a, - coeffs_a, - norm_a, - coord_b, - np.array([angmom_b]), - exps_b, - coeffs_b, - norm_b, - ) == test[i, 0, j, 0, k] +## See issue #152: https://github.com/theochem/gbasis/issues/152 +# def test_compute_multipole_moment_integrals_multiarray(): +# """Test _compute_multipole_moment_integrals for computing multiple cases simultaneously. +# +# Note +# ---- +# The function itself `_compute_multipole_moment_integrals` is used to test the use case for +# contractions. It assumes that this function behaves correctly for contractions. +# +# """ +# coord_a = np.array([0.2, 0.4, 0.6]) +# coord_b = np.array([0.3, 0.5, 0.7]) +# angmoms_a = np.array( +# [ +# [3, 0, 0], +# [0, 3, 0], +# [0, 0, 3], +# [2, 1, 0], +# [2, 0, 1], +# [1, 2, 0], +# [0, 2, 1], +# [1, 0, 2], +# [0, 1, 2], +# ] +# ) +# angmoms_b = np.array([[2, 0, 0], [0, 2, 0], [0, 0, 2], [1, 1, 0], [1, 0, 1], [0, 1, 1]]) +# exps_a = np.array([5.4471780, 0.8245470]) +# exps_b = np.array([0.1831920]) +# coeffs_a = np.array([[0.1562850], [0.9046910]]) +# coeffs_b = np.array([[1.0]]) +# coord_moment = np.array([0.25, 0.45, 0.65]) +# orders_moment = np.array( +# [ +# [3, 0, 0], +# [0, 3, 0], +# [0, 0, 3], +# [2, 1, 0], +# [2, 0, 1], +# [1, 2, 0], +# [0, 2, 1], +# [1, 0, 2], +# [0, 1, 2], +# [2, 0, 0], +# [0, 2, 0], +# [0, 0, 2], +# [1, 1, 0], +# [1, 0, 1], +# [0, 1, 1], +# ] +# ) +# +# norm_a = np.prod( +# np.sqrt( +# (2 * exps_a[np.newaxis, np.newaxis, :] / np.pi) ** (1 / 2) +# * (4 * exps_a[np.newaxis, np.newaxis, :]) ** angmoms_a[:, :, np.newaxis] +# / factorial2(2 * angmoms_a[:, :, np.newaxis] - 1) +# ), +# axis=1, +# ) +# norm_b = np.prod( +# np.sqrt( +# (2 * exps_b[np.newaxis, np.newaxis, :] / np.pi) ** (1 / 2) +# * (4 * exps_b[np.newaxis, np.newaxis, :]) ** angmoms_b[:, :, np.newaxis] +# / factorial2(2 * angmoms_b[:, :, np.newaxis] - 1) +# ), +# axis=1, +# ) +# test = _compute_multipole_moment_integrals( +# coord_moment, +# orders_moment, +# coord_a, +# angmoms_a, +# exps_a, +# coeffs_a, +# norm_a, +# coord_b, +# angmoms_b, +# exps_b, +# coeffs_b, +# norm_b, +# ) +# assert test.shape == (orders_moment.shape[0], 1, angmoms_a.shape[0], 1, angmoms_b.shape[0]) +# for i, order_moment in enumerate(orders_moment): +# for j, angmom_a in enumerate(angmoms_a): +# for k, angmom_b in enumerate(angmoms_b): +# assert np.allclose( +# _compute_multipole_moment_integrals( +# coord_moment, +# np.array([order_moment]), +# coord_a, +# np.array([angmom_a]), +# exps_a, +# coeffs_a, +# norm_a, +# coord_b, +# np.array([angmom_b]), +# exps_b, +# coeffs_b, +# norm_b, +# ), +# test[i, 0, j, 0, k] +# ) def test_compute_multipole_moment_integrals_generalized_contraction(): From 301dd5f34d32343fc3dffff6f834b8fb6cfae904 Mon Sep 17 00:00:00 2001 From: Ali-Tehrani Date: Wed, 10 Jan 2024 23:20:24 -0500 Subject: [PATCH 06/20] Add permissions to github action for pytest-cov --- .github/workflows/pytest.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index 10c71b0b..d2c7e3bb 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -12,7 +12,8 @@ jobs: tests: name: "Python ${{ matrix.py }} on OS ${{ matrix.os }}" runs-on: ${{ matrix.os }} - + permissions: write-all + strategy: matrix: os: ["ubuntu-latest", "windows-latest"] From 5dcfe5e70a8973581f385e0963be9120c523a6f3 Mon Sep 17 00:00:00 2001 From: Ali-Tehrani Date: Thu, 11 Jan 2024 10:07:28 -0500 Subject: [PATCH 07/20] Fix test that wasn't asserting --- tests/test_diff_operator_int.py | 197 +++++++++++++++---------------- tests/test_moment_int.py | 203 ++++++++++++++++---------------- 2 files changed, 199 insertions(+), 201 deletions(-) diff --git a/tests/test_diff_operator_int.py b/tests/test_diff_operator_int.py index 35e3d224..5539aa95 100644 --- a/tests/test_diff_operator_int.py +++ b/tests/test_diff_operator_int.py @@ -232,102 +232,101 @@ def test_compute_differential_operator_integrals_diff_recursion(): ) -# See issue #152: https://github.com/theochem/gbasis/issues/152 -# def test_compute_differential_operator_integrals_multiarray(): -# """Test _compute_differential_operator_integrals for computing multiple cases simultaneously. -# -# Note -# ---- -# The function itself `_compute_differential._operator_integrals` is used to test the use case for -# contractions. It assumes that this function behaves correctly for contractions. -# -# """ -# coord_a = np.array([0.2, 0.4, 0.6]) -# coord_b = np.array([0.3, 0.5, 0.7]) -# angmoms_a = np.array( -# [ -# [3, 0, 0], -# [0, 3, 0], -# [0, 0, 3], -# [2, 1, 0], -# [2, 0, 1], -# [1, 2, 0], -# [0, 2, 1], -# [1, 0, 2], -# [0, 1, 2], -# ] -# ) -# angmoms_b = np.array([[2, 0, 0], [0, 2, 0], [0, 0, 2], [1, 1, 0], [1, 0, 1], [0, 1, 1]]) -# exps_a = np.array([5.4471780, 0.8245470]) -# exps_b = np.array([0.1831920]) -# coeffs_a = np.array([[0.1562850], [0.9046910]]) -# coeffs_b = np.array([[1.0]]) -# orders_diff = np.array( -# [ -# [3, 0, 0], -# [0, 3, 0], -# [0, 0, 3], -# [2, 1, 0], -# [2, 0, 1], -# [1, 2, 0], -# [0, 2, 1], -# [1, 0, 2], -# [0, 1, 2], -# [2, 0, 0], -# [0, 2, 0], -# [0, 0, 2], -# [1, 1, 0], -# [1, 0, 1], -# [0, 1, 1], -# ] -# ) -# -# norm_a = np.prod( -# np.sqrt( -# (2 * exps_a[np.newaxis, np.newaxis, :] / np.pi) ** (1 / 2) -# * (4 * exps_a[np.newaxis, np.newaxis, :]) ** angmoms_a[:, :, np.newaxis] -# / factorial2(2 * angmoms_a[:, :, np.newaxis] - 1) -# ), -# axis=1, -# ) -# norm_b = np.prod( -# np.sqrt( -# (2 * exps_b[np.newaxis, np.newaxis, :] / np.pi) ** (1 / 2) -# * (4 * exps_b[np.newaxis, np.newaxis, :]) ** angmoms_b[:, :, np.newaxis] -# / factorial2(2 * angmoms_b[:, :, np.newaxis] - 1) -# ), -# axis=1, -# ) -# test = _compute_differential_operator_integrals( -# orders_diff, -# coord_a, -# angmoms_a, -# exps_a, -# coeffs_a, -# norm_a, -# coord_b, -# angmoms_b, -# exps_b, -# coeffs_b, -# norm_b, -# ) -# assert test.shape == (orders_diff.shape[0], 1, angmoms_a.shape[0], 1, angmoms_b.shape[0]) -# for i, order_diff in enumerate(orders_diff): -# for j, angmom_a in enumerate(angmoms_a): -# for k, angmom_b in enumerate(angmoms_b): -# assert np.allclose( -# _compute_differential_operator_integrals( -# np.array([order_diff]), -# coord_a, -# np.array([angmom_a]), -# exps_a, -# coeffs_a, -# norm_a, -# coord_b, -# np.array([angmom_b]), -# exps_b, -# coeffs_b, -# norm_b, -# ), -# test[i, 0, j, 0, k] -# ) +def test_compute_differential_operator_integrals_multiarray(): + """Test _compute_differential_operator_integrals for computing multiple cases simultaneously. + + Note + ---- + The function itself `_compute_differential._operator_integrals` is used to test the use case for + contractions. It assumes that this function behaves correctly for contractions. + + """ + coord_a = np.array([0.2, 0.4, 0.6]) + coord_b = np.array([0.3, 0.5, 0.7]) + angmoms_a = np.array( + [ + [3, 0, 0], + [0, 3, 0], + [0, 0, 3], + [2, 1, 0], + [2, 0, 1], + [1, 2, 0], + [0, 2, 1], + [1, 0, 2], + [0, 1, 2], + ] + ) + angmoms_b = np.array([[2, 0, 0], [0, 2, 0], [0, 0, 2], [1, 1, 0], [1, 0, 1], [0, 1, 1]]) + exps_a = np.array([5.4471780, 0.8245470]) + exps_b = np.array([0.1831920]) + coeffs_a = np.array([[0.1562850], [0.9046910]]) + coeffs_b = np.array([[1.0]]) + orders_diff = np.array( + [ + [3, 0, 0], + [0, 3, 0], + [0, 0, 3], + [2, 1, 0], + [2, 0, 1], + [1, 2, 0], + [0, 2, 1], + [1, 0, 2], + [0, 1, 2], + [2, 0, 0], + [0, 2, 0], + [0, 0, 2], + [1, 1, 0], + [1, 0, 1], + [0, 1, 1], + ] + ) + + norm_a = np.prod( + np.sqrt( + (2 * exps_a[np.newaxis, np.newaxis, :] / np.pi) ** (1 / 2) + * (4 * exps_a[np.newaxis, np.newaxis, :]) ** angmoms_a[:, :, np.newaxis] + / factorial2(2 * angmoms_a[:, :, np.newaxis] - 1) + ), + axis=1, + ) + norm_b = np.prod( + np.sqrt( + (2 * exps_b[np.newaxis, np.newaxis, :] / np.pi) ** (1 / 2) + * (4 * exps_b[np.newaxis, np.newaxis, :]) ** angmoms_b[:, :, np.newaxis] + / factorial2(2 * angmoms_b[:, :, np.newaxis] - 1) + ), + axis=1, + ) + test = _compute_differential_operator_integrals( + orders_diff, + coord_a, + angmoms_a, + exps_a, + coeffs_a, + norm_a, + coord_b, + angmoms_b, + exps_b, + coeffs_b, + norm_b, + ) + assert test.shape == (orders_diff.shape[0], 1, angmoms_a.shape[0], 1, angmoms_b.shape[0]) + for i, single_order in enumerate(orders_diff): + for j, angmom_a in enumerate(angmoms_a): + for k, angmom_b in enumerate(angmoms_b): + assert np.allclose( + _compute_differential_operator_integrals( + np.array([single_order]), + coord_a, + np.array([angmom_a]), + exps_a, + coeffs_a, + norm_a, + coord_b, + np.array([angmom_b]), + exps_b, + coeffs_b, + norm_b, + )[0, 0, j, 0, k], + test[i, 0, j, 0, k] + ) diff --git a/tests/test_moment_int.py b/tests/test_moment_int.py index c0cecd13..0f95b1b1 100644 --- a/tests/test_moment_int.py +++ b/tests/test_moment_int.py @@ -715,108 +715,107 @@ def test_compute_multipole_moment_integrals_contraction(): ) -## See issue #152: https://github.com/theochem/gbasis/issues/152 -# def test_compute_multipole_moment_integrals_multiarray(): -# """Test _compute_multipole_moment_integrals for computing multiple cases simultaneously. -# -# Note -# ---- -# The function itself `_compute_multipole_moment_integrals` is used to test the use case for -# contractions. It assumes that this function behaves correctly for contractions. -# -# """ -# coord_a = np.array([0.2, 0.4, 0.6]) -# coord_b = np.array([0.3, 0.5, 0.7]) -# angmoms_a = np.array( -# [ -# [3, 0, 0], -# [0, 3, 0], -# [0, 0, 3], -# [2, 1, 0], -# [2, 0, 1], -# [1, 2, 0], -# [0, 2, 1], -# [1, 0, 2], -# [0, 1, 2], -# ] -# ) -# angmoms_b = np.array([[2, 0, 0], [0, 2, 0], [0, 0, 2], [1, 1, 0], [1, 0, 1], [0, 1, 1]]) -# exps_a = np.array([5.4471780, 0.8245470]) -# exps_b = np.array([0.1831920]) -# coeffs_a = np.array([[0.1562850], [0.9046910]]) -# coeffs_b = np.array([[1.0]]) -# coord_moment = np.array([0.25, 0.45, 0.65]) -# orders_moment = np.array( -# [ -# [3, 0, 0], -# [0, 3, 0], -# [0, 0, 3], -# [2, 1, 0], -# [2, 0, 1], -# [1, 2, 0], -# [0, 2, 1], -# [1, 0, 2], -# [0, 1, 2], -# [2, 0, 0], -# [0, 2, 0], -# [0, 0, 2], -# [1, 1, 0], -# [1, 0, 1], -# [0, 1, 1], -# ] -# ) -# -# norm_a = np.prod( -# np.sqrt( -# (2 * exps_a[np.newaxis, np.newaxis, :] / np.pi) ** (1 / 2) -# * (4 * exps_a[np.newaxis, np.newaxis, :]) ** angmoms_a[:, :, np.newaxis] -# / factorial2(2 * angmoms_a[:, :, np.newaxis] - 1) -# ), -# axis=1, -# ) -# norm_b = np.prod( -# np.sqrt( -# (2 * exps_b[np.newaxis, np.newaxis, :] / np.pi) ** (1 / 2) -# * (4 * exps_b[np.newaxis, np.newaxis, :]) ** angmoms_b[:, :, np.newaxis] -# / factorial2(2 * angmoms_b[:, :, np.newaxis] - 1) -# ), -# axis=1, -# ) -# test = _compute_multipole_moment_integrals( -# coord_moment, -# orders_moment, -# coord_a, -# angmoms_a, -# exps_a, -# coeffs_a, -# norm_a, -# coord_b, -# angmoms_b, -# exps_b, -# coeffs_b, -# norm_b, -# ) -# assert test.shape == (orders_moment.shape[0], 1, angmoms_a.shape[0], 1, angmoms_b.shape[0]) -# for i, order_moment in enumerate(orders_moment): -# for j, angmom_a in enumerate(angmoms_a): -# for k, angmom_b in enumerate(angmoms_b): -# assert np.allclose( -# _compute_multipole_moment_integrals( -# coord_moment, -# np.array([order_moment]), -# coord_a, -# np.array([angmom_a]), -# exps_a, -# coeffs_a, -# norm_a, -# coord_b, -# np.array([angmom_b]), -# exps_b, -# coeffs_b, -# norm_b, -# ), -# test[i, 0, j, 0, k] -# ) +def test_compute_multipole_moment_integrals_multiarray(): + """Test _compute_multipole_moment_integrals for computing multiple cases simultaneously. + + Note + ---- + The function itself `_compute_multipole_moment_integrals` is used to test the use case for + contractions. It assumes that this function behaves correctly for contractions. + + """ + coord_a = np.array([0.2, 0.4, 0.6]) + coord_b = np.array([0.3, 0.5, 0.7]) + angmoms_a = np.array( + [ + [3, 0, 0], + [0, 3, 0], + [0, 0, 3], + [2, 1, 0], + [2, 0, 1], + [1, 2, 0], + [0, 2, 1], + [1, 0, 2], + [0, 1, 2], + ] + ) + angmoms_b = np.array([[2, 0, 0], [0, 2, 0], [0, 0, 2], [1, 1, 0], [1, 0, 1], [0, 1, 1]]) + exps_a = np.array([5.4471780, 0.8245470]) + exps_b = np.array([0.1831920]) + coeffs_a = np.array([[0.1562850], [0.9046910]]) + coeffs_b = np.array([[1.0]]) + coord_moment = np.array([0.25, 0.45, 0.65]) + orders_moment = np.array( + [ + [3, 0, 0], + [0, 3, 0], + [0, 0, 3], + [2, 1, 0], + [2, 0, 1], + [1, 2, 0], + [0, 2, 1], + [1, 0, 2], + [0, 1, 2], + [2, 0, 0], + [0, 2, 0], + [0, 0, 2], + [1, 1, 0], + [1, 0, 1], + [0, 1, 1], + ] + ) + + norm_a = np.prod( + np.sqrt( + (2 * exps_a[np.newaxis, np.newaxis, :] / np.pi) ** (1 / 2) + * (4 * exps_a[np.newaxis, np.newaxis, :]) ** angmoms_a[:, :, np.newaxis] + / factorial2(2 * angmoms_a[:, :, np.newaxis] - 1) + ), + axis=1, + ) + norm_b = np.prod( + np.sqrt( + (2 * exps_b[np.newaxis, np.newaxis, :] / np.pi) ** (1 / 2) + * (4 * exps_b[np.newaxis, np.newaxis, :]) ** angmoms_b[:, :, np.newaxis] + / factorial2(2 * angmoms_b[:, :, np.newaxis] - 1) + ), + axis=1, + ) + test = _compute_multipole_moment_integrals( + coord_moment, + orders_moment, + coord_a, + angmoms_a, + exps_a, + coeffs_a, + norm_a, + coord_b, + angmoms_b, + exps_b, + coeffs_b, + norm_b, + ) + assert test.shape == (orders_moment.shape[0], 1, angmoms_a.shape[0], 1, angmoms_b.shape[0]) + for i, order_moment in enumerate(orders_moment): + for j, angmom_a in enumerate(angmoms_a): + for k, angmom_b in enumerate(angmoms_b): + assert np.allclose( + _compute_multipole_moment_integrals( + coord_moment, + np.array([order_moment]), + coord_a, + np.array([angmom_a]), + exps_a, + coeffs_a, + norm_a, + coord_b, + np.array([angmom_b]), + exps_b, + coeffs_b, + norm_b, + )[0, 0, j, 0, k], + test[i, 0, j, 0, k] + ) def test_compute_multipole_moment_integrals_generalized_contraction(): From 67c0a143971ca42d3d847e6cffb1ba1b51a78c82 Mon Sep 17 00:00:00 2001 From: Ali-Tehrani Date: Thu, 11 Jan 2024 10:33:26 -0500 Subject: [PATCH 08/20] Remove coverage comment and just do coverage - Adding a comment on teh pull-request based on teh coverage only works if you're doign a pull-request from teh master branch - Instead just did, get an error if it reaches a certain pt --- .github/workflows/pytest.yaml | 41 ++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index d2c7e3bb..0ee3326f 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -9,11 +9,13 @@ on: pull_request: jobs: - tests: + pytest: name: "Python ${{ matrix.py }} on OS ${{ matrix.os }}" runs-on: ${{ matrix.os }} - permissions: write-all - + env: + COVERAGE_SINGLE: 80 + COVERAGE_TOTAL: 90 + strategy: matrix: os: ["ubuntu-latest", "windows-latest"] @@ -37,18 +39,23 @@ jobs: # Need editable mode in order to include the test files pip install -e . - - name: Run pytest - uses: pavelzw/pytest-action@v2 - with: - verbose: true - emoji: true - job-summary: true - click-to-expand: true - custom-arguments: "--junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=gbasis" - report-title: 'Test Report' - - - name: Pytest coverage comment - uses: MishaKav/pytest-coverage-comment@main + - name: pytester-cov + id: pytester-cov + uses: programmingwithalex/pytester-cov@main with: - pytest-coverage-path: ./pytest-coverage.txt - junitxml-path: ./pytest.xml + pytest-root-dir: './gbasis/' + pytest-tests-dir: "./tests/" + cov-threshold-single: ${{ env.COVERAGE_SINGLE }} + cov-threshold-total: ${{ env.COVERAGE_TOTAL }} + + - name: Coverage single fail - exit + if: ${{ steps.pytester-cov.outputs.cov-threshold-single-fail == 'true' }} + run: | + echo "cov single fail ${{ steps.pytester-cov.outputs.cov-threshold-single-fail }}" + exit 1 + + - name: Coverage total fail - exit + if: ${{ steps.pytester-cov.outputs.cov-threshold-total-fail == 'true' }} + run: | + echo "cov single fail ${{ steps.pytester-cov.outputs.cov-threshold-total-fail }}" + exit 1 From f926d061cb71e315fefb9e91c80641e67acb611c Mon Sep 17 00:00:00 2001 From: Ali-Tehrani Date: Thu, 11 Jan 2024 10:45:44 -0500 Subject: [PATCH 09/20] Update pre-commit so it doesn't run on websites --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 669bb11e..a37abf3c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,4 @@ +exclude: "./website/" repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 From 313b71a14606f3a97cae0927190552060e7e4ae2 Mon Sep 17 00:00:00 2001 From: Ali-Tehrani Date: Thu, 11 Jan 2024 10:56:57 -0500 Subject: [PATCH 10/20] Update precommit to only work on gbasis and tests --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a37abf3c..6be9b960 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,4 @@ -exclude: "./website/" +include: "gbasis/|tests/" repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 From 2be59ca3549dd3e5447b9ef4d2d11f2f93a258ac Mon Sep 17 00:00:00 2001 From: Ali-Tehrani Date: Thu, 11 Jan 2024 11:07:46 -0500 Subject: [PATCH 11/20] Add my own pytest-cov - Fails if the total coverage is less than 90 percent. --- .github/workflows/pytest.yaml | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index 0ee3326f..f40c14a7 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -39,23 +39,6 @@ jobs: # Need editable mode in order to include the test files pip install -e . - - name: pytester-cov - id: pytester-cov - uses: programmingwithalex/pytester-cov@main - with: - pytest-root-dir: './gbasis/' - pytest-tests-dir: "./tests/" - cov-threshold-single: ${{ env.COVERAGE_SINGLE }} - cov-threshold-total: ${{ env.COVERAGE_TOTAL }} - - - name: Coverage single fail - exit - if: ${{ steps.pytester-cov.outputs.cov-threshold-single-fail == 'true' }} - run: | - echo "cov single fail ${{ steps.pytester-cov.outputs.cov-threshold-single-fail }}" - exit 1 - - - name: Coverage total fail - exit - if: ${{ steps.pytester-cov.outputs.cov-threshold-total-fail == 'true' }} + - name: Run Pytest run: | - echo "cov single fail ${{ steps.pytester-cov.outputs.cov-threshold-total-fail }}" - exit 1 + pytest --cov=./gbasis/ --cov-fail-under=90 --cov-report term . From 0db7ba0c00a5aa9b881023240e2c2f5e1a398605 Mon Sep 17 00:00:00 2001 From: Ali-Tehrani Date: Thu, 11 Jan 2024 11:13:00 -0500 Subject: [PATCH 12/20] Fix previous bad merge --- gbasis/evals/eval_deriv.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gbasis/evals/eval_deriv.py b/gbasis/evals/eval_deriv.py index c7dbf536..6f50b59f 100644 --- a/gbasis/evals/eval_deriv.py +++ b/gbasis/evals/eval_deriv.py @@ -3,8 +3,10 @@ from gbasis.base_one import BaseOneIndex from gbasis.contractions import GeneralizedContractionShell -from gbasis.evals._deriv import _eval_first_second_order_deriv_contractions - +from gbasis.evals._deriv import ( + _eval_deriv_contractions, + _eval_first_second_order_deriv_contractions, +) class EvalDeriv(BaseOneIndex): """Class for evaluating Gaussian contractions and their linear combinations. From 619a56c1e021bfe3d567fba18017560cacf648cd Mon Sep 17 00:00:00 2001 From: Ali-Tehrani Date: Thu, 11 Jan 2024 14:41:57 -0500 Subject: [PATCH 13/20] Fix test error with not using factorial2 --- tests/test_diff_operator_int.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_diff_operator_int.py b/tests/test_diff_operator_int.py index 5539aa95..5ac66a8d 100644 --- a/tests/test_diff_operator_int.py +++ b/tests/test_diff_operator_int.py @@ -2,10 +2,10 @@ import itertools as it import numpy as np -from scipy.special import factorial2 from test_moment_int import answer_prim as answer_prim_overlap from gbasis.integrals._diff_operator_int import _compute_differential_operator_integrals +from gbasis.utils import factorial2 def answer_prim(coord_type, i, j, k): @@ -297,6 +297,7 @@ def test_compute_differential_operator_integrals_multiarray(): ), axis=1, ) + test = _compute_differential_operator_integrals( orders_diff, coord_a, From 3476723642e7499da55e7d43f7215f8ec005bcfe Mon Sep 17 00:00:00 2001 From: Ali-Tehrani Date: Thu, 11 Jan 2024 14:50:51 -0500 Subject: [PATCH 14/20] Update editorconfig to remove the comment --- .editorconfig | 2 +- .pre-commit-config.yaml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index df64623b..dde5c5bf 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,4 +1,4 @@ -# EditorConfig is awesome: https://EditorConfig.org +# EditorConfig: https://EditorConfig.org root = true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6be9b960..d8765a00 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,5 @@ -include: "gbasis/|tests/" +include: "gbasis/*|gbasis/*/*|tests/.*" +exclude: "website/*" repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 From 9303716b8fa85a02b9929246a162901336de5e26 Mon Sep 17 00:00:00 2001 From: Ali-Tehrani Date: Thu, 11 Jan 2024 14:57:14 -0500 Subject: [PATCH 15/20] Fix black issues --- gbasis/contractions.py | 3 +- gbasis/evals/_deriv.py | 50 ++++++---- gbasis/evals/density.py | 160 ++++++++++++++++++++++---------- gbasis/evals/eval_deriv.py | 17 ++-- gbasis/spherical.py | 5 +- tests/test_density_direct.py | 65 +++++++------ tests/test_deriv.py | 10 +- tests/test_diff_operator_int.py | 2 +- tests/test_moment_int.py | 2 +- tests/test_two_elec_int.py | 1 + tests/utils.py | 4 +- 11 files changed, 200 insertions(+), 119 deletions(-) diff --git a/gbasis/contractions.py b/gbasis/contractions.py index 60480bb8..da5fc56c 100644 --- a/gbasis/contractions.py +++ b/gbasis/contractions.py @@ -385,8 +385,7 @@ def angmom_components_sph(self): """ return tuple( - [f"s{m}" for m in range(self.angmom, 0, -1)] - + [f"c{m}" for m in range(self.angmom + 1)] + [f"s{m}" for m in range(self.angmom, 0, -1)] + [f"c{m}" for m in range(self.angmom + 1)] ) @property diff --git a/gbasis/evals/_deriv.py b/gbasis/evals/_deriv.py index c96331a1..c357a82b 100644 --- a/gbasis/evals/_deriv.py +++ b/gbasis/evals/_deriv.py @@ -143,7 +143,7 @@ def _eval_deriv_contractions(coords, orders, center, angmom_comps, alphas, prim_ def _eval_first_second_order_deriv_contractions( - coords, orders, center, angmom_comps, alphas, prim_coeffs, norm + coords, orders, center, angmom_comps, alphas, prim_coeffs, norm ): """Return the evaluation of direct 1st and 2nd derivative orders of a Cartesian contraction. @@ -195,7 +195,7 @@ def _eval_first_second_order_deriv_contractions( # Useful variables new_coords = coords.T - center[None, :].T - gauss = np.exp(-alphas[:, None, None] * (new_coords ** 2)) + gauss = np.exp(-alphas[:, None, None] * (new_coords**2)) # Filters derivative orders indices_noderiv = orders <= 0 @@ -216,17 +216,21 @@ def _eval_first_second_order_deriv_contractions( # Calling 1st and 2nd derivatives functions for different combination of orders if indices_first_deriv.any(): - first_deriv = _first_derivative(new_coords, gauss, indices_first_deriv, - angmom_comps, alphas) + first_deriv = _first_derivative( + new_coords, gauss, indices_first_deriv, angmom_comps, alphas + ) if indices_second_deriv.any(): - second_deriv = _second_derivative(new_coords, gauss, indices_second_deriv, - angmom_comps, alphas) + second_deriv = _second_derivative( + new_coords, gauss, indices_second_deriv, angmom_comps, alphas + ) elif indices_second_deriv.any(): - second_deriv = _second_derivative(new_coords, gauss, indices_second_deriv, - angmom_comps, alphas) + second_deriv = _second_derivative( + new_coords, gauss, indices_second_deriv, angmom_comps, alphas + ) if indices_first_deriv.any(): - first_deriv = _first_derivative(new_coords, gauss, indices_first_deriv, - angmom_comps, alphas) + first_deriv = _first_derivative( + new_coords, gauss, indices_first_deriv, angmom_comps, alphas + ) # Combining all the derivatives norm = norm.T[:, :, np.newaxis] output = np.tensordot(prim_coeffs, norm * zeroth_deriv * first_deriv * second_deriv, (0, 0)) @@ -279,14 +283,15 @@ def _first_derivative(center_coords, gauss, indices_first_deriv, angmom_comps, a # zero (and negative power is undefined). power_part_1[power_part_1 < 0] = 0 part1 = first_coords[:, None, :] ** power_part_1[:, :, None] - part2 = (2 * alphas[:, None, None]) * (first_coords ** 2) + part2 = (2 * alphas[:, None, None]) * (first_coords**2) part2 = first_ang_comp[None, :, :, None] - part2[:, :, None, :] # NOTE: Using an array of ones with same shape as first_ang_comp to power part2_zero_ang_mom # variable in order to get the same shape as part2. This is done in order to make easier # to filter at the end for the angular components corresponding to n=0 array_ones = np.ones(first_ang_comp.shape) - part2_n_0 = -2 * alphas[:, None, None, None] * ( - first_coords[:, None, :] ** array_ones[:, :, None]) + part2_n_0 = ( + -2 * alphas[:, None, None, None] * (first_coords[:, None, :] ** array_ones[:, :, None]) + ) raw_first_deriv = part1 * part2 # Substitute angular components n=0 with correct derivative raw_first_deriv[:, n_0_indices, :] = part2_n_0[:, n_0_indices, :] @@ -342,13 +347,15 @@ def _second_derivative(center_coords, gauss, indices_second_deriv, angmom_comps, n_2_indices = second_ang_comp >= 2 # angular momentum == 0 - total_n_0 = ((4 * alphas[:, None, None] ** 2) * (second_coords ** 2)) - \ - (2 * alphas[:, None, None]) + total_n_0 = ((4 * alphas[:, None, None] ** 2) * (second_coords**2)) - ( + 2 * alphas[:, None, None] + ) raw_second_deriv = total_n_0[:, :, None, :] ** array_ones[None, :, :, None] # angular momentum == 1 if any(second_ang_comp[0] == 1): - total_n_1 = ((4 * alphas[:, None, None] ** 2) * (second_coords ** 3)) \ - - ((6 * alphas[:, None, None]) * second_coords) + total_n_1 = ((4 * alphas[:, None, None] ** 2) * (second_coords**3)) - ( + (6 * alphas[:, None, None]) * second_coords + ) total_n_1 = total_n_1[:, :, None, :] ** array_ones[None, :, :, None] # Substitute angular components n=1 with correct derivative raw_second_deriv[:, n_1_indices, :] = total_n_1[:, n_1_indices, :] @@ -363,9 +370,12 @@ def _second_derivative(center_coords, gauss, indices_second_deriv, angmom_comps, # Calculating # ..math:: 4 \alpha^{2}\left(x-X_{A}\right)^{4}- # \alpha(4 n+2)\left(x-X_{A}\right)^{2}+n(n-1) - part2_1_n_2 = (4 * alphas[:, None, None] ** 2) * (second_coords ** 4) - part2_2_n_2 = alphas[:, None, None, None] * (4 * second_ang_comp[:, :, None] + 2) \ - * second_coords[:, None, :] ** 2 + part2_1_n_2 = (4 * alphas[:, None, None] ** 2) * (second_coords**4) + part2_2_n_2 = ( + alphas[:, None, None, None] + * (4 * second_ang_comp[:, :, None] + 2) + * second_coords[:, None, :] ** 2 + ) part2_3_n_2 = second_ang_comp * (second_ang_comp - 1) part2_n_2 = part2_1_n_2[:, :, None, :] - part2_2_n_2 + part2_3_n_2[None, :, :, None] total_n_2 = part1_n_2[None, :, :, :] * part2_n_2 diff --git a/gbasis/evals/density.py b/gbasis/evals/density.py index 21342ae9..4daaca2e 100644 --- a/gbasis/evals/density.py +++ b/gbasis/evals/density.py @@ -112,7 +112,7 @@ def evaluate_deriv_reduced_density_matrix( points, transform=None, coord_type="spherical", - deriv_type="general" + deriv_type="general", ): r"""Return the derivative of the first-order reduced density matrix at the given points. @@ -185,8 +185,12 @@ def evaluate_deriv_reduced_density_matrix( deriv_orb_eval_two = deriv_orb_eval_one else: deriv_orb_eval_two = evaluate_deriv_basis( - basis, points, orders_two, transform=transform, coord_type=coord_type, - deriv_type=deriv_type + basis, + points, + orders_two, + transform=transform, + coord_type=coord_type, + deriv_type=deriv_type, ) density = one_density_matrix.dot(deriv_orb_eval_two) density *= deriv_orb_eval_one @@ -195,8 +199,13 @@ def evaluate_deriv_reduced_density_matrix( def evaluate_deriv_density( - orders, one_density_matrix, basis, points, transform=None, - coord_type="spherical", deriv_type="general" + orders, + one_density_matrix, + basis, + points, + transform=None, + coord_type="spherical", + deriv_type="general", ): r"""Return the derivative of density of the given transformed basis set at the given points. @@ -260,15 +269,15 @@ def evaluate_deriv_density( orders_two = orders - orders_one if any(orders_one > 2) or any(orders_two > 2): density = evaluate_deriv_reduced_density_matrix( - orders_one, - orders_two, - one_density_matrix, - basis, - points, - transform=transform, - coord_type=coord_type, - deriv_type='general', - ) + orders_one, + orders_two, + one_density_matrix, + basis, + points, + transform=transform, + coord_type=coord_type, + deriv_type="general", + ) else: density = evaluate_deriv_reduced_density_matrix( orders_one, @@ -332,19 +341,23 @@ def evaluate_density_gradient( output = np.zeros((3, len(points))) # Evaluation of generalized contraction shell for zeroth order = 0,0,0 zeroth_deriv = evaluate_deriv_basis( - basis, points, np.array([0, 0, 0]), - transform=transform, coord_type=coord_type, deriv_type=deriv_type + basis, + points, + np.array([0, 0, 0]), + transform=transform, + coord_type=coord_type, + deriv_type=deriv_type, ) # Evaluation of generalized contraction shell for each partial derivative for ind, orders in enumerate(orders_one): deriv_comp = evaluate_deriv_basis( basis, points, orders, transform=transform, coord_type=coord_type, deriv_type=deriv_type - ) + ) # output[ind] = 2*(np.einsum('ij,ik,jk -> k',one_density_matrix, zeroth_deriv, deriv_comp)) density = one_density_matrix.dot(zeroth_deriv) density *= deriv_comp - output[ind] = (2 * 1 * np.sum(density, axis=0)) + output[ind] = 2 * 1 * np.sum(density, axis=0) return output.T @@ -397,8 +410,12 @@ def evaluate_density_laplacian( output = np.zeros(points.shape[0]) # Evaluation of generalized contraction shell for zeroth order = 0,0,0 zeroth_deriv = evaluate_deriv_basis( - basis, points, np.array([0, 0, 0]), - transform=transform, coord_type=coord_type, deriv_type=deriv_type + basis, + points, + np.array([0, 0, 0]), + transform=transform, + coord_type=coord_type, + deriv_type=deriv_type, ) # Evaluation of generalized contraction shell for each partial derivative @@ -409,22 +426,30 @@ def evaluate_density_laplacian( density = one_density_matrix.dot(zeroth_deriv) density *= deriv_one - output += (2 * 1 * np.sum(density, axis=0)) + output += 2 * 1 * np.sum(density, axis=0) for orders in zip(orders_one_first, orders_two): deriv_one = evaluate_deriv_basis( - basis, points, orders[0], transform=transform, coord_type=coord_type, - deriv_type=deriv_type + basis, + points, + orders[0], + transform=transform, + coord_type=coord_type, + deriv_type=deriv_type, ) deriv_two = evaluate_deriv_basis( - basis, points, orders[1], transform=transform, coord_type=coord_type, - deriv_type=deriv_type + basis, + points, + orders[1], + transform=transform, + coord_type=coord_type, + deriv_type=deriv_type, ) # output[ind] = 2*(np.einsum('ij,ik,jk -> k',one_density_matrix, zeroth_deriv, deriv_comp)) density = one_density_matrix.dot(deriv_two) density *= deriv_one - output += (2 * 1 * np.sum(density, axis=0)) + output += 2 * 1 * np.sum(density, axis=0) return output @@ -476,19 +501,31 @@ def evaluate_density_hessian( """ # Orders combined with zeroth derivative - orders_one_zeroth = np.array(([[2, 0, 0], [1, 1, 0], [1, 0, 1]], - [[1, 1, 0], [0, 2, 0], [0, 1, 1]], - [[1, 0, 1], [0, 1, 1], [0, 0, 2]])) + orders_one_zeroth = np.array( + ( + [[2, 0, 0], [1, 1, 0], [1, 0, 1]], + [[1, 1, 0], [0, 2, 0], [0, 1, 1]], + [[1, 0, 1], [0, 1, 1], [0, 0, 2]], + ) + ) # Pairs of first order derivatives - orders_one_two = np.array(([[1, 0, 0], [0, 1, 0], [0, 0, 1]], - [[1, 0, 0], [0, 1, 0], [0, 0, 1]], - [[1, 0, 0], [0, 1, 0], [0, 0, 1]])) + orders_one_two = np.array( + ( + [[1, 0, 0], [0, 1, 0], [0, 0, 1]], + [[1, 0, 0], [0, 1, 0], [0, 0, 1]], + [[1, 0, 0], [0, 1, 0], [0, 0, 1]], + ) + ) # Evaluation of generalized contraction shell for zeroth order = 0,0,0 zeroth_deriv = evaluate_deriv_basis( - basis, points, np.array([0, 0, 0]), - transform=transform, coord_type=coord_type, deriv_type=deriv_type + basis, + points, + np.array([0, 0, 0]), + transform=transform, + coord_type=coord_type, + deriv_type=deriv_type, ) # Arrays for derivative @@ -501,25 +538,37 @@ def evaluate_density_hessian( for j in range(i + 1): # for j in range(3): one_zeroth_arr[j][i] = evaluate_deriv_basis( - basis, points, orders_one_zeroth[j][i], transform=transform, - coord_type=coord_type, deriv_type=deriv_type + basis, + points, + orders_one_zeroth[j][i], + transform=transform, + coord_type=coord_type, + deriv_type=deriv_type, ) one_two_arr_1[j][i] = evaluate_deriv_basis( - basis, points, orders_one_two[j][j], transform=transform, - coord_type=coord_type, deriv_type=deriv_type + basis, + points, + orders_one_two[j][j], + transform=transform, + coord_type=coord_type, + deriv_type=deriv_type, ) one_two_arr_2[j][i] = evaluate_deriv_basis( - basis, points, orders_one_two[j][i], transform=transform, - coord_type=coord_type, deriv_type=deriv_type + basis, + points, + orders_one_two[j][i], + transform=transform, + coord_type=coord_type, + deriv_type=deriv_type, ) # double orders-zeroth density raw_density_1 = np.tensordot(one_zeroth_arr, one_density_matrix, (2, 1)) - density_1 = np.einsum('ijkm,ijmk -> ijkm', zeroth_arr, raw_density_1) + density_1 = np.einsum("ijkm,ijmk -> ijkm", zeroth_arr, raw_density_1) # one_two density raw_density_2 = np.tensordot(one_two_arr_2, one_density_matrix, (2, 1)) - density_2 = np.einsum('ijkm,ijmk -> ijkm', one_two_arr_1, raw_density_2) + density_2 = np.einsum("ijkm,ijmk -> ijkm", one_two_arr_1, raw_density_2) # factors and sum over basis functions output = 2 * 1 * np.sum(density_1, axis=2) @@ -597,7 +646,7 @@ def evaluate_posdef_kinetic_energy_density( points, transform=transform, coord_type=coord_type, - deriv_type=deriv_type + deriv_type=deriv_type, ) # Fix: #117; to avoid small negative values, the array is clipped return (0.5 * output).clip(min=0.0) @@ -605,8 +654,13 @@ def evaluate_posdef_kinetic_energy_density( # TODO: test against a reference def evaluate_general_kinetic_energy_density( - one_density_matrix, basis, points, alpha, transform=None, - coord_type="spherical", deriv_type="general" + one_density_matrix, + basis, + points, + alpha, + transform=None, + coord_type="spherical", + deriv_type="general", ): r"""Return evaluations of general form of the kinetic energy density at the given points. @@ -666,12 +720,20 @@ def evaluate_general_kinetic_energy_density( raise TypeError("`alpha` must be an int or float.") general_kinetic_energy_density = evaluate_posdef_kinetic_energy_density( - one_density_matrix, basis, points, transform=transform, coord_type=coord_type, - deriv_type=deriv_type + one_density_matrix, + basis, + points, + transform=transform, + coord_type=coord_type, + deriv_type=deriv_type, ) if alpha != 0: general_kinetic_energy_density += alpha * evaluate_density_laplacian( - one_density_matrix, basis, points, transform=transform, coord_type=coord_type, - deriv_type=deriv_type + one_density_matrix, + basis, + points, + transform=transform, + coord_type=coord_type, + deriv_type=deriv_type, ) return general_kinetic_energy_density diff --git a/gbasis/evals/eval_deriv.py b/gbasis/evals/eval_deriv.py index 6f50b59f..841cf14c 100644 --- a/gbasis/evals/eval_deriv.py +++ b/gbasis/evals/eval_deriv.py @@ -8,6 +8,7 @@ _eval_first_second_order_deriv_contractions, ) + class EvalDeriv(BaseOneIndex): """Class for evaluating Gaussian contractions and their linear combinations. @@ -131,11 +132,11 @@ def construct_array_contraction(contractions, points, orders, deriv_type="genera norm_prim_cart = contractions.norm_prim_cart if deriv_type == "general": output = _eval_deriv_contractions( - points, orders, center, angmom_comps, alphas, prim_coeffs, norm_prim_cart + points, orders, center, angmom_comps, alphas, prim_coeffs, norm_prim_cart ) elif deriv_type == "direct": output = _eval_first_second_order_deriv_contractions( - points, orders, center, angmom_comps, alphas, prim_coeffs, norm_prim_cart + points, orders, center, angmom_comps, alphas, prim_coeffs, norm_prim_cart ) return output @@ -194,12 +195,12 @@ def evaluate_deriv_basis( ) if all([item == "cartesian" for item in coord_type]) or coord_type == "cartesian": return EvalDeriv(basis).construct_array_cartesian( - points=points, orders=orders, deriv_type=deriv_type - ) + points=points, orders=orders, deriv_type=deriv_type + ) if all([item == "spherical" for item in coord_type]) or coord_type == "spherical": return EvalDeriv(basis).construct_array_spherical( - points=points, orders=orders, deriv_type=deriv_type - ) + points=points, orders=orders, deriv_type=deriv_type + ) return EvalDeriv(basis).construct_array_mix( - coord_type, points=points, orders=orders, deriv_type=deriv_type - ) + coord_type, points=points, orders=orders, deriv_type=deriv_type + ) diff --git a/gbasis/spherical.py b/gbasis/spherical.py index 113cfbbc..5f3ffede 100644 --- a/gbasis/spherical.py +++ b/gbasis/spherical.py @@ -303,10 +303,7 @@ def generate_transformation(angmom, cartesian_order, spherical_order, apply_from len(spherical_order) == 2 * angmom + 1 # Strip out "-" from the ordering to make sure the right components are there and {x.replace("-", "") for x in spherical_order} - == set( - [f"s{m}" for m in range(angmom, 0, -1)] - + [f"c{m}" for m in range(angmom + 1)] - ) + == set([f"s{m}" for m in range(angmom, 0, -1)] + [f"c{m}" for m in range(angmom + 1)]) ): raise ValueError( "`spherical_order` must contain exactly 2 * `angmom` + 1 pure function strings, with " diff --git a/tests/test_density_direct.py b/tests/test_density_direct.py index e2b0bbf7..69526149 100644 --- a/tests/test_density_direct.py +++ b/tests/test_density_direct.py @@ -86,8 +86,9 @@ def test_evaluate_deriv_density(): points = np.random.rand(10, 3) assert np.allclose( - evaluate_deriv_density(np.array([1, 0, 0]), density, basis, points, - transform, deriv_type="direct"), + evaluate_deriv_density( + np.array([1, 0, 0]), density, basis, points, transform, deriv_type="direct" + ), np.einsum( "ij,ik,jk->k", density, @@ -103,8 +104,9 @@ def test_evaluate_deriv_density(): ) assert np.allclose( - evaluate_deriv_density(np.array([0, 1, 0]), density, basis, - points, transform, deriv_type='direct'), + evaluate_deriv_density( + np.array([0, 1, 0]), density, basis, points, transform, deriv_type="direct" + ), np.einsum( "ij,ik,jk->k", density, @@ -120,8 +122,9 @@ def test_evaluate_deriv_density(): ) assert np.allclose( - evaluate_deriv_density(np.array([0, 0, 1]), density, basis, - points, transform, deriv_type='direct'), + evaluate_deriv_density( + np.array([0, 0, 1]), density, basis, points, transform, deriv_type="direct" + ), np.einsum( "ij,ik,jk->k", density, @@ -137,8 +140,9 @@ def test_evaluate_deriv_density(): ) assert np.allclose( - evaluate_deriv_density(np.array([2, 3, 0]), density, basis, points, - transform, deriv_type='direct'), + evaluate_deriv_density( + np.array([2, 3, 0]), density, basis, points, transform, deriv_type="direct" + ), np.einsum( "ij,ik,jk->k", density, @@ -234,7 +238,7 @@ def test_evaluate_density_gradient(): points = np.random.rand(10, 3) np.allclose( - evaluate_density_gradient(density, basis, points, transform, deriv_type='direct').T, + evaluate_density_gradient(density, basis, points, transform, deriv_type="direct").T, np.array( [ np.einsum( @@ -320,8 +324,9 @@ def test_evaluate_density_gradient_horton(): grid_3d = np.vstack([grid_x.ravel(), grid_y.ravel(), grid_z.ravel()]).T assert np.allclose( - evaluate_density_gradient(np.identity(88), basis, grid_3d, - np.identity(88), deriv_type='direct'), + evaluate_density_gradient( + np.identity(88), basis, grid_3d, np.identity(88), deriv_type="direct" + ), horton_density_gradient, ) @@ -338,7 +343,7 @@ def test_evaluate_hessian_deriv_horton(): basis = make_contractions(basis_dict, ["H", "He"], points) basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps) for i in basis] - horton_density_hessian = np.zeros((10 ** 3, 3, 3)) + horton_density_hessian = np.zeros((10**3, 3, 3)) horton_density_hessian[:, [0, 0, 0, 1, 1, 2], [0, 1, 2, 1, 2, 2]] = np.load( find_datafile("data_horton_hhe_sph_density_hessian.npy") ) @@ -351,8 +356,9 @@ def test_evaluate_hessian_deriv_horton(): grid_3d = np.vstack([grid_x.ravel(), grid_y.ravel(), grid_z.ravel()]).T assert np.allclose( - evaluate_density_hessian(np.identity(88), basis, grid_3d, - np.identity(88), deriv_type='direct'), + evaluate_density_hessian( + np.identity(88), basis, grid_3d, np.identity(88), deriv_type="direct" + ), horton_density_hessian, ) @@ -376,8 +382,9 @@ def test_evaluate_laplacian_deriv_horton(): grid_3d = np.vstack([grid_x.ravel(), grid_y.ravel(), grid_z.ravel()]).T assert np.allclose( - evaluate_density_laplacian(np.identity(88), basis, grid_3d, - np.identity(88), deriv_type='direct'), + evaluate_density_laplacian( + np.identity(88), basis, grid_3d, np.identity(88), deriv_type="direct" + ), horton_density_laplacian, ) @@ -403,8 +410,9 @@ def test_evaluate_posdef_kinetic_energy_density(): grid_3d = np.vstack([grid_x.ravel(), grid_y.ravel(), grid_z.ravel()]).T assert np.allclose( - evaluate_posdef_kinetic_energy_density(np.identity(88), basis, grid_3d, - np.identity(88), deriv_type='direct'), + evaluate_posdef_kinetic_energy_density( + np.identity(88), basis, grid_3d, np.identity(88), deriv_type="direct" + ), horton_density_kinetic_density, ) @@ -433,7 +441,7 @@ def test_evaluate_general_kinetic_energy_density_horton(): assert np.allclose( evaluate_general_kinetic_energy_density( - np.identity(88), basis, grid_3d, 0, np.identity(88), deriv_type='direct' + np.identity(88), basis, grid_3d, 0, np.identity(88), deriv_type="direct" ), horton_density_kinetic_density, ) @@ -448,17 +456,20 @@ def test_evaluate_general_kinetic_energy_density(): with pytest.raises(TypeError): evaluate_general_kinetic_energy_density( - np.identity(40), basis, points, np.identity(40), np.array(0), deriv_type='direct' + np.identity(40), basis, points, np.identity(40), np.array(0), deriv_type="direct" ) with pytest.raises(TypeError): evaluate_general_kinetic_energy_density( - np.identity(40), basis, points, None, np.identity(40), deriv_type='direct' + np.identity(40), basis, points, None, np.identity(40), deriv_type="direct" ) assert np.allclose( - evaluate_general_kinetic_energy_density(np.identity(40), basis, points, 1, - np.identity(40), deriv_type='direct'), - evaluate_posdef_kinetic_energy_density(np.identity(40), basis, points, - np.identity(40), deriv_type='direct') - + evaluate_density_laplacian(np.identity(40), basis, points, - np.identity(40), deriv_type='direct'), + evaluate_general_kinetic_energy_density( + np.identity(40), basis, points, 1, np.identity(40), deriv_type="direct" + ), + evaluate_posdef_kinetic_energy_density( + np.identity(40), basis, points, np.identity(40), deriv_type="direct" + ) + + evaluate_density_laplacian( + np.identity(40), basis, points, np.identity(40), deriv_type="direct" + ), ) diff --git a/tests/test_deriv.py b/tests/test_deriv.py index 93485d09..a06936fd 100644 --- a/tests/test_deriv.py +++ b/tests/test_deriv.py @@ -119,8 +119,9 @@ def test_evaluate_deriv_prim(): np.array([2, 3, 4]), orders, np.array([0.5, 1, 1.5]), np.array([x, y, z]), 1 ), partial_deriv_finite_diff( - lambda xyz, x=x, y=y, z=z: - evaluate_prim(xyz, np.array([0.5, 1, 1.5]), np.array([x, y, z]), 1), + lambda xyz, x=x, y=y, z=z: evaluate_prim( + xyz, np.array([0.5, 1, 1.5]), np.array([x, y, z]), 1 + ), np.array([2, 3, 4]), orders, ), @@ -136,8 +137,9 @@ def test_evaluate_deriv_prim(): np.array([2, 3, 4]), orders, np.array([0.5, 1, 1.5]), np.array([x, y, z]), 1 ), partial_deriv_finite_diff( - lambda xyz, x=x, y=y, z=z: - evaluate_prim(xyz, np.array([0.5, 1, 1.5]), np.array([x, y, z]), 1), + lambda xyz, x=x, y=y, z=z: evaluate_prim( + xyz, np.array([0.5, 1, 1.5]), np.array([x, y, z]), 1 + ), np.array([2, 3, 4]), orders, epsilon=1e-5, diff --git a/tests/test_diff_operator_int.py b/tests/test_diff_operator_int.py index 5ac66a8d..39fa7327 100644 --- a/tests/test_diff_operator_int.py +++ b/tests/test_diff_operator_int.py @@ -329,5 +329,5 @@ def test_compute_differential_operator_integrals_multiarray(): coeffs_b, norm_b, )[0, 0, j, 0, k], - test[i, 0, j, 0, k] + test[i, 0, j, 0, k], ) diff --git a/tests/test_moment_int.py b/tests/test_moment_int.py index 0f95b1b1..5fafdced 100644 --- a/tests/test_moment_int.py +++ b/tests/test_moment_int.py @@ -814,7 +814,7 @@ def test_compute_multipole_moment_integrals_multiarray(): coeffs_b, norm_b, )[0, 0, j, 0, k], - test[i, 0, j, 0, k] + test[i, 0, j, 0, k], ) diff --git a/tests/test_two_elec_int.py b/tests/test_two_elec_int.py index b6140431..df15e433 100644 --- a/tests/test_two_elec_int.py +++ b/tests/test_two_elec_int.py @@ -46,6 +46,7 @@ def boys_func(order, weighted_dist): return hyp1f1(order + 1 / 2, order + 3 / 2, -weighted_dist) / (2 * order + 1) + # ruff: noqa: PLR0911 def two_int_brute( i_0, diff --git a/tests/utils.py b/tests/utils.py index 41a13232..bf90200a 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -63,9 +63,7 @@ def disable_abstract(abclass, dict_overwrite={}): # replace namespace new_dict.update(dict_overwrite) # make subclass of the abstract class with - return type( - f"{abclass.__name__} class with abstract methods disabled", (abclass,), new_dict - ) + return type(f"{abclass.__name__} class with abstract methods disabled", (abclass,), new_dict) def partial_deriv_finite_diff(func, x, order, epsilon=1e-8, num_points=1): From f73c446713cff7df0bd2271a675adf250e8a0b8d Mon Sep 17 00:00:00 2001 From: Ali-Tehrani Date: Thu, 11 Jan 2024 15:02:02 -0500 Subject: [PATCH 16/20] Precommit only work on python files --- .pre-commit-config.yaml | 2 +- tests/test_density_direct.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d8765a00..b46b9e4a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,4 @@ -include: "gbasis/*|gbasis/*/*|tests/.*" +include: "gbasis/*.py|gbasis/*/*.py|tests/*.py" exclude: "website/*" repos: - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/tests/test_density_direct.py b/tests/test_density_direct.py index 69526149..64c4fff3 100644 --- a/tests/test_density_direct.py +++ b/tests/test_density_direct.py @@ -1,4 +1,8 @@ """Test gbasis.evals.density.""" +import numpy as np +import pytest +from utils import HortonContractions, find_datafile + from gbasis.evals.density import ( evaluate_density, evaluate_density_gradient, @@ -12,9 +16,6 @@ from gbasis.evals.eval import evaluate_basis from gbasis.evals.eval_deriv import evaluate_deriv_basis from gbasis.parsers import make_contractions, parse_nwchem -import numpy as np -import pytest -from utils import find_datafile, HortonContractions def test_evaluate_density_using_evaluated_orbs(): From 666c86892594d7e3c185e8ef46c739d4c6150bb4 Mon Sep 17 00:00:00 2001 From: Ali-Tehrani Date: Thu, 11 Jan 2024 15:30:38 -0500 Subject: [PATCH 17/20] Remove trailing white-space for pre-commit --- .pre-commit-config.yaml | 4 ++-- CODE_OF_CONDUCT.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b46b9e4a..fff0c061 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ -include: "gbasis/*.py|gbasis/*/*.py|tests/*.py" -exclude: "website/*" +files: "gbasis/|tests/" +exclude: "website/" repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 166f66e5..a272a6d3 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -61,4 +61,4 @@ As quickly as possible, the QCDevs administrators will review the incident and d Once the QCDevs administrators have determined our final action, we will contact the original reporter to let them know what action (if any) we will be taking. We welcome feedback from the reporter on the appropriateness of our response, and we may (or may not) modulate our response based on that feedback. -**Credits:** This document was written by Wil Adams, Paul Ayers, Fanwang Meng, Lian Pharoah, and Michael Richer based on previous codes of conduct in QCDevs projects (primarily from Farnaz Heidar-Zadeh and Toon Verstraelen) and the freeBSD code of conduct, the Python code of conduct, the Open-Source Contributor Code of Conduct, and resources provided by the Office of Equity and Inclusion at McMaster University. The current version of the code of conduct was edited, then approved, by the QCDevs administrators. +**Credits:** This document was written by Wil Adams, Paul Ayers, Fanwang Meng, Lian Pharoah, and Michael Richer based on previous codes of conduct in QCDevs projects (primarily from Farnaz Heidar-Zadeh and Toon Verstraelen) and the freeBSD code of conduct, the Python code of conduct, the Open-Source Contributor Code of Conduct, and resources provided by the Office of Equity and Inclusion at McMaster University. The current version of the code of conduct was edited, then approved, by the QCDevs administrators. 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 18/20] [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) From 7b8269e804ebcc5b60778271ac01d6cc61b8d132 Mon Sep 17 00:00:00 2001 From: Ali-Tehrani Date: Thu, 11 Jan 2024 16:05:32 -0500 Subject: [PATCH 19/20] Add python=3.8 to teh test --- .github/workflows/pytest.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index f40c14a7..73a3aa13 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -19,7 +19,7 @@ jobs: strategy: matrix: os: ["ubuntu-latest", "windows-latest"] - py: ["3.7", "3.9", "3.10", "3.11"] + py: ["3.7", "3.8", "3.9", "3.10", "3.11"] steps: - uses: "actions/checkout@v3" From a36c523257c4a1c4aef36e4e3cb3e355147c88ef Mon Sep 17 00:00:00 2001 From: Ali-Tehrani Date: Thu, 11 Jan 2024 16:05:43 -0500 Subject: [PATCH 20/20] Fix ruff linter complaints --- gbasis/parsers.py | 10 +++++----- tests/test_parsers.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gbasis/parsers.py b/gbasis/parsers.py index 0d6782a6..e2615302 100644 --- a/gbasis/parsers.py +++ b/gbasis/parsers.py @@ -177,12 +177,12 @@ def make_contractions(basis_dict, atoms, coords, coord_types): Atoms at which the contractions are centered. coords : np.ndarray(N, 3) Coordinates of each atom. - coord_types : {"cartesian"/"c", list/tuple of "cartesian"/"c" or "spherical"/"p", "spherical"/"p"} + coord_types: {"cartesian"/"c", list/tuple of "cartesian"/"c", "spherical"/"p", "spherical"/"p"} Types of the coordinate system for the contractions. If "cartesian" or "c", then all of the contractions are treated as Cartesian contractions. If "spherical" or "p", then all of the contractions are treated as spherical contractions. - If list/tuple, then each entry must be a "cartesian" (or "c") or "spherical" (or "p") to specify the - coordinate type of each `GeneralizedContractionShell` instance. + If list/tuple, then each entry must be a "cartesian" (or "c") or "spherical" (or "p") to + specify the coordinate type of each `GeneralizedContractionShell` instance. Default value is "spherical". Returns @@ -224,8 +224,8 @@ def make_contractions(basis_dict, atoms, coords, coord_types): if len(coord_types) != num_coord_types: raise ValueError( - f"If coord_types is a list, it must be the same length as the total number of contractions." - f"got {len(coord_types)}" + f"If coord_types is a list, it must be the same length " + f"as the total number of contractions. got {len(coord_types)}" ) # make shells diff --git a/tests/test_parsers.py b/tests/test_parsers.py index 9144cd13..f699c4a9 100644 --- a/tests/test_parsers.py +++ b/tests/test_parsers.py @@ -763,7 +763,7 @@ 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", "C"}, 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")