From ef08c7e381ffe5d200f2aebb129268286ee2a226 Mon Sep 17 00:00:00 2001 From: Ali-Tehrani Date: Wed, 5 Aug 2020 09:55:59 -0400 Subject: [PATCH] Fix rob issues in basis --- iodata/basis.py | 34 +++++++++++++++++++--------------- iodata/test/test_basis.py | 4 ++-- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/iodata/basis.py b/iodata/basis.py index a32e11e6..3d306bcd 100644 --- a/iodata/basis.py +++ b/iodata/basis.py @@ -34,11 +34,13 @@ def _alsolist(f): """Wrap a function to accepts also list as first argument and then return list.""" + @wraps(f) def wrapper(firsts, *args, **kwargs): if isinstance(firsts, (Integral, str)): return f(firsts, *args, **kwargs) return [f(first, *args, **kwargs) for first in firsts] + return wrapper @@ -83,7 +85,7 @@ def angmom_its(angmom: Union[int, List[int]]) -> Union[str, List[str]]: class Shell(NamedTuple): - """Contracted shell representing (generalized) contractions with the same exponents. + r"""Contracted shell representing (generalized) contractions with the same exponents. Attributes ---------- @@ -123,7 +125,7 @@ class Shell(NamedTuple): C_{lm}(r, \theta, \phi) &:= \sqrt{2} (-1)^m \sqrt{\frac{(l - m)!}{(l + m)!}} r^l P^m_l(\cos(\theta)) \cos(m \phi) & m \in \{1, \cdots, l\} \\ S_{lm}(r, \theta, \phi) &:= \sqrt{2} (-1)^m \sqrt{\frac{(l - m)!}{(l + m)!}} - r^l P^m_l(\cos(\theta)) \sin(m \phi) & m \in \{1, \cdots, l\} \\ + r^l P^m_l(\cos(\theta)) \sin(m \phi) & m \in \{1, \cdots, l\}\\ \end{align*} where :math:`P_l^m` is the associated Legrende function and :math:`N(\alpha, l)` is the @@ -132,7 +134,7 @@ class Shell(NamedTuple): - Contraction of Primitive Gaussians is the linear combination of primitive Gaussian functions of the same shell-type l, meant as a basis function. It has the form - .. math:: P(\cdots) \sum^M_m c_m N e^{-\alpha_m r_A^2}, + .. math:: P(\cdots) \sum^M_m c_m N e^{-\alpha_m r_A^2}, where N is the normalization constant and P is either the Cartesian polynomial for a fixed (i, j, k) or the real regular solid harmonic for a fixed (l, m). The degree is the number @@ -154,7 +156,7 @@ class Shell(NamedTuple): coeffs: np.ndarray @property - def nbasis(self) -> int: # noqa: D401 + def nbasis(self) -> int: # noqa: D401 """Number of basis functions (e.g. 3 for a P shell and 4 for an SP shell).""" result = 0 for angmom, kind in zip(self.angmoms, self.kinds): @@ -167,21 +169,21 @@ def nbasis(self) -> int: # noqa: D401 return result @property - def nprim(self) -> int: # noqa: D401 + def nprim(self) -> int: # noqa: D401 """Number of primitive contracted shells, also known as the contraction length.""" return len(self.exponents) @property - def ncon(self) -> int: # noqa: D401 + def ncon(self) -> int: # noqa: D401 """Number of contractions with distinct angular momentum numbers. - This is usually 1; e.g., it would be 2 for an SP shell. - """ + This is usually 1; e.g., it would be 2 for an SP shell. + """ return len(self.angmoms) class MolecularBasis(NamedTuple): - """A complete molecular orbital or density basis set as a collection of contracted shells. + r"""A complete molecular orbital or density basis set as a collection of contracted shells. Attributes ---------- @@ -256,7 +258,7 @@ class MolecularBasis(NamedTuple): primitive_normalization: str @property - def nbasis(self) -> int: # noqa: D401 + def nbasis(self) -> int: # noqa: D401 """Number of basis functions.""" return sum(shell.nbasis for shell in self.shells) @@ -319,7 +321,7 @@ def convert_kind(self, to: str): convert_primitive_kind : Converts primitive shells with no averaging. """ - if to != "c" and to != "p": + if to not in ("c", "p"): raise ValueError("The to string was not recognized: %s" % to) shells = [] @@ -349,7 +351,9 @@ def convert_kind(self, to: str): coeffs_new.append(coeffs) shells.append( - Shell(shell.icenter, angmom, kind_new, shell.exponents, np.array(coeffs_new).T) + Shell( + shell.icenter, shell.angmoms, kind_new, shell.exponents, np.array(coeffs_new).T + ) ) # pylint: disable=no-member return self._replace(shells=shells) @@ -357,7 +361,7 @@ def convert_kind(self, to: str): def convert_primitive_kind(angmom: int, kind: str, coeffs: np.ndarray, to: str) -> np.ndarray: r""" - Converts coefficients in Cartesian to Pure or vice-versa of a Primitive shell. + Convert coefficients in Cartesian to Pure or vice-versa of a Primitive shell. Parameters ---------- @@ -398,9 +402,9 @@ def convert_primitive_kind(angmom: int, kind: str, coeffs: np.ndarray, to: str) >> new_coeffs = convert_primitive_kind(1, "c", coeff, "p") """ - if to != "c" and to != "p": + if to not in ("p", "c"): raise ValueError("The to string was not recognized: %s" % to) - if kind != "c" and kind != "p": + if kind not in ("p", "c"): raise ValueError("The kind string was not recognized: %s" % kind) if to != kind: if kind == "c": diff --git a/iodata/test/test_basis.py b/iodata/test/test_basis.py index eb898218..513cbb31 100644 --- a/iodata/test/test_basis.py +++ b/iodata/test/test_basis.py @@ -218,7 +218,7 @@ def test_get_decontracted(): ncontshells = 8 # Number of contracted shells now is equal to the number of primitives. assert_equal(len(obasis.shells), ncontshells) # Assert each shell has length one exponents - for i in range(0, ncontshells): + for _ in range(0, ncontshells): assert_equal(len(obasis.shells[0].exponents), 1) # Assert they have the right exponents. assert_equal(obasis.shells[0].exponents, 0.01) @@ -339,7 +339,7 @@ def test_convert_primitive_kind(): # Test converting D-type from kind="p" to kind="c". coeff = np.array([1., 2., 3., 4., 5.]) ccoeff = convert_primitive_kind(2, "p", coeff, "c") - desired = np.array([1.97606774, 5., 2., -2.64273441, 3., 0.66666667]) + desired = np.array([1.97606774, 5., 2., -2.64273441, 3., 0.66666667]) assert_allclose(ccoeff, desired)