Skip to content

Commit

Permalink
fix complaints of flake8 and black on the python API
Browse files Browse the repository at this point in the history
  • Loading branch information
liam-o-marsh committed Nov 22, 2023
1 parent 76a9008 commit e841798
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 41 deletions.
25 changes: 15 additions & 10 deletions python/rascaline/rascaline/calculators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <spherical-expansion>`.
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,
Expand All @@ -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,
Expand All @@ -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).
Expand Down
9 changes: 5 additions & 4 deletions python/rascaline/rascaline/systems/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)

Expand Down
51 changes: 24 additions & 27 deletions python/rascaline/rascaline/systems/pyscf.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
import warnings

import numpy as np

from .._c_api import c_uintptr_t
from .base import SystemBase


try:
import pyscf

HAVE_PYSCF = True
except ImportError:
HAVE_PYSCF = False


# copied from pyscf/data/elements.py
def _std_symbol_without_ghost(symb_or_chg):
'''For a given atom symbol (lower case or upper case) or charge, return the
"""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]
elif len(rawsymb) > 1 and symb_or_chg[0] == 'X' and symb_or_chg[:2] != 'XE':
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]
elif len(rawsymb) > 5 and rawsymb[:5] == 'GHOST':
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)
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
Expand All @@ -51,16 +51,19 @@ 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):
"""
:param frame : `chemfiles.Frame`_ object object to be wrapped
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
Expand All @@ -84,19 +87,13 @@ 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(
"pyscf systems can only be used with 'use_native_system=True'"
)
raise Exception("pyscf systems can only be used with 'use_native_system=True'")

def pairs(self):
raise Exception(
"pyscf systems can only be used with 'use_native_system=True'"
)
raise Exception("pyscf systems can only be used with 'use_native_system=True'")

def pairs_containing(self, center):
raise Exception(
"pyscf systems can only be used with 'use_native_system=True'"
)
raise Exception("pyscf systems can only be used with 'use_native_system=True'")

0 comments on commit e841798

Please sign in to comment.