From 7971a1a22a67a1b2dfa30745c29762be65852275 Mon Sep 17 00:00:00 2001 From: Liam Marsh Date: Wed, 22 Nov 2023 13:28:27 +0100 Subject: [PATCH] fix flake8's complaints --- python/rascaline/rascaline/calculators.py | 25 ++++++++++------- .../rascaline/rascaline/systems/__init__.py | 9 +++--- python/rascaline/rascaline/systems/pyscf.py | 28 ++++++++++--------- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/python/rascaline/rascaline/calculators.py b/python/rascaline/rascaline/calculators.py index b73ade6aa..0357dfccb 100644 --- a/python/rascaline/rascaline/calculators.py +++ b/python/rascaline/rascaline/calculators.py @@ -219,23 +219,27 @@ def __init__( class SphericalExpansionForBonds(CalculatorBase): """A SOAP-like spherical expansion coefficients for bond-centered environments - In other words, the spherical expansion of the neighbor density function centered on the center of a bond, + In other words, the spherical expansion of the neighbor density function centered + on the center of a bond, 'after' rotating the system so that the bond is aligned with the z axis. - - This is not rotationally invariant, and as such you should use some not-implemented-here matheatical trick + + This is not rotationally invariant, and as such you should use some + not-implemented-here matheatical trick similar to what SOAP (the :py:class:`SoapPowerSpectrum` class) uses. Most hyperparameters are identical to that of the regulat spherical expansion: :ref:`documentation `. - + the few changes to this are: - + - "cutoff" renamed to "third_cutoff" - - "bond_cutoff" which expresses how the pairs of atoms used for the 'bonds' are chosen. - - "center_atomS_weight" (caps only used for emphasis): the weight multiplier for the coefficients of the self - interactions (where the neighboring atom is one of the pair's atoms). + - "bond_cutoff" which expresses how the pairs of atoms used for the 'bonds' are + chosen. + - "center_atomS_weight" (caps only used for emphasis): the weight multiplier + for the coefficients of the self interactions + (where the neighboring atom is one of the pair's atoms). """ - + def __init__( self, bond_cutoff, @@ -249,7 +253,7 @@ def __init__( radial_scaling=None, ): parameters = { - "cutoffs": [bond_cutoff,third_cutoff], + "cutoffs": [bond_cutoff, third_cutoff], "max_radial": max_radial, "max_angular": max_angular, "atomic_gaussian_width": atomic_gaussian_width, @@ -263,6 +267,7 @@ def __init__( super().__init__("spherical_expansion_for_bonds", json.dumps(parameters)) + class SoapRadialSpectrum(CalculatorBase): """Radial spectrum of Smooth Overlap of Atomic Positions (SOAP). diff --git a/python/rascaline/rascaline/systems/__init__.py b/python/rascaline/rascaline/systems/__init__.py index 2000b006a..6c3d08496 100644 --- a/python/rascaline/rascaline/systems/__init__.py +++ b/python/rascaline/rascaline/systems/__init__.py @@ -35,14 +35,15 @@ def __init__(self): if HAVE_PYSCF: IntoSystem.__doc__ += """ - - `pyscf.gto.mole.Mole`_ or `pyscf.pbc.gto.cell.Cell`_: pyscf' Frame type. There is no associated neighbor - list implementation, the system will only be usable with - ``use_native_system=True`` + - `pyscf.gto.mole.Mole`_ or `pyscf.pbc.gto.cell.Cell`_: pyscf' Frame type. + There is no associated neighbor list implementation, the system will only + be usable with ``use_native_system=True`` .. _pyscf.gto.mole.Mole: https://pyscf.org/user/gto.html .. _pyscf.pbc.gto.cell.Cell: https://pyscf.org/user/pbc/gto.html """ + def wrap_system(system: IntoSystem) -> SystemBase: """Wrap different systems implementation into the right class. @@ -63,7 +64,7 @@ def wrap_system(system: IntoSystem) -> SystemBase: if HAVE_ASE and AseSystem.can_wrap(system): return AseSystem(system) - + if HAVE_PYSCF and PyscfSystem.can_wrap(system): return PyscfSystem(system) diff --git a/python/rascaline/rascaline/systems/pyscf.py b/python/rascaline/rascaline/systems/pyscf.py index 4e27f14f6..c13d4410b 100644 --- a/python/rascaline/rascaline/systems/pyscf.py +++ b/python/rascaline/rascaline/systems/pyscf.py @@ -1,8 +1,5 @@ -import warnings - import numpy as np -from .._c_api import c_uintptr_t from .base import SystemBase @@ -18,24 +15,26 @@ def _std_symbol_without_ghost(symb_or_chg): '''For a given atom symbol (lower case or upper case) or charge, return the standardized atom symbol ''' - if isinstance(symb_or_chg, (str, unicode)): + if isinstance(symb_or_chg, str): symb_or_chg = str(symb_or_chg.upper()) rawsymb = pyscf.data.elements._rm_digit(symb_or_chg) - if rawsymb in _ELEMENTS_UPPER: - return _ELEMENTS_UPPER[rawsymb] + if rawsymb in pyscf.data.elements._ELEMENTS_UPPER: + return pyscf.data.elements._ELEMENTS_UPPER[rawsymb] elif len(rawsymb) > 1 and symb_or_chg[0] == 'X' and symb_or_chg[:2] != 'XE': rawsymb = rawsymb[1:] # Remove the prefix X - return _ELEMENTS_UPPER[rawsymb] + return pyscf.data.elements._ELEMENTS_UPPER[rawsymb] elif len(rawsymb) > 5 and rawsymb[:5] == 'GHOST': rawsymb = rawsymb[5:] # Remove the prefix GHOST - return _ELEMENTS_UPPER[rawsymb] + return pyscf.data.elements._ELEMENTS_UPPER[rawsymb] else: raise RuntimeError('Unsupported atom symbol %s' % symb_or_chg) else: return pyscf.data.elements.ELEMENTS[symb_or_chg] + class PyscfSystem(SystemBase): - """Implements :py:class:`rascaline.SystemBase` wrapping a `pyscf.gto.mole.Mole`_ or `pyscf.pbc.gto.cell.Cell`_. + """Implements :py:class:`rascaline.SystemBase` wrapping a `pyscf.gto.mole.Mole`_ + or `pyscf.pbc.gto.cell.Cell`_. Since pyscf does not offer a neighbors list, this implementation of system can only be used with ``use_native_system=True`` in @@ -51,7 +50,7 @@ class PyscfSystem(SystemBase): @staticmethod def can_wrap(o): - return isinstance(o, (pyscf.gto.mole.Mole,pyscf.pbc.gto.cell.Cell)) + return isinstance(o, (pyscf.gto.mole.Mole, pyscf.pbc.gto.cell.Cell)) def __init__(self, frame): """ @@ -59,8 +58,11 @@ def __init__(self, frame): in this ``ChemfilesSystem`` """ super().__init__() - if not isinstance(frame, (pyscf.gto.mole.Mole,pyscf.pbc.gto.cell.Cell)): - raise Exception("this class expects pyscf.gto.mole.Mole or pyscf.pbc.gto.cell.Cell objects") + if not isinstance(frame, (pyscf.gto.mole.Mole, pyscf.pbc.gto.cell.Cell)): + raise Exception( + "this class expects pyscf.gto.mole.Mole" + + "or pyscf.pbc.gto.cell.Cell objects" + ) self._frame = frame self._species = self._frame.atom_charges().copy() # dtype=int32 @@ -84,7 +86,7 @@ def cell(self): if self.is_periodic: return self._frame.a else: - return np.zeros((3,3),float) + return np.zeros((3, 3), float) def compute_neighbors(self, cutoff): raise Exception(