From c6734504d6b9d454dcc6d4c464e6b01c04afa3c6 Mon Sep 17 00:00:00 2001 From: Kevin Kazuki Huguenin-Dumittan Date: Fri, 1 Dec 2023 17:32:05 +0100 Subject: [PATCH] linting --- examples/madelung.py | 24 ++++++++++++++---------- src/meshlode/calculators.py | 4 ++-- src/meshlode/fourier_convolution.py | 6 +++--- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/examples/madelung.py b/examples/madelung.py index 6335aabd..7700c734 100644 --- a/examples/madelung.py +++ b/examples/madelung.py @@ -7,13 +7,15 @@ """ import torch + from meshlode import MeshPotential, System + # Define simple example structure having the CsCl structure -positions = torch.tensor([[0,0,0],[0.5,0.5,0.5]]) -atomic_numbers = torch.tensor([55,17]) # Cs and Cl +positions = torch.tensor([[0, 0, 0], [0.5, 0.5, 0.5]]) +atomic_numbers = torch.tensor([55, 17]) # Cs and Cl cell = torch.eye(3) -charges = torch.tensor([1.,-1.]) +charges = torch.tensor([1.0, -1.0]) frame = System(species=atomic_numbers, positions=positions, cell=torch.eye(3)) # Define parameters in MeshLODE @@ -23,10 +25,12 @@ interpolation_order = 2 # Compute features -MP = MeshPotential(atomic_smearing=atomic_smearing, - mesh_spacing=mesh_spacing, - interpolation_order=interpolation_order, - subtract_self=True) +MP = MeshPotential( + atomic_smearing=atomic_smearing, + mesh_spacing=mesh_spacing, + interpolation_order=interpolation_order, + subtract_self=True, +) potentials_mesh = MP.compute(frame) # The ``potentials'' that have been computed so far are not the actual electrostatic @@ -55,6 +59,6 @@ # Compare against reference Madelung constant: madelung = 2 * 1.7626 / torch.sqrt(torch.tensor(3)) energies_ref = -madelung * torch.ones((n_atoms, 1)) -print('Computed energies on each atom = \n', atomic_energies) -print('Reference Madelung constant = \n', madelung) -print('Total energy = \n', total_energy) \ No newline at end of file +print("Computed energies on each atom = \n", atomic_energies) +print("Reference Madelung constant = \n", madelung) +print("Total energy = \n", total_energy) diff --git a/src/meshlode/calculators.py b/src/meshlode/calculators.py index 6792e38d..f73c20fe 100644 --- a/src/meshlode/calculators.py +++ b/src/meshlode/calculators.py @@ -9,7 +9,7 @@ Our calculator API follows the `rascaline `_ API and coding guidelines to promote usability and interoperability with existing workflows. """ -from typing import Dict, List, Union, Optional +from typing import Dict, List, Optional, Union import torch from metatensor.torch import Labels, TensorBlock, TensorMap @@ -33,7 +33,7 @@ class MeshPotential(torch.nn.Module): :param atomic_smearing: Width of the atom-centered gaussian used to create the atomic density. :param mesh_spacing: Value that determines the umber of Fourier-space grid points - that will be used along each axis. If set to ``None``, it will automatically + that will be used along each axis. If set to None, it will automatically be set to half of ``atomic_smearing`` :param interpolation_order: Interpolation order for mapping onto the grid, where an interpolation order of p corresponds to interpolation by a polynomial of degree diff --git a/src/meshlode/fourier_convolution.py b/src/meshlode/fourier_convolution.py index 92bcbba6..b43c9561 100644 --- a/src/meshlode/fourier_convolution.py +++ b/src/meshlode/fourier_convolution.py @@ -2,9 +2,10 @@ Fourier Convolution =================== """ -import torch from typing import Optional +import torch + class FourierSpaceConvolution: """ @@ -58,8 +59,7 @@ def generate_kvectors(self, ns: torch.Tensor) -> torch.Tensor: return k_vectors def kernel_func( - self, ksq: torch.Tensor, potential_exponent: int = 1, - smearing: float = 0.2 + self, ksq: torch.Tensor, potential_exponent: int = 1, smearing: float = 0.2 ) -> torch.Tensor: """ Fourier transform of the Coulomb potential or more general effective 1/r**p