Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Kazuki Huguenin-Dumittan committed Dec 1, 2023
1 parent ce4a357 commit c673450
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
24 changes: 14 additions & 10 deletions examples/madelung.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
print("Computed energies on each atom = \n", atomic_energies)
print("Reference Madelung constant = \n", madelung)
print("Total energy = \n", total_energy)
4 changes: 2 additions & 2 deletions src/meshlode/calculators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Our calculator API follows the `rascaline <https://luthaf.fr/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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/meshlode/fourier_convolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
Fourier Convolution
===================
"""
import torch
from typing import Optional

import torch


class FourierSpaceConvolution:
"""
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c673450

Please sign in to comment.