Skip to content

Commit

Permalink
Flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
ceriottm committed Dec 3, 2023
1 parent 276686a commit 864c97a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
13 changes: 5 additions & 8 deletions examples/lode-demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@
"""


# %%
# Loads libraries and defines utility functions
# ---------------------------------------------
#

import numpy as np
import matplotlib.pyplot as plt
import torch

torch.set_default_dtype(torch.float64)

import chemiscope, ase
import ase
import chemiscope
import meshlode as ml


torch.set_default_dtype(torch.float64)


# plot a 3D mesh with a stack of 2D plots
def sliceplot(mesh, sz=12, cmap="viridis", vmin=None, vmax=None):
mesh = mesh.detach().numpy()
Expand Down
12 changes: 7 additions & 5 deletions src/meshlode/fourier_convolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ def kernel_func(
self, ksq: torch.Tensor, potential_exponent: int = 1, smearing: float = 0.2
) -> torch.Tensor:
"""
Fourier transform of the Coulomb potential or more general effective :math:`1/r^p`
potentials with additional smearing to remove the singularity at the origin.
Fourier transform of the Coulomb potential or more general
effective :math:`1/r^p` potentials with additional smearing to remove the
singularity at the origin.
:param ksq: torch.tensor of shape ``(N,)`` Squared norm of the k-vectors
:param potential_exponent: Exponent of the effective :math:`1/r^p` decay
Expand All @@ -75,7 +76,7 @@ def kernel_func(
if potential_exponent == 1:
return 4 * torch.pi / ksq * torch.exp(-0.5 * smearing**2 * ksq)
elif potential_exponent == 0:
return torch.exp(-0.5 * smearing**2 * ksq)
return torch.exp(-0.5 * smearing**2 * ksq)
else:
raise ValueError("Only potential exponents 0 and 1 are supported")

Expand Down Expand Up @@ -111,8 +112,9 @@ def compute(
:param mesh_values: torch.tensor of shape ``(n_channels, nx, ny, nz)``
The values of the density defined on a mesh.
:param potential_exponent: int
The exponent in the :math:`1/r^p` decay of the effective potential, where :math:`p=1`
corresponds to the Coulomb potential, and :math:`p=0` is set as Gaussian smearing.
The exponent in the :math:`1/r^p` decay of the effective potential,
where :math:`p=1` corresponds to the Coulomb potential,
and :math:`p=0` is set as Gaussian smearing.
:param smearing: float
Width of the Gaussian smearing (for the Coulomb potential).
Expand Down
18 changes: 10 additions & 8 deletions src/meshlode/mesh_interpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ class MeshInterpolator:
Class for handling all steps related to interpolations in the context of a mesh
based Ewald summation.
In particular, this includes two core functionalities: 1. "forwards"
interpolation, in which the "charges" or more general "particle weights" of
atoms are assigned to grid points of a mesh. This is done in the
:func:`points_to_mesh` function. 2. "backwards" interpolation, in which values defined
In particular, this includes two core functionalities:
1. "forwards" interpolation, in which the "charges" or more general
"particle weights" of atoms are assigned to grid points of a mesh.
This is done in the :func:`points_to_mesh` function.
2. "backwards" interpolation, in which values defined
on a mesh are interpolated to arbitrary positions typically lying between mesh
points. This is done in the :func:`mesh_to_points` function.
Expand Down Expand Up @@ -115,8 +116,8 @@ def compute_interpolation_weights(self, positions: torch.Tensor):
"""
Compute the interpolation weights of each atom for a given cell (specified
during initialization of this class). The weights are not returned, but are used
when calling the forward (:func:`points_to_mesh`) and backward (:func:`mesh_to_points`)
interpolation functions.
when calling the forward (:func:`points_to_mesh`) and backward
(:func:`mesh_to_points`) interpolation functions.
:param positions: torch.tensor of shape ``(N,3)``
Absolute positions of atoms in Cartesian coordinates
Expand Down Expand Up @@ -219,8 +220,9 @@ def mesh_to_points(self, mesh_vals: torch.Tensor) -> torch.Tensor:
:param mesh_vals: torch.tensor of shape ``(n_channels, nx, ny, nz)``
The tensor contains the values of a function evaluated on a
three-dimensional mesh. ``(nx, ny, nz)`` are the number of points along each of
the three directions, while ``n_channels`` provides the number of such functions
three-dimensional mesh. ``(nx, ny, nz)`` are the number of
points along each of the three directions, while ``n_channels``
provides the number of such functions
that are treated simulateously for the present system.
:return: interpolated_values: torch.tensor of shape ``(n_points, n_channels)``
Expand Down

0 comments on commit 864c97a

Please sign in to comment.